diff --git a/packages/api-contract/src/base/Blueprint.ts b/packages/api-contract/src/base/Blueprint.ts index 9969f50c54..fb86120a11 100644 --- a/packages/api-contract/src/base/Blueprint.ts +++ b/packages/api-contract/src/base/Blueprint.ts @@ -56,9 +56,9 @@ export class Blueprint extends Base { return this.#tx; } - #deploy = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, value = BN_ZERO }: BlueprintOptions, params: unknown[]): SubmittableExtrinsic> => { + #deploy = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, storageDepositLimit = null, value = BN_ZERO }: BlueprintOptions, params: unknown[]): SubmittableExtrinsic> => { const hasStorageDeposit = this.api.tx.contracts.instantiate.meta.args.length === 6; - const storageDepositLimit = null; + const tx = hasStorageDeposit ? this.api.tx.contracts.instantiate(value, gasLimit, storageDepositLimit, this.codeHash, this.abi.findConstructor(constructorOrId).toU8a(params), encodeSalt(salt)) // eslint-disable-next-line @typescript-eslint/ban-ts-comment diff --git a/packages/api-contract/src/base/Code.ts b/packages/api-contract/src/base/Code.ts index 992cdaebb7..7210e46a64 100644 --- a/packages/api-contract/src/base/Code.ts +++ b/packages/api-contract/src/base/Code.ts @@ -61,9 +61,9 @@ export class Code extends Base { return this.#tx; } - #instantiate = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, value = BN_ZERO }: BlueprintOptions, params: unknown[]): SubmittableExtrinsic> => { + #instantiate = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, storageDepositLimit = null, value = BN_ZERO }: BlueprintOptions, params: unknown[]): SubmittableExtrinsic> => { const hasStorageDeposit = this.api.tx.contracts.instantiateWithCode.meta.args.length === 6; - const storageDepositLimit = null; + const tx = hasStorageDeposit ? this.api.tx.contracts.instantiateWithCode(value, gasLimit, storageDepositLimit, compactAddLength(this.code), this.abi.findConstructor(constructorOrId).toU8a(params), encodeSalt(salt)) // eslint-disable-next-line @typescript-eslint/ban-ts-comment diff --git a/packages/api-contract/src/base/Contract.ts b/packages/api-contract/src/base/Contract.ts index ea37336a64..0e02fde2ba 100644 --- a/packages/api-contract/src/base/Contract.ts +++ b/packages/api-contract/src/base/Contract.ts @@ -106,9 +106,9 @@ export class Contract extends Base { : gasLimit; }; - #exec = (messageOrId: AbiMessage | string | number, { gasLimit = BN_ZERO, value = BN_ZERO }: ContractOptions, params: unknown[]): SubmittableExtrinsic => { + #exec = (messageOrId: AbiMessage | string | number, { gasLimit = BN_ZERO, storageDepositLimit = null, value = BN_ZERO }: ContractOptions, params: unknown[]): SubmittableExtrinsic => { const hasStorageDeposit = this.api.tx.contracts.call.meta.args.length === 5; - const storageDepositLimit = null; + const tx = hasStorageDeposit ? this.api.tx.contracts.call(this.address, value, this.#getGas(gasLimit), storageDepositLimit, this.abi.findMessage(messageOrId).toU8a(params)) // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -133,7 +133,7 @@ export class Contract extends Base { ); }; - #read = (messageOrId: AbiMessage | string | number, { gasLimit = BN_ZERO, value = BN_ZERO }: ContractOptions, params: unknown[]): ContractCallSend => { + #read = (messageOrId: AbiMessage | string | number, { gasLimit = BN_ZERO, storageDepositLimit = null, value = BN_ZERO }: ContractOptions, params: unknown[]): ContractCallSend => { assert(this.hasRpcContractsCall, ERROR_NO_CALL); const message = this.abi.findMessage(messageOrId); @@ -143,7 +143,7 @@ export class Contract extends Base { send: this._decorateMethod((origin: string | AccountId | Uint8Array) => { const hasStorageDeposit = this.api.tx.contracts.call.meta.args.length === 5; const rpc = hasStorageDeposit - ? this.api.rx.rpc.contracts.call({ dest: this.address, gasLimit: this.#getGas(gasLimit, true), inputData: message.toU8a(params), origin, value }) + ? this.api.rx.rpc.contracts.call({ dest: this.address, gasLimit: this.#getGas(gasLimit, true), inputData: message.toU8a(params), origin, storageDepositLimit, value }) : this.api.rx.rpc.contracts.call({ dest: this.address, gasLimit: this.#getGas(gasLimit, true), inputData: message.toU8a(params), origin, value }); const mapFn = ({ debugMessage, gasConsumed, gasRequired, result }: ContractExecResult): ContractCallOutcome => ({ diff --git a/packages/api-contract/src/types.ts b/packages/api-contract/src/types.ts index 949a553f7e..37d208efe8 100644 --- a/packages/api-contract/src/types.ts +++ b/packages/api-contract/src/types.ts @@ -70,13 +70,12 @@ export interface DecodedMessage { message: AbiMessage; } -export interface BlueprintOptions { - gasLimit?: bigint | string | number | BN; - salt?: Uint8Array | string | null; - value?: bigint | string | number | BN; -} - export interface ContractOptions { - gasLimit?: bigint | BN | string | number; + gasLimit?: bigint | string | number | BN; + storageDepositLimit?: bigint | string | number | BN | null; value?: bigint | BN | string | number; } + +export interface BlueprintOptions extends ContractOptions { + salt?: Uint8Array | string | null; +} diff --git a/packages/rpc-augment/src/augment/jsonrpc.ts b/packages/rpc-augment/src/augment/jsonrpc.ts index e0c6f8cf2b..0c7a5cc5d1 100644 --- a/packages/rpc-augment/src/augment/jsonrpc.ts +++ b/packages/rpc-augment/src/augment/jsonrpc.ts @@ -133,7 +133,7 @@ declare module '@polkadot/rpc-core/types/jsonrpc' { /** * Executes a call to a contract **/ - call: AugmentedRpc<(callRequest: ContractCallRequest | { origin?: any; dest?: any; value?: any; gasLimit?: any; inputData?: any } | string | Uint8Array, at?: BlockHash | string | Uint8Array) => Observable>; + call: AugmentedRpc<(callRequest: ContractCallRequest | { origin?: any; dest?: any; value?: any; gasLimit?: any; storageDepositLimit?: any; inputData?: any } | string | Uint8Array, at?: BlockHash | string | Uint8Array) => Observable>; /** * Returns the value under a specified storage key in a contract **/ @@ -141,7 +141,7 @@ declare module '@polkadot/rpc-core/types/jsonrpc' { /** * Instantiate a new contract **/ - instantiate: AugmentedRpc<(request: InstantiateRequest | { origin?: any; value?: any; gasLimit?: any; code?: any; data?: any; salt?: any } | string | Uint8Array, at?: BlockHash | string | Uint8Array) => Observable>; + instantiate: AugmentedRpc<(request: InstantiateRequest | { origin?: any; value?: any; gasLimit?: any; storageDepositLimit?: any; code?: any; data?: any; salt?: any } | string | Uint8Array, at?: BlockHash | string | Uint8Array) => Observable>; /** * Returns the projected time a given contract will be able to sustain paying its rent **/ diff --git a/packages/types-augment/src/augment/registry.ts b/packages/types-augment/src/augment/registry.ts index 4655e6ee07..c556a399fd 100644 --- a/packages/types-augment/src/augment/registry.ts +++ b/packages/types-augment/src/augment/registry.ts @@ -17,7 +17,7 @@ import type { PrefixedStorageKey } from '@polkadot/types/interfaces/childstate'; 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, ContractCallRequest, ContractExecResult, ContractExecResultErr, ContractExecResultErrModule, ContractExecResultOk, ContractExecResultResult, ContractExecResultSuccessTo255, ContractExecResultSuccessTo260, ContractExecResultTo255, ContractExecResultTo260, ContractExecResultTo267, ContractInfo, ContractInstantiateResult, ContractInstantiateResultTo267, ContractStorageKey, DeletedContract, ExecReturnValue, Gas, HostFnWeights, HostFnWeightsTo264, InstantiateRequest, InstantiateReturnValue, InstantiateReturnValueTo267, InstructionWeights, Limits, LimitsTo264, PrefabWasmModule, RentProjection, Schedule, ScheduleTo212, ScheduleTo258, ScheduleTo264, SeedOf, TombstoneContractInfo, TrieId } from '@polkadot/types/interfaces/contracts'; +import type { AliveContractInfo, CodeHash, ContractCallRequest, ContractExecResult, ContractExecResultErr, ContractExecResultErrModule, ContractExecResultOk, ContractExecResultResult, ContractExecResultSuccessTo255, ContractExecResultSuccessTo260, ContractExecResultTo255, ContractExecResultTo260, ContractExecResultTo267, ContractInfo, ContractInstantiateResult, ContractInstantiateResultTo267, ContractStorageKey, DeletedContract, ExecReturnValue, Gas, HostFnWeights, HostFnWeightsTo264, InstantiateRequest, InstantiateReturnValue, InstantiateReturnValueTo267, InstructionWeights, Limits, LimitsTo264, PrefabWasmModule, RentProjection, Schedule, ScheduleTo212, ScheduleTo258, ScheduleTo264, SeedOf, StorageDeposit, TombstoneContractInfo, TrieId } from '@polkadot/types/interfaces/contracts'; import type { ContractConstructorSpecLatest, ContractConstructorSpecV0, ContractConstructorSpecV2, ContractContractSpecV0, ContractContractSpecV2, ContractCryptoHasher, ContractDiscriminant, ContractDisplayName, ContractEventParamSpecLatest, ContractEventParamSpecV0, ContractEventParamSpecV2, ContractEventSpecLatest, ContractEventSpecV0, ContractEventSpecV2, ContractLayoutArray, ContractLayoutCell, ContractLayoutEnum, ContractLayoutHash, ContractLayoutHashingStrategy, ContractLayoutKey, ContractLayoutStruct, ContractLayoutStructField, ContractMessageParamSpecLatest, ContractMessageParamSpecV0, ContractMessageParamSpecV2, ContractMessageSpecLatest, ContractMessageSpecV0, ContractMessageSpecV2, ContractMetadata, ContractMetadataLatest, ContractMetadataV0, ContractMetadataV1, ContractMetadataV2, ContractProject, ContractProjectContract, ContractProjectInfo, ContractProjectSource, ContractProjectV0, ContractSelector, ContractStorageLayout, ContractTypeSpec } from '@polkadot/types/interfaces/contractsAbi'; import type { FundIndex, FundInfo, LastContribution, TrieIndex } from '@polkadot/types/interfaces/crowdloan'; import type { ConfigData, MessageId, OverweightIndex, PageCounter, PageIndexData } from '@polkadot/types/interfaces/cumulus'; @@ -914,6 +914,7 @@ declare module '@polkadot/types/types/registry' { StatementKind: StatementKind; StorageChangeSet: StorageChangeSet; StorageData: StorageData; + StorageDeposit: StorageDeposit; StorageEntryMetadataLatest: StorageEntryMetadataLatest; StorageEntryMetadataV10: StorageEntryMetadataV10; StorageEntryMetadataV11: StorageEntryMetadataV11; diff --git a/packages/types/src/interfaces/contracts/definitions.ts b/packages/types/src/interfaces/contracts/definitions.ts index 24959d7dbf..9dd5c36298 100644 --- a/packages/types/src/interfaces/contracts/definitions.ts +++ b/packages/types/src/interfaces/contracts/definitions.ts @@ -28,6 +28,7 @@ export default { dest: 'AccountId', value: 'Balance', gasLimit: 'u64', + storageDepositLimit: 'Option', inputData: 'Bytes' }, ContractExecResultSuccessTo255: { @@ -82,6 +83,7 @@ export default { ContractExecResult: { gasConsumed: 'u64', gasRequired: 'u64', + storageDeposit: 'StorageDeposit', debugMessage: 'Text', result: 'ContractExecResultResult' }, @@ -206,6 +208,7 @@ export default { origin: 'AccountId', value: 'Balance', gasLimit: 'Gas', + storageDepositLimit: 'Option', code: 'Bytes', data: 'Bytes', salt: 'Bytes' @@ -371,6 +374,12 @@ export default { hostFnWeights: 'HostFnWeights' }, SeedOf: 'Hash', + StorageDeposit: { + _enum: { + Refund: 'Balance', + Charge: 'Balance' + } + }, TombstoneContractInfo: 'Hash', TrieId: 'Bytes' } diff --git a/packages/types/src/interfaces/contracts/types.ts b/packages/types/src/interfaces/contracts/types.ts index 9bbbd108e7..089f24690c 100644 --- a/packages/types/src/interfaces/contracts/types.ts +++ b/packages/types/src/interfaces/contracts/types.ts @@ -26,6 +26,7 @@ export interface ContractCallRequest extends Struct { readonly dest: AccountId; readonly value: Balance; readonly gasLimit: u64; + readonly storageDepositLimit: Option; readonly inputData: Bytes; } @@ -33,6 +34,7 @@ export interface ContractCallRequest extends Struct { export interface ContractExecResult extends Struct { readonly gasConsumed: u64; readonly gasRequired: u64; + readonly storageDeposit: StorageDeposit; readonly debugMessage: Text; readonly result: ContractExecResultResult; } @@ -259,6 +261,7 @@ export interface InstantiateRequest extends Struct { readonly origin: AccountId; readonly value: Balance; readonly gasLimit: Gas; + readonly storageDepositLimit: Option; readonly code: Bytes; readonly data: Bytes; readonly salt: Bytes; @@ -436,6 +439,15 @@ export interface ScheduleTo264 extends Struct { /** @name SeedOf */ export interface SeedOf extends Hash {} +/** @name StorageDeposit */ +export interface StorageDeposit extends Enum { + readonly isRefund: boolean; + readonly asRefund: Balance; + readonly isCharge: boolean; + readonly asCharge: Balance; + readonly type: 'Refund' | 'Charge'; +} + /** @name TombstoneContractInfo */ export interface TombstoneContractInfo extends Hash {}