@algorandfoundation/algokit-utils 10.0.0-alpha.6 → 10.0.0-alpha.8

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.
@@ -247,8 +247,8 @@ declare class AppFactory {
247
247
  signer: AddressWithTransactionSigner | TransactionSigner | undefined;
248
248
  method: ABIMethod;
249
249
  args: (Transaction | ABIValue | TransactionWithSigner | AppMethodCall<{
250
- sender: SendingAddress;
251
250
  signer?: AddressWithTransactionSigner | TransactionSigner | undefined;
251
+ sender: SendingAddress;
252
252
  rekeyTo?: ReadableAddress | undefined;
253
253
  note?: string | Uint8Array | undefined;
254
254
  lease?: string | Uint8Array | undefined;
@@ -258,8 +258,7 @@ declare class AppFactory {
258
258
  validityWindow?: number | bigint | undefined;
259
259
  firstValidRound?: bigint | undefined;
260
260
  lastValidRound?: bigint | undefined;
261
- appId: bigint;
262
- onComplete?: OnApplicationComplete.UpdateApplication | undefined;
261
+ onComplete?: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication | undefined;
263
262
  args?: Uint8Array[] | undefined;
264
263
  accountReferences?: ReadableAddress[] | undefined;
265
264
  appReferences?: bigint[] | undefined;
@@ -269,9 +268,16 @@ declare class AppFactory {
269
268
  rejectVersion?: number | undefined;
270
269
  approvalProgram: string | Uint8Array;
271
270
  clearStateProgram: string | Uint8Array;
272
- }> | AppMethodCall<{
273
- signer?: AddressWithTransactionSigner | TransactionSigner | undefined;
271
+ schema?: {
272
+ globalInts: number;
273
+ globalByteSlices: number;
274
+ localInts: number;
275
+ localByteSlices: number;
276
+ } | undefined;
277
+ extraProgramPages?: number | undefined;
278
+ }> | Promise<Transaction> | AppMethodCall<{
274
279
  sender: SendingAddress;
280
+ signer?: AddressWithTransactionSigner | TransactionSigner | undefined;
275
281
  rekeyTo?: ReadableAddress | undefined;
276
282
  note?: string | Uint8Array | undefined;
277
283
  lease?: string | Uint8Array | undefined;
@@ -281,7 +287,8 @@ declare class AppFactory {
281
287
  validityWindow?: number | bigint | undefined;
282
288
  firstValidRound?: bigint | undefined;
283
289
  lastValidRound?: bigint | undefined;
284
- onComplete?: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication | undefined;
290
+ appId: bigint;
291
+ onComplete?: OnApplicationComplete.UpdateApplication | undefined;
285
292
  args?: Uint8Array[] | undefined;
286
293
  accountReferences?: ReadableAddress[] | undefined;
287
294
  appReferences?: bigint[] | undefined;
@@ -291,14 +298,7 @@ declare class AppFactory {
291
298
  rejectVersion?: number | undefined;
292
299
  approvalProgram: string | Uint8Array;
293
300
  clearStateProgram: string | Uint8Array;
294
- schema?: {
295
- globalInts: number;
296
- globalByteSlices: number;
297
- localInts: number;
298
- localByteSlices: number;
299
- } | undefined;
300
- extraProgramPages?: number | undefined;
301
- }> | Promise<Transaction> | AppMethodCall<AppMethodCallParams> | undefined)[] | undefined;
301
+ }> | AppMethodCall<AppMethodCallParams> | undefined)[] | undefined;
302
302
  onComplete: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication;
303
303
  }>;
304
304
  /** Return params for a deployment update ABI call */
@@ -349,8 +349,8 @@ declare class AppFactory {
349
349
  signer: AddressWithTransactionSigner | TransactionSigner | undefined;
350
350
  method: ABIMethod;
351
351
  args: (Transaction | ABIValue | TransactionWithSigner | AppMethodCall<{
352
- sender: SendingAddress;
353
352
  signer?: AddressWithTransactionSigner | TransactionSigner | undefined;
353
+ sender: SendingAddress;
354
354
  rekeyTo?: ReadableAddress | undefined;
355
355
  note?: string | Uint8Array | undefined;
356
356
  lease?: string | Uint8Array | undefined;
@@ -360,8 +360,7 @@ declare class AppFactory {
360
360
  validityWindow?: number | bigint | undefined;
361
361
  firstValidRound?: bigint | undefined;
362
362
  lastValidRound?: bigint | undefined;
363
- appId: bigint;
364
- onComplete?: OnApplicationComplete.UpdateApplication | undefined;
363
+ onComplete?: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication | undefined;
365
364
  args?: Uint8Array[] | undefined;
366
365
  accountReferences?: ReadableAddress[] | undefined;
367
366
  appReferences?: bigint[] | undefined;
@@ -371,9 +370,16 @@ declare class AppFactory {
371
370
  rejectVersion?: number | undefined;
372
371
  approvalProgram: string | Uint8Array;
373
372
  clearStateProgram: string | Uint8Array;
374
- }> | AppMethodCall<{
375
- signer?: AddressWithTransactionSigner | TransactionSigner | undefined;
373
+ schema?: {
374
+ globalInts: number;
375
+ globalByteSlices: number;
376
+ localInts: number;
377
+ localByteSlices: number;
378
+ } | undefined;
379
+ extraProgramPages?: number | undefined;
380
+ }> | Promise<Transaction> | AppMethodCall<{
376
381
  sender: SendingAddress;
382
+ signer?: AddressWithTransactionSigner | TransactionSigner | undefined;
377
383
  rekeyTo?: ReadableAddress | undefined;
378
384
  note?: string | Uint8Array | undefined;
379
385
  lease?: string | Uint8Array | undefined;
@@ -383,7 +389,8 @@ declare class AppFactory {
383
389
  validityWindow?: number | bigint | undefined;
384
390
  firstValidRound?: bigint | undefined;
385
391
  lastValidRound?: bigint | undefined;
386
- onComplete?: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication | undefined;
392
+ appId: bigint;
393
+ onComplete?: OnApplicationComplete.UpdateApplication | undefined;
387
394
  args?: Uint8Array[] | undefined;
388
395
  accountReferences?: ReadableAddress[] | undefined;
389
396
  appReferences?: bigint[] | undefined;
@@ -393,14 +400,7 @@ declare class AppFactory {
393
400
  rejectVersion?: number | undefined;
394
401
  approvalProgram: string | Uint8Array;
395
402
  clearStateProgram: string | Uint8Array;
396
- schema?: {
397
- globalInts: number;
398
- globalByteSlices: number;
399
- localInts: number;
400
- localByteSlices: number;
401
- } | undefined;
402
- extraProgramPages?: number | undefined;
403
- }> | Promise<Transaction> | AppMethodCall<AppMethodCallParams> | undefined)[] | undefined;
403
+ }> | AppMethodCall<AppMethodCallParams> | undefined)[] | undefined;
404
404
  onComplete: OnApplicationComplete.UpdateApplication;
405
405
  };
406
406
  /** Return params for a deployment delete ABI call */
@@ -451,8 +451,8 @@ declare class AppFactory {
451
451
  signer: AddressWithTransactionSigner | TransactionSigner | undefined;
452
452
  method: ABIMethod;
453
453
  args: (Transaction | ABIValue | TransactionWithSigner | AppMethodCall<{
454
- sender: SendingAddress;
455
454
  signer?: AddressWithTransactionSigner | TransactionSigner | undefined;
455
+ sender: SendingAddress;
456
456
  rekeyTo?: ReadableAddress | undefined;
457
457
  note?: string | Uint8Array | undefined;
458
458
  lease?: string | Uint8Array | undefined;
@@ -462,8 +462,7 @@ declare class AppFactory {
462
462
  validityWindow?: number | bigint | undefined;
463
463
  firstValidRound?: bigint | undefined;
464
464
  lastValidRound?: bigint | undefined;
465
- appId: bigint;
466
- onComplete?: OnApplicationComplete.UpdateApplication | undefined;
465
+ onComplete?: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication | undefined;
467
466
  args?: Uint8Array[] | undefined;
468
467
  accountReferences?: ReadableAddress[] | undefined;
469
468
  appReferences?: bigint[] | undefined;
@@ -473,9 +472,16 @@ declare class AppFactory {
473
472
  rejectVersion?: number | undefined;
474
473
  approvalProgram: string | Uint8Array;
475
474
  clearStateProgram: string | Uint8Array;
476
- }> | AppMethodCall<{
477
- signer?: AddressWithTransactionSigner | TransactionSigner | undefined;
475
+ schema?: {
476
+ globalInts: number;
477
+ globalByteSlices: number;
478
+ localInts: number;
479
+ localByteSlices: number;
480
+ } | undefined;
481
+ extraProgramPages?: number | undefined;
482
+ }> | Promise<Transaction> | AppMethodCall<{
478
483
  sender: SendingAddress;
484
+ signer?: AddressWithTransactionSigner | TransactionSigner | undefined;
479
485
  rekeyTo?: ReadableAddress | undefined;
480
486
  note?: string | Uint8Array | undefined;
481
487
  lease?: string | Uint8Array | undefined;
@@ -485,7 +491,8 @@ declare class AppFactory {
485
491
  validityWindow?: number | bigint | undefined;
486
492
  firstValidRound?: bigint | undefined;
487
493
  lastValidRound?: bigint | undefined;
488
- onComplete?: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication | undefined;
494
+ appId: bigint;
495
+ onComplete?: OnApplicationComplete.UpdateApplication | undefined;
489
496
  args?: Uint8Array[] | undefined;
490
497
  accountReferences?: ReadableAddress[] | undefined;
491
498
  appReferences?: bigint[] | undefined;
@@ -495,14 +502,7 @@ declare class AppFactory {
495
502
  rejectVersion?: number | undefined;
496
503
  approvalProgram: string | Uint8Array;
497
504
  clearStateProgram: string | Uint8Array;
498
- schema?: {
499
- globalInts: number;
500
- globalByteSlices: number;
501
- localInts: number;
502
- localByteSlices: number;
503
- } | undefined;
504
- extraProgramPages?: number | undefined;
505
- }> | Promise<Transaction> | AppMethodCall<AppMethodCallParams> | undefined)[] | undefined;
505
+ }> | AppMethodCall<AppMethodCallParams> | undefined)[] | undefined;
506
506
  onComplete: OnApplicationComplete.DeleteApplication;
507
507
  };
508
508
  bare: {
@@ -799,14 +799,14 @@ declare class AppFactory {
799
799
  compiledApproval?: CompiledTeal | undefined;
800
800
  compiledClear?: CompiledTeal | undefined;
801
801
  operationPerformed: "create";
802
+ updatable?: boolean | undefined;
803
+ deletable?: boolean | undefined;
802
804
  createdRound: bigint;
803
805
  updatedRound: bigint;
804
806
  createdMetadata: AppDeployMetadata;
805
807
  deleted: boolean;
806
808
  name: string;
807
809
  version: string;
808
- deletable?: boolean | undefined;
809
- updatable?: boolean | undefined;
810
810
  groupId: string | undefined;
811
811
  txIds: string[];
812
812
  returns?: ABIReturn[] | undefined;
@@ -845,14 +845,14 @@ declare class AppFactory {
845
845
  compiledApproval?: CompiledTeal | undefined;
846
846
  compiledClear?: CompiledTeal | undefined;
847
847
  operationPerformed: "replace";
848
+ updatable?: boolean | undefined;
849
+ deletable?: boolean | undefined;
848
850
  createdRound: bigint;
849
851
  updatedRound: bigint;
850
852
  createdMetadata: AppDeployMetadata;
851
853
  deleted: boolean;
852
854
  name: string;
853
855
  version: string;
854
- deletable?: boolean | undefined;
855
- updatable?: boolean | undefined;
856
856
  groupId: string | undefined;
857
857
  txIds: string[];
858
858
  returns?: ABIReturn[] | undefined;
package/types/app-spec.js CHANGED
@@ -35,16 +35,23 @@ function arc32ToArc56(appSpec) {
35
35
  if (c.update_application && ["ALL", type].includes(c.update_application)) actions$1.push("UpdateApplication");
36
36
  return actions$1;
37
37
  };
38
- const getDefaultArgValue = (type, defaultArg) => {
38
+ const getDefaultArgValue = (defaultArg) => {
39
39
  if (!defaultArg) return void 0;
40
40
  if (defaultArg.source === "abi-method") return {
41
41
  source: "method",
42
42
  data: defaultArg.data.name
43
43
  };
44
+ const mappedSource = defaultArg.source === "constant" ? "literal" : defaultArg.source === "global-state" ? "global" : "local";
45
+ let defaultValueType = void 0;
46
+ if (mappedSource === "literal") {
47
+ if (typeof defaultArg.data === "number") defaultValueType = "uint64";
48
+ else if (typeof defaultArg.data === "string") defaultValueType = "AVMString";
49
+ }
50
+ const argData = typeof defaultArg.data === "number" ? require_abi_type.ABIType.from("uint64").encode(defaultArg.data) : typeof defaultArg.data === "string" ? new TextEncoder().encode(defaultArg.data) : defaultArg.data;
44
51
  return {
45
- source: defaultArg.source === "constant" ? "literal" : defaultArg.source === "global-state" ? "global" : "local",
46
- data: Buffer.from(typeof defaultArg.data === "number" ? require_abi_type.ABIType.from("uint64").encode(defaultArg.data) : defaultArg.data).toString("base64"),
47
- type: type === "string" ? "AVMString" : type
52
+ source: mappedSource,
53
+ data: Buffer.from(argData).toString("base64"),
54
+ type: defaultValueType
48
55
  };
49
56
  };
50
57
  return {
@@ -60,7 +67,7 @@ function arc32ToArc56(appSpec) {
60
67
  type: a.type,
61
68
  desc: a.desc,
62
69
  struct: a.name ? hint(m)?.structs?.[a.name]?.name : void 0,
63
- defaultValue: getDefaultArgValue(a.type, !a.name ? void 0 : hint(m)?.default_arguments?.[a.name])
70
+ defaultValue: getDefaultArgValue(!a.name ? void 0 : hint(m)?.default_arguments?.[a.name])
64
71
  })),
65
72
  returns: {
66
73
  type: m.returns.type,
@@ -1 +1 @@
1
- {"version":3,"file":"app-spec.js","names":["hint","actions: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[]","actions","ABITypeClass"],"sources":["../../src/types/app-spec.ts"],"sourcesContent":["import {\n ABIMethod,\n ABIType as ABITypeClass,\n ARC28Event,\n Arc56Contract,\n Arc56Method,\n StorageKey,\n StructField,\n} from '@algorandfoundation/algokit-abi'\n\n/**\n * Converts an ARC-32 Application Specification to an ARC-56 Contract\n * @param appSpec The ARC-32 Application Specification\n * @returns The ARC-56 Contract\n * @example\n * ```typescript\n * const arc56AppSpec = arc32ToArc56(arc32AppSpec)\n * ```\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[getABIMethodParamsSignature(m)] 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) return undefined\n\n if (defaultArg.source === 'abi-method') {\n return {\n source: 'method',\n data: defaultArg.data.name,\n }\n }\n\n return {\n source: defaultArg.source === 'constant' ? 'literal' : defaultArg.source === 'global-state' ? 'global' : 'local',\n data: Buffer.from(\n typeof defaultArg.data === 'number' ? ABITypeClass.from('uint64').encode(defaultArg.data) : defaultArg.data,\n ).toString('base64'),\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\nfunction getABIMethodParamsSignature(params: ABIMethodParams) {\n const args = params.args.map((a) => a.type).join(',')\n return `${params.name}(${args})${params.returns.type}`\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\ninterface ABIContractParams {\n name: string\n desc?: string\n networks?: ABIContractNetworks\n methods: ABIMethodParams[]\n events?: ARC28Event[]\n}\n\ninterface ABIContractNetworks {\n [network: string]: ABIContractNetworkInfo\n}\n\ninterface ABIContractNetworkInfo {\n appID: number\n}\n\ninterface ABIMethodParams {\n name: string\n desc?: string\n args: ABIMethodArgParams[]\n returns: ABIMethodReturnParams\n /** Optional, is it a read-only method (according to [ARC-22](https://arc.algorand.foundation/ARCs/arc-0022)) */\n readonly?: boolean\n /** [ARC-28](https://arc.algorand.foundation/ARCs/arc-0028) events that MAY be emitted by this method */\n events?: ARC28Event[]\n}\n\ninterface ABIMethodArgParams {\n type: string\n name?: string\n desc?: string\n}\n\ninterface ABIMethodReturnParams {\n type: string\n desc?: string\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: ABIMethod\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"],"mappings":";;;;;;;;;;;;AAmBA,SAAgB,aAAa,SAAiC;CAC5D,MAAM,eAAe,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,GAAG,KAAK,QAAQ,CAAC,SAAS,SAAS;KACtD,SAAS;KACT,WAAW,EAAE,GAAG,SAAS,WAAW,cAAc;KAClD,MAAM,EAAE,GAAG;KACZ,CACF,CAAC,CACH;IACD,OAAO,OAAO,YACZ,OAAO,QAAQ,QAAQ,OAAO,MAAM,SAAS,CAAC,KAAK,MAAM,CACvD,EAAE,IACF;KACE,KAAK,OAAO,KAAK,EAAE,GAAG,KAAK,QAAQ,CAAC,SAAS,SAAS;KACtD,SAAS;KACT,WAAW,EAAE,GAAG,SAAS,WAAW,cAAc;KAClD,MAAM,EAAE,GAAG;KACZ,CACF,CAAC,CACH;IACD,KAAK,EAAE;IACR;GACD,MAAM;IACJ,QAAQ,EAAE;IACV,OAAO,EAAE;IACT,KAAK,EAAE;IACR;GACF;EACD,QAAQ,QAAQ;EAChB,aAAa;GACX,QAAQ,YAAY,SAAS;GAC7B,MAAM,YAAY,OAAO;GAC1B;EACD,UAAU;EACV,cAAc;EACd,QAAQ;EACR,UAAU;EACV,kBAAkB;EAClB,YAAY;EACZ,mBAAmB;EACpB;;AAGH,SAAS,4BAA4B,QAAyB;CAC5D,MAAM,OAAO,OAAO,KAAK,KAAK,MAAM,EAAE,KAAK,CAAC,KAAK,IAAI;AACrD,QAAO,GAAG,OAAO,KAAK,GAAG,KAAK,GAAG,OAAO,QAAQ"}
1
+ {"version":3,"file":"app-spec.js","names":["hint","actions: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[]","actions","defaultValueType: string | undefined","ABITypeClass"],"sources":["../../src/types/app-spec.ts"],"sourcesContent":["import {\n ABIMethod,\n ABIType as ABITypeClass,\n ARC28Event,\n Arc56Contract,\n Arc56Method,\n StorageKey,\n StructField,\n} from '@algorandfoundation/algokit-abi'\n\n/**\n * Converts an ARC-32 Application Specification to an ARC-56 Contract\n * @param appSpec The ARC-32 Application Specification\n * @returns The ARC-56 Contract\n * @example\n * ```typescript\n * const arc56AppSpec = arc32ToArc56(arc32AppSpec)\n * ```\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[getABIMethodParamsSignature(m)] 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 = (defaultArg: DefaultArgument | undefined): Arc56Contract['methods'][0]['args'][0]['defaultValue'] => {\n if (!defaultArg) return undefined\n\n if (defaultArg.source === 'abi-method') {\n return {\n source: 'method',\n data: defaultArg.data.name,\n }\n }\n\n const mappedSource = defaultArg.source === 'constant' ? 'literal' : defaultArg.source === 'global-state' ? 'global' : 'local'\n\n // type is only set for literal source\n let defaultValueType: string | undefined = undefined\n if (mappedSource === 'literal') {\n if (typeof defaultArg.data === 'number') {\n defaultValueType = 'uint64'\n } else if (typeof defaultArg.data === 'string') {\n defaultValueType = 'AVMString'\n }\n }\n\n const argData =\n typeof defaultArg.data === 'number'\n ? ABITypeClass.from('uint64').encode(defaultArg.data)\n : typeof defaultArg.data === 'string'\n ? new TextEncoder().encode(defaultArg.data)\n : defaultArg.data\n\n return {\n source: mappedSource,\n data: Buffer.from(argData).toString('base64'),\n type: defaultValueType,\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.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\nfunction getABIMethodParamsSignature(params: ABIMethodParams) {\n const args = params.args.map((a) => a.type).join(',')\n return `${params.name}(${args})${params.returns.type}`\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\ninterface ABIContractParams {\n name: string\n desc?: string\n networks?: ABIContractNetworks\n methods: ABIMethodParams[]\n events?: ARC28Event[]\n}\n\ninterface ABIContractNetworks {\n [network: string]: ABIContractNetworkInfo\n}\n\ninterface ABIContractNetworkInfo {\n appID: number\n}\n\ninterface ABIMethodParams {\n name: string\n desc?: string\n args: ABIMethodArgParams[]\n returns: ABIMethodReturnParams\n /** Optional, is it a read-only method (according to [ARC-22](https://arc.algorand.foundation/ARCs/arc-0022)) */\n readonly?: boolean\n /** [ARC-28](https://arc.algorand.foundation/ARCs/arc-0028) events that MAY be emitted by this method */\n events?: ARC28Event[]\n}\n\ninterface ABIMethodArgParams {\n type: string\n name?: string\n desc?: string\n}\n\ninterface ABIMethodReturnParams {\n type: string\n desc?: string\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: ABIMethod\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"],"mappings":";;;;;;;;;;;;AAmBA,SAAgB,aAAa,SAAiC;CAC5D,MAAM,eAAe,OAAO,OAAO,QAAQ,MAAM,CAAC,SAAS,WAAS,OAAO,QAAQA,OAAK,WAAW,EAAE,CAAC,CAAC;CACvG,MAAM,UAAU,OAAO,YACrB,aAAa,KAAK,CAAC,GAAG,YAAY;EAChC,MAAM,SAAS,OAAO,SAAS,KAAK,OAAO;GAAE,MAAM,EAAE;GAAI,MAAM,EAAE;GAAI,EAAE;AACvE,SAAO,CAAC,OAAO,MAAM,OAAO;GAC5B,CACH;CACD,MAAM,QAAQ,MAAuB,QAAQ,MAAM,4BAA4B,EAAE;CACjF,MAAM,WAAW,GAAoB,SAA4B;AAE/D,SAAO,KAAK,EAAE,EAAE,gBAAgB,SAAY,oBAAoB,KAAK,EAAE,EAAE,aAAc,KAAK,GAAG,EAAE;;CAEnG,MAAM,eAAe,SAA4B;AAC/C,SAAO,oBAAo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KACT,WAAW,EAAE,GAAG,SAAS,WAAW,cAAc;KAClD,MAAM,EAAE,GAAG;KACZ,CACF,CAAC,CACH;IACD,KAAK,EAAE;IACR;GACD,MAAM;IACJ,QAAQ,EAAE;IACV,OAAO,EAAE;IACT,KAAK,EAAE;IACR;GACF;EACD,QAAQ,QAAQ;EAChB,aAAa;GACX,QAAQ,YAAY,SAAS;GAC7B,MAAM,YAAY,OAAO;GAC1B;EACD,UAAU;EACV,cAAc;EACd,QAAQ;EACR,UAAU;EACV,kBAAkB;EAClB,YAAY;EACZ,mBAAmB;EACpB;;AAGH,SAAS,4BAA4B,QAAyB;CAC5D,MAAM,OAAO,OAAO,KAAK,KAAK,MAAM,EAAE,KAAK,CAAC,KAAK,IAAI;AACrD,QAAO,GAAG,OAAO,KAAK,GAAG,KAAK,GAAG,OAAO,QAAQ"}
@@ -35,16 +35,23 @@ function arc32ToArc56(appSpec) {
35
35
  if (c.update_application && ["ALL", type].includes(c.update_application)) actions$1.push("UpdateApplication");
36
36
  return actions$1;
37
37
  };
38
- const getDefaultArgValue = (type, defaultArg) => {
38
+ const getDefaultArgValue = (defaultArg) => {
39
39
  if (!defaultArg) return void 0;
40
40
  if (defaultArg.source === "abi-method") return {
41
41
  source: "method",
42
42
  data: defaultArg.data.name
43
43
  };
44
+ const mappedSource = defaultArg.source === "constant" ? "literal" : defaultArg.source === "global-state" ? "global" : "local";
45
+ let defaultValueType = void 0;
46
+ if (mappedSource === "literal") {
47
+ if (typeof defaultArg.data === "number") defaultValueType = "uint64";
48
+ else if (typeof defaultArg.data === "string") defaultValueType = "AVMString";
49
+ }
50
+ const argData = typeof defaultArg.data === "number" ? ABIType.from("uint64").encode(defaultArg.data) : typeof defaultArg.data === "string" ? new TextEncoder().encode(defaultArg.data) : defaultArg.data;
44
51
  return {
45
- source: defaultArg.source === "constant" ? "literal" : defaultArg.source === "global-state" ? "global" : "local",
46
- data: Buffer.from(typeof defaultArg.data === "number" ? ABIType.from("uint64").encode(defaultArg.data) : defaultArg.data).toString("base64"),
47
- type: type === "string" ? "AVMString" : type
52
+ source: mappedSource,
53
+ data: Buffer.from(argData).toString("base64"),
54
+ type: defaultValueType
48
55
  };
49
56
  };
50
57
  return {
@@ -60,7 +67,7 @@ function arc32ToArc56(appSpec) {
60
67
  type: a.type,
61
68
  desc: a.desc,
62
69
  struct: a.name ? hint(m)?.structs?.[a.name]?.name : void 0,
63
- defaultValue: getDefaultArgValue(a.type, !a.name ? void 0 : hint(m)?.default_arguments?.[a.name])
70
+ defaultValue: getDefaultArgValue(!a.name ? void 0 : hint(m)?.default_arguments?.[a.name])
64
71
  })),
65
72
  returns: {
66
73
  type: m.returns.type,
@@ -1 +1 @@
1
- {"version":3,"file":"app-spec.mjs","names":["hint","actions: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[]","actions","ABITypeClass"],"sources":["../../src/types/app-spec.ts"],"sourcesContent":["import {\n ABIMethod,\n ABIType as ABITypeClass,\n ARC28Event,\n Arc56Contract,\n Arc56Method,\n StorageKey,\n StructField,\n} from '@algorandfoundation/algokit-abi'\n\n/**\n * Converts an ARC-32 Application Specification to an ARC-56 Contract\n * @param appSpec The ARC-32 Application Specification\n * @returns The ARC-56 Contract\n * @example\n * ```typescript\n * const arc56AppSpec = arc32ToArc56(arc32AppSpec)\n * ```\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[getABIMethodParamsSignature(m)] 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) return undefined\n\n if (defaultArg.source === 'abi-method') {\n return {\n source: 'method',\n data: defaultArg.data.name,\n }\n }\n\n return {\n source: defaultArg.source === 'constant' ? 'literal' : defaultArg.source === 'global-state' ? 'global' : 'local',\n data: Buffer.from(\n typeof defaultArg.data === 'number' ? ABITypeClass.from('uint64').encode(defaultArg.data) : defaultArg.data,\n ).toString('base64'),\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\nfunction getABIMethodParamsSignature(params: ABIMethodParams) {\n const args = params.args.map((a) => a.type).join(',')\n return `${params.name}(${args})${params.returns.type}`\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\ninterface ABIContractParams {\n name: string\n desc?: string\n networks?: ABIContractNetworks\n methods: ABIMethodParams[]\n events?: ARC28Event[]\n}\n\ninterface ABIContractNetworks {\n [network: string]: ABIContractNetworkInfo\n}\n\ninterface ABIContractNetworkInfo {\n appID: number\n}\n\ninterface ABIMethodParams {\n name: string\n desc?: string\n args: ABIMethodArgParams[]\n returns: ABIMethodReturnParams\n /** Optional, is it a read-only method (according to [ARC-22](https://arc.algorand.foundation/ARCs/arc-0022)) */\n readonly?: boolean\n /** [ARC-28](https://arc.algorand.foundation/ARCs/arc-0028) events that MAY be emitted by this method */\n events?: ARC28Event[]\n}\n\ninterface ABIMethodArgParams {\n type: string\n name?: string\n desc?: string\n}\n\ninterface ABIMethodReturnParams {\n type: string\n desc?: string\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: ABIMethod\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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AAQ,QAAQ,OAAO,OAAO,SAAS,CAAC,KAAK,MAAM,CACxD,EAAE,IACF;KACE,KAAK,OAAO,KAAK,EAAE,GAAG,KAAK,QAAQ,CAAC,SAAS,SAAS;KACtD,SAAS;KACT,WAAW,EAAE,GAAG,SAAS,WAAW,cAAc;KAClD,MAAM,EAAE,GAAG;KACZ,CACF,CAAC,CACH;IACD,OAAO,OAAO,YACZ,OAAO,QAAQ,QAAQ,OAAO,MAAM,SAAS,CAAC,KAAK,MAAM,CACvD,EAAE,IACF;KACE,KAAK,OAAO,KAAK,EAAE,GAAG,KAAK,QAAQ,CAAC,SAAS,SAAS;KACtD,SAAS;KACT,WAAW,EAAE,GAAG,SAAS,WAAW,cAAc;KAClD,MAAM,EAAE,GAAG;KACZ,CACF,CAAC,CACH;IACD,KAAK,EAAE;IACR;GACD,MAAM;IACJ,QAAQ,EAAE;IACV,OAAO,EAAE;IACT,KAAK,EAAE;IACR;GACF;EACD,QAAQ,QAAQ;EAChB,aAAa;GACX,QAAQ,YAAY,SAAS;GAC7B,MAAM,YAAY,OAAO;GAC1B;EACD,UAAU;EACV,cAAc;EACd,QAAQ;EACR,UAAU;EACV,kBAAkB;EAClB,YAAY;EACZ,mBAAmB;EACpB;;AAGH,SAAS,4BAA4B,QAAyB;CAC5D,MAAM,OAAO,OAAO,KAAK,KAAK,MAAM,EAAE,KAAK,CAAC,KAAK,IAAI;AACrD,QAAO,GAAG,OAAO,KAAK,GAAG,KAAK,GAAG,OAAO,QAAQ"}
1
+ {"version":3,"file":"app-spec.mjs","names":["hint","actions: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[]","actions","defaultValueType: string | undefined","ABITypeClass"],"sources":["../../src/types/app-spec.ts"],"sourcesContent":["import {\n ABIMethod,\n ABIType as ABITypeClass,\n ARC28Event,\n Arc56Contract,\n Arc56Method,\n StorageKey,\n StructField,\n} from '@algorandfoundation/algokit-abi'\n\n/**\n * Converts an ARC-32 Application Specification to an ARC-56 Contract\n * @param appSpec The ARC-32 Application Specification\n * @returns The ARC-56 Contract\n * @example\n * ```typescript\n * const arc56AppSpec = arc32ToArc56(arc32AppSpec)\n * ```\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[getABIMethodParamsSignature(m)] 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 = (defaultArg: DefaultArgument | undefined): Arc56Contract['methods'][0]['args'][0]['defaultValue'] => {\n if (!defaultArg) return undefined\n\n if (defaultArg.source === 'abi-method') {\n return {\n source: 'method',\n data: defaultArg.data.name,\n }\n }\n\n const mappedSource = defaultArg.source === 'constant' ? 'literal' : defaultArg.source === 'global-state' ? 'global' : 'local'\n\n // type is only set for literal source\n let defaultValueType: string | undefined = undefined\n if (mappedSource === 'literal') {\n if (typeof defaultArg.data === 'number') {\n defaultValueType = 'uint64'\n } else if (typeof defaultArg.data === 'string') {\n defaultValueType = 'AVMString'\n }\n }\n\n const argData =\n typeof defaultArg.data === 'number'\n ? ABITypeClass.from('uint64').encode(defaultArg.data)\n : typeof defaultArg.data === 'string'\n ? new TextEncoder().encode(defaultArg.data)\n : defaultArg.data\n\n return {\n source: mappedSource,\n data: Buffer.from(argData).toString('base64'),\n type: defaultValueType,\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.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\nfunction getABIMethodParamsSignature(params: ABIMethodParams) {\n const args = params.args.map((a) => a.type).join(',')\n return `${params.name}(${args})${params.returns.type}`\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\ninterface ABIContractParams {\n name: string\n desc?: string\n networks?: ABIContractNetworks\n methods: ABIMethodParams[]\n events?: ARC28Event[]\n}\n\ninterface ABIContractNetworks {\n [network: string]: ABIContractNetworkInfo\n}\n\ninterface ABIContractNetworkInfo {\n appID: number\n}\n\ninterface ABIMethodParams {\n name: string\n desc?: string\n args: ABIMethodArgParams[]\n returns: ABIMethodReturnParams\n /** Optional, is it a read-only method (according to [ARC-22](https://arc.algorand.foundation/ARCs/arc-0022)) */\n readonly?: boolean\n /** [ARC-28](https://arc.algorand.foundation/ARCs/arc-0028) events that MAY be emitted by this method */\n events?: ARC28Event[]\n}\n\ninterface ABIMethodArgParams {\n type: string\n name?: string\n desc?: string\n}\n\ninterface ABIMethodReturnParams {\n type: string\n desc?: string\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: ABIMethod\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"],"mappings":";;;;;;;;;;;;AAmBA,SAAgB,aAAa,SAAiC;CAC5D,MAAM,eAAe,OAAO,OAAO,QAAQ,MAAM,CAAC,SAAS,WAAS,OAAO,QAAQA,OAAK,WAAW,EAAE,CAAC,CAAC;CACvG,MAAM,UAAU,OAAO,YACrB,aAAa,KAAK,CAAC,GAAG,YAAY;EAChC,MAAM,SAAS,OAAO,SAAS,KAAK,OAAO;GAAE,MAAM,EAAE;GAAI,MAAM,EAAE;GAAI,EAAE;AACvE,SAAO,CAAC,OAAO,MAAM,OAAO;GAC5B,CACH;CACD,MAAM,QAAQ,MAAuB,QAAQ,MAAM,4BAA4B,EAAE;CACjF,MAAM,WAAW,GAAoB,SAA4B;AAE/D,SAAO,KAAK,EAAE,EAAE,gBAAgB,SAAY,o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