Skip to content

Commit bc81ca4

Browse files
authored
fix: ChargeAssetTxPayment to work with Asset Conversion on Westend's and Kusama's Asset Hubs (polkadot-js#5752)
* fix: added type override for AssetConversion * fix: modified ChargeAssetTxPayment SE for AssetHub * fixed ChargeAssetTxPayment for AssetConversion * ran yarn lint * added default type for AssetConversion * added default type TAssetConversion * ran yarn lint
1 parent 7a8a4f1 commit bc81ca4

File tree

10 files changed

+165
-11
lines changed

10 files changed

+165
-11
lines changed

packages/api-base/src/types/submittable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface SignerOptions {
1616
nonce: AnyNumber | Codec;
1717
signer?: Signer;
1818
tip?: AnyNumber;
19-
assetId?: AnyNumber;
19+
assetId?: AnyNumber | object;
2020
}
2121

2222
export type SubmittableDryRunResult<ApiType extends ApiTypes> =

packages/types-augment/src/registry/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import '@polkadot/types/types/registry';
77

88
import type { Data, StorageKey } from '@polkadot/types';
99
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';
10+
import type { TAssetConversion } from '@polkadot/types/interfaces/assetConversion';
1011
import type { AssetApproval, AssetApprovalKey, AssetBalance, AssetDestroyWitness, AssetDetails, AssetMetadata, TAssetBalance, TAssetDepositBalance } from '@polkadot/types/interfaces/assets';
1112
import type { BlockAttestations, IncludedBlocks, MoreAttestations } from '@polkadot/types/interfaces/attestations';
1213
import type { RawAuraPreDigest } from '@polkadot/types/interfaces/aura';
@@ -1092,6 +1093,7 @@ declare module '@polkadot/types/types/registry' {
10921093
Tally: Tally;
10931094
TaskAddress: TaskAddress;
10941095
TAssetBalance: TAssetBalance;
1096+
TAssetConversion: TAssetConversion;
10951097
TAssetDepositBalance: TAssetDepositBalance;
10961098
Text: Text;
10971099
Timepoint: Timepoint;

packages/types-known/src/spec/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import { versioned as nodeTemplate } from './node-template.js';
1010
import { versioned as polkadot } from './polkadot.js';
1111
import { versioned as rococo } from './rococo.js';
1212
import { versioned as shell } from './shell.js';
13+
import { versioned as statemine } from './statemine.js';
1314
import { versioned as statemint } from './statemint.js';
1415
import { versioned as westend } from './westend.js';
16+
import { versioned as westmint } from './westmint.js';
1517

1618
// Type overrides for specific spec types & versions as given in runtimeVersion
1719
export const typesSpec: Record<string, OverrideVersionedType[]> = {
@@ -22,8 +24,8 @@ export const typesSpec: Record<string, OverrideVersionedType[]> = {
2224
polkadot,
2325
rococo,
2426
shell,
25-
statemine: statemint,
27+
statemine,
2628
statemint,
2729
westend,
28-
westmint: statemint
30+
westmint
2931
};
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2017-2023 @polkadot/types-known authors & contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
/* eslint-disable sort-keys */
5+
6+
import type { OverrideVersionedType } from '@polkadot/types/types';
7+
8+
import { mapXcmTypes } from '@polkadot/types-create';
9+
10+
const sharedTypes = {
11+
DispatchErrorModule: 'DispatchErrorModuleU8',
12+
TAssetBalance: 'u128',
13+
ProxyType: {
14+
_enum: [
15+
'Any',
16+
'NonTransfer',
17+
'CancelProxy',
18+
'Assets',
19+
'AssetOwner',
20+
'AssetManager',
21+
'Staking'
22+
]
23+
},
24+
Weight: 'WeightV1'
25+
};
26+
27+
// these are override types for Statemine, Westmint
28+
export const versioned: OverrideVersionedType[] = [
29+
{
30+
minmax: [0, 3],
31+
types: {
32+
// Enum was modified mid-flight -
33+
// https://github.com/paritytech/substrate/pull/10382/files#diff-e4e016b33a82268b6208dc974eea841bad47597865a749fee2f937eb6fdf67b4R498
34+
DispatchError: 'DispatchErrorPre6First',
35+
...sharedTypes,
36+
...mapXcmTypes('V0')
37+
}
38+
},
39+
{
40+
minmax: [4, 5],
41+
types: {
42+
// As above, see https://github.com/polkadot-js/api/issues/5301
43+
DispatchError: 'DispatchErrorPre6First',
44+
...sharedTypes,
45+
...mapXcmTypes('V1')
46+
}
47+
},
48+
{
49+
// metadata V14
50+
minmax: [500, 9999],
51+
types: {
52+
Weight: 'WeightV1',
53+
TAssetConversion: 'Option<AssetId>'
54+
}
55+
},
56+
{
57+
minmax: [10000, undefined],
58+
types: {
59+
Weight: 'WeightV1'
60+
}
61+
}
62+
];

packages/types-known/src/spec/statemint.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export const versioned: OverrideVersionedType[] = [
4949
// metadata V14
5050
minmax: [500, undefined],
5151
types: {
52-
Weight: 'WeightV1'
52+
Weight: 'WeightV1',
53+
TAssetConversion: 'Option<AssetId>'
5354
}
5455
}
5556
// ,
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2017-2023 @polkadot/types-known authors & contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
/* eslint-disable sort-keys */
5+
6+
import type { OverrideVersionedType } from '@polkadot/types/types';
7+
8+
import { mapXcmTypes } from '@polkadot/types-create';
9+
10+
const sharedTypes = {
11+
DispatchErrorModule: 'DispatchErrorModuleU8',
12+
TAssetBalance: 'u128',
13+
ProxyType: {
14+
_enum: [
15+
'Any',
16+
'NonTransfer',
17+
'CancelProxy',
18+
'Assets',
19+
'AssetOwner',
20+
'AssetManager',
21+
'Staking'
22+
]
23+
},
24+
Weight: 'WeightV1'
25+
};
26+
27+
// these are override types for Statemine, Westmint
28+
export const versioned: OverrideVersionedType[] = [
29+
{
30+
minmax: [0, 3],
31+
types: {
32+
// Enum was modified mid-flight -
33+
// https://github.com/paritytech/substrate/pull/10382/files#diff-e4e016b33a82268b6208dc974eea841bad47597865a749fee2f937eb6fdf67b4R498
34+
DispatchError: 'DispatchErrorPre6First',
35+
...sharedTypes,
36+
...mapXcmTypes('V0')
37+
}
38+
},
39+
{
40+
minmax: [4, 5],
41+
types: {
42+
// As above, see https://github.com/polkadot-js/api/issues/5301
43+
DispatchError: 'DispatchErrorPre6First',
44+
...sharedTypes,
45+
...mapXcmTypes('V1')
46+
}
47+
},
48+
{
49+
// metadata V14
50+
minmax: [500, 9434],
51+
types: {
52+
Weight: 'WeightV1',
53+
TAssetConversion: 'Option<AssetId>'
54+
}
55+
},
56+
{
57+
minmax: [9435, undefined],
58+
types: {
59+
Weight: 'WeightV1'
60+
}
61+
}
62+
];

packages/types/src/extrinsic/SignerPayload.spec.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ describe('SignerPayload', (): void => {
6161
});
6262

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

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

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

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

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

111124
expect(payload.era.toHex()).toEqual(TEST.era);
@@ -114,6 +127,10 @@ describe('SignerPayload', (): void => {
114127
expect(payload.nonce.eq(TEST.nonce)).toBe(true);
115128
expect(payload.tip.eq(TEST.tip)).toBe(true);
116129
// @ts-expect-error assetId is of unknown type, so we don't know about "isSome"
117-
expect(payload.inner?.get('assetId')?.isSome && payload.inner?.get('assetId')?.eq(123)).toBe(true);
130+
expect(payload.inner?.get('assetId')?.isSome && payload.inner?.get('assetId')
131+
?.eq(registry.createType('MultiLocation', {
132+
// eslint-disable-next-line sort-keys
133+
parents: 0, interior: { X2: [{ palletInstance: 50 }, { generalIndex: 123 }] }
134+
}))).toBe(true);
118135
});
119136
});

packages/types/src/extrinsic/signedExtensions/statemint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const statemint: ExtDef = {
88
extrinsic: {
99
tip: 'Compact<Balance>',
1010
// eslint-disable-next-line sort-keys
11-
assetId: 'Option<AssetId>'
11+
assetId: 'TAssetConversion'
1212
},
1313
payload: {}
1414
}

packages/types/src/interfaces/assetConversion/definitions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ import { runtime } from './runtime.js';
1111
export default {
1212
rpc: {},
1313
runtime,
14-
types: {}
14+
types: {
15+
TAssetConversion: 'Option<MultiLocation>'
16+
}
1517
} as Definitions;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
22
/* eslint-disable */
33

4+
import type { Option } from '@polkadot/types-codec';
5+
import type { MultiLocation } from '@polkadot/types/interfaces/xcm';
6+
7+
/** @name TAssetConversion */
8+
export interface TAssetConversion extends Option<MultiLocation> {}
9+
410
export type PHANTOM_ASSETCONVERSION = 'assetConversion';

0 commit comments

Comments
 (0)