Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

CORE-1910 POC Add contract version conditional logic #380

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,14 @@ export const Config = {

createConfig: createConfig,
};

export enum ContractVersion {
V3,
V4,
V5,
}

export const contractAddressToVersion = new Map<string, ContractVersion>([
['0x5FDCCA53617f4d2b9134B29090C87D01058e27e9', ContractVersion.V3], // Mainnet
['0x2d5C349fD8464DA06a3f90b4B0E9195F3d1b7F98', ContractVersion.V3], // Sandbox
Comment on lines +103 to +104
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These contracts are the wrapping proxy contract and not the implementation itself, it's got no VERSION concept like in the implementation contract, thus, we can't take a decision based on it.

]);
60 changes: 35 additions & 25 deletions src/workflows/deposit/depositEth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import {
} from '../registration';
import { ETHAmount } from '../../types';
import { BigNumber } from '@ethersproject/bignumber';
import { ImmutableXConfiguration } from '../../config';
import {
ContractVersion,
ImmutableXConfiguration,
contractAddressToVersion,
} from '../../config';

interface ETHTokenData {
decimals: number;
Expand Down Expand Up @@ -103,35 +107,41 @@ export async function depositEthWorkflow(
config.ethConfiguration.coreContractAddress,
signer,
);

const registrationContract = Registration__factory.connect(
config.ethConfiguration.registrationContractAddress,
signer,
);

const isRegistered = await isRegisteredOnChainWorkflow(
starkPublicKey,
registrationContract,
const version = contractAddressToVersion.get(
config.ethConfiguration.coreContractAddress,
);

if (!isRegistered) {
return executeRegisterAndDepositEth(
if (version == ContractVersion.V3) {
const registrationContract = Registration__factory.connect(
config.ethConfiguration.registrationContractAddress,
signer,
amount,
assetType,
starkPublicKey,
vaultId,
coreContract,
usersApi,
);
} else {
return executeDepositEth(
signer,
amount,
assetType,

const isRegistered = await isRegisteredOnChainWorkflow(
starkPublicKey,
vaultId,
coreContract,
registrationContract,
);

if (!isRegistered) {
return executeRegisterAndDepositEth(
signer,
amount,
assetType,
starkPublicKey,
vaultId,
coreContract,
usersApi,
);
}
}

// if V4, skip registration
return executeDepositEth(
signer,
amount,
assetType,
starkPublicKey,
vaultId,
coreContract,
);
}
Loading