diff --git a/packages/config/src/balance/__snapshots__/balance.test.ts.snap b/packages/config/src/balance/__snapshots__/balance.test.ts.snap index 3dded7de..3815d735 100644 --- a/packages/config/src/balance/__snapshots__/balance.test.ts.snap +++ b/packages/config/src/balance/__snapshots__/balance.test.ts.snap @@ -92,3 +92,12 @@ exports[`balance tokens should be correct params with Token 1`] = ` }, ] `; + +exports[`balance tokens should be correct params with Token2 1`] = ` +[ + "", + { + "Token2": 1, + }, +] +`; diff --git a/packages/config/src/balance/balance.constants.ts b/packages/config/src/balance/balance.constants.ts index e76dc4a2..eb2f7363 100644 --- a/packages/config/src/balance/balance.constants.ts +++ b/packages/config/src/balance/balance.constants.ts @@ -11,4 +11,5 @@ export enum BalanceFunction { Accounts = 'accounts', Asset = 'asset', AssetMetadatas = 'assetMetadatas', + CurrencyMetadatas = 'currencyMetadatas', } diff --git a/packages/config/src/balance/balance.interfaces.ts b/packages/config/src/balance/balance.interfaces.ts index 2116e4d6..02594ad0 100644 --- a/packages/config/src/balance/balance.interfaces.ts +++ b/packages/config/src/balance/balance.interfaces.ts @@ -53,6 +53,7 @@ export interface TokensBalanceConfig< Token: Symbols | 'MOVR' | 'KUSD'; } | { ForeignAsset: AssetId } + | { Token2: AssetId } ), ]; calc: (data: TokensPalletAccountData) => bigint; @@ -71,7 +72,7 @@ export interface MinBalanceAssetsConfig { export interface MinBalanceAssetRegistryConfig { pallet: BalancePallet.AssetRegistry; - function: BalanceFunction.AssetMetadatas; + function: BalanceFunction.AssetMetadatas | BalanceFunction.CurrencyMetadatas; path: ['minimalBalance']; - params: [{ ForeignAssetId: AssetId }]; + params: [{ ForeignAssetId: AssetId } | { Token2: AssetId }]; } diff --git a/packages/config/src/balance/balance.test.ts b/packages/config/src/balance/balance.test.ts index 43656518..e03d76b2 100644 --- a/packages/config/src/balance/balance.test.ts +++ b/packages/config/src/balance/balance.test.ts @@ -54,5 +54,11 @@ describe('balance', () => { expect(cfg2.getParams(account)).toMatchSnapshot(); }); + + it('should be correct params with Token2', () => { + const cfg2 = balance.tokens2(1); + + expect(cfg2.getParams(account)).toMatchSnapshot(); + }); }); }); diff --git a/packages/config/src/balance/balance.ts b/packages/config/src/balance/balance.ts index ec401b5c..182884a3 100644 --- a/packages/config/src/balance/balance.ts +++ b/packages/config/src/balance/balance.ts @@ -23,10 +23,12 @@ export function createBalanceBuilder< assets, minAssetPallet, minAssetRegistryPallet, + minCurrencyMetadata, ormlTokens, system, tokens: (asset: number | bigint | Symbols | 'MOVR' | 'KUSD' | 'AUSD') => tokens(asset), + tokens2: (asset: AssetId) => tokens2(asset), }; } @@ -58,6 +60,15 @@ function minAssetRegistryPallet(asset: AssetId): MinBalanceAssetRegistryConfig { }; } +function minCurrencyMetadata(asset: AssetId): MinBalanceAssetRegistryConfig { + return { + pallet: BalancePallet.AssetRegistry, + function: BalanceFunction.CurrencyMetadatas, + path: ['minimalBalance'], + params: [{ Token2: asset }], + }; +} + function ormlTokens(asset: AssetId): OrmlTokensBalanceConfig { return { pallet: BalancePallet.OrmlTokens, @@ -80,6 +91,10 @@ function system(): SystemBalanceConfig { }; } +function calcTokensBalance({ free, frozen }: TokensPalletAccountData): bigint { + return BigInt(free.sub(frozen).toString()); +} + function tokens( asset: number | bigint | Symbols | 'MOVR' | 'KUSD' | 'AUSD', ): TokensBalanceConfig { @@ -93,7 +108,18 @@ function tokens( ? { ForeignAsset: asset as number } : { Token: asset as Symbols }, ], - calc: ({ free, frozen }: TokensPalletAccountData) => - BigInt(free.sub(frozen).toString()), + calc: calcTokensBalance, + }; +} + +function tokens2( + asset: AssetId, +): TokensBalanceConfig { + return { + pallet: BalancePallet.Tokens, + function: BalanceFunction.Accounts, + path: [], + getParams: (account: string) => [account, { Token2: asset }], + calc: calcTokensBalance, }; } diff --git a/packages/config/src/config/moonbeam/assets/bnc.ts b/packages/config/src/config/moonbeam/assets/bnc.ts new file mode 100644 index 00000000..426ee505 --- /dev/null +++ b/packages/config/src/config/moonbeam/assets/bnc.ts @@ -0,0 +1,42 @@ +import { AssetSymbol, ChainKey } from '../../../constants'; +import { + XTokensExtrinsicCurrencyTypes, + XTokensExtrinsicSuccessEvent, +} from '../../../extrinsic'; +import { + assets, + balance, + chains, + extrinsic, + withdraw, +} from '../moonbeam.common'; +import { MoonbeamXcmConfig } from '../moonbeam.interfaces'; + +const asset = assets[AssetSymbol.BNC]; +const origin = chains[ChainKey.BifrostPolkadot]; + +export const BNC: MoonbeamXcmConfig = { + asset, + origin, + deposit: { + [origin.key]: { + source: origin, + balance: balance.system(), + extrinsic: extrinsic + .xTokens() + .transfer() + .successEvent(XTokensExtrinsicSuccessEvent.TransferredMultiAssets) + .origin(origin) + .asset({ + [XTokensExtrinsicCurrencyTypes.Native]: asset.originSymbol, + }), + }, + }, + withdraw: { + [origin.key]: withdraw.xTokens({ + balance: balance.system(), + destination: origin, + feePerWeight: 64, + }), + }, +}; diff --git a/packages/config/src/config/moonbeam/assets/glmr.ts b/packages/config/src/config/moonbeam/assets/glmr.ts index a89a1ebb..0c605ec8 100644 --- a/packages/config/src/config/moonbeam/assets/glmr.ts +++ b/packages/config/src/config/moonbeam/assets/glmr.ts @@ -19,11 +19,13 @@ import { MoonbeamXcmConfig } from '../moonbeam.interfaces'; const asset = assets[AssetSymbol.GLMR]; const acala = chains[ChainKey.Acala]; const astar = chains[ChainKey.Astar]; +const bifrost = chains[ChainKey.BifrostPolkadot]; const parallel = chains[ChainKey.Parallel]; const phala = chains[ChainKey.Phala]; const acalaGlmrId = getMoonAssetId(acala); const astarGlmrId = getMoonAssetId(astar); +const bifrostGlmrId = getMoonAssetId(bifrost); const parallelGlmrId = getMoonAssetId(parallel); const phalaGlmrId = getMoonAssetId(phala); @@ -56,6 +58,19 @@ export const GLMR: MoonbeamXcmConfig = { .V1() .X2(getPalletInstance(astar)), }, + [bifrost.key]: { + source: bifrost, + balance: balance.tokens2(bifrostGlmrId), + sourceFeeBalance: balance.system(), + extrinsic: extrinsic + .xTokens() + .transfer() + .successEvent(XTokensExtrinsicSuccessEvent.TransferredMultiAssets) + .origin(bifrost) + .asset({ + [XTokensExtrinsicCurrencyTypes.Token2]: bifrostGlmrId, + }), + }, [parallel.key]: { source: parallel, balance: balance.assets(parallelGlmrId), @@ -91,6 +106,12 @@ export const GLMR: MoonbeamXcmConfig = { destination: astar, feePerWeight: 50_000, }), + [bifrost.key]: withdraw.xTokens({ + balance: balance.tokens2(bifrostGlmrId), + destination: bifrost, + feePerWeight: 0.8, + sourceMinBalance: balance.minCurrencyMetadata(bifrostGlmrId), + }), [parallel.key]: withdraw.xTokens({ balance: balance.assets(parallelGlmrId), destination: parallel, diff --git a/packages/config/src/config/moonbeam/moonbeam.assets.ts b/packages/config/src/config/moonbeam/moonbeam.assets.ts index f6df414b..e30b76de 100644 --- a/packages/config/src/config/moonbeam/moonbeam.assets.ts +++ b/packages/config/src/config/moonbeam/moonbeam.assets.ts @@ -6,6 +6,7 @@ export const MOONBEAM_ASSETS = [ AssetSymbol.ACA, AssetSymbol.ASTR, AssetSymbol.AUSD, + AssetSymbol.BNC, AssetSymbol.DOT, AssetSymbol.GLMR, AssetSymbol.IBTC, @@ -32,6 +33,11 @@ export const MOONBEAM_ASSETS_MAP: AssetsMap = { erc20Id: '0xffffffff52c56a9257bb97f4b2b6f7b2d624ecda', originSymbol: AssetSymbol.AUSD, }, + [AssetSymbol.BNC]: { + id: '165823357460190568952172802245839421906', + erc20Id: '0xffffffff7cc06abdf7201b350a1265c62c8601d2', + originSymbol: AssetSymbol.BNC, + }, [AssetSymbol.DOT]: { id: '42259045809535163221576417993425387648', erc20Id: '0xffffffff1fcacbd218edc0eba20fc2308c778080', diff --git a/packages/config/src/config/moonbeam/moonbeam.chains.ts b/packages/config/src/config/moonbeam/moonbeam.chains.ts index 3c38dbb6..fb6c01f1 100644 --- a/packages/config/src/config/moonbeam/moonbeam.chains.ts +++ b/packages/config/src/config/moonbeam/moonbeam.chains.ts @@ -5,6 +5,7 @@ import { MoonbeamChains } from './moonbeam.interfaces'; export const MOONBEAM_CHAINS = [ ChainKey.Acala, ChainKey.Astar, + ChainKey.BifrostPolkadot, ChainKey.Darwinia, ChainKey.Interlay, ChainKey.Parallel, @@ -31,6 +32,14 @@ export const MOONBEAM_CHAINS_MAP: ChainsMap = { moonAssetId: 18446744073709551619n, palletInstance: 10, }, + [ChainKey.BifrostPolkadot]: { + key: ChainKey.BifrostPolkadot, + name: 'Bifrost', + ws: 'wss://hk.p.bifrost-rpc.liebi.com/ws', + weight: 1_000_000_000, + parachainId: 2030, + moonAssetId: 1, + }, [ChainKey.Darwinia]: { key: ChainKey.Darwinia, name: 'Darwinia', diff --git a/packages/config/src/config/moonbeam/moonbeam.ts b/packages/config/src/config/moonbeam/moonbeam.ts index cdcbfb26..bd89c131 100644 --- a/packages/config/src/config/moonbeam/moonbeam.ts +++ b/packages/config/src/config/moonbeam/moonbeam.ts @@ -4,6 +4,7 @@ import { MoonbeamXcmConfigs } from './moonbeam.interfaces'; import { ACA } from './assets/aca'; import { ASTR } from './assets/astr'; import { AUSD } from './assets/ausd'; +import { BNC } from './assets/bnc'; import { DOT } from './assets/dot'; import { GLMR } from './assets/glmr'; import { IBTC } from './assets/ibtc'; @@ -17,6 +18,7 @@ export const MOONBEAM_CONFIGS: MoonbeamXcmConfigs = { [AssetSymbol.ACA]: ACA, [AssetSymbol.ASTR]: ASTR, [AssetSymbol.AUSD]: AUSD, + [AssetSymbol.BNC]: BNC, [AssetSymbol.DOT]: DOT, [AssetSymbol.GLMR]: GLMR, [AssetSymbol.IBTC]: IBTC, diff --git a/packages/config/src/constants/chains.ts b/packages/config/src/constants/chains.ts index ddb29133..fff809b6 100644 --- a/packages/config/src/constants/chains.ts +++ b/packages/config/src/constants/chains.ts @@ -46,6 +46,7 @@ export enum ChainKey { AlphanetRelay = 'AlphanetRelay', Astar = 'Astar', Bifrost = 'Bifrost', + BifrostPolkadot = 'BifrostPolkadot', Calamari = 'Calamari', CloverAlphanet = 'CloverAlphanet', Crab = 'Crab', diff --git a/packages/config/src/extrinsic/xTokens/xTokens.constants.ts b/packages/config/src/extrinsic/xTokens/xTokens.constants.ts index d7428730..77963da4 100644 --- a/packages/config/src/extrinsic/xTokens/xTokens.constants.ts +++ b/packages/config/src/extrinsic/xTokens/xTokens.constants.ts @@ -12,6 +12,7 @@ export enum XTokensExtrinsicSuccessEvent { export enum XTokensExtrinsicCurrencyTypes { Token = 'Token', + Token2 = 'Token2', Native = 'Native', ForeignAsset = 'ForeignAsset', MantaCurrency = 'MantaCurrency', diff --git a/packages/config/src/extrinsic/xTokens/xTokens.interfaces.ts b/packages/config/src/extrinsic/xTokens/xTokens.interfaces.ts index 00ddeec5..cf5be154 100644 --- a/packages/config/src/extrinsic/xTokens/xTokens.interfaces.ts +++ b/packages/config/src/extrinsic/xTokens/xTokens.interfaces.ts @@ -198,6 +198,9 @@ export type XTokensTransferExtrinsicParamsAsset< | { [XTokensExtrinsicCurrencyTypes.Token]: Symbols | 'KUSD' | 'MOVR'; } + | { + [XTokensExtrinsicCurrencyTypes.Token2]: AssetId; + } | { [XTokensExtrinsicCurrencyTypes.Native]: Symbols; }