Skip to content

Commit

Permalink
adapt foreignAssets pallet queries and add snowbridge assets configur…
Browse files Browse the repository at this point in the history
…ations
  • Loading branch information
mmaurello committed Nov 25, 2024
1 parent 610d37b commit dcc64c5
Show file tree
Hide file tree
Showing 14 changed files with 317 additions and 636 deletions.
11 changes: 0 additions & 11 deletions packages/builder/fixtures/builderParamsMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,3 @@ 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,
};
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;
}
5 changes: 4 additions & 1 deletion packages/builder/src/asset-min/AssetMinBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ describe('assetMinBuilder', () => {
const config = AssetMinBuilder()
.foreignAssets()
.asset()
.build({ asset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' });
.build({
asset,
address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
});

it('should be correct config', () => {
expect(config).toMatchSnapshot();
Expand Down
9 changes: 7 additions & 2 deletions packages/builder/src/asset-min/AssetMinBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ function assets() {
function foreignAssets() {
return {
asset: (): AssetMinConfigBuilder => ({
build: ({ asset }) => {
build: ({ address }) => {
if (!address) {
throw new Error(
'Asset address is missing for foreignAssets.asset min calculation',
);
}
const multilocation = {
parents: 2,
interior: {
Expand All @@ -72,7 +77,7 @@ function foreignAssets() {
},
},
},
getExtrinsicAccount(asset as string),
getExtrinsicAccount(address),
],
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,50 +65,7 @@ SubstrateQueryConfig {
"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`;
8 changes: 7 additions & 1 deletion packages/builder/src/balance/BalanceBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@ 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 as string), // TODO mjm fix
getExtrinsicAccount(asset.address),
],
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@ SubstrateQueryConfig {
},
{
"AccountKey20": {
"key": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"key": "0x98891e5FD24Ef33A488A47101F65D212Ff6E650E",
},
},
],
},
"parents": 2,
},
"<ACCOUNT>",
"<ADDRESS>",
],
"func": "account",
"module": "foreignAssets",
"transform": [Function],
"type": "Substrate",
}
`;

Expand Down
Loading

0 comments on commit dcc64c5

Please sign in to comment.