Skip to content

Commit

Permalink
added tests for account32 (#37)
Browse files Browse the repository at this point in the history
* old tests work

* route to account32 works

* add deploy account helper script

* todo

* fix

* polish name
  • Loading branch information
shunjizhan authored Nov 10, 2023
1 parent bd2bcc0 commit 50f740c
Show file tree
Hide file tree
Showing 10 changed files with 414 additions and 115 deletions.
43 changes: 0 additions & 43 deletions chopsticks/configs/acala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,56 +20,13 @@ import-storage:
- 246gNkjCexYRsCpdjtVhz35sHjcb21jpqipzT9u4uwKV8iEE
- data:
free: 1000000000000000
-
-
- 249LSvsEyxS4VpEJGg62yhYA7sHy1KcgGW6KzACBCLW1RsZF
- data:
free: 1000000000000000
-
-
- 21y4X7QDByUjnu5KX9W1H5TbG2wTLPDbhYFHqc4v6Q1nTBnu
- data:
free: 1000000000000000
-
-
- 265dERKLvMFwWWvtGNUjQBrHFTT88VcEtb5QYh2Zuj79UGMf
- data:
free: 1000000000000000
-
-
- 21XH88Kd5vDLkrZMb4D2eYJAB9yKbycfkYBqAaD1wQQi1uJ8
- data:
free: 1000000000000000
Tokens:
Accounts:
-
-
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
- token: AUSD
- free: 1000000000000000
-
-
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
- token: DOT
- free: 1000000000000000
-
-
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
- token: LDOT
- free: 1000000000000000
GeneralCouncil:
Members:
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
- 246gNkjCexYRsCpdjtVhz35sHjcb21jpqipzT9u4uwKV8iEE
- 249LSvsEyxS4VpEJGg62yhYA7sHy1KcgGW6KzACBCLW1RsZF
- 21y4X7QDByUjnu5KX9W1H5TbG2wTLPDbhYFHqc4v6Q1nTBnu
- 265dERKLvMFwWWvtGNUjQBrHFTT88VcEtb5QYh2Zuj79UGMf
- 21XH88Kd5vDLkrZMb4D2eYJAB9yKbycfkYBqAaD1wQQi1uJ8
TechnicalCommittee:
Members:
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
- 246gNkjCexYRsCpdjtVhz35sHjcb21jpqipzT9u4uwKV8iEE
- 249LSvsEyxS4VpEJGg62yhYA7sHy1KcgGW6KzACBCLW1RsZF
EvmAccounts:
EvmAddresses:
- - - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
Expand Down
6 changes: 3 additions & 3 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dotenv from 'dotenv';
import { HardhatUserConfig } from 'hardhat/config';
import '@nomicfoundation/hardhat-toolbox';
import '@nomicfoundation/hardhat-foundry';
import '@nomicfoundation/hardhat-toolbox';
import { HardhatUserConfig } from 'hardhat/config';
import dotenv from 'dotenv';

dotenv.config();

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@certusone/wormhole-sdk": "^0.9.11",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/providers": "^5.7.0",
"@polkadot/util-crypto": "^12.5.1",
"ethers": "^5.7.0"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion scripts/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export const ADDRESSES = {
factoryAddr: '0x4D72F3b3e6D2AFeD99923137a04b9Cd9Cd2F21C5',
feeAddr: '0x9933F9dfDEf1A5D51A1b0A210A591FEfCEBC6163',
usdcAddr: '0x07DF96D1341A7d16Ba1AD431E2c847d978BC2bCe',
homaFactoryAddr: '0x3d3593927228553b349767ABa68d4fb1514678CB', // on chopsticks. TODO: update after deploying to mainnet
homaFactoryAddr: '0x2ed9aa0e30D52958E21Db37FfBDC3F0B0fD4b973',
accountHelperAddr: '0x0252340cC347718f9169d329CEFf8B15A92badf8',
},
} as const;

Expand Down
21 changes: 21 additions & 0 deletions scripts/deploy-account-helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ethers, run } from 'hardhat';

async function main() {
const AccountHelper = await ethers.getContractFactory('AccountHelper');
const ac = await AccountHelper.deploy();
await ac.deployed();

if (process.env.VERIFY) {
await run('verify:verify', {
address: ac.address,
constructorArguments: [],
});
}

console.log(`AccountHelper address: ${ac.address}`);
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
10 changes: 8 additions & 2 deletions scripts/deploy-homa-factory.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { ethers, run } from 'hardhat';
import { DOT, LDOT } from '@acala-network/contracts/utils/AcalaTokens';
import { ethers, run } from 'hardhat';

import { ADDRESSES } from './consts';

async function main() {
const stakingToken = DOT;
const liquidToken = LDOT;

const Factory = await ethers.getContractFactory('HomaFactory');
const Factory = await ethers.getContractFactory('HomaFactory', {
libraries: {
AccountHelper: ADDRESSES.ACALA.accountHelperAddr,
},
});
const factory = await Factory.deploy(stakingToken, liquidToken);
await factory.deployed();

Expand Down
3 changes: 2 additions & 1 deletion scripts/publish.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ethers } from 'hardhat';
import { EVM as EVM_ADDR } from '@acala-network/contracts/utils/Predeploy';
import { EVM__factory } from '@acala-network/contracts/typechain';
import { ethers } from 'hardhat';

import { ADDRESSES } from './consts';

const targetContract = ADDRESSES.ACALA.homaFactoryAddr;
Expand Down
21 changes: 21 additions & 0 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

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

import { ADDRESSES } from './consts';

export const loadSetups = async () => {
Expand Down Expand Up @@ -30,3 +34,20 @@ export const loadSetups = async () => {

return { deployer, user, relayer, usdt, fee, factory, ...ADDRESSES[network.name] };
};

// convert evm addr to bytes32 with prefix of `evm:` and suffix of 8 bytes of zeros
const EVM_PREFIX = '65766d3a'; // evm:
export const evmToAddr32 = (addr: string) => `0x${EVM_PREFIX}${addr.slice(2)}${'0'.repeat(16)}`;

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

export type Resolved<T> = T extends Promise<infer U> ? U : T;

export const toHuman = (amount: BigNumber, decimals: number) => Number(formatUnits(amount, decimals));

export const almostEq = (a: BigNumber, b: BigNumber) => {
const diff = a.sub(b).abs();
return a.div(diff).gt(100); // within 1% diff
};

export const ONE_ACA = parseEther('1');
Loading

0 comments on commit 50f740c

Please sign in to comment.