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

fix: ChargeAssetTxPayment to work with Asset Conversion on Westend's and Kusama's Asset Hubs #5752

Merged
merged 7 commits into from
Nov 16, 2023
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
2 changes: 1 addition & 1 deletion packages/api-base/src/types/submittable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface SignerOptions {
nonce: AnyNumber | Codec;
signer?: Signer;
tip?: AnyNumber;
assetId?: AnyNumber;
assetId?: AnyNumber | object;
}

export type SubmittableDryRunResult<ApiType extends ApiTypes> =
Expand Down
2 changes: 2 additions & 0 deletions packages/types-augment/src/registry/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import '@polkadot/types/types/registry';

import type { Data, StorageKey } from '@polkadot/types';
import type { BitVec, Bool, Bytes, F32, F64, I128, I16, I256, I32, I64, I8, ISize, Json, Null, OptionBool, Raw, Text, Type, U128, U16, U256, U32, U64, U8, USize, bool, f32, f64, i128, i16, i256, i32, i64, i8, isize, u128, u16, u256, u32, u64, u8, usize } from '@polkadot/types-codec';
import type { TAssetConversion } from '@polkadot/types/interfaces/assetConversion';
import type { AssetApproval, AssetApprovalKey, AssetBalance, AssetDestroyWitness, AssetDetails, AssetMetadata, TAssetBalance, TAssetDepositBalance } from '@polkadot/types/interfaces/assets';
import type { BlockAttestations, IncludedBlocks, MoreAttestations } from '@polkadot/types/interfaces/attestations';
import type { RawAuraPreDigest } from '@polkadot/types/interfaces/aura';
Expand Down Expand Up @@ -1092,6 +1093,7 @@ declare module '@polkadot/types/types/registry' {
Tally: Tally;
TaskAddress: TaskAddress;
TAssetBalance: TAssetBalance;
TAssetConversion: TAssetConversion;
TAssetDepositBalance: TAssetDepositBalance;
Text: Text;
Timepoint: Timepoint;
Expand Down
6 changes: 4 additions & 2 deletions packages/types-known/src/spec/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import { versioned as nodeTemplate } from './node-template.js';
import { versioned as polkadot } from './polkadot.js';
import { versioned as rococo } from './rococo.js';
import { versioned as shell } from './shell.js';
import { versioned as statemine } from './statemine.js';
import { versioned as statemint } from './statemint.js';
import { versioned as westend } from './westend.js';
import { versioned as westmint } from './westmint.js';

// Type overrides for specific spec types & versions as given in runtimeVersion
export const typesSpec: Record<string, OverrideVersionedType[]> = {
Expand All @@ -22,8 +24,8 @@ export const typesSpec: Record<string, OverrideVersionedType[]> = {
polkadot,
rococo,
shell,
statemine: statemint,
statemine,
statemint,
westend,
westmint: statemint
westmint
};
62 changes: 62 additions & 0 deletions packages/types-known/src/spec/statemine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2017-2023 @polkadot/types-known authors & contributors
// SPDX-License-Identifier: Apache-2.0

/* eslint-disable sort-keys */

import type { OverrideVersionedType } from '@polkadot/types/types';

import { mapXcmTypes } from '@polkadot/types-create';

const sharedTypes = {
DispatchErrorModule: 'DispatchErrorModuleU8',
TAssetBalance: 'u128',
ProxyType: {
_enum: [
'Any',
'NonTransfer',
'CancelProxy',
'Assets',
'AssetOwner',
'AssetManager',
'Staking'
]
},
Weight: 'WeightV1'
};

// these are override types for Statemine, Westmint
export const versioned: OverrideVersionedType[] = [
{
minmax: [0, 3],
types: {
// Enum was modified mid-flight -
// https://github.com/paritytech/substrate/pull/10382/files#diff-e4e016b33a82268b6208dc974eea841bad47597865a749fee2f937eb6fdf67b4R498
DispatchError: 'DispatchErrorPre6First',
...sharedTypes,
...mapXcmTypes('V0')
}
},
{
minmax: [4, 5],
types: {
// As above, see https://github.com/polkadot-js/api/issues/5301
DispatchError: 'DispatchErrorPre6First',
...sharedTypes,
...mapXcmTypes('V1')
}
},
{
// metadata V14
minmax: [500, 9999],
types: {
Weight: 'WeightV1',
TAssetConversion: 'Option<AssetId>'
}
},
{
minmax: [10000, undefined],
types: {
Weight: 'WeightV1'
}
}
];
3 changes: 2 additions & 1 deletion packages/types-known/src/spec/statemint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export const versioned: OverrideVersionedType[] = [
// metadata V14
minmax: [500, undefined],
types: {
Weight: 'WeightV1'
Weight: 'WeightV1',
TAssetConversion: 'Option<AssetId>'
}
}
// ,
Expand Down
62 changes: 62 additions & 0 deletions packages/types-known/src/spec/westmint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2017-2023 @polkadot/types-known authors & contributors
// SPDX-License-Identifier: Apache-2.0

/* eslint-disable sort-keys */

import type { OverrideVersionedType } from '@polkadot/types/types';

import { mapXcmTypes } from '@polkadot/types-create';

const sharedTypes = {
DispatchErrorModule: 'DispatchErrorModuleU8',
TAssetBalance: 'u128',
ProxyType: {
_enum: [
'Any',
'NonTransfer',
'CancelProxy',
'Assets',
'AssetOwner',
'AssetManager',
'Staking'
]
},
Weight: 'WeightV1'
};

// these are override types for Statemine, Westmint
export const versioned: OverrideVersionedType[] = [
{
minmax: [0, 3],
types: {
// Enum was modified mid-flight -
// https://github.com/paritytech/substrate/pull/10382/files#diff-e4e016b33a82268b6208dc974eea841bad47597865a749fee2f937eb6fdf67b4R498
DispatchError: 'DispatchErrorPre6First',
...sharedTypes,
...mapXcmTypes('V0')
}
},
{
minmax: [4, 5],
types: {
// As above, see https://github.com/polkadot-js/api/issues/5301
DispatchError: 'DispatchErrorPre6First',
...sharedTypes,
...mapXcmTypes('V1')
}
},
{
// metadata V14
minmax: [500, 9434],
types: {
Weight: 'WeightV1',
TAssetConversion: 'Option<AssetId>'
}
},
{
minmax: [9435, undefined],
types: {
Weight: 'WeightV1'
}
}
];
27 changes: 22 additions & 5 deletions packages/types/src/extrinsic/SignerPayload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ describe('SignerPayload', (): void => {
});

it('handles Option<AssetId> correctly', (): void => {
const test = new SignerPayload(registry, { assetId: 123 });
const test = new SignerPayload(registry, {
// eslint-disable-next-line sort-keys
assetId: { parents: 0, interior: { x2: [{ palletInstance: 50 }, { generalIndex: 123 }] } }
});

expect(
[...test.keys()].includes('assetId')
Expand All @@ -70,12 +73,18 @@ describe('SignerPayload', (): void => {
expect(
// @ts-expect-error We don't have getters for this field
test.toPayload().assetId
).toEqual(123);
).toEqual({
// eslint-disable-next-line sort-keys
parents: 0, interior: { x2: [{ palletInstance: 50 }, { generalIndex: 123 }] }
});

expect(
// @ts-expect-error We don't have getters for this field
new SignerPayload(registry, { assetId: 0 }).toPayload().assetId
).toEqual(0);
).toEqual({
// eslint-disable-next-line sort-keys
parents: 0, interior: { here: null }
});

expect(
// @ts-expect-error We don't have getters for this field
Expand Down Expand Up @@ -105,7 +114,11 @@ describe('SignerPayload', (): void => {
});

it('can be used as a feed to ExtrinsicPayload', (): void => {
const signer = new SignerPayload(registry, { ...TEST, assetId: 123 }).toPayload();
const signer = new SignerPayload(registry, {
...TEST,
// eslint-disable-next-line sort-keys
assetId: { parents: 0, interior: { x2: [{ palletInstance: 50 }, { generalIndex: 123 }] } }
}).toPayload();
const payload = registry.createType('ExtrinsicPayload', signer, { version: signer.version });

expect(payload.era.toHex()).toEqual(TEST.era);
Expand All @@ -114,6 +127,10 @@ describe('SignerPayload', (): void => {
expect(payload.nonce.eq(TEST.nonce)).toBe(true);
expect(payload.tip.eq(TEST.tip)).toBe(true);
// @ts-expect-error assetId is of unknown type, so we don't know about "isSome"
expect(payload.inner?.get('assetId')?.isSome && payload.inner?.get('assetId')?.eq(123)).toBe(true);
expect(payload.inner?.get('assetId')?.isSome && payload.inner?.get('assetId')
?.eq(registry.createType('MultiLocation', {
// eslint-disable-next-line sort-keys
parents: 0, interior: { X2: [{ palletInstance: 50 }, { generalIndex: 123 }] }
}))).toBe(true);
});
});
2 changes: 1 addition & 1 deletion packages/types/src/extrinsic/signedExtensions/statemint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const statemint: ExtDef = {
extrinsic: {
tip: 'Compact<Balance>',
// eslint-disable-next-line sort-keys
assetId: 'Option<AssetId>'
assetId: 'TAssetConversion'
},
payload: {}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/types/src/interfaces/assetConversion/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ import { runtime } from './runtime.js';
export default {
rpc: {},
runtime,
types: {}
types: {
TAssetConversion: 'Option<MultiLocation>'
}
} as Definitions;
6 changes: 6 additions & 0 deletions packages/types/src/interfaces/assetConversion/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */

import type { Option } from '@polkadot/types-codec';
import type { MultiLocation } from '@polkadot/types/interfaces/xcm';

/** @name TAssetConversion */
export interface TAssetConversion extends Option<MultiLocation> {}

export type PHANTOM_ASSETCONVERSION = 'assetConversion';