Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forgeign Assets builders - Snowbridge Assets configuration #400

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
8 changes: 4 additions & 4 deletions packages/builder/src/asset-min/AssetMinBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ describe('assetMinBuilder', () => {

describe('foreignAssets', () => {
describe('asset', () => {
const config = AssetMinBuilder()
.foreignAssets()
.asset()
.build({ asset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' });
const config = AssetMinBuilder().foreignAssets().asset().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