Skip to content

Commit de7bd92

Browse files
authored
v1.0.11 (#38)
* bump v1.0.11, include utils in dist * refactor * use Awaited
1 parent 50f740c commit de7bd92

File tree

8 files changed

+55
-58
lines changed

8 files changed

+55
-58
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@acala-network/asset-router",
3-
"version": "1.0.10",
3+
"version": "1.0.11",
44
"main": "dist/index.js",
55
"repository": "[email protected]:AcalaNetwork/asset-router.git",
66
"author": "Acala Developers <[email protected]>",

scripts/deploy-fee.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { ethers, run, network } from 'hardhat';
2-
import { ROUTER_TOKEN_INFO } from './consts';
1+
import { ethers, network, run } from 'hardhat';
32
import { parseUnits } from 'ethers/lib/utils';
3+
44
import { FeeStruct } from '../typechain-types/src/FeeRegistry';
5+
import { ROUTER_TOKEN_INFO } from './consts';
56

67
async function main() {
78
const isAcala = network.name === 'acala';

scripts/route-wormhole.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,37 @@
11
import { CHAIN_ID_ETH, tryNativeToHexString } from '@certusone/wormhole-sdk';
2-
import { ethers } from 'hardhat';
32
import { WormholeInstructionsStruct } from '../typechain-types/src/Factory';
4-
import { loadSetups } from './utils';
3+
import { ethers, network } from 'hardhat';
4+
5+
import { ADDRESSES } from './consts';
6+
7+
export const loadSetups = async () => {
8+
const [[deployer, user, relayer], FeeRegistry, Factory, Token] = await Promise.all([
9+
ethers.getSigners(),
10+
ethers.getContractFactory('FeeRegistry'),
11+
ethers.getContractFactory('Factory'),
12+
ethers.getContractFactory('MockToken'),
13+
]);
14+
15+
const { usdcAddr, factoryAddr, feeAddr } = ADDRESSES[network.name];
16+
17+
const usdt = Token.attach(usdcAddr);
18+
const fee = FeeRegistry.attach(feeAddr);
19+
const factory = Factory.attach(factoryAddr).connect(relayer);
20+
21+
console.log('setup finished');
22+
console.log({
23+
deployerAddr: deployer.address,
24+
userAddr: user.address,
25+
relayerAddr: relayer.address,
26+
factoryAddr: factory.address,
27+
usdcAddr: usdcAddr,
28+
feeRegistryAddr: fee.address,
29+
routerFee: ethers.utils.formatEther(await fee.getFee(usdcAddr)),
30+
});
31+
console.log('');
32+
33+
return { deployer, user, relayer, usdt, fee, factory, ...ADDRESSES[network.name] };
34+
};
535

636
async function main() {
737
const { deployer, user, relayer, usdt, fee, factory, tokenBridgeAddr } = await loadSetups();

scripts/utils.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,14 @@
11

22
import { BigNumber } from 'ethers';
33
import { decodeAddress } from '@polkadot/util-crypto';
4-
import { ethers, network } from 'hardhat';
54
import { formatUnits, parseEther } from 'ethers/lib/utils';
65

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-
386
// convert evm addr to bytes32 with prefix of `evm:` and suffix of 8 bytes of zeros
397
const EVM_PREFIX = '65766d3a'; // evm:
408
export const evmToAddr32 = (addr: string) => `0x${EVM_PREFIX}${addr.slice(2)}${'0'.repeat(16)}`;
419

4210
export const nativeToAddr32 = (addr: string) => '0x' + Buffer.from(decodeAddress(addr)).toString('hex');
4311

44-
export type Resolved<T> = T extends Promise<infer U> ? U : T;
45-
4612
export const toHuman = (amount: BigNumber, decimals: number) => Number(formatUnits(amount, decimals));
4713

4814
export const almostEq = (a: BigNumber, b: BigNumber) => {

test/config.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import { Bridge__factory } from '@certusone/wormhole-sdk/lib/cjs/ethers-contracts';
2+
import { CONTRACTS, ChainName, tryNativeToHexString } from '@certusone/wormhole-sdk';
3+
import { JsonRpcProvider } from '@ethersproject/providers';
14
import { expect } from 'chai';
5+
26
import {
37
CHAIN,
48
CHAIN_NAME,
59
CHAIN_NAME_TO_WORMHOLE_CHAIN_ID,
6-
ROUTER_TOKEN_INFO,
710
ROUTER_CHAIN,
11+
ROUTER_TOKEN_INFO,
812
} from '../scripts/consts';
913
import { MockToken__factory } from '../dist/typechain-types';
10-
import { JsonRpcProvider } from '@ethersproject/providers';
11-
import { Bridge__factory } from '@certusone/wormhole-sdk/lib/cjs/ethers-contracts';
12-
import { CONTRACTS, ChainName, tryNativeToHexString } from '@certusone/wormhole-sdk';
1314

1415
const getProvider = (networkName: string) => {
1516
const ethRpc = ({

test/homa-router.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { formatEther, parseEther, parseUnits } from 'ethers/lib/utils';
99

1010
import { ADDRESSES } from '../scripts/consts';
1111
import { FeeRegistry, HomaFactory, MockToken } from '../typechain-types';
12-
import { ONE_ACA, Resolved, almostEq, evmToAddr32, nativeToAddr32, toHuman } from '../scripts/utils';
12+
import { ONE_ACA, almostEq, evmToAddr32, nativeToAddr32, toHuman } from '../scripts/utils';
1313

1414
const { homaFactoryAddr, feeAddr, accountHelperAddr } = ADDRESSES.ACALA;
1515

@@ -28,8 +28,8 @@ describe('Homa Router', () => {
2828

2929
// dynamic
3030
let routerAddr: string;
31-
let bal0: Resolved<ReturnType<typeof fetchTokenBalances>>;
32-
let bal1: Resolved<ReturnType<typeof fetchTokenBalances>>;
31+
let bal0: Awaited<ReturnType<typeof fetchTokenBalances>>;
32+
let bal1: Awaited<ReturnType<typeof fetchTokenBalances>>;
3333

3434
const fetchTokenBalances = async () => {
3535
const [

test/xcm-route.test.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import { expect } from 'chai';
2-
import { ethers } from 'hardhat';
3-
import { Xtokens__factory } from '@acala-network/contracts/typechain';
4-
import { XTOKENS } from '@acala-network/contracts/utils/Predeploy';
51
import { BigNumber, Contract } from 'ethers';
62
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
3+
import { XTOKENS } from '@acala-network/contracts/utils/Predeploy';
4+
import { Xtokens__factory } from '@acala-network/contracts/typechain';
5+
import { ethers } from 'hardhat';
6+
import { expect } from 'chai';
77

8-
import { FeeRegistry, MockToken } from '../typechain-types';
9-
import { Factory, XcmInstructionsStruct } from '../typechain-types/src/Factory';
108
import { ADDRESSES } from '../scripts/consts';
11-
12-
type Resolved<T> = T extends Promise<infer U> ? U : T;
9+
import { Factory, XcmInstructionsStruct } from '../typechain-types/src/Factory';
10+
import { FeeRegistry, MockToken } from '../typechain-types';
1311

1412
const {
1513
feeAddr,
@@ -30,9 +28,9 @@ describe('XcmRouter', () => {
3028

3129
// dynamic
3230
let routerAddr: string;
33-
let bal0: Resolved<ReturnType<typeof fetchTokenBalances>>;
34-
let bal1: Resolved<ReturnType<typeof fetchTokenBalances>>;
35-
let bal2: Resolved<ReturnType<typeof fetchTokenBalances>>;
31+
let bal0: Awaited<ReturnType<typeof fetchTokenBalances>>;
32+
let bal1: Awaited<ReturnType<typeof fetchTokenBalances>>;
33+
let bal2: Awaited<ReturnType<typeof fetchTokenBalances>>;
3634
let xcmInstruction: XcmInstructionsStruct;
3735

3836
const fetchTokenBalances = async () => {

tsconfig-cjs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
},
88
"include": [
99
"./typechain-types",
10-
"./scripts/consts.ts"
10+
"./scripts/consts.ts",
11+
"./scripts/utils.ts",
1112
]
1213
}

0 commit comments

Comments
 (0)