Skip to content

Commit

Permalink
Merge branch 'v3-next' of github.com:moonbeam-foundation/xcm-sdk into…
Browse files Browse the repository at this point in the history
… v3-next-mrl-integration-0
  • Loading branch information
mmaurello committed Nov 25, 2024
2 parents 09cc138 + 160ef18 commit 58be9a5
Show file tree
Hide file tree
Showing 38 changed files with 1,091 additions and 993 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml → .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ jobs:
if: always()
id: spell-check
run: pnpm run spell

- name: 🚪 Run Check Exports
run: npm run lint:exports
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
17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"link": "turbo run link",
"lint": "pnpm biome check .",
"lint:fix": "pnpm biome check --write .",
"lint:exports": "ts-unused-exports tsconfig.json --excludePathsFromReport='vitest.workspace.ts;tsup.config.ts;build;examples;vitest.config;src/index.ts' --exitWithCount",
"typecheck": "turbo run typecheck",
"spell": "cspell --quiet -c cspell.config.cjs 'packages/**/src/**'",
"test": "turbo run test",
Expand All @@ -37,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 @@ -59,10 +60,14 @@
"glob": "^11.0.0",
"lefthook": "^1.7.15",
"syncpack": "^13.0.0",
"ts-unused-exports": "^10.1.0",
"tsup": "^8.3.0",
"turbo": "^2.1.3",
"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
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export type AssetMinConfigBuilder = ConfigBuilder<
>;

export interface AssetMinConfigBuilderParams {
address?: string;
asset: ChainAssetId;
}
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,
address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
});

it('should be correct config', () => {
expect(config).toMatchSnapshot();
});

it('should transform correctly', async () => {
await expect(
config.transform({
unwrapOrDefault: () => ({
minBalance: balanceOf(999),
}),
}),
).resolves.toMatchSnapshot();
});
});
});
});
40 changes: 40 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,41 @@ function assets() {
}),
};
}

function foreignAssets() {
return {
asset: (): AssetMinConfigBuilder => ({
build: ({ address }) => {
if (!address) {
throw new Error(
'Asset address is missing for foreignAssets.asset min calculation',
);
}
const multilocation = {
parents: 2,
interior: {
X2: [
{
globalconsensus: {
ethereum: {
chainId: 1,
},
},
},
getExtrinsicAccount(address),
],
},
};
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,34 @@ 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],
}
`;

exports[`assetMinBuilder > foreignAssets > 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
35 changes: 35 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,39 @@ function assets() {
};
}

function foreignAssets() {
return {
account: (): BalanceConfigBuilder => ({
build: ({ address, asset }) => {
if (!asset.address) {
throw new Error(
'Asset address is needed to calculate balance with foreignAssets.account function',
);
}

const multilocation = {
parents: 2,
interior: {
X2: [
{ GlobalConsensus: { ethereum: { chainId: 1 } } },
getExtrinsicAccount(asset.address),
],
},
};

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,38 @@ 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": "0x98891e5FD24Ef33A488A47101F65D212Ff6E650E",
},
},
],
},
"parents": 2,
},
"<ADDRESS>",
],
"func": "account",
"module": "foreignAssets",
"transform": [Function],
}
`;

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 58be9a5

Please sign in to comment.