feat(api-contract): add support for ink! v6 and pallet-revive compatibility (#6158)

* wip: support revive for ink! v6

* revive components

* fix: support v6 metadata

* fix: remove debug messages

* test: extend tests for v6ToLatestCompatible

* refactor: remove Revive specific components

* test: construct revive compatible contract

* feat: use ContractReviveProjectInfo new type

* fix: parse version to decide what kind of contract

* refactor: remove hardcoded address

* fix: format

---------

Co-authored-by: Peter White <petras9789@gmail.com>
This commit is contained in:
Alex Bean
2025-06-09 14:46:57 -03:00
committed by GitHub
co-authored by Peter White
parent 252de3b812
commit 3ffc196cc3
20 changed files with 2157 additions and 34 deletions
+27 -7
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { Bytes, Vec } from '@polkadot/types';
import type { ChainProperties, ContractConstructorSpecLatest, ContractEventParamSpecLatest, ContractMessageParamSpecLatest, ContractMessageSpecLatest, ContractMetadata, ContractMetadataV4, ContractMetadataV5, ContractProjectInfo, ContractTypeSpec, EventRecord } from '@polkadot/types/interfaces';
import type { ChainProperties, ContractConstructorSpecLatest, ContractEventParamSpecLatest, ContractMessageParamSpecLatest, ContractMessageSpecLatest, ContractMetadata, ContractMetadataV4, ContractMetadataV5, ContractMetadataV6, ContractProjectInfo, ContractTypeSpec, EventRecord } from '@polkadot/types/interfaces';
import type { Codec, Registry, TypeDef } from '@polkadot/types/types';
import type { AbiConstructor, AbiEvent, AbiEventParam, AbiMessage, AbiMessageParam, AbiParam, DecodedEvent, DecodedMessage } from '../types.js';
@@ -19,12 +19,12 @@ interface AbiJson {
}
type EventOf<M> = M extends {spec: { events: Vec<infer E>}} ? E : never
export type ContractMetadataSupported = ContractMetadataV4 | ContractMetadataV5;
export type ContractMetadataSupported = ContractMetadataV4 | ContractMetadataV5 | ContractMetadataV6;
type ContractEventSupported = EventOf<ContractMetadataSupported>;
const l = logger('Abi');
const PRIMITIVE_ALWAYS = ['AccountId', 'AccountIndex', 'Address', 'Balance'];
const PRIMITIVE_ALWAYS = ['AccountId', 'AccountId20', 'AccountIndex', 'Address', 'Balance'];
function findMessage <T extends AbiMessage> (list: T[], messageOrId: T | string | number): T {
const message = isNumber(messageOrId)
@@ -66,9 +66,28 @@ function getMetadata (registry: Registry, json: AbiJson): ContractMetadataSuppor
return upgradedMetadata;
}
function parseJson (json: Record<string, unknown>, chainProperties?: ChainProperties): [Record<string, unknown>, Registry, ContractMetadataSupported, ContractProjectInfo] {
function isRevive (json: Record<string, unknown>): boolean {
const source = json['source'];
const version = json['version'];
const hasContractBinary =
typeof source === 'object' &&
source !== null &&
'contract_binary' in source;
const hasVersion =
typeof version === 'number' && version >= 6;
return hasContractBinary || hasVersion;
}
function parseJson (json: Record<string, unknown>, chainProperties?: ChainProperties): [Record<string, unknown>, Registry, ContractMetadataSupported, ContractProjectInfo, boolean] {
const registry = new TypeRegistry();
const info = registry.createType('ContractProjectInfo', json) as unknown as ContractProjectInfo;
const revive = isRevive(json);
const typeName = revive ? 'ContractReviveProjectInfo' : 'ContractProjectInfo';
const info = registry.createType(typeName, json) as unknown as ContractProjectInfo;
const metadata = getMetadata(registry, json as unknown as AbiJson);
const lookup = registry.createType('PortableRegistry', { types: metadata.types }, true);
@@ -84,7 +103,7 @@ function parseJson (json: Record<string, unknown>, chainProperties?: ChainProper
lookup.getTypeDef(id)
);
return [json, registry, metadata, info];
return [json, registry, metadata, info, revive];
}
/**
@@ -112,9 +131,10 @@ export class Abi {
readonly metadata: ContractMetadataSupported;
readonly registry: Registry;
readonly environment = new Map<string, TypeDef | Codec>();
readonly isRevive: boolean;
constructor (abiJson: Record<string, unknown> | string, chainProperties?: ChainProperties) {
[this.json, this.registry, this.metadata, this.info] = parseJson(
[this.json, this.registry, this.metadata, this.info, this.isRevive] = parseJson(
isString(abiJson)
? JSON.parse(abiJson) as Record<string, unknown>
: abiJson,
@@ -6,7 +6,7 @@
import { TypeRegistry } from '@polkadot/types';
import abis from '../test/contracts/index.js';
import { v0ToLatestCompatible, v1ToLatestCompatible, v2ToLatestCompatible, v3ToLatestCompatible, v4ToLatestCompatible, v5ToLatestCompatible } from './toLatestCompatible.js';
import { v0ToLatestCompatible, v1ToLatestCompatible, v2ToLatestCompatible, v3ToLatestCompatible, v4ToLatestCompatible, v5ToLatestCompatible, v6ToLatestCompatible } from './toLatestCompatible.js';
describe('v0ToLatestCompatible', (): void => {
const registry = new TypeRegistry();
@@ -191,3 +191,29 @@ describe('v5ToLatestCompatible', (): void => {
expect(latest.version.toString()).toEqual('5');
});
});
describe('v6ToLatestCompatible', (): void => {
const registry = new TypeRegistry();
const contract = registry.createType('ContractMetadata', { V6: abis['ink_v6_erc20Metadata'] });
const latest = v6ToLatestCompatible(registry, contract.asV6);
it('has the correct messages', (): void => {
expect(
latest.spec.messages.map(({ label }) => label.toString())
).toEqual(['total_supply', 'balance_of', 'allowance', 'transfer', 'approve', 'transfer_from']);
});
it('has H160 as the type of balance_of argument', (): void => {
const arg = latest.spec.messages.find(
(m) => m.label.toString() === 'balance_of'
)?.args[0];
const name = arg?.type.displayName?.[0]?.toString();
expect(name).toBe('H160');
});
it('has the latest compatible version number', (): void => {
expect(latest.version.toString()).toEqual('6');
});
});
@@ -1,7 +1,7 @@
// Copyright 2017-2025 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ContractMetadataV4, ContractMetadataV5 } from '@polkadot/types/interfaces';
import type { ContractMetadataV4, ContractMetadataV5, ContractMetadataV6 } from '@polkadot/types/interfaces';
import type { Registry } from '@polkadot/types/types';
import type { ContractMetadataSupported } from './index.js';
@@ -12,7 +12,7 @@ import { v3ToV4 } from './toV4.js';
// The versions where an enum is used, aka V0 is missing
// (Order from newest, i.e. we expect more on newest vs oldest)
export const enumVersions = ['V5', 'V4', 'V3', 'V2', 'V1'] as const;
export const enumVersions = ['V6', 'V5', 'V4', 'V3', 'V2', 'V1'] as const;
type Versions = typeof enumVersions[number] | 'V0';
@@ -24,6 +24,10 @@ function createConverter <I, O> (next: (registry: Registry, input: O) => Contrac
next(registry, step(registry, input));
}
export function v6ToLatestCompatible (_registry: Registry, v6: ContractMetadataV6): ContractMetadataV6 {
return v6;
}
export function v5ToLatestCompatible (_registry: Registry, v5: ContractMetadataV5): ContractMetadataV5 {
return v5;
}
@@ -38,6 +42,7 @@ export const v1ToLatestCompatible = /*#__PURE__*/ createConverter(v2ToLatestComp
export const v0ToLatestCompatible = /*#__PURE__*/ createConverter(v1ToLatestCompatible, v0ToV1);
export const convertVersions: [Versions, Converter][] = [
['V6', v6ToLatestCompatible],
['V5', v5ToLatestCompatible],
['V4', v4ToLatestCompatible],
['V3', v3ToLatestCompatible],
+16 -4
View File
@@ -16,14 +16,11 @@ export abstract class Base<ApiType extends ApiTypes> {
protected readonly _decorateMethod: DecorateMethod<ApiType>;
protected readonly _isWeightV1: boolean;
protected readonly _isRevive: boolean;
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, decorateMethod: DecorateMethod<ApiType>) {
if (!api || !api.isConnected || !api.tx) {
throw new Error('Your API has not been initialized correctly and is not connected to a chain');
} else if (!api.tx.contracts || !isFunction(api.tx.contracts.instantiateWithCode) || api.tx.contracts.instantiateWithCode.meta.args.length !== 6) {
throw new Error('The runtime does not expose api.tx.contracts.instantiateWithCode with storageDepositLimit');
} else if (!api.call.contractsApi || !isFunction(api.call.contractsApi.call)) {
throw new Error('Your runtime does not expose the api.call.contractsApi.call runtime interfaces');
}
this.abi = abi instanceof Abi
@@ -32,6 +29,21 @@ export abstract class Base<ApiType extends ApiTypes> {
this.api = api;
this._decorateMethod = decorateMethod;
this._isWeightV1 = !api.registry.createType<WeightV2>('Weight').proofSize;
this._isRevive = this.abi.isRevive;
if (this._isRevive) {
if (!api.tx.revive || !isFunction(api.tx.revive.instantiateWithCode) || api.tx.revive.instantiateWithCode.meta.args.length !== 6) {
throw new Error('The runtime does not expose api.tx.revive.instantiateWithCode with storageDepositLimit');
} else if (!api.call.reviveApi || !isFunction(api.call.reviveApi.call)) {
throw new Error('Your runtime does not expose the api.call.reviveApi.call runtime interfaces');
}
} else {
if (!api.tx.contracts || !isFunction(api.tx.contracts.instantiateWithCode) || api.tx.contracts.instantiateWithCode.meta.args.length !== 6) {
throw new Error('The runtime does not expose api.tx.contracts.instantiateWithCode with storageDepositLimit');
} else if (!api.call.contractsApi || !isFunction(api.call.contractsApi.call)) {
throw new Error('Your runtime does not expose the api.call.contractsApi.call runtime interfaces');
}
}
}
public get registry (): Registry {
+22 -4
View File
@@ -55,7 +55,11 @@ export class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
}
#deploy = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, storageDepositLimit = null, value = BN_ZERO }: BlueprintOptions, params: unknown[]): SubmittableExtrinsic<ApiType, BlueprintSubmittableResult<ApiType>> => {
return this.api.tx.contracts.instantiate(
const palletTx = this._isRevive
? this.api.tx.revive
: this.api.tx.contracts;
return palletTx.instantiate(
value,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore jiggle v1 weights, metadata points to latest
@@ -67,9 +71,23 @@ export class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
this.abi.findConstructor(constructorOrId).toU8a(params),
encodeSalt(salt)
).withResultTransform((result: ISubmittableResult) =>
new BlueprintSubmittableResult(result, applyOnEvent(result, ['Instantiated'], ([record]: EventRecord[]) =>
new Contract<ApiType>(this.api, this.abi, record.event.data[1] as AccountId, this._decorateMethod)
))
new BlueprintSubmittableResult(result,
this._isRevive
? (
(result.status.isInBlock || result.status.isFinalized)
? new Contract<ApiType>(
this.api,
this.abi,
// your fixed address for revive deployments
this.registry.createType('AccountId', '0x'),
this._decorateMethod
)
: undefined
)
: applyOnEvent(result, ['Instantiated'], ([record]: EventRecord[]) =>
new Contract<ApiType>(this.api, this.abi, record.event.data[1] as AccountId, this._decorateMethod)
)
)
);
};
}
+12 -1
View File
@@ -10,8 +10,9 @@ import { toPromiseMethod } from '@polkadot/api';
import v0contractFlipper from '../test/contracts/ink/v0/flipper.contract.json' assert { type: 'json' };
import v0abiFlipper from '../test/contracts/ink/v0/flipper.json' assert { type: 'json' };
import v1contractFlipper from '../test/contracts/ink/v1/flipper.contract.json' assert { type: 'json' };
import v6contractErc20 from '../test/contracts/ink/v6/erc20.contract.json' assert { type: 'json' };
import { Code } from './Code.js';
import { mockApi } from './mock.js';
import { mockApi, mockReviveApi } from './mock.js';
const v0wasmFlipper = fs.readFileSync(new URL('../test/contracts/ink/v0/flipper.wasm', import.meta.url), 'utf-8');
@@ -33,4 +34,14 @@ describe('Code', (): void => {
() => new Code(mockApi, v1contractFlipper as Record<string, unknown>, null, toPromiseMethod)
).not.toThrow();
});
it('can construct a revive compatible contract (v6)', (): void => {
expect(
() => new Code(mockApi, v6contractErc20 as Record<string, unknown>, null, toPromiseMethod)
).toThrow('The runtime does not expose api.tx.revive.instantiateWithCode with storageDepositLimit');
expect(
() => new Code(mockReviveApi, v6contractErc20 as Record<string, unknown>, null, toPromiseMethod)
).not.toThrow();
});
});
+24 -1
View File
@@ -68,7 +68,30 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
}
#instantiate = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, storageDepositLimit = null, value = BN_ZERO }: BlueprintOptions, params: unknown[]): SubmittableExtrinsic<ApiType, CodeSubmittableResult<ApiType>> => {
return this.api.tx.contracts.instantiateWithCode(
const palletTx = this._isRevive ? this.api.tx.revive : this.api.tx.contracts;
if (this._isRevive) {
return palletTx.instantiateWithCode(
value,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore jiggle v1 weights, metadata points to latest
this._isWeightV1
? convertWeight(gasLimit).v1Weight
: convertWeight(gasLimit).v2Weight,
storageDepositLimit,
compactAddLength(this.code),
this.abi.findConstructor(constructorOrId).toU8a(params),
encodeSalt(salt)
).withResultTransform((result: ISubmittableResult) =>
new CodeSubmittableResult(
result,
new Blueprint<ApiType>(this.api, this.abi, this.abi.info.source.hash, this._decorateMethod),
new Contract<ApiType>(this.api, this.abi, '0x', this._decorateMethod)
)
);
}
return palletTx.instantiateWithCode(
value,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore jiggle v1 weights, metadata points to latest
+10 -6
View File
@@ -4,7 +4,7 @@
import type { ApiBase } from '@polkadot/api/base';
import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
import type { AccountId, ContractExecResult, EventRecord, Weight, WeightV2 } from '@polkadot/types/interfaces';
import type { AccountId, AccountId20, ContractExecResult, EventRecord, Weight, WeightV2 } from '@polkadot/types/interfaces';
import type { ISubmittableResult } from '@polkadot/types/types';
import type { Abi } from '../Abi/index.js';
import type { AbiMessage, ContractCallOutcome, ContractOptions, DecodedEvent, WeightAll } from '../types.js';
@@ -52,15 +52,15 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
/**
* @description The on-chain address for this contract
*/
readonly address: AccountId;
readonly address: AccountId | AccountId20;
readonly #query: MapMessageQuery<ApiType> = {};
readonly #tx: MapMessageTx<ApiType> = {};
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId, decorateMethod: DecorateMethod<ApiType>) {
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId | AccountId20, decorateMethod: DecorateMethod<ApiType>) {
super(api, abi, decorateMethod);
this.address = this.registry.createType('AccountId', address);
this.address = this.registry.createType(this._isRevive ? 'AccountId20' : 'AccountId', address);
this.abi.messages.forEach((m): void => {
if (isUndefined(this.#tx[m.method])) {
@@ -100,7 +100,9 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
};
#exec = (messageOrId: AbiMessage | string | number, { gasLimit = BN_ZERO, storageDepositLimit = null, value = BN_ZERO }: ContractOptions, params: unknown[]): SubmittableExtrinsic<ApiType> => {
return this.api.tx.contracts.call(
const palletTx = this._isRevive ? this.api.tx.revive : this.api.tx.contracts;
return palletTx.call(
this.address,
value,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -134,7 +136,9 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
return {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
send: this._decorateMethod((origin: string | AccountId | Uint8Array) =>
this.api.rx.call.contractsApi.call<ContractExecResult>(
(this._isRevive
? this.api.rx.call.reviveApi.call
: this.api.rx.call.contractsApi.call)<ContractExecResult>(
origin,
this.address,
value,
+17
View File
@@ -29,3 +29,20 @@ export const mockApi = {
}
}
} as unknown as ApiBase<'promise'>;
export const mockReviveApi = {
call: {
reviveApi: {
call: (): never => {
throw new Error('mock');
}
}
},
isConnected: true,
registry,
tx: {
revive: {
instantiateWithCode
}
}
} as unknown as ApiBase<'promise'>;
+2 -2
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { ApiPromise } from '@polkadot/api';
import type { AccountId, Hash } from '@polkadot/types/interfaces';
import type { AccountId, AccountId20, Hash } from '@polkadot/types/interfaces';
import type { Abi } from '../Abi/index.js';
import { toPromiseMethod } from '@polkadot/api';
@@ -22,7 +22,7 @@ export class CodePromise extends Code<'promise'> {
}
export class ContractPromise extends Contract<'promise'> {
constructor (api: ApiPromise, abi: string | Record<string, unknown> | Abi, address: string | AccountId) {
constructor (api: ApiPromise, abi: string | Record<string, unknown> | Abi, address: string | AccountId | AccountId20) {
super(api, abi, address, toPromiseMethod);
}
}
@@ -0,0 +1,418 @@
[
{
"info": "Plain",
"lookupIndex": 0,
"type": "U256",
"docs": [],
"namespace": "primitive_types::U256",
"lookupNameRoot": "PrimitiveTypesU256"
},
{
"info": "VecFixed",
"lookupIndex": 1,
"type": "[u64;4]",
"docs": [],
"namespace": "",
"length": 4,
"sub": {
"info": "Plain",
"lookupIndex": 2,
"type": "u64",
"docs": [],
"namespace": ""
}
},
{
"info": "Plain",
"lookupIndex": 2,
"type": "u64",
"docs": [],
"namespace": ""
},
{
"info": "Null",
"lookupIndex": 3,
"type": "Null",
"docs": [],
"namespace": "ink_storage::lazy::mapping::Mapping"
},
{
"info": "Plain",
"lookupIndex": 4,
"type": "H160",
"docs": [],
"namespace": "primitive_types::H160",
"lookupNameRoot": "PrimitiveTypesH160"
},
{
"info": "VecFixed",
"lookupIndex": 5,
"type": "[u8;20]",
"docs": [],
"namespace": "",
"length": 20,
"sub": {
"info": "Plain",
"lookupIndex": 6,
"type": "u8",
"docs": [],
"namespace": ""
}
},
{
"info": "Plain",
"lookupIndex": 6,
"type": "u8",
"docs": [],
"namespace": ""
},
{
"info": "Null",
"lookupIndex": 7,
"type": "Null",
"docs": [],
"namespace": "ink_storage_traits::impls::ResolverKey"
},
{
"info": "Null",
"lookupIndex": 8,
"lookupName": "InkStorageTraitsImplsAutoKey",
"type": "Null",
"docs": [],
"namespace": "ink_storage_traits::impls::AutoKey"
},
{
"info": "Null",
"lookupIndex": 9,
"lookupName": "InkStorageTraitsImplsManualKey",
"type": "Null",
"docs": [],
"namespace": "ink_storage_traits::impls::ManualKey"
},
{
"info": "Null",
"lookupIndex": 10,
"type": "Null",
"docs": [],
"namespace": ""
},
{
"info": "Null",
"lookupIndex": 11,
"lookupName": "InkStorageLazyMapping",
"type": "Null",
"docs": [],
"namespace": "ink_storage::lazy::mapping::Mapping"
},
{
"info": "Tuple",
"lookupIndex": 12,
"type": "(H160,H160)",
"docs": [],
"namespace": "",
"sub": [
{
"info": "Plain",
"lookupIndex": 4,
"type": "H160",
"docs": [],
"namespace": "primitive_types::H160",
"lookupNameRoot": "PrimitiveTypesH160"
},
{
"info": "Plain",
"lookupIndex": 4,
"type": "H160",
"docs": [],
"namespace": "primitive_types::H160",
"lookupNameRoot": "PrimitiveTypesH160"
}
]
},
{
"info": "Null",
"lookupIndex": 13,
"lookupName": "InkStorageTraitsImplsResolverKey",
"type": "Null",
"docs": [],
"namespace": "ink_storage_traits::impls::ResolverKey"
},
{
"info": "Null",
"lookupIndex": 14,
"lookupName": "InkStorageTraitsImplsManualKey",
"type": "Null",
"docs": [],
"namespace": "ink_storage_traits::impls::ManualKey"
},
{
"info": "Struct",
"lookupIndex": 15,
"lookupName": "Erc20",
"type": "{\"totalSupply\":\"U256\",\"balances\":\"Null\",\"allowances\":\"InkStorageLazyMapping\"}",
"docs": [],
"namespace": "erc20::erc20::Erc20",
"sub": [
{
"docs": [],
"name": "totalSupply",
"info": "Plain",
"lookupIndex": 0,
"type": "U256",
"namespace": "primitive_types::U256",
"lookupNameRoot": "PrimitiveTypesU256",
"typeName": ""
},
{
"docs": [],
"name": "balances",
"info": "Null",
"lookupIndex": 3,
"type": "Null",
"namespace": "ink_storage::lazy::mapping::Mapping",
"typeName": ""
},
{
"docs": [],
"name": "allowances",
"info": "Null",
"lookupIndex": 11,
"lookupName": "InkStorageLazyMapping",
"type": "Null",
"namespace": "ink_storage::lazy::mapping::Mapping",
"typeName": ""
}
]
},
{
"info": "Result",
"lookupIndex": 16,
"type": "Result<Null, InkPrimitivesLangError>",
"docs": [],
"namespace": "Result",
"sub": [
{
"name": "Ok",
"info": "Null",
"lookupIndex": 10,
"type": "Null",
"docs": [],
"namespace": ""
},
{
"name": "Error",
"docs": [],
"info": "Si",
"lookupIndex": 17,
"lookupName": "InkPrimitivesLangError",
"type": "Lookup17"
}
]
},
{
"info": "Enum",
"lookupIndex": 17,
"lookupName": "InkPrimitivesLangError",
"type": "{\"_enum\":[\"__Unused0\",\"CouldNotReadInput\"]}",
"docs": [],
"namespace": "ink_primitives::LangError",
"sub": [
{
"index": 0,
"info": "Null",
"name": "__Unused0",
"type": "Null"
},
{
"info": "Null",
"type": "Null",
"index": 1,
"name": "CouldNotReadInput"
}
]
},
{
"info": "Result",
"lookupIndex": 18,
"type": "Result<U256, InkPrimitivesLangError>",
"docs": [],
"namespace": "Result",
"sub": [
{
"name": "Ok",
"info": "Plain",
"lookupIndex": 0,
"type": "U256",
"docs": [],
"namespace": "primitive_types::U256",
"lookupNameRoot": "PrimitiveTypesU256"
},
{
"name": "Error",
"docs": [],
"info": "Si",
"lookupIndex": 17,
"lookupName": "InkPrimitivesLangError",
"type": "Lookup17"
}
]
},
{
"info": "Result",
"lookupIndex": 19,
"type": "Result<Result<Null, Erc20Error>, InkPrimitivesLangError>",
"docs": [],
"namespace": "Result",
"sub": [
{
"name": "Ok",
"info": "Result",
"lookupIndex": 20,
"type": "Result<Null, Erc20Error>",
"docs": [],
"namespace": "Result",
"sub": [
{
"name": "Ok",
"info": "Null",
"lookupIndex": 10,
"type": "Null",
"docs": [],
"namespace": ""
},
{
"name": "Error",
"docs": [],
"info": "Si",
"lookupIndex": 21,
"lookupName": "Erc20Error",
"type": "Lookup21"
}
]
},
{
"name": "Error",
"docs": [],
"info": "Si",
"lookupIndex": 17,
"lookupName": "InkPrimitivesLangError",
"type": "Lookup17"
}
]
},
{
"info": "Result",
"lookupIndex": 20,
"type": "Result<Null, Erc20Error>",
"docs": [],
"namespace": "Result",
"sub": [
{
"name": "Ok",
"info": "Null",
"lookupIndex": 10,
"type": "Null",
"docs": [],
"namespace": ""
},
{
"name": "Error",
"docs": [],
"info": "Si",
"lookupIndex": 21,
"lookupName": "Erc20Error",
"type": "Lookup21"
}
]
},
{
"info": "Enum",
"lookupIndex": 21,
"lookupName": "Erc20Error",
"type": "{\"_enum\":[\"InsufficientBalance\",\"InsufficientAllowance\"]}",
"docs": [],
"namespace": "erc20::erc20::Error",
"sub": [
{
"info": "Null",
"type": "Null",
"index": 0,
"name": "InsufficientBalance"
},
{
"info": "Null",
"type": "Null",
"index": 1,
"name": "InsufficientAllowance"
}
]
},
{
"info": "Option",
"lookupIndex": 22,
"type": "Option<H160>",
"docs": [],
"namespace": "Option",
"sub": {
"info": "Plain",
"lookupIndex": 4,
"type": "H160",
"docs": [],
"namespace": "primitive_types::H160",
"lookupNameRoot": "PrimitiveTypesH160"
}
},
{
"info": "Plain",
"lookupIndex": 23,
"type": "AccountId",
"docs": [],
"namespace": "ink_primitives::types::AccountId",
"lookupNameRoot": "InkPrimitivesAccountId"
},
{
"info": "VecFixed",
"lookupIndex": 24,
"type": "[u8;32]",
"docs": [],
"namespace": "",
"length": 32,
"sub": {
"info": "Plain",
"lookupIndex": 6,
"type": "u8",
"docs": [],
"namespace": ""
}
},
{
"info": "Plain",
"lookupIndex": 25,
"type": "u128",
"docs": [],
"namespace": ""
},
{
"info": "Plain",
"lookupIndex": 26,
"type": "Hash",
"docs": [],
"namespace": "ink_primitives::types::Hash",
"lookupNameRoot": "InkPrimitivesHash"
},
{
"info": "Plain",
"lookupIndex": 27,
"type": "u32",
"docs": [],
"namespace": ""
},
{
"info": "Plain",
"lookupIndex": 28,
"type": "NoChainExtension",
"docs": [],
"namespace": "ink_primitives::types::NoChainExtension",
"lookupNameRoot": "InkPrimitivesNoChainExtension"
}
]
@@ -0,0 +1,418 @@
[
{
"info": "Plain",
"lookupIndex": 0,
"type": "U256",
"docs": [],
"namespace": "primitive_types::U256",
"lookupNameRoot": "PrimitiveTypesU256"
},
{
"info": "VecFixed",
"lookupIndex": 1,
"type": "[u64;4]",
"docs": [],
"namespace": "",
"length": 4,
"sub": {
"info": "Plain",
"lookupIndex": 2,
"type": "u64",
"docs": [],
"namespace": ""
}
},
{
"info": "Plain",
"lookupIndex": 2,
"type": "u64",
"docs": [],
"namespace": ""
},
{
"info": "Null",
"lookupIndex": 3,
"type": "Null",
"docs": [],
"namespace": "ink_storage::lazy::mapping::Mapping"
},
{
"info": "Plain",
"lookupIndex": 4,
"type": "H160",
"docs": [],
"namespace": "primitive_types::H160",
"lookupNameRoot": "PrimitiveTypesH160"
},
{
"info": "VecFixed",
"lookupIndex": 5,
"type": "[u8;20]",
"docs": [],
"namespace": "",
"length": 20,
"sub": {
"info": "Plain",
"lookupIndex": 6,
"type": "u8",
"docs": [],
"namespace": ""
}
},
{
"info": "Plain",
"lookupIndex": 6,
"type": "u8",
"docs": [],
"namespace": ""
},
{
"info": "Null",
"lookupIndex": 7,
"type": "Null",
"docs": [],
"namespace": "ink_storage_traits::impls::ResolverKey"
},
{
"info": "Null",
"lookupIndex": 8,
"lookupName": "InkStorageTraitsImplsAutoKey",
"type": "Null",
"docs": [],
"namespace": "ink_storage_traits::impls::AutoKey"
},
{
"info": "Null",
"lookupIndex": 9,
"lookupName": "InkStorageTraitsImplsManualKey",
"type": "Null",
"docs": [],
"namespace": "ink_storage_traits::impls::ManualKey"
},
{
"info": "Null",
"lookupIndex": 10,
"type": "Null",
"docs": [],
"namespace": ""
},
{
"info": "Null",
"lookupIndex": 11,
"lookupName": "InkStorageLazyMapping",
"type": "Null",
"docs": [],
"namespace": "ink_storage::lazy::mapping::Mapping"
},
{
"info": "Tuple",
"lookupIndex": 12,
"type": "(H160,H160)",
"docs": [],
"namespace": "",
"sub": [
{
"info": "Plain",
"lookupIndex": 4,
"type": "H160",
"docs": [],
"namespace": "primitive_types::H160",
"lookupNameRoot": "PrimitiveTypesH160"
},
{
"info": "Plain",
"lookupIndex": 4,
"type": "H160",
"docs": [],
"namespace": "primitive_types::H160",
"lookupNameRoot": "PrimitiveTypesH160"
}
]
},
{
"info": "Null",
"lookupIndex": 13,
"lookupName": "InkStorageTraitsImplsResolverKey",
"type": "Null",
"docs": [],
"namespace": "ink_storage_traits::impls::ResolverKey"
},
{
"info": "Null",
"lookupIndex": 14,
"lookupName": "InkStorageTraitsImplsManualKey",
"type": "Null",
"docs": [],
"namespace": "ink_storage_traits::impls::ManualKey"
},
{
"info": "Struct",
"lookupIndex": 15,
"lookupName": "Erc20",
"type": "{\"totalSupply\":\"U256\",\"balances\":\"Null\",\"allowances\":\"InkStorageLazyMapping\"}",
"docs": [],
"namespace": "erc20::erc20::Erc20",
"sub": [
{
"docs": [],
"name": "totalSupply",
"info": "Plain",
"lookupIndex": 0,
"type": "U256",
"namespace": "primitive_types::U256",
"lookupNameRoot": "PrimitiveTypesU256",
"typeName": ""
},
{
"docs": [],
"name": "balances",
"info": "Null",
"lookupIndex": 3,
"type": "Null",
"namespace": "ink_storage::lazy::mapping::Mapping",
"typeName": ""
},
{
"docs": [],
"name": "allowances",
"info": "Null",
"lookupIndex": 11,
"lookupName": "InkStorageLazyMapping",
"type": "Null",
"namespace": "ink_storage::lazy::mapping::Mapping",
"typeName": ""
}
]
},
{
"info": "Result",
"lookupIndex": 16,
"type": "Result<Null, InkPrimitivesLangError>",
"docs": [],
"namespace": "Result",
"sub": [
{
"name": "Ok",
"info": "Null",
"lookupIndex": 10,
"type": "Null",
"docs": [],
"namespace": ""
},
{
"name": "Error",
"docs": [],
"info": "Si",
"lookupIndex": 17,
"lookupName": "InkPrimitivesLangError",
"type": "Lookup17"
}
]
},
{
"info": "Enum",
"lookupIndex": 17,
"lookupName": "InkPrimitivesLangError",
"type": "{\"_enum\":[\"__Unused0\",\"CouldNotReadInput\"]}",
"docs": [],
"namespace": "ink_primitives::LangError",
"sub": [
{
"index": 0,
"info": "Null",
"name": "__Unused0",
"type": "Null"
},
{
"info": "Null",
"type": "Null",
"index": 1,
"name": "CouldNotReadInput"
}
]
},
{
"info": "Result",
"lookupIndex": 18,
"type": "Result<U256, InkPrimitivesLangError>",
"docs": [],
"namespace": "Result",
"sub": [
{
"name": "Ok",
"info": "Plain",
"lookupIndex": 0,
"type": "U256",
"docs": [],
"namespace": "primitive_types::U256",
"lookupNameRoot": "PrimitiveTypesU256"
},
{
"name": "Error",
"docs": [],
"info": "Si",
"lookupIndex": 17,
"lookupName": "InkPrimitivesLangError",
"type": "Lookup17"
}
]
},
{
"info": "Result",
"lookupIndex": 19,
"type": "Result<Result<Null, Erc20Error>, InkPrimitivesLangError>",
"docs": [],
"namespace": "Result",
"sub": [
{
"name": "Ok",
"info": "Result",
"lookupIndex": 20,
"type": "Result<Null, Erc20Error>",
"docs": [],
"namespace": "Result",
"sub": [
{
"name": "Ok",
"info": "Null",
"lookupIndex": 10,
"type": "Null",
"docs": [],
"namespace": ""
},
{
"name": "Error",
"docs": [],
"info": "Si",
"lookupIndex": 21,
"lookupName": "Erc20Error",
"type": "Lookup21"
}
]
},
{
"name": "Error",
"docs": [],
"info": "Si",
"lookupIndex": 17,
"lookupName": "InkPrimitivesLangError",
"type": "Lookup17"
}
]
},
{
"info": "Result",
"lookupIndex": 20,
"type": "Result<Null, Erc20Error>",
"docs": [],
"namespace": "Result",
"sub": [
{
"name": "Ok",
"info": "Null",
"lookupIndex": 10,
"type": "Null",
"docs": [],
"namespace": ""
},
{
"name": "Error",
"docs": [],
"info": "Si",
"lookupIndex": 21,
"lookupName": "Erc20Error",
"type": "Lookup21"
}
]
},
{
"info": "Enum",
"lookupIndex": 21,
"lookupName": "Erc20Error",
"type": "{\"_enum\":[\"InsufficientBalance\",\"InsufficientAllowance\"]}",
"docs": [],
"namespace": "erc20::erc20::Error",
"sub": [
{
"info": "Null",
"type": "Null",
"index": 0,
"name": "InsufficientBalance"
},
{
"info": "Null",
"type": "Null",
"index": 1,
"name": "InsufficientAllowance"
}
]
},
{
"info": "Option",
"lookupIndex": 22,
"type": "Option<H160>",
"docs": [],
"namespace": "Option",
"sub": {
"info": "Plain",
"lookupIndex": 4,
"type": "H160",
"docs": [],
"namespace": "primitive_types::H160",
"lookupNameRoot": "PrimitiveTypesH160"
}
},
{
"info": "Plain",
"lookupIndex": 23,
"type": "AccountId",
"docs": [],
"namespace": "ink_primitives::types::AccountId",
"lookupNameRoot": "InkPrimitivesAccountId"
},
{
"info": "VecFixed",
"lookupIndex": 24,
"type": "[u8;32]",
"docs": [],
"namespace": "",
"length": 32,
"sub": {
"info": "Plain",
"lookupIndex": 6,
"type": "u8",
"docs": [],
"namespace": ""
}
},
{
"info": "Plain",
"lookupIndex": 25,
"type": "u128",
"docs": [],
"namespace": ""
},
{
"info": "Plain",
"lookupIndex": 26,
"type": "Hash",
"docs": [],
"namespace": "ink_primitives::types::Hash",
"lookupNameRoot": "InkPrimitivesHash"
},
{
"info": "Plain",
"lookupIndex": 27,
"type": "u32",
"docs": [],
"namespace": ""
},
{
"info": "Plain",
"lookupIndex": 28,
"type": "NoChainExtension",
"docs": [],
"namespace": "ink_primitives::types::NoChainExtension",
"lookupNameRoot": "InkPrimitivesNoChainExtension"
}
]
@@ -8,5 +8,6 @@ import * as v2 from './v2/index.js';
import * as v3 from './v3/index.js';
import * as v4 from './v4/index.js';
import * as v5 from './v5/index.js';
import * as v6 from './v6/index.js';
export default createVersionedExport({ v0, v1, v2, v3, v4, v5 });
export default createVersionedExport({ v0, v1, v2, v3, v4, v5, v6 });
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,5 @@
// Copyright 2017-2025 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { default as erc20Contract } from './erc20.contract.json' assert { type: 'json' };
export { default as erc20Metadata } from './erc20.json' assert { type: 'json' };
@@ -25,7 +25,7 @@ import type { StatementKind } from '@polkadot/types/interfaces/claims';
import type { CollectiveOrigin, MemberCount, ProposalIndex, Votes, VotesTo230 } from '@polkadot/types/interfaces/collective';
import type { AuthorityId, RawVRFOutput } from '@polkadot/types/interfaces/consensus';
import type { AliveContractInfo, CodeHash, CodeSource, CodeUploadRequest, CodeUploadResult, CodeUploadResultValue, ContractCallFlags, ContractCallRequest, ContractExecResult, ContractExecResultOk, ContractExecResultResult, ContractExecResultSuccessTo255, ContractExecResultSuccessTo260, ContractExecResultTo255, ContractExecResultTo260, ContractExecResultTo267, ContractExecResultU64, ContractInfo, ContractInstantiateResult, ContractInstantiateResultTo267, ContractInstantiateResultTo299, ContractInstantiateResultU64, ContractReturnFlags, ContractStorageKey, DeletedContract, ExecReturnValue, Gas, HostFnWeights, HostFnWeightsTo264, InstantiateRequest, InstantiateRequestV1, InstantiateRequestV2, InstantiateReturnValue, InstantiateReturnValueOk, InstantiateReturnValueTo267, InstructionWeights, Limits, LimitsTo264, PrefabWasmModule, RentProjection, Schedule, ScheduleTo212, ScheduleTo258, ScheduleTo264, SeedOf, StorageDeposit, TombstoneContractInfo, TrieId } from '@polkadot/types/interfaces/contracts';
import type { ContractConstructorSpecLatest, ContractConstructorSpecV0, ContractConstructorSpecV1, ContractConstructorSpecV2, ContractConstructorSpecV3, ContractConstructorSpecV4, ContractContractSpecV0, ContractContractSpecV1, ContractContractSpecV2, ContractContractSpecV3, ContractContractSpecV4, ContractContractSpecV5, ContractCryptoHasher, ContractDiscriminant, ContractDisplayName, ContractEnvironmentV4, ContractEventParamSpecLatest, ContractEventParamSpecV0, ContractEventParamSpecV2, ContractEventSpecLatest, ContractEventSpecV0, ContractEventSpecV1, ContractEventSpecV2, ContractEventSpecV3, ContractLayoutArray, ContractLayoutCell, ContractLayoutEnum, ContractLayoutHash, ContractLayoutHashingStrategy, ContractLayoutKey, ContractLayoutStruct, ContractLayoutStructField, ContractMessageParamSpecLatest, ContractMessageParamSpecV0, ContractMessageParamSpecV2, ContractMessageSpecLatest, ContractMessageSpecV0, ContractMessageSpecV1, ContractMessageSpecV2, ContractMessageSpecV3, ContractMetadata, ContractMetadataLatest, ContractMetadataV0, ContractMetadataV1, ContractMetadataV2, ContractMetadataV3, ContractMetadataV4, ContractMetadataV5, ContractProject, ContractProjectContract, ContractProjectInfo, ContractProjectSource, ContractProjectV0, ContractSelector, ContractStorageLayout, ContractTypeSpec } from '@polkadot/types/interfaces/contractsAbi';
import type { ContractConstructorSpecLatest, ContractConstructorSpecV0, ContractConstructorSpecV1, ContractConstructorSpecV2, ContractConstructorSpecV3, ContractConstructorSpecV4, ContractContractSpecV0, ContractContractSpecV1, ContractContractSpecV2, ContractContractSpecV3, ContractContractSpecV4, ContractContractSpecV5, ContractContractSpecV6, ContractCryptoHasher, ContractDiscriminant, ContractDisplayName, ContractEnvironmentV4, ContractEventParamSpecLatest, ContractEventParamSpecV0, ContractEventParamSpecV2, ContractEventSpecLatest, ContractEventSpecV0, ContractEventSpecV1, ContractEventSpecV2, ContractEventSpecV3, ContractLayoutArray, ContractLayoutCell, ContractLayoutEnum, ContractLayoutHash, ContractLayoutHashingStrategy, ContractLayoutKey, ContractLayoutStruct, ContractLayoutStructField, ContractMessageParamSpecLatest, ContractMessageParamSpecV0, ContractMessageParamSpecV2, ContractMessageSpecLatest, ContractMessageSpecV0, ContractMessageSpecV1, ContractMessageSpecV2, ContractMessageSpecV3, ContractMetadata, ContractMetadataLatest, ContractMetadataV0, ContractMetadataV1, ContractMetadataV2, ContractMetadataV3, ContractMetadataV4, ContractMetadataV5, ContractMetadataV6, ContractProject, ContractProjectContract, ContractProjectInfo, ContractProjectSource, ContractProjectV0, ContractReviveProjectInfo, ContractReviveProjectSource, ContractSelector, ContractStorageLayout, ContractTypeSpec } from '@polkadot/types/interfaces/contractsAbi';
import type { FundIndex, FundInfo, LastContribution, TrieIndex } from '@polkadot/types/interfaces/crowdloan';
import type { CollationInfo, CollationInfoV1, ConfigData, MessageId, OverweightIndex, PageCounter, PageIndexData } from '@polkadot/types/interfaces/cumulus';
import type { AccountVote, AccountVoteSplit, AccountVoteStandard, Conviction, Delegations, PreimageStatus, PreimageStatusAvailable, PriorLock, PropIndex, Proposal, ProxyState, ReferendumIndex, ReferendumInfo, ReferendumInfoFinished, ReferendumInfoTo239, ReferendumStatus, Tally, Voting, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces/democracy';
@@ -285,6 +285,7 @@ declare module '@polkadot/types/types/registry' {
ContractContractSpecV3: ContractContractSpecV3;
ContractContractSpecV4: ContractContractSpecV4;
ContractContractSpecV5: ContractContractSpecV5;
ContractContractSpecV6: ContractContractSpecV6;
ContractCryptoHasher: ContractCryptoHasher;
ContractDiscriminant: ContractDiscriminant;
ContractDisplayName: ContractDisplayName;
@@ -335,12 +336,15 @@ declare module '@polkadot/types/types/registry' {
ContractMetadataV3: ContractMetadataV3;
ContractMetadataV4: ContractMetadataV4;
ContractMetadataV5: ContractMetadataV5;
ContractMetadataV6: ContractMetadataV6;
ContractProject: ContractProject;
ContractProjectContract: ContractProjectContract;
ContractProjectInfo: ContractProjectInfo;
ContractProjectSource: ContractProjectSource;
ContractProjectV0: ContractProjectV0;
ContractReturnFlags: ContractReturnFlags;
ContractReviveProjectInfo: ContractReviveProjectInfo;
ContractReviveProjectSource: ContractReviveProjectSource;
ContractSelector: ContractSelector;
ContractStorageKey: ContractStorageKey;
ContractStorageLayout: ContractStorageLayout;
@@ -127,6 +127,13 @@ const spec = {
docs: 'Vec<Text>',
environment: 'ContractEnvironmentV4'
},
ContractContractSpecV6: {
constructors: 'Vec<ContractConstructorSpecV4>',
messages: 'Vec<ContractMessageSpecV3>',
events: 'Vec<ContractEventSpecV3>',
docs: 'Vec<Text>',
environment: 'ContractEnvironmentV4'
},
ContractDisplayName: 'SiPath',
ContractEventParamSpecV0: {
@@ -221,7 +228,7 @@ const latest = {
ContractEventParamSpecLatest: 'ContractEventParamSpecV2',
ContractMessageParamSpecLatest: 'ContractMessageParamSpecV2',
ContractMessageSpecLatest: 'ContractMessageSpecV3',
ContractMetadataLatest: 'ContractMetadataV5'
ContractMetadataLatest: 'ContractMetadataV6'
};
export default {
@@ -234,6 +241,10 @@ export default {
source: 'ContractProjectSource',
contract: 'ContractProjectContract'
},
ContractReviveProjectInfo: {
source: 'ContractReviveProjectSource',
contract: 'ContractProjectContract'
},
ContractMetadataV0: {
metadataVersion: 'Text',
types: 'Vec<Si0Type>',
@@ -261,6 +272,11 @@ export default {
spec: 'ContractContractSpecV5',
version: 'u64'
},
ContractMetadataV6: {
types: 'Vec<PortableType>',
spec: 'ContractContractSpecV6',
version: 'u64'
},
ContractMetadata: {
_enum: {
V0: 'ContractMetadataV0',
@@ -268,7 +284,8 @@ export default {
V2: 'ContractMetadataV2',
V3: 'ContractMetadataV3',
V4: 'ContractMetadataV4',
V5: 'ContractMetadataV5'
V5: 'ContractMetadataV5',
V6: 'ContractMetadataV6'
}
},
ContractProjectV0: {
@@ -301,6 +318,16 @@ export default {
compiler: 'Text',
wasm: 'Raw'
},
ContractReviveProjectSource: {
_alias: {
wasmHash: 'hash',
wasm: 'contract_binary'
},
wasmHash: '[u8; 32]',
language: 'Text',
compiler: 'Text',
wasm: 'Raw'
},
ContractEnvironmentV4: {
_alias: {
hashType: 'hash'
@@ -103,6 +103,15 @@ export interface ContractContractSpecV5 extends Struct {
readonly environment: ContractEnvironmentV4;
}
/** @name ContractContractSpecV6 */
export interface ContractContractSpecV6 extends Struct {
readonly constructors: Vec<ContractConstructorSpecV4>;
readonly messages: Vec<ContractMessageSpecV3>;
readonly events: Vec<ContractEventSpecV3>;
readonly docs: Vec<Text>;
readonly environment: ContractEnvironmentV4;
}
/** @name ContractCryptoHasher */
export interface ContractCryptoHasher extends Enum {
readonly isBlake2x256: boolean;
@@ -304,11 +313,13 @@ export interface ContractMetadata extends Enum {
readonly asV4: ContractMetadataV4;
readonly isV5: boolean;
readonly asV5: ContractMetadataV5;
readonly type: 'V0' | 'V1' | 'V2' | 'V3' | 'V4' | 'V5';
readonly isV6: boolean;
readonly asV6: ContractMetadataV6;
readonly type: 'V0' | 'V1' | 'V2' | 'V3' | 'V4' | 'V5' | 'V6';
}
/** @name ContractMetadataLatest */
export interface ContractMetadataLatest extends ContractMetadataV5 {}
export interface ContractMetadataLatest extends ContractMetadataV6 {}
/** @name ContractMetadataV0 */
export interface ContractMetadataV0 extends Struct {
@@ -349,6 +360,13 @@ export interface ContractMetadataV5 extends Struct {
readonly version: u64;
}
/** @name ContractMetadataV6 */
export interface ContractMetadataV6 extends Struct {
readonly types: Vec<PortableType>;
readonly spec: ContractContractSpecV6;
readonly version: u64;
}
/** @name ContractProject */
export interface ContractProject extends ITuple<[ContractProjectInfo, ContractMetadata]> {}
@@ -387,6 +405,20 @@ export interface ContractProjectV0 extends Struct {
readonly spec: ContractContractSpecV0;
}
/** @name ContractReviveProjectInfo */
export interface ContractReviveProjectInfo extends Struct {
readonly source: ContractReviveProjectSource;
readonly contract: ContractProjectContract;
}
/** @name ContractReviveProjectSource */
export interface ContractReviveProjectSource extends Struct {
readonly wasmHash: U8aFixed;
readonly language: Text;
readonly compiler: Text;
readonly wasm: Raw;
}
/** @name ContractSelector */
export interface ContractSelector extends U8aFixed {}