@algorandfoundation/algokit-utils 7.0.0 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +3 -3
  2. package/package.json +1 -1
  3. package/testing/test-logger.js +7 -5
  4. package/testing/test-logger.js.map +1 -1
  5. package/testing/test-logger.mjs +7 -5
  6. package/testing/test-logger.mjs.map +1 -1
  7. package/transaction/transaction.js +4 -4
  8. package/transaction/transaction.js.map +1 -1
  9. package/transaction/transaction.mjs +5 -5
  10. package/transaction/transaction.mjs.map +1 -1
  11. package/types/algorand-client-transaction-sender.js +7 -1
  12. package/types/algorand-client-transaction-sender.js.map +1 -1
  13. package/types/algorand-client-transaction-sender.mjs +7 -1
  14. package/types/algorand-client-transaction-sender.mjs.map +1 -1
  15. package/types/app-client.d.ts +12 -8
  16. package/types/app-client.js +6 -6
  17. package/types/app-client.js.map +1 -1
  18. package/types/app-client.mjs +7 -7
  19. package/types/app-client.mjs.map +1 -1
  20. package/types/app-factory.d.ts +30 -29
  21. package/types/app-factory.js +8 -0
  22. package/types/app-factory.js.map +1 -1
  23. package/types/app-factory.mjs +8 -0
  24. package/types/app-factory.mjs.map +1 -1
  25. package/types/app-manager.d.ts +2 -2
  26. package/types/app-manager.js +2 -1
  27. package/types/app-manager.js.map +1 -1
  28. package/types/app-manager.mjs +2 -1
  29. package/types/app-manager.mjs.map +1 -1
  30. package/types/composer.d.ts +20 -6
  31. package/types/composer.js +8 -10
  32. package/types/composer.js.map +1 -1
  33. package/types/composer.mjs +8 -10
  34. package/types/composer.mjs.map +1 -1
  35. package/types/config.d.ts +0 -4
  36. package/types/config.js.map +1 -1
  37. package/types/config.mjs.map +1 -1
  38. package/types/dispenser-client.js +3 -1
  39. package/types/dispenser-client.js.map +1 -1
  40. package/types/dispenser-client.mjs +3 -1
  41. package/types/dispenser-client.mjs.map +1 -1
  42. package/types/transaction.d.ts +1 -1
  43. package/util.d.ts +2 -0
  44. package/util.js +16 -0
  45. package/util.js.map +1 -1
  46. package/util.mjs +15 -1
  47. package/util.mjs.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"app-factory.mjs","sources":["../../src/types/app-factory.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { AlgorandClientInterface } from './algorand-client-interface'\nimport {\n AppCompilationResult,\n AppReturn,\n DELETABLE_TEMPLATE_NAME,\n SendAppTransactionResult,\n TealTemplateParams,\n UPDATABLE_TEMPLATE_NAME,\n} from './app'\nimport {\n ABIStruct,\n Arc56Contract,\n Arc56Method,\n getABIDecodedValue,\n getABITupleFromABIStruct,\n getArc56Method,\n getArc56ReturnValue,\n} from './app-arc56'\nimport {\n AppClient,\n AppClientBareCallParams,\n AppClientCompilationParams,\n AppClientMethodCallParams,\n AppClientParams,\n AppSourceMaps,\n ResolveAppClientByCreatorAndName,\n} from './app-client'\nimport {\n AppDeployParams,\n DeployAppDeleteMethodCall,\n DeployAppDeleteParams,\n DeployAppUpdateMethodCall,\n DeployAppUpdateParams,\n} from './app-deployer'\nimport { AppSpec } from './app-spec'\nimport { AppCreateMethodCall, AppCreateParams, AppMethodCall, AppMethodCallTransactionArgument, CommonAppCallParams } from './composer'\nimport { Expand } from './expand'\nimport { SendParams } from './transaction'\nimport SourceMap = algosdk.SourceMap\nimport OnApplicationComplete = algosdk.OnApplicationComplete\nimport ABIValue = algosdk.ABIValue\nimport TransactionSigner = algosdk.TransactionSigner\n\n/** Parameters to create an app client */\nexport interface AppFactoryParams {\n /** The ARC-56 or ARC-32 application spec as either:\n * * Parsed JSON ARC-56 `Contract`\n * * Parsed JSON ARC-32 `AppSpec`\n * * Raw JSON string (in either ARC-56 or ARC-32 format)\n */\n appSpec: Arc56Contract | AppSpec | string\n\n /** `AlgorandClient` instance */\n algorand: AlgorandClientInterface\n\n /**\n * Optional override for the app name; used for on-chain metadata and lookups.\n * Defaults to the ARC-32/ARC-56 app spec name.\n */\n appName?: string\n\n /** Optional address to use for the account to use as the default sender for calls. */\n defaultSender?: string\n\n /** Optional signer to use as the default signer for default sender calls (if not specified then the signer will be resolved from `AlgorandClient`). */\n defaultSigner?: TransactionSigner\n\n /** The version of app that is / will be deployed; defaults to 1.0 */\n version?: string\n\n /**\n * Whether or not the contract should have deploy-time immutability control set, undefined = ignore.\n * If specified here will get used in calls to `deploy` and `create` calls unless overridden in those calls.\n *\n * Useful if you want to vend multiple contracts from the same factory without specifying this value\n * for each call.\n */\n updatable?: boolean\n\n /**\n * Whether or not the contract should have deploy-time permanence control set, undefined = ignore.\n * If specified here will get used in calls to `deploy` and `create` calls unless overridden in those calls.\n *\n * Useful if you want to vend multiple contracts from the same factory without specifying this value\n * for each call.\n */\n deletable?: boolean\n\n /**\n * Optional deploy-time TEAL template replacement parameters.\n * If specified here will get used in calls to `deploy` and `create` calls unless overridden in those calls.\n *\n * Useful if you want to vend multiple contracts from the same factory without specifying this value\n * for each call.\n */\n deployTimeParams?: TealTemplateParams\n}\n\n/** onComplete parameter for a create app call */\nexport type CreateOnComplete = {\n onComplete?: Exclude<OnApplicationComplete, OnApplicationComplete.ClearStateOC>\n}\n\n/** Specifies a schema used for creating an app */\nexport type CreateSchema = {\n /** The state schema for the app. This is immutable once the app is created. By default uses the ARC32/ARC-56 spec. */\n schema?: {\n /** The number of integers saved in global state. */\n globalInts: number\n /** The number of byte slices saved in global state. */\n globalByteSlices: number\n /** The number of integers saved in local state. */\n localInts: number\n /** The number of byte slices saved in local state. */\n localByteSlices: number\n }\n /** Number of extra pages required for the programs.\n * Defaults to the number needed for the programs in this call if not specified.\n * This is immutable once the app is created. */\n extraProgramPages?: number\n}\n\n/** Params to specify a bare (raw) create call for an app */\nexport type AppFactoryCreateParams = Expand<AppClientBareCallParams & AppClientCompilationParams & CreateOnComplete & CreateSchema>\n\n/** Params to specify a create method call for an app */\nexport type AppFactoryCreateMethodCallParams = Expand<\n AppClientMethodCallParams & AppClientCompilationParams & CreateOnComplete & CreateSchema\n>\n\n/** Params to get an app client by ID from an app factory. */\nexport type AppFactoryAppClientParams = Expand<Omit<AppClientParams, 'algorand' | 'appSpec'>>\n\n/** Params to get an app client by creator address and name from an app factory. */\nexport type AppFactoryResolveAppClientByCreatorAndNameParams = Expand<Omit<ResolveAppClientByCreatorAndName, 'algorand' | 'appSpec'>>\n\n/** Parameters to define a deployment for an `AppFactory` */\nexport type AppFactoryDeployParams = Expand<\n Omit<AppDeployParams, 'createParams' | 'updateParams' | 'deleteParams' | 'metadata'> & {\n /** Create transaction parameters to use if a create needs to be issued as part of deployment */\n createParams?:\n | Expand<AppClientMethodCallParams & CreateOnComplete & CreateSchema>\n | Expand<AppClientBareCallParams & CreateOnComplete & CreateSchema>\n /** Update transaction parameters to use if a create needs to be issued as part of deployment */\n updateParams?: AppClientMethodCallParams | AppClientBareCallParams\n /** Delete transaction parameters to use if a create needs to be issued as part of deployment */\n deleteParams?: AppClientMethodCallParams | AppClientBareCallParams\n /**\n * Whether or not the contract should have deploy-time immutability control set.\n * `undefined` = use AppFactory constructor value if set or base it on the app spec.\n */\n updatable?: boolean\n /**\n * Whether or not the contract should have deploy-time permanence control set.\n * `undefined` = use AppFactory constructor value if set or base it on the app spec.\n */\n deletable?: boolean\n /** Override the app name for this deployment */\n appName?: string\n }\n>\n\n/**\n * ARC-56/ARC-32 app factory that, for a given app spec, allows you to create\n * and deploy one or more app instances and to create one or more app clients\n * to interact with those (or other) app instances.\n */\nexport class AppFactory {\n private _appSpec: Arc56Contract\n private _appName: string\n private _algorand: AlgorandClientInterface\n private _version: string\n private _defaultSender?: string\n private _defaultSigner?: TransactionSigner\n private _deployTimeParams?: TealTemplateParams\n private _updatable?: boolean\n private _deletable?: boolean\n\n private _approvalSourceMap: SourceMap | undefined\n private _clearSourceMap: SourceMap | undefined\n\n private _paramsMethods: ReturnType<AppFactory['getParamsMethods']>\n\n constructor(params: AppFactoryParams) {\n this._appSpec = AppClient.normaliseAppSpec(params.appSpec)\n this._appName = params.appName ?? this._appSpec.name\n this._algorand = params.algorand\n this._version = params.version ?? '1.0'\n this._defaultSender = params.defaultSender\n this._defaultSigner = params.defaultSigner\n this._deployTimeParams = params.deployTimeParams\n this._updatable = params.updatable\n this._deletable = params.deletable\n this._paramsMethods = this.getParamsMethods()\n }\n\n /** The name of the app (from the ARC-32 / ARC-56 app spec or override). */\n public get appName() {\n return this._appName\n }\n\n /** The ARC-56 app spec being used */\n get appSpec() {\n return this._appSpec\n }\n\n /** Return the algorand client this factory is using. */\n get algorand() {\n return this._algorand\n }\n\n /** Get parameters to create transactions (create and deploy related calls) for the current app.\n *\n * A good mental model for this is that these parameters represent a deferred transaction creation.\n * @example Create a transaction in the future using Algorand Client\n * ```typescript\n * const createAppParams = appFactory.params.create({method: 'create_method', args: [123, 'hello']})\n * // ...\n * await algorand.send.AppCreateMethodCall(createAppParams)\n * ```\n * @example Define a nested transaction as an ABI argument\n * ```typescript\n * const createAppParams = appFactory.params.create({method: 'create_method', args: [123, 'hello']})\n * await appClient.send.call({method: 'my_method', args: [createAppParams]})\n * ```\n */\n get params() {\n return this._paramsMethods\n }\n\n /** Create transactions for the current app */\n readonly createTransaction = {\n /** Create bare (raw) transactions for the current app */\n bare: {\n /** Create a create call transaction, including deploy-time TEAL template replacements and compilation if provided */\n create: async (params?: AppFactoryCreateParams) => {\n return this._algorand.createTransaction.appCreate(await this.params.bare.create(params))\n },\n },\n\n /** Create a create ABI call transaction, including deploy-time TEAL template replacements and compilation if provided */\n create: async (params: AppFactoryCreateMethodCallParams) => {\n return this._algorand.createTransaction.appCreateMethodCall(await this.params.create(params))\n },\n }\n\n /** Send transactions to the current app */\n readonly send = {\n /** Send bare (raw) transactions for the current app */\n bare: {\n create: async (params?: AppFactoryCreateParams & SendParams) => {\n const updatable = params?.updatable ?? this._updatable\n const deletable = params?.deletable ?? this._deletable\n const deployTimeParams = params?.deployTimeParams ?? this._deployTimeParams\n const compiled = await this.compile({ deployTimeParams, updatable, deletable })\n const result = await this.handleCallErrors(async () => ({\n ...(await this._algorand.send.appCreate(await this.params.bare.create({ ...params, updatable, deletable, deployTimeParams }))),\n return: undefined,\n }))\n return {\n appClient: this.getAppClientById({\n appId: result.appId,\n }),\n result: {\n ...result,\n ...(compiled as Partial<AppCompilationResult>),\n },\n }\n },\n },\n\n /**\n * Creates an instance of the app and returns the result of the creation\n * transaction and an app client to interact with that app instance.\n *\n * Performs deploy-time TEAL template placeholder substitutions (if specified).\n * @param params The parameters to create the app\n * @returns The app client and the result of the creation transaction\n */\n create: async (params: AppFactoryCreateMethodCallParams & SendParams) => {\n const updatable = params?.updatable ?? this._updatable\n const deletable = params?.deletable ?? this._deletable\n const deployTimeParams = params?.deployTimeParams ?? this._deployTimeParams\n const compiled = await this.compile({ deployTimeParams, updatable, deletable })\n const result = await this.handleCallErrors(async () =>\n this.parseMethodCallReturn(\n this._algorand.send.appCreateMethodCall(await this.params.create({ ...params, updatable, deletable, deployTimeParams })),\n getArc56Method(params.method, this._appSpec),\n ),\n )\n return {\n appClient: this.getAppClientById({\n appId: result.appId,\n }),\n result: {\n ...result,\n ...(compiled as Partial<AppCompilationResult>),\n },\n }\n },\n }\n\n /**\n * Idempotently deploy (create if not exists, update if changed) an app against the given name for the given creator account, including deploy-time TEAL template placeholder substitutions (if specified).\n *\n * **Note:** When using the return from this function be sure to check `operationPerformed` to get access to various return properties like `transaction`, `confirmation` and `deleteResult`.\n *\n * **Note:** if there is a breaking state schema change to an existing app (and `onSchemaBreak` is set to `'replace'`) the existing app will be deleted and re-created.\n *\n * **Note:** if there is an update (different TEAL code) to an existing app (and `onUpdate` is set to `'replace'`) the existing app will be deleted and re-created.\n * @param params The arguments to control the app deployment\n * @returns The app client and the result of the deployment\n */\n public async deploy(params: AppFactoryDeployParams) {\n const updatable = params.updatable ?? this._updatable ?? this.getDeployTimeControl('updatable')\n const deletable = params.deletable ?? this._deletable ?? this.getDeployTimeControl('deletable')\n const deployTimeParams = params.deployTimeParams ?? this._deployTimeParams\n const compiled = await this.compile({ deployTimeParams, updatable, deletable })\n const deployResult = await this._algorand.appDeployer.deploy({\n ...params,\n createParams: await (params.createParams && 'method' in params.createParams\n ? this.params.create({ ...params.createParams, updatable, deletable, deployTimeParams })\n : this.params.bare.create({ ...params.createParams, updatable, deletable, deployTimeParams })),\n updateParams:\n params.updateParams && 'method' in params.updateParams\n ? this.params.deployUpdate(params.updateParams)\n : this.params.bare.deployUpdate(params.updateParams),\n deleteParams:\n params.deleteParams && 'method' in params.deleteParams\n ? this.params.deployDelete(params.deleteParams)\n : this.params.bare.deployDelete(params.deleteParams),\n metadata: {\n name: params.appName ?? this._appName,\n version: this._version,\n updatable,\n deletable,\n },\n })\n const appClient = this.getAppClientById({\n appId: deployResult.appId,\n appName: params.appName,\n })\n const result = {\n ...deployResult,\n ...(compiled as Partial<AppCompilationResult>),\n }\n return {\n appClient,\n result: {\n ...result,\n return:\n 'return' in result\n ? result.operationPerformed === 'update'\n ? params.updateParams && 'method' in params.updateParams\n ? getArc56ReturnValue(result.return, getArc56Method(params.updateParams.method, this._appSpec), this._appSpec.structs)\n : undefined\n : params.createParams && 'method' in params.createParams\n ? getArc56ReturnValue(result.return, getArc56Method(params.createParams.method, this._appSpec), this._appSpec.structs)\n : undefined\n : undefined,\n deleteReturn:\n 'deleteReturn' in result && params.deleteParams && 'method' in params.deleteParams\n ? getArc56ReturnValue(result.deleteReturn, getArc56Method(params.deleteParams.method, this._appSpec), this._appSpec.structs)\n : undefined,\n },\n }\n }\n\n /**\n * Returns a new `AppClient` client for an app instance of the given ID.\n *\n * Automatically populates appName, defaultSender and source maps from the factory\n * if not specified in the params.\n * @param params The parameters to create the app client\n * @returns The `AppClient`\n */\n public getAppClientById(params: AppFactoryAppClientParams) {\n return new AppClient({\n ...params,\n algorand: this._algorand,\n appSpec: this._appSpec,\n appName: params.appName ?? this._appName,\n defaultSender: params.defaultSender ?? this._defaultSender,\n defaultSigner: params.defaultSigner ?? this._defaultSigner,\n approvalSourceMap: params.approvalSourceMap ?? this._approvalSourceMap,\n clearSourceMap: params.clearSourceMap ?? this._clearSourceMap,\n })\n }\n\n /**\n * Returns a new `AppClient` client, resolving the app by creator address and name\n * using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).\n *\n * Automatically populates appName, defaultSender and source maps from the factory\n * if not specified in the params.\n * @param params The parameters to create the app client\n * @returns The `AppClient`\n */\n public getAppClientByCreatorAndName(params: AppFactoryResolveAppClientByCreatorAndNameParams) {\n return AppClient.fromCreatorAndName({\n ...params,\n algorand: this._algorand,\n appSpec: this._appSpec,\n appName: params.appName ?? this._appName,\n defaultSender: params.defaultSender ?? this._defaultSender,\n approvalSourceMap: params.approvalSourceMap ?? this._approvalSourceMap,\n clearSourceMap: params.clearSourceMap ?? this._clearSourceMap,\n })\n }\n\n /**\n * Takes an error that may include a logic error from a call to the current app and re-exposes the\n * error to include source code information via the source map and ARC-56 spec.\n * @param e The error to parse\n * @param isClearStateProgram Whether or not the code was running the clear state program (defaults to approval program)\n * @returns The new error, or if there was no logic error or source map then the wrapped error with source details\n */\n exposeLogicError(e: Error, isClearStateProgram?: boolean): Error {\n return AppClient.exposeLogicError(e, this._appSpec, {\n isClearStateProgram,\n approvalSourceMap: this._approvalSourceMap,\n clearSourceMap: this._clearSourceMap,\n })\n }\n\n /**\n * Export the current source maps for the app.\n * @returns The source maps\n */\n exportSourceMaps(): AppSourceMaps {\n if (!this._approvalSourceMap || !this._clearSourceMap) {\n throw new Error(\n \"Unable to export source maps; they haven't been loaded into this client - you need to call create, update, or deploy first\",\n )\n }\n\n return {\n approvalSourceMap: this._approvalSourceMap,\n clearSourceMap: this._clearSourceMap,\n }\n }\n\n /**\n * Import source maps for the app.\n * @param sourceMaps The source maps to import\n */\n importSourceMaps(sourceMaps: AppSourceMaps) {\n this._approvalSourceMap = new SourceMap(sourceMaps.approvalSourceMap)\n this._clearSourceMap = new SourceMap(sourceMaps.clearSourceMap)\n }\n\n private getDeployTimeControl(control: 'updatable' | 'deletable'): boolean | undefined {\n const approval = this._appSpec.source?.approval ? Buffer.from(this._appSpec.source.approval, 'base64').toString('utf-8') : undefined\n // variable not present, so unknown control value\n if (!approval || !approval.includes(control === 'updatable' ? UPDATABLE_TEMPLATE_NAME : DELETABLE_TEMPLATE_NAME)) return undefined\n\n // A call is present and configured\n return (\n this._appSpec.bareActions.call.includes(control === 'updatable' ? 'UpdateApplication' : 'DeleteApplication') ||\n Object.values(this._appSpec.methods).some((c) =>\n c.actions.call.includes(control === 'updatable' ? 'UpdateApplication' : 'DeleteApplication'),\n )\n )\n }\n\n private getParamsMethods() {\n return {\n /** Return params for a create ABI call, including deploy-time TEAL template replacements and compilation if provided */\n create: async (params: AppFactoryCreateMethodCallParams) => {\n const compiled = await this.compile({ ...params, deployTimeParams: params.deployTimeParams ?? this._deployTimeParams })\n return this.getABIParams(\n {\n ...params,\n deployTimeParams: params.deployTimeParams ?? this._deployTimeParams,\n schema: params.schema ?? {\n globalByteSlices: this._appSpec.state.schema.global.bytes,\n globalInts: this._appSpec.state.schema.global.ints,\n localByteSlices: this._appSpec.state.schema.local.bytes,\n localInts: this._appSpec.state.schema.local.ints,\n },\n approvalProgram: compiled.approvalProgram,\n clearStateProgram: compiled.clearStateProgram,\n },\n params.onComplete ?? OnApplicationComplete.NoOpOC,\n ) satisfies AppCreateMethodCall\n },\n /** Return params for a deployment update ABI call */\n deployUpdate: (params: AppClientMethodCallParams) => {\n return this.getABIParams(params, OnApplicationComplete.UpdateApplicationOC) satisfies DeployAppUpdateMethodCall\n },\n /** Return params for a deployment delete ABI call */\n deployDelete: (params: AppClientMethodCallParams) => {\n return this.getABIParams(params, OnApplicationComplete.DeleteApplicationOC) satisfies DeployAppDeleteMethodCall\n },\n bare: {\n /** Return params for a create bare call, including deploy-time TEAL template replacements and compilation if provided */\n create: async (params?: AppFactoryCreateParams) => {\n return this.getBareParams(\n {\n ...params,\n deployTimeParams: params?.deployTimeParams ?? this._deployTimeParams,\n schema: params?.schema ?? {\n globalByteSlices: this._appSpec.state.schema.global.bytes,\n globalInts: this._appSpec.state.schema.global.ints,\n localByteSlices: this._appSpec.state.schema.local.bytes,\n localInts: this._appSpec.state.schema.local.ints,\n },\n ...(await this.compile({ ...params, deployTimeParams: params?.deployTimeParams ?? this._deployTimeParams })),\n },\n params?.onComplete ?? OnApplicationComplete.NoOpOC,\n ) satisfies AppCreateParams\n },\n /** Return params for a deployment update bare call */\n deployUpdate: (params?: AppClientBareCallParams) => {\n return this.getBareParams(params, OnApplicationComplete.UpdateApplicationOC) satisfies DeployAppUpdateParams\n },\n /** Return params for a deployment delete bare call */\n deployDelete: (params?: AppClientBareCallParams) => {\n return this.getBareParams(params, OnApplicationComplete.DeleteApplicationOC) satisfies DeployAppDeleteParams\n },\n },\n }\n }\n\n /** Make the given call and catch any errors, augmenting with debugging information before re-throwing. */\n private async handleCallErrors<TResult>(call: () => Promise<TResult>) {\n try {\n return await call()\n } catch (e) {\n throw this.exposeLogicError(e as Error)\n }\n }\n\n /**\n * Compiles the approval and clear state programs (if TEAL templates provided),\n * performing any provided deploy-time parameter replacement and stores\n * the source maps.\n *\n * If no TEAL templates provided it will use any byte code provided in the app spec.\n *\n * Will store any generated source maps for later use in debugging.\n */\n public async compile(compilation?: AppClientCompilationParams) {\n const result = await AppClient.compile(this._appSpec, this._algorand.app, compilation)\n\n if (result.compiledApproval) {\n this._approvalSourceMap = result.compiledApproval.sourceMap\n }\n if (result.compiledClear) {\n this._clearSourceMap = result.compiledClear.sourceMap\n }\n\n return result\n }\n\n private getBareParams<TParams extends { sender?: string } | undefined, TOnComplete extends OnApplicationComplete>(\n params: TParams,\n onComplete: TOnComplete,\n ) {\n return {\n ...params,\n sender: this.getSender(params?.sender),\n onComplete,\n }\n }\n\n private getABIParams<\n TParams extends { method: string; sender?: string; args?: AppClientMethodCallParams['args'] },\n TOnComplete extends OnApplicationComplete,\n >(params: TParams, onComplete: TOnComplete) {\n return {\n ...params,\n sender: this.getSender(params.sender),\n method: getArc56Method(params.method, this._appSpec),\n args: this.getCreateABIArgsWithDefaultValues(params.method, params.args),\n onComplete,\n }\n }\n\n private getCreateABIArgsWithDefaultValues(\n methodNameOrSignature: string,\n args: AppClientMethodCallParams['args'] | undefined,\n ): AppMethodCall<CommonAppCallParams>['args'] {\n const m = getArc56Method(methodNameOrSignature, this._appSpec)\n return args?.map((a, i) => {\n const arg = m.args[i]\n if (a !== undefined) {\n // If a struct then convert to tuple for the underlying call\n return arg.struct && typeof a === 'object' && !Array.isArray(a)\n ? getABITupleFromABIStruct(a as ABIStruct, this._appSpec.structs[arg.struct], this._appSpec.structs)\n : (a as ABIValue | AppMethodCallTransactionArgument)\n }\n const defaultValue = arg.defaultValue\n if (defaultValue) {\n switch (defaultValue.source) {\n case 'literal':\n return getABIDecodedValue(Buffer.from(defaultValue.data, 'base64'), m.method.args[i].type, this._appSpec.structs) as ABIValue\n default:\n throw new Error(`Can't provide default value for ${defaultValue.source} for a contract creation call`)\n }\n }\n throw new Error(`No value provided for required argument ${arg.name ?? `arg${i + 1}`} in call to method ${m.name}`)\n })\n }\n\n /** Returns the sender for a call, using the `defaultSender`\n * if none provided and throws an error if neither provided */\n private getSender(sender: string | undefined): string {\n if (!sender && !this._defaultSender) {\n throw new Error(`No sender provided and no default sender present in app client for call to app ${this._appName}`)\n }\n return sender ?? this._defaultSender!\n }\n\n /**\n * Checks for decode errors on the SendAppTransactionResult and maps the return value to the specified type\n * on the ARC-56 method.\n *\n * If the return type is a struct then the struct will be returned.\n *\n * @param result The SendAppTransactionResult to be mapped\n * @param method The method that was called\n * @returns The smart contract response with an updated return value\n */\n async parseMethodCallReturn<\n TReturn extends Uint8Array | ABIValue | ABIStruct | undefined,\n TResult extends SendAppTransactionResult = SendAppTransactionResult,\n >(result: Promise<TResult> | TResult, method: Arc56Method): Promise<Omit<TResult, 'return'> & AppReturn<TReturn>> {\n const resultValue = await result\n return { ...resultValue, return: getArc56ReturnValue(resultValue.return, method, this._appSpec.structs) }\n }\n}\n"],"names":[],"mappings":";;;;;AAuCA,IAAO,SAAS,GAAG,OAAO,CAA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,QAAA,MAAM,WAAW,GAAG,MAAM,MAAM;QAChC,OAAO,EAAE,GAAG,WAAW,EAAE,MAAM,EAAE,mBAAmB,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;;AAE5G;;;;"}
1
+ {"version":3,"file":"app-factory.mjs","sources":["../../src/types/app-factory.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { TransactionSignerAccount } from './account'\nimport { AlgorandClientInterface } from './algorand-client-interface'\nimport {\n AppCompilationResult,\n AppReturn,\n DELETABLE_TEMPLATE_NAME,\n SendAppTransactionResult,\n TealTemplateParams,\n UPDATABLE_TEMPLATE_NAME,\n} from './app'\nimport {\n ABIStruct,\n Arc56Contract,\n Arc56Method,\n getABIDecodedValue,\n getABITupleFromABIStruct,\n getArc56Method,\n getArc56ReturnValue,\n} from './app-arc56'\nimport {\n AppClient,\n AppClientBareCallParams,\n AppClientCompilationParams,\n AppClientMethodCallParams,\n AppClientParams,\n AppSourceMaps,\n ResolveAppClientByCreatorAndName,\n} from './app-client'\nimport {\n AppDeployParams,\n DeployAppDeleteMethodCall,\n DeployAppDeleteParams,\n DeployAppUpdateMethodCall,\n DeployAppUpdateParams,\n} from './app-deployer'\nimport { AppSpec } from './app-spec'\nimport { AppCreateMethodCall, AppCreateParams, AppMethodCall, AppMethodCallTransactionArgument, CommonAppCallParams } from './composer'\nimport { Expand } from './expand'\nimport { SendParams } from './transaction'\nimport SourceMap = algosdk.SourceMap\nimport OnApplicationComplete = algosdk.OnApplicationComplete\nimport ABIValue = algosdk.ABIValue\nimport TransactionSigner = algosdk.TransactionSigner\n\n/** Parameters to create an app client */\nexport interface AppFactoryParams {\n /** The ARC-56 or ARC-32 application spec as either:\n * * Parsed JSON ARC-56 `Contract`\n * * Parsed JSON ARC-32 `AppSpec`\n * * Raw JSON string (in either ARC-56 or ARC-32 format)\n */\n appSpec: Arc56Contract | AppSpec | string\n\n /** `AlgorandClient` instance */\n algorand: AlgorandClientInterface\n\n /**\n * Optional override for the app name; used for on-chain metadata and lookups.\n * Defaults to the ARC-32/ARC-56 app spec name.\n */\n appName?: string\n\n /** Optional address to use for the account to use as the default sender for calls. */\n defaultSender?: string\n\n /** Optional signer to use as the default signer for default sender calls (if not specified then the signer will be resolved from `AlgorandClient`). */\n defaultSigner?: TransactionSigner\n\n /** The version of app that is / will be deployed; defaults to 1.0 */\n version?: string\n\n /**\n * Whether or not the contract should have deploy-time immutability control set, undefined = ignore.\n * If specified here will get used in calls to `deploy` and `create` calls unless overridden in those calls.\n *\n * Useful if you want to vend multiple contracts from the same factory without specifying this value\n * for each call.\n */\n updatable?: boolean\n\n /**\n * Whether or not the contract should have deploy-time permanence control set, undefined = ignore.\n * If specified here will get used in calls to `deploy` and `create` calls unless overridden in those calls.\n *\n * Useful if you want to vend multiple contracts from the same factory without specifying this value\n * for each call.\n */\n deletable?: boolean\n\n /**\n * Optional deploy-time TEAL template replacement parameters.\n * If specified here will get used in calls to `deploy` and `create` calls unless overridden in those calls.\n *\n * Useful if you want to vend multiple contracts from the same factory without specifying this value\n * for each call.\n */\n deployTimeParams?: TealTemplateParams\n}\n\n/** onComplete parameter for a create app call */\nexport type CreateOnComplete = {\n onComplete?: Exclude<OnApplicationComplete, OnApplicationComplete.ClearStateOC>\n}\n\n/** Specifies a schema used for creating an app */\nexport type CreateSchema = {\n /** The state schema for the app. This is immutable once the app is created. By default uses the ARC32/ARC-56 spec. */\n schema?: {\n /** The number of integers saved in global state. */\n globalInts: number\n /** The number of byte slices saved in global state. */\n globalByteSlices: number\n /** The number of integers saved in local state. */\n localInts: number\n /** The number of byte slices saved in local state. */\n localByteSlices: number\n }\n /** Number of extra pages required for the programs.\n * Defaults to the number needed for the programs in this call if not specified.\n * This is immutable once the app is created. */\n extraProgramPages?: number\n}\n\n/** Params to specify a bare (raw) create call for an app */\nexport type AppFactoryCreateParams = Expand<AppClientBareCallParams & AppClientCompilationParams & CreateOnComplete & CreateSchema>\n\n/** Params to specify a create method call for an app */\nexport type AppFactoryCreateMethodCallParams = Expand<\n AppClientMethodCallParams & AppClientCompilationParams & CreateOnComplete & CreateSchema\n>\n\n/** Params to get an app client by ID from an app factory. */\nexport type AppFactoryAppClientParams = Expand<Omit<AppClientParams, 'algorand' | 'appSpec'>>\n\n/** Params to get an app client by creator address and name from an app factory. */\nexport type AppFactoryResolveAppClientByCreatorAndNameParams = Expand<Omit<ResolveAppClientByCreatorAndName, 'algorand' | 'appSpec'>>\n\n/** Parameters to define a deployment for an `AppFactory` */\nexport type AppFactoryDeployParams = Expand<\n Omit<AppDeployParams, 'createParams' | 'updateParams' | 'deleteParams' | 'metadata'> & {\n /** Create transaction parameters to use if a create needs to be issued as part of deployment */\n createParams?:\n | Expand<AppClientMethodCallParams & CreateOnComplete & CreateSchema>\n | Expand<AppClientBareCallParams & CreateOnComplete & CreateSchema>\n /** Update transaction parameters to use if a create needs to be issued as part of deployment */\n updateParams?: AppClientMethodCallParams | AppClientBareCallParams\n /** Delete transaction parameters to use if a create needs to be issued as part of deployment */\n deleteParams?: AppClientMethodCallParams | AppClientBareCallParams\n /**\n * Whether or not the contract should have deploy-time immutability control set.\n * `undefined` = use AppFactory constructor value if set or base it on the app spec.\n */\n updatable?: boolean\n /**\n * Whether or not the contract should have deploy-time permanence control set.\n * `undefined` = use AppFactory constructor value if set or base it on the app spec.\n */\n deletable?: boolean\n /** Override the app name for this deployment */\n appName?: string\n }\n>\n\n/**\n * ARC-56/ARC-32 app factory that, for a given app spec, allows you to create\n * and deploy one or more app instances and to create one or more app clients\n * to interact with those (or other) app instances.\n */\nexport class AppFactory {\n private _appSpec: Arc56Contract\n private _appName: string\n private _algorand: AlgorandClientInterface\n private _version: string\n private _defaultSender?: string\n private _defaultSigner?: TransactionSigner\n private _deployTimeParams?: TealTemplateParams\n private _updatable?: boolean\n private _deletable?: boolean\n\n private _approvalSourceMap: SourceMap | undefined\n private _clearSourceMap: SourceMap | undefined\n\n private _paramsMethods: ReturnType<AppFactory['getParamsMethods']>\n\n constructor(params: AppFactoryParams) {\n this._appSpec = AppClient.normaliseAppSpec(params.appSpec)\n this._appName = params.appName ?? this._appSpec.name\n this._algorand = params.algorand\n this._version = params.version ?? '1.0'\n this._defaultSender = params.defaultSender\n this._defaultSigner = params.defaultSigner\n this._deployTimeParams = params.deployTimeParams\n this._updatable = params.updatable\n this._deletable = params.deletable\n this._paramsMethods = this.getParamsMethods()\n }\n\n /** The name of the app (from the ARC-32 / ARC-56 app spec or override). */\n public get appName() {\n return this._appName\n }\n\n /** The ARC-56 app spec being used */\n get appSpec() {\n return this._appSpec\n }\n\n /** Return the algorand client this factory is using. */\n get algorand() {\n return this._algorand\n }\n\n /** Get parameters to create transactions (create and deploy related calls) for the current app.\n *\n * A good mental model for this is that these parameters represent a deferred transaction creation.\n * @example Create a transaction in the future using Algorand Client\n * ```typescript\n * const createAppParams = appFactory.params.create({method: 'create_method', args: [123, 'hello']})\n * // ...\n * await algorand.send.AppCreateMethodCall(createAppParams)\n * ```\n * @example Define a nested transaction as an ABI argument\n * ```typescript\n * const createAppParams = appFactory.params.create({method: 'create_method', args: [123, 'hello']})\n * await appClient.send.call({method: 'my_method', args: [createAppParams]})\n * ```\n */\n get params() {\n return this._paramsMethods\n }\n\n /** Create transactions for the current app */\n readonly createTransaction = {\n /** Create bare (raw) transactions for the current app */\n bare: {\n /** Create a create call transaction, including deploy-time TEAL template replacements and compilation if provided */\n create: async (params?: AppFactoryCreateParams) => {\n return this._algorand.createTransaction.appCreate(await this.params.bare.create(params))\n },\n },\n\n /** Create a create ABI call transaction, including deploy-time TEAL template replacements and compilation if provided */\n create: async (params: AppFactoryCreateMethodCallParams) => {\n return this._algorand.createTransaction.appCreateMethodCall(await this.params.create(params))\n },\n }\n\n /** Send transactions to the current app */\n readonly send = {\n /** Send bare (raw) transactions for the current app */\n bare: {\n create: async (params?: AppFactoryCreateParams & SendParams) => {\n const updatable = params?.updatable ?? this._updatable\n const deletable = params?.deletable ?? this._deletable\n const deployTimeParams = params?.deployTimeParams ?? this._deployTimeParams\n const compiled = await this.compile({ deployTimeParams, updatable, deletable })\n const result = await this.handleCallErrors(async () => ({\n ...(await this._algorand.send.appCreate(await this.params.bare.create({ ...params, updatable, deletable, deployTimeParams }))),\n return: undefined,\n }))\n return {\n appClient: this.getAppClientById({\n appId: result.appId,\n }),\n result: {\n ...result,\n ...(compiled as Partial<AppCompilationResult>),\n },\n }\n },\n },\n\n /**\n * Creates an instance of the app and returns the result of the creation\n * transaction and an app client to interact with that app instance.\n *\n * Performs deploy-time TEAL template placeholder substitutions (if specified).\n * @param params The parameters to create the app\n * @returns The app client and the result of the creation transaction\n */\n create: async (params: AppFactoryCreateMethodCallParams & SendParams) => {\n const updatable = params?.updatable ?? this._updatable\n const deletable = params?.deletable ?? this._deletable\n const deployTimeParams = params?.deployTimeParams ?? this._deployTimeParams\n const compiled = await this.compile({ deployTimeParams, updatable, deletable })\n const result = await this.handleCallErrors(async () =>\n this.parseMethodCallReturn(\n this._algorand.send.appCreateMethodCall(await this.params.create({ ...params, updatable, deletable, deployTimeParams })),\n getArc56Method(params.method, this._appSpec),\n ),\n )\n return {\n appClient: this.getAppClientById({\n appId: result.appId,\n }),\n result: {\n ...result,\n ...(compiled as Partial<AppCompilationResult>),\n },\n }\n },\n }\n\n /**\n * Idempotently deploy (create if not exists, update if changed) an app against the given name for the given creator account, including deploy-time TEAL template placeholder substitutions (if specified).\n *\n * **Note:** When using the return from this function be sure to check `operationPerformed` to get access to various return properties like `transaction`, `confirmation` and `deleteResult`.\n *\n * **Note:** if there is a breaking state schema change to an existing app (and `onSchemaBreak` is set to `'replace'`) the existing app will be deleted and re-created.\n *\n * **Note:** if there is an update (different TEAL code) to an existing app (and `onUpdate` is set to `'replace'`) the existing app will be deleted and re-created.\n * @param params The arguments to control the app deployment\n * @returns The app client and the result of the deployment\n */\n public async deploy(params: AppFactoryDeployParams) {\n const updatable = params.updatable ?? this._updatable ?? this.getDeployTimeControl('updatable')\n const deletable = params.deletable ?? this._deletable ?? this.getDeployTimeControl('deletable')\n const deployTimeParams = params.deployTimeParams ?? this._deployTimeParams\n const compiled = await this.compile({ deployTimeParams, updatable, deletable })\n const deployResult = await this._algorand.appDeployer.deploy({\n ...params,\n createParams: await (params.createParams && 'method' in params.createParams\n ? this.params.create({ ...params.createParams, updatable, deletable, deployTimeParams })\n : this.params.bare.create({ ...params.createParams, updatable, deletable, deployTimeParams })),\n updateParams:\n params.updateParams && 'method' in params.updateParams\n ? this.params.deployUpdate(params.updateParams)\n : this.params.bare.deployUpdate(params.updateParams),\n deleteParams:\n params.deleteParams && 'method' in params.deleteParams\n ? this.params.deployDelete(params.deleteParams)\n : this.params.bare.deployDelete(params.deleteParams),\n metadata: {\n name: params.appName ?? this._appName,\n version: this._version,\n updatable,\n deletable,\n },\n })\n const appClient = this.getAppClientById({\n appId: deployResult.appId,\n appName: params.appName,\n })\n const result = {\n ...deployResult,\n ...(compiled as Partial<AppCompilationResult>),\n }\n return {\n appClient,\n result: {\n ...result,\n return:\n 'return' in result\n ? result.operationPerformed === 'update'\n ? params.updateParams && 'method' in params.updateParams\n ? getArc56ReturnValue(result.return, getArc56Method(params.updateParams.method, this._appSpec), this._appSpec.structs)\n : undefined\n : params.createParams && 'method' in params.createParams\n ? getArc56ReturnValue(result.return, getArc56Method(params.createParams.method, this._appSpec), this._appSpec.structs)\n : undefined\n : undefined,\n deleteReturn:\n 'deleteReturn' in result && params.deleteParams && 'method' in params.deleteParams\n ? getArc56ReturnValue(result.deleteReturn, getArc56Method(params.deleteParams.method, this._appSpec), this._appSpec.structs)\n : undefined,\n },\n }\n }\n\n /**\n * Returns a new `AppClient` client for an app instance of the given ID.\n *\n * Automatically populates appName, defaultSender and source maps from the factory\n * if not specified in the params.\n * @param params The parameters to create the app client\n * @returns The `AppClient`\n */\n public getAppClientById(params: AppFactoryAppClientParams) {\n return new AppClient({\n ...params,\n algorand: this._algorand,\n appSpec: this._appSpec,\n appName: params.appName ?? this._appName,\n defaultSender: params.defaultSender ?? this._defaultSender,\n defaultSigner: params.defaultSigner ?? this._defaultSigner,\n approvalSourceMap: params.approvalSourceMap ?? this._approvalSourceMap,\n clearSourceMap: params.clearSourceMap ?? this._clearSourceMap,\n })\n }\n\n /**\n * Returns a new `AppClient` client, resolving the app by creator address and name\n * using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).\n *\n * Automatically populates appName, defaultSender and source maps from the factory\n * if not specified in the params.\n * @param params The parameters to create the app client\n * @returns The `AppClient`\n */\n public getAppClientByCreatorAndName(params: AppFactoryResolveAppClientByCreatorAndNameParams) {\n return AppClient.fromCreatorAndName({\n ...params,\n algorand: this._algorand,\n appSpec: this._appSpec,\n appName: params.appName ?? this._appName,\n defaultSender: params.defaultSender ?? this._defaultSender,\n approvalSourceMap: params.approvalSourceMap ?? this._approvalSourceMap,\n clearSourceMap: params.clearSourceMap ?? this._clearSourceMap,\n })\n }\n\n /**\n * Takes an error that may include a logic error from a call to the current app and re-exposes the\n * error to include source code information via the source map and ARC-56 spec.\n * @param e The error to parse\n * @param isClearStateProgram Whether or not the code was running the clear state program (defaults to approval program)\n * @returns The new error, or if there was no logic error or source map then the wrapped error with source details\n */\n exposeLogicError(e: Error, isClearStateProgram?: boolean): Error {\n return AppClient.exposeLogicError(e, this._appSpec, {\n isClearStateProgram,\n approvalSourceMap: this._approvalSourceMap,\n clearSourceMap: this._clearSourceMap,\n })\n }\n\n /**\n * Export the current source maps for the app.\n * @returns The source maps\n */\n exportSourceMaps(): AppSourceMaps {\n if (!this._approvalSourceMap || !this._clearSourceMap) {\n throw new Error(\n \"Unable to export source maps; they haven't been loaded into this client - you need to call create, update, or deploy first\",\n )\n }\n\n return {\n approvalSourceMap: this._approvalSourceMap,\n clearSourceMap: this._clearSourceMap,\n }\n }\n\n /**\n * Import source maps for the app.\n * @param sourceMaps The source maps to import\n */\n importSourceMaps(sourceMaps: AppSourceMaps) {\n this._approvalSourceMap = new SourceMap(sourceMaps.approvalSourceMap)\n this._clearSourceMap = new SourceMap(sourceMaps.clearSourceMap)\n }\n\n private getDeployTimeControl(control: 'updatable' | 'deletable'): boolean | undefined {\n const approval = this._appSpec.source?.approval ? Buffer.from(this._appSpec.source.approval, 'base64').toString('utf-8') : undefined\n // variable not present, so unknown control value\n if (!approval || !approval.includes(control === 'updatable' ? UPDATABLE_TEMPLATE_NAME : DELETABLE_TEMPLATE_NAME)) return undefined\n\n // A call is present and configured\n return (\n this._appSpec.bareActions.call.includes(control === 'updatable' ? 'UpdateApplication' : 'DeleteApplication') ||\n Object.values(this._appSpec.methods).some((c) =>\n c.actions.call.includes(control === 'updatable' ? 'UpdateApplication' : 'DeleteApplication'),\n )\n )\n }\n\n private getParamsMethods() {\n return {\n /** Return params for a create ABI call, including deploy-time TEAL template replacements and compilation if provided */\n create: async (params: AppFactoryCreateMethodCallParams) => {\n const compiled = await this.compile({ ...params, deployTimeParams: params.deployTimeParams ?? this._deployTimeParams })\n return this.getABIParams(\n {\n ...params,\n deployTimeParams: params.deployTimeParams ?? this._deployTimeParams,\n schema: params.schema ?? {\n globalByteSlices: this._appSpec.state.schema.global.bytes,\n globalInts: this._appSpec.state.schema.global.ints,\n localByteSlices: this._appSpec.state.schema.local.bytes,\n localInts: this._appSpec.state.schema.local.ints,\n },\n approvalProgram: compiled.approvalProgram,\n clearStateProgram: compiled.clearStateProgram,\n },\n params.onComplete ?? OnApplicationComplete.NoOpOC,\n ) satisfies AppCreateMethodCall\n },\n /** Return params for a deployment update ABI call */\n deployUpdate: (params: AppClientMethodCallParams) => {\n return this.getABIParams(params, OnApplicationComplete.UpdateApplicationOC) satisfies DeployAppUpdateMethodCall\n },\n /** Return params for a deployment delete ABI call */\n deployDelete: (params: AppClientMethodCallParams) => {\n return this.getABIParams(params, OnApplicationComplete.DeleteApplicationOC) satisfies DeployAppDeleteMethodCall\n },\n bare: {\n /** Return params for a create bare call, including deploy-time TEAL template replacements and compilation if provided */\n create: async (params?: AppFactoryCreateParams) => {\n return this.getBareParams(\n {\n ...params,\n deployTimeParams: params?.deployTimeParams ?? this._deployTimeParams,\n schema: params?.schema ?? {\n globalByteSlices: this._appSpec.state.schema.global.bytes,\n globalInts: this._appSpec.state.schema.global.ints,\n localByteSlices: this._appSpec.state.schema.local.bytes,\n localInts: this._appSpec.state.schema.local.ints,\n },\n ...(await this.compile({ ...params, deployTimeParams: params?.deployTimeParams ?? this._deployTimeParams })),\n },\n params?.onComplete ?? OnApplicationComplete.NoOpOC,\n ) satisfies AppCreateParams\n },\n /** Return params for a deployment update bare call */\n deployUpdate: (params?: AppClientBareCallParams) => {\n return this.getBareParams(params, OnApplicationComplete.UpdateApplicationOC) satisfies DeployAppUpdateParams\n },\n /** Return params for a deployment delete bare call */\n deployDelete: (params?: AppClientBareCallParams) => {\n return this.getBareParams(params, OnApplicationComplete.DeleteApplicationOC) satisfies DeployAppDeleteParams\n },\n },\n }\n }\n\n /** Make the given call and catch any errors, augmenting with debugging information before re-throwing. */\n private async handleCallErrors<TResult>(call: () => Promise<TResult>) {\n try {\n return await call()\n } catch (e) {\n throw this.exposeLogicError(e as Error)\n }\n }\n\n /**\n * Compiles the approval and clear state programs (if TEAL templates provided),\n * performing any provided deploy-time parameter replacement and stores\n * the source maps.\n *\n * If no TEAL templates provided it will use any byte code provided in the app spec.\n *\n * Will store any generated source maps for later use in debugging.\n */\n public async compile(compilation?: AppClientCompilationParams) {\n const result = await AppClient.compile(this._appSpec, this._algorand.app, compilation)\n\n if (result.compiledApproval) {\n this._approvalSourceMap = result.compiledApproval.sourceMap\n }\n if (result.compiledClear) {\n this._clearSourceMap = result.compiledClear.sourceMap\n }\n\n return result\n }\n\n private getBareParams<\n TParams extends { sender?: string; signer?: TransactionSigner | TransactionSignerAccount } | undefined,\n TOnComplete extends OnApplicationComplete,\n >(params: TParams, onComplete: TOnComplete) {\n return {\n ...params,\n sender: this.getSender(params?.sender),\n signer: this.getSigner(params?.sender, params?.signer),\n onComplete,\n }\n }\n\n private getABIParams<\n TParams extends {\n method: string\n sender?: string\n signer?: TransactionSigner | TransactionSignerAccount\n args?: AppClientMethodCallParams['args']\n },\n TOnComplete extends OnApplicationComplete,\n >(params: TParams, onComplete: TOnComplete) {\n return {\n ...params,\n sender: this.getSender(params.sender),\n signer: this.getSigner(params.sender, params.signer),\n method: getArc56Method(params.method, this._appSpec),\n args: this.getCreateABIArgsWithDefaultValues(params.method, params.args),\n onComplete,\n }\n }\n\n private getCreateABIArgsWithDefaultValues(\n methodNameOrSignature: string,\n args: AppClientMethodCallParams['args'] | undefined,\n ): AppMethodCall<CommonAppCallParams>['args'] {\n const m = getArc56Method(methodNameOrSignature, this._appSpec)\n return args?.map((a, i) => {\n const arg = m.args[i]\n if (a !== undefined) {\n // If a struct then convert to tuple for the underlying call\n return arg.struct && typeof a === 'object' && !Array.isArray(a)\n ? getABITupleFromABIStruct(a as ABIStruct, this._appSpec.structs[arg.struct], this._appSpec.structs)\n : (a as ABIValue | AppMethodCallTransactionArgument)\n }\n const defaultValue = arg.defaultValue\n if (defaultValue) {\n switch (defaultValue.source) {\n case 'literal':\n return getABIDecodedValue(Buffer.from(defaultValue.data, 'base64'), m.method.args[i].type, this._appSpec.structs) as ABIValue\n default:\n throw new Error(`Can't provide default value for ${defaultValue.source} for a contract creation call`)\n }\n }\n throw new Error(`No value provided for required argument ${arg.name ?? `arg${i + 1}`} in call to method ${m.name}`)\n })\n }\n\n /** Returns the sender for a call, using the `defaultSender`\n * if none provided and throws an error if neither provided */\n private getSender(sender: string | undefined): string {\n if (!sender && !this._defaultSender) {\n throw new Error(`No sender provided and no default sender present in app client for call to app ${this._appName}`)\n }\n return sender ?? this._defaultSender!\n }\n\n /** Returns the signer for a call, using the provided signer or the `defaultSigner`\n * if no signer was provided and the sender resolves to the default sender, the call will use default signer\n * or `undefined` otherwise (so the signer is resolved from `AlgorandClient`) */\n private getSigner(\n sender: string | undefined,\n signer: TransactionSigner | TransactionSignerAccount | undefined,\n ): TransactionSigner | TransactionSignerAccount | undefined {\n return signer ?? (!sender || sender === this._defaultSender ? this._defaultSigner : undefined)\n }\n\n /**\n * Checks for decode errors on the SendAppTransactionResult and maps the return value to the specified type\n * on the ARC-56 method.\n *\n * If the return type is a struct then the struct will be returned.\n *\n * @param result The SendAppTransactionResult to be mapped\n * @param method The method that was called\n * @returns The smart contract response with an updated return value\n */\n async parseMethodCallReturn<\n TReturn extends Uint8Array | ABIValue | ABIStruct | undefined,\n TResult extends SendAppTransactionResult = SendAppTransactionResult,\n >(result: Promise<TResult> | TResult, method: Arc56Method): Promise<Omit<TResult, 'return'> & AppReturn<TReturn>> {\n const resultValue = await result\n return { ...resultValue, return: getArc56ReturnValue(resultValue.return, method, this._appSpec.structs) }\n }\n}\n"],"names":[],"mappings":";;;;;AAwCA,IAAO,SAAS,GAAG,OAAO,CAAC,SAAS;AACpC,IAAO,qBAAqB,GAAG,OAAO,CAAC,qBAAqB;AA2H5D;;;;AAIG;MACU,UAAU,CAAA;AAgBrB,IAAA,WAAA,CAAY,MAAwB,EAAA;;AAgD3B,QAAA,IAAA,CAAA,iBAAiB,GAAG;;AAE3B,YAAA,IAAI,EAAE;;AAEJ,gBAAA,MAAM,EAAE,OAAO,MAA+B,KAAI;oBAChD,OAAO,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,SAAS,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;iBACzF;AACF,aAAA;;AAGD,YAAA,MAAM,EAAE,OAAO,MAAwC,KAAI;AACzD,gBAAA,OAAO,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;aAC9F;SACF;;AAGQ,QAAA,IAAA,CAAA,IAAI,GAAG;;AAEd,YAAA,IAAI,EAAE;AACJ,gBAAA,MAAM,EAAE,OAAO,MAA4C,KAAI;oBAC7D,MAAM,SAAS,GAAG,MAAM,EAAE,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AC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAa;AAC/H,oBAAA;wBACE,MAAM,IAAI,KAAK,CAAC,CAAA,gCAAA,EAAmC,YAAY,CAAC,MAAM,CAA+B,6BAAA,CAAA,CAAC;;;AAG5G,YAAA,MAAM,IAAI,KAAK,CAAC,2CAA2C,GAAG,CAAC,IAAI,IAAI,CAAA,GAAA,EAAM,CAAC,GAAG,CAAC,EAAE,CAAsB,mBAAA,EAAA,CAAC,CAAC,IAAI,CAAA,CAAE,CAAC;AACrH,SAAC,CAAC;;AAGJ;AAC8D;AACtD,IAAA,SAAS,CAAC,MAA0B,EAAA;QAC1C,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;YACnC,MAAM,IAAI,KAAK,CAAC,CAAA,+EAAA,EAAkF,IAAI,CAAC,QAAQ,CAAE,CAAA,CAAC;;AAEpH,QAAA,OAAO,MAAM,IAAI,IAAI,CAAC,cAAe;;AAGvC;;AAEgF;IACxE,SAAS,CACf,MAA0B,EAC1B,MAAgE,EAAA;QAEhE,OAAO,MAAM,KAAK,CAAC,MAAM,IAAI,MAAM,KAAK,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;;AAGhG;;;;;;;;;AASG;AACH,IAAA,MAAM,qBAAqB,CAGzB,MAAkC,EAAE,MAAmB,EAAA;AACvD,QAAA,MAAM,WAAW,GAAG,MAAM,MAAM;QAChC,OAAO,EAAE,GAAG,WAAW,EAAE,MAAM,EAAE,mBAAmB,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;;AAE5G;;;;"}
@@ -164,14 +164,14 @@ export declare class AppManager {
164
164
  * @param boxName The name of the box to return either as a string, binary array or `BoxName`
165
165
  * @returns The current box value as a byte array
166
166
  */
167
- getBoxValue(appId: bigint, boxName: BoxIdentifier): Promise<Uint8Array>;
167
+ getBoxValue(appId: bigint, boxName: BoxIdentifier | BoxName): Promise<Uint8Array>;
168
168
  /**
169
169
  * Returns the value of the given box names for the given app.
170
170
  * @param appId The ID of the app return box names for
171
171
  * @param boxNames The names of the boxes to return either as a string, binary array or `BoxName`
172
172
  * @returns The current box values as a byte array in the same order as the passed in box names
173
173
  */
174
- getBoxValues(appId: bigint, boxNames: BoxIdentifier[]): Promise<Uint8Array[]>;
174
+ getBoxValues(appId: bigint, boxNames: (BoxIdentifier | BoxName)[]): Promise<Uint8Array[]>;
175
175
  /**
176
176
  * Returns the value of the given box name for the given app decoded based on the given ABI type.
177
177
  * @param request The parameters for the box value request
@@ -144,7 +144,8 @@ class AppManager {
144
144
  * @returns The current box value as a byte array
145
145
  */
146
146
  async getBoxValue(appId, boxName) {
147
- const name = AppManager.getBoxReference(boxName).name;
147
+ const boxId = typeof boxName === 'object' && 'nameRaw' in boxName ? boxName.nameRaw : boxName;
148
+ const name = AppManager.getBoxReference(boxId).name;
148
149
  const boxResult = await this._algod.getApplicationBoxByName(Number(appId), name).do();
149
150
  return boxResult.value;
150
151
  }
@@ -1 +1 @@
1
- {"version":3,"file":"app-manager.js","sources":["../../src/types/app-manager.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { getABIReturnValue } from '../transaction/transaction'\nimport { TransactionSignerAccount } from './account'\nimport {\n BoxName,\n DELETABLE_TEMPLATE_NAME,\n UPDATABLE_TEMPLATE_NAME,\n type ABIReturn,\n type AppState,\n type CompiledTeal,\n type TealTemplateParams,\n} from './app'\nimport modelsv2 = algosdk.modelsv2\n\n/** Information about an app. */\nexport interface AppInformation {\n /** The ID of the app. */\n appId: bigint\n /** The escrow address that the app operates with. */\n appAddress: string\n /**\n * Approval program.\n */\n approvalProgram: Uint8Array\n /**\n * Clear state program.\n */\n clearStateProgram: Uint8Array\n /**\n * The address that created this application. This is the address where the\n * parameters and global state for this application can be found.\n */\n creator: string\n /**\n * Current global state values.\n */\n globalState: AppState\n /** The number of allocated ints in per-user local state. */\n localInts: number\n /** The number of allocated byte slices in per-user local state. */\n localByteSlices: number\n /** The number of allocated ints in global state. */\n globalInts: number\n /** The number of allocated byte slices in global state. */\n globalByteSlices: number\n /** Any extra pages that are needed for the smart contract. */\n extraProgramPages?: number\n}\n\n/**\n * Something that identifies an app box name - either a:\n * * `Uint8Array` (the actual binary of the box name)\n * * `string` (that will be encoded to a `Uint8Array`)\n * * `TransactionSignerAccount` (that will be encoded into the\n * public key address of the corresponding account)\n */\nexport type BoxIdentifier = string | Uint8Array | TransactionSignerAccount\n\n/**\n * A grouping of the app ID and name identifier to reference an app box.\n */\nexport interface BoxReference {\n /**\n * A unique application id\n */\n appId: bigint\n /**\n * Identifier for a box name\n */\n name: BoxIdentifier\n}\n\n/**\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValueRequestParams {\n /** The ID of the app return box names for */\n appId: bigint\n /** The name of the box to return either as a string, binary array or `BoxName` */\n boxName: BoxIdentifier\n /** The ABI type to decode the value using */\n type: algosdk.ABIType\n}\n\n/**\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValuesRequestParams {\n /** The ID of the app return box names for */\n appId: bigint\n /** The names of the boxes to return either as a string, binary array or BoxName` */\n boxNames: BoxIdentifier[]\n /** The ABI type to decode the value using */\n type: algosdk.ABIType\n}\n\n/** Allows management of application information. */\nexport class AppManager {\n private _algod: algosdk.Algodv2\n private _compilationResults: Record<string, CompiledTeal> = {}\n\n /**\n * Creates an `AppManager`\n * @param algod An algod instance\n */\n constructor(algod: algosdk.Algodv2) {\n this._algod = algod\n }\n\n /**\n * Compiles the given TEAL using algod and returns the result, including source map.\n *\n * The result of this compilation is also cached keyed by the TEAL\n * code so it can be retrieved via `getCompilationResult`.\n *\n * This function is re-entrant; it will only compile the same code once.\n *\n * @param tealCode The TEAL code\n * @returns The information about the compiled file\n */\n async compileTeal(tealCode: string): Promise<CompiledTeal> {\n if (this._compilationResults[tealCode]) {\n return this._compilationResults[tealCode]\n }\n\n const compiled = await this._algod.compile(tealCode).sourcemap(true).do()\n const result = {\n teal: tealCode,\n compiled: compiled.result,\n compiledHash: compiled.hash,\n compiledBase64ToBytes: new Uint8Array(Buffer.from(compiled.result, 'base64')),\n sourceMap: new algosdk.SourceMap(compiled['sourcemap']),\n }\n this._compilationResults[tealCode] = result\n\n return result\n }\n\n /**\n * Performs template substitution of a teal template and compiles it, returning the compiled result.\n *\n * Looks for `TMPL_{parameter}` for template replacements and replaces AlgoKit deploy-time control parameters\n * if deployment metadata is specified.\n *\n * * `TMPL_UPDATABLE` for updatability / immutability control\n * * `TMPL_DELETABLE` for deletability / permanence control\n *\n * @param tealTemplateCode The TEAL logic to compile\n * @param templateParams Any parameters to replace in the .teal file before compiling\n * @param deploymentMetadata The deployment metadata the app will be deployed with\n * @returns The information about the compiled code\n */\n async compileTealTemplate(\n tealTemplateCode: string,\n templateParams?: TealTemplateParams,\n deploymentMetadata?: { updatable?: boolean; deletable?: boolean },\n ): Promise<CompiledTeal> {\n let tealCode = AppManager.stripTealComments(tealTemplateCode)\n\n tealCode = AppManager.replaceTealTemplateParams(tealCode, templateParams)\n\n if (deploymentMetadata) {\n tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealCode, deploymentMetadata)\n }\n\n return await this.compileTeal(tealCode)\n }\n\n /**\n * Returns a previous compilation result.\n * @param tealCode The TEAL code\n * @returns The information about the previously compiled file\n * or `undefined` if that TEAL code wasn't previously compiled\n */\n getCompilationResult(tealCode: string): CompiledTeal | undefined {\n return this._compilationResults[tealCode]\n }\n\n /**\n * Returns the current app information for the app with the given ID.\n *\n * @example\n * ```typescript\n * const appInfo = await appManager.getById(12353n);\n * ```\n *\n * @param appId The ID of the app\n * @returns The app information\n */\n public async getById(appId: bigint): Promise<AppInformation> {\n const app = modelsv2.Application.from_obj_for_encoding(await this._algod.getApplicationByID(Number(appId)).do())\n return {\n appId: BigInt(app.id),\n appAddress: algosdk.getApplicationAddress(app.id),\n approvalProgram: app.params.approvalProgram,\n clearStateProgram: app.params.clearStateProgram,\n creator: app.params.creator,\n localInts: Number(app.params.localStateSchema?.numUint ?? 0),\n localByteSlices: Number(app.params.localStateSchema?.numByteSlice ?? 0),\n globalInts: Number(app.params.globalStateSchema?.numUint ?? 0),\n globalByteSlices: Number(app.params.globalStateSchema?.numByteSlice ?? 0),\n extraProgramPages: Number(app.params.extraProgramPages ?? 0),\n globalState: AppManager.decodeAppState(app.params.globalState ?? []),\n }\n }\n\n /**\n * Returns the current global state values for the given app ID and account address\n *\n * @param appId The ID of the app to return global state for\n * @returns The current global state for the given app\n */\n public async getGlobalState(appId: bigint) {\n return (await this.getById(appId)).globalState\n }\n\n /**\n * Returns the current local state values for the given app ID and account address\n *\n * @param appId The ID of the app to return local state for\n * @param address The string address of the account to get local state for the given app\n * @returns The current local state for the given (app, account) combination\n */\n public async getLocalState(appId: bigint, address: string) {\n const appInfo = modelsv2.AccountApplicationResponse.from_obj_for_encoding(\n await this._algod.accountApplicationInformation(address, Number(appId)).do(),\n )\n\n if (!appInfo.appLocalState?.keyValue) {\n throw new Error(\"Couldn't find local state\")\n }\n\n return AppManager.decodeAppState(appInfo.appLocalState.keyValue)\n }\n\n /**\n * Returns the names of the current boxes for the given app.\n * @param appId The ID of the app return box names for\n * @returns The current box names\n */\n public async getBoxNames(appId: bigint): Promise<BoxName[]> {\n const boxResult = await this._algod.getApplicationBoxes(Number(appId)).do()\n return boxResult.boxes.map((b) => {\n return {\n nameRaw: b.name,\n nameBase64: Buffer.from(b.name).toString('base64'),\n name: Buffer.from(b.name).toString('utf-8'),\n }\n })\n }\n\n /**\n * Returns the value of the given box name for the given app.\n * @param appId The ID of the app return box names for\n * @param boxName The name of the box to return either as a string, binary array or `BoxName`\n * @returns The current box value as a byte array\n */\n public async getBoxValue(appId: bigint, boxName: BoxIdentifier): Promise<Uint8Array> {\n const name = AppManager.getBoxReference(boxName).name\n const boxResult = await this._algod.getApplicationBoxByName(Number(appId), name).do()\n return boxResult.value\n }\n\n /**\n * Returns the value of the given box names for the given app.\n * @param appId The ID of the app return box names for\n * @param boxNames The names of the boxes to return either as a string, binary array or `BoxName`\n * @returns The current box values as a byte array in the same order as the passed in box names\n */\n public async getBoxValues(appId: bigint, boxNames: BoxIdentifier[]): Promise<Uint8Array[]> {\n return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValue(appId, boxName)))\n }\n\n /**\n * Returns the value of the given box name for the given app decoded based on the given ABI type.\n * @param request The parameters for the box value request\n * @returns The current box value as an ABI value\n */\n public async getBoxValueFromABIType(request: BoxValueRequestParams): Promise<algosdk.ABIValue> {\n const { appId, boxName, type } = request\n const value = await this.getBoxValue(appId, boxName)\n return type.decode(value)\n }\n\n /**\n * Returns the value of the given box names for the given app decoded based on the given ABI type.\n * @param request The parameters for the box value request\n * @returns The current box values as an ABI value in the same order as the passed in box names\n */\n public async getBoxValuesFromABIType(request: BoxValuesRequestParams): Promise<algosdk.ABIValue[]> {\n const { appId, boxNames, type } = request\n return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValueFromABIType({ appId, boxName, type })))\n }\n\n /**\n * Returns a `algosdk.BoxReference` given a `BoxIdentifier` or `BoxReference`.\n * @param boxId The box to return a reference for\n * @returns The box reference ready to pass into a `algosdk.Transaction`\n */\n public static getBoxReference(boxId: BoxIdentifier | BoxReference): algosdk.BoxReference {\n const ref = typeof boxId === 'object' && 'appId' in boxId ? boxId : { appId: 0n, name: boxId }\n return {\n appIndex: Number(ref.appId),\n name:\n typeof ref.name === 'string'\n ? new TextEncoder().encode(ref.name)\n : 'length' in ref.name\n ? ref.name\n : algosdk.decodeAddress(ref.name.addr).publicKey,\n } as algosdk.BoxReference\n }\n\n /**\n * Converts an array of global/local state values from the algod api to a more friendly\n * generic object keyed by the UTF-8 value of the key.\n * @param state A `global-state`, `local-state`, `global-state-deltas` or `local-state-deltas`\n * @returns An object keyeed by the UTF-8 representation of the key with various parsings of the values\n */\n public static decodeAppState(state: { key: string; value: modelsv2.TealValue | modelsv2.EvalDelta }[]): AppState {\n const stateValues = {} as AppState\n\n // Start with empty set\n for (const stateVal of state) {\n const keyBase64 = stateVal.key\n const keyRaw = Buffer.from(keyBase64, 'base64')\n const key = keyRaw.toString('utf-8')\n const tealValue = stateVal.value\n\n const dataTypeFlag = 'action' in tealValue ? tealValue.action : tealValue.type\n let valueBase64: string\n let valueRaw: Buffer\n switch (dataTypeFlag) {\n case 1:\n valueBase64 = tealValue.bytes ?? ''\n valueRaw = Buffer.from(valueBase64, 'base64')\n stateValues[key] = {\n keyRaw,\n keyBase64,\n valueRaw: new Uint8Array(valueRaw),\n valueBase64: valueBase64,\n value: valueRaw.toString('utf-8'),\n }\n break\n case 2: {\n const value = tealValue.uint ?? 0\n stateValues[key] = {\n keyRaw,\n keyBase64,\n value: BigInt(value),\n }\n break\n }\n default:\n throw new Error(`Received unknown state data type of ${dataTypeFlag}`)\n }\n }\n\n return stateValues\n }\n\n /**\n * Returns any ABI return values for the given app call arguments and transaction confirmation.\n * @param confirmation The transaction confirmation from algod\n * @param method The ABI method\n * @returns The return value for the method call\n */\n public static getABIReturn(\n confirmation: modelsv2.PendingTransactionResponse | undefined,\n method: algosdk.ABIMethod | undefined,\n ): ABIReturn | undefined {\n if (!method || !confirmation || method.returns.type === 'void') {\n return undefined\n }\n\n // The parseMethodResponse method mutates the second parameter :(\n const resultDummy: algosdk.ABIResult = {\n txID: '',\n method,\n rawReturnValue: new Uint8Array(),\n }\n return getABIReturnValue(algosdk.AtomicTransactionComposer.parseMethodResponse(method, resultDummy, confirmation))\n }\n\n /**\n * Replaces AlgoKit deploy-time deployment control parameters within the given TEAL template code.\n *\n * * `TMPL_UPDATABLE` for updatability / immutability control\n * * `TMPL_DELETABLE` for deletability / permanence control\n *\n * Note: If these values are defined, but the corresponding `TMPL_*` value\n * isn't in the teal code it will throw an exception.\n *\n * @param tealTemplateCode The TEAL template code to substitute\n * @param params The deploy-time deployment control parameter value to replace\n * @returns The replaced TEAL code\n */\n static replaceTealTemplateDeployTimeControlParams(tealTemplateCode: string, params: { updatable?: boolean; deletable?: boolean }) {\n if (params.updatable !== undefined) {\n if (!tealTemplateCode.includes(UPDATABLE_TEMPLATE_NAME)) {\n throw new Error(\n `Deploy-time updatability control requested for app deployment, but ${UPDATABLE_TEMPLATE_NAME} not present in TEAL code`,\n )\n }\n tealTemplateCode = replaceTemplateVariable(tealTemplateCode, UPDATABLE_TEMPLATE_NAME, (params.updatable ? 1 : 0).toString())\n }\n\n if (params.deletable !== undefined) {\n if (!tealTemplateCode.includes(DELETABLE_TEMPLATE_NAME)) {\n throw new Error(\n `Deploy-time deletability control requested for app deployment, but ${DELETABLE_TEMPLATE_NAME} not present in TEAL code`,\n )\n }\n tealTemplateCode = replaceTemplateVariable(tealTemplateCode, DELETABLE_TEMPLATE_NAME, (params.deletable ? 1 : 0).toString())\n }\n\n return tealTemplateCode\n }\n\n /**\n * Performs template substitution of a teal file.\n *\n * Looks for `TMPL_{parameter}` for template replacements.\n *\n * @param tealTemplateCode The TEAL template code to make parameter replacements in\n * @param templateParams Any parameters to replace in the teal code\n * @returns The TEAL code with replacements\n */\n static replaceTealTemplateParams(tealTemplateCode: string, templateParams?: TealTemplateParams) {\n if (templateParams !== undefined) {\n for (const key in templateParams) {\n const value = templateParams[key]\n const token = `TMPL_${key.replace(/^TMPL_/, '')}`\n\n // If this is a number, first replace any byte representations of the number\n // These may appear in the TEAL in order to circumvent int compression and preserve PC values\n if (typeof value === 'number' || typeof value === 'bigint') {\n tealTemplateCode = tealTemplateCode.replace(new RegExp(`(?<=bytes )${token}`, 'g'), `0x${value.toString(16).padStart(16, '0')}`)\n\n // We could probably return here since mixing pushint and pushbytes is likely not going to happen, but might as well do both\n }\n\n tealTemplateCode = replaceTemplateVariable(\n tealTemplateCode,\n token,\n typeof value === 'string'\n ? `0x${Buffer.from(value, 'utf-8').toString('hex')}`\n : ArrayBuffer.isView(value)\n ? `0x${Buffer.from(value).toString('hex')}`\n : value.toString(),\n )\n }\n }\n\n return tealTemplateCode\n }\n\n /**\n * Remove comments from TEAL code (useful to reduce code size before compilation).\n *\n * @param tealCode The TEAL logic to strip\n * @returns The TEAL without comments\n */\n static stripTealComments(tealCode: string) {\n const stripCommentFromLine = (line: string) => {\n const commentIndex = findUnquotedString(line, '//')\n if (commentIndex === undefined) {\n return line\n }\n return line.slice(0, commentIndex).trimEnd()\n }\n\n return tealCode\n .split('\\n')\n .map((line) => stripCommentFromLine(line))\n .join('\\n')\n }\n}\n\n/**\n * Find the first string within a line of TEAL. Only matches outside of quotes and base64 are returned.\n * Returns undefined if not found\n */\nconst findUnquotedString = (line: string, token: string, startIndex: number = 0, _endIndex?: number): number | undefined => {\n const endIndex = _endIndex === undefined ? line.length : _endIndex\n let index = startIndex\n let inQuotes = false\n let inBase64 = false\n\n while (index < endIndex) {\n const currentChar = line[index]\n if ((currentChar === ' ' || currentChar === '(') && !inQuotes && lastTokenBase64(line, index)) {\n // enter base64\n inBase64 = true\n } else if ((currentChar === ' ' || currentChar === ')') && !inQuotes && inBase64) {\n // exit base64\n inBase64 = false\n } else if (currentChar === '\\\\' && inQuotes) {\n // escaped char, skip next character\n index += 1\n } else if (currentChar === '\"') {\n // quote boundary\n inQuotes = !inQuotes\n } else if (!inQuotes && !inBase64 && line.startsWith(token, index)) {\n // can test for match\n return index\n }\n index += 1\n }\n return undefined\n}\n\nconst lastTokenBase64 = (line: string, index: number): boolean => {\n try {\n const tokens = line.slice(0, index).split(/\\s+/)\n const last = tokens[tokens.length - 1]\n return ['base64', 'b64'].includes(last)\n } catch {\n return false\n }\n}\n\nfunction replaceTemplateVariable(program: string, token: string, replacement: string): string {\n const result: string[] = []\n const tokenIndexOffset = replacement.length - token.length\n\n const programLines = program.split('\\n')\n\n for (const line of programLines) {\n const _commentIndex = findUnquotedString(line, '//')\n const commentIndex = _commentIndex === undefined ? line.length : _commentIndex\n let code = line.substring(0, commentIndex)\n const comment = line.substring(commentIndex)\n let trailingIndex = 0\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const tokenIndex = findTemplateToken(code, token, trailingIndex)\n if (tokenIndex === undefined) {\n break\n }\n trailingIndex = tokenIndex + token.length\n const prefix = code.substring(0, tokenIndex)\n const suffix = code.substring(trailingIndex)\n code = `${prefix}${replacement}${suffix}`\n trailingIndex += tokenIndexOffset\n }\n result.push(code + comment)\n }\n\n return result.join('\\n')\n}\n\nconst findTemplateToken = (line: string, token: string, startIndex: number = 0, _endIndex?: number): number | undefined => {\n const endIndex = _endIndex === undefined ? line.length : _endIndex\n\n let index = startIndex\n while (index < endIndex) {\n const tokenIndex = findUnquotedString(line, token, index, endIndex)\n if (tokenIndex === undefined) {\n break\n }\n const trailingIndex = tokenIndex + token.length\n if (\n (tokenIndex === 0 || !isValidTokenCharacter(line[tokenIndex - 1])) &&\n (trailingIndex >= line.length || !isValidTokenCharacter(line[trailingIndex]))\n ) {\n return tokenIndex\n }\n index = trailingIndex\n }\n return undefined\n}\n\nfunction isValidTokenCharacter(char: string): boolean {\n return char.length === 1 && (/\\w/.test(char) || char === '_')\n}\n"],"names":["getABIReturnValue","UPDATABLE_TEMPLATE_NAME","DELETABLE_TEMPLATE_NAME"],"mappings":";;;;;;AAYA,IAAO,QAAQ,GAAG,OAAO,CAAC,QAAQ;AAoFlC;MACa,UAAU,CAAA;AAIrB;;;AAGG;AACH,IAAA,WAAA,CAAY,KAAsB,EAAA;QAN1B,IAAmB,CAAA,mBAAA,GAAiC,EAAE;AAO5D,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK;;AAGrB;;;;;;;;;;AAUG;IACH,MAAM,WAAW,CAAC,QAAgB,EAAA;AAChC,QAAA,IAAI,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EAAE;AACtC,YAAA,OAAO,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC;;AAG3C,QAAA,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE;AAC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,"file":"app-manager.js","sources":["../../src/types/app-manager.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { getABIReturnValue } from '../transaction/transaction'\nimport { TransactionSignerAccount } from './account'\nimport {\n BoxName,\n DELETABLE_TEMPLATE_NAME,\n UPDATABLE_TEMPLATE_NAME,\n type ABIReturn,\n type AppState,\n type CompiledTeal,\n type TealTemplateParams,\n} from './app'\nimport modelsv2 = algosdk.modelsv2\n\n/** Information about an app. */\nexport interface AppInformation {\n /** The ID of the app. */\n appId: bigint\n /** The escrow address that the app operates with. */\n appAddress: string\n /**\n * Approval program.\n */\n approvalProgram: Uint8Array\n /**\n * Clear state program.\n */\n clearStateProgram: Uint8Array\n /**\n * The address that created this application. This is the address where the\n * parameters and global state for this application can be found.\n */\n creator: string\n /**\n * Current global state values.\n */\n globalState: AppState\n /** The number of allocated ints in per-user local state. */\n localInts: number\n /** The number of allocated byte slices in per-user local state. */\n localByteSlices: number\n /** The number of allocated ints in global state. */\n globalInts: number\n /** The number of allocated byte slices in global state. */\n globalByteSlices: number\n /** Any extra pages that are needed for the smart contract. */\n extraProgramPages?: number\n}\n\n/**\n * Something that identifies an app box name - either a:\n * * `Uint8Array` (the actual binary of the box name)\n * * `string` (that will be encoded to a `Uint8Array`)\n * * `TransactionSignerAccount` (that will be encoded into the\n * public key address of the corresponding account)\n */\nexport type BoxIdentifier = string | Uint8Array | TransactionSignerAccount\n\n/**\n * A grouping of the app ID and name identifier to reference an app box.\n */\nexport interface BoxReference {\n /**\n * A unique application id\n */\n appId: bigint\n /**\n * Identifier for a box name\n */\n name: BoxIdentifier\n}\n\n/**\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValueRequestParams {\n /** The ID of the app return box names for */\n appId: bigint\n /** The name of the box to return either as a string, binary array or `BoxName` */\n boxName: BoxIdentifier\n /** The ABI type to decode the value using */\n type: algosdk.ABIType\n}\n\n/**\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValuesRequestParams {\n /** The ID of the app return box names for */\n appId: bigint\n /** The names of the boxes to return either as a string, binary array or BoxName` */\n boxNames: BoxIdentifier[]\n /** The ABI type to decode the value using */\n type: algosdk.ABIType\n}\n\n/** Allows management of application information. */\nexport class AppManager {\n private _algod: algosdk.Algodv2\n private _compilationResults: Record<string, CompiledTeal> = {}\n\n /**\n * Creates an `AppManager`\n * @param algod An algod instance\n */\n constructor(algod: algosdk.Algodv2) {\n this._algod = algod\n }\n\n /**\n * Compiles the given TEAL using algod and returns the result, including source map.\n *\n * The result of this compilation is also cached keyed by the TEAL\n * code so it can be retrieved via `getCompilationResult`.\n *\n * This function is re-entrant; it will only compile the same code once.\n *\n * @param tealCode The TEAL code\n * @returns The information about the compiled file\n */\n async compileTeal(tealCode: string): Promise<CompiledTeal> {\n if (this._compilationResults[tealCode]) {\n return this._compilationResults[tealCode]\n }\n\n const compiled = await this._algod.compile(tealCode).sourcemap(true).do()\n const result = {\n teal: tealCode,\n compiled: compiled.result,\n compiledHash: compiled.hash,\n compiledBase64ToBytes: new Uint8Array(Buffer.from(compiled.result, 'base64')),\n sourceMap: new algosdk.SourceMap(compiled['sourcemap']),\n }\n this._compilationResults[tealCode] = result\n\n return result\n }\n\n /**\n * Performs template substitution of a teal template and compiles it, returning the compiled result.\n *\n * Looks for `TMPL_{parameter}` for template replacements and replaces AlgoKit deploy-time control parameters\n * if deployment metadata is specified.\n *\n * * `TMPL_UPDATABLE` for updatability / immutability control\n * * `TMPL_DELETABLE` for deletability / permanence control\n *\n * @param tealTemplateCode The TEAL logic to compile\n * @param templateParams Any parameters to replace in the .teal file before compiling\n * @param deploymentMetadata The deployment metadata the app will be deployed with\n * @returns The information about the compiled code\n */\n async compileTealTemplate(\n tealTemplateCode: string,\n templateParams?: TealTemplateParams,\n deploymentMetadata?: { updatable?: boolean; deletable?: boolean },\n ): Promise<CompiledTeal> {\n let tealCode = AppManager.stripTealComments(tealTemplateCode)\n\n tealCode = AppManager.replaceTealTemplateParams(tealCode, templateParams)\n\n if (deploymentMetadata) {\n tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealCode, deploymentMetadata)\n }\n\n return await this.compileTeal(tealCode)\n }\n\n /**\n * Returns a previous compilation result.\n * @param tealCode The TEAL code\n * @returns The information about the previously compiled file\n * or `undefined` if that TEAL code wasn't previously compiled\n */\n getCompilationResult(tealCode: string): CompiledTeal | undefined {\n return this._compilationResults[tealCode]\n }\n\n /**\n * Returns the current app information for the app with the given ID.\n *\n * @example\n * ```typescript\n * const appInfo = await appManager.getById(12353n);\n * ```\n *\n * @param appId The ID of the app\n * @returns The app information\n */\n public async getById(appId: bigint): Promise<AppInformation> {\n const app = modelsv2.Application.from_obj_for_encoding(await this._algod.getApplicationByID(Number(appId)).do())\n return {\n appId: BigInt(app.id),\n appAddress: algosdk.getApplicationAddress(app.id),\n approvalProgram: app.params.approvalProgram,\n clearStateProgram: app.params.clearStateProgram,\n creator: app.params.creator,\n localInts: Number(app.params.localStateSchema?.numUint ?? 0),\n localByteSlices: Number(app.params.localStateSchema?.numByteSlice ?? 0),\n globalInts: Number(app.params.globalStateSchema?.numUint ?? 0),\n globalByteSlices: Number(app.params.globalStateSchema?.numByteSlice ?? 0),\n extraProgramPages: Number(app.params.extraProgramPages ?? 0),\n globalState: AppManager.decodeAppState(app.params.globalState ?? []),\n }\n }\n\n /**\n * Returns the current global state values for the given app ID and account address\n *\n * @param appId The ID of the app to return global state for\n * @returns The current global state for the given app\n */\n public async getGlobalState(appId: bigint) {\n return (await this.getById(appId)).globalState\n }\n\n /**\n * Returns the current local state values for the given app ID and account address\n *\n * @param appId The ID of the app to return local state for\n * @param address The string address of the account to get local state for the given app\n * @returns The current local state for the given (app, account) combination\n */\n public async getLocalState(appId: bigint, address: string) {\n const appInfo = modelsv2.AccountApplicationResponse.from_obj_for_encoding(\n await this._algod.accountApplicationInformation(address, Number(appId)).do(),\n )\n\n if (!appInfo.appLocalState?.keyValue) {\n throw new Error(\"Couldn't find local state\")\n }\n\n return AppManager.decodeAppState(appInfo.appLocalState.keyValue)\n }\n\n /**\n * Returns the names of the current boxes for the given app.\n * @param appId The ID of the app return box names for\n * @returns The current box names\n */\n public async getBoxNames(appId: bigint): Promise<BoxName[]> {\n const boxResult = await this._algod.getApplicationBoxes(Number(appId)).do()\n return boxResult.boxes.map((b) => {\n return {\n nameRaw: b.name,\n nameBase64: Buffer.from(b.name).toString('base64'),\n name: Buffer.from(b.name).toString('utf-8'),\n }\n })\n }\n\n /**\n * Returns the value of the given box name for the given app.\n * @param appId The ID of the app return box names for\n * @param boxName The name of the box to return either as a string, binary array or `BoxName`\n * @returns The current box value as a byte array\n */\n public async getBoxValue(appId: bigint, boxName: BoxIdentifier | BoxName): Promise<Uint8Array> {\n const boxId = typeof boxName === 'object' && 'nameRaw' in boxName ? boxName.nameRaw : boxName\n const name = AppManager.getBoxReference(boxId).name\n const boxResult = await this._algod.getApplicationBoxByName(Number(appId), name).do()\n return boxResult.value\n }\n\n /**\n * Returns the value of the given box names for the given app.\n * @param appId The ID of the app return box names for\n * @param boxNames The names of the boxes to return either as a string, binary array or `BoxName`\n * @returns The current box values as a byte array in the same order as the passed in box names\n */\n public async getBoxValues(appId: bigint, boxNames: (BoxIdentifier | BoxName)[]): Promise<Uint8Array[]> {\n return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValue(appId, boxName)))\n }\n\n /**\n * Returns the value of the given box name for the given app decoded based on the given ABI type.\n * @param request The parameters for the box value request\n * @returns The current box value as an ABI value\n */\n public async getBoxValueFromABIType(request: BoxValueRequestParams): Promise<algosdk.ABIValue> {\n const { appId, boxName, type } = request\n const value = await this.getBoxValue(appId, boxName)\n return type.decode(value)\n }\n\n /**\n * Returns the value of the given box names for the given app decoded based on the given ABI type.\n * @param request The parameters for the box value request\n * @returns The current box values as an ABI value in the same order as the passed in box names\n */\n public async getBoxValuesFromABIType(request: BoxValuesRequestParams): Promise<algosdk.ABIValue[]> {\n const { appId, boxNames, type } = request\n return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValueFromABIType({ appId, boxName, type })))\n }\n\n /**\n * Returns a `algosdk.BoxReference` given a `BoxIdentifier` or `BoxReference`.\n * @param boxId The box to return a reference for\n * @returns The box reference ready to pass into a `algosdk.Transaction`\n */\n public static getBoxReference(boxId: BoxIdentifier | BoxReference): algosdk.BoxReference {\n const ref = typeof boxId === 'object' && 'appId' in boxId ? boxId : { appId: 0n, name: boxId }\n return {\n appIndex: Number(ref.appId),\n name:\n typeof ref.name === 'string'\n ? new TextEncoder().encode(ref.name)\n : 'length' in ref.name\n ? ref.name\n : algosdk.decodeAddress(ref.name.addr).publicKey,\n } as algosdk.BoxReference\n }\n\n /**\n * Converts an array of global/local state values from the algod api to a more friendly\n * generic object keyed by the UTF-8 value of the key.\n * @param state A `global-state`, `local-state`, `global-state-deltas` or `local-state-deltas`\n * @returns An object keyeed by the UTF-8 representation of the key with various parsings of the values\n */\n public static decodeAppState(state: { key: string; value: modelsv2.TealValue | modelsv2.EvalDelta }[]): AppState {\n const stateValues = {} as AppState\n\n // Start with empty set\n for (const stateVal of state) {\n const keyBase64 = stateVal.key\n const keyRaw = Buffer.from(keyBase64, 'base64')\n const key = keyRaw.toString('utf-8')\n const tealValue = stateVal.value\n\n const dataTypeFlag = 'action' in tealValue ? tealValue.action : tealValue.type\n let valueBase64: string\n let valueRaw: Buffer\n switch (dataTypeFlag) {\n case 1:\n valueBase64 = tealValue.bytes ?? ''\n valueRaw = Buffer.from(valueBase64, 'base64')\n stateValues[key] = {\n keyRaw,\n keyBase64,\n valueRaw: new Uint8Array(valueRaw),\n valueBase64: valueBase64,\n value: valueRaw.toString('utf-8'),\n }\n break\n case 2: {\n const value = tealValue.uint ?? 0\n stateValues[key] = {\n keyRaw,\n keyBase64,\n value: BigInt(value),\n }\n break\n }\n default:\n throw new Error(`Received unknown state data type of ${dataTypeFlag}`)\n }\n }\n\n return stateValues\n }\n\n /**\n * Returns any ABI return values for the given app call arguments and transaction confirmation.\n * @param confirmation The transaction confirmation from algod\n * @param method The ABI method\n * @returns The return value for the method call\n */\n public static getABIReturn(\n confirmation: modelsv2.PendingTransactionResponse | undefined,\n method: algosdk.ABIMethod | undefined,\n ): ABIReturn | undefined {\n if (!method || !confirmation || method.returns.type === 'void') {\n return undefined\n }\n\n // The parseMethodResponse method mutates the second parameter :(\n const resultDummy: algosdk.ABIResult = {\n txID: '',\n method,\n rawReturnValue: new Uint8Array(),\n }\n return getABIReturnValue(algosdk.AtomicTransactionComposer.parseMethodResponse(method, resultDummy, confirmation))\n }\n\n /**\n * Replaces AlgoKit deploy-time deployment control parameters within the given TEAL template code.\n *\n * * `TMPL_UPDATABLE` for updatability / immutability control\n * * `TMPL_DELETABLE` for deletability / permanence control\n *\n * Note: If these values are defined, but the corresponding `TMPL_*` value\n * isn't in the teal code it will throw an exception.\n *\n * @param tealTemplateCode The TEAL template code to substitute\n * @param params The deploy-time deployment control parameter value to replace\n * @returns The replaced TEAL code\n */\n static replaceTealTemplateDeployTimeControlParams(tealTemplateCode: string, params: { updatable?: boolean; deletable?: boolean }) {\n if (params.updatable !== undefined) {\n if (!tealTemplateCode.includes(UPDATABLE_TEMPLATE_NAME)) {\n throw new Error(\n `Deploy-time updatability control requested for app deployment, but ${UPDATABLE_TEMPLATE_NAME} not present in TEAL code`,\n )\n }\n tealTemplateCode = replaceTemplateVariable(tealTemplateCode, UPDATABLE_TEMPLATE_NAME, (params.updatable ? 1 : 0).toString())\n }\n\n if (params.deletable !== undefined) {\n if (!tealTemplateCode.includes(DELETABLE_TEMPLATE_NAME)) {\n throw new Error(\n `Deploy-time deletability control requested for app deployment, but ${DELETABLE_TEMPLATE_NAME} not present in TEAL code`,\n )\n }\n tealTemplateCode = replaceTemplateVariable(tealTemplateCode, DELETABLE_TEMPLATE_NAME, (params.deletable ? 1 : 0).toString())\n }\n\n return tealTemplateCode\n }\n\n /**\n * Performs template substitution of a teal file.\n *\n * Looks for `TMPL_{parameter}` for template replacements.\n *\n * @param tealTemplateCode The TEAL template code to make parameter replacements in\n * @param templateParams Any parameters to replace in the teal code\n * @returns The TEAL code with replacements\n */\n static replaceTealTemplateParams(tealTemplateCode: string, templateParams?: TealTemplateParams) {\n if (templateParams !== undefined) {\n for (const key in templateParams) {\n const value = templateParams[key]\n const token = `TMPL_${key.replace(/^TMPL_/, '')}`\n\n // If this is a number, first replace any byte representations of the number\n // These may appear in the TEAL in order to circumvent int compression and preserve PC values\n if (typeof value === 'number' || typeof value === 'bigint') {\n tealTemplateCode = tealTemplateCode.replace(new RegExp(`(?<=bytes )${token}`, 'g'), `0x${value.toString(16).padStart(16, '0')}`)\n\n // We could probably return here since mixing pushint and pushbytes is likely not going to happen, but might as well do both\n }\n\n tealTemplateCode = replaceTemplateVariable(\n tealTemplateCode,\n token,\n typeof value === 'string'\n ? `0x${Buffer.from(value, 'utf-8').toString('hex')}`\n : ArrayBuffer.isView(value)\n ? `0x${Buffer.from(value).toString('hex')}`\n : value.toString(),\n )\n }\n }\n\n return tealTemplateCode\n }\n\n /**\n * Remove comments from TEAL code (useful to reduce code size before compilation).\n *\n * @param tealCode The TEAL logic to strip\n * @returns The TEAL without comments\n */\n static stripTealComments(tealCode: string) {\n const stripCommentFromLine = (line: string) => {\n const commentIndex = findUnquotedString(line, '//')\n if (commentIndex === undefined) {\n return line\n }\n return line.slice(0, commentIndex).trimEnd()\n }\n\n return tealCode\n .split('\\n')\n .map((line) => stripCommentFromLine(line))\n .join('\\n')\n }\n}\n\n/**\n * Find the first string within a line of TEAL. Only matches outside of quotes and base64 are returned.\n * Returns undefined if not found\n */\nconst findUnquotedString = (line: string, token: string, startIndex: number = 0, _endIndex?: number): number | undefined => {\n const endIndex = _endIndex === undefined ? line.length : _endIndex\n let index = startIndex\n let inQuotes = false\n let inBase64 = false\n\n while (index < endIndex) {\n const currentChar = line[index]\n if ((currentChar === ' ' || currentChar === '(') && !inQuotes && lastTokenBase64(line, index)) {\n // enter base64\n inBase64 = true\n } else if ((currentChar === ' ' || currentChar === ')') && !inQuotes && inBase64) {\n // exit base64\n inBase64 = false\n } else if (currentChar === '\\\\' && inQuotes) {\n // escaped char, skip next character\n index += 1\n } else if (currentChar === '\"') {\n // quote boundary\n inQuotes = !inQuotes\n } else if (!inQuotes && !inBase64 && line.startsWith(token, index)) {\n // can test for match\n return index\n }\n index += 1\n }\n return undefined\n}\n\nconst lastTokenBase64 = (line: string, index: number): boolean => {\n try {\n const tokens = line.slice(0, index).split(/\\s+/)\n const last = tokens[tokens.length - 1]\n return ['base64', 'b64'].includes(last)\n } catch {\n return false\n }\n}\n\nfunction replaceTemplateVariable(program: string, token: string, replacement: string): string {\n const result: string[] = []\n const tokenIndexOffset = replacement.length - token.length\n\n const programLines = program.split('\\n')\n\n for (const line of programLines) {\n const _commentIndex = findUnquotedString(line, '//')\n const commentIndex = _commentIndex === undefined ? line.length : _commentIndex\n let code = line.substring(0, commentIndex)\n const comment = line.substring(commentIndex)\n let trailingIndex = 0\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const tokenIndex = findTemplateToken(code, token, trailingIndex)\n if (tokenIndex === undefined) {\n break\n }\n trailingIndex = tokenIndex + token.length\n const prefix = code.substring(0, tokenIndex)\n const suffix = code.substring(trailingIndex)\n code = `${prefix}${replacement}${suffix}`\n trailingIndex += tokenIndexOffset\n }\n result.push(code + comment)\n }\n\n return result.join('\\n')\n}\n\nconst findTemplateToken = (line: string, token: string, startIndex: number = 0, _endIndex?: number): number | undefined => {\n const endIndex = _endIndex === undefined ? line.length : _endIndex\n\n let index = startIndex\n while (index < endIndex) {\n const tokenIndex = findUnquotedString(line, token, index, endIndex)\n if (tokenIndex === undefined) {\n break\n }\n const trailingIndex = tokenIndex + token.length\n if (\n (tokenIndex === 0 || !isValidTokenCharacter(line[tokenIndex - 1])) &&\n (trailingIndex >= line.length || !isValidTokenCharacter(line[trailingIndex]))\n ) {\n return tokenIndex\n }\n index = trailingIndex\n }\n return undefined\n}\n\nfunction isValidTokenCharacter(char: string): boolean {\n return char.length === 1 && (/\\w/.test(char) || char === '_')\n}\n"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GAAG,QAAQ,EAAE;AACvB,QAAA,MAAM,UAAU,GAAG,kBAAkB,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC;AACnE,QAAA,IAAI,UAAU,KAAK,SAAS,EAAE;YAC5B;;AAEF,QAAA,MAAM,aAAa,GAAG,UAAU,GAAG,KAAK,CAAC,MAAM;AAC/C,QAAA,IACE,CAAC,UAAU,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;AACjE,aAAC,aAAa,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAC7E;AACA,YAAA,OAAO,UAAU;;QAEnB,KAAK,GAAG,aAAa;;AAEvB,IAAA,OAAO,SAAS;AAClB,CAAC;AAED,SAAS,qBAAqB,CAAC,IAAY,EAAA;AACzC,IAAA,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,GAAG,CAAC;AAC/D;;;;"}
@@ -142,7 +142,8 @@ class AppManager {
142
142
  * @returns The current box value as a byte array
143
143
  */
144
144
  async getBoxValue(appId, boxName) {
145
- const name = AppManager.getBoxReference(boxName).name;
145
+ const boxId = typeof boxName === 'object' && 'nameRaw' in boxName ? boxName.nameRaw : boxName;
146
+ const name = AppManager.getBoxReference(boxId).name;
146
147
  const boxResult = await this._algod.getApplicationBoxByName(Number(appId), name).do();
147
148
  return boxResult.value;
148
149
  }
@@ -1 +1 @@
1
- {"version":3,"file":"app-manager.mjs","sources":["../../src/types/app-manager.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { getABIReturnValue } from '../transaction/transaction'\nimport { TransactionSignerAccount } from './account'\nimport {\n BoxName,\n DELETABLE_TEMPLATE_NAME,\n UPDATABLE_TEMPLATE_NAME,\n type ABIReturn,\n type AppState,\n type CompiledTeal,\n type TealTemplateParams,\n} from './app'\nimport modelsv2 = algosdk.modelsv2\n\n/** Information about an app. */\nexport interface AppInformation {\n /** The ID of the app. */\n appId: bigint\n /** The escrow address that the app operates with. */\n appAddress: string\n /**\n * Approval program.\n */\n approvalProgram: Uint8Array\n /**\n * Clear state program.\n */\n clearStateProgram: Uint8Array\n /**\n * The address that created this application. This is the address where the\n * parameters and global state for this application can be found.\n */\n creator: string\n /**\n * Current global state values.\n */\n globalState: AppState\n /** The number of allocated ints in per-user local state. */\n localInts: number\n /** The number of allocated byte slices in per-user local state. */\n localByteSlices: number\n /** The number of allocated ints in global state. */\n globalInts: number\n /** The number of allocated byte slices in global state. */\n globalByteSlices: number\n /** Any extra pages that are needed for the smart contract. */\n extraProgramPages?: number\n}\n\n/**\n * Something that identifies an app box name - either a:\n * * `Uint8Array` (the actual binary of the box name)\n * * `string` (that will be encoded to a `Uint8Array`)\n * * `TransactionSignerAccount` (that will be encoded into the\n * public key address of the corresponding account)\n */\nexport type BoxIdentifier = string | Uint8Array | TransactionSignerAccount\n\n/**\n * A grouping of the app ID and name identifier to reference an app box.\n */\nexport interface BoxReference {\n /**\n * A unique application id\n */\n appId: bigint\n /**\n * Identifier for a box name\n */\n name: BoxIdentifier\n}\n\n/**\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValueRequestParams {\n /** The ID of the app return box names for */\n appId: bigint\n /** The name of the box to return either as a string, binary array or `BoxName` */\n boxName: BoxIdentifier\n /** The ABI type to decode the value using */\n type: algosdk.ABIType\n}\n\n/**\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValuesRequestParams {\n /** The ID of the app return box names for */\n appId: bigint\n /** The names of the boxes to return either as a string, binary array or BoxName` */\n boxNames: BoxIdentifier[]\n /** The ABI type to decode the value using */\n type: algosdk.ABIType\n}\n\n/** Allows management of application information. */\nexport class AppManager {\n private _algod: algosdk.Algodv2\n private _compilationResults: Record<string, CompiledTeal> = {}\n\n /**\n * Creates an `AppManager`\n * @param algod An algod instance\n */\n constructor(algod: algosdk.Algodv2) {\n this._algod = algod\n }\n\n /**\n * Compiles the given TEAL using algod and returns the result, including source map.\n *\n * The result of this compilation is also cached keyed by the TEAL\n * code so it can be retrieved via `getCompilationResult`.\n *\n * This function is re-entrant; it will only compile the same code once.\n *\n * @param tealCode The TEAL code\n * @returns The information about the compiled file\n */\n async compileTeal(tealCode: string): Promise<CompiledTeal> {\n if (this._compilationResults[tealCode]) {\n return this._compilationResults[tealCode]\n }\n\n const compiled = await this._algod.compile(tealCode).sourcemap(true).do()\n const result = {\n teal: tealCode,\n compiled: compiled.result,\n compiledHash: compiled.hash,\n compiledBase64ToBytes: new Uint8Array(Buffer.from(compiled.result, 'base64')),\n sourceMap: new algosdk.SourceMap(compiled['sourcemap']),\n }\n this._compilationResults[tealCode] = result\n\n return result\n }\n\n /**\n * Performs template substitution of a teal template and compiles it, returning the compiled result.\n *\n * Looks for `TMPL_{parameter}` for template replacements and replaces AlgoKit deploy-time control parameters\n * if deployment metadata is specified.\n *\n * * `TMPL_UPDATABLE` for updatability / immutability control\n * * `TMPL_DELETABLE` for deletability / permanence control\n *\n * @param tealTemplateCode The TEAL logic to compile\n * @param templateParams Any parameters to replace in the .teal file before compiling\n * @param deploymentMetadata The deployment metadata the app will be deployed with\n * @returns The information about the compiled code\n */\n async compileTealTemplate(\n tealTemplateCode: string,\n templateParams?: TealTemplateParams,\n deploymentMetadata?: { updatable?: boolean; deletable?: boolean },\n ): Promise<CompiledTeal> {\n let tealCode = AppManager.stripTealComments(tealTemplateCode)\n\n tealCode = AppManager.replaceTealTemplateParams(tealCode, templateParams)\n\n if (deploymentMetadata) {\n tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealCode, deploymentMetadata)\n }\n\n return await this.compileTeal(tealCode)\n }\n\n /**\n * Returns a previous compilation result.\n * @param tealCode The TEAL code\n * @returns The information about the previously compiled file\n * or `undefined` if that TEAL code wasn't previously compiled\n */\n getCompilationResult(tealCode: string): CompiledTeal | undefined {\n return this._compilationResults[tealCode]\n }\n\n /**\n * Returns the current app information for the app with the given ID.\n *\n * @example\n * ```typescript\n * const appInfo = await appManager.getById(12353n);\n * ```\n *\n * @param appId The ID of the app\n * @returns The app information\n */\n public async getById(appId: bigint): Promise<AppInformation> {\n const app = modelsv2.Application.from_obj_for_encoding(await this._algod.getApplicationByID(Number(appId)).do())\n return {\n appId: BigInt(app.id),\n appAddress: algosdk.getApplicationAddress(app.id),\n approvalProgram: app.params.approvalProgram,\n clearStateProgram: app.params.clearStateProgram,\n creator: app.params.creator,\n localInts: Number(app.params.localStateSchema?.numUint ?? 0),\n localByteSlices: Number(app.params.localStateSchema?.numByteSlice ?? 0),\n globalInts: Number(app.params.globalStateSchema?.numUint ?? 0),\n globalByteSlices: Number(app.params.globalStateSchema?.numByteSlice ?? 0),\n extraProgramPages: Number(app.params.extraProgramPages ?? 0),\n globalState: AppManager.decodeAppState(app.params.globalState ?? []),\n }\n }\n\n /**\n * Returns the current global state values for the given app ID and account address\n *\n * @param appId The ID of the app to return global state for\n * @returns The current global state for the given app\n */\n public async getGlobalState(appId: bigint) {\n return (await this.getById(appId)).globalState\n }\n\n /**\n * Returns the current local state values for the given app ID and account address\n *\n * @param appId The ID of the app to return local state for\n * @param address The string address of the account to get local state for the given app\n * @returns The current local state for the given (app, account) combination\n */\n public async getLocalState(appId: bigint, address: string) {\n const appInfo = modelsv2.AccountApplicationResponse.from_obj_for_encoding(\n await this._algod.accountApplicationInformation(address, Number(appId)).do(),\n )\n\n if (!appInfo.appLocalState?.keyValue) {\n throw new Error(\"Couldn't find local state\")\n }\n\n return AppManager.decodeAppState(appInfo.appLocalState.keyValue)\n }\n\n /**\n * Returns the names of the current boxes for the given app.\n * @param appId The ID of the app return box names for\n * @returns The current box names\n */\n public async getBoxNames(appId: bigint): Promise<BoxName[]> {\n const boxResult = await this._algod.getApplicationBoxes(Number(appId)).do()\n return boxResult.boxes.map((b) => {\n return {\n nameRaw: b.name,\n nameBase64: Buffer.from(b.name).toString('base64'),\n name: Buffer.from(b.name).toString('utf-8'),\n }\n })\n }\n\n /**\n * Returns the value of the given box name for the given app.\n * @param appId The ID of the app return box names for\n * @param boxName The name of the box to return either as a string, binary array or `BoxName`\n * @returns The current box value as a byte array\n */\n public async getBoxValue(appId: bigint, boxName: BoxIdentifier): Promise<Uint8Array> {\n const name = AppManager.getBoxReference(boxName).name\n const boxResult = await this._algod.getApplicationBoxByName(Number(appId), name).do()\n return boxResult.value\n }\n\n /**\n * Returns the value of the given box names for the given app.\n * @param appId The ID of the app return box names for\n * @param boxNames The names of the boxes to return either as a string, binary array or `BoxName`\n * @returns The current box values as a byte array in the same order as the passed in box names\n */\n public async getBoxValues(appId: bigint, boxNames: BoxIdentifier[]): Promise<Uint8Array[]> {\n return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValue(appId, boxName)))\n }\n\n /**\n * Returns the value of the given box name for the given app decoded based on the given ABI type.\n * @param request The parameters for the box value request\n * @returns The current box value as an ABI value\n */\n public async getBoxValueFromABIType(request: BoxValueRequestParams): Promise<algosdk.ABIValue> {\n const { appId, boxName, type } = request\n const value = await this.getBoxValue(appId, boxName)\n return type.decode(value)\n }\n\n /**\n * Returns the value of the given box names for the given app decoded based on the given ABI type.\n * @param request The parameters for the box value request\n * @returns The current box values as an ABI value in the same order as the passed in box names\n */\n public async getBoxValuesFromABIType(request: BoxValuesRequestParams): Promise<algosdk.ABIValue[]> {\n const { appId, boxNames, type } = request\n return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValueFromABIType({ appId, boxName, type })))\n }\n\n /**\n * Returns a `algosdk.BoxReference` given a `BoxIdentifier` or `BoxReference`.\n * @param boxId The box to return a reference for\n * @returns The box reference ready to pass into a `algosdk.Transaction`\n */\n public static getBoxReference(boxId: BoxIdentifier | BoxReference): algosdk.BoxReference {\n const ref = typeof boxId === 'object' && 'appId' in boxId ? boxId : { appId: 0n, name: boxId }\n return {\n appIndex: Number(ref.appId),\n name:\n typeof ref.name === 'string'\n ? new TextEncoder().encode(ref.name)\n : 'length' in ref.name\n ? ref.name\n : algosdk.decodeAddress(ref.name.addr).publicKey,\n } as algosdk.BoxReference\n }\n\n /**\n * Converts an array of global/local state values from the algod api to a more friendly\n * generic object keyed by the UTF-8 value of the key.\n * @param state A `global-state`, `local-state`, `global-state-deltas` or `local-state-deltas`\n * @returns An object keyeed by the UTF-8 representation of the key with various parsings of the values\n */\n public static decodeAppState(state: { key: string; value: modelsv2.TealValue | modelsv2.EvalDelta }[]): AppState {\n const stateValues = {} as AppState\n\n // Start with empty set\n for (const stateVal of state) {\n const keyBase64 = stateVal.key\n const keyRaw = Buffer.from(keyBase64, 'base64')\n const key = keyRaw.toString('utf-8')\n const tealValue = stateVal.value\n\n const dataTypeFlag = 'action' in tealValue ? tealValue.action : tealValue.type\n let valueBase64: string\n let valueRaw: Buffer\n switch (dataTypeFlag) {\n case 1:\n valueBase64 = tealValue.bytes ?? ''\n valueRaw = Buffer.from(valueBase64, 'base64')\n stateValues[key] = {\n keyRaw,\n keyBase64,\n valueRaw: new Uint8Array(valueRaw),\n valueBase64: valueBase64,\n value: valueRaw.toString('utf-8'),\n }\n break\n case 2: {\n const value = tealValue.uint ?? 0\n stateValues[key] = {\n keyRaw,\n keyBase64,\n value: BigInt(value),\n }\n break\n }\n default:\n throw new Error(`Received unknown state data type of ${dataTypeFlag}`)\n }\n }\n\n return stateValues\n }\n\n /**\n * Returns any ABI return values for the given app call arguments and transaction confirmation.\n * @param confirmation The transaction confirmation from algod\n * @param method The ABI method\n * @returns The return value for the method call\n */\n public static getABIReturn(\n confirmation: modelsv2.PendingTransactionResponse | undefined,\n method: algosdk.ABIMethod | undefined,\n ): ABIReturn | undefined {\n if (!method || !confirmation || method.returns.type === 'void') {\n return undefined\n }\n\n // The parseMethodResponse method mutates the second parameter :(\n const resultDummy: algosdk.ABIResult = {\n txID: '',\n method,\n rawReturnValue: new Uint8Array(),\n }\n return getABIReturnValue(algosdk.AtomicTransactionComposer.parseMethodResponse(method, resultDummy, confirmation))\n }\n\n /**\n * Replaces AlgoKit deploy-time deployment control parameters within the given TEAL template code.\n *\n * * `TMPL_UPDATABLE` for updatability / immutability control\n * * `TMPL_DELETABLE` for deletability / permanence control\n *\n * Note: If these values are defined, but the corresponding `TMPL_*` value\n * isn't in the teal code it will throw an exception.\n *\n * @param tealTemplateCode The TEAL template code to substitute\n * @param params The deploy-time deployment control parameter value to replace\n * @returns The replaced TEAL code\n */\n static replaceTealTemplateDeployTimeControlParams(tealTemplateCode: string, params: { updatable?: boolean; deletable?: boolean }) {\n if (params.updatable !== undefined) {\n if (!tealTemplateCode.includes(UPDATABLE_TEMPLATE_NAME)) {\n throw new Error(\n `Deploy-time updatability control requested for app deployment, but ${UPDATABLE_TEMPLATE_NAME} not present in TEAL code`,\n )\n }\n tealTemplateCode = replaceTemplateVariable(tealTemplateCode, UPDATABLE_TEMPLATE_NAME, (params.updatable ? 1 : 0).toString())\n }\n\n if (params.deletable !== undefined) {\n if (!tealTemplateCode.includes(DELETABLE_TEMPLATE_NAME)) {\n throw new Error(\n `Deploy-time deletability control requested for app deployment, but ${DELETABLE_TEMPLATE_NAME} not present in TEAL code`,\n )\n }\n tealTemplateCode = replaceTemplateVariable(tealTemplateCode, DELETABLE_TEMPLATE_NAME, (params.deletable ? 1 : 0).toString())\n }\n\n return tealTemplateCode\n }\n\n /**\n * Performs template substitution of a teal file.\n *\n * Looks for `TMPL_{parameter}` for template replacements.\n *\n * @param tealTemplateCode The TEAL template code to make parameter replacements in\n * @param templateParams Any parameters to replace in the teal code\n * @returns The TEAL code with replacements\n */\n static replaceTealTemplateParams(tealTemplateCode: string, templateParams?: TealTemplateParams) {\n if (templateParams !== undefined) {\n for (const key in templateParams) {\n const value = templateParams[key]\n const token = `TMPL_${key.replace(/^TMPL_/, '')}`\n\n // If this is a number, first replace any byte representations of the number\n // These may appear in the TEAL in order to circumvent int compression and preserve PC values\n if (typeof value === 'number' || typeof value === 'bigint') {\n tealTemplateCode = tealTemplateCode.replace(new RegExp(`(?<=bytes )${token}`, 'g'), `0x${value.toString(16).padStart(16, '0')}`)\n\n // We could probably return here since mixing pushint and pushbytes is likely not going to happen, but might as well do both\n }\n\n tealTemplateCode = replaceTemplateVariable(\n tealTemplateCode,\n token,\n typeof value === 'string'\n ? `0x${Buffer.from(value, 'utf-8').toString('hex')}`\n : ArrayBuffer.isView(value)\n ? `0x${Buffer.from(value).toString('hex')}`\n : value.toString(),\n )\n }\n }\n\n return tealTemplateCode\n }\n\n /**\n * Remove comments from TEAL code (useful to reduce code size before compilation).\n *\n * @param tealCode The TEAL logic to strip\n * @returns The TEAL without comments\n */\n static stripTealComments(tealCode: string) {\n const stripCommentFromLine = (line: string) => {\n const commentIndex = findUnquotedString(line, '//')\n if (commentIndex === undefined) {\n return line\n }\n return line.slice(0, commentIndex).trimEnd()\n }\n\n return tealCode\n .split('\\n')\n .map((line) => stripCommentFromLine(line))\n .join('\\n')\n }\n}\n\n/**\n * Find the first string within a line of TEAL. Only matches outside of quotes and base64 are returned.\n * Returns undefined if not found\n */\nconst findUnquotedString = (line: string, token: string, startIndex: number = 0, _endIndex?: number): number | undefined => {\n const endIndex = _endIndex === undefined ? line.length : _endIndex\n let index = startIndex\n let inQuotes = false\n let inBase64 = false\n\n while (index < endIndex) {\n const currentChar = line[index]\n if ((currentChar === ' ' || currentChar === '(') && !inQuotes && lastTokenBase64(line, index)) {\n // enter base64\n inBase64 = true\n } else if ((currentChar === ' ' || currentChar === ')') && !inQuotes && inBase64) {\n // exit base64\n inBase64 = false\n } else if (currentChar === '\\\\' && inQuotes) {\n // escaped char, skip next character\n index += 1\n } else if (currentChar === '\"') {\n // quote boundary\n inQuotes = !inQuotes\n } else if (!inQuotes && !inBase64 && line.startsWith(token, index)) {\n // can test for match\n return index\n }\n index += 1\n }\n return undefined\n}\n\nconst lastTokenBase64 = (line: string, index: number): boolean => {\n try {\n const tokens = line.slice(0, index).split(/\\s+/)\n const last = tokens[tokens.length - 1]\n return ['base64', 'b64'].includes(last)\n } catch {\n return false\n }\n}\n\nfunction replaceTemplateVariable(program: string, token: string, replacement: string): string {\n const result: string[] = []\n const tokenIndexOffset = replacement.length - token.length\n\n const programLines = program.split('\\n')\n\n for (const line of programLines) {\n const _commentIndex = findUnquotedString(line, '//')\n const commentIndex = _commentIndex === undefined ? line.length : _commentIndex\n let code = line.substring(0, commentIndex)\n const comment = line.substring(commentIndex)\n let trailingIndex = 0\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const tokenIndex = findTemplateToken(code, token, trailingIndex)\n if (tokenIndex === undefined) {\n break\n }\n trailingIndex = tokenIndex + token.length\n const prefix = code.substring(0, tokenIndex)\n const suffix = code.substring(trailingIndex)\n code = `${prefix}${replacement}${suffix}`\n trailingIndex += tokenIndexOffset\n }\n result.push(code + comment)\n }\n\n return result.join('\\n')\n}\n\nconst findTemplateToken = (line: string, token: string, startIndex: number = 0, _endIndex?: number): number | undefined => {\n const endIndex = _endIndex === undefined ? line.length : _endIndex\n\n let index = startIndex\n while (index < endIndex) {\n const tokenIndex = findUnquotedString(line, token, index, endIndex)\n if (tokenIndex === undefined) {\n break\n }\n const trailingIndex = tokenIndex + token.length\n if (\n (tokenIndex === 0 || !isValidTokenCharacter(line[tokenIndex - 1])) &&\n (trailingIndex >= line.length || !isValidTokenCharacter(line[trailingIndex]))\n ) {\n return tokenIndex\n }\n index = trailingIndex\n }\n return undefined\n}\n\nfunction isValidTokenCharacter(char: string): boolean {\n return char.length === 1 && (/\\w/.test(char) || char === '_')\n}\n"],"names":[],"mappings":";;;;AAYA,IAAO,QAAQ,GAAG,OAAO,CAAC,QAAQ;AAoFlC;MACa,UAAU,CAAA;AAIrB;;;AAGG;AACH,IAAA,WAAA,CAAY,KAAsB,EAAA;QAN1B,IAAmB,CAAA,mBAAA,GAAiC,EAAE;AAO5D,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK;;AAGrB;;;;;;;;;;AAUG;IACH,MAAM,WAAW,CAAC,QAAgB,EAAA;AAChC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U;;QAEnB,KAAK,GAAG,aAAa;;AAEvB,IAAA,OAAO,SAAS;AAClB,CAAC;AAED,SAAS,qBAAqB,CAAC,IAAY,EAAA;AACzC,IAAA,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,GAAG,CAAC;AAC/D;;;;"}
1
+ {"version":3,"file":"app-manager.mjs","sources":["../../src/types/app-manager.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { getABIReturnValue } from '../transaction/transaction'\nimport { TransactionSignerAccount } from './account'\nimport {\n BoxName,\n DELETABLE_TEMPLATE_NAME,\n UPDATABLE_TEMPLATE_NAME,\n type ABIReturn,\n type AppState,\n type CompiledTeal,\n type TealTemplateParams,\n} from './app'\nimport modelsv2 = algosdk.modelsv2\n\n/** Information about an app. */\nexport interface AppInformation {\n /** The ID of the app. */\n appId: bigint\n /** The escrow address that the app operates with. */\n appAddress: string\n /**\n * Approval program.\n */\n approvalProgram: Uint8Array\n /**\n * Clear state program.\n */\n clearStateProgram: Uint8Array\n /**\n * The address that created this application. This is the address where the\n * parameters and global state for this application can be found.\n */\n creator: string\n /**\n * Current global state values.\n */\n globalState: AppState\n /** The number of allocated ints in per-user local state. */\n localInts: number\n /** The number of allocated byte slices in per-user local state. */\n localByteSlices: number\n /** The number of allocated ints in global state. */\n globalInts: number\n /** The number of allocated byte slices in global state. */\n globalByteSlices: number\n /** Any extra pages that are needed for the smart contract. */\n extraProgramPages?: number\n}\n\n/**\n * Something that identifies an app box name - either a:\n * * `Uint8Array` (the actual binary of the box name)\n * * `string` (that will be encoded to a `Uint8Array`)\n * * `TransactionSignerAccount` (that will be encoded into the\n * public key address of the corresponding account)\n */\nexport type BoxIdentifier = string | Uint8Array | TransactionSignerAccount\n\n/**\n * A grouping of the app ID and name identifier to reference an app box.\n */\nexport interface BoxReference {\n /**\n * A unique application id\n */\n appId: bigint\n /**\n * Identifier for a box name\n */\n name: BoxIdentifier\n}\n\n/**\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValueRequestParams {\n /** The ID of the app return box names for */\n appId: bigint\n /** The name of the box to return either as a string, binary array or `BoxName` */\n boxName: BoxIdentifier\n /** The ABI type to decode the value using */\n type: algosdk.ABIType\n}\n\n/**\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValuesRequestParams {\n /** The ID of the app return box names for */\n appId: bigint\n /** The names of the boxes to return either as a string, binary array or BoxName` */\n boxNames: BoxIdentifier[]\n /** The ABI type to decode the value using */\n type: algosdk.ABIType\n}\n\n/** Allows management of application information. */\nexport class AppManager {\n private _algod: algosdk.Algodv2\n private _compilationResults: Record<string, CompiledTeal> = {}\n\n /**\n * Creates an `AppManager`\n * @param algod An algod instance\n */\n constructor(algod: algosdk.Algodv2) {\n this._algod = algod\n }\n\n /**\n * Compiles the given TEAL using algod and returns the result, including source map.\n *\n * The result of this compilation is also cached keyed by the TEAL\n * code so it can be retrieved via `getCompilationResult`.\n *\n * This function is re-entrant; it will only compile the same code once.\n *\n * @param tealCode The TEAL code\n * @returns The information about the compiled file\n */\n async compileTeal(tealCode: string): Promise<CompiledTeal> {\n if (this._compilationResults[tealCode]) {\n return this._compilationResults[tealCode]\n }\n\n const compiled = await this._algod.compile(tealCode).sourcemap(true).do()\n const result = {\n teal: tealCode,\n compiled: compiled.result,\n compiledHash: compiled.hash,\n compiledBase64ToBytes: new Uint8Array(Buffer.from(compiled.result, 'base64')),\n sourceMap: new algosdk.SourceMap(compiled['sourcemap']),\n }\n this._compilationResults[tealCode] = result\n\n return result\n }\n\n /**\n * Performs template substitution of a teal template and compiles it, returning the compiled result.\n *\n * Looks for `TMPL_{parameter}` for template replacements and replaces AlgoKit deploy-time control parameters\n * if deployment metadata is specified.\n *\n * * `TMPL_UPDATABLE` for updatability / immutability control\n * * `TMPL_DELETABLE` for deletability / permanence control\n *\n * @param tealTemplateCode The TEAL logic to compile\n * @param templateParams Any parameters to replace in the .teal file before compiling\n * @param deploymentMetadata The deployment metadata the app will be deployed with\n * @returns The information about the compiled code\n */\n async compileTealTemplate(\n tealTemplateCode: string,\n templateParams?: TealTemplateParams,\n deploymentMetadata?: { updatable?: boolean; deletable?: boolean },\n ): Promise<CompiledTeal> {\n let tealCode = AppManager.stripTealComments(tealTemplateCode)\n\n tealCode = AppManager.replaceTealTemplateParams(tealCode, templateParams)\n\n if (deploymentMetadata) {\n tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealCode, deploymentMetadata)\n }\n\n return await this.compileTeal(tealCode)\n }\n\n /**\n * Returns a previous compilation result.\n * @param tealCode The TEAL code\n * @returns The information about the previously compiled file\n * or `undefined` if that TEAL code wasn't previously compiled\n */\n getCompilationResult(tealCode: string): CompiledTeal | undefined {\n return this._compilationResults[tealCode]\n }\n\n /**\n * Returns the current app information for the app with the given ID.\n *\n * @example\n * ```typescript\n * const appInfo = await appManager.getById(12353n);\n * ```\n *\n * @param appId The ID of the app\n * @returns The app information\n */\n public async getById(appId: bigint): Promise<AppInformation> {\n const app = modelsv2.Application.from_obj_for_encoding(await this._algod.getApplicationByID(Number(appId)).do())\n return {\n appId: BigInt(app.id),\n appAddress: algosdk.getApplicationAddress(app.id),\n approvalProgram: app.params.approvalProgram,\n clearStateProgram: app.params.clearStateProgram,\n creator: app.params.creator,\n localInts: Number(app.params.localStateSchema?.numUint ?? 0),\n localByteSlices: Number(app.params.localStateSchema?.numByteSlice ?? 0),\n globalInts: Number(app.params.globalStateSchema?.numUint ?? 0),\n globalByteSlices: Number(app.params.globalStateSchema?.numByteSlice ?? 0),\n extraProgramPages: Number(app.params.extraProgramPages ?? 0),\n globalState: AppManager.decodeAppState(app.params.globalState ?? []),\n }\n }\n\n /**\n * Returns the current global state values for the given app ID and account address\n *\n * @param appId The ID of the app to return global state for\n * @returns The current global state for the given app\n */\n public async getGlobalState(appId: bigint) {\n return (await this.getById(appId)).globalState\n }\n\n /**\n * Returns the current local state values for the given app ID and account address\n *\n * @param appId The ID of the app to return local state for\n * @param address The string address of the account to get local state for the given app\n * @returns The current local state for the given (app, account) combination\n */\n public async getLocalState(appId: bigint, address: string) {\n const appInfo = modelsv2.AccountApplicationResponse.from_obj_for_encoding(\n await this._algod.accountApplicationInformation(address, Number(appId)).do(),\n )\n\n if (!appInfo.appLocalState?.keyValue) {\n throw new Error(\"Couldn't find local state\")\n }\n\n return AppManager.decodeAppState(appInfo.appLocalState.keyValue)\n }\n\n /**\n * Returns the names of the current boxes for the given app.\n * @param appId The ID of the app return box names for\n * @returns The current box names\n */\n public async getBoxNames(appId: bigint): Promise<BoxName[]> {\n const boxResult = await this._algod.getApplicationBoxes(Number(appId)).do()\n return boxResult.boxes.map((b) => {\n return {\n nameRaw: b.name,\n nameBase64: Buffer.from(b.name).toString('base64'),\n name: Buffer.from(b.name).toString('utf-8'),\n }\n })\n }\n\n /**\n * Returns the value of the given box name for the given app.\n * @param appId The ID of the app return box names for\n * @param boxName The name of the box to return either as a string, binary array or `BoxName`\n * @returns The current box value as a byte array\n */\n public async getBoxValue(appId: bigint, boxName: BoxIdentifier | BoxName): Promise<Uint8Array> {\n const boxId = typeof boxName === 'object' && 'nameRaw' in boxName ? boxName.nameRaw : boxName\n const name = AppManager.getBoxReference(boxId).name\n const boxResult = await this._algod.getApplicationBoxByName(Number(appId), name).do()\n return boxResult.value\n }\n\n /**\n * Returns the value of the given box names for the given app.\n * @param appId The ID of the app return box names for\n * @param boxNames The names of the boxes to return either as a string, binary array or `BoxName`\n * @returns The current box values as a byte array in the same order as the passed in box names\n */\n public async getBoxValues(appId: bigint, boxNames: (BoxIdentifier | BoxName)[]): Promise<Uint8Array[]> {\n return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValue(appId, boxName)))\n }\n\n /**\n * Returns the value of the given box name for the given app decoded based on the given ABI type.\n * @param request The parameters for the box value request\n * @returns The current box value as an ABI value\n */\n public async getBoxValueFromABIType(request: BoxValueRequestParams): Promise<algosdk.ABIValue> {\n const { appId, boxName, type } = request\n const value = await this.getBoxValue(appId, boxName)\n return type.decode(value)\n }\n\n /**\n * Returns the value of the given box names for the given app decoded based on the given ABI type.\n * @param request The parameters for the box value request\n * @returns The current box values as an ABI value in the same order as the passed in box names\n */\n public async getBoxValuesFromABIType(request: BoxValuesRequestParams): Promise<algosdk.ABIValue[]> {\n const { appId, boxNames, type } = request\n return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValueFromABIType({ appId, boxName, type })))\n }\n\n /**\n * Returns a `algosdk.BoxReference` given a `BoxIdentifier` or `BoxReference`.\n * @param boxId The box to return a reference for\n * @returns The box reference ready to pass into a `algosdk.Transaction`\n */\n public static getBoxReference(boxId: BoxIdentifier | BoxReference): algosdk.BoxReference {\n const ref = typeof boxId === 'object' && 'appId' in boxId ? boxId : { appId: 0n, name: boxId }\n return {\n appIndex: Number(ref.appId),\n name:\n typeof ref.name === 'string'\n ? new TextEncoder().encode(ref.name)\n : 'length' in ref.name\n ? ref.name\n : algosdk.decodeAddress(ref.name.addr).publicKey,\n } as algosdk.BoxReference\n }\n\n /**\n * Converts an array of global/local state values from the algod api to a more friendly\n * generic object keyed by the UTF-8 value of the key.\n * @param state A `global-state`, `local-state`, `global-state-deltas` or `local-state-deltas`\n * @returns An object keyeed by the UTF-8 representation of the key with various parsings of the values\n */\n public static decodeAppState(state: { key: string; value: modelsv2.TealValue | modelsv2.EvalDelta }[]): AppState {\n const stateValues = {} as AppState\n\n // Start with empty set\n for (const stateVal of state) {\n const keyBase64 = stateVal.key\n const keyRaw = Buffer.from(keyBase64, 'base64')\n const key = keyRaw.toString('utf-8')\n const tealValue = stateVal.value\n\n const dataTypeFlag = 'action' in tealValue ? tealValue.action : tealValue.type\n let valueBase64: string\n let valueRaw: Buffer\n switch (dataTypeFlag) {\n case 1:\n valueBase64 = tealValue.bytes ?? ''\n valueRaw = Buffer.from(valueBase64, 'base64')\n stateValues[key] = {\n keyRaw,\n keyBase64,\n valueRaw: new Uint8Array(valueRaw),\n valueBase64: valueBase64,\n value: valueRaw.toString('utf-8'),\n }\n break\n case 2: {\n const value = tealValue.uint ?? 0\n stateValues[key] = {\n keyRaw,\n keyBase64,\n value: BigInt(value),\n }\n break\n }\n default:\n throw new Error(`Received unknown state data type of ${dataTypeFlag}`)\n }\n }\n\n return stateValues\n }\n\n /**\n * Returns any ABI return values for the given app call arguments and transaction confirmation.\n * @param confirmation The transaction confirmation from algod\n * @param method The ABI method\n * @returns The return value for the method call\n */\n public static getABIReturn(\n confirmation: modelsv2.PendingTransactionResponse | undefined,\n method: algosdk.ABIMethod | undefined,\n ): ABIReturn | undefined {\n if (!method || !confirmation || method.returns.type === 'void') {\n return undefined\n }\n\n // The parseMethodResponse method mutates the second parameter :(\n const resultDummy: algosdk.ABIResult = {\n txID: '',\n method,\n rawReturnValue: new Uint8Array(),\n }\n return getABIReturnValue(algosdk.AtomicTransactionComposer.parseMethodResponse(method, resultDummy, confirmation))\n }\n\n /**\n * Replaces AlgoKit deploy-time deployment control parameters within the given TEAL template code.\n *\n * * `TMPL_UPDATABLE` for updatability / immutability control\n * * `TMPL_DELETABLE` for deletability / permanence control\n *\n * Note: If these values are defined, but the corresponding `TMPL_*` value\n * isn't in the teal code it will throw an exception.\n *\n * @param tealTemplateCode The TEAL template code to substitute\n * @param params The deploy-time deployment control parameter value to replace\n * @returns The replaced TEAL code\n */\n static replaceTealTemplateDeployTimeControlParams(tealTemplateCode: string, params: { updatable?: boolean; deletable?: boolean }) {\n if (params.updatable !== undefined) {\n if (!tealTemplateCode.includes(UPDATABLE_TEMPLATE_NAME)) {\n throw new Error(\n `Deploy-time updatability control requested for app deployment, but ${UPDATABLE_TEMPLATE_NAME} not present in TEAL code`,\n )\n }\n tealTemplateCode = replaceTemplateVariable(tealTemplateCode, UPDATABLE_TEMPLATE_NAME, (params.updatable ? 1 : 0).toString())\n }\n\n if (params.deletable !== undefined) {\n if (!tealTemplateCode.includes(DELETABLE_TEMPLATE_NAME)) {\n throw new Error(\n `Deploy-time deletability control requested for app deployment, but ${DELETABLE_TEMPLATE_NAME} not present in TEAL code`,\n )\n }\n tealTemplateCode = replaceTemplateVariable(tealTemplateCode, DELETABLE_TEMPLATE_NAME, (params.deletable ? 1 : 0).toString())\n }\n\n return tealTemplateCode\n }\n\n /**\n * Performs template substitution of a teal file.\n *\n * Looks for `TMPL_{parameter}` for template replacements.\n *\n * @param tealTemplateCode The TEAL template code to make parameter replacements in\n * @param templateParams Any parameters to replace in the teal code\n * @returns The TEAL code with replacements\n */\n static replaceTealTemplateParams(tealTemplateCode: string, templateParams?: TealTemplateParams) {\n if (templateParams !== undefined) {\n for (const key in templateParams) {\n const value = templateParams[key]\n const token = `TMPL_${key.replace(/^TMPL_/, '')}`\n\n // If this is a number, first replace any byte representations of the number\n // These may appear in the TEAL in order to circumvent int compression and preserve PC values\n if (typeof value === 'number' || typeof value === 'bigint') {\n tealTemplateCode = tealTemplateCode.replace(new RegExp(`(?<=bytes )${token}`, 'g'), `0x${value.toString(16).padStart(16, '0')}`)\n\n // We could probably return here since mixing pushint and pushbytes is likely not going to happen, but might as well do both\n }\n\n tealTemplateCode = replaceTemplateVariable(\n tealTemplateCode,\n token,\n typeof value === 'string'\n ? `0x${Buffer.from(value, 'utf-8').toString('hex')}`\n : ArrayBuffer.isView(value)\n ? `0x${Buffer.from(value).toString('hex')}`\n : value.toString(),\n )\n }\n }\n\n return tealTemplateCode\n }\n\n /**\n * Remove comments from TEAL code (useful to reduce code size before compilation).\n *\n * @param tealCode The TEAL logic to strip\n * @returns The TEAL without comments\n */\n static stripTealComments(tealCode: string) {\n const stripCommentFromLine = (line: string) => {\n const commentIndex = findUnquotedString(line, '//')\n if (commentIndex === undefined) {\n return line\n }\n return line.slice(0, commentIndex).trimEnd()\n }\n\n return tealCode\n .split('\\n')\n .map((line) => stripCommentFromLine(line))\n .join('\\n')\n }\n}\n\n/**\n * Find the first string within a line of TEAL. Only matches outside of quotes and base64 are returned.\n * Returns undefined if not found\n */\nconst findUnquotedString = (line: string, token: string, startIndex: number = 0, _endIndex?: number): number | undefined => {\n const endIndex = _endIndex === undefined ? line.length : _endIndex\n let index = startIndex\n let inQuotes = false\n let inBase64 = false\n\n while (index < endIndex) {\n const currentChar = line[index]\n if ((currentChar === ' ' || currentChar === '(') && !inQuotes && lastTokenBase64(line, index)) {\n // enter base64\n inBase64 = true\n } else if ((currentChar === ' ' || currentChar === ')') && !inQuotes && inBase64) {\n // exit base64\n inBase64 = false\n } else if (currentChar === '\\\\' && inQuotes) {\n // escaped char, skip next character\n index += 1\n } else if (currentChar === '\"') {\n // quote boundary\n inQuotes = !inQuotes\n } else if (!inQuotes && !inBase64 && line.startsWith(token, index)) {\n // can test for match\n return index\n }\n index += 1\n }\n return undefined\n}\n\nconst lastTokenBase64 = (line: string, index: number): boolean => {\n try {\n const tokens = line.slice(0, index).split(/\\s+/)\n const last = tokens[tokens.length - 1]\n return ['base64', 'b64'].includes(last)\n } catch {\n return false\n }\n}\n\nfunction replaceTemplateVariable(program: string, token: string, replacement: string): string {\n const result: string[] = []\n const tokenIndexOffset = replacement.length - token.length\n\n const programLines = program.split('\\n')\n\n for (const line of programLines) {\n const _commentIndex = findUnquotedString(line, '//')\n const commentIndex = _commentIndex === undefined ? line.length : _commentIndex\n let code = line.substring(0, commentIndex)\n const comment = line.substring(commentIndex)\n let trailingIndex = 0\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const tokenIndex = findTemplateToken(code, token, trailingIndex)\n if (tokenIndex === undefined) {\n break\n }\n trailingIndex = tokenIndex + token.length\n const prefix = code.substring(0, tokenIndex)\n const suffix = code.substring(trailingIndex)\n code = `${prefix}${replacement}${suffix}`\n trailingIndex += tokenIndexOffset\n }\n result.push(code + comment)\n }\n\n return result.join('\\n')\n}\n\nconst findTemplateToken = (line: string, token: string, startIndex: number = 0, _endIndex?: number): number | undefined => {\n const endIndex = _endIndex === undefined ? line.length : _endIndex\n\n let index = startIndex\n while (index < endIndex) {\n const tokenIndex = findUnquotedString(line, token, index, endIndex)\n if (tokenIndex === undefined) {\n break\n }\n const trailingIndex = tokenIndex + token.length\n if (\n (tokenIndex === 0 || !isValidTokenCharacter(line[tokenIndex - 1])) &&\n (trailingIndex >= line.length || !isValidTokenCharacter(line[trailingIndex]))\n ) {\n return tokenIndex\n }\n index = trailingIndex\n }\n return undefined\n}\n\nfunction isValidTokenCharacter(char: string): boolean {\n return char.length === 1 && (/\\w/.test(char) || char === '_')\n}\n"],"names":[],"mappings":";;;;AAYA,IAAO,QAAQ,GAAG,OAAO,CAAC,QAAQ;AAoFlC;MACa,UAAU,CAAA;AAIrB;;;AAGG;AACH,IAAA,WAAA,CAAY,KAAsB,EAAA;QAN1B,IAAmB,CAAA,mBAAA,GAAiC,EAAE;AAO5D,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK;;AAGrB;;;;;;;;;;AAUG;IACH,MAAM,WAAW,CAAC,QAAgB,EAAA;AAChC,QAAA,IAAI,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EAAE;AACtC,YAAA,OAAO,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC;;AAG3C,QAAA,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE;AACzE,QAAA,MAAM,MAAM,GAAG;AACb,YAAA,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,QAAQ,CAAC,MAAM;YACzB,YAAY,EAAE,QAAQ,CAAC,IAAI;AAC3B,YAAA,qBAAqB,EAAE,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YAC7E,SAAS,EAAE,IAAI,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;SACxD;AACD,QAAA,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,GAAG,MAAM;AAE3C,QAAA,OAAO,MAAM;;AAGf;;;;;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GAAG,CAAC,IAAY,EAAE,KAAa,EAAE,UAAA,GAAqB,CAAC,EAAE,SAAkB,KAAwB;AACxH,IAAA,MAAM,QAAQ,GAA6B,IAAI,CAAC,MAAM,CAAY;IAElE,IAAI,KAAK,GAAG,UAAU;AACtB,IAAA,OAAO,KAAK,GAAG,QAAQ,EAAE;AACvB,QAAA,MAAM,UAAU,GAAG,kBAAkB,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC;AACnE,QAAA,IAAI,UAAU,KAAK,SAAS,EAAE;YAC5B;;AAEF,QAAA,MAAM,aAAa,GAAG,UAAU,GAAG,KAAK,CAAC,MAAM;AAC/C,QAAA,IACE,CAAC,UAAU,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;AACjE,aAAC,aAAa,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAC7E;AACA,YAAA,OAAO,UAAU;;QAEnB,KAAK,GAAG,aAAa;;AAEvB,IAAA,OAAO,SAAS;AAClB,CAAC;AAED,SAAS,qBAAqB,CAAC,IAAY,EAAA;AACzC,IAAA,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,GAAG,CAAC;AAC/D;;;;"}
@@ -10,11 +10,19 @@ import TransactionWithSigner = algosdk.TransactionWithSigner;
10
10
  import SimulateResponse = algosdk.modelsv2.SimulateResponse;
11
11
  import modelsv2 = algosdk.modelsv2;
12
12
  export declare const MAX_TRANSACTION_GROUP_SIZE = 16;
13
- /** Options to control a simulate request */
14
- export type SimulateOptions = Expand<Omit<ConstructorParameters<typeof modelsv2.SimulateRequest>[0], 'txnGroups'>> & {
15
- /** Whether or not to skip signatures for all built transactions and use an empty signer instead. */
16
- skipSignatures?: boolean;
17
- };
13
+ /** Options to control a simulate request, that does not require transaction signing */
14
+ export type SkipSignaturesSimulateOptions = Expand<Omit<RawSimulateOptions, 'fixSigners' | 'allowEmptySignatures'> & {
15
+ /** Whether or not to skip signatures for all built transactions and use an empty signer instead.
16
+ * This will set `fixSigners` and `allowEmptySignatures` when sending the request to the algod API.
17
+ */
18
+ skipSignatures: boolean;
19
+ }>;
20
+ /** The raw API options to control a simulate request.
21
+ * See algod API docs for more information: https://developer.algorand.org/docs/rest-apis/algod/#simulaterequest
22
+ */
23
+ export type RawSimulateOptions = Expand<Omit<ConstructorParameters<typeof modelsv2.SimulateRequest>[0], 'txnGroups'>>;
24
+ /** All options to control a simulate request */
25
+ export type SimulateOptions = Expand<Partial<SkipSignaturesSimulateOptions> & RawSimulateOptions>;
18
26
  /** Common parameters for defining a transaction. */
19
27
  export type CommonTransactionParams = {
20
28
  /** The address of the account sending the transaction. */
@@ -674,7 +682,13 @@ export declare class TransactionComposer {
674
682
  * Compose the atomic transaction group and simulate sending it to the network
675
683
  * @returns The simulation result
676
684
  */
677
- simulate(options?: SimulateOptions): Promise<SendAtomicTransactionComposerResults & {
685
+ simulate(): Promise<SendAtomicTransactionComposerResults & {
686
+ simulateResponse: SimulateResponse;
687
+ }>;
688
+ simulate(options: SkipSignaturesSimulateOptions): Promise<SendAtomicTransactionComposerResults & {
689
+ simulateResponse: SimulateResponse;
690
+ }>;
691
+ simulate(options: RawSimulateOptions): Promise<SendAtomicTransactionComposerResults & {
678
692
  simulateResponse: SimulateResponse;
679
693
  }>;
680
694
  /**