/// import { AssetDef } from "algosdk"; import { LogicSig } from "./logicsig"; import type { AccountAddress, ASADeploymentFlags, AssetHoldingM, Context, ExecParams, SSCAttributesM, SSCDeploymentFlags, SSCOptionalFlags, StackElem, StoreAccountI, Txn, TxParams } from "./types"; import { ExecutionMode } from "./types"; export declare class Runtime { /** * We are using Maps instead of algosdk arrays * because of faster and easy querying. * This way when querying, instead of traversing the whole object, * we can get the value directly from Map * Note: Runtime operates on `store`, it doesn't operate on `ctx`. */ private store; ctx: Context; private appCounter; private assetCounter; private round; private timestamp; private readonly loadedAssetsDefs; constructor(accounts: StoreAccountI[]); /** * asserts if account is defined. * @param a account * @param line line number in TEAL file * Note: if user is accessing this function directly through runtime, * the line number is unknown */ assertAccountDefined(address: string, a?: StoreAccountI, line?: number): StoreAccountI; /** * asserts if account address is defined * @param addr account address * @param line line number in TEAL file * Note: if user is accessing this function directly through runtime, * the line number is unknown */ assertAddressDefined(addr: string | undefined, line?: number): string; /** * asserts if application exists in state * @param app application * @param appId application index * @param line line number in TEAL file * Note: if user is accessing this function directly through runtime, * the line number is unknown */ assertAppDefined(appId: number, app?: SSCAttributesM, line?: number): SSCAttributesM; /** * asserts if asset exists in state * @param assetId asset index * @param assetDef asset definitions * @param line line number * Note: if user is accessing this function directly through runtime, * the line number is unknown */ assertAssetDefined(assetId: number, assetDef?: AssetDef, line?: number): AssetDef; /** * Asserts if correct transaction parameters are passed * @param txnParams Transaction Parameters */ assertAmbiguousTxnParams(txnParams: ExecParams): void; /** * Validate first and last rounds of transaction using current round * @param gtxns transactions */ validateTxRound(gtxns: Txn[]): void; /** * set current round with timestamp for a block * @param r current round * @param timestamp block's timestamp */ setRoundAndTimestamp(r: number, timestamp: number): void; /** * Return current round */ getRound(): number; /** * Return current timestamp */ getTimestamp(): number; /** * Fetches app from `this.store` * @param appId Application Index */ getApp(appId: number): SSCAttributesM; /** * Fetches account from `this.store` * @param address account address */ getAccount(address: string): StoreAccountI; /** * Fetches global state value for key present in creator's global state * for given appId, returns undefined otherwise * @param appId: current application id * @param key: key to fetch value of from local state */ getGlobalState(appId: number, key: Uint8Array | string): StackElem | undefined; /** * Fetches local state for account address and application index * @param appId application index * @param accountAddr address for which local state needs to be retrieved * @param key: key to fetch value of from local state */ getLocalState(appId: number, accountAddr: string, key: Uint8Array | string): StackElem | undefined; /** * Returns asset creator account or throws error is it doesn't exist * @param Asset Index */ getAssetAccount(assetId: number): StoreAccountI; /** * Returns Asset Definitions * @param assetId Asset Index */ getAssetDef(assetId: number): AssetDef; /** * Setup initial accounts as {address: SDKAccount}. This should be called only when initializing Runtime. * @param accounts: array of account info's */ initializeAccounts(accounts: StoreAccountI[]): void; /** * Creates new transaction object (tx, gtxs) from given txnParams * @param txnParams : Transaction parameters for current txn or txn Group * @returns: [current transaction, transaction group] */ createTxnContext(txnParams: ExecParams | ExecParams[]): [Txn, Txn[]]; mkAssetCreateTx(name: string, flags: ASADeploymentFlags, asaDef: AssetDef): void; /** * Add Asset in Runtime * @param name ASA name * @param flags ASA Deployment Flags */ addAsset(name: string, flags: ASADeploymentFlags): number; /** * Asset Opt-In for account in Runtime * @param assetIndex Asset Index * @param address Account address to opt-into asset * @param flags Transaction Parameters */ optIntoASA(assetIndex: number, address: AccountAddress, flags: TxParams): void; /** * Returns Asset Holding from an account * @param assetIndex Asset Index * @param address address of account to get holding from */ getAssetHolding(assetIndex: number, address: AccountAddress): AssetHoldingM; addCtxAppCreateTxn(flags: SSCDeploymentFlags, payFlags: TxParams): void; /** * creates new application and returns application id * Note: In this function we are operating on ctx to ensure that * the states are updated correctly * - First we are setting ctx according to application * - Second we run the TEAL code * - Finally if run is successful we update the store. * @param flags SSCDeployment flags * @param payFlags Transaction parameters * @param approvalProgram application approval program * @param clearProgram application clear program * NOTE - approval and clear program must be the TEAL code as string (not compiled code) */ addApp(flags: SSCDeploymentFlags, payFlags: TxParams, approvalProgram: string, clearProgram: string): number; addCtxOptInTx(senderAddr: string, appId: number, payFlags: TxParams, flags: SSCOptionalFlags): void; /** * Account address opt-in for application Id * @param accountAddr Account address * @param appId Application Id * @param flags Stateful smart contract transaction optional parameters (accounts, args..) * @param payFlags Transaction Parameters */ optInToApp(accountAddr: string, appId: number, flags: SSCOptionalFlags, payFlags: TxParams): void; addCtxAppUpdateTx(senderAddr: string, appId: number, payFlags: TxParams, flags: SSCOptionalFlags): void; /** * Update application * @param senderAddr sender address * @param appId application Id * @param approvalProgram new approval program * @param clearProgram new clear program * @param payFlags Transaction parameters * @param flags Stateful smart contract transaction optional parameters (accounts, args..) * NOTE - approval and clear program must be the TEAL code as string */ updateApp(senderAddr: string, appId: number, approvalProgram: string, clearProgram: string, payFlags: TxParams, flags: SSCOptionalFlags): void; assertMinBalance(amt: bigint, address: string): void; /** * Returns logic signature * @param program TEAL code * @param args arguments passed */ getLogicSig(program: string, args: Uint8Array[]): LogicSig; /** * validate logic signature and teal logic * @param txnParam Transaction Parameters */ validateLsigAndRun(txnParam: ExecParams): void; /** * This function executes a transaction based on a smart * contract logic and updates state afterwards * @param txnParams : Transaction parameters * @param program : teal code as a string * @param args : external arguments to smart contract */ executeTx(txnParams: ExecParams | ExecParams[]): void; /** * This function executes TEAL code line by line * @param program : teal code as string * @param executionMode : execution Mode (Stateless or Stateful) * NOTE: Application mode is only supported in TEAL v2 */ run(program: string, executionMode: ExecutionMode): void; }