|
1 | 1 |
|
2 | 2 | import { BigNumber } from 'ethers'; |
3 | 3 | import { decodeAddress } from '@polkadot/util-crypto'; |
4 | | -import { ethers, network } from 'hardhat'; |
5 | 4 | import { formatUnits, parseEther } from 'ethers/lib/utils'; |
6 | 5 |
|
7 | | -import { ADDRESSES } from './consts'; |
8 | | - |
9 | | -export const loadSetups = async () => { |
10 | | - const [[deployer, user, relayer], FeeRegistry, Factory, Token] = await Promise.all([ |
11 | | - ethers.getSigners(), |
12 | | - ethers.getContractFactory('FeeRegistry'), |
13 | | - ethers.getContractFactory('Factory'), |
14 | | - ethers.getContractFactory('MockToken'), |
15 | | - ]); |
16 | | - |
17 | | - const { usdcAddr, factoryAddr, feeAddr } = ADDRESSES[network.name]; |
18 | | - |
19 | | - const usdt = Token.attach(usdcAddr); |
20 | | - const fee = FeeRegistry.attach(feeAddr); |
21 | | - const factory = Factory.attach(factoryAddr).connect(relayer); |
22 | | - |
23 | | - console.log('setup finished'); |
24 | | - console.log({ |
25 | | - deployerAddr: deployer.address, |
26 | | - userAddr: user.address, |
27 | | - relayerAddr: relayer.address, |
28 | | - factoryAddr: factory.address, |
29 | | - usdcAddr: usdcAddr, |
30 | | - feeRegistryAddr: fee.address, |
31 | | - routerFee: ethers.utils.formatEther(await fee.getFee(usdcAddr)), |
32 | | - }); |
33 | | - console.log(''); |
34 | | - |
35 | | - return { deployer, user, relayer, usdt, fee, factory, ...ADDRESSES[network.name] }; |
36 | | -}; |
37 | | - |
38 | 6 | // convert evm addr to bytes32 with prefix of `evm:` and suffix of 8 bytes of zeros |
39 | 7 | const EVM_PREFIX = '65766d3a'; // evm: |
40 | 8 | export const evmToAddr32 = (addr: string) => `0x${EVM_PREFIX}${addr.slice(2)}${'0'.repeat(16)}`; |
41 | 9 |
|
42 | 10 | export const nativeToAddr32 = (addr: string) => '0x' + Buffer.from(decodeAddress(addr)).toString('hex'); |
43 | 11 |
|
44 | | -export type Resolved<T> = T extends Promise<infer U> ? U : T; |
45 | | - |
46 | 12 | export const toHuman = (amount: BigNumber, decimals: number) => Number(formatUnits(amount, decimals)); |
47 | 13 |
|
48 | 14 | export const almostEq = (a: BigNumber, b: BigNumber) => { |
|
0 commit comments