From c383bd49eca242114d707770d6ab415b0bc2b28a Mon Sep 17 00:00:00 2001 From: Kai Hirota <34954529+kaihirota@users.noreply.github.com> Date: Wed, 8 Nov 2023 11:52:06 +1100 Subject: [PATCH 1/2] update --- src/config/config.ts | 11 +++++ src/workflows/deposit/depositEth.ts | 69 ++++++++++++++++++----------- 2 files changed, 55 insertions(+), 25 deletions(-) diff --git a/src/config/config.ts b/src/config/config.ts index 3ab83ae6..85c07668 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -92,3 +92,14 @@ export const Config = { createConfig: createConfig, }; + +export enum ContractVersion { + V3, + V4, + V5, +} + +export const contractAddressToVersion = new Map([ + ['0x5FDCCA53617f4d2b9134B29090C87D01058e27e9', ContractVersion.V3], // Mainnet + ['0x2d5C349fD8464DA06a3f90b4B0E9195F3d1b7F98', ContractVersion.V3], // Sandbox +]); diff --git a/src/workflows/deposit/depositEth.ts b/src/workflows/deposit/depositEth.ts index b04502c6..8954331e 100644 --- a/src/workflows/deposit/depositEth.ts +++ b/src/workflows/deposit/depositEth.ts @@ -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; @@ -103,35 +107,50 @@ 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, + ); + } else { + return executeDepositEth( + signer, + amount, + assetType, + starkPublicKey, + vaultId, + coreContract, + ); + } } + + // if V4, skip registration + return executeDepositEth( + signer, + amount, + assetType, + starkPublicKey, + vaultId, + coreContract, + ); } From 25765805f1841ad361db1d35391c0d4e7bde87cd Mon Sep 17 00:00:00 2001 From: Kai Hirota <34954529+kaihirota@users.noreply.github.com> Date: Wed, 8 Nov 2023 13:21:34 +1100 Subject: [PATCH 2/2] update --- src/workflows/deposit/depositEth.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/workflows/deposit/depositEth.ts b/src/workflows/deposit/depositEth.ts index 8954331e..cbedcbaa 100644 --- a/src/workflows/deposit/depositEth.ts +++ b/src/workflows/deposit/depositEth.ts @@ -132,15 +132,6 @@ export async function depositEthWorkflow( coreContract, usersApi, ); - } else { - return executeDepositEth( - signer, - amount, - assetType, - starkPublicKey, - vaultId, - coreContract, - ); } }