@algorandfoundation/algokit-utils 7.0.0-beta.6 → 7.0.0-beta.7

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 (98) hide show
  1. package/app.d.ts +6 -6
  2. package/app.js +6 -6
  3. package/app.js.map +1 -1
  4. package/app.mjs +6 -6
  5. package/app.mjs.map +1 -1
  6. package/asset.d.ts +3 -3
  7. package/asset.js +3 -3
  8. package/asset.js.map +1 -1
  9. package/asset.mjs +3 -3
  10. package/asset.mjs.map +1 -1
  11. package/package.json +1 -1
  12. package/testing/fixtures/algorand-fixture.js +1 -1
  13. package/testing/fixtures/algorand-fixture.js.map +1 -1
  14. package/testing/fixtures/algorand-fixture.mjs +1 -1
  15. package/testing/fixtures/algorand-fixture.mjs.map +1 -1
  16. package/transaction/legacy-bridge.d.ts +3 -3
  17. package/transaction/legacy-bridge.js.map +1 -1
  18. package/transaction/legacy-bridge.mjs.map +1 -1
  19. package/transaction/transaction.d.ts +1 -3
  20. package/transaction/transaction.js +17 -11
  21. package/transaction/transaction.js.map +1 -1
  22. package/transaction/transaction.mjs +17 -11
  23. package/transaction/transaction.mjs.map +1 -1
  24. package/transfer/transfer-algos.d.ts +1 -1
  25. package/transfer/transfer-algos.js +1 -1
  26. package/transfer/transfer-algos.js.map +1 -1
  27. package/transfer/transfer-algos.mjs +1 -1
  28. package/transfer/transfer-algos.mjs.map +1 -1
  29. package/transfer/transfer.d.ts +1 -1
  30. package/transfer/transfer.js +1 -1
  31. package/transfer/transfer.js.map +1 -1
  32. package/transfer/transfer.mjs +1 -1
  33. package/transfer/transfer.mjs.map +1 -1
  34. package/types/account-manager.d.ts +13 -4
  35. package/types/account-manager.js +17 -3
  36. package/types/account-manager.js.map +1 -1
  37. package/types/account-manager.mjs +17 -3
  38. package/types/account-manager.mjs.map +1 -1
  39. package/types/algorand-client-interface.d.ts +1 -1
  40. package/types/algorand-client-transaction-creator.d.ts +30 -30
  41. package/types/algorand-client-transaction-creator.js +30 -30
  42. package/types/algorand-client-transaction-creator.js.map +1 -1
  43. package/types/algorand-client-transaction-creator.mjs +30 -30
  44. package/types/algorand-client-transaction-creator.mjs.map +1 -1
  45. package/types/algorand-client-transaction-sender.d.ts +18 -18
  46. package/types/algorand-client-transaction-sender.js +1 -1
  47. package/types/algorand-client-transaction-sender.js.map +1 -1
  48. package/types/algorand-client-transaction-sender.mjs +1 -1
  49. package/types/algorand-client-transaction-sender.mjs.map +1 -1
  50. package/types/algorand-client.d.ts +8 -8
  51. package/types/algorand-client.js +8 -8
  52. package/types/algorand-client.js.map +1 -1
  53. package/types/algorand-client.mjs +8 -8
  54. package/types/algorand-client.mjs.map +1 -1
  55. package/types/app-arc56.d.ts +60 -37
  56. package/types/app-arc56.js +37 -16
  57. package/types/app-arc56.js.map +1 -1
  58. package/types/app-arc56.mjs +37 -16
  59. package/types/app-arc56.mjs.map +1 -1
  60. package/types/app-client.d.ts +101 -78
  61. package/types/app-client.js +145 -84
  62. package/types/app-client.js.map +1 -1
  63. package/types/app-client.mjs +145 -84
  64. package/types/app-client.mjs.map +1 -1
  65. package/types/app-deployer.d.ts +2 -2
  66. package/types/app-deployer.js +24 -24
  67. package/types/app-deployer.js.map +1 -1
  68. package/types/app-deployer.mjs +24 -24
  69. package/types/app-deployer.mjs.map +1 -1
  70. package/types/app-factory.d.ts +141 -86
  71. package/types/app-factory.js +106 -34
  72. package/types/app-factory.js.map +1 -1
  73. package/types/app-factory.mjs +107 -35
  74. package/types/app-factory.mjs.map +1 -1
  75. package/types/app-spec.js +15 -9
  76. package/types/app-spec.js.map +1 -1
  77. package/types/app-spec.mjs +15 -9
  78. package/types/app-spec.mjs.map +1 -1
  79. package/types/asset-manager.d.ts +3 -3
  80. package/types/asset-manager.js +2 -2
  81. package/types/asset-manager.js.map +1 -1
  82. package/types/asset-manager.mjs +2 -2
  83. package/types/asset-manager.mjs.map +1 -1
  84. package/types/client-manager.d.ts +30 -8
  85. package/types/client-manager.js +6 -0
  86. package/types/client-manager.js.map +1 -1
  87. package/types/client-manager.mjs +6 -0
  88. package/types/client-manager.mjs.map +1 -1
  89. package/types/composer.d.ts +29 -4
  90. package/types/composer.js +24 -7
  91. package/types/composer.js.map +1 -1
  92. package/types/composer.mjs +24 -7
  93. package/types/composer.mjs.map +1 -1
  94. package/types/kmd-account-manager.js +1 -1
  95. package/types/kmd-account-manager.js.map +1 -1
  96. package/types/kmd-account-manager.mjs +1 -1
  97. package/types/kmd-account-manager.mjs.map +1 -1
  98. package/types/transaction.d.ts +4 -6
@@ -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 { ABIStruct, Arc56Contract, Arc56Method, getArc56Method, getArc56ReturnValue } 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 } from './composer'\nimport { Expand } from './expand'\nimport { ExecuteParams } from './transaction'\nimport SourceMap = algosdk.SourceMap\nimport OnApplicationComplete = algosdk.OnApplicationComplete\nimport ABIValue = algosdk.ABIValue\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 /** 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/** Parameters to define a create call for an `AppFactory` */\nexport type AppFactoryCreateParams =\n | Expand<AppClientMethodCallParams & AppClientCompilationParams & CreateOnComplete & ExecuteParams & CreateSchema>\n | Expand<AppClientBareCallParams & AppClientCompilationParams & CreateOnComplete & ExecuteParams & CreateSchema>\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 }\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 _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._deployTimeParams = params.deployTimeParams\n this._updatable = params.updatable\n this._deletable = params.deletable\n this._paramsMethods = this.getParamsMethods()\n }\n\n /** Get parameters to define create and deploy related calls to the current app */\n get params() {\n return this._paramsMethods\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 public async create(params?: AppFactoryCreateParams) {\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 params && 'method' in params\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 ...(await this._algorand.send.appCreate(await this.params.bare.create({ ...params, updatable, deletable, deployTimeParams }))),\n return: undefined,\n },\n )\n return {\n app: this.getAppClientById({\n appId: result.appId,\n }),\n result: {\n ...result,\n ...(compiled as Partial<AppCompilationResult>),\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: this._appName,\n version: this._version,\n updatable,\n deletable,\n },\n })\n const app = this.getAppClientById({\n appId: deployResult.appId,\n })\n const result = {\n ...deployResult,\n ...compiled,\n }\n return {\n app,\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: Expand<Omit<AppClientParams, 'algorand' | 'appSpec'>>) {\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 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 getAppClientByCreatorAddressAndName(\n params: Expand<Omit<AppClientParams, 'algorand' | 'appSpec' | 'appId'> & ResolveAppClientByCreatorAndName>,\n ) {\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: Expand<AppClientMethodCallParams & AppClientCompilationParams & CreateOnComplete & CreateSchema>) => {\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 ...(await this.compile({ ...params, deployTimeParams: params.deployTimeParams ?? this._deployTimeParams })),\n },\n params.onComplete ?? OnApplicationComplete.NoOpOC,\n ) satisfies AppCreateMethodCall\n },\n /** Return params for a deployment update ABI call */\n deployUpdate: (params: Expand<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?: Expand<AppClientBareCallParams & AppClientCompilationParams & CreateOnComplete & CreateSchema>) => {\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?: Expand<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 private 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: AppClient.getABIArgsWithDefaultValues(params.method, params.args, this._appSpec),\n onComplete,\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<Expand<Omit<TResult, 'return'> & AppReturn<TReturn>>> {\n const resultValue = await result\n return { ...resultValue, return: getArc56ReturnValue(resultValue.return, method, this._appSpec.structs) } as unknown as Expand<\n Omit<TResult, 'return'> & AppReturn<TReturn>\n >\n }\n}\n"],"names":[],"mappings":";;;;;AA+BA,IAAO,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;AACpC,IAAO,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,CAAA;AA4G5D;;;;AAIG;MACU,UAAU,CAAA;AAerB,IAAA,WAAA,CAAY,MAAwB,EAAA;QAClC,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;AAC1D,QAAA,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAA;AACpD,QAAA,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAA;QAChC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,OAAO,IAAI,KAAK,CAAA;AACvC,QAAA,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,aAAa,CAAA;AAC1C,QAAA,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC,gBAAgB,CAAA;AAChD,QAAA,IAAI,CAAC,UAAU,GAAG,M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,YAAY,CAGlB,MAAe,EAAE,UAAuB,EAAA;QACxC,OAAO;AACL,YAAA,GAAG,MAAM;YACT,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC;YACrC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC;AACpD,YAAA,IAAI,EAAE,SAAS,CAAC,2BAA2B,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC;YACtF,UAAU;SACX,CAAA;KACF;AAED;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,CAAA;SACnH;AACD,QAAA,OAAO,MAAM,IAAI,IAAI,CAAC,cAAe,CAAA;KACtC;AAED;;;;;;;;;AASG;AACH,IAAA,MAAM,qBAAqB,CAGzB,MAAkC,EAAE,MAAmB,EAAA;AACvD,QAAA,MAAM,WAAW,GAAG,MAAM,MAAM,CAAA;QAChC,OAAO,EAAE,GAAG,WAAW,EAAE,MAAM,EAAE,mBAAmB,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAEtG,CAAA;KACF;AACF;;;;"}
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\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 /** 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 }\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 _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._deployTimeParams = params.deployTimeParams\n this._updatable = params.updatable\n this._deletable = params.deletable\n this._paramsMethods = this.getParamsMethods()\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: this._appName,\n version: this._version,\n updatable,\n deletable,\n },\n })\n const appClient = this.getAppClientById({\n appId: deployResult.appId,\n })\n const result = {\n ...deployResult,\n ...compiled,\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 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 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 ...(await this.compile({ ...params, deployTimeParams: params.deployTimeParams ?? this._deployTimeParams })),\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 if (typeof defaultValue.data === 'number') return defaultValue.data\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,CAAC,SAAS,CAAA;AACpC,IAAO,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,CAAA;AAqH5D;;;;AAIG;MACU,UAAU,CAAA;AAerB,IAAA,WAAA,CAAY,MAAwB,EAAA;;AAgC3B,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,CAAA;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,CAAA;aAC9F;SACF,CAAA;;AAGQ,QAAA,IAAA,CAAA,IAAI,GAAG;;AAEd,YAAA,IAAI,EAAE;AACJ,gBAAA,MAAM,EAAE,OAAO,MAA4C,KAAI;oBAC7D,MAAM,SAAS,GAAG,MAAM,EAAE,SAAS,IAAI,IAAI,CAAC,UAAU,CAAA;oBACtD,MAAM,SAAS,GAAG,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AAC,CAAA,gCAAA,EAAmC,YAAY,CAAC,MAAM,CAA+B,6BAAA,CAAA,CAAC,CAAA;iBACzG;aACF;AACD,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,CAAA;AACrH,SAAC,CAAC,CAAA;KACH;AAED;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,CAAA;SACnH;AACD,QAAA,OAAO,MAAM,IAAI,IAAI,CAAC,cAAe,CAAA;KACtC;AAED;;;;;;;;;AASG;AACH,IAAA,MAAM,qBAAqB,CAGzB,MAAkC,EAAE,MAAmB,EAAA;AACvD,QAAA,MAAM,WAAW,GAAG,MAAM,MAAM,CAAA;QAChC,OAAO,EAAE,GAAG,WAAW,EAAE,MAAM,EAAE,mBAAmB,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAA;KAC1G;AACF;;;;"}
package/types/app-spec.js CHANGED
@@ -1,13 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var algosdk = require('algosdk');
4
- var types_appArc56 = require('./app-arc56.js');
5
4
 
6
5
  var ABIMethod = algosdk.ABIMethod;
7
6
  function arc32ToArc56(appSpec) {
8
7
  const arc32Structs = Object.values(appSpec.hints).flatMap((hint) => Object.entries(hint.structs ?? {}));
9
8
  const structs = Object.fromEntries(arc32Structs.map(([_, struct]) => {
10
- const fields = Object.fromEntries(struct.elements.map((e) => [e[0], e[1]]));
9
+ const fields = struct.elements.map((e) => ({ name: e[0], type: e[1] }));
11
10
  return [struct.name, fields];
12
11
  }));
13
12
  const hint = (m) => appSpec.hints[new ABIMethod(m).getSignature()];
@@ -32,6 +31,15 @@ function arc32ToArc56(appSpec) {
32
31
  actions.push('UpdateApplication');
33
32
  return actions;
34
33
  };
34
+ const getDefaultArgValue = (type, defaultArg) => {
35
+ if (!defaultArg || defaultArg.source === 'abi-method')
36
+ return undefined;
37
+ return {
38
+ source: defaultArg.source === 'constant' ? 'literal' : defaultArg.source === 'global-state' ? 'global' : 'local',
39
+ data: typeof defaultArg.data === 'string' ? Buffer.from(defaultArg.data).toString('base64') : defaultArg.data,
40
+ type: type === 'string' ? 'AVMString' : type,
41
+ };
42
+ };
35
43
  return {
36
44
  arcs: [],
37
45
  name: appSpec.contract.name,
@@ -45,9 +53,7 @@ function arc32ToArc56(appSpec) {
45
53
  type: a.type,
46
54
  desc: a.desc,
47
55
  struct: a.name ? hint(m)?.structs?.[a.name]?.name : undefined,
48
- defaultValue: a.name && hint(m)?.default_arguments?.[a.name].source === 'constant'
49
- ? Buffer.from(types_appArc56.getABIEncodedValue(hint(m).default_arguments[a.name].data, a.type, structs)).toString('base64')
50
- : undefined,
56
+ defaultValue: getDefaultArgValue(a.type, !a.name ? undefined : hint(m)?.default_arguments?.[a.name]),
51
57
  })),
52
58
  returns: {
53
59
  type: m.returns.type,
@@ -77,8 +83,8 @@ function arc32ToArc56(appSpec) {
77
83
  s[0],
78
84
  {
79
85
  key: Buffer.from(s[1].key, 'utf-8').toString('base64'),
80
- keyType: 'bytes',
81
- valueType: s[1].type,
86
+ keyType: 'AVMString',
87
+ valueType: s[1].type === 'uint64' ? 'AVMUint64' : 'AVMBytes',
82
88
  desc: s[1].descr,
83
89
  },
84
90
  ])),
@@ -86,8 +92,8 @@ function arc32ToArc56(appSpec) {
86
92
  s[0],
87
93
  {
88
94
  key: Buffer.from(s[1].key, 'utf-8').toString('base64'),
89
- keyType: 'bytes',
90
- valueType: s[1].type,
95
+ keyType: 'AVMString',
96
+ valueType: s[1].type === 'uint64' ? 'AVMUint64' : 'AVMBytes',
91
97
  desc: s[1].descr,
92
98
  },
93
99
  ])),
@@ -1 +1 @@
1
- {"version":3,"file":"app-spec.js","sources":["../../src/types/app-spec.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { Arc56Contract, Method as Arc56Method, StorageKey, StructFields, getABIEncodedValue } from './app-arc56'\nimport ABIContractParams = algosdk.ABIContractParams\nimport ABIMethodParams = algosdk.ABIMethodParams\nimport ABIMethod = algosdk.ABIMethod\n\nexport function arc32ToArc56(appSpec: AppSpec): Arc56Contract {\n const arc32Structs = Object.values(appSpec.hints).flatMap((hint) => Object.entries(hint.structs ?? {}))\n const structs = Object.fromEntries(\n arc32Structs.map(([_, struct]) => {\n const fields = Object.fromEntries(struct.elements.map((e) => [e[0], e[1]]))\n return [struct.name, fields satisfies StructFields]\n }),\n ) satisfies { [structName: string]: StructFields }\n const hint = (m: ABIMethodParams) => appSpec.hints[new ABIMethod(m).getSignature()] as Hint | undefined\n const actions = (m: ABIMethodParams, type: 'CREATE' | 'CALL') => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n return hint(m)?.call_config !== undefined ? callConfigToActions(hint(m)?.call_config!, type) : []\n }\n const bareActions = (type: 'CREATE' | 'CALL') => {\n return callConfigToActions(appSpec.bare_call_config, type)\n }\n const callConfigToActions = (c: CallConfig, type: 'CREATE' | 'CALL') => {\n const actions: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[] = []\n if (c.close_out && ['ALL', type].includes(c.close_out)) actions.push('CloseOut')\n if (c.delete_application && ['ALL', type].includes(c.delete_application)) actions.push('DeleteApplication')\n if (c.no_op && ['ALL', type].includes(c.no_op)) actions.push('NoOp')\n if (c.opt_in && ['ALL', type].includes(c.opt_in)) actions.push('OptIn')\n if (c.update_application && ['ALL', type].includes(c.update_application)) actions.push('UpdateApplication')\n return actions\n }\n\n return {\n arcs: [],\n name: appSpec.contract.name,\n desc: appSpec.contract.desc,\n structs: structs,\n methods: appSpec.contract.methods.map(\n (m) =>\n ({\n name: m.name,\n desc: m.desc,\n args: m.args.map((a) => ({\n name: a.name,\n type: a.type,\n desc: a.desc,\n struct: a.name ? hint(m)?.structs?.[a.name]?.name : undefined,\n defaultValue:\n a.name && hint(m)?.default_arguments?.[a.name].source === 'constant'\n ? Buffer.from(getABIEncodedValue(hint(m)!.default_arguments![a.name].data as string | number, a.type, structs)).toString(\n 'base64',\n )\n : undefined,\n })),\n returns: {\n type: m.returns.type,\n desc: m.returns.desc,\n struct: hint(m)?.structs?.output?.name,\n },\n events: [],\n readonly: hint(m)?.read_only,\n actions: {\n create: actions(m, 'CREATE') as Arc56Method['actions']['create'],\n call: actions(m, 'CALL'),\n },\n }) satisfies Arc56Method,\n ),\n state: {\n schema: {\n global: {\n ints: appSpec.state.global.num_uints,\n bytes: appSpec.state.global.num_byte_slices,\n },\n local: {\n ints: appSpec.state.local.num_uints,\n bytes: appSpec.state.local.num_byte_slices,\n },\n },\n keys: {\n global: Object.fromEntries(\n Object.entries(appSpec.schema.global.declared).map((s) => [\n s[0],\n {\n key: Buffer.from(s[1].key, 'utf-8').toString('base64'),\n keyType: 'bytes',\n valueType: s[1].type,\n desc: s[1].descr,\n } satisfies StorageKey,\n ]),\n ),\n local: Object.fromEntries(\n Object.entries(appSpec.schema.local.declared).map((s) => [\n s[0],\n {\n key: Buffer.from(s[1].key, 'utf-8').toString('base64'),\n keyType: 'bytes',\n valueType: s[1].type,\n desc: s[1].descr,\n } satisfies StorageKey,\n ]),\n ),\n box: {},\n },\n maps: {\n global: {},\n local: {},\n box: {},\n },\n },\n source: appSpec.source,\n bareActions: {\n create: bareActions('CREATE') as unknown as Arc56Contract['bareActions']['create'],\n call: bareActions('CALL'),\n },\n byteCode: undefined,\n compilerInfo: undefined,\n events: undefined,\n networks: undefined,\n scratchVariables: undefined,\n sourceInfo: undefined,\n templateVariables: undefined,\n } satisfies Arc56Contract\n}\n\n/** An ARC-0032 Application Specification see https://github.com/algorandfoundation/ARCs/pull/150 */\nexport interface AppSpec {\n /** Method call hints */\n hints: HintSpec\n /** The TEAL source */\n source: AppSources\n /** The ABI-0004 contract definition see https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0004.md */\n contract: ABIContractParams\n /** The values that make up the local and global state */\n schema: SchemaSpec\n /** The rolled-up schema allocation values for local and global state */\n state: StateSchemaSpec\n /** The config of all BARE calls (i.e. non ABI calls with no args) */\n bare_call_config: CallConfig\n}\n\n/** A lookup of encoded method call spec to hint */\nexport type HintSpec = Record<string, Hint>\n\n/** The TEAL source of a contract */\nexport interface AppSources {\n /** The TEAL source of the approval program */\n approval: string\n /** The TEAL source of the clear program */\n clear: string\n}\n\n/** The various call configs:\n * * `NEVER`: Will not be called\n * * `CALL`: Can be called during a non-create call i.e. app id != 0\n * * `CREATE`: Can be called during a create call i.e. app id = 0\n * * `ALL`: Can be during a create OR non-create call\n **/\nexport type CallConfigValue = 'NEVER' | 'CALL' | 'CREATE' | 'ALL'\n\n/** Call configuration for a method */\nexport interface CallConfig {\n /** NoOp call config */\n no_op?: CallConfigValue\n /** Opt-in call config */\n opt_in?: CallConfigValue\n /** Close out call config */\n close_out?: CallConfigValue\n /** Update call config */\n update_application?: CallConfigValue\n /** Delete call config */\n delete_application?: CallConfigValue\n}\n\n/** Hint information for a given method call to allow client generation */\nexport interface Hint {\n /** Any user-defined struct/tuple types used in the method call, keyed by parameter name or `output` for return type */\n structs?: Record<string, Struct>\n read_only?: boolean\n default_arguments?: Record<string, DefaultArgument>\n call_config: CallConfig\n}\n\n/** The name of a field */\nexport type FieldName = string\n\n/** The string name of an ABI type */\nexport type ABIType = string\n\n/** The elements of the struct/tuple: `FieldName`, `ABIType` */\nexport type StructElement = [FieldName, ABIType]\n\n/** A user-defined struct/tuple type */\nexport interface Struct {\n /** The name of the type */\n name: string\n /** The elements (in order) that make up the struct/tuple */\n elements: StructElement[]\n}\n\n/**\n * Defines a strategy for obtaining a default value for a given ABI arg.\n */\nexport type DefaultArgument =\n | {\n /**\n * The default value should be fetched by invoking an ABI method\n */\n source: 'abi-method'\n data: ABIMethodParams\n }\n | {\n /**\n * The default value should be fetched from global state\n */\n source: 'global-state'\n /**\n * The key of the state variable\n */\n data: string\n }\n | {\n /**\n * The default value should be fetched from the local state of the sender user\n */\n source: 'local-state'\n /**\n * The key of the state variable\n */\n data: string\n }\n | {\n /**\n * The default value is a constant.\n */\n source: 'constant'\n /**\n * The static default value to use.\n */\n data: string | number\n }\n\n/** AVM data type */\nexport type AVMType = 'uint64' | 'bytes'\n\n/** Declared schema value specification */\nexport interface DeclaredSchemaValueSpec {\n /** The type of value */\n type: AVMType\n /** The name of the key */\n key: string\n /** A description of the variable */\n descr?: string\n /** Whether or not the value is set statically (at create time only) or dynamically */\n static?: boolean\n}\n\n/** Reserved schema value specification */\nexport interface ReservedSchemaValueSpec {\n /** The type of value */\n type: AVMType\n /** The description of the reserved storage space */\n descr: string\n /** The maximum number of slots to reserve */\n max_keys: number\n}\n\n/** The schema for global and local storage */\nexport interface SchemaSpec {\n /** The local storage schema */\n local: Schema\n /** The global storage schema */\n global: Schema\n}\n\n/** The storage schema definition */\nexport interface Schema {\n /** Declared storage schema */\n declared: Record<string, DeclaredSchemaValueSpec>\n /** Reserved storage schema */\n reserved: Record<string, ReservedSchemaValueSpec>\n}\n\n/** The rolled-up schema allocation specification for local and global state */\nexport interface StateSchemaSpec {\n /** Global storage spec */\n global: StateSchema\n /** Local storage spec */\n local: StateSchema\n}\n\n/** Schema spec summary for global or local storage */\nexport type StateSchema = {\n /** Number of uint slots */\n num_uints: number\n /** Number of byte slots */\n num_byte_slices: number\n}\n"],"names":["getABIEncodedValue"],"mappings":";;;;;AAIA,IAAO,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;AAE9B,SAAU,YAAY,CAAC,OAAgB,EAAA;AAC3C,IAAA,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CA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CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;AACpB,wBAAA,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK;AACI,qBAAA;AACvB,iBAAA,CAAC,CACH;AACD,gBAAA,GAAG,EAAE,EAAE;AACR,aAAA;AACD,YAAA,IAAI,EAAE;AACJ,gBAAA,MAAM,EAAE,EAAE;AACV,gBAAA,KAAK,EAAE,EAAE;AACT,gBAAA,GAAG,EAAE,EAAE;AACR,aAAA;AACF,SAAA;QACD,MAAM,EAAE,OAAO,CAAC,MAAM;AACtB,QAAA,WAAW,EAAE;AACX,YAAA,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAsD;AAClF,YAAA,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC;AAC1B,SAAA;AACD,QAAA,QAAQ,EAAE,SAAS;AACnB,QAAA,YAAY,EAAE,SAAS;AACvB,QAAA,MAAM,EAAE,SAAS;AACjB,QAAA,QAAQ,EAAE,SAAS;AACnB,QAAA,gBAAgB,EAAE,SAAS;AAC3B,QAAA,UAAU,EAAE,SAAS;AACrB,QAAA,iBAAiB,EAAE,SAAS;KACL,CAAA;AAC3B;;;;"}
1
+ {"version":3,"file":"app-spec.js","sources":["../../src/types/app-spec.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { Arc56Contract, Method as Arc56Method, StorageKey, StructField } from './app-arc56'\nimport ABIContractParams = algosdk.ABIContractParams\nimport ABIMethodParams = algosdk.ABIMethodParams\nimport ABIMethod = algosdk.ABIMethod\n\nexport function arc32ToArc56(appSpec: AppSpec): Arc56Contract {\n const arc32Structs = Object.values(appSpec.hints).flatMap((hint) => Object.entries(hint.structs ?? {}))\n const structs = Object.fromEntries(\n arc32Structs.map(([_, struct]) => {\n const fields = struct.elements.map((e) => ({ name: e[0], type: e[1] }))\n return [struct.name, fields]\n }),\n ) satisfies { [structName: string]: StructField[] }\n const hint = (m: ABIMethodParams) => appSpec.hints[new ABIMethod(m).getSignature()] as Hint | undefined\n const actions = (m: ABIMethodParams, type: 'CREATE' | 'CALL') => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n return hint(m)?.call_config !== undefined ? callConfigToActions(hint(m)?.call_config!, type) : []\n }\n const bareActions = (type: 'CREATE' | 'CALL') => {\n return callConfigToActions(appSpec.bare_call_config, type)\n }\n const callConfigToActions = (c: CallConfig, type: 'CREATE' | 'CALL') => {\n const actions: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[] = []\n if (c.close_out && ['ALL', type].includes(c.close_out)) actions.push('CloseOut')\n if (c.delete_application && ['ALL', type].includes(c.delete_application)) actions.push('DeleteApplication')\n if (c.no_op && ['ALL', type].includes(c.no_op)) actions.push('NoOp')\n if (c.opt_in && ['ALL', type].includes(c.opt_in)) actions.push('OptIn')\n if (c.update_application && ['ALL', type].includes(c.update_application)) actions.push('UpdateApplication')\n return actions\n }\n const getDefaultArgValue = (\n type: string,\n defaultArg: DefaultArgument | undefined,\n ): Arc56Contract['methods'][0]['args'][0]['defaultValue'] => {\n if (!defaultArg || defaultArg.source === 'abi-method') return undefined\n\n return {\n source: defaultArg.source === 'constant' ? 'literal' : defaultArg.source === 'global-state' ? 'global' : 'local',\n data: typeof defaultArg.data === 'string' ? Buffer.from(defaultArg.data).toString('base64') : defaultArg.data,\n type: type === 'string' ? 'AVMString' : type,\n }\n }\n\n return {\n arcs: [],\n name: appSpec.contract.name,\n desc: appSpec.contract.desc,\n structs: structs,\n methods: appSpec.contract.methods.map(\n (m) =>\n ({\n name: m.name,\n desc: m.desc,\n args: m.args.map((a) => ({\n name: a.name,\n type: a.type,\n desc: a.desc,\n struct: a.name ? hint(m)?.structs?.[a.name]?.name : undefined,\n defaultValue: getDefaultArgValue(a.type, !a.name ? undefined : hint(m)?.default_arguments?.[a.name]),\n })),\n returns: {\n type: m.returns.type,\n desc: m.returns.desc,\n struct: hint(m)?.structs?.output?.name,\n },\n events: [],\n readonly: hint(m)?.read_only,\n actions: {\n create: actions(m, 'CREATE') as Arc56Method['actions']['create'],\n call: actions(m, 'CALL'),\n },\n }) satisfies Arc56Method,\n ),\n state: {\n schema: {\n global: {\n ints: appSpec.state.global.num_uints,\n bytes: appSpec.state.global.num_byte_slices,\n },\n local: {\n ints: appSpec.state.local.num_uints,\n bytes: appSpec.state.local.num_byte_slices,\n },\n },\n keys: {\n global: Object.fromEntries(\n Object.entries(appSpec.schema.global.declared).map((s) => [\n s[0],\n {\n key: Buffer.from(s[1].key, 'utf-8').toString('base64'),\n keyType: 'AVMString',\n valueType: s[1].type === 'uint64' ? 'AVMUint64' : 'AVMBytes',\n desc: s[1].descr,\n } satisfies StorageKey,\n ]),\n ),\n local: Object.fromEntries(\n Object.entries(appSpec.schema.local.declared).map((s) => [\n s[0],\n {\n key: Buffer.from(s[1].key, 'utf-8').toString('base64'),\n keyType: 'AVMString',\n valueType: s[1].type === 'uint64' ? 'AVMUint64' : 'AVMBytes',\n desc: s[1].descr,\n } satisfies StorageKey,\n ]),\n ),\n box: {},\n },\n maps: {\n global: {},\n local: {},\n box: {},\n },\n },\n source: appSpec.source,\n bareActions: {\n create: bareActions('CREATE') as unknown as Arc56Contract['bareActions']['create'],\n call: bareActions('CALL'),\n },\n byteCode: undefined,\n compilerInfo: undefined,\n events: undefined,\n networks: undefined,\n scratchVariables: undefined,\n sourceInfo: undefined,\n templateVariables: undefined,\n } satisfies Arc56Contract\n}\n\n/** An ARC-0032 Application Specification see https://github.com/algorandfoundation/ARCs/pull/150 */\nexport interface AppSpec {\n /** Method call hints */\n hints: HintSpec\n /** The TEAL source */\n source: AppSources\n /** The ABI-0004 contract definition see https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0004.md */\n contract: ABIContractParams\n /** The values that make up the local and global state */\n schema: SchemaSpec\n /** The rolled-up schema allocation values for local and global state */\n state: StateSchemaSpec\n /** The config of all BARE calls (i.e. non ABI calls with no args) */\n bare_call_config: CallConfig\n}\n\n/** A lookup of encoded method call spec to hint */\nexport type HintSpec = Record<string, Hint>\n\n/** The TEAL source of a contract */\nexport interface AppSources {\n /** The TEAL source of the approval program */\n approval: string\n /** The TEAL source of the clear program */\n clear: string\n}\n\n/** The various call configs:\n * * `NEVER`: Will not be called\n * * `CALL`: Can be called during a non-create call i.e. app id != 0\n * * `CREATE`: Can be called during a create call i.e. app id = 0\n * * `ALL`: Can be during a create OR non-create call\n **/\nexport type CallConfigValue = 'NEVER' | 'CALL' | 'CREATE' | 'ALL'\n\n/** Call configuration for a method */\nexport interface CallConfig {\n /** NoOp call config */\n no_op?: CallConfigValue\n /** Opt-in call config */\n opt_in?: CallConfigValue\n /** Close out call config */\n close_out?: CallConfigValue\n /** Update call config */\n update_application?: CallConfigValue\n /** Delete call config */\n delete_application?: CallConfigValue\n}\n\n/** Hint information for a given method call to allow client generation */\nexport interface Hint {\n /** Any user-defined struct/tuple types used in the method call, keyed by parameter name or `output` for return type */\n structs?: Record<string, Struct>\n read_only?: boolean\n default_arguments?: Record<string, DefaultArgument>\n call_config: CallConfig\n}\n\n/** The name of a field */\nexport type FieldName = string\n\n/** The string name of an ABI type */\nexport type ABIType = string\n\n/** The elements of the struct/tuple: `FieldName`, `ABIType` */\nexport type StructElement = [FieldName, ABIType]\n\n/** A user-defined struct/tuple type */\nexport interface Struct {\n /** The name of the type */\n name: string\n /** The elements (in order) that make up the struct/tuple */\n elements: StructElement[]\n}\n\n/**\n * Defines a strategy for obtaining a default value for a given ABI arg.\n */\nexport type DefaultArgument =\n | {\n /**\n * The default value should be fetched by invoking an ABI method\n */\n source: 'abi-method'\n data: ABIMethodParams\n }\n | {\n /**\n * The default value should be fetched from global state\n */\n source: 'global-state'\n /**\n * The key of the state variable\n */\n data: string\n }\n | {\n /**\n * The default value should be fetched from the local state of the sender user\n */\n source: 'local-state'\n /**\n * The key of the state variable\n */\n data: string\n }\n | {\n /**\n * The default value is a constant.\n */\n source: 'constant'\n /**\n * The static default value to use.\n */\n data: string | number\n }\n\n/** AVM data type */\nexport type AVMType = 'uint64' | 'bytes'\n\n/** Declared schema value specification */\nexport interface DeclaredSchemaValueSpec {\n /** The type of value */\n type: AVMType\n /** The name of the key */\n key: string\n /** A description of the variable */\n descr?: string\n /** Whether or not the value is set statically (at create time only) or dynamically */\n static?: boolean\n}\n\n/** Reserved schema value specification */\nexport interface ReservedSchemaValueSpec {\n /** The type of value */\n type: AVMType\n /** The description of the reserved storage space */\n descr: string\n /** The maximum number of slots to reserve */\n max_keys: number\n}\n\n/** The schema for global and local storage */\nexport interface SchemaSpec {\n /** The local storage schema */\n local: Schema\n /** The global storage schema */\n global: Schema\n}\n\n/** The storage schema definition */\nexport interface Schema {\n /** Declared storage schema */\n declared: Record<string, DeclaredSchemaValueSpec>\n /** Reserved storage schema */\n reserved: Record<string, ReservedSchemaValueSpec>\n}\n\n/** The rolled-up schema allocation specification for local and global state */\nexport interface StateSchemaSpec {\n /** Global storage spec */\n global: StateSchema\n /** Local storage spec */\n local: StateSchema\n}\n\n/** Schema spec summary for global or local storage */\nexport type StateSchema = {\n /** Number of uint slots */\n num_uints: number\n /** Number of byte slots */\n num_byte_slices: number\n}\n"],"names":[],"mappings":";;;;AAIA,IAAO,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;AAE9B,SAAU,YAAY,CAAC,OAAgB,EAAA;AAC3C,IAAA,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAA;AACvG,IAAA,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAChC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAI;AAC/B,QAAA,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,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AAC;AACtD,wBAAA,OAAO,EAAE,WAAW;AACpB,wBAAA,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,GAAG,WAAW,GAAG,UAAU;AAC5D,wBAAA,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK;AACI,qBAAA;AACvB,iBAAA,CAAC,CACH;AACD,gBAAA,GAAG,EAAE,EAAE;AACR,aAAA;AACD,YAAA,IAAI,EAAE;AACJ,gBAAA,MAAM,EAAE,EAAE;AACV,gBAAA,KAAK,EAAE,EAAE;AACT,gBAAA,GAAG,EAAE,EAAE;AACR,aAAA;AACF,SAAA;QACD,MAAM,EAAE,OAAO,CAAC,MAAM;AACtB,QAAA,WAAW,EAAE;AACX,YAAA,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAsD;AAClF,YAAA,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC;AAC1B,SAAA;AACD,QAAA,QAAQ,EAAE,SAAS;AACnB,QAAA,YAAY,EAAE,SAAS;AACvB,QAAA,MAAM,EAAE,SAAS;AACjB,QAAA,QAAQ,EAAE,SAAS;AACnB,QAAA,gBAAgB,EAAE,SAAS;AAC3B,QAAA,UAAU,EAAE,SAAS;AACrB,QAAA,iBAAiB,EAAE,SAAS;KACL,CAAA;AAC3B;;;;"}
@@ -1,11 +1,10 @@
1
1
  import algosdk from 'algosdk';
2
- import { getABIEncodedValue } from './app-arc56.mjs';
3
2
 
4
3
  var ABIMethod = algosdk.ABIMethod;
5
4
  function arc32ToArc56(appSpec) {
6
5
  const arc32Structs = Object.values(appSpec.hints).flatMap((hint) => Object.entries(hint.structs ?? {}));
7
6
  const structs = Object.fromEntries(arc32Structs.map(([_, struct]) => {
8
- const fields = Object.fromEntries(struct.elements.map((e) => [e[0], e[1]]));
7
+ const fields = struct.elements.map((e) => ({ name: e[0], type: e[1] }));
9
8
  return [struct.name, fields];
10
9
  }));
11
10
  const hint = (m) => appSpec.hints[new ABIMethod(m).getSignature()];
@@ -30,6 +29,15 @@ function arc32ToArc56(appSpec) {
30
29
  actions.push('UpdateApplication');
31
30
  return actions;
32
31
  };
32
+ const getDefaultArgValue = (type, defaultArg) => {
33
+ if (!defaultArg || defaultArg.source === 'abi-method')
34
+ return undefined;
35
+ return {
36
+ source: defaultArg.source === 'constant' ? 'literal' : defaultArg.source === 'global-state' ? 'global' : 'local',
37
+ data: typeof defaultArg.data === 'string' ? Buffer.from(defaultArg.data).toString('base64') : defaultArg.data,
38
+ type: type === 'string' ? 'AVMString' : type,
39
+ };
40
+ };
33
41
  return {
34
42
  arcs: [],
35
43
  name: appSpec.contract.name,
@@ -43,9 +51,7 @@ function arc32ToArc56(appSpec) {
43
51
  type: a.type,
44
52
  desc: a.desc,
45
53
  struct: a.name ? hint(m)?.structs?.[a.name]?.name : undefined,
46
- defaultValue: a.name && hint(m)?.default_arguments?.[a.name].source === 'constant'
47
- ? Buffer.from(getABIEncodedValue(hint(m).default_arguments[a.name].data, a.type, structs)).toString('base64')
48
- : undefined,
54
+ defaultValue: getDefaultArgValue(a.type, !a.name ? undefined : hint(m)?.default_arguments?.[a.name]),
49
55
  })),
50
56
  returns: {
51
57
  type: m.returns.type,
@@ -75,8 +81,8 @@ function arc32ToArc56(appSpec) {
75
81
  s[0],
76
82
  {
77
83
  key: Buffer.from(s[1].key, 'utf-8').toString('base64'),
78
- keyType: 'bytes',
79
- valueType: s[1].type,
84
+ keyType: 'AVMString',
85
+ valueType: s[1].type === 'uint64' ? 'AVMUint64' : 'AVMBytes',
80
86
  desc: s[1].descr,
81
87
  },
82
88
  ])),
@@ -84,8 +90,8 @@ function arc32ToArc56(appSpec) {
84
90
  s[0],
85
91
  {
86
92
  key: Buffer.from(s[1].key, 'utf-8').toString('base64'),
87
- keyType: 'bytes',
88
- valueType: s[1].type,
93
+ keyType: 'AVMString',
94
+ valueType: s[1].type === 'uint64' ? 'AVMUint64' : 'AVMBytes',
89
95
  desc: s[1].descr,
90
96
  },
91
97
  ])),
@@ -1 +1 @@
1
- {"version":3,"file":"app-spec.mjs","sources":["../../src/types/app-spec.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { Arc56Contract, Method as Arc56Method, StorageKey, StructFields, getABIEncodedValue } from './app-arc56'\nimport ABIContractParams = algosdk.ABIContractParams\nimport ABIMethodParams = algosdk.ABIMethodParams\nimport ABIMethod = algosdk.ABIMethod\n\nexport function arc32ToArc56(appSpec: AppSpec): Arc56Contract {\n const arc32Structs = Object.values(appSpec.hints).flatMap((hint) => Object.entries(hint.structs ?? {}))\n const structs = Object.fromEntries(\n arc32Structs.map(([_, struct]) => {\n const fields = Object.fromEntries(struct.elements.map((e) => [e[0], e[1]]))\n return [struct.name, fields satisfies StructFields]\n }),\n ) satisfies { [structName: string]: StructFields }\n const hint = (m: ABIMethodParams) => appSpec.hints[new ABIMethod(m).getSignature()] as Hint | undefined\n const actions = (m: ABIMethodParams, type: 'CREATE' | 'CALL') => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n return hint(m)?.call_config !== undefined ? callConfigToActions(hint(m)?.call_config!, type) : []\n }\n const bareActions = (type: 'CREATE' | 'CALL') => {\n return callConfigToActions(appSpec.bare_call_config, type)\n }\n const callConfigToActions = (c: CallConfig, type: 'CREATE' | 'CALL') => {\n const actions: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[] = []\n if (c.close_out && ['ALL', type].includes(c.close_out)) actions.push('CloseOut')\n if (c.delete_application && ['ALL', type].includes(c.delete_application)) actions.push('DeleteApplication')\n if (c.no_op && ['ALL', type].includes(c.no_op)) actions.push('NoOp')\n if (c.opt_in && ['ALL', type].includes(c.opt_in)) actions.push('OptIn')\n if (c.update_application && ['ALL', type].includes(c.update_application)) actions.push('UpdateApplication')\n return actions\n }\n\n return {\n arcs: [],\n name: appSpec.contract.name,\n desc: appSpec.contract.desc,\n structs: structs,\n methods: appSpec.contract.methods.map(\n (m) =>\n ({\n name: m.name,\n desc: m.desc,\n args: m.args.map((a) => ({\n name: a.name,\n type: a.type,\n desc: a.desc,\n struct: a.name ? hint(m)?.structs?.[a.name]?.name : undefined,\n defaultValue:\n a.name && hint(m)?.default_arguments?.[a.name].source === 'constant'\n ? Buffer.from(getABIEncodedValue(hint(m)!.default_arguments![a.name].data as string | number, a.type, structs)).toString(\n 'base64',\n )\n : undefined,\n })),\n returns: {\n type: m.returns.type,\n desc: m.returns.desc,\n struct: hint(m)?.structs?.output?.name,\n },\n events: [],\n readonly: hint(m)?.read_only,\n actions: {\n create: actions(m, 'CREATE') as Arc56Method['actions']['create'],\n call: actions(m, 'CALL'),\n },\n }) satisfies Arc56Method,\n ),\n state: {\n schema: {\n global: {\n ints: appSpec.state.global.num_uints,\n bytes: appSpec.state.global.num_byte_slices,\n },\n local: {\n ints: appSpec.state.local.num_uints,\n bytes: appSpec.state.local.num_byte_slices,\n },\n },\n keys: {\n global: Object.fromEntries(\n Object.entries(appSpec.schema.global.declared).map((s) => [\n s[0],\n {\n key: Buffer.from(s[1].key, 'utf-8').toString('base64'),\n keyType: 'bytes',\n valueType: s[1].type,\n desc: s[1].descr,\n } satisfies StorageKey,\n ]),\n ),\n local: Object.fromEntries(\n Object.entries(appSpec.schema.local.declared).map((s) => [\n s[0],\n {\n key: Buffer.from(s[1].key, 'utf-8').toString('base64'),\n keyType: 'bytes',\n valueType: s[1].type,\n desc: s[1].descr,\n } satisfies StorageKey,\n ]),\n ),\n box: {},\n },\n maps: {\n global: {},\n local: {},\n box: {},\n },\n },\n source: appSpec.source,\n bareActions: {\n create: bareActions('CREATE') as unknown as Arc56Contract['bareActions']['create'],\n call: bareActions('CALL'),\n },\n byteCode: undefined,\n compilerInfo: undefined,\n events: undefined,\n networks: undefined,\n scratchVariables: undefined,\n sourceInfo: undefined,\n templateVariables: undefined,\n } satisfies Arc56Contract\n}\n\n/** An ARC-0032 Application Specification see https://github.com/algorandfoundation/ARCs/pull/150 */\nexport interface AppSpec {\n /** Method call hints */\n hints: HintSpec\n /** The TEAL source */\n source: AppSources\n /** The ABI-0004 contract definition see https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0004.md */\n contract: ABIContractParams\n /** The values that make up the local and global state */\n schema: SchemaSpec\n /** The rolled-up schema allocation values for local and global state */\n state: StateSchemaSpec\n /** The config of all BARE calls (i.e. non ABI calls with no args) */\n bare_call_config: CallConfig\n}\n\n/** A lookup of encoded method call spec to hint */\nexport type HintSpec = Record<string, Hint>\n\n/** The TEAL source of a contract */\nexport interface AppSources {\n /** The TEAL source of the approval program */\n approval: string\n /** The TEAL source of the clear program */\n clear: string\n}\n\n/** The various call configs:\n * * `NEVER`: Will not be called\n * * `CALL`: Can be called during a non-create call i.e. app id != 0\n * * `CREATE`: Can be called during a create call i.e. app id = 0\n * * `ALL`: Can be during a create OR non-create call\n **/\nexport type CallConfigValue = 'NEVER' | 'CALL' | 'CREATE' | 'ALL'\n\n/** Call configuration for a method */\nexport interface CallConfig {\n /** NoOp call config */\n no_op?: CallConfigValue\n /** Opt-in call config */\n opt_in?: CallConfigValue\n /** Close out call config */\n close_out?: CallConfigValue\n /** Update call config */\n update_application?: CallConfigValue\n /** Delete call config */\n delete_application?: CallConfigValue\n}\n\n/** Hint information for a given method call to allow client generation */\nexport interface Hint {\n /** Any user-defined struct/tuple types used in the method call, keyed by parameter name or `output` for return type */\n structs?: Record<string, Struct>\n read_only?: boolean\n default_arguments?: Record<string, DefaultArgument>\n call_config: CallConfig\n}\n\n/** The name of a field */\nexport type FieldName = string\n\n/** The string name of an ABI type */\nexport type ABIType = string\n\n/** The elements of the struct/tuple: `FieldName`, `ABIType` */\nexport type StructElement = [FieldName, ABIType]\n\n/** A user-defined struct/tuple type */\nexport interface Struct {\n /** The name of the type */\n name: string\n /** The elements (in order) that make up the struct/tuple */\n elements: StructElement[]\n}\n\n/**\n * Defines a strategy for obtaining a default value for a given ABI arg.\n */\nexport type DefaultArgument =\n | {\n /**\n * The default value should be fetched by invoking an ABI method\n */\n source: 'abi-method'\n data: ABIMethodParams\n }\n | {\n /**\n * The default value should be fetched from global state\n */\n source: 'global-state'\n /**\n * The key of the state variable\n */\n data: string\n }\n | {\n /**\n * The default value should be fetched from the local state of the sender user\n */\n source: 'local-state'\n /**\n * The key of the state variable\n */\n data: string\n }\n | {\n /**\n * The default value is a constant.\n */\n source: 'constant'\n /**\n * The static default value to use.\n */\n data: string | number\n }\n\n/** AVM data type */\nexport type AVMType = 'uint64' | 'bytes'\n\n/** Declared schema value specification */\nexport interface DeclaredSchemaValueSpec {\n /** The type of value */\n type: AVMType\n /** The name of the key */\n key: string\n /** A description of the variable */\n descr?: string\n /** Whether or not the value is set statically (at create time only) or dynamically */\n static?: boolean\n}\n\n/** Reserved schema value specification */\nexport interface ReservedSchemaValueSpec {\n /** The type of value */\n type: AVMType\n /** The description of the reserved storage space */\n descr: string\n /** The maximum number of slots to reserve */\n max_keys: number\n}\n\n/** The schema for global and local storage */\nexport interface SchemaSpec {\n /** The local storage schema */\n local: Schema\n /** The global storage schema */\n global: Schema\n}\n\n/** The storage schema definition */\nexport interface Schema {\n /** Declared storage schema */\n declared: Record<string, DeclaredSchemaValueSpec>\n /** Reserved storage schema */\n reserved: Record<string, ReservedSchemaValueSpec>\n}\n\n/** The rolled-up schema allocation specification for local and global state */\nexport interface StateSchemaSpec {\n /** Global storage spec */\n global: StateSchema\n /** Local storage spec */\n local: StateSchema\n}\n\n/** Schema spec summary for global or local storage */\nexport type StateSchema = {\n /** Number of uint slots */\n num_uints: number\n /** Number of byte slots */\n num_byte_slices: number\n}\n"],"names":[],"mappings":";;;AAIA,IAAO,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;AAE9B,SAAU,YAAY,CAAC,OAAgB,EAAA;AAC3C,IAAA,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,IA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,CAAC,KAAK;AACI,qBAAA;AACvB,iBAAA,CAAC,CACH;AACD,gBAAA,GAAG,EAAE,EAAE;AACR,aAAA;AACD,YAAA,IAAI,EAAE;AACJ,gBAAA,MAAM,EAAE,EAAE;AACV,gBAAA,KAAK,EAAE,EAAE;AACT,gBAAA,GAAG,EAAE,EAAE;AACR,aAAA;AACF,SAAA;QACD,MAAM,EAAE,OAAO,CAAC,MAAM;AACtB,QAAA,WAAW,EAAE;AACX,YAAA,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAsD;AAClF,YAAA,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC;AAC1B,SAAA;AACD,QAAA,QAAQ,EAAE,SAAS;AACnB,QAAA,YAAY,EAAE,SAAS;AACvB,QAAA,MAAM,EAAE,SAAS;AACjB,QAAA,QAAQ,EAAE,SAAS;AACnB,QAAA,gBAAgB,EAAE,SAAS;AAC3B,QAAA,UAAU,EAAE,SAAS;AACrB,QAAA,iBAAiB,EAAE,SAAS;KACL,CAAA;AAC3B;;;;"}
1
+ {"version":3,"file":"app-spec.mjs","sources":["../../src/types/app-spec.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { Arc56Contract, Method as Arc56Method, StorageKey, StructField } from './app-arc56'\nimport ABIContractParams = algosdk.ABIContractParams\nimport ABIMethodParams = algosdk.ABIMethodParams\nimport ABIMethod = algosdk.ABIMethod\n\nexport function arc32ToArc56(appSpec: AppSpec): Arc56Contract {\n const arc32Structs = Object.values(appSpec.hints).flatMap((hint) => Object.entries(hint.structs ?? {}))\n const structs = Object.fromEntries(\n arc32Structs.map(([_, struct]) => {\n const fields = struct.elements.map((e) => ({ name: e[0], type: e[1] }))\n return [struct.name, fields]\n }),\n ) satisfies { [structName: string]: StructField[] }\n const hint = (m: ABIMethodParams) => appSpec.hints[new ABIMethod(m).getSignature()] as Hint | undefined\n const actions = (m: ABIMethodParams, type: 'CREATE' | 'CALL') => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n return hint(m)?.call_config !== undefined ? callConfigToActions(hint(m)?.call_config!, type) : []\n }\n const bareActions = (type: 'CREATE' | 'CALL') => {\n return callConfigToActions(appSpec.bare_call_config, type)\n }\n const callConfigToActions = (c: CallConfig, type: 'CREATE' | 'CALL') => {\n const actions: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[] = []\n if (c.close_out && ['ALL', type].includes(c.close_out)) actions.push('CloseOut')\n if (c.delete_application && ['ALL', type].includes(c.delete_application)) actions.push('DeleteApplication')\n if (c.no_op && ['ALL', type].includes(c.no_op)) actions.push('NoOp')\n if (c.opt_in && ['ALL', type].includes(c.opt_in)) actions.push('OptIn')\n if (c.update_application && ['ALL', type].includes(c.update_application)) actions.push('UpdateApplication')\n return actions\n }\n const getDefaultArgValue = (\n type: string,\n defaultArg: DefaultArgument | undefined,\n ): Arc56Contract['methods'][0]['args'][0]['defaultValue'] => {\n if (!defaultArg || defaultArg.source === 'abi-method') return undefined\n\n return {\n source: defaultArg.source === 'constant' ? 'literal' : defaultArg.source === 'global-state' ? 'global' : 'local',\n data: typeof defaultArg.data === 'string' ? Buffer.from(defaultArg.data).toString('base64') : defaultArg.data,\n type: type === 'string' ? 'AVMString' : type,\n }\n }\n\n return {\n arcs: [],\n name: appSpec.contract.name,\n desc: appSpec.contract.desc,\n structs: structs,\n methods: appSpec.contract.methods.map(\n (m) =>\n ({\n name: m.name,\n desc: m.desc,\n args: m.args.map((a) => ({\n name: a.name,\n type: a.type,\n desc: a.desc,\n struct: a.name ? hint(m)?.structs?.[a.name]?.name : undefined,\n defaultValue: getDefaultArgValue(a.type, !a.name ? undefined : hint(m)?.default_arguments?.[a.name]),\n })),\n returns: {\n type: m.returns.type,\n desc: m.returns.desc,\n struct: hint(m)?.structs?.output?.name,\n },\n events: [],\n readonly: hint(m)?.read_only,\n actions: {\n create: actions(m, 'CREATE') as Arc56Method['actions']['create'],\n call: actions(m, 'CALL'),\n },\n }) satisfies Arc56Method,\n ),\n state: {\n schema: {\n global: {\n ints: appSpec.state.global.num_uints,\n bytes: appSpec.state.global.num_byte_slices,\n },\n local: {\n ints: appSpec.state.local.num_uints,\n bytes: appSpec.state.local.num_byte_slices,\n },\n },\n keys: {\n global: Object.fromEntries(\n Object.entries(appSpec.schema.global.declared).map((s) => [\n s[0],\n {\n key: Buffer.from(s[1].key, 'utf-8').toString('base64'),\n keyType: 'AVMString',\n valueType: s[1].type === 'uint64' ? 'AVMUint64' : 'AVMBytes',\n desc: s[1].descr,\n } satisfies StorageKey,\n ]),\n ),\n local: Object.fromEntries(\n Object.entries(appSpec.schema.local.declared).map((s) => [\n s[0],\n {\n key: Buffer.from(s[1].key, 'utf-8').toString('base64'),\n keyType: 'AVMString',\n valueType: s[1].type === 'uint64' ? 'AVMUint64' : 'AVMBytes',\n desc: s[1].descr,\n } satisfies StorageKey,\n ]),\n ),\n box: {},\n },\n maps: {\n global: {},\n local: {},\n box: {},\n },\n },\n source: appSpec.source,\n bareActions: {\n create: bareActions('CREATE') as unknown as Arc56Contract['bareActions']['create'],\n call: bareActions('CALL'),\n },\n byteCode: undefined,\n compilerInfo: undefined,\n events: undefined,\n networks: undefined,\n scratchVariables: undefined,\n sourceInfo: undefined,\n templateVariables: undefined,\n } satisfies Arc56Contract\n}\n\n/** An ARC-0032 Application Specification see https://github.com/algorandfoundation/ARCs/pull/150 */\nexport interface AppSpec {\n /** Method call hints */\n hints: HintSpec\n /** The TEAL source */\n source: AppSources\n /** The ABI-0004 contract definition see https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0004.md */\n contract: ABIContractParams\n /** The values that make up the local and global state */\n schema: SchemaSpec\n /** The rolled-up schema allocation values for local and global state */\n state: StateSchemaSpec\n /** The config of all BARE calls (i.e. non ABI calls with no args) */\n bare_call_config: CallConfig\n}\n\n/** A lookup of encoded method call spec to hint */\nexport type HintSpec = Record<string, Hint>\n\n/** The TEAL source of a contract */\nexport interface AppSources {\n /** The TEAL source of the approval program */\n approval: string\n /** The TEAL source of the clear program */\n clear: string\n}\n\n/** The various call configs:\n * * `NEVER`: Will not be called\n * * `CALL`: Can be called during a non-create call i.e. app id != 0\n * * `CREATE`: Can be called during a create call i.e. app id = 0\n * * `ALL`: Can be during a create OR non-create call\n **/\nexport type CallConfigValue = 'NEVER' | 'CALL' | 'CREATE' | 'ALL'\n\n/** Call configuration for a method */\nexport interface CallConfig {\n /** NoOp call config */\n no_op?: CallConfigValue\n /** Opt-in call config */\n opt_in?: CallConfigValue\n /** Close out call config */\n close_out?: CallConfigValue\n /** Update call config */\n update_application?: CallConfigValue\n /** Delete call config */\n delete_application?: CallConfigValue\n}\n\n/** Hint information for a given method call to allow client generation */\nexport interface Hint {\n /** Any user-defined struct/tuple types used in the method call, keyed by parameter name or `output` for return type */\n structs?: Record<string, Struct>\n read_only?: boolean\n default_arguments?: Record<string, DefaultArgument>\n call_config: CallConfig\n}\n\n/** The name of a field */\nexport type FieldName = string\n\n/** The string name of an ABI type */\nexport type ABIType = string\n\n/** The elements of the struct/tuple: `FieldName`, `ABIType` */\nexport type StructElement = [FieldName, ABIType]\n\n/** A user-defined struct/tuple type */\nexport interface Struct {\n /** The name of the type */\n name: string\n /** The elements (in order) that make up the struct/tuple */\n elements: StructElement[]\n}\n\n/**\n * Defines a strategy for obtaining a default value for a given ABI arg.\n */\nexport type DefaultArgument =\n | {\n /**\n * The default value should be fetched by invoking an ABI method\n */\n source: 'abi-method'\n data: ABIMethodParams\n }\n | {\n /**\n * The default value should be fetched from global state\n */\n source: 'global-state'\n /**\n * The key of the state variable\n */\n data: string\n }\n | {\n /**\n * The default value should be fetched from the local state of the sender user\n */\n source: 'local-state'\n /**\n * The key of the state variable\n */\n data: string\n }\n | {\n /**\n * The default value is a constant.\n */\n source: 'constant'\n /**\n * The static default value to use.\n */\n data: string | number\n }\n\n/** AVM data type */\nexport type AVMType = 'uint64' | 'bytes'\n\n/** Declared schema value specification */\nexport interface DeclaredSchemaValueSpec {\n /** The type of value */\n type: AVMType\n /** The name of the key */\n key: string\n /** A description of the variable */\n descr?: string\n /** Whether or not the value is set statically (at create time only) or dynamically */\n static?: boolean\n}\n\n/** Reserved schema value specification */\nexport interface ReservedSchemaValueSpec {\n /** The type of value */\n type: AVMType\n /** The description of the reserved storage space */\n descr: string\n /** The maximum number of slots to reserve */\n max_keys: number\n}\n\n/** The schema for global and local storage */\nexport interface SchemaSpec {\n /** The local storage schema */\n local: Schema\n /** The global storage schema */\n global: Schema\n}\n\n/** The storage schema definition */\nexport interface Schema {\n /** Declared storage schema */\n declared: Record<string, DeclaredSchemaValueSpec>\n /** Reserved storage schema */\n reserved: Record<string, ReservedSchemaValueSpec>\n}\n\n/** The rolled-up schema allocation specification for local and global state */\nexport interface StateSchemaSpec {\n /** Global storage spec */\n global: StateSchema\n /** Local storage spec */\n local: StateSchema\n}\n\n/** Schema spec summary for global or local storage */\nexport type StateSchema = {\n /** Number of uint slots */\n num_uints: number\n /** Number of byte slots */\n num_byte_slices: number\n}\n"],"names":[],"mappings":";;AAIA,IAAO,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;AAE9B,SAAU,YAAY,CAAC,OAAgB,EAAA;AAC3C,IAAA,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAA;AACvG,IAAA,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAChC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAI;AAC/B,QAAA,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AACvE,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,CAAC,IAAI,KAAK,QAAQ,GAAG,WAAW,GAAG,UAAU;AAC5D,wBAAA,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK;AACI,qBAAA;AACvB,iBAAA,CAAC,CACH;AACD,gBAAA,GAAG,EAAE,EAAE;AACR,aAAA;AACD,YAAA,IAAI,EAAE;AACJ,gBAAA,MAAM,EAAE,EAAE;AACV,gBAAA,KAAK,EAAE,EAAE;AACT,gBAAA,GAAG,EAAE,EAAE;AACR,aAAA;AACF,SAAA;QACD,MAAM,EAAE,OAAO,CAAC,MAAM;AACtB,QAAA,WAAW,EAAE;AACX,YAAA,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAsD;AAClF,YAAA,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC;AAC1B,SAAA;AACD,QAAA,QAAQ,EAAE,SAAS;AACnB,QAAA,YAAY,EAAE,SAAS;AACvB,QAAA,MAAM,EAAE,SAAS;AACjB,QAAA,QAAQ,EAAE,SAAS;AACnB,QAAA,gBAAgB,EAAE,SAAS;AAC3B,QAAA,UAAU,EAAE,SAAS;AACrB,QAAA,iBAAiB,EAAE,SAAS;KACL,CAAA;AAC3B;;;;"}
@@ -1,7 +1,7 @@
1
1
  import algosdk from 'algosdk';
2
2
  import { AccountAssetInformation, TransactionSignerAccount } from './account';
3
3
  import AlgoKitComposer, { CommonTransactionParams } from './composer';
4
- import { ExecuteParams } from './transaction';
4
+ import { SendParams } from './transaction';
5
5
  /** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */
6
6
  export interface BulkAssetOptInOutResult {
7
7
  /** The ID of the asset opted into / out of */
@@ -173,7 +173,7 @@ export declare class AssetManager {
173
173
  * ```
174
174
  * @returns An array of records matching asset ID to transaction ID of the opt in
175
175
  */
176
- bulkOptIn(account: string | TransactionSignerAccount, assetIds: bigint[], options?: Omit<CommonTransactionParams, 'sender'> & ExecuteParams): Promise<BulkAssetOptInOutResult[]>;
176
+ bulkOptIn(account: string | TransactionSignerAccount, assetIds: bigint[], options?: Omit<CommonTransactionParams, 'sender'> & SendParams): Promise<BulkAssetOptInOutResult[]>;
177
177
  /**
178
178
  * Opt an account out of a list of Algorand Standard Assets.
179
179
  *
@@ -191,7 +191,7 @@ export declare class AssetManager {
191
191
  * ```
192
192
  * @returns An array of records matching asset ID to transaction ID of the opt in
193
193
  */
194
- bulkOptOut(account: string | TransactionSignerAccount, assetIds: bigint[], options?: Omit<CommonTransactionParams, 'sender'> & ExecuteParams & {
194
+ bulkOptOut(account: string | TransactionSignerAccount, assetIds: bigint[], options?: Omit<CommonTransactionParams, 'sender'> & SendParams & {
195
195
  /** Whether or not to check if the account has a zero balance for each asset first or not.
196
196
  *
197
197
  * Defaults to `true`.
@@ -105,7 +105,7 @@ class AssetManager {
105
105
  assetId: BigInt(assetId),
106
106
  });
107
107
  }
108
- const result = await composer.execute(options);
108
+ const result = await composer.send(options);
109
109
  config.Config.getLogger(options?.suppressLog).info(`Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +
110
110
  `\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`);
111
111
  assetGroup.forEach((assetId, index) => {
@@ -164,7 +164,7 @@ class AssetManager {
164
164
  assetId: BigInt(assetId),
165
165
  });
166
166
  }
167
- const result = await composer.execute(options);
167
+ const result = await composer.send(options);
168
168
  config.Config.getLogger(options?.suppressLog).info(`Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +
169
169
  `\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`);
170
170
  assetGroup.forEach((assetId, index) => {
@@ -1 +1 @@
1
- {"version":3,"file":"asset-manager.js","sources":["../../src/types/asset-manager.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { Config } from '../config'\nimport { chunkArray } from '../util'\nimport { AccountAssetInformation, TransactionSignerAccount } from './account'\nimport AlgoKitComposer, { CommonTransactionParams, MAX_TRANSACTION_GROUP_SIZE } from './composer'\nimport { ExecuteParams } from './transaction'\nimport AssetModel = algosdk.modelsv2.Asset\n\n/** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */\nexport interface BulkAssetOptInOutResult {\n /** The ID of the asset opted into / out of */\n assetId: bigint\n /** The transaction ID of the resulting opt in / out */\n transactionId: string\n}\n\n/** Information about an asset. */\nexport interface AssetInformation {\n /** The ID of the asset. */\n assetId: bigint\n\n /** The address of the account that created the asset.\n *\n * This is the address where the parameters for this asset can be found,\n * and also the address where unwanted asset units can be sent when\n * closing out an asset position and opting-out of the asset.\n */\n creator: string\n\n /** The total amount of the smallest divisible (decimal) units that were created of the asset.\n *\n * For example, if `decimals` is, say, 2, then for every 100 `total` there is 1 whole unit.\n */\n total: bigint\n\n /** The amount of decimal places the asset was created with.\n *\n * * If 0, the asset is not divisible;\n * * If 1, the base unit of the asset is in tenths;\n * * If 2, the base unit of the asset is in hundredths;\n * * If 3, the base unit of the asset is in thousandths;\n * * and so on up to 19 decimal places.\n */\n decimals: number\n\n /** Whether the asset was frozen by default for all accounts.\n *\n * If `true` then for anyone apart from the creator to hold the\n * asset it needs to be unfrozen per account using an asset freeze\n * transaction from the `freeze` account.\n */\n defaultFrozen?: boolean\n\n /** The address of the optional account that can manage the configuration of the asset and destroy it.\n *\n * If not set the asset is permanently immutable.\n */\n manager?: string\n\n /**\n * The address of the optional account that holds the reserve (uncirculated supply) units of the asset.\n *\n * This address has no specific authority in the protocol itself and is informational only.\n *\n * Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md)\n * rely on this field to hold meaningful data.\n *\n * It can be used in the case where you want to signal to holders of your asset that the uncirculated units\n * of the asset reside in an account that is different from the default creator account.\n *\n * If not set the field is permanently empty.\n */\n reserve?: string\n\n /**\n * The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account.\n *\n * If empty, freezing is not permitted.\n *\n * If not set the field is permanently empty.\n */\n freeze?: string\n\n /**\n * The address of the optional account that can clawback holdings of this asset from any account.\n *\n * The clawback account has the ability to **unconditionally take assets from any account**.\n *\n * If empty, clawback is not permitted.\n *\n * If not set the field is permanently empty.\n */\n clawback?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitName?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitNameAsBytes?: Uint8Array\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetName?: string\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetNameAsBytes?: Uint8Array\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n url?: string\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n urlAsBytes?: Uint8Array\n\n /** 32-byte hash of some metadata that is relevant to the asset and/or asset holders.\n *\n * The format of this metadata is up to the application.\n */\n metadataHash?: Uint8Array\n}\n\n/** Allows management of asset information. */\nexport class AssetManager {\n private _algod: algosdk.Algodv2\n private _newGroup: () => AlgoKitComposer\n\n /**\n * Create a new asset manager.\n * @param algod An algod client\n * @param newGroup A function that creates a new `AlgoKitComposer` transaction group\n * @example Create a new asset manager\n * ```typescript\n * const assetManager = new AssetManager(algod, () => new AlgoKitComposer({algod, () => signer, () => suggestedParams}))\n * ```\n */\n constructor(algod: algosdk.Algodv2, newGroup: () => AlgoKitComposer) {\n this._algod = algod\n this._newGroup = newGroup\n }\n\n /**\n * Returns the current asset information for the asset with the given ID.\n *\n * @example\n * ```typescript\n * const assetInfo = await assetManager.getById(12353n);\n * ```\n *\n * @param assetId The ID of the asset\n * @returns The asset information\n */\n public async getById(assetId: bigint): Promise<AssetInformation> {\n const asset = AssetModel.from_obj_for_encoding(await this._algod.getAssetByID(Number(assetId)).do())\n\n return {\n assetId: BigInt(asset.index),\n total: BigInt(asset.params.total),\n decimals: Number(asset.params.decimals),\n assetName: asset.params.name,\n assetNameAsBytes: asset.params.nameB64,\n unitName: asset.params.unitName,\n unitNameAsBytes: asset.params.unitNameB64,\n url: asset.params.url,\n urlAsBytes: asset.params.urlB64,\n creator: asset.params.creator,\n manager: asset.params.manager,\n clawback: asset.params.clawback,\n freeze: asset.params.freeze,\n reserve: asset.params.reserve,\n defaultFrozen: asset.params.defaultFrozen,\n metadataHash: asset.params.metadataHash,\n }\n }\n\n /**\n * Returns the given sender account's asset holding for a given asset.\n *\n * @example\n * ```typescript\n * const address = \"XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA\";\n * const assetId = 123345n;\n * const accountInfo = await algorand.asset.getAccountInformation(address, assetId);\n * ```\n *\n * [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddressassetsasset-id)\n * @param sender The address of the sender/account to look up\n * @param assetId The ID of the asset to return a holding for\n * @returns The account asset holding information\n */\n public async getAccountInformation(sender: string | TransactionSignerAccount, assetId: bigint): Promise<AccountAssetInformation> {\n const info = await this._algod.accountAssetInformation(typeof sender === 'string' ? sender : sender.addr, Number(assetId)).do()\n\n return {\n assetId: BigInt(assetId),\n balance: BigInt(info['asset-holding']['amount']),\n frozen: info['asset-holding']['is-frozen'] === true,\n round: BigInt(info['round']),\n }\n }\n\n /**\n * Opt an account in to a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-in to\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * algorand.asset.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * algorand.asset.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n], { maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptIn(\n account: string | TransactionSignerAccount,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> & ExecuteParams,\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n for (const assetId of assetGroup) {\n composer.addAssetOptIn({\n ...options,\n sender: typeof account === 'string' ? account : account.addr,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.execute(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n\n /**\n * Opt an account out of a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-out of\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * algorand.asset.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * algorand.asset.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptOut(\n account: string | TransactionSignerAccount,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> &\n ExecuteParams & {\n /** Whether or not to check if the account has a zero balance for each asset first or not.\n *\n * Defaults to `true`.\n *\n * If this is set to `true` and the account has an asset balance it will throw an error.\n *\n * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator.\n */\n ensureZeroBalance?: boolean\n },\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n const sender = typeof account === 'string' ? account : account.addr\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n const notOptedInAssetIds: bigint[] = []\n const nonZeroBalanceAssetIds: bigint[] = []\n for (const assetId of assetGroup) {\n if (options?.ensureZeroBalance !== false) {\n try {\n const accountAssetInfo = await this.getAccountInformation(sender, assetId)\n if (accountAssetInfo.balance !== 0n) {\n nonZeroBalanceAssetIds.push(BigInt(assetId))\n }\n } catch {\n notOptedInAssetIds.push(BigInt(assetId))\n }\n }\n }\n\n if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) {\n throw new Error(\n `Account ${sender}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${\n nonZeroBalanceAssetIds.length > 0\n ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? 's' : ''} ${nonZeroBalanceAssetIds.join(', ')}`\n : ''\n }; can't opt-out.`,\n )\n }\n\n for (const assetId of assetGroup) {\n composer.addAssetOptOut({\n ...options,\n creator: (await this.getById(BigInt(assetId))).creator,\n sender,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.execute(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n}\n"],"names":["chunkArray","MAX_TRANSACTION_GROUP_SIZE","Config"],"mappings":";;;;;;;AAMA,IAAO,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAA;AAmI1C;MACa,YAAY,CAAA;AAIvB;;;;;;;;AAQG;IACH,WAAY,CAAA,KA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AAA;aACH;YAED,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAE9C,YAAAC,aAAM,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,IAAI,CACzC,CAAsB,mBAAA,EAAA,OAAO,CAAkB,eAAA,EAAA,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,sBAAA,EAAyB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAE,CAAA;AACpH,gBAAA,CAAA,kBAAA,EAAqB,MAAM,CAAC,OAAO,CAAA,UAAA,EAAa,MAAM,CAAC,aAAa,GAAG,CAAC,CAAC,EAAE,cAAc,CAAA,CAAA,CAAG,CAC/F,CAAA;YAED,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,KAAI;gBACpC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;AAChF,aAAC,CAAC,CAAA;SACH;AAED,QAAA,OAAO,OAAO,CAAA;KACf;AACF;;;;"}
1
+ {"version":3,"file":"asset-manager.js","sources":["../../src/types/asset-manager.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { Config } from '../config'\nimport { chunkArray } from '../util'\nimport { AccountAssetInformation, TransactionSignerAccount } from './account'\nimport AlgoKitComposer, { CommonTransactionParams, MAX_TRANSACTION_GROUP_SIZE } from './composer'\nimport { SendParams } from './transaction'\nimport AssetModel = algosdk.modelsv2.Asset\n\n/** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */\nexport interface BulkAssetOptInOutResult {\n /** The ID of the asset opted into / out of */\n assetId: bigint\n /** The transaction ID of the resulting opt in / out */\n transactionId: string\n}\n\n/** Information about an asset. */\nexport interface AssetInformation {\n /** The ID of the asset. */\n assetId: bigint\n\n /** The address of the account that created the asset.\n *\n * This is the address where the parameters for this asset can be found,\n * and also the address where unwanted asset units can be sent when\n * closing out an asset position and opting-out of the asset.\n */\n creator: string\n\n /** The total amount of the smallest divisible (decimal) units that were created of the asset.\n *\n * For example, if `decimals` is, say, 2, then for every 100 `total` there is 1 whole unit.\n */\n total: bigint\n\n /** The amount of decimal places the asset was created with.\n *\n * * If 0, the asset is not divisible;\n * * If 1, the base unit of the asset is in tenths;\n * * If 2, the base unit of the asset is in hundredths;\n * * If 3, the base unit of the asset is in thousandths;\n * * and so on up to 19 decimal places.\n */\n decimals: number\n\n /** Whether the asset was frozen by default for all accounts.\n *\n * If `true` then for anyone apart from the creator to hold the\n * asset it needs to be unfrozen per account using an asset freeze\n * transaction from the `freeze` account.\n */\n defaultFrozen?: boolean\n\n /** The address of the optional account that can manage the configuration of the asset and destroy it.\n *\n * If not set the asset is permanently immutable.\n */\n manager?: string\n\n /**\n * The address of the optional account that holds the reserve (uncirculated supply) units of the asset.\n *\n * This address has no specific authority in the protocol itself and is informational only.\n *\n * Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md)\n * rely on this field to hold meaningful data.\n *\n * It can be used in the case where you want to signal to holders of your asset that the uncirculated units\n * of the asset reside in an account that is different from the default creator account.\n *\n * If not set the field is permanently empty.\n */\n reserve?: string\n\n /**\n * The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account.\n *\n * If empty, freezing is not permitted.\n *\n * If not set the field is permanently empty.\n */\n freeze?: string\n\n /**\n * The address of the optional account that can clawback holdings of this asset from any account.\n *\n * The clawback account has the ability to **unconditionally take assets from any account**.\n *\n * If empty, clawback is not permitted.\n *\n * If not set the field is permanently empty.\n */\n clawback?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitName?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitNameAsBytes?: Uint8Array\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetName?: string\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetNameAsBytes?: Uint8Array\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n url?: string\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n urlAsBytes?: Uint8Array\n\n /** 32-byte hash of some metadata that is relevant to the asset and/or asset holders.\n *\n * The format of this metadata is up to the application.\n */\n metadataHash?: Uint8Array\n}\n\n/** Allows management of asset information. */\nexport class AssetManager {\n private _algod: algosdk.Algodv2\n private _newGroup: () => AlgoKitComposer\n\n /**\n * Create a new asset manager.\n * @param algod An algod client\n * @param newGroup A function that creates a new `AlgoKitComposer` transaction group\n * @example Create a new asset manager\n * ```typescript\n * const assetManager = new AssetManager(algod, () => new AlgoKitComposer({algod, () => signer, () => suggestedParams}))\n * ```\n */\n constructor(algod: algosdk.Algodv2, newGroup: () => AlgoKitComposer) {\n this._algod = algod\n this._newGroup = newGroup\n }\n\n /**\n * Returns the current asset information for the asset with the given ID.\n *\n * @example\n * ```typescript\n * const assetInfo = await assetManager.getById(12353n);\n * ```\n *\n * @param assetId The ID of the asset\n * @returns The asset information\n */\n public async getById(assetId: bigint): Promise<AssetInformation> {\n const asset = AssetModel.from_obj_for_encoding(await this._algod.getAssetByID(Number(assetId)).do())\n\n return {\n assetId: BigInt(asset.index),\n total: BigInt(asset.params.total),\n decimals: Number(asset.params.decimals),\n assetName: asset.params.name,\n assetNameAsBytes: asset.params.nameB64,\n unitName: asset.params.unitName,\n unitNameAsBytes: asset.params.unitNameB64,\n url: asset.params.url,\n urlAsBytes: asset.params.urlB64,\n creator: asset.params.creator,\n manager: asset.params.manager,\n clawback: asset.params.clawback,\n freeze: asset.params.freeze,\n reserve: asset.params.reserve,\n defaultFrozen: asset.params.defaultFrozen,\n metadataHash: asset.params.metadataHash,\n }\n }\n\n /**\n * Returns the given sender account's asset holding for a given asset.\n *\n * @example\n * ```typescript\n * const address = \"XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA\";\n * const assetId = 123345n;\n * const accountInfo = await algorand.asset.getAccountInformation(address, assetId);\n * ```\n *\n * [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddressassetsasset-id)\n * @param sender The address of the sender/account to look up\n * @param assetId The ID of the asset to return a holding for\n * @returns The account asset holding information\n */\n public async getAccountInformation(sender: string | TransactionSignerAccount, assetId: bigint): Promise<AccountAssetInformation> {\n const info = await this._algod.accountAssetInformation(typeof sender === 'string' ? sender : sender.addr, Number(assetId)).do()\n\n return {\n assetId: BigInt(assetId),\n balance: BigInt(info['asset-holding']['amount']),\n frozen: info['asset-holding']['is-frozen'] === true,\n round: BigInt(info['round']),\n }\n }\n\n /**\n * Opt an account in to a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-in to\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * algorand.asset.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * algorand.asset.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n], { maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptIn(\n account: string | TransactionSignerAccount,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> & SendParams,\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n for (const assetId of assetGroup) {\n composer.addAssetOptIn({\n ...options,\n sender: typeof account === 'string' ? account : account.addr,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n\n /**\n * Opt an account out of a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-out of\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * algorand.asset.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * algorand.asset.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptOut(\n account: string | TransactionSignerAccount,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> &\n SendParams & {\n /** Whether or not to check if the account has a zero balance for each asset first or not.\n *\n * Defaults to `true`.\n *\n * If this is set to `true` and the account has an asset balance it will throw an error.\n *\n * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator.\n */\n ensureZeroBalance?: boolean\n },\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n const sender = typeof account === 'string' ? account : account.addr\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n const notOptedInAssetIds: bigint[] = []\n const nonZeroBalanceAssetIds: bigint[] = []\n for (const assetId of assetGroup) {\n if (options?.ensureZeroBalance !== false) {\n try {\n const accountAssetInfo = await this.getAccountInformation(sender, assetId)\n if (accountAssetInfo.balance !== 0n) {\n nonZeroBalanceAssetIds.push(BigInt(assetId))\n }\n } catch {\n notOptedInAssetIds.push(BigInt(assetId))\n }\n }\n }\n\n if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) {\n throw new Error(\n `Account ${sender}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${\n nonZeroBalanceAssetIds.length > 0\n ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? 's' : ''} ${nonZeroBalanceAssetIds.join(', ')}`\n : ''\n }; can't opt-out.`,\n )\n }\n\n for (const assetId of assetGroup) {\n composer.addAssetOptOut({\n ...options,\n creator: (await this.getById(BigInt(assetId))).creator,\n sender,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n}\n"],"names":["chunkArray","MAX_TRANSACTION_GROUP_SIZE","Config"],"mappings":";;;;;;;AAMA,IAAO,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAA;AAmI1C;MACa,YAAY,CAAA;AAIvB;;;;;;;;AAQG;IACH,WAAY,CAAA,KAAsB,EAAE,QAA+B,EAAA;AACjE,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;AACnB,QAAA,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;KAC1B;AAED;;;;;;;;;;AAUG;IACI,MAAM,OAAO,CAAC,OAAe,EAAA;QAClC,MAAM,KAAK,GAAG,UAAU,CAAC,qBAAqB,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,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