Skip to content

Commit

Permalink
Merge branch 'v3-next' into add-export-check
Browse files Browse the repository at this point in the history
  • Loading branch information
Rihyx committed Nov 25, 2024
2 parents 5704f5b + 610d37b commit bd97316
Show file tree
Hide file tree
Showing 27 changed files with 1,309 additions and 967 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"biomejs",
"bncs",
"composablenodes",
"concensus",
"crustnetwork",
"darwinia",
"darwiniacrab",
Expand All @@ -21,6 +22,7 @@
"foucoco",
"ftmwh",
"fullnode",
"globalconsensus",
"heiko",
"helikon",
"hydradx",
Expand Down Expand Up @@ -90,6 +92,9 @@
"vmovr",
"wagmi",
"wftm",
"wbtce",
"wethe",
"wstethe",
"wifd",
"xfer",
"xtokens"
Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
"changeset:publish": "pnpm run build && pnpm publish -r"
},
"dependencies": {
"@polkadot/api": "^12.4.2",
"@polkadot/api-augment": "^12.4.2",
"@polkadot/apps-config": "^0.143.2",
"@polkadot/types": "^12.4.2",
"@polkadot/util": "^13.1.1",
"@polkadot/util-crypto": "^13.1.1",
"@polkadot/api": "14.3.1",
"@polkadot/api-augment": "14.3.1",
"@polkadot/apps-config": "0.146.1",
"@polkadot/types": "14.3.1",
"@polkadot/util": "13.2.3",
"@polkadot/util-crypto": "13.2.3",
"@wormhole-foundation/sdk-connect": "^0.10.7",
"@wormhole-foundation/sdk-evm": "^0.10.7",
"@wormhole-foundation/sdk-evm-tokenbridge": "^0.10.7"
Expand All @@ -66,5 +66,8 @@
"typescript": "^5.6.3",
"viem": "^2.21.7",
"vitest": "^2.1.3"
},
"overrides": {
"cross-spawn": "^7.0.5"
}
}
18 changes: 18 additions & 0 deletions packages/builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions packages/builder/fixtures/builderParamsMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
12 changes: 6 additions & 6 deletions packages/builder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moonbeam-network/xcm-builder",
"version": "2.5.4",
"version": "2.6.0",
"description": "Moonbeam XCM builder",
"scripts": {
"build": "tsup",
Expand Down Expand Up @@ -38,11 +38,11 @@
"big.js": "^6.2.1"
},
"peerDependencies": {
"@polkadot/api": "^12.4.2",
"@polkadot/api-augment": "^12.4.2",
"@polkadot/types": "^12.4.2",
"@polkadot/util": "^13.1.1",
"@polkadot/util-crypto": "^13.1.1",
"@polkadot/api": "14.3.1",
"@polkadot/api-augment": "14.3.1",
"@polkadot/types": "14.3.1",
"@polkadot/util": "13.2.3",
"@polkadot/util-crypto": "13.2.3",
"@wormhole-foundation/sdk-connect": "^0.10.7",
"@wormhole-foundation/sdk-evm": "^0.10.7",
"viem": "^2.21.7"
Expand Down
23 changes: 23 additions & 0 deletions packages/builder/src/asset-min/AssetMinBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
});
35 changes: 35 additions & 0 deletions packages/builder/src/asset-min/AssetMinBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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';

export function AssetMinBuilder() {
return {
assetRegistry,
assets,
foreignAssets,
};
}

Expand Down Expand Up @@ -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<PalletAssetsAssetDetails>,
): Promise<bigint> =>
response.unwrapOrDefault().minBalance.toBigInt(),
});
},
}),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
"<ASSET>",
],
"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": [
"<ASSET>",
],
"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": [
"<ASSET>",
],
"func": "asset",
"module": "assets",
"transform": [Function],
"type": "Substrate",
}
`;

exports[`assetMinBuilder assets asset should transform correctly 1`] = `999n`;
25 changes: 25 additions & 0 deletions packages/builder/src/balance/BalanceBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
29 changes: 29 additions & 0 deletions packages/builder/src/balance/BalanceBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -62,6 +63,7 @@ function native(): BalanceConfigBuilder {
export function substrate() {
return {
assets,
foreignAssets,
system,
tokens,
};
Expand All @@ -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<PalletAssetsAssetAccount>,
): Promise<bigint> => response.unwrapOrDefault().balance.toBigInt(),
});
},
}),
};
}

function system() {
return {
account: (): BalanceConfigBuilder => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
"<ACCOUNT>",
],
"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": [
Expand Down
Loading

0 comments on commit bd97316

Please sign in to comment.