diff --git a/.changeset/popular-tomatoes-sniff.md b/.changeset/popular-tomatoes-sniff.md new file mode 100644 index 00000000..476fcd88 --- /dev/null +++ b/.changeset/popular-tomatoes-sniff.md @@ -0,0 +1,5 @@ +--- +'@moonbeam-network/xcm-builder': patch +--- + +Add AccountId32 support diff --git a/package-lock.json b/package-lock.json index ad259a64..bf974787 100644 --- a/package-lock.json +++ b/package-lock.json @@ -66,11 +66,6 @@ "@polkadot/types": "^10.5.1" } }, - "node_modules/@adraffy/ens-normalize": { - "version": "1.9.2", - "resolved": "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.9.2.tgz", - "integrity": "sha512-0h+FrQDqe2Wn+IIGFkTCd4aAwTJ+7834Ek1COohCyV26AXhwQ7WQaz+4F/nLOeVl/3BtWHOHLPsq46V8YB46Eg==" - }, "node_modules/@ampproject/remapping": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.1.tgz", @@ -4012,7 +4007,8 @@ "type": "individual", "url": "https://paulmillr.com/funding/" } - ] + ], + "peer": true }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", @@ -16855,7 +16851,6 @@ "@moonbeam-network/xcm-types": "1.0.1", "@moonbeam-network/xcm-utils": "1.0.3", "big.js": "^6.2.1", - "ethers": "^5.7.2", "type-fest": "^3.8.0" }, "peerDependencies": { @@ -16866,59 +16861,6 @@ "@polkadot/util-crypto": "^12.5.1" } }, - "packages/builder/node_modules/@noble/hashes": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.1.2.tgz", - "integrity": "sha512-KYRCASVTv6aeUi1tsF8/vpyR7zpfs3FUzy2Jqm+MU+LmUKhQ0y2FpfwqkCcxSg2ua4GALJd8k2R76WxwZGbQpA==", - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ] - }, - "packages/builder/node_modules/@types/node": { - "version": "18.15.13", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.13.tgz", - "integrity": "sha512-N+0kuo9KgrUQ1Sn/ifDXsvg0TTleP7rIy4zOBGECxAljqvqfqpTfzx0Q1NUedOixRMBfe2Whhb056a42cWs26Q==" - }, - "packages/builder/node_modules/aes-js": { - "version": "4.0.0-beta.5", - "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-4.0.0-beta.5.tgz", - "integrity": "sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q==" - }, - "packages/builder/node_modules/ethers": { - "version": "6.6.2", - "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.6.2.tgz", - "integrity": "sha512-vyWfVAj2g7xeZIivOqlbpt7PbS2MzvJkKgsncgn4A/1xZr8Q3BznBmEBRQyPXKCgHmX4PzRQLpnYG7jl/yutMg==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/ethers-io/" - }, - { - "type": "individual", - "url": "https://www.buymeacoffee.com/ricmoo" - } - ], - "dependencies": { - "@adraffy/ens-normalize": "1.9.2", - "@noble/hashes": "1.1.2", - "@noble/secp256k1": "1.7.1", - "@types/node": "18.15.13", - "aes-js": "4.0.0-beta.5", - "tslib": "2.4.0", - "ws": "8.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/builder/node_modules/tslib": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", - "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" - }, "packages/builder/node_modules/type-fest": { "version": "3.8.0", "license": "(MIT OR CC0-1.0)", @@ -16929,26 +16871,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "packages/builder/node_modules/ws": { - "version": "8.5.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz", - "integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==", - "engines": { - "node": ">=10.0.0" - }, - "peerDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" - }, - "peerDependenciesMeta": { - "bufferutil": { - "optional": true - }, - "utf-8-validate": { - "optional": true - } - } - }, "packages/config": { "name": "@moonbeam-network/xcm-config", "version": "1.3.12", diff --git a/packages/builder/fixtures/builderParamsMock.ts b/packages/builder/fixtures/builderParamsMock.ts index 7a336164..adcdaa22 100644 --- a/packages/builder/fixtures/builderParamsMock.ts +++ b/packages/builder/fixtures/builderParamsMock.ts @@ -5,6 +5,18 @@ import { } from '@moonbeam-network/xcm-types'; import { ExtrinsicConfigBuilderPrams } from '../src/extrinsic'; +export const interlayTestnetMock = new Parachain({ + ecosystem: Ecosystem.AlphanetRelay, + genesisHash: + '0x418ae94c9fce02b1ab3b5bc211cd2f2133426f2861d97482bbdfdac1bbb0fb92', + isTestChain: true, + key: 'interlay-testnet', + name: 'Interlay Testnet', + parachainId: 2032, + ss58Format: 2032, + ws: 'wss://interlay-moonbeam-alphanet.interlay.io/', +}); + export const alphanetAssetHubMock = new Parachain({ ecosystem: Ecosystem.AlphanetRelay, genesisHash: @@ -41,3 +53,14 @@ export const buildParamsMock: ExtrinsicConfigBuilderPrams = { palletInstance: 10, source: alphanetAssetHubMock, }; + +export const buildParachainParamsMock: ExtrinsicConfigBuilderPrams = { + address: 'wd84XqsQ4LVzhmTBVd4s5ApGt9sBnnk8K7Q5PhBwwhxwqgm1u', + amount: 99_000_000_000n, + asset: 'USDT', + destination: interlayTestnetMock, + fee: 5_000_000_000n, + feeAsset: 'RMRK', + palletInstance: 10, + source: alphanetAssetHubMock, +}; diff --git a/packages/builder/package.json b/packages/builder/package.json index bc02aad4..eb81d987 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -53,7 +53,6 @@ "@moonbeam-network/xcm-types": "1.0.1", "@moonbeam-network/xcm-utils": "1.0.3", "big.js": "^6.2.1", - "ethers": "^5.7.2", "type-fest": "^3.8.0" }, "peerDependencies": { diff --git a/packages/builder/src/extrinsic/ExtrinsicBuilder.utils.ts b/packages/builder/src/extrinsic/ExtrinsicBuilder.utils.ts index 67e29694..938477d1 100644 --- a/packages/builder/src/extrinsic/ExtrinsicBuilder.utils.ts +++ b/packages/builder/src/extrinsic/ExtrinsicBuilder.utils.ts @@ -1,5 +1,7 @@ import { SubmittableExtrinsicFunction } from '@polkadot/api/types'; import { getTypeDef } from '@polkadot/types'; +import { u8aToHex } from '@polkadot/util'; +import { decodeAddress } from '@polkadot/util-crypto'; import { XcmVersion } from './ExtrinsicBuilder.interfaces'; export function getExtrinsicArgumentVersion( @@ -34,3 +36,21 @@ export function getExtrinsicArgumentVersion( throw new Error("Can't find Xcm version"); } + +export function getExtrinsicAccount(address: string) { + const isEthAddress = address.length === 42; + + return isEthAddress + ? { + AccountKey20: { + key: address, + network: 'Any', + }, + } + : { + AccountId32: { + id: u8aToHex(decodeAddress(address)), + network: null, + }, + }; +} diff --git a/packages/builder/src/extrinsic/pallets/eqBalances/__snapshots__/eqBalances.test.ts.snap b/packages/builder/src/extrinsic/pallets/eqBalances/__snapshots__/eqBalances.test.ts.snap index 4412b23f..8b2f83cf 100644 --- a/packages/builder/src/extrinsic/pallets/eqBalances/__snapshots__/eqBalances.test.ts.snap +++ b/packages/builder/src/extrinsic/pallets/eqBalances/__snapshots__/eqBalances.test.ts.snap @@ -28,6 +28,44 @@ exports[`eqBalances transferXcm should get correct arguments 1`] = ` { "AccountKey20": { "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + "network": "Any", + }, + }, + ], + }, + "parents": 1, + }, +] +`; + +exports[`eqBalances transferXcm to parachain should be correct config 1`] = ` +ExtrinsicConfig { + "func": "transferXcm", + "getArgs": [Function], + "module": "eqBalances", + "type": "Substrate", +} +`; + +exports[`eqBalances transferXcm to parachain should get correct arguments 1`] = ` +[ + [ + "USDT", + 99000000000n, + ], + [ + "RMRK", + 5000000000n, + ], + { + "interior": { + "X2": [ + { + "Parachain": 2032, + }, + { + "AccountId32": { + "id": "0x18e6c7ad45fbab18778710642072fdd057470b76d4d568b44dea6accd5b0c423", "network": null, }, }, @@ -60,6 +98,39 @@ exports[`eqBalances xcmTransfer should get correct arguments 1`] = ` { "AccountKey20": { "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + "network": "Any", + }, + }, + ], + }, + "parents": 1, + }, + "ThisAccWillPay", +] +`; + +exports[`eqBalances xcmTransfer to parachain should be correct config 1`] = ` +ExtrinsicConfig { + "func": "xcmTransfer", + "getArgs": [Function], + "module": "eqBalances", + "type": "Substrate", +} +`; + +exports[`eqBalances xcmTransfer to parachain should get correct arguments 1`] = ` +[ + "USDT", + 99000000000n, + { + "interior": { + "X2": [ + { + "Parachain": 2032, + }, + { + "AccountId32": { + "id": "0x18e6c7ad45fbab18778710642072fdd057470b76d4d568b44dea6accd5b0c423", "network": null, }, }, diff --git a/packages/builder/src/extrinsic/pallets/eqBalances/eqBalances.test.ts b/packages/builder/src/extrinsic/pallets/eqBalances/eqBalances.test.ts index 636b82e9..44728928 100644 --- a/packages/builder/src/extrinsic/pallets/eqBalances/eqBalances.test.ts +++ b/packages/builder/src/extrinsic/pallets/eqBalances/eqBalances.test.ts @@ -1,4 +1,7 @@ -import { buildParamsMock } from '../../../../fixtures'; +import { + buildParachainParamsMock, + buildParamsMock, +} from '../../../../fixtures'; import { eqBalances } from './eqBalances'; describe('eqBalances', () => { @@ -25,4 +28,32 @@ describe('eqBalances', () => { expect(extrinsic.getArgs({} as any)).toMatchSnapshot(); }); }); + + describe('xcmTransfer to parachain', () => { + const extrinsic = eqBalances() + .xcmTransfer() + .build(buildParachainParamsMock); + + it('should be correct config', () => { + expect(extrinsic).toMatchSnapshot(); + }); + + it('should get correct arguments', () => { + expect(extrinsic.getArgs({} as any)).toMatchSnapshot(); + }); + }); + + describe('transferXcm to parachain', () => { + const extrinsic = eqBalances() + .transferXcm() + .build(buildParachainParamsMock); + + it('should be correct config', () => { + expect(extrinsic).toMatchSnapshot(); + }); + + it('should get correct arguments', () => { + expect(extrinsic.getArgs({} as any)).toMatchSnapshot(); + }); + }); }); diff --git a/packages/builder/src/extrinsic/pallets/eqBalances/eqBalances.ts b/packages/builder/src/extrinsic/pallets/eqBalances/eqBalances.ts index b66df2db..d34d1e2b 100644 --- a/packages/builder/src/extrinsic/pallets/eqBalances/eqBalances.ts +++ b/packages/builder/src/extrinsic/pallets/eqBalances/eqBalances.ts @@ -1,5 +1,6 @@ /* eslint-disable sort-keys */ import { ExtrinsicConfigBuilder } from '../../ExtrinsicBuilder.interfaces'; +import { getExtrinsicAccount } from '../../ExtrinsicBuilder.utils'; import { ExtrinsicConfig } from '../../ExtrinsicConfig'; export enum EqBalancesFee { @@ -27,12 +28,7 @@ export function eqBalances() { { Parachain: destination.parachainId, }, - { - AccountKey20: { - network: null, - key: address, - }, - }, + getExtrinsicAccount(address), ], }, }, @@ -58,12 +54,7 @@ export function eqBalances() { { Parachain: destination.parachainId, }, - { - AccountKey20: { - network: null, - key: address, - }, - }, + getExtrinsicAccount(address), ], }, }, diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap b/packages/builder/src/extrinsic/pallets/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap index 3c5fb4ce..635b285f 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap @@ -54,6 +54,69 @@ exports[`polkadotXcm limitedReserveTransferAssets here should get correct argume ] `; +exports[`polkadotXcm limitedReserveTransferAssets parachain should be correct config 1`] = ` +ExtrinsicConfig { + "func": "limitedReserveTransferAssets", + "getArgs": [Function], + "module": "polkadotXcm", + "type": "Substrate", +} +`; + +exports[`polkadotXcm limitedReserveTransferAssets parachain should get correct arguments 1`] = ` +[ + { + "V1": { + "interior": { + "X1": { + "Parachain": 2032, + }, + }, + "parents": 1, + }, + }, + { + "V1": { + "interior": { + "X1": { + "AccountId32": { + "id": "0x18e6c7ad45fbab18778710642072fdd057470b76d4d568b44dea6accd5b0c423", + "network": null, + }, + }, + }, + "parents": 0, + }, + }, + { + "V1": [ + { + "fun": { + "Fungible": 99000000000n, + }, + "id": { + "Concrete": { + "interior": { + "X2": [ + { + "PalletInstance": 10, + }, + { + "GeneralIndex": "USDT", + }, + ], + }, + "parents": 0, + }, + }, + }, + ], + }, + 0, + "Unlimited", +] +`; + exports[`polkadotXcm limitedReserveTransferAssets x1 should be correct config 1`] = ` ExtrinsicConfig { "func": "limitedReserveTransferAssets", @@ -175,6 +238,69 @@ exports[`polkadotXcm limitedReserveTransferAssets x2 should get correct argument ] `; +exports[`polkadotXcm limitedReserveWithdrawAssets parachain should be correct config 1`] = ` +ExtrinsicConfig { + "func": "limitedReserveWithdrawAssets", + "getArgs": [Function], + "module": "polkadotXcm", + "type": "Substrate", +} +`; + +exports[`polkadotXcm limitedReserveWithdrawAssets parachain should get correct arguments 1`] = ` +[ + { + "V1": { + "interior": { + "X1": { + "Parachain": 2032, + }, + }, + "parents": 1, + }, + }, + { + "V1": { + "interior": { + "X1": { + "AccountId32": { + "id": "0x18e6c7ad45fbab18778710642072fdd057470b76d4d568b44dea6accd5b0c423", + "network": null, + }, + }, + }, + "parents": 0, + }, + }, + { + "V1": [ + { + "fun": { + "Fungible": 99000000000n, + }, + "id": { + "Concrete": { + "interior": { + "X2": [ + { + "Parachain": 2032, + }, + { + "PalletInstance": 10, + }, + ], + }, + "parents": 1, + }, + }, + }, + ], + }, + 0, + "Unlimited", +] +`; + exports[`polkadotXcm limitedReserveWithdrawAssets x2 should be correct config 1`] = ` ExtrinsicConfig { "func": "limitedReserveWithdrawAssets", diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts index 1b8698db..62dab60e 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts @@ -1,4 +1,7 @@ -import { buildParamsMock } from '../../../../fixtures'; +import { + buildParachainParamsMock, + buildParamsMock, +} from '../../../../fixtures'; import { polkadotXcm } from './polkadotXcm'; describe('polkadotXcm', () => { @@ -47,6 +50,21 @@ describe('polkadotXcm', () => { expect(extrinsic.getArgs()).toMatchSnapshot(); }); }); + + describe('parachain', () => { + const extrinsic = polkadotXcm() + .limitedReserveTransferAssets() + .X2() + .build(buildParachainParamsMock); + + it('should be correct config', () => { + expect(extrinsic).toMatchSnapshot(); + }); + + it('should get correct arguments', () => { + expect(extrinsic.getArgs()).toMatchSnapshot(); + }); + }); }); describe('limitedReserveWithdrawAssets', () => { @@ -64,5 +82,20 @@ describe('polkadotXcm', () => { expect(extrinsic.getArgs()).toMatchSnapshot(); }); }); + + describe('parachain', () => { + const extrinsic = polkadotXcm() + .limitedReserveWithdrawAssets() + .X2() + .build(buildParachainParamsMock); + + it('should be correct config', () => { + expect(extrinsic).toMatchSnapshot(); + }); + + it('should get correct arguments', () => { + expect(extrinsic.getArgs()).toMatchSnapshot(); + }); + }); }); }); diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.util.ts b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.util.ts index c592ccd7..e73107d1 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.util.ts +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.util.ts @@ -4,7 +4,10 @@ import { ExtrinsicConfigBuilderPrams, Parents, } from '../../ExtrinsicBuilder.interfaces'; -import { getExtrinsicArgumentVersion } from '../../ExtrinsicBuilder.utils'; +import { + getExtrinsicAccount, + getExtrinsicArgumentVersion, +} from '../../ExtrinsicBuilder.utils'; export interface GetExtrinsicParams extends ExtrinsicConfigBuilderPrams { asset: any; @@ -37,12 +40,7 @@ export function getPolkadotXcmExtrinsicArgs({ [version]: { parents: 0, interior: { - X1: { - AccountKey20: { - network: 'Any', - key: address, - }, - }, + X1: getExtrinsicAccount(address), }, }, }, diff --git a/packages/builder/src/extrinsic/pallets/xTokens/__snapshots__/xTokens.test.ts.snap b/packages/builder/src/extrinsic/pallets/xTokens/__snapshots__/xTokens.test.ts.snap index d9b1304e..905be276 100644 --- a/packages/builder/src/extrinsic/pallets/xTokens/__snapshots__/xTokens.test.ts.snap +++ b/packages/builder/src/extrinsic/pallets/xTokens/__snapshots__/xTokens.test.ts.snap @@ -35,6 +35,61 @@ exports[`xTokens transfer should get correct arguments 1`] = ` ] `; +exports[`xTokens transferMultiAsset parachain should be correct config 1`] = ` +ExtrinsicConfig { + "func": "transferMultiasset", + "getArgs": [Function], + "module": "xTokens", + "type": "Substrate", +} +`; + +exports[`xTokens transferMultiAsset parachain should get correct arguments 1`] = ` +[ + { + "V1": { + "fun": { + "Fungible": 99000000000n, + }, + "id": { + "Concrete": { + "interior": { + "X2": [ + { + "Parachain": 100, + }, + { + "GeneralKey": "USDT", + }, + ], + }, + "parents": 1, + }, + }, + }, + }, + { + "V1": { + "interior": { + "X2": [ + { + "Parachain": 2032, + }, + { + "AccountId32": { + "id": "0x18e6c7ad45fbab18778710642072fdd057470b76d4d568b44dea6accd5b0c423", + "network": null, + }, + }, + ], + }, + "parents": 1, + }, + }, + 1000000000, +] +`; + exports[`xTokens transferMultiAsset x1 should be correct config 1`] = ` ExtrinsicConfig { "func": "transferMultiasset", @@ -140,7 +195,51 @@ exports[`xTokens transferMultiAsset x2 should get correct arguments 1`] = ` ] `; -exports[`xTokens transferMultiCurrencies should be correct config 1`] = ` +exports[`xTokens transferMultiCurrencies parachain should be correct config 1`] = ` +ExtrinsicConfig { + "func": "transferMulticurrencies", + "getArgs": [Function], + "module": "xTokens", + "type": "Substrate", +} +`; + +exports[`xTokens transferMultiCurrencies parachain should get correct arguments 1`] = ` +[ + [ + [ + "USDT", + 99000000000n, + ], + [ + "RMRK", + 5000000000n, + ], + ], + 1, + { + "V3": { + "interior": { + "X2": [ + { + "Parachain": 2032, + }, + { + "AccountId32": { + "id": "0x18e6c7ad45fbab18778710642072fdd057470b76d4d568b44dea6accd5b0c423", + "network": null, + }, + }, + ], + }, + "parents": 1, + }, + }, + "Unlimited", +] +`; + +exports[`xTokens transferMultiCurrencies x2 should be correct config 1`] = ` ExtrinsicConfig { "func": "transferMulticurrencies", "getArgs": [Function], @@ -149,7 +248,7 @@ ExtrinsicConfig { } `; -exports[`xTokens transferMultiCurrencies should get correct arguments 1`] = ` +exports[`xTokens transferMultiCurrencies x2 should get correct arguments 1`] = ` [ [ [ @@ -172,6 +271,7 @@ exports[`xTokens transferMultiCurrencies should get correct arguments 1`] = ` { "AccountKey20": { "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + "network": "Any", }, }, ], diff --git a/packages/builder/src/extrinsic/pallets/xTokens/xTokens.test.ts b/packages/builder/src/extrinsic/pallets/xTokens/xTokens.test.ts index dfa992e2..0b468147 100644 --- a/packages/builder/src/extrinsic/pallets/xTokens/xTokens.test.ts +++ b/packages/builder/src/extrinsic/pallets/xTokens/xTokens.test.ts @@ -1,4 +1,7 @@ -import { buildParamsMock } from '../../../../fixtures'; +import { + buildParachainParamsMock, + buildParamsMock, +} from '../../../../fixtures'; import { xTokens } from './xTokens'; describe('xTokens', () => { @@ -39,6 +42,20 @@ describe('xTokens', () => { expect(extrinsic).toMatchSnapshot(); }); + it('should get correct arguments', () => { + expect(extrinsic.getArgs()).toMatchSnapshot(); + }); + }); + describe('parachain', () => { + const extrinsic = xTokens() + .transferMultiAsset(100) + .X2() + .build(buildParachainParamsMock); + + it('should be correct config', () => { + expect(extrinsic).toMatchSnapshot(); + }); + it('should get correct arguments', () => { expect(extrinsic.getArgs()).toMatchSnapshot(); }); @@ -46,16 +63,32 @@ describe('xTokens', () => { }); describe('transferMultiCurrencies', () => { - const extrinsic = xTokens() - .transferMultiCurrencies() - .build(buildParamsMock); + describe('x2', () => { + const extrinsic = xTokens() + .transferMultiCurrencies() + .build(buildParamsMock); - it('should be correct config', () => { - expect(extrinsic).toMatchSnapshot(); + it('should be correct config', () => { + expect(extrinsic).toMatchSnapshot(); + }); + + it('should get correct arguments', () => { + expect(extrinsic.getArgs()).toMatchSnapshot(); + }); }); - it('should get correct arguments', () => { - expect(extrinsic.getArgs()).toMatchSnapshot(); + describe('parachain', () => { + const extrinsic = xTokens() + .transferMultiCurrencies() + .build(buildParachainParamsMock); + + it('should be correct config', () => { + expect(extrinsic).toMatchSnapshot(); + }); + + it('should get correct arguments', () => { + expect(extrinsic.getArgs()).toMatchSnapshot(); + }); }); }); }); diff --git a/packages/builder/src/extrinsic/pallets/xTokens/xTokens.ts b/packages/builder/src/extrinsic/pallets/xTokens/xTokens.ts index 5df50db0..a5eca27d 100644 --- a/packages/builder/src/extrinsic/pallets/xTokens/xTokens.ts +++ b/packages/builder/src/extrinsic/pallets/xTokens/xTokens.ts @@ -3,7 +3,10 @@ import { ExtrinsicConfigBuilder, XcmVersion, } from '../../ExtrinsicBuilder.interfaces'; -import { getExtrinsicArgumentVersion } from '../../ExtrinsicBuilder.utils'; +import { + getExtrinsicAccount, + getExtrinsicArgumentVersion, +} from '../../ExtrinsicBuilder.utils'; import { ExtrinsicConfig } from '../../ExtrinsicConfig'; import { getWeight } from './xTokens.utils'; @@ -30,12 +33,7 @@ export function xTokens() { { Parachain: destination.parachainId, }, - { - AccountKey20: { - network: 'Any', - key: address, - }, - }, + getExtrinsicAccount(address), ], }, }, @@ -83,12 +81,7 @@ export function xTokens() { { Parachain: destination.parachainId, }, - { - AccountKey20: { - network: 'Any', - key: address, - }, - }, + getExtrinsicAccount(address), ], }, }, @@ -137,12 +130,7 @@ export function xTokens() { { Parachain: destination.parachainId, }, - { - AccountKey20: { - network: 'Any', - key: address, - }, - }, + getExtrinsicAccount(address), ], }, }, @@ -173,11 +161,7 @@ export function xTokens() { { Parachain: destination.parachainId, }, - { - AccountKey20: { - key: address, - }, - }, + getExtrinsicAccount(address), ], }, }, diff --git a/packages/builder/src/extrinsic/pallets/xTransfer/__snapshots__/xTransfer.test.ts.snap b/packages/builder/src/extrinsic/pallets/xTransfer/__snapshots__/xTransfer.test.ts.snap index 8fd88dfb..7b4367ed 100644 --- a/packages/builder/src/extrinsic/pallets/xTransfer/__snapshots__/xTransfer.test.ts.snap +++ b/packages/builder/src/extrinsic/pallets/xTransfer/__snapshots__/xTransfer.test.ts.snap @@ -31,6 +31,61 @@ exports[`xTransfer transfer here should get correct arguments 1`] = ` { "AccountKey20": { "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + "network": "Any", + }, + }, + ], + }, + "parents": 1, + }, + { + "proofSize": 0, + "refTime": 5000000000, + }, +] +`; + +exports[`xTransfer transfer parachain should be correct config 1`] = ` +ExtrinsicConfig { + "func": "transfer", + "getArgs": [Function], + "module": "xTransfer", + "type": "Substrate", +} +`; + +exports[`xTransfer transfer parachain should get correct arguments 1`] = ` +[ + { + "fun": { + "Fungible": 99000000000n, + }, + "id": { + "Concrete": { + "interior": { + "X2": [ + { + "Parachain": 2032, + }, + { + "PalletInstance": 10, + }, + ], + }, + "parents": 1, + }, + }, + }, + { + "interior": { + "X2": [ + { + "Parachain": 2032, + }, + { + "AccountId32": { + "id": "0x18e6c7ad45fbab18778710642072fdd057470b76d4d568b44dea6accd5b0c423", + "network": null, }, }, ], @@ -84,6 +139,7 @@ exports[`xTransfer transfer x2 should get correct arguments 1`] = ` { "AccountKey20": { "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + "network": "Any", }, }, ], diff --git a/packages/builder/src/extrinsic/pallets/xTransfer/xTransfer.test.ts b/packages/builder/src/extrinsic/pallets/xTransfer/xTransfer.test.ts index 65e782c0..9222cbfa 100644 --- a/packages/builder/src/extrinsic/pallets/xTransfer/xTransfer.test.ts +++ b/packages/builder/src/extrinsic/pallets/xTransfer/xTransfer.test.ts @@ -1,4 +1,7 @@ -import { buildParamsMock } from '../../../../fixtures'; +import { + buildParachainParamsMock, + buildParamsMock, +} from '../../../../fixtures'; import { xTransfer } from './xTransfer'; describe('xTransfer', () => { @@ -26,5 +29,20 @@ describe('xTransfer', () => { expect(extrinsic.getArgs()).toMatchSnapshot(); }); }); + + describe('parachain', () => { + const extrinsic = xTransfer() + .transfer() + .X2() + .build(buildParachainParamsMock); + + it('should be correct config', () => { + expect(extrinsic).toMatchSnapshot(); + }); + + it('should get correct arguments', () => { + expect(extrinsic.getArgs()).toMatchSnapshot(); + }); + }); }); }); diff --git a/packages/builder/src/extrinsic/pallets/xTransfer/xTransfer.ts b/packages/builder/src/extrinsic/pallets/xTransfer/xTransfer.ts index 0b7e8fb5..094b88bf 100644 --- a/packages/builder/src/extrinsic/pallets/xTransfer/xTransfer.ts +++ b/packages/builder/src/extrinsic/pallets/xTransfer/xTransfer.ts @@ -1,5 +1,6 @@ /* eslint-disable sort-keys */ import { ExtrinsicConfigBuilder } from '../../ExtrinsicBuilder.interfaces'; +import { getExtrinsicAccount } from '../../ExtrinsicBuilder.utils'; import { ExtrinsicConfig } from '../../ExtrinsicConfig'; const pallet = 'xTransfer'; @@ -34,11 +35,7 @@ export function xTransfer() { { Parachain: destination.parachainId, }, - { - AccountKey20: { - key: address, - }, - }, + getExtrinsicAccount(address), ], }, }, @@ -82,11 +79,7 @@ export function xTransfer() { { Parachain: destination.parachainId, }, - { - AccountKey20: { - key: address, - }, - }, + getExtrinsicAccount(address), ], }, },