diff --git a/.vscode/settings.json b/.vscode/settings.json index 923367e4..60ab47b6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,6 +12,7 @@ "biomejs", "bncs", "composablenodes", + "concensus", "crustnetwork", "darwinia", "darwiniacrab", @@ -21,6 +22,7 @@ "foucoco", "ftmwh", "fullnode", + "globalconsensus", "heiko", "helikon", "hydradx", @@ -90,6 +92,9 @@ "vmovr", "wagmi", "wftm", + "wbtce", + "wethe", + "wstethe", "wifd", "xfer", "xtokens" diff --git a/package.json b/package.json index f964f356..5eb08845 100644 --- a/package.json +++ b/package.json @@ -64,5 +64,8 @@ "typescript": "^5.6.3", "viem": "^2.21.7", "vitest": "^2.1.3" + }, + "overrides": { + "cross-spawn": "^7.0.5" } } diff --git a/packages/builder/CHANGELOG.md b/packages/builder/CHANGELOG.md index bbbe3026..42d4a0c1 100644 --- a/packages/builder/CHANGELOG.md +++ b/packages/builder/CHANGELOG.md @@ -1,5 +1,23 @@ # @moonbeam-network/xcm-builder +## 2.6.0 + +### Minor Changes + +- [#383](https://github.com/moonbeam-foundation/xcm-sdk/pull/383) [`5d3e8b4`](https://github.com/moonbeam-foundation/xcm-sdk/commit/5d3e8b470fb9c5640ba3d27c6140e2ff09fc897d) Thanks [@mmaurello](https://github.com/mmaurello)! - Add foreign assets configuration and Snowbridge assets tranfers between Asset Hub and Moonbeam + +## 2.5.5 + +### Patch Changes + +- [#390](https://github.com/moonbeam-foundation/xcm-sdk/pull/390) [`2790340`](https://github.com/moonbeam-foundation/xcm-sdk/commit/2790340bb8ea0edda13765875d91a3a5d993a072) Thanks [@dependabot](https://github.com/apps/dependabot)! - Fix vulnerability + +- [#393](https://github.com/moonbeam-foundation/xcm-sdk/pull/393) [`1546937`](https://github.com/moonbeam-foundation/xcm-sdk/commit/1546937e5636cb6e225a06a8e41c6e6593413c42) Thanks [@Rihyx](https://github.com/Rihyx)! - fix cross-spawn vulnerability + +- Updated dependencies [[`2790340`](https://github.com/moonbeam-foundation/xcm-sdk/commit/2790340bb8ea0edda13765875d91a3a5d993a072), [`1546937`](https://github.com/moonbeam-foundation/xcm-sdk/commit/1546937e5636cb6e225a06a8e41c6e6593413c42)]: + - @moonbeam-network/xcm-types@2.5.3 + - @moonbeam-network/xcm-utils@2.2.3 + ## 2.5.4 ### Patch Changes diff --git a/packages/builder/fixtures/builderParamsMock.ts b/packages/builder/fixtures/builderParamsMock.ts index 4b14992e..05dadba2 100644 --- a/packages/builder/fixtures/builderParamsMock.ts +++ b/packages/builder/fixtures/builderParamsMock.ts @@ -216,3 +216,14 @@ export const wormholeToMoonchainConfigBuilderParams: MrlBuilderParams = { sourceAddress: '0xeF46c7649270C912704fB09B75097f6E32208b85', sourceApi: apiMock, }; + +export const buildParamsMockEth: ExtrinsicConfigBuilderPrams = { + address: '0xeF46c7649270C912704fB09B75097f6E32208b85', + amount: 99_000_000_000n, + asset: '0xeF46c7649270C912704fB09B75097f6E32208b85', + destination: moonbaseAlphaMock, + fee: 5_000_000_000n, + feeAsset: 'WETH.e', + palletInstance: 10, + source: alphanetAssetHubMock, +}; diff --git a/packages/builder/package.json b/packages/builder/package.json index 4bfc862d..68908689 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -1,6 +1,6 @@ { "name": "@moonbeam-network/xcm-builder", - "version": "2.5.4", + "version": "2.6.0", "description": "Moonbeam XCM builder", "scripts": { "build": "tsup", diff --git a/packages/builder/src/asset-min/AssetMinBuilder.test.ts b/packages/builder/src/asset-min/AssetMinBuilder.test.ts index bfea8c51..5d251ffb 100644 --- a/packages/builder/src/asset-min/AssetMinBuilder.test.ts +++ b/packages/builder/src/asset-min/AssetMinBuilder.test.ts @@ -77,4 +77,27 @@ describe('assetMinBuilder', () => { }); }); }); + + describe('foreignAssets', () => { + describe('asset', () => { + const config = AssetMinBuilder() + .foreignAssets() + .asset() + .build({ asset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' }); + + it('should be correct config', () => { + expect(config).toMatchSnapshot(); + }); + + it('should transform correctly', async () => { + await expect( + config.transform({ + unwrapOrDefault: () => ({ + minBalance: balanceOf(999), + }), + }), + ).resolves.toMatchSnapshot(); + }); + }); + }); }); diff --git a/packages/builder/src/asset-min/AssetMinBuilder.ts b/packages/builder/src/asset-min/AssetMinBuilder.ts index 48bd13b8..7bffe740 100644 --- a/packages/builder/src/asset-min/AssetMinBuilder.ts +++ b/packages/builder/src/asset-min/AssetMinBuilder.ts @@ -1,5 +1,6 @@ import type { Option } from '@polkadot/types'; import type { PalletAssetsAssetDetails } from '@polkadot/types/lookup'; +import { getExtrinsicAccount } from '../extrinsic/ExtrinsicBuilder.utils'; import { SubstrateQueryConfig } from '../types/substrate/SubstrateQueryConfig'; import type { AssetMinConfigBuilder } from './AssetMinBuilder.interfaces'; @@ -7,6 +8,7 @@ export function AssetMinBuilder() { return { assetRegistry, assets, + foreignAssets, }; } @@ -54,3 +56,36 @@ function assets() { }), }; } + +function foreignAssets() { + return { + asset: (): AssetMinConfigBuilder => ({ + build: ({ asset }) => { + const multilocation = { + parents: 2, + interior: { + X2: [ + { + globalconsensus: { + ethereum: { + chainId: 1, + }, + }, + }, + getExtrinsicAccount(asset as string), + ], + }, + }; + return new SubstrateQueryConfig({ + module: 'foreignAssets', + func: 'asset', + args: [multilocation], + transform: async ( + response: Option, + ): Promise => + response.unwrapOrDefault().minBalance.toBigInt(), + }); + }, + }), + }; +} diff --git a/packages/builder/src/asset-min/__snapshots__/AssetMinBuilder.test.ts.snap b/packages/builder/src/asset-min/__snapshots__/AssetMinBuilder.test.ts.snap index fee3549c..f667eb77 100644 --- a/packages/builder/src/asset-min/__snapshots__/AssetMinBuilder.test.ts.snap +++ b/packages/builder/src/asset-min/__snapshots__/AssetMinBuilder.test.ts.snap @@ -38,3 +38,77 @@ SubstrateQueryConfig { `; exports[`assetMinBuilder > assets > asset > should transform correctly 1`] = `999n`; + +exports[`assetMinBuilder > foreignAssets > asset > should be correct config 1`] = ` +SubstrateQueryConfig { + "args": [ + { + "interior": { + "X2": [ + { + "globalconsensus": { + "ethereum": { + "chainId": 1, + }, + }, + }, + { + "AccountKey20": { + "key": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", + }, + }, + ], + }, + "parents": 2, + }, + ], + "func": "asset", + "module": "foreignAssets", + "transform": [Function], + "type": "Substrate", +} +`; + +exports[`assetMinBuilder > foreignAssets > asset > should transform correctly 1`] = `999n`; + +exports[`assetMinBuilder assetRegistry assetMetadatas should be correct config 1`] = ` +SubstrateQueryConfig { + "args": [ + "", + ], + "func": "assetMetadatas", + "module": "assetRegistry", + "transform": [Function], + "type": "Substrate", +} +`; + +exports[`assetMinBuilder assetRegistry assetMetadatas should transform correctly 1`] = `999n`; + +exports[`assetMinBuilder assetRegistry currencyMetadatas should be correct config 1`] = ` +SubstrateQueryConfig { + "args": [ + "", + ], + "func": "currencyMetadatas", + "module": "assetRegistry", + "transform": [Function], + "type": "Substrate", +} +`; + +exports[`assetMinBuilder assetRegistry currencyMetadatas should transform correctly 1`] = `999n`; + +exports[`assetMinBuilder assets asset should be correct config 1`] = ` +SubstrateQueryConfig { + "args": [ + "", + ], + "func": "asset", + "module": "assets", + "transform": [Function], + "type": "Substrate", +} +`; + +exports[`assetMinBuilder assets asset should transform correctly 1`] = `999n`; diff --git a/packages/builder/src/balance/BalanceBuilder.test.ts b/packages/builder/src/balance/BalanceBuilder.test.ts index 0b73e4f0..0bd9c80b 100644 --- a/packages/builder/src/balance/BalanceBuilder.test.ts +++ b/packages/builder/src/balance/BalanceBuilder.test.ts @@ -47,6 +47,31 @@ describe('balanceBuilder', () => { }); }); + describe('foreignAssets', () => { + describe('account', () => { + const config = BalanceBuilder() + .substrate() + .foreignAssets() + .account() + .build({ + address, + asset, + }) as SubstrateQueryConfig; + + it('should be correct config', () => { + expect(config).toMatchSnapshot(); + }); + + it('should transform correctly', async () => { + await expect( + config.transform({ + unwrapOrDefault: () => ({ balance: balanceOf(999) }), + }), + ).resolves.toMatchSnapshot(); + }); + }); + }); + describe('system', () => { describe('account', () => { const config = BalanceBuilder() diff --git a/packages/builder/src/balance/BalanceBuilder.ts b/packages/builder/src/balance/BalanceBuilder.ts index ff05f805..30be6b2e 100644 --- a/packages/builder/src/balance/BalanceBuilder.ts +++ b/packages/builder/src/balance/BalanceBuilder.ts @@ -7,6 +7,7 @@ import type { import { evmToAddress } from '@polkadot/util-crypto'; import type { Address } from 'viem'; import { ContractConfig } from '../contract'; +import { getExtrinsicAccount } from '../extrinsic/ExtrinsicBuilder.utils'; import { EvmQueryConfig } from '../types/evm/EvmQueryConfig'; import { SubstrateQueryConfig } from '../types/substrate/SubstrateQueryConfig'; import type { @@ -62,6 +63,7 @@ function native(): BalanceConfigBuilder { export function substrate() { return { assets, + foreignAssets, system, tokens, }; @@ -83,6 +85,33 @@ function assets() { }; } +function foreignAssets() { + return { + account: (): BalanceConfigBuilder => ({ + build: ({ address, asset }) => { + const multilocation = { + parents: 2, + interior: { + X2: [ + { GlobalConsensus: { ethereum: { chainId: 1 } } }, + getExtrinsicAccount(asset.address as string), // TODO mjm fix + ], + }, + }; + + return new SubstrateQueryConfig({ + module: 'foreignAssets', + func: 'account', + args: [multilocation, address], + transform: async ( + response: Option, + ): Promise => response.unwrapOrDefault().balance.toBigInt(), + }); + }, + }), + }; +} + function system() { return { account: (): BalanceConfigBuilder => ({ diff --git a/packages/builder/src/balance/__snapshots__/BalanceBuilder.test.ts.snap b/packages/builder/src/balance/__snapshots__/BalanceBuilder.test.ts.snap index ec2300ed..aae0ecde 100644 --- a/packages/builder/src/balance/__snapshots__/BalanceBuilder.test.ts.snap +++ b/packages/builder/src/balance/__snapshots__/BalanceBuilder.test.ts.snap @@ -14,6 +14,39 @@ SubstrateQueryConfig { exports[`balanceBuilder > assets > account > should transform correctly 1`] = `999n`; +exports[`balanceBuilder > foreignAssets > account > should be correct config 1`] = ` +SubstrateQueryConfig { + "args": [ + { + "interior": { + "X2": [ + { + "GlobalConsensus": { + "ethereum": { + "chainId": 1, + }, + }, + }, + { + "AccountKey20": { + "key": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", + }, + }, + ], + }, + "parents": 2, + }, + "", + ], + "func": "account", + "module": "foreignAssets", + "transform": [Function], + "type": "Substrate", +} +`; + +exports[`balanceBuilder > foreignAssets > account > should transform correctly 1`] = `999n`; + exports[`balanceBuilder > system > account > should be correct config 1`] = ` SubstrateQueryConfig { "args": [ 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 9e217f1f..7f17342b 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 @@ -454,3 +454,568 @@ exports[`polkadotXcm > limitedReserveWithdrawAssets > x2 > should get correct ar "Unlimited", ] `; + +exports[`polkadotXcm > transferAssetsUsingTypeAndThen > x2 > should be correct config 1`] = ` +ExtrinsicConfig { + "func": "transferAssetsUsingTypeAndThen", + "getArgs": [Function], + "module": "polkadotXcm", + "type": "Substrate", +} +`; + +exports[`polkadotXcm > transferAssetsUsingTypeAndThen > x2 > should get correct arguments 1`] = ` +[ + { + "V4": { + "interior": { + "X1": [ + { + "Parachain": 1000, + }, + ], + }, + "parents": 1, + }, + }, + { + "V4": [ + { + "fun": { + "fungible": 99000000000n, + }, + "id": { + "interior": { + "X2": [ + { + "globalConsensus": { + "Ethereum": { + "ChainId": 1, + }, + }, + }, + { + "AccountKey20": { + "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + }, + }, + ], + }, + "parents": 2, + }, + }, + ], + }, + "LocalReserve", + { + "V4": { + "interior": { + "X2": [ + { + "globalConsensus": { + "Ethereum": { + "ChainId": 1, + }, + }, + }, + { + "AccountKey20": { + "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + }, + }, + ], + }, + "parents": 2, + }, + }, + "LocalReserve", + { + "V4": [ + { + "DepositAsset": { + "assets": { + "Wild": { + "AllCounted": 1, + }, + }, + "beneficiary": { + "interior": { + "X1": [ + { + "AccountKey20": { + "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + }, + }, + ], + }, + "parents": 0, + }, + }, + }, + ], + }, + "Unlimited", +] +`; + +exports[`polkadotXcm limitedReserveTransferAssets here should be correct config 1`] = ` +ExtrinsicConfig { + "func": "limitedReserveTransferAssets", + "getArgs": [Function], + "module": "polkadotXcm", + "type": "Substrate", +} +`; + +exports[`polkadotXcm limitedReserveTransferAssets here should get correct arguments 1`] = ` +[ + { + "V1": { + "interior": { + "X1": { + "Parachain": 1000, + }, + }, + "parents": 1, + }, + }, + { + "V1": { + "interior": { + "X1": { + "AccountKey20": { + "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + }, + }, + }, + "parents": 0, + }, + }, + { + "V1": [ + { + "fun": { + "Fungible": 99000000000n, + }, + "id": { + "Concrete": { + "interior": "Here", + "parents": 0, + }, + }, + }, + ], + }, + 0, + "Unlimited", +] +`; + +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, + }, + }, + }, + { + "fun": { + "Fungible": 5000000000n, + }, + "id": { + "Concrete": { + "interior": { + "X2": [ + { + "PalletInstance": 10, + }, + { + "GeneralIndex": "RMRK", + }, + ], + }, + "parents": 0, + }, + }, + }, + ], + }, + 1, + "Unlimited", +] +`; + +exports[`polkadotXcm limitedReserveTransferAssets x1 should be correct config 1`] = ` +ExtrinsicConfig { + "func": "limitedReserveTransferAssets", + "getArgs": [Function], + "module": "polkadotXcm", + "type": "Substrate", +} +`; + +exports[`polkadotXcm limitedReserveTransferAssets x1 should get correct arguments 1`] = ` +[ + { + "V1": { + "interior": { + "X1": { + "Parachain": 1000, + }, + }, + "parents": 1, + }, + }, + { + "V1": { + "interior": { + "X1": { + "AccountKey20": { + "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + }, + }, + }, + "parents": 0, + }, + }, + { + "V1": [ + { + "fun": { + "Fungible": 99000000000n, + }, + "id": { + "Concrete": { + "interior": { + "X1": { + "PalletInstance": 10, + }, + }, + "parents": 0, + }, + }, + }, + ], + }, + 0, + "Unlimited", +] +`; + +exports[`polkadotXcm limitedReserveTransferAssets x2 different assets should be correct config 1`] = ` +ExtrinsicConfig { + "func": "limitedReserveTransferAssets", + "getArgs": [Function], + "module": "polkadotXcm", + "type": "Substrate", +} +`; + +exports[`polkadotXcm limitedReserveTransferAssets x2 different assets should get correct arguments 1`] = ` +[ + { + "V1": { + "interior": { + "X1": { + "Parachain": 1000, + }, + }, + "parents": 1, + }, + }, + { + "V1": { + "interior": { + "X1": { + "AccountKey20": { + "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + }, + }, + }, + "parents": 0, + }, + }, + { + "V1": [ + { + "fun": { + "Fungible": 99000000000n, + }, + "id": { + "Concrete": { + "interior": { + "X2": [ + { + "PalletInstance": 10, + }, + { + "GeneralIndex": "USDT", + }, + ], + }, + "parents": 0, + }, + }, + }, + { + "fun": { + "Fungible": 5000000000n, + }, + "id": { + "Concrete": { + "interior": { + "X2": [ + { + "PalletInstance": 10, + }, + { + "GeneralIndex": "RMRK", + }, + ], + }, + "parents": 0, + }, + }, + }, + ], + }, + 1, + "Unlimited", +] +`; + +exports[`polkadotXcm limitedReserveTransferAssets x2 the same asset should be correct config 1`] = ` +ExtrinsicConfig { + "func": "limitedReserveTransferAssets", + "getArgs": [Function], + "module": "polkadotXcm", + "type": "Substrate", +} +`; + +exports[`polkadotXcm limitedReserveTransferAssets x2 the same asset should get correct arguments 1`] = ` +[ + { + "V1": { + "interior": { + "X1": { + "Parachain": 1000, + }, + }, + "parents": 1, + }, + }, + { + "V1": { + "interior": { + "X1": { + "AccountKey20": { + "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + }, + }, + }, + "parents": 0, + }, + }, + { + "V1": [ + { + "fun": { + "Fungible": 99000000000n, + }, + "id": { + "Concrete": { + "interior": { + "X2": [ + { + "PalletInstance": 10, + }, + { + "GeneralIndex": "USDT", + }, + ], + }, + "parents": 0, + }, + }, + }, + ], + }, + 0, + "Unlimited", +] +`; + +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", + "getArgs": [Function], + "module": "polkadotXcm", + "type": "Substrate", +} +`; + +exports[`polkadotXcm limitedReserveWithdrawAssets x2 should get correct arguments 1`] = ` +[ + { + "V1": { + "interior": { + "X1": { + "Parachain": 1000, + }, + }, + "parents": 1, + }, + }, + { + "V1": { + "interior": { + "X1": { + "AccountKey20": { + "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + }, + }, + }, + "parents": 0, + }, + }, + { + "V1": [ + { + "fun": { + "Fungible": 99000000000n, + }, + "id": { + "Concrete": { + "interior": { + "X2": [ + { + "Parachain": 1000, + }, + { + "PalletInstance": 10, + }, + ], + }, + "parents": 1, + }, + }, + }, + ], + }, + 0, + "Unlimited", +] +`; diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts index 6a2e55e7..623fbb58 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts @@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest'; import { buildParachainParamsMock, buildParamsMock, + buildParamsMockEth, buildParamsSameAssetMock, } from '../../../../fixtures'; import { polkadotXcm } from './polkadotXcm'; @@ -118,4 +119,21 @@ describe('polkadotXcm', () => { }); }); }); + + describe('transferAssetsUsingTypeAndThen', () => { + describe('x2', () => { + const extrinsic = polkadotXcm() + .transferAssetsUsingTypeAndThen() + .globalConsensusEthereum() + .build(buildParamsMockEth); + + 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.ts b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts index 8c3f1422..73a99ecd 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts @@ -1,6 +1,8 @@ +import { XcmVersion } from '../../../../build'; import { ExtrinsicConfig } from '../../../types/substrate/ExtrinsicConfig'; import type { ExtrinsicConfigBuilder } from '../../ExtrinsicBuilder.interfaces'; import { + getExtrinsicAccount, getExtrinsicArgumentVersion, normalizeConcrete, normalizeX1, @@ -223,5 +225,88 @@ export function polkadotXcm() { }), }; }, + transferAssetsUsingTypeAndThen: () => { + const func = 'transferAssetsUsingTypeAndThen'; + return { + // TODO we could pass a parameter globalConsensus in the chain asset + // but we can do it in V3 + globalConsensusEthereum: (): ExtrinsicConfigBuilder => ({ + build: (params) => { + const version = XcmVersion.v4; + return new ExtrinsicConfig({ + module: pallet, + func, + + getArgs: () => [ + { + [version]: { + parents: 1, + interior: { + X1: [ + { + Parachain: params.destination.parachainId, + }, + ], + }, + }, + }, + { + [version]: [ + { + id: { + parents: 2, + interior: { + X2: [ + // TODO param + { globalConsensus: { Ethereum: { ChainId: 1 } } }, + getExtrinsicAccount(params.asset.address as string), + ], + }, + }, + fun: { fungible: params.asset.amount }, + }, + ], + }, + 'LocalReserve', + { + [version]: { + parents: 2, + interior: { + X2: [ + { globalConsensus: { Ethereum: { ChainId: 1 } } }, + getExtrinsicAccount(params.asset.address as string), + ], + }, + }, + }, + 'LocalReserve', + { + [version]: [ + { + DepositAsset: { + assets: { + Wild: { AllCounted: 1 }, + }, + beneficiary: { + parents: 0, + interior: { + X1: [ + getExtrinsicAccount( + params.asset.address as string, + ), + ], + }, + }, + }, + }, + ], + }, + 'Unlimited', + ], + }); + }, + }), + }; + }, }; } diff --git a/packages/config/CHANGELOG.md b/packages/config/CHANGELOG.md index 0ccfbe2f..57c97030 100644 --- a/packages/config/CHANGELOG.md +++ b/packages/config/CHANGELOG.md @@ -1,5 +1,26 @@ # @moonbeam-network/xcm-config +## 2.7.6 + +### Patch Changes + +- [#383](https://github.com/moonbeam-foundation/xcm-sdk/pull/383) [`5d3e8b4`](https://github.com/moonbeam-foundation/xcm-sdk/commit/5d3e8b470fb9c5640ba3d27c6140e2ff09fc897d) Thanks [@mmaurello](https://github.com/mmaurello)! - Add foreign assets configuration and Snowbridge assets tranfers between Asset Hub and Moonbeam + +- Updated dependencies [[`5d3e8b4`](https://github.com/moonbeam-foundation/xcm-sdk/commit/5d3e8b470fb9c5640ba3d27c6140e2ff09fc897d)]: + - @moonbeam-network/xcm-builder@2.6.0 + +## 2.7.5 + +### Patch Changes + +- [#390](https://github.com/moonbeam-foundation/xcm-sdk/pull/390) [`2790340`](https://github.com/moonbeam-foundation/xcm-sdk/commit/2790340bb8ea0edda13765875d91a3a5d993a072) Thanks [@dependabot](https://github.com/apps/dependabot)! - Fix vulnerability + +- [#393](https://github.com/moonbeam-foundation/xcm-sdk/pull/393) [`1546937`](https://github.com/moonbeam-foundation/xcm-sdk/commit/1546937e5636cb6e225a06a8e41c6e6593413c42) Thanks [@Rihyx](https://github.com/Rihyx)! - fix cross-spawn vulnerability + +- Updated dependencies [[`2790340`](https://github.com/moonbeam-foundation/xcm-sdk/commit/2790340bb8ea0edda13765875d91a3a5d993a072), [`1546937`](https://github.com/moonbeam-foundation/xcm-sdk/commit/1546937e5636cb6e225a06a8e41c6e6593413c42)]: + - @moonbeam-network/xcm-builder@2.5.5 + - @moonbeam-network/xcm-types@2.5.3 + ## 2.7.4 ### Patch Changes diff --git a/packages/config/package.json b/packages/config/package.json index 78e6d85e..568381da 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -1,6 +1,6 @@ { "name": "@moonbeam-network/xcm-config", - "version": "2.7.4", + "version": "2.7.6", "description": "All necessary configuration to transfer assets from Moonbeam, Moonriver, Moonbase to other parachains and back", "scripts": { "build": "tsup", diff --git a/packages/config/src/assets.ts b/packages/config/src/assets.ts index 958516a7..e6395c2f 100644 --- a/packages/config/src/assets.ts +++ b/packages/config/src/assets.ts @@ -390,6 +390,21 @@ export const ztg = new Asset({ originSymbol: 'ZTG', }); +export const wbtce = new Asset({ + key: 'wbtce', + originSymbol: 'WBTC.e', +}); + +export const wstethe = new Asset({ + key: 'wstethe', + originSymbol: 'wstETH.e', +}); + +export const wethe = new Asset({ + key: 'wethe', + originSymbol: 'WETH.e', +}); + export const assetsList: Asset[] = [ aca, agng, @@ -464,9 +479,12 @@ export const assetsList: Asset[] = [ vmanta, vmovr, wbtc, + wbtce, weth, + wethe, wftm, wifd, + wstethe, xrt, ztg, ]; diff --git a/packages/config/src/chains.ts b/packages/config/src/chains.ts index bcf08ec0..3fcfb5f2 100644 --- a/packages/config/src/chains.ts +++ b/packages/config/src/chains.ts @@ -79,8 +79,11 @@ import { vmanta, vmovr, wbtc, + wbtce, weth, + wethe, wifd, + wstethe, xrt, ztg, } from './assets'; @@ -1321,6 +1324,27 @@ export const moonbeam = new EvmParachain({ id: '61295607754960722617854661686514597014', }, }), + ChainAsset.fromAsset(wbtce, { + // address: '0xffffffff2e1d1ac9ea1686255befe995b31abc96', + decimals: 8, + ids: { + id: '36282181791341254438422467838694599751', + }, + }), + ChainAsset.fromAsset(wethe, { + // address: '0xffffffff2e1d1ac9ea1686255befe995b31abc96', + decimals: 18, + ids: { + id: '178794693648360392906933130845919698647', + }, + }), + ChainAsset.fromAsset(wstethe, { + // address: '0xffffffff2e1d1ac9ea1686255befe995b31abc96', + decimals: 18, + ids: { + id: '124105859028862849477017063633156007283', + }, + }), ], ecosystem: Ecosystem.Polkadot, genesisHash: @@ -2005,6 +2029,18 @@ export const polkadotAssetHub = new Parachain({ palletInstance: 50, }, }), + ChainAsset.fromAsset(wbtce, { + address: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', + decimals: 8, + }), + ChainAsset.fromAsset(wethe, { + address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', + decimals: 18, + }), + ChainAsset.fromAsset(wethe, { + address: '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0', + decimals: 18, + }), ], checkSovereignAccountBalances: true, ecosystem: Ecosystem.Polkadot, diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md index 9841d32f..3cbb7c45 100644 --- a/packages/sdk/CHANGELOG.md +++ b/packages/sdk/CHANGELOG.md @@ -1,5 +1,27 @@ # @moonbeam-network/xcm-sdk +## 2.7.6 + +### Patch Changes + +- Updated dependencies [[`5d3e8b4`](https://github.com/moonbeam-foundation/xcm-sdk/commit/5d3e8b470fb9c5640ba3d27c6140e2ff09fc897d)]: + - @moonbeam-network/xcm-builder@2.6.0 + - @moonbeam-network/xcm-config@2.7.6 + +## 2.7.5 + +### Patch Changes + +- [#390](https://github.com/moonbeam-foundation/xcm-sdk/pull/390) [`2790340`](https://github.com/moonbeam-foundation/xcm-sdk/commit/2790340bb8ea0edda13765875d91a3a5d993a072) Thanks [@dependabot](https://github.com/apps/dependabot)! - Fix vulnerability + +- [#393](https://github.com/moonbeam-foundation/xcm-sdk/pull/393) [`1546937`](https://github.com/moonbeam-foundation/xcm-sdk/commit/1546937e5636cb6e225a06a8e41c6e6593413c42) Thanks [@Rihyx](https://github.com/Rihyx)! - fix cross-spawn vulnerability + +- Updated dependencies [[`2790340`](https://github.com/moonbeam-foundation/xcm-sdk/commit/2790340bb8ea0edda13765875d91a3a5d993a072), [`1546937`](https://github.com/moonbeam-foundation/xcm-sdk/commit/1546937e5636cb6e225a06a8e41c6e6593413c42)]: + - @moonbeam-network/xcm-builder@2.5.5 + - @moonbeam-network/xcm-config@2.7.5 + - @moonbeam-network/xcm-types@2.5.3 + - @moonbeam-network/xcm-utils@2.2.3 + ## 2.7.4 ### Patch Changes diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 07fe052e..3f27cb18 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@moonbeam-network/xcm-sdk", - "version": "2.7.4", + "version": "2.7.6", "description": "The Moonbeam XCM SDK enables developers to easily deposit and withdraw assets to Moonbeam/Moonriver from the relay chain and other parachains in the Polkadot/Kusama ecosystem", "scripts": { "build": "tsup", diff --git a/packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap b/packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap index 04919784..72e42646 100644 --- a/packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap +++ b/packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap @@ -516,6 +516,27 @@ exports[`sdk > getParachainBalances > on 'Moonbeam' for address: '0x4E82143Af671 [ _AssetAmount { "address": "0xCa01a1D0993565291051daFF390892518ACfAD3A", + "amount": 0n, + "decimals": 18, + "key": "wstethe", + "originSymbol": "wstETH.e", + "symbol": "wstETH.e", + }, + r { + "amount": 0n, + "decimals": 8, + "key": "wbtce", + "originSymbol": "WBTC.e", + "symbol": "WBTC.e", + }, + r { + "amount": 0n, + "decimals": 18, + "key": "wethe", + "originSymbol": "WETH.e", + "symbol": "WETH.e", + }, + r { "amount": 0n, "decimals": 6, "ids": undefined, diff --git a/packages/types/CHANGELOG.md b/packages/types/CHANGELOG.md index 53e84712..895d0b89 100644 --- a/packages/types/CHANGELOG.md +++ b/packages/types/CHANGELOG.md @@ -1,5 +1,16 @@ # @moonbeam-network/xcm-types +## 2.5.3 + +### Patch Changes + +- [#390](https://github.com/moonbeam-foundation/xcm-sdk/pull/390) [`2790340`](https://github.com/moonbeam-foundation/xcm-sdk/commit/2790340bb8ea0edda13765875d91a3a5d993a072) Thanks [@dependabot](https://github.com/apps/dependabot)! - Fix vulnerability + +- [#393](https://github.com/moonbeam-foundation/xcm-sdk/pull/393) [`1546937`](https://github.com/moonbeam-foundation/xcm-sdk/commit/1546937e5636cb6e225a06a8e41c6e6593413c42) Thanks [@Rihyx](https://github.com/Rihyx)! - fix cross-spawn vulnerability + +- Updated dependencies [[`2790340`](https://github.com/moonbeam-foundation/xcm-sdk/commit/2790340bb8ea0edda13765875d91a3a5d993a072), [`1546937`](https://github.com/moonbeam-foundation/xcm-sdk/commit/1546937e5636cb6e225a06a8e41c6e6593413c42)]: + - @moonbeam-network/xcm-utils@2.2.3 + ## 2.5.2 ### Patch Changes diff --git a/packages/types/package.json b/packages/types/package.json index eeddfa85..6487c323 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "@moonbeam-network/xcm-types", - "version": "2.5.2", + "version": "2.5.3", "description": "Moonbeam XCM Types", "scripts": { "build": "tsup", diff --git a/packages/utils/CHANGELOG.md b/packages/utils/CHANGELOG.md index 6b3ba5d2..aa11519f 100644 --- a/packages/utils/CHANGELOG.md +++ b/packages/utils/CHANGELOG.md @@ -1,5 +1,13 @@ # @moonbeam-network/xcm-utils +## 2.2.3 + +### Patch Changes + +- [#390](https://github.com/moonbeam-foundation/xcm-sdk/pull/390) [`2790340`](https://github.com/moonbeam-foundation/xcm-sdk/commit/2790340bb8ea0edda13765875d91a3a5d993a072) Thanks [@dependabot](https://github.com/apps/dependabot)! - Fix vulnerability + +- [#393](https://github.com/moonbeam-foundation/xcm-sdk/pull/393) [`1546937`](https://github.com/moonbeam-foundation/xcm-sdk/commit/1546937e5636cb6e225a06a8e41c6e6593413c42) Thanks [@Rihyx](https://github.com/Rihyx)! - fix cross-spawn vulnerability + ## 2.2.2 ### Patch Changes diff --git a/packages/utils/package.json b/packages/utils/package.json index 97f0ef1b..f2e894ad 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@moonbeam-network/xcm-utils", - "version": "2.2.2", + "version": "2.2.3", "description": "Moonbeam XCM utilities", "scripts": { "build": "tsup",