fix: ChargeAssetTxPayment to work with Asset Conversion on Westend's and Kusama's Asset Hubs (#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
This commit is contained in:
Alberto Nicolas Penayo
2023-11-16 09:26:21 +02:00
committed by GitHub
parent 7a8a4f1c64
commit bc81ca45ef
10 changed files with 165 additions and 11 deletions
+1 -1
View File
@@ -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> =
@@ -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';
@@ -1092,6 +1093,7 @@ declare module '@polkadot/types/types/registry' {
Tally: Tally;
TaskAddress: TaskAddress;
TAssetBalance: TAssetBalance;
TAssetConversion: TAssetConversion;
TAssetDepositBalance: TAssetDepositBalance;
Text: Text;
Timepoint: Timepoint;
+4 -2
View File
@@ -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[]> = {
@@ -22,8 +24,8 @@ export const typesSpec: Record<string, OverrideVersionedType[]> = {
polkadot,
rococo,
shell,
statemine: statemint,
statemine,
statemint,
westend,
westmint: statemint
westmint
};
@@ -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'
}
}
];
+2 -1
View File
@@ -49,7 +49,8 @@ export const versioned: OverrideVersionedType[] = [
// metadata V14
minmax: [500, undefined],
types: {
Weight: 'WeightV1'
Weight: 'WeightV1',
TAssetConversion: 'Option<AssetId>'
}
}
// ,
+62
View File
@@ -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'
}
}
];
@@ -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')
@@ -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
@@ -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);
@@ -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);
});
});
@@ -8,7 +8,7 @@ export const statemint: ExtDef = {
extrinsic: {
tip: 'Compact<Balance>',
// eslint-disable-next-line sort-keys
assetId: 'Option<AssetId>'
assetId: 'TAssetConversion'
},
payload: {}
}
@@ -11,5 +11,7 @@ import { runtime } from './runtime.js';
export default {
rpc: {},
runtime,
types: {}
types: {
TAssetConversion: 'Option<MultiLocation>'
}
} as Definitions;
@@ -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';