Skip to content

Commit

Permalink
merge with main (pending adding snowbridge assets stuff)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Nov 22, 2024
2 parents ca3b12e + 3fc89fe commit 610d37b
Show file tree
Hide file tree
Showing 25 changed files with 1,066 additions and 5 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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,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,
};
2 changes: 1 addition & 1 deletion 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
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 610d37b

Please sign in to comment.