import "../../_dnt.polyfills.js"; import { AccountId, NumberOrHex, SerdeEnum, SerdeResult } from "./utils.js"; /** A struct that encodes RPC parameters required for a call to a smart-contract. */ export interface CallRequest { origin: AccountId; dest: AccountId; value: NumberOrHex; gasLimit: NumberOrHex; storageDepositLimit: NumberOrHex | undefined; inputData: string; } /** * Result type of a `bare_call` or `bare_instantiate` call. * * It contains the execution result together with some auxiliary information. */ export interface ContractResult { /** How much gas was consumed during execution. */ gasConsumed: number; /** * How much gas is required as gas limit in order to execute this call. * * This value should be used to determine the gas limit for on-chain execution. * * # Note * * This can only different from [`Self::gas_consumed`] when weight pre charging * is used. Currently, only `seal_call_runtime` makes use of pre charging. * Additionally, any `seal_call` or `seal_instantiate` makes use of pre-charging * when a non-zero `gas_limit` argument is supplied. */ gasRequired: number; /** * How much balance was deposited and reserved during execution in order to pay for storage. * * The storage deposit is never actually charged from the caller in case of [`Self::result`] * is `Err`. This is because on error all storage changes are rolled back. */ storageDeposit: StorageDeposit; /** * An optional debug message. This message is only filled when explicitly requested * by the code that calls into the contract. Otherwise it is empty. * * The contained bytes are valid UTF-8. This is not declared as `String` because * this type is not allowed within the runtime. * * Clients should not make any assumptions about the format of the buffer. * They should just display it as-is. It is **not** only a collection of log lines * provided by a contract but a formatted buffer with different sections. * * # Note * * The debug message is never generated during on-chain execution. It is reserved for * RPC calls. */ debugMessage: string; /** The execution result of the wasm code. */ result: R; } /** The amount of balance that was either charged or refunded in order to pay for storage. */ export type StorageDeposit = SerdeEnum<{ /** * The transaction reduced storage consumption. * * This means that the specified amount of balance was transferred from the involved * contracts to the call origin. */ Refund: NumberOrHex; /** * The transaction increased overall storage usage. * * This means that the specified amount of balance was transferred from the call origin * to the contracts involved. */ Charge: NumberOrHex; }>; /** Flags used by a contract to customize exit behavior. */ export declare enum ReturnFlags { REVERT = 1 } /** Output of a contract call or instantiation which ran to completion. */ export interface ExecReturnValue { /** Flags passed along by `seal_return`. Empty when `seal_return` was never called. */ flags: ReturnFlags; /** Buffer passed along by `seal_return`. Empty when `seal_return` was never called. */ data: string; } /** Reason why a dispatch call failed. */ export type DispatchError = SerdeEnum<{ /** Some error occurred. */ Other: string; /** Failed to lookup some data. */ CannotLookup: void; /** A bad origin. */ BadOrigin: void; /** A custom error in a module. */ Module: ModuleError; /** At least one consumer is remaining so the account cannot be destroyed. */ ConsumerRemaining: void; /** There are no providers so the account cannot be created. */ NoProviders: void; /** There are too many consumers so the account cannot be created. */ TooManyConsumers: void; /** An error to do with tokens. */ Token: TokenError; /** An arithmetic error. */ Arithmetic: ArithmeticError; /** * The number of transactional layers has been reached, or we are not in a transactional * layer. */ Transactional: TransactionalError; }>; /** Reason why a pallet call failed. */ export type ModuleError = { /** Module index, matching the metadata module index. */ index: number; /** Module specific error value. */ error: number; /** Optional error message. */ message: string | undefined; }; /** Arithmetic errors. */ export type ArithmeticError = SerdeEnum<{ /** Underflow. */ Underflow: void; /** Overflow. */ Overflow: void; /** Division by zero. */ DivisionByZero: void; }>; /** Description of what went wrong when trying to complete an operation on a token. */ export type TokenError = SerdeEnum<{ /** Funds are unavailable. */ NoFunds: void; /** Account that must exist would die. */ WouldDie: void; /** Account cannot exist with the funds that would be given. */ BelowMinimum: void; /** Account cannot be created. */ CannotCreate: void; /** The asset in question is unknown. */ UnknownAsset: void; /** Funds exist but are frozen. */ Frozen: void; /** Operation is not supported by the asset. */ Unsupported: void; }>; /** Errors related to transactional storage layers. */ export type TransactionalError = SerdeEnum<{ /** Too many transactional layers have been spawned. */ LimitReached: void; /** A transactional layer was expected, but does not exist. */ NoLayer: void; }>; /** Reference to an existing code hash or a new wasm module */ export type Code = SerdeEnum<{ /** A wasm module as raw bytes. */ upload: string; /** The code hash of an on-chain wasm blob. */ existing: string; }>; /** A struct that encodes RPC parameters required to instantiate a new smart-contract. */ export interface InstantiateRequest { origin: AccountId; value: NumberOrHex; gasLimit: NumberOrHex; storageDepositLimit: NumberOrHex | undefined; code: Code; data: string; salt: string; } /** A struct that encodes RPC parameters required for a call to upload a new code. */ export interface CodeUploadRequest { origin: AccountId; code: string; storageDepositLimit: NumberOrHex | undefined; } /** The result of successfully uploading a contract. */ export interface CodeUploadReturnValue { /** The key under which the new code is stored. */ codeHash: string; /** The deposit that was reserved at the caller. Is zero when the code already existed. */ deposit: NumberOrHex; } /** The result of a successful contract instantiation. */ export interface InstantiateReturnValue { /** The output of the called constructor. */ result: ExecReturnValue; /** The account id of the new contract. */ account_id: AccountId; } export type ContractsCalls = { /** * Executes a call to a contract. * * This call is performed locally without submitting any transactions. Thus executing this * won't change any state. Nonetheless, the calling state-changing contracts is still possible. * * This method is useful for calling getter-like methods on contracts or to dry-run a * a contract call in order to determine the `gas_limit`. */ contracts_call(callRequest: CallRequest, at?: string): ContractResult>; /** * Instantiate a new contract. * * This instantiate is performed locally without submitting any transactions. Thus the contract * is not actually created. * * This method is useful for UIs to dry-run contract instantiations. */ contracts_instantiate(instantiateRequest: InstantiateRequest): ContractResult>; /** * Upload new code without instantiating a contract from it. * * This upload is performed locally without submitting any transactions. Thus executing this * won't change any state. * * This method is useful for UIs to dry-run code upload. */ contracts_upload_code(uploadRequest: CodeUploadRequest, at?: string): SerdeResult; /** * Returns the value under a specified storage `key` in a contract given by `address` param, * or `None` if it is not set. */ contracts_getStorage(accountId: AccountId, key: string, aat?: string): string | null; };