diff --git a/bouncer/commands/create_lp_pool.ts b/bouncer/commands/create_lp_pool.ts index 3b067f824b..a55d6f963c 100755 --- a/bouncer/commands/create_lp_pool.ts +++ b/bouncer/commands/create_lp_pool.ts @@ -6,7 +6,7 @@ // initial price in USDC // For example: ./commands/create_lp_pool.ts btc 10000 -import { Asset } from '@chainflip-io/cli'; +import { Asset } from '@chainflip/cli'; import { createLpPool } from '../shared/create_lp_pool'; import { runWithTimeout } from '../shared/utils'; diff --git a/bouncer/commands/get_balance.ts b/bouncer/commands/get_balance.ts index c5e1ae5e04..7fa0efd926 100755 --- a/bouncer/commands/get_balance.ts +++ b/bouncer/commands/get_balance.ts @@ -1,5 +1,5 @@ #!/usr/bin/env -S pnpm tsx -import { Asset } from '@chainflip-io/cli'; +import { Asset } from '@chainflip/cli'; import { getBalance as getBalanceShared } from '../shared/get_balance'; async function getBalance(ccy: string, address: string) { diff --git a/bouncer/commands/go_bananas.ts b/bouncer/commands/go_bananas.ts index 81dc7ac0d1..aeceae1656 100755 --- a/bouncer/commands/go_bananas.ts +++ b/bouncer/commands/go_bananas.ts @@ -1,6 +1,6 @@ #!/usr/bin/env -S pnpm tsx import axios from 'axios'; -import { Asset, assetDecimals } from '@chainflip-io/cli'; +import { Asset } from '@chainflip/cli'; import bitcoin from 'bitcoinjs-lib'; import { Tapleaf } from 'bitcoinjs-lib/src/types'; import { blake2AsHex } from '@polkadot/util-crypto'; @@ -11,6 +11,7 @@ import { hexStringToBytesArray, sleep, fineAmountToAmount, + assetDecimals, } from '../shared/utils'; import { requestNewSwap } from '../shared/perform_swap'; import { testSwap } from '../shared/swapping'; @@ -124,7 +125,7 @@ async function playLp(asset: Asset, price: number, liquidity: number) { } const fees = fineAmountToAmount( BigInt(update.collected_fees.toString()).toString(10), - assetDecimals[ccy], + assetDecimals(ccy), ); console.log(`Collected ${fees} ${ccy} in fees`); } @@ -140,7 +141,7 @@ async function playLp(asset: Asset, price: number, liquidity: number) { } const amount = fineAmountToAmount( BigInt(update.bought_amount.toString()).toString(10), - assetDecimals[buyCcy], + assetDecimals(buyCcy), ); console.log(`Bought ${amount} ${buyCcy} for ${sellCcy}`); } @@ -227,22 +228,22 @@ async function bananas() { await Promise.all([ playLp( 'ETH', - price.get('ETH')! * 10 ** (assetDecimals.USDC - assetDecimals.ETH), + price.get('ETH')! * 10 ** (assetDecimals('USDC') - assetDecimals('ETH')), liquidityUsdc, ), playLp( 'BTC', - price.get('BTC')! * 10 ** (assetDecimals.USDC - assetDecimals.BTC), + price.get('BTC')! * 10 ** (assetDecimals('USDC') - assetDecimals('BTC')), liquidityUsdc, ), playLp( 'DOT', - price.get('DOT')! * 10 ** (assetDecimals.USDC - assetDecimals.DOT), + price.get('DOT')! * 10 ** (assetDecimals('USDC') - assetDecimals('DOT')), liquidityUsdc, ), playLp( 'FLIP', - price.get('FLIP')! * 10 ** (assetDecimals.USDC - assetDecimals.FLIP), + price.get('FLIP')! * 10 ** (assetDecimals('USDC') - assetDecimals('FLIP')), liquidityUsdc, ), playSwapper(), diff --git a/bouncer/commands/new_swap.ts b/bouncer/commands/new_swap.ts index 8e529e80c8..2ce4b3ff1d 100755 --- a/bouncer/commands/new_swap.ts +++ b/bouncer/commands/new_swap.ts @@ -8,7 +8,7 @@ // Argument 3 is the destination address // For example: ./commands/new_swap.ts dot btc n1ocq2FF95qopwbEsjUTy3ZrawwXDJ6UsX -import { Asset } from '@chainflip-io/cli'; +import { Asset } from '@chainflip/cli'; import { runWithTimeout } from '../shared/utils'; import { newSwap } from '../shared/new_swap'; diff --git a/bouncer/commands/perform_swap.ts b/bouncer/commands/perform_swap.ts index 1db17d5b9e..9909768063 100755 --- a/bouncer/commands/perform_swap.ts +++ b/bouncer/commands/perform_swap.ts @@ -1,5 +1,5 @@ #!/usr/bin/env -S pnpm tsx -import { Asset } from '@chainflip-io/cli'; +import { Asset } from '@chainflip/cli'; import { performSwap } from '../shared/perform_swap'; async function main() { diff --git a/bouncer/commands/provide_liquidity.ts b/bouncer/commands/provide_liquidity.ts index 4fded347c7..cd4e6e6629 100755 --- a/bouncer/commands/provide_liquidity.ts +++ b/bouncer/commands/provide_liquidity.ts @@ -5,7 +5,7 @@ // It will fund liquidity of the given currency and amount // For example: ./commands/provide_liquidity.ts btc 1.5 -import { Asset } from '@chainflip-io/cli'; +import { Asset } from '@chainflip/cli'; import { runWithTimeout } from '../shared/utils'; import { provideLiquidity } from '../shared/provide_liquidity'; diff --git a/bouncer/commands/range_order.ts b/bouncer/commands/range_order.ts index cf8a2e3031..304d6434dc 100755 --- a/bouncer/commands/range_order.ts +++ b/bouncer/commands/range_order.ts @@ -5,7 +5,7 @@ // It will create a zero to infinity range order for the currency and amount given // For example: ./commands/range_order.ts btc 10 -import { Asset } from '@chainflip-io/cli'; +import { Asset } from '@chainflip/cli'; import { rangeOrder } from '../shared/range_order'; import { runWithTimeout } from '../shared/utils'; diff --git a/bouncer/commands/send.ts b/bouncer/commands/send.ts index 698a6a711e..aa8f7d3e1c 100755 --- a/bouncer/commands/send.ts +++ b/bouncer/commands/send.ts @@ -1,5 +1,5 @@ #!/usr/bin/env -S pnpm tsx -import { Asset } from '@chainflip-io/cli'; +import { Asset } from '@chainflip/cli'; import { send } from '../shared/send'; send(process.argv[2].toUpperCase() as Asset, process.argv[3]); diff --git a/bouncer/commands/setup_swaps.ts b/bouncer/commands/setup_swaps.ts index f73b75aa2f..0e8395d221 100755 --- a/bouncer/commands/setup_swaps.ts +++ b/bouncer/commands/setup_swaps.ts @@ -6,7 +6,7 @@ // For example: ./commands/setup_swaps.ts import { cryptoWaitReady } from '@polkadot/util-crypto'; -import { Asset } from '@chainflip-io/cli'; +import { Asset } from '@chainflip/cli'; import { runWithTimeout } from '../shared/utils'; import { createLpPool } from '../shared/create_lp_pool'; import { provideLiquidity } from '../shared/provide_liquidity'; diff --git a/bouncer/package.json b/bouncer/package.json index ecabd8fd13..3d3d443b1a 100644 --- a/bouncer/package.json +++ b/bouncer/package.json @@ -6,7 +6,7 @@ "prettier:write": "prettier --write ." }, "dependencies": { - "@chainflip-io/cli": "^0.1.5-rc.1", + "@chainflip/cli": "^1.2.1-alpha.3", "@iarna/toml": "^2.2.5", "@polkadot/api": "10.7.2", "@polkadot/keyring": "12.2.1", @@ -26,7 +26,8 @@ "tiny-secp256k1": "^2.2.1", "toml": "^3.0.0", "web3": "^1.9.0", - "yargs": "^17.7.2" + "yargs": "^17.7.2", + "zod": "^3.22.4" }, "devDependencies": { "@types/minimist": "^1.2.2", diff --git a/bouncer/pnpm-lock.yaml b/bouncer/pnpm-lock.yaml index 610391a7ef..e44170d109 100644 --- a/bouncer/pnpm-lock.yaml +++ b/bouncer/pnpm-lock.yaml @@ -5,9 +5,9 @@ settings: excludeLinksFromLockfile: false dependencies: - '@chainflip-io/cli': - specifier: ^0.1.5-rc.1 - version: 0.1.5-rc.1 + '@chainflip/cli': + specifier: ^1.2.1-alpha.3 + version: 1.2.1-alpha.3(@polkadot/util-crypto@12.2.1)(@polkadot/util@12.2.1)(axios@1.3.5)(ethers@6.8.0) '@iarna/toml': specifier: ^2.2.5 version: 2.2.5 @@ -68,6 +68,9 @@ dependencies: yargs: specifier: ^17.7.2 version: 17.7.2 + zod: + specifier: ^3.22.4 + version: 3.22.4 devDependencies: '@types/minimist': @@ -117,15 +120,23 @@ packages: regenerator-runtime: 0.14.1 dev: false - /@chainflip-io/cli@0.1.5-rc.1: - resolution: {integrity: sha512-G2TS0UG/Ato0aOvDDBQtqQsHpHEP1P0CiBaXYr0hB1sknSP1cMoLZKXHfuudwey5IbuKxTtnydM+b2wzCYnybw==, tarball: https://npm.pkg.github.com/download/@chainflip-io/cli/0.1.5-rc.1/2de8ba984c607049eb9ecd55b69f9fcee4389d4e} + /@chainflip/cli@1.2.1-alpha.3(@polkadot/util-crypto@12.2.1)(@polkadot/util@12.2.1)(axios@1.3.5)(ethers@6.8.0): + resolution: {integrity: sha512-k/O1ApANYDtydfJsGKmD29pYwpJyT4MOsUksR3qpdw5QpM61Iyj/lT//xJzYiqTrBTKfboeuhAd4ybGKx4pEEg==} hasBin: true + peerDependencies: + '@polkadot/util': ^12.x + '@polkadot/util-crypto': ^12.x + axios: ^1.x + ethers: ^6.x dependencies: + '@polkadot/util': 12.2.1 + '@polkadot/util-crypto': 12.2.1(@polkadot/util@12.2.1) + axios: 1.3.5 ethers: 6.8.0 + ioredis: 5.3.2 yargs: 17.7.2 transitivePeerDependencies: - - bufferutil - - utf-8-validate + - supports-color dev: false /@esbuild-kit/cjs-loader@2.4.2: @@ -581,6 +592,10 @@ packages: resolution: {integrity: sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==} dev: false + /@ioredis/commands@1.2.0: + resolution: {integrity: sha512-Sx1pU8EM64o2BrqNpEO1CNLtKQwyhuXuqyfH7oGKCk+1a33d2r5saW8zNwm3j6BTExtjrv2BxTgzzkMwts6vGg==} + dev: false + /@noble/curves@1.0.0: resolution: {integrity: sha512-2upgEu0iLiDVDZkNLeFV2+ht0BAVgQnEmCk6JsOch9Rp8xfkMCbvbAZlA2pBHQc73dbl+vFOXfqkf4uemdn0bw==} dependencies: @@ -1814,6 +1829,11 @@ packages: mimic-response: 1.0.1 dev: false + /cluster-key-slot@1.1.2: + resolution: {integrity: sha512-RMr0FhtfXemyinomL4hrWcYJxmX6deFdCxpJzhDttxgO1+bcCnkk+9drydLVDmAMG7NE6aN/fl4F7ucU/90gAA==} + engines: {node: '>=0.10.0'} + dev: false + /color-convert@2.0.1: resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} engines: {node: '>=7.0.0'} @@ -2038,6 +2058,11 @@ packages: engines: {node: '>=0.4.0'} dev: false + /denque@2.1.0: + resolution: {integrity: sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==} + engines: {node: '>=0.10'} + dev: false + /depd@2.0.0: resolution: {integrity: sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==} engines: {node: '>= 0.8'} @@ -3186,6 +3211,23 @@ packages: side-channel: 1.0.4 dev: true + /ioredis@5.3.2: + resolution: {integrity: sha512-1DKMMzlIHM02eBBVOFQ1+AolGjs6+xEcM4PDL7NqOS6szq7H9jSaEkIUH6/a5Hl241LzW6JLSiAbNvTQjUupUA==} + engines: {node: '>=12.22.0'} + dependencies: + '@ioredis/commands': 1.2.0 + cluster-key-slot: 1.1.2 + debug: 4.3.4 + denque: 2.1.0 + lodash.defaults: 4.2.0 + lodash.isarguments: 3.1.0 + redis-errors: 1.2.0 + redis-parser: 3.0.0 + standard-as-callback: 2.1.0 + transitivePeerDependencies: + - supports-color + dev: false + /ipaddr.js@1.9.1: resolution: {integrity: sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==} engines: {node: '>= 0.10'} @@ -3486,6 +3528,14 @@ packages: p-locate: 5.0.0 dev: true + /lodash.defaults@4.2.0: + resolution: {integrity: sha512-qjxPLHd3r5DnsdGacqOMU6pb/avJzdh9tFX2ymgoZE27BmjXrNy/y4LoaiTeAb+O3gL8AfpJGtqfX/ae2leYYQ==} + dev: false + + /lodash.isarguments@3.1.0: + resolution: {integrity: sha512-chi4NHZlZqZD18a0imDHnZPrDeBbTtVN7GXMwuGdRH9qotxAjYs3aVLKc7zNOG9eddR5Ksd8rvFEBc9SsggPpg==} + dev: false + /lodash.merge@4.6.2: resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} dev: true @@ -4110,6 +4160,18 @@ packages: util-deprecate: 1.0.2 dev: false + /redis-errors@1.2.0: + resolution: {integrity: sha512-1qny3OExCf0UvUV/5wpYKf2YwPcOqXzkwKKSmKHiE6ZMQs5heeE/c8eXK+PNllPvmjgAbfnsbpkGZWy8cBpn9w==} + engines: {node: '>=4'} + dev: false + + /redis-parser@3.0.0: + resolution: {integrity: sha512-DJnGAeenTdpMEH6uAJRK/uiyEIH9WVsUmoLwzudwGJUwZPp80PDBWPHXSAGNPwNvIXAbe7MSUB1zQFugFml66A==} + engines: {node: '>=4'} + dependencies: + redis-errors: 1.2.0 + dev: false + /regenerator-runtime@0.14.1: resolution: {integrity: sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==} dev: false @@ -4434,6 +4496,10 @@ packages: tweetnacl: 0.14.5 dev: false + /standard-as-callback@2.1.0: + resolution: {integrity: sha512-qoRRSyROncaz1z0mvYqIE4lCd9p2R90i6GxW3uZv5ucSu8tU7B5HXUP1gG8pVZsYNVaXjk8ClXHPttLyxAL48A==} + dev: false + /standard-error@1.1.0: resolution: {integrity: sha512-4v7qzU7oLJfMI5EltUSHCaaOd65J6S4BqKRWgzMi4EYaE5fvNabPxmAPGdxpGXqrcWjhDGI/H09CIdEuUOUeXg==} dev: false @@ -5308,3 +5374,7 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} dev: true + + /zod@3.22.4: + resolution: {integrity: sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==} + dev: false diff --git a/bouncer/shared/approve_erc20.ts b/bouncer/shared/approve_erc20.ts index 1fb1850510..6014b4e0a2 100644 --- a/bouncer/shared/approve_erc20.ts +++ b/bouncer/shared/approve_erc20.ts @@ -1,5 +1,5 @@ import Web3 from 'web3'; -import { Asset } from '@chainflip-io/cli'; +import { Asset } from '@chainflip/cli'; import { amountToFineAmount, chainFromAsset, getEvmEndpoint } from '../shared/utils'; import { getEvmContractAddress } from './utils'; import { signAndSendTxEvm } from './send_evm'; diff --git a/bouncer/shared/contract_swap.ts b/bouncer/shared/contract_swap.ts index 745664b8bc..2be6f153e7 100644 --- a/bouncer/shared/contract_swap.ts +++ b/bouncer/shared/contract_swap.ts @@ -1,10 +1,4 @@ -import { - Asset, - executeSwap, - ExecuteSwapParams, - approveVault, - assetDecimals, -} from '@chainflip-io/cli'; +import { Asset, executeSwap, ExecuteSwapParams, approveVault } from '@chainflip/cli'; import { Wallet, getDefaultProvider } from 'ethers'; import { getChainflipApi, @@ -17,6 +11,7 @@ import { chainFromAsset, getEvmEndpoint, getWhaleMnemonic, + assetDecimals, } from './utils'; import { getNextEvmNonce } from './send_evm'; import { getBalance } from './get_balance'; @@ -53,7 +48,7 @@ export async function executeContractSwap( destAsset, // It is important that this is large enough to result in // an amount larger than existential (e.g. on Polkadot): - amount: amountToFineAmount(defaultAssetAmounts(srcAsset), assetDecimals[srcAsset]), + amount: amountToFineAmount(defaultAssetAmounts(srcAsset), assetDecimals(srcAsset)), destAddress, srcAsset, srcChain, @@ -149,6 +144,7 @@ export async function approveTokenVault(srcAsset: 'FLIP' | 'USDC' | 'ARBUSDC', a approveVault( { amount, + srcChain: chainFromAsset(srcAsset as Asset), srcAsset, }, { diff --git a/bouncer/shared/create_lp_pool.ts b/bouncer/shared/create_lp_pool.ts index 7a8e06e9f1..4388042a8e 100644 --- a/bouncer/shared/create_lp_pool.ts +++ b/bouncer/shared/create_lp_pool.ts @@ -1,5 +1,5 @@ -import { assetDecimals, Asset } from '@chainflip-io/cli'; -import { observeEvent, getChainflipApi } from '../shared/utils'; +import { Asset } from '@chainflip/cli'; +import { observeEvent, getChainflipApi, assetDecimals } from '../shared/utils'; import { submitGovernanceExtrinsic } from './cf_governance'; export async function createLpPool(ccy: Asset, initialPrice: number) { @@ -13,7 +13,7 @@ export async function createLpPool(ccy: Asset, initialPrice: number) { ).toJSON()! === null ) { const price = BigInt( - Math.round((initialPrice / 10 ** (assetDecimals[ccy] - assetDecimals.USDC)) * 2 ** 128), + Math.round((initialPrice / 10 ** (assetDecimals(ccy) - assetDecimals('USDC'))) * 2 ** 128), ); console.log( 'Setting up ' + ccy + ' pool with an initial price of ' + initialPrice + ' USDC per ' + ccy, diff --git a/bouncer/shared/evm_deposits.ts b/bouncer/shared/evm_deposits.ts index c94b18c914..76bc8d62c7 100644 --- a/bouncer/shared/evm_deposits.ts +++ b/bouncer/shared/evm_deposits.ts @@ -1,5 +1,5 @@ import Web3 from 'web3'; -import { Asset, chainContractIds, assetContractIds, assetDecimals } from '@chainflip-io/cli'; +import { Asset } from '@chainflip/cli'; import { doPerformSwap } from '../shared/perform_swap'; import { prepareSwap, testSwap } from '../shared/swapping'; import { @@ -14,6 +14,9 @@ import { amountToFineAmount, chainFromAsset, getEvmEndpoint, + assetDecimals, + chainContractId, + assetContractId, } from '../shared/utils'; import { signAndSendTxEvm } from './send_evm'; import { getCFTesterAbi } from './eth_abis'; @@ -81,14 +84,14 @@ async function testTxMultipleContractSwaps(sourceAsset: Asset, destAsset: Asset) // eslint-disable-next-line @typescript-eslint/no-explicit-any const cfTesterContract = new web3.eth.Contract(cfTesterAbi as any, cfTesterAddress); const amount = BigInt( - amountToFineAmount(defaultAssetAmounts(sourceAsset), assetDecimals[sourceAsset]), + amountToFineAmount(defaultAssetAmounts(sourceAsset), assetDecimals(sourceAsset)), ); const numSwaps = 2; const txData = cfTesterContract.methods .multipleContractSwap( - chainContractIds[chainFromAsset(destAsset)], + chainContractId(chainFromAsset(destAsset)), destAsset === 'DOT' ? decodeDotAddressForContract(destAddress) : destAddress, - assetContractIds[destAsset], + assetContractId(destAsset), getEvmContractAddress(chainFromAsset(sourceAsset), sourceAsset), amount, '0x', diff --git a/bouncer/shared/fund_flip.ts b/bouncer/shared/fund_flip.ts index d8a3351b1d..73a11e5304 100644 --- a/bouncer/shared/fund_flip.ts +++ b/bouncer/shared/fund_flip.ts @@ -1,6 +1,6 @@ import { HexString } from '@polkadot/util/types'; import { cryptoWaitReady } from '@polkadot/util-crypto'; -import { assetDecimals, fundStateChainAccount } from '@chainflip-io/cli'; +import { fundStateChainAccount } from '@chainflip/cli'; import { Wallet, ethers } from 'ethers'; import { getNextEvmNonce } from './send_evm'; import { @@ -9,6 +9,7 @@ import { decodeFlipAddressForContract, getEvmEndpoint, getWhaleKey, + assetDecimals, } from './utils'; import { observeEvent, getChainflipApi, amountToFineAmount } from '../shared/utils'; import { approveErc20 } from './approve_erc20'; @@ -19,7 +20,7 @@ export async function fundFlip(scAddress: string, flipAmount: string) { await approveErc20('FLIP', getEvmContractAddress('Ethereum', 'GATEWAY'), flipAmount); - const flipperinoAmount = amountToFineAmount(flipAmount, assetDecimals.FLIP); + const flipperinoAmount = amountToFineAmount(flipAmount, assetDecimals('FLIP')); const flipContractAddress = process.env.ETH_FLIP_ADDRESS ?? getEvmContractAddress('Ethereum', 'FLIP'); @@ -39,7 +40,7 @@ export async function fundFlip(scAddress: string, flipAmount: string) { flipContractAddress, } as const; const txOptions = { - nonce: BigInt(await getNextEvmNonce('Ethereum')), + nonce: await getNextEvmNonce('Ethereum'), } as const; console.log('Funding ' + flipAmount + ' FLIP to ' + scAddress); @@ -54,14 +55,14 @@ export async function fundFlip(scAddress: string, flipAmount: string) { } const receipt2 = await fundStateChainAccount( pubkey as HexString, - flipperinoAmount, + BigInt(flipperinoAmount), networkOptions, txOptions, ); console.log( 'Transaction complete, tx_hash: ' + - receipt2.transactionHash + + receipt2.hash + ' blockNumber: ' + receipt2.blockNumber + ' blockHash: ' + diff --git a/bouncer/shared/fund_redeem.ts b/bouncer/shared/fund_redeem.ts index 6d4ab05fc9..454478e88a 100644 --- a/bouncer/shared/fund_redeem.ts +++ b/bouncer/shared/fund_redeem.ts @@ -1,12 +1,12 @@ import assert from 'assert'; import { randomBytes } from 'crypto'; import { HexString } from '@polkadot/util/types'; -import { assetDecimals } from '@chainflip-io/cli'; import { fineAmountToAmount, newAddress, observeBalanceIncrease, getChainflipApi, + assetDecimals, } from '../shared/utils'; import { getBalance } from '../shared/get_balance'; import { fundFlip } from '../shared/fund_flip'; @@ -45,7 +45,7 @@ export async function testFundRedeem(providedSeed?: string) { const chainflip = await getChainflipApi(); const redemptionTax = await chainflip.query.funding.redemptionTax(); const redemptionTaxAmount = parseInt( - fineAmountToAmount(redemptionTax.toString(), assetDecimals.FLIP), + fineAmountToAmount(redemptionTax.toString(), assetDecimals('FLIP')), ); console.log(`Redemption tax: ${redemptionTax} = ${redemptionTaxAmount} FLIP`); diff --git a/bouncer/shared/gaslimit_ccm.ts b/bouncer/shared/gaslimit_ccm.ts index f243dc15b5..196e7d9ba2 100644 --- a/bouncer/shared/gaslimit_ccm.ts +++ b/bouncer/shared/gaslimit_ccm.ts @@ -1,5 +1,5 @@ import Web3 from 'web3'; -import { Asset, Assets, Chain } from '@chainflip-io/cli'; +import { Asset, Assets, Chain } from '@chainflip/cli'; import { newCcmMetadata, prepareSwap } from './swapping'; import { chainFromAsset, diff --git a/bouncer/shared/get_balance.ts b/bouncer/shared/get_balance.ts index 27a7084ed0..ff51c15a34 100644 --- a/bouncer/shared/get_balance.ts +++ b/bouncer/shared/get_balance.ts @@ -1,4 +1,4 @@ -import { Asset } from '@chainflip-io/cli'; +import { Asset } from '@chainflip/cli'; import { getEvmContractAddress } from './utils'; import { getBtcBalance } from './get_btc_balance'; import { getDotBalance } from './get_dot_balance'; diff --git a/bouncer/shared/get_dot_balance.ts b/bouncer/shared/get_dot_balance.ts index 57034b906c..99f3c4829b 100644 --- a/bouncer/shared/get_dot_balance.ts +++ b/bouncer/shared/get_dot_balance.ts @@ -1,9 +1,8 @@ -import { assetDecimals } from '@chainflip-io/cli'; -import { getPolkadotApi, fineAmountToAmount } from './utils'; +import { getPolkadotApi, fineAmountToAmount, assetDecimals } from './utils'; export async function getDotBalance(address: string): Promise { const polkadot = await getPolkadotApi(process.env.POLKADOT_ENDPOINT); const planckBalance: string = (await polkadot.query.system.account(address)).data.free.toString(); - return fineAmountToAmount(planckBalance, assetDecimals.DOT); + return fineAmountToAmount(planckBalance, assetDecimals('DOT')); } diff --git a/bouncer/shared/get_erc20_balance.ts b/bouncer/shared/get_erc20_balance.ts index b74f258fa0..a5bb061ab4 100644 --- a/bouncer/shared/get_erc20_balance.ts +++ b/bouncer/shared/get_erc20_balance.ts @@ -1,5 +1,5 @@ import Web3 from 'web3'; -import { Chain } from '@chainflip-io/cli/.'; +import { Chain } from '@chainflip/cli/.'; import { fineAmountToAmount, getEvmEndpoint } from './utils'; import { getErc20abi } from './eth_abis'; diff --git a/bouncer/shared/get_evm_native_balance.ts b/bouncer/shared/get_evm_native_balance.ts index 81ab4b1d9a..ed63a30357 100644 --- a/bouncer/shared/get_evm_native_balance.ts +++ b/bouncer/shared/get_evm_native_balance.ts @@ -1,10 +1,10 @@ -import { Chain, assetDecimals } from '@chainflip-io/cli'; +import { Chain } from '@chainflip/cli'; import Web3 from 'web3'; -import { fineAmountToAmount, getEvmEndpoint } from './utils'; +import { assetDecimals, fineAmountToAmount, getEvmEndpoint } from './utils'; export async function getEvmNativeBalance(chain: Chain, address: string): Promise { const web3 = new Web3(getEvmEndpoint(chain)); const weiBalance: string = await web3.eth.getBalance(address); - return fineAmountToAmount(weiBalance, assetDecimals.ETH); + return fineAmountToAmount(weiBalance, assetDecimals('ETH')); } diff --git a/bouncer/shared/lp_api_test.ts b/bouncer/shared/lp_api_test.ts index 4cb74ce0c6..92933ac5d1 100644 --- a/bouncer/shared/lp_api_test.ts +++ b/bouncer/shared/lp_api_test.ts @@ -1,4 +1,4 @@ -import { assetDecimals, Asset, Chain, Assets } from '@chainflip-io/cli'; +import { Asset, Chain, Assets } from '@chainflip/cli'; import assert from 'assert'; import { getChainflipApi, @@ -10,6 +10,7 @@ import { observeBalanceIncrease, chainFromAsset, isWithinOnePercent, + assetDecimals, } from './utils'; import { jsonRpc } from './json_rpc'; import { provideLiquidity } from './provide_liquidity'; @@ -24,7 +25,7 @@ type RpcAsset = { const testAsset: Asset = 'ETH'; // TODO: Make these tests work with any asset const testRpcAsset: RpcAsset = { chain: chainFromAsset(testAsset), asset: testAsset }; const testAmount = 0.1; -const testAssetAmount = parseInt(amountToFineAmount(testAmount.toString(), assetDecimals.ETH)); +const testAssetAmount = parseInt(amountToFineAmount(testAmount.toString(), assetDecimals('ETH'))); const amountToProvide = testAmount * 50; // Provide plenty of the asset for the tests const chainflip = await getChainflipApi(); const testAddress = '0x1594300cbd587694affd70c933b9ee9155b186d9'; @@ -37,7 +38,7 @@ async function lpApiRpc(method: string, params: any[]): Promise { async function provideLiquidityAndTestAssetBalances() { const fineAmountToProvide = parseInt( - amountToFineAmount(amountToProvide.toString(), assetDecimals.ETH), + amountToFineAmount(amountToProvide.toString(), assetDecimals('ETH')), ); // We have to wait finalization here because the LP API server is using a finalized block stream (This may change in PRO-777 PR#3986) await provideLiquidity(testAsset, amountToProvide, true); diff --git a/bouncer/shared/new_swap.ts b/bouncer/shared/new_swap.ts index 1d295b2bd0..1dffc8363a 100644 --- a/bouncer/shared/new_swap.ts +++ b/bouncer/shared/new_swap.ts @@ -1,4 +1,4 @@ -import { Asset, broker } from '@chainflip-io/cli'; +import { Asset, broker } from '@chainflip/cli'; import { decodeDotAddressForContract, chainFromAsset } from './utils'; const defaultCommissionBps = 100; // 1% @@ -35,5 +35,6 @@ export async function newSwap( url: brokerUrl, commissionBps: brokerCommissionBps, }, + 'backspin', ); } diff --git a/bouncer/shared/perform_swap.ts b/bouncer/shared/perform_swap.ts index 5289b1fed9..e011a57d34 100644 --- a/bouncer/shared/perform_swap.ts +++ b/bouncer/shared/perform_swap.ts @@ -1,5 +1,5 @@ import { encodeAddress } from '@polkadot/util-crypto'; -import { Asset } from '@chainflip-io/cli'; +import { Asset } from '@chainflip/cli'; import { newSwap } from './new_swap'; import { send, sendViaCfTester } from './send'; import { getBalance } from './get_balance'; @@ -8,7 +8,7 @@ import { observeBalanceIncrease, observeEvent, observeCcmReceived, - assetToChain, + shortChainFomAsset, observeSwapScheduled, observeSwapEvents, observeBroadcastSuccess, @@ -51,7 +51,7 @@ export async function requestNewSwap( (event) => { // Find deposit address for the right swap by looking at destination address: const destAddressEvent = encodeDestinationAddress( - event.data.destinationAddress[assetToChain(destAsset)], + event.data.destinationAddress[shortChainFomAsset(destAsset)], destAsset, ); if (!destAddressEvent) return false; @@ -77,8 +77,8 @@ export async function requestNewSwap( const res = (await addressPromise).data; - const depositAddress = res.depositAddress[assetToChain(sourceAsset)]; - const channelDestAddress = res.destinationAddress[assetToChain(destAsset)]; + const depositAddress = res.depositAddress[shortChainFomAsset(sourceAsset)]; + const channelDestAddress = res.destinationAddress[shortChainFomAsset(destAsset)]; const channelId = Number(res.channelId); if (log) { diff --git a/bouncer/shared/polkadot_runtime_update.ts b/bouncer/shared/polkadot_runtime_update.ts index c1a4724ff5..01d5ebc46a 100644 --- a/bouncer/shared/polkadot_runtime_update.ts +++ b/bouncer/shared/polkadot_runtime_update.ts @@ -4,13 +4,14 @@ import assert from 'assert'; import { execSync } from 'child_process'; import { blake2AsU8a } from '@polkadot/util-crypto'; -import { Asset, Assets, assetDecimals } from '@chainflip-io/cli'; +import { Asset, Assets } from '@chainflip/cli'; import { getPolkadotApi, observeEvent, amountToFineAmount, sleep, observeBadEvents, + assetDecimals, } from '../shared/utils'; import { specVersion, getNetworkRuntimeVersion } from './utils/spec_version'; import { handleDispatchError, submitAndGetEvent } from '../shared/polkadot_utils'; @@ -72,7 +73,7 @@ export async function pushPolkadotRuntimeUpdate(wasmPath: string): Promise // Submit the proposal const observeDemocracyStarted = observeEvent('democracy:Started', polkadot); - const amount = amountToFineAmount(PROPOSAL_AMOUNT, assetDecimals.DOT); + const amount = amountToFineAmount(PROPOSAL_AMOUNT, assetDecimals('DOT')); console.log(`Submitting proposal with amount: ${PROPOSAL_AMOUNT}`); const democracyStartedEvent = await submitAndGetEvent( polkadot.tx.democracy.propose({ Legacy: preimageHash }, amount), diff --git a/bouncer/shared/provide_liquidity.ts b/bouncer/shared/provide_liquidity.ts index c1ad72e573..cadd8da9f7 100644 --- a/bouncer/shared/provide_liquidity.ts +++ b/bouncer/shared/provide_liquidity.ts @@ -1,6 +1,6 @@ import { Keyring } from '@polkadot/keyring'; import { cryptoWaitReady } from '@polkadot/util-crypto'; -import { Asset, chainContractIds, assetDecimals } from '@chainflip-io/cli'; +import { Asset } from '@chainflip/cli'; import { observeEvent, newAddress, @@ -8,10 +8,12 @@ import { decodeDotAddressForContract, handleSubstrateError, lpMutex, - assetToChain, + shortChainFomAsset, amountToFineAmount, isWithinOnePercent, chainFromAsset, + chainContractId, + assetDecimals, } from '../shared/utils'; import { send } from '../shared/send'; @@ -23,7 +25,7 @@ export async function provideLiquidity( ) { const chainflip = await getChainflipApi(); await cryptoWaitReady(); - const chain = assetToChain(ccy); + const chain = shortChainFomAsset(ccy); const keyring = new Keyring({ type: 'sr25519' }); const lpUri = lpKey ?? (process.env.LP_URI || '//LP_1'); @@ -34,7 +36,7 @@ export async function provideLiquidity( ( await chainflip.query.liquidityProvider.liquidityRefundAddress( lp.address, - chainContractIds[chainFromAsset(ccy)], + chainContractId(chainFromAsset(ccy)), ) ).toJSON() === null ) { @@ -73,7 +75,7 @@ export async function provideLiquidity( event.data.asset.toUpperCase() === ccy && isWithinOnePercent( BigInt(event.data.amountCredited.replace(/,/g, '')), - BigInt(amountToFineAmount(String(amount), assetDecimals[ccy])), + BigInt(amountToFineAmount(String(amount), assetDecimals(ccy))), ), undefined, waitForFinalization, diff --git a/bouncer/shared/range_order.ts b/bouncer/shared/range_order.ts index 0f90727abb..677baf2f1b 100644 --- a/bouncer/shared/range_order.ts +++ b/bouncer/shared/range_order.ts @@ -1,16 +1,17 @@ import { Keyring } from '@polkadot/keyring'; import { cryptoWaitReady } from '@polkadot/util-crypto'; -import { assetDecimals, Asset } from '@chainflip-io/cli'; +import { Asset } from '@chainflip/cli'; import { observeEvent, getChainflipApi, handleSubstrateError, amountToFineAmount, lpMutex, + assetDecimals, } from '../shared/utils'; export async function rangeOrder(ccy: Asset, amount: number) { - const fineAmount = amountToFineAmount(String(amount), assetDecimals[ccy]); + const fineAmount = amountToFineAmount(String(amount), assetDecimals(ccy)); const chainflip = await getChainflipApi(); await cryptoWaitReady(); diff --git a/bouncer/shared/redeem_flip.ts b/bouncer/shared/redeem_flip.ts index bcfff48a0f..4ae9fd04dd 100644 --- a/bouncer/shared/redeem_flip.ts +++ b/bouncer/shared/redeem_flip.ts @@ -1,5 +1,5 @@ import assert from 'assert'; -import { Assets, assetDecimals, executeRedemption, getRedemptionDelay } from '@chainflip-io/cli'; +import { Assets, executeRedemption, getRedemptionDelay } from '@chainflip/cli'; import { HexString } from '@polkadot/util/types'; import { Wallet, ethers } from 'ethers'; import Keyring from '@polkadot/keyring'; @@ -16,13 +16,14 @@ import { chainFromAsset, getEvmEndpoint, getWhaleKey, + assetDecimals, } from './utils'; export type RedeemAmount = 'Max' | { Exact: string }; function intoFineAmount(amount: RedeemAmount): RedeemAmount { if (typeof amount === 'object' && amount.Exact) { - const fineAmount = amountToFineAmount(amount.Exact, assetDecimals.FLIP); + const fineAmount = amountToFineAmount(amount.Exact, assetDecimals('FLIP')); return { Exact: fineAmount }; } return amount; diff --git a/bouncer/shared/send.ts b/bouncer/shared/send.ts index 9d9a2e9527..6c55fc9651 100644 --- a/bouncer/shared/send.ts +++ b/bouncer/shared/send.ts @@ -1,5 +1,5 @@ import Web3 from 'web3'; -import { Asset, assetDecimals } from '@chainflip-io/cli'; +import { Asset } from '@chainflip/cli'; import { sendDot } from './send_dot'; import { sendBtc } from './send_btc'; import { sendErc20 } from './send_erc20'; @@ -10,6 +10,7 @@ import { amountToFineAmount, chainFromAsset, getEvmEndpoint, + assetDecimals, } from './utils'; import { approveErc20 } from './approve_erc20'; import { getCFTesterAbi } from './eth_abis'; @@ -82,7 +83,7 @@ export async function sendViaCfTester(asset: Asset, toAddress: string, amount?: switch (asset) { case 'ETH': txData = cfTesterContract.methods.transferEth(toAddress).encodeABI(); - value = amountToFineAmount(amount ?? defaultAssetAmounts(asset), assetDecimals[asset]); + value = amountToFineAmount(amount ?? defaultAssetAmounts(asset), assetDecimals(asset)); break; case 'USDC': case 'FLIP': { @@ -91,7 +92,7 @@ export async function sendViaCfTester(asset: Asset, toAddress: string, amount?: .transferToken( toAddress, getEvmContractAddress(chain, asset), - amountToFineAmount(amount ?? defaultAssetAmounts(asset), assetDecimals[asset]), + amountToFineAmount(amount ?? defaultAssetAmounts(asset), assetDecimals(asset)), ) .encodeABI(); break; diff --git a/bouncer/shared/send_dot.ts b/bouncer/shared/send_dot.ts index 25fc7bceb3..4800efe5b0 100644 --- a/bouncer/shared/send_dot.ts +++ b/bouncer/shared/send_dot.ts @@ -1,9 +1,14 @@ -import { assetDecimals } from '@chainflip-io/cli'; -import { polkadotSigningMutex, sleep, amountToFineAmount, getPolkadotApi } from './utils'; +import { + polkadotSigningMutex, + sleep, + amountToFineAmount, + getPolkadotApi, + assetDecimals, +} from './utils'; import { aliceKeyringPair } from './polkadot_keyring'; export async function sendDot(address: string, amount: string) { - const planckAmount = amountToFineAmount(amount, assetDecimals.DOT); + const planckAmount = amountToFineAmount(amount, assetDecimals('DOT')); const alice = await aliceKeyringPair(); const polkadot = await getPolkadotApi(); diff --git a/bouncer/shared/send_erc20.ts b/bouncer/shared/send_erc20.ts index 1faff3fca6..7516d0beba 100644 --- a/bouncer/shared/send_erc20.ts +++ b/bouncer/shared/send_erc20.ts @@ -1,5 +1,5 @@ import Web3 from 'web3'; -import { Chain } from '@chainflip-io/cli/.'; +import { Chain } from '@chainflip/cli/.'; import { signAndSendTxEvm } from './send_evm'; import { amountToFineAmount, getEvmEndpoint } from './utils'; import { getErc20abi } from './eth_abis'; diff --git a/bouncer/shared/send_evm.ts b/bouncer/shared/send_evm.ts index c2444163b8..5e4bd7d009 100644 --- a/bouncer/shared/send_evm.ts +++ b/bouncer/shared/send_evm.ts @@ -1,11 +1,12 @@ import Web3 from 'web3'; -import { assetDecimals, approveVault, Chain } from '@chainflip-io/cli'; +import { approveVault, Chain } from '@chainflip/cli'; import { amountToFineAmount, ethNonceMutex, arbNonceMutex, getEvmEndpoint, getWhaleKey, + assetDecimals, } from './utils'; const nextEvmNonce: { [key in 'Ethereum' | 'Arbitrum']: number | undefined } = { @@ -88,6 +89,6 @@ export async function sendEvmNative( ethAmount: string, log = true, ) { - const weiAmount = amountToFineAmount(ethAmount, assetDecimals.ETH); + const weiAmount = amountToFineAmount(ethAmount, assetDecimals('ETH')); await signAndSendTxEvm(chain, evmAddress, weiAmount, undefined, undefined, log); } diff --git a/bouncer/shared/swapping.ts b/bouncer/shared/swapping.ts index 3c20350690..d79c630798 100644 --- a/bouncer/shared/swapping.ts +++ b/bouncer/shared/swapping.ts @@ -1,5 +1,5 @@ import { randomAsHex, randomAsNumber } from '@polkadot/util-crypto'; -import { Asset, assetDecimals, Assets } from '@chainflip-io/cli'; +import { Asset, Assets } from '@chainflip/cli'; import Web3 from 'web3'; import { performSwap, SwapParams } from '../shared/perform_swap'; import { @@ -8,6 +8,7 @@ import { getEvmContractAddress, amountToFineAmount, defaultAssetAmounts, + assetDecimals, } from '../shared/utils'; import { BtcAddressType, btcAddressTypes } from '../shared/new_btc_address'; import { CcmDepositMetadata } from '../shared/new_swap'; @@ -78,7 +79,7 @@ export function newCcmMetadata( const gasDiv = gasBudgetFraction ?? 100; const gasBudget = Math.floor( - Number(amountToFineAmount(defaultAssetAmounts(sourceAsset), assetDecimals[sourceAsset])) / + Number(amountToFineAmount(defaultAssetAmounts(sourceAsset), assetDecimals(sourceAsset))) / gasDiv, ); @@ -190,11 +191,15 @@ export async function testAllSwaps() { // (numberAssetsEthereum - 1) + (numberAssets (BTC has 4 different types) - 1) = 2 + 7 = 9 await approveTokenVault( 'USDC', - (BigInt(amountToFineAmount(defaultAssetAmounts('USDC'), assetDecimals.USDC)) * 9n).toString(), + ( + BigInt(amountToFineAmount(defaultAssetAmounts('USDC'), assetDecimals('USDC'))) * 9n + ).toString(), ); await approveTokenVault( 'FLIP', - (BigInt(amountToFineAmount(defaultAssetAmounts('FLIP'), assetDecimals.FLIP)) * 9n).toString(), + ( + BigInt(amountToFineAmount(defaultAssetAmounts('FLIP'), assetDecimals('FLIP'))) * 9n + ).toString(), ); // TODO: Remove this but for now skipping arbitrum swaps as they are not supported yet diff --git a/bouncer/shared/utils.ts b/bouncer/shared/utils.ts index 1f4dc351d4..d99f742420 100644 --- a/bouncer/shared/utils.ts +++ b/bouncer/shared/utils.ts @@ -3,14 +3,7 @@ import { setTimeout as sleep } from 'timers/promises'; import Client from 'bitcoin-core'; import { ApiPromise, WsProvider, Keyring } from '@polkadot/api'; import { Mutex } from 'async-mutex'; -import { - Chain, - Asset, - assetChains, - chainContractIds, - assetDecimals, - Assets, -} from '@chainflip-io/cli'; +import { Chain, Asset, Assets, assetConstants, chainConstants } from '@chainflip/cli'; import Web3 from 'web3'; import { Connection, Keypair } from '@solana/web3.js'; import { u8aToHex } from '@polkadot/util'; @@ -80,7 +73,7 @@ export function getEvmContractAddress(chain: Chain, contract: string): string { } // We use this instead of assetChains[asset] from the SDK because the SC strings are lowercase -export function assetToChain(asset: Asset): string { +export function shortChainFomAsset(asset: Asset): string { switch (asset) { case 'DOT': return 'Dot'; @@ -97,7 +90,7 @@ export function assetToChain(asset: Asset): string { case 'SOLUSDC': return 'Solana'; default: - return ''; + throw new Error(`Unsupported asset: ${asset}`); } } @@ -144,6 +137,53 @@ export function defaultAssetAmounts(asset: Asset): string { } } +export function assetContractId(asset: Asset): number { + switch (asset) { + case 'BTC': + return assetConstants.Btc.contractId; + case 'ETH': + return assetConstants.Eth.contractId; + case 'USDC': + return assetConstants.Usdc.contractId; + case 'FLIP': + return assetConstants.Flip.contractId; + case 'DOT': + return assetConstants.Dot.contractId; + default: + throw new Error(`Unsupported asset: ${asset}`); + } +} + +export function assetDecimals(asset: Asset): number { + switch (asset) { + case 'BTC': + return assetConstants.Btc.decimals; + case 'ETH': + return assetConstants.Eth.decimals; + case 'USDC': + return assetConstants.Usdc.decimals; + case 'FLIP': + return assetConstants.Flip.decimals; + case 'DOT': + return assetConstants.Dot.decimals; + default: + throw new Error(`Unsupported asset: ${asset}`); + } +} + +export function chainContractId(chain: Chain): number { + switch (chain) { + case 'Ethereum': + return chainConstants.Ethereum.contractId; + case 'Bitcoin': + return chainConstants.Bitcoin.contractId; + case 'Polkadot': + return chainConstants.Polkadot.contractId; + default: + throw new Error(`Unsupported chain: ${chain}`); + } +} + export const runWithTimeout = async (promise: Promise, millis: number): Promise => { const controller = new AbortController(); const result = await Promise.race([ @@ -439,18 +479,31 @@ export async function newAddress( rawAddress = await newBtcAddress(seed, type ?? 'P2PKH'); break; default: - throw new Error('unexpected asset'); + throw new Error(`Unsupported asset: ${asset}`); } return String(rawAddress).trim(); } export function chainFromAsset(asset: Asset): Chain { - if (asset in assetChains) { - return assetChains[asset]; + switch (asset) { + case 'DOT': + return 'Polkadot'; + case 'ETH': + case 'FLIP': + case 'USDC': + return 'Ethereum'; + case 'BTC': + return 'Bitcoin'; + case 'ARBUSDC': + case 'ARBETH': + return 'Arbitrum'; + case 'SOL': + case 'SOLUSDC': + return 'Solana'; + default: + throw new Error(`Unsupported asset: ${asset}`); } - - throw new Error('unexpected asset'); } export function getEvmEndpoint(chain: Chain): string { @@ -514,24 +567,6 @@ export function getWhaleKey(chain: Chain): string { } } -export function chainShortNameFromAsset(asset: Asset): string { - switch (asset) { - case Assets.FLIP: - case Assets.ETH: - case Assets.USDC: - return 'Eth'; - case Assets.DOT: - return 'Dot'; - case Assets.BTC: - return 'Btc'; - case 'ARBETH': - case 'ARBUSDC': - return 'Arb'; - default: - throw new Error('unexpected asset'); - } -} - export async function observeBalanceIncrease( dstCcy: string, address: string, @@ -646,7 +681,7 @@ export async function observeCcmReceived( address, 'ReceivedxSwapAndCall', [ - chainContractIds[chainFromAsset(sourceAsset)].toString(), + chainContractId(chainFromAsset(sourceAsset)).toString(), sourceAddress ?? null, messageMetadata.message, getEvmContractAddress(chainFromAsset(destAsset), destAsset.toString()), @@ -748,7 +783,7 @@ type SwapRate = { export async function getSwapRate(from: Asset, to: Asset, fromAmount: string) { const chainflipApi = await getChainflipApi(); - const fineFromAmount = amountToFineAmount(fromAmount, assetDecimals[from]); + const fineFromAmount = amountToFineAmount(fromAmount, assetDecimals(from)); const hexPrice = (await chainflipApi.rpc( 'cf_swap_rate', from, @@ -757,7 +792,7 @@ export async function getSwapRate(from: Asset, to: Asset, fromAmount: string) { )) as SwapRate; const finePriceOutput = parseInt(hexPrice.output); - const outputPrice = fineAmountToAmount(finePriceOutput.toString(), assetDecimals[to]); + const outputPrice = fineAmountToAmount(finePriceOutput.toString(), assetDecimals(to)); return outputPrice; } diff --git a/bouncer/tests/broker_fee_collection_test.ts b/bouncer/tests/broker_fee_collection_test.ts index fc934e7604..f48c6a26ff 100755 --- a/bouncer/tests/broker_fee_collection_test.ts +++ b/bouncer/tests/broker_fee_collection_test.ts @@ -2,13 +2,12 @@ import assert from 'assert'; import { randomBytes } from 'crypto'; import Keyring from '@polkadot/keyring'; -import { Asset, Assets, assetDecimals } from '@chainflip-io/cli'; +import { Asset, Assets } from '@chainflip/cli'; import { cryptoWaitReady } from '@polkadot/util-crypto'; import { EgressId, amountToFineAmount, brokerMutex, - chainShortNameFromAsset, decodeDotAddressForContract, getChainflipApi, handleSubstrateError, @@ -16,6 +15,8 @@ import { observeBalanceIncrease, observeEvent, runWithTimeout, + shortChainFomAsset, + assetDecimals, } from '../shared/utils'; import { getBalance } from '../shared/get_balance'; import { performSwap } from '../shared/perform_swap'; @@ -60,7 +61,7 @@ async function testBrokerFees(asset: Asset, seed?: string): Promise { const destinationAddress = await newAddress(swapAsset, seed ?? randomBytes(32).toString('hex')); const observeDestinationAddress = asset === Assets.DOT ? decodeDotAddressForContract(destinationAddress) : destinationAddress; - const destinationChain = chainShortNameFromAsset(swapAsset); // "ETH" -> "Eth" + const destinationChain = shortChainFomAsset(swapAsset); // "ETH" -> "Eth" console.log(`${asset} destinationAddress:`, destinationAddress); const observeSwapScheduledEvent = observeEvent( ':SwapScheduled', @@ -94,7 +95,7 @@ async function testBrokerFees(asset: Asset, seed?: string): Promise { swapScheduledEvent.data.depositAmount.replaceAll(',', ''), ); const rawDepositForSwapAmountBigInt = BigInt( - amountToFineAmount(rawDepositForSwapAmount, assetDecimals[asset]), + amountToFineAmount(rawDepositForSwapAmount, assetDecimals(asset)), ); console.log('depositAmount:', depositAmountAfterIngressFee); assert( @@ -132,7 +133,7 @@ async function testBrokerFees(asset: Asset, seed?: string): Promise { const withdrawalAddress = await newAddress(asset, seed ?? randomBytes(32).toString('hex')); const observeWithdrawalAddress = asset === Assets.DOT ? decodeDotAddressForContract(withdrawalAddress) : withdrawalAddress; - const chain = chainShortNameFromAsset(asset); + const chain = shortChainFomAsset(asset); console.log(`${chain} withdrawalAddress:`, withdrawalAddress); const balanceBeforeWithdrawal = await getBalance(asset, withdrawalAddress); console.log( @@ -172,10 +173,10 @@ async function testBrokerFees(asset: Asset, seed?: string): Promise { const balanceAfterWithdrawal = await getBalance(asset, withdrawalAddress); console.log(`${asset} Balance after withdrawal:`, balanceAfterWithdrawal); const balanceAfterWithdrawalBigInt = BigInt( - amountToFineAmount(balanceAfterWithdrawal, assetDecimals[asset]), + amountToFineAmount(balanceAfterWithdrawal, assetDecimals(asset)), ); const balanceBeforeWithdrawalBigInt = BigInt( - amountToFineAmount(balanceBeforeWithdrawal, assetDecimals[asset]), + amountToFineAmount(balanceBeforeWithdrawal, assetDecimals(asset)), ); // Log the chain state for Ethereum assets to help debugging. if (['FLIP', 'ETH', 'USDC'].includes(asset.toString())) {