File tree Expand file tree Collapse file tree 5 files changed +50
-9
lines changed
packages/checkout/sdk/src
smartCheckout/routing/bridge Expand file tree Collapse file tree 5 files changed +50
-9
lines changed Original file line number Diff line number Diff line change @@ -19,14 +19,15 @@ import { TokenBalanceResult } from '../types';
1919import { createBlockchainDataInstance } from '../../../instance' ;
2020import { estimateGasForBridgeApproval } from './estimateApprovalGas' ;
2121import { bridgeGasEstimate } from './bridgeGasEstimate' ;
22- import { INDEXER_ETH_ROOT_CONTRACT_ADDRESS } from './constants' ;
22+ import { getImxL1Representation , INDEXER_ETH_ROOT_CONTRACT_ADDRESS } from './constants' ;
2323import { CheckoutErrorType } from '../../../errors' ;
2424import { allowListCheckForBridge } from '../../allowList/allowListCheck' ;
2525
2626jest . mock ( '../../../gasEstimate' ) ;
2727jest . mock ( '../../../instance' ) ;
2828jest . mock ( './estimateApprovalGas' ) ;
2929jest . mock ( './bridgeGasEstimate' ) ;
30+ jest . mock ( './constants' ) ;
3031jest . mock ( '../../allowList/allowListCheck' ) ;
3132
3233describe ( 'bridgeRoute' , ( ) => {
@@ -947,7 +948,7 @@ describe('bridgeRoute', () => {
947948 } ,
948949 } ,
949950 } ;
950-
951+ ( getImxL1Representation as jest . Mock ) . mockResolvedValue ( '0x2Fa06C6672dDCc066Ab04631192738799231dE4a' ) ;
951952 ( createBlockchainDataInstance as jest . Mock ) . mockReturnValue ( {
952953 getToken : jest . fn ( ) . mockResolvedValue ( { } ) ,
953954 } ) ;
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ export const fetchL1Representation = async (
5050 if ( l2address === '' ) return '' ;
5151
5252 if ( l2address === IMX_ADDRESS_ZKEVM ) {
53- return getImxL1Representation ( getL1ChainId ( config ) ) ;
53+ return await getImxL1Representation ( getL1ChainId ( config ) , config ) ;
5454 }
5555
5656 const chainName = getIndexerChainName ( getL2ChainId ( config ) ) ;
Original file line number Diff line number Diff line change 1+ import { getImxL1Representation } from './constants' ;
2+ import { ChainId } from '../../../types' ;
3+
4+ describe ( 'constants' , ( ) => {
5+ it ( 'should return the IMX address matching the chainId' , async ( ) => {
6+ const config = {
7+ remote : {
8+ getConfig : jest . fn ( ) . mockResolvedValue ( {
9+ [ ChainId . SEPOLIA ] : '0x123' ,
10+ } ) ,
11+ } ,
12+ } as any ;
13+
14+ const result = await getImxL1Representation ( ChainId . SEPOLIA , config ) ;
15+ expect ( result ) . toBe ( '0x123' ) ;
16+ } ) ;
17+
18+ it ( 'should return empty when no matching chainId' , async ( ) => {
19+ const config = {
20+ remote : {
21+ getConfig : jest . fn ( ) . mockResolvedValue ( { } ) ,
22+ } ,
23+ } as any ;
24+
25+ const result = await getImxL1Representation ( ChainId . SEPOLIA , config ) ;
26+ expect ( result ) . toBe ( '' ) ;
27+ } ) ;
28+ } ) ;
Original file line number Diff line number Diff line change 1- import { ChainId } from '../../../types' ;
1+ import { ChainId , ImxAddressConfig } from '../../../types' ;
2+ import { CheckoutConfiguration } from '../../../config' ;
23
34// If the root address evaluates to this then its ETH
45export const INDEXER_ETH_ROOT_CONTRACT_ADDRESS = '0x0000000000000000000000000000000000000001' ;
@@ -9,9 +10,11 @@ export const getIndexerChainName = (chainId: ChainId): string => {
910} ;
1011
1112// Indexer ERC20 call does not support IMX so cannot get root chain mapping from this endpoint.
12- // TODO: WT-1693 - Move mapping to remote config
13- export const getImxL1Representation = ( chainId : ChainId ) : string => {
14- if ( chainId === ChainId . SEPOLIA ) return '0x2Fa06C6672dDCc066Ab04631192738799231dE4a' ;
15- if ( chainId === ChainId . ETHEREUM ) return '0xF57e7e7C23978C3cAEC3C3548E3D615c346e79fF' ;
16- return '' ;
13+ // Use the remote config instead to find IMX address mapping.
14+ export const getImxL1Representation = async ( chainId : ChainId , config : CheckoutConfiguration ) : Promise < string > => {
15+ const imxMappingConfig = ( await config . remote . getConfig (
16+ 'imxAddressMapping' ,
17+ ) ) as ImxAddressConfig ;
18+
19+ return imxMappingConfig [ chainId ] ?? '' ;
1720} ;
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ export type RemoteConfiguration = {
2424 bridge : BridgeConfig ;
2525 allowedNetworks : AllowedNetworkConfig [ ] ;
2626 gasEstimateTokens ?: GasEstimateTokenConfig ;
27+ imxAddressMapping ?: ImxAddressConfig ;
2728} ;
2829
2930/**
@@ -87,6 +88,14 @@ export type AllowedNetworkConfig = {
8788 chainId : number ;
8889} ;
8990
91+ /**
92+ * A type representing the IMX address mappings across available networks.
93+ * @type {{ [chainId: string]: string } }
94+ */
95+ export type ImxAddressConfig = {
96+ [ chainId : string ] : string ;
97+ } ;
98+
9099/**
91100 * A type representing the required information to estimate gas for a transaction.
92101 * @type {{ [key: string]: { bridgeToL2Addresses?: GasEstimateBridgeToL2TokenConfig, swapAddresses?: GasEstimateSwapTokenConfig } } }
You can’t perform that action at this time.
0 commit comments