-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: wcgcyx <[email protected]>
- Loading branch information
1 parent
34e2f06
commit 20c0e27
Showing
3 changed files
with
82 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ETH_MAINNET_TO_ZKEVM_MAINNET, ETH_SEPOLIA_TO_ZKEVM_TESTNET } from 'constants/bridges'; | ||
import { exportedForTesting } from './utils'; | ||
|
||
describe('utils', () => { | ||
describe('getAddresses', () => { | ||
it('should return mainnet address', () => { | ||
const source = ETH_MAINNET_TO_ZKEVM_MAINNET.rootChainID; | ||
const addresses = { mainnet: 'mainnet', testnet: 'testnet', devnet: 'devnet' }; | ||
const result = exportedForTesting.getAddresses(source, addresses); | ||
expect(result).toEqual('mainnet'); | ||
}); | ||
|
||
it('should return testnet address', () => { | ||
const source = ETH_SEPOLIA_TO_ZKEVM_TESTNET.rootChainID; | ||
const addresses = { mainnet: 'mainnet', testnet: 'testnet', devnet: 'devnet' }; | ||
const result = exportedForTesting.getAddresses(source, addresses); | ||
expect(result).toEqual('testnet'); | ||
}); | ||
|
||
it('should return devnet address in all other cases', () => { | ||
const source = 'devnet'; | ||
const addresses = { mainnet: 'mainnet', testnet: 'testnet', devnet: 'devnet' }; | ||
const result = exportedForTesting.getAddresses(source, addresses); | ||
expect(result).toEqual('devnet'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,68 @@ | ||
import { | ||
ETH_MAINNET_TO_ZKEVM_MAINNET, childETHs, ETH_SEPOLIA_TO_ZKEVM_TESTNET, rootIMXs, | ||
childAdaptors, | ||
rootAdaptors, | ||
childChains, | ||
axelarGateways, | ||
axelarAPIEndpoints, | ||
tenderlyAPIEndpoints, | ||
} from 'constants/bridges'; | ||
import { FungibleToken } from 'types'; | ||
|
||
export function getChildETH(source: string) { | ||
let eth:string; | ||
function getAddresses(source:string, addresses:Record<string, string>) { | ||
let address:string; | ||
if (source === ETH_MAINNET_TO_ZKEVM_MAINNET.rootChainID | ||
|| source === ETH_MAINNET_TO_ZKEVM_MAINNET.childChainID) { | ||
eth = childETHs.mainnet; | ||
address = addresses.mainnet; | ||
} else if (source === ETH_SEPOLIA_TO_ZKEVM_TESTNET.rootChainID | ||
|| source === ETH_SEPOLIA_TO_ZKEVM_TESTNET.childChainID) { | ||
eth = childETHs.testnet; | ||
address = addresses.testnet; | ||
} else { | ||
eth = childETHs.devnet; | ||
address = addresses.devnet; | ||
} | ||
return eth; | ||
return address; | ||
} | ||
|
||
export function getChildETH(source: string) { | ||
return getAddresses(source, childETHs); | ||
} | ||
|
||
export function isChildETH(token: FungibleToken, source: string) { | ||
return token.toUpperCase() === getChildETH(source).toUpperCase(); | ||
} | ||
|
||
export function getRootIMX(source: string) { | ||
let rootIMX:string; | ||
if (source === ETH_MAINNET_TO_ZKEVM_MAINNET.rootChainID | ||
|| source === ETH_MAINNET_TO_ZKEVM_MAINNET.childChainID) { | ||
rootIMX = rootIMXs.mainnet; | ||
} else if (source === ETH_SEPOLIA_TO_ZKEVM_TESTNET.rootChainID | ||
|| source === ETH_SEPOLIA_TO_ZKEVM_TESTNET.childChainID) { | ||
rootIMX = rootIMXs.testnet; | ||
} else { | ||
rootIMX = rootIMXs.devnet; | ||
} | ||
return rootIMX; | ||
return getAddresses(source, rootIMXs); | ||
} | ||
|
||
export function isRootIMX(token: FungibleToken, source: string) { | ||
return token.toUpperCase() === getRootIMX(source).toUpperCase(); | ||
} | ||
|
||
export function getChildAdaptor(source: string) { | ||
return getAddresses(source, childAdaptors); | ||
} | ||
|
||
export function getRootAdaptor(source: string) { | ||
return getAddresses(source, rootAdaptors); | ||
} | ||
|
||
export function getChildchain(source: string) { | ||
return getAddresses(source, childChains); | ||
} | ||
|
||
export function getAxelarGateway(source: string) { | ||
return getAddresses(source, axelarGateways); | ||
} | ||
|
||
export function getAxelarEndpoint(source:string) { | ||
return getAddresses(source, axelarAPIEndpoints); | ||
} | ||
|
||
export function getTenderlyEndpoint(source:string) { | ||
return getAddresses(source, tenderlyAPIEndpoints); | ||
} | ||
|
||
export const exportedForTesting = { | ||
getAddresses, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters