@algorandfoundation/puya-ts 1.0.0-beta.2 → 1.0.0-beta.4

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.
@@ -1,4 +1,4 @@
1
- import type { SourceLocation } from '../../../awst/source-location';
1
+ import { SourceLocation } from '../../../awst/source-location';
2
2
  import type { PType } from '../../ptypes';
3
3
  import type { NodeBuilder } from '../index';
4
4
  import { FunctionBuilder } from '../index';
@@ -29,8 +29,8 @@ export declare class ARC4InstanceType extends ARC4EncodedType {
29
29
  }
30
30
  export declare const ARC4BoolClass: LibClassType;
31
31
  export declare const ARC4StrClass: LibClassType;
32
- export declare const ARC4BooleanType: ARC4InstanceType;
33
- export declare const ARC4StringType: ARC4InstanceType;
32
+ export declare const arc4BooleanType: ARC4InstanceType;
33
+ export declare const arc4StringType: ARC4InstanceType;
34
34
  export declare class ARC4StructClass extends PType {
35
35
  readonly name: string;
36
36
  readonly module: string;
package/bin/run-cli.mjs CHANGED
@@ -6,13 +6,14 @@ import 'zod';
6
6
  import 'glob';
7
7
  import 'node:fs';
8
8
  import 'upath';
9
- import '../index-D4-4PUG7.js';
9
+ import '../index-Cg8BBwmU.js';
10
10
  import 'change-case';
11
11
  import 'node:path';
12
12
  import 'typescript';
13
13
  import 'node:buffer';
14
14
  import 'node:util';
15
15
  import 'polytype';
16
+ import 'arcsecond';
16
17
  import 'crypto';
17
18
  import 'fs';
18
19
  import 'os';
@@ -1 +1 @@
1
- {"version":3,"file":"run-cli.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"run-cli.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
package/cli.mjs CHANGED
@@ -4,7 +4,7 @@ import { z } from 'zod';
4
4
  import { globSync } from 'glob';
5
5
  import * as fs from 'node:fs';
6
6
  import upath from 'upath';
7
- import { n as normalisePath, l as logger, P as PuyaError, L as LoggingContext, a as LogLevel, b as LocalsCoalescingStrategy, d as defaultPuyaOptions, c as compile } from './index-D4-4PUG7.js';
7
+ import { n as normalisePath, l as logger, P as PuyaError, L as LoggingContext, a as LogLevel, b as LocalsCoalescingStrategy, d as defaultPuyaOptions, c as compile } from './index-Cg8BBwmU.js';
8
8
  import chalk from 'chalk';
9
9
  import 'change-case';
10
10
  import 'node:path';
@@ -12,6 +12,7 @@ import 'typescript';
12
12
  import 'node:buffer';
13
13
  import 'node:util';
14
14
  import 'polytype';
15
+ import 'arcsecond';
15
16
  import 'crypto';
16
17
  import 'fs';
17
18
  import 'os';
@@ -166,7 +167,7 @@ function cli() {
166
167
  .addOption(new Option('--optimization-level [level]', 'Set optimization level of output TEAL / AVM bytecode')
167
168
  .choices(['0', '1', '2'])
168
169
  .default(defaultPuyaOptions.optimizationLevel))
169
- .addOption(new Option('--target-avm-version [version]', '').choices(['10']).default(10))
170
+ .addOption(new Option('--target-avm-version [version]', '').choices(['10', '11']).default(10))
170
171
  .addOption(new Option('--cli-template-definitions <...definitions>', 'Define template vars for use when assembling via --output-bytecode, should be specified without the prefix (see --template-vars-prefix)'))
171
172
  .addOption(new Option('--template-vars-prefix [prefix]', 'Define the prefix to use with --template-var').default(defaultPuyaOptions.templateVarsPrefix))
172
173
  .addOption(new Option('--locals-coalescing-strategy', '')
package/cli.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.mjs","sources":["../src/compile-options.ts","../src/logger/sinks/console-log-sink.ts","../src/cli.ts"],"sourcesContent":["import { globSync } from 'glob'\nimport * as fs from 'node:fs'\nimport upath from 'upath'\nimport { PuyaError } from './errors'\nimport type { LogLevel } from './logger'\nimport { logger } from './logger'\nimport { normalisePath } from './util'\n\nexport interface AlgoFile {\n matchedInput: string\n sourceFile: string\n outDir: string\n}\n\nexport interface CompileOptions {\n filePaths: AlgoFile[]\n logLevel: LogLevel\n outputAwst: boolean\n outputAwstJson: boolean\n /*\n Don't generate artifacts for puya, or invoke puya\n */\n dryRun: boolean\n\n getFileFromSource(sourceFile: string): AlgoFile | undefined\n}\n\nexport const buildCompileOptions = ({\n paths,\n workingDirectory = process.cwd(),\n outDir,\n ...rest\n}: {\n paths: string[]\n outputAwst: boolean\n outDir: string\n outputAwstJson: boolean\n workingDirectory?: string\n dryRun: boolean\n logLevel: LogLevel\n}): CompileOptions => {\n const filePaths: AlgoFile[] = []\n\n for (const p of paths) {\n if (p.endsWith('.algo.ts')) {\n if (fs.existsSync(p)) {\n const actualPath = normalisePath(p, workingDirectory)\n\n filePaths.push({\n matchedInput: p,\n sourceFile: actualPath,\n outDir: upath.isAbsolute(outDir) ? upath.normalize(outDir) : upath.join(upath.dirname(actualPath), outDir),\n })\n } else {\n logger.warn(undefined, `File ${p} could not be found`)\n }\n } else if (p.endsWith('.ts')) {\n logger.warn(undefined, `Ignoring path ${p} as it does use the .algo.ts extension`)\n } else {\n const matches = globSync(upath.join(p, '**/*.algo.ts'))\n if (matches.length) {\n for (const match of matches) {\n filePaths.push({\n matchedInput: p,\n sourceFile: normalisePath(match, workingDirectory),\n outDir: upath.join(upath.isAbsolute(outDir) ? outDir : upath.join(p, outDir), upath.relative(p, upath.dirname(match))),\n })\n }\n } else {\n logger.warn(undefined, `Path '${p}' did not match any .algo.ts files`)\n }\n }\n }\n if (filePaths.length === 0) {\n throw new PuyaError('Input paths did not match any .algo.ts files')\n }\n\n return {\n filePaths: filePaths.map(replaceOutDirTokens),\n ...rest,\n getFileFromSource(sourceFile: string): AlgoFile | undefined {\n return this.filePaths.find((p) => p.sourceFile === sourceFile)\n },\n }\n}\n\nfunction replaceOutDirTokens(algoFile: AlgoFile): AlgoFile {\n const replacements = {\n name: upath.basename(algoFile.sourceFile).replace('.algo.ts', ''),\n }\n\n return {\n ...algoFile,\n outDir: algoFile.outDir.replaceAll('[name]', replacements.name),\n }\n}\n","import chalk from 'chalk'\nimport type { SourceLocation } from '../../awst/source-location'\nimport type { LogEvent, LogLevel } from '../index'\nimport { LoggingContext } from '../index'\nimport type { LogSink } from './index'\n\ntype ColorFn = (text: string) => string\nconst levelConfig: Record<LogEvent['level'], { colorFn: ColorFn; writeFn: (...args: unknown[]) => void }> = {\n /* eslint-disable no-console */\n debug: { colorFn: chalk.green, writeFn: console.debug },\n info: { colorFn: chalk.green, writeFn: console.info },\n warning: { colorFn: chalk.yellow, writeFn: console.warn },\n error: { colorFn: chalk.red, writeFn: console.error },\n critical: { colorFn: chalk.red, writeFn: console.error },\n /* eslint-enable no-console */\n}\n\nexport class ConsoleLogSink implements LogSink {\n constructor(public readonly minLogLevel: LogLevel) {}\n\n add(logEvent: LogEvent): void {\n const config = levelConfig[logEvent.level]\n\n let logText = `${config.colorFn(logEvent.level)}: ${logEvent.message}`\n if (logEvent.sourceLocation) {\n const sourceLocationText = logEvent.sourceLocation.toString()\n const indentSize = sourceLocationText.length + logEvent.level.length + 4\n\n logText = `${sourceLocationText} ${logText}${this.getSourceSummary(logEvent.sourceLocation, indentSize)}`\n }\n config.writeFn(logText)\n }\n\n getSourceSummary(sourceLocation: SourceLocation, indent: number): string {\n const sourceFile = sourceLocation.file && LoggingContext.current.sourcesByPath[sourceLocation.file]\n if (!sourceFile || sourceLocation.scope === 'file') return ''\n\n const line = sourceFile[sourceLocation.line - 1]\n const trimmedLine = line.trimStart()\n const marker = `${''.padStart(sourceLocation.column - (line.length - trimmedLine.length))}^${''.padStart(Math.max(sourceLocation.endColumn - sourceLocation.column - 1, 0), '~')}`\n const indentChars = ''.padStart(indent, ' ')\n return `\\n${indentChars}${trimmedLine}\\n${indentChars}${marker}`\n }\n}\n","import { Command, Option } from 'commander'\nimport { z } from 'zod'\nimport { buildCompileOptions } from './compile-options'\nimport { compile } from './index'\nimport { logger, LoggingContext, LogLevel } from './logger'\nimport { ConsoleLogSink } from './logger/sinks/console-log-sink'\nimport type { PuyaPassThroughOptions } from './puya/options'\nimport { defaultPuyaOptions, LocalsCoalescingStrategy } from './puya/options'\n\nconst cmdInteger = () => z.preprocess((x) => (typeof x === 'string' && x.length > 0 ? Number(x) : x), z.number().int())\n\nconst cliOptionsSchema = z.object({\n outputAwst: z.boolean(),\n outputAwstJson: z.boolean(),\n outDir: z.string(),\n dryRun: z.boolean(),\n logLevel: z.nativeEnum(LogLevel),\n isolatedFiles: z.boolean(),\n\n // Puya options\n outputSourceMap: z.boolean(),\n outputTeal: z.boolean(),\n outputArc32: z.boolean(),\n outputArc56: z.boolean(),\n outputSsaIr: z.boolean(),\n outputOptimizationIr: z.boolean(),\n outputDestructuredIr: z.boolean(),\n outputMemoryIr: z.boolean(),\n outputBytecode: z.boolean(),\n matchAlgodBytecode: z.boolean(),\n debugLevel: cmdInteger(),\n optimizationLevel: cmdInteger(),\n targetAvmVersion: cmdInteger(),\n cliTemplateDefinitions: z.preprocess((x) => x ?? [], z.array(z.string())),\n templateVarsPrefix: z.string(),\n localsCoalescingStrategy: z.nativeEnum(LocalsCoalescingStrategy),\n})\n\nconst cliArgumentsSchema = z.array(z.string())\n\nfunction cli() {\n const commander = new Command().name('puya-ts').description('Algo-TS to Algorand smart contract compiler')\n\n commander.helpCommand(true)\n\n commander\n .command('build')\n .argument('<paths...>', 'The path, or paths to search for compatible .algo.ts files')\n .addOption(\n new Option('--log-level [level]', 'The minimum log level to output')\n .choices([LogLevel.Debug, LogLevel.Info, LogLevel.Warning, LogLevel.Error, LogLevel.Critical])\n .default(LogLevel.Info),\n )\n .addOption(new Option('--output-awst', 'Output debugging awst file per parsed file').default(false))\n .addOption(new Option('--output-awst-json', 'Output debugging awst json file per parsed file').default(false))\n .addOption(new Option('--out-dir [outDir]').default('out'))\n .addOption(new Option('--dry-run', \"Just parse typescript files, don't invoke puya compiler\").default(false))\n .addOption(new Option('--isolated-files', 'Invoke compilation on each input file individually').default(false))\n .addOption(new Option('--no-output-teal', 'Do not output TEAL code').default(defaultPuyaOptions.outputTeal))\n .addOption(new Option('--output-source-map', 'Output debug source maps ').default(defaultPuyaOptions.outputSourceMap))\n .addOption(\n new Option(\n '--no-output-arc32',\n 'Do not output {contract}.arc32.json ARC-32 app spec file. Only applicable to ARC4 contracts',\n ).default(defaultPuyaOptions.outputArc32),\n )\n .addOption(\n new Option('--output-arc56', 'Output {contract}.arc56.json ARC-56 app spec file. Only applicable to ARC4 contracts').default(\n defaultPuyaOptions.outputArc56,\n ),\n )\n .addOption(new Option('--output-ssa-ir', 'Output IR (in SSA form) before optimisations').default(defaultPuyaOptions.outputSsaIr))\n .addOption(new Option('--output-optimization-ir', 'Output IR after each optimization').default(defaultPuyaOptions.outputOptimizationIr))\n .addOption(\n new Option('--output-destructured-ir', 'Output IR after SSA destructuring and before MIR').default(\n defaultPuyaOptions.outputDestructuredIr,\n ),\n )\n .addOption(new Option('--output-memory-ir', 'Output MIR before lowering to TealOps').default(defaultPuyaOptions.outputMemoryIr))\n .addOption(new Option('--output-bytecode', 'Output AVM bytecode').default(defaultPuyaOptions.outputBytecode))\n .addOption(\n new Option('--match-algod-bytecode', 'When outputting bytecode, ensure bytecode matches algod output').default(\n defaultPuyaOptions.matchAlgodBytecode,\n ),\n )\n .addOption(\n new Option('--debug-level [level]', 'Output debug information level, 0 = none, 1 = debug, 2 = reserved for future use')\n .choices(['0', '1', '2'])\n .default(defaultPuyaOptions.debugLevel),\n )\n .addOption(\n new Option('--optimization-level [level]', 'Set optimization level of output TEAL / AVM bytecode')\n .choices(['0', '1', '2'])\n .default(defaultPuyaOptions.optimizationLevel),\n )\n .addOption(new Option('--target-avm-version [version]', '').choices(['10']).default(10))\n .addOption(\n new Option(\n '--cli-template-definitions <...definitions>',\n 'Define template vars for use when assembling via --output-bytecode, should be specified without the prefix (see --template-vars-prefix)',\n ),\n )\n .addOption(\n new Option('--template-vars-prefix [prefix]', 'Define the prefix to use with --template-var').default(\n defaultPuyaOptions.templateVarsPrefix,\n ),\n )\n .addOption(\n new Option('--locals-coalescing-strategy', '')\n .default(defaultPuyaOptions.localsCoalescingStrategy)\n .choices([\n LocalsCoalescingStrategy.root_operand,\n LocalsCoalescingStrategy.root_operand_excluding_args,\n LocalsCoalescingStrategy.aggressive,\n ]),\n )\n\n .action((a, o) => {\n using logCtx = LoggingContext.create()\n logger.configure([new ConsoleLogSink(LogLevel.Warning)])\n try {\n const paths = cliArgumentsSchema.parse(a)\n const cliOptions = cliOptionsSchema.parse(o)\n logger.configure([new ConsoleLogSink(cliOptions.logLevel)])\n const compileOptions = buildCompileOptions({\n paths,\n ...cliOptions,\n })\n const passThroughOptions: PuyaPassThroughOptions = cliOptions\n\n if (cliOptions.isolatedFiles) {\n let anyHasErrors = false\n for (const file of compileOptions.filePaths) {\n using logCtx = LoggingContext.create()\n try {\n compile(\n {\n ...compileOptions,\n filePaths: [file],\n },\n passThroughOptions,\n )\n } catch (e) {\n logger.critical(undefined, `Compilation failure: ${e}`)\n }\n anyHasErrors ||= logCtx.hasErrors()\n }\n if (anyHasErrors) {\n process.exit(-1)\n }\n } else {\n compile(compileOptions, passThroughOptions)\n logCtx.exitIfErrors()\n }\n } catch (e) {\n if (e instanceof Error) {\n logger.error(e)\n } else {\n throw e\n }\n }\n })\n\n if (process.argv.length < 3) {\n commander.help()\n } else {\n commander.parse(process.argv)\n }\n}\ncli()\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AA2BO,MAAM,mBAAmB,GAAG,CAAC,EAClC,KAAK,EACL,gBAAgB,GAAG,OAAO,CAAC,GAAG,EAAE,EAChC,MAAM,EACN,GAAG,IAAI,EASR,KAAoB;IACnB,MAAM,SAAS,GAAe,EAAE;AAEhC,IAAA,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;AACrB,QAAA,IAAI,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;AAC1B,YAAA,IAAI,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;gBACpB,MAAM,UAAU,GAAG,aAAa,CAAC,CAAC,EAAE,gBAAgB,CAAC;gBAErD,SAAS,CAAC,IAAI,CAAC;AACb,oBAAA,YAAY,EAAE,CAAC;AACf,oBAAA,UA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pC;oBACD,IAAI,YAAY,EAAE;AAChB,wBAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;;;qBAEb;AACL,oBAAA,OAAO,CAAC,cAAc,EAAE,kBAAkB,CAAC;oBAC3C,MAAM,CAAC,YAAY,EAAE;;;YAEvB,OAAO,CAAC,EAAE;AACV,gBAAA,IAAI,CAAC,YAAY,KAAK,EAAE;AACtB,oBAAA,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;;qBACV;AACL,oBAAA,MAAM,CAAC;;;;;;;;;;;AAGZ,KAAA,CAAC;IAEJ,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;QAC3B,SAAS,CAAC,IAAI,EAAE;;SACX;AACL,QAAA,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;;AAEjC;AACA,GAAG,EAAE"}
1
+ {"version":3,"file":"cli.mjs","sources":["../src/compile-options.ts","../src/logger/sinks/console-log-sink.ts","../src/cli.ts"],"sourcesContent":["import { globSync } from 'glob'\nimport * as fs from 'node:fs'\nimport upath from 'upath'\nimport { PuyaError } from './errors'\nimport type { LogLevel } from './logger'\nimport { logger } from './logger'\nimport { normalisePath } from './util'\n\nexport interface AlgoFile {\n matchedInput: string\n sourceFile: string\n outDir: string\n}\n\nexport interface CompileOptions {\n filePaths: AlgoFile[]\n logLevel: LogLevel\n outputAwst: boolean\n outputAwstJson: boolean\n /*\n Don't generate artifacts for puya, or invoke puya\n */\n dryRun: boolean\n\n getFileFromSource(sourceFile: string): AlgoFile | undefined\n}\n\nexport const buildCompileOptions = ({\n paths,\n workingDirectory = process.cwd(),\n outDir,\n ...rest\n}: {\n paths: string[]\n outputAwst: boolean\n outDir: string\n outputAwstJson: boolean\n workingDirectory?: string\n dryRun: boolean\n logLevel: LogLevel\n}): CompileOptions => {\n const filePaths: AlgoFile[] = []\n\n for (const p of paths) {\n if (p.endsWith('.algo.ts')) {\n if (fs.existsSync(p)) {\n const actualPath = normalisePath(p, workingDirectory)\n\n filePaths.push({\n matchedInput: p,\n sourceFile: actualPath,\n outDir: upath.isAbsolute(outDir) ? upath.normalize(outDir) : upath.join(upath.dirname(actualPath), outDir),\n })\n } else {\n logger.warn(undefined, `File ${p} could not be found`)\n }\n } else if (p.endsWith('.ts')) {\n logger.warn(undefined, `Ignoring path ${p} as it does use the .algo.ts extension`)\n } else {\n const matches = globSync(upath.join(p, '**/*.algo.ts'))\n if (matches.length) {\n for (const match of matches) {\n filePaths.push({\n matchedInput: p,\n sourceFile: normalisePath(match, workingDirectory),\n outDir: upath.join(upath.isAbsolute(outDir) ? outDir : upath.join(p, outDir), upath.relative(p, upath.dirname(match))),\n })\n }\n } else {\n logger.warn(undefined, `Path '${p}' did not match any .algo.ts files`)\n }\n }\n }\n if (filePaths.length === 0) {\n throw new PuyaError('Input paths did not match any .algo.ts files')\n }\n\n return {\n filePaths: filePaths.map(replaceOutDirTokens),\n ...rest,\n getFileFromSource(sourceFile: string): AlgoFile | undefined {\n return this.filePaths.find((p) => p.sourceFile === sourceFile)\n },\n }\n}\n\nfunction replaceOutDirTokens(algoFile: AlgoFile): AlgoFile {\n const replacements = {\n name: upath.basename(algoFile.sourceFile).replace('.algo.ts', ''),\n }\n\n return {\n ...algoFile,\n outDir: algoFile.outDir.replaceAll('[name]', replacements.name),\n }\n}\n","import chalk from 'chalk'\nimport type { SourceLocation } from '../../awst/source-location'\nimport type { LogEvent, LogLevel } from '../index'\nimport { LoggingContext } from '../index'\nimport type { LogSink } from './index'\n\ntype ColorFn = (text: string) => string\nconst levelConfig: Record<LogEvent['level'], { colorFn: ColorFn; writeFn: (...args: unknown[]) => void }> = {\n /* eslint-disable no-console */\n debug: { colorFn: chalk.green, writeFn: console.debug },\n info: { colorFn: chalk.green, writeFn: console.info },\n warning: { colorFn: chalk.yellow, writeFn: console.warn },\n error: { colorFn: chalk.red, writeFn: console.error },\n critical: { colorFn: chalk.red, writeFn: console.error },\n /* eslint-enable no-console */\n}\n\nexport class ConsoleLogSink implements LogSink {\n constructor(public readonly minLogLevel: LogLevel) {}\n\n add(logEvent: LogEvent): void {\n const config = levelConfig[logEvent.level]\n\n let logText = `${config.colorFn(logEvent.level)}: ${logEvent.message}`\n if (logEvent.sourceLocation) {\n const sourceLocationText = logEvent.sourceLocation.toString()\n const indentSize = sourceLocationText.length + logEvent.level.length + 4\n\n logText = `${sourceLocationText} ${logText}${this.getSourceSummary(logEvent.sourceLocation, indentSize)}`\n }\n config.writeFn(logText)\n }\n\n getSourceSummary(sourceLocation: SourceLocation, indent: number): string {\n const sourceFile = sourceLocation.file && LoggingContext.current.sourcesByPath[sourceLocation.file]\n if (!sourceFile || sourceLocation.scope === 'file') return ''\n\n const line = sourceFile[sourceLocation.line - 1]\n const trimmedLine = line.trimStart()\n const marker = `${''.padStart(sourceLocation.column - (line.length - trimmedLine.length))}^${''.padStart(Math.max(sourceLocation.endColumn - sourceLocation.column - 1, 0), '~')}`\n const indentChars = ''.padStart(indent, ' ')\n return `\\n${indentChars}${trimmedLine}\\n${indentChars}${marker}`\n }\n}\n","import { Command, Option } from 'commander'\nimport { z } from 'zod'\nimport { buildCompileOptions } from './compile-options'\nimport { compile } from './index'\nimport { logger, LoggingContext, LogLevel } from './logger'\nimport { ConsoleLogSink } from './logger/sinks/console-log-sink'\nimport type { PuyaPassThroughOptions } from './puya/options'\nimport { defaultPuyaOptions, LocalsCoalescingStrategy } from './puya/options'\n\nconst cmdInteger = () => z.preprocess((x) => (typeof x === 'string' && x.length > 0 ? Number(x) : x), z.number().int())\n\nconst cliOptionsSchema = z.object({\n outputAwst: z.boolean(),\n outputAwstJson: z.boolean(),\n outDir: z.string(),\n dryRun: z.boolean(),\n logLevel: z.nativeEnum(LogLevel),\n isolatedFiles: z.boolean(),\n\n // Puya options\n outputSourceMap: z.boolean(),\n outputTeal: z.boolean(),\n outputArc32: z.boolean(),\n outputArc56: z.boolean(),\n outputSsaIr: z.boolean(),\n outputOptimizationIr: z.boolean(),\n outputDestructuredIr: z.boolean(),\n outputMemoryIr: z.boolean(),\n outputBytecode: z.boolean(),\n matchAlgodBytecode: z.boolean(),\n debugLevel: cmdInteger(),\n optimizationLevel: cmdInteger(),\n targetAvmVersion: cmdInteger(),\n cliTemplateDefinitions: z.preprocess((x) => x ?? [], z.array(z.string())),\n templateVarsPrefix: z.string(),\n localsCoalescingStrategy: z.nativeEnum(LocalsCoalescingStrategy),\n})\n\nconst cliArgumentsSchema = z.array(z.string())\n\nfunction cli() {\n const commander = new Command().name('puya-ts').description('Algo-TS to Algorand smart contract compiler')\n\n commander.helpCommand(true)\n\n commander\n .command('build')\n .argument('<paths...>', 'The path, or paths to search for compatible .algo.ts files')\n .addOption(\n new Option('--log-level [level]', 'The minimum log level to output')\n .choices([LogLevel.Debug, LogLevel.Info, LogLevel.Warning, LogLevel.Error, LogLevel.Critical])\n .default(LogLevel.Info),\n )\n .addOption(new Option('--output-awst', 'Output debugging awst file per parsed file').default(false))\n .addOption(new Option('--output-awst-json', 'Output debugging awst json file per parsed file').default(false))\n .addOption(new Option('--out-dir [outDir]').default('out'))\n .addOption(new Option('--dry-run', \"Just parse typescript files, don't invoke puya compiler\").default(false))\n .addOption(new Option('--isolated-files', 'Invoke compilation on each input file individually').default(false))\n .addOption(new Option('--no-output-teal', 'Do not output TEAL code').default(defaultPuyaOptions.outputTeal))\n .addOption(new Option('--output-source-map', 'Output debug source maps ').default(defaultPuyaOptions.outputSourceMap))\n .addOption(\n new Option(\n '--no-output-arc32',\n 'Do not output {contract}.arc32.json ARC-32 app spec file. Only applicable to ARC4 contracts',\n ).default(defaultPuyaOptions.outputArc32),\n )\n .addOption(\n new Option('--output-arc56', 'Output {contract}.arc56.json ARC-56 app spec file. Only applicable to ARC4 contracts').default(\n defaultPuyaOptions.outputArc56,\n ),\n )\n .addOption(new Option('--output-ssa-ir', 'Output IR (in SSA form) before optimisations').default(defaultPuyaOptions.outputSsaIr))\n .addOption(new Option('--output-optimization-ir', 'Output IR after each optimization').default(defaultPuyaOptions.outputOptimizationIr))\n .addOption(\n new Option('--output-destructured-ir', 'Output IR after SSA destructuring and before MIR').default(\n defaultPuyaOptions.outputDestructuredIr,\n ),\n )\n .addOption(new Option('--output-memory-ir', 'Output MIR before lowering to TealOps').default(defaultPuyaOptions.outputMemoryIr))\n .addOption(new Option('--output-bytecode', 'Output AVM bytecode').default(defaultPuyaOptions.outputBytecode))\n .addOption(\n new Option('--match-algod-bytecode', 'When outputting bytecode, ensure bytecode matches algod output').default(\n defaultPuyaOptions.matchAlgodBytecode,\n ),\n )\n .addOption(\n new Option('--debug-level [level]', 'Output debug information level, 0 = none, 1 = debug, 2 = reserved for future use')\n .choices(['0', '1', '2'])\n .default(defaultPuyaOptions.debugLevel),\n )\n .addOption(\n new Option('--optimization-level [level]', 'Set optimization level of output TEAL / AVM bytecode')\n .choices(['0', '1', '2'])\n .default(defaultPuyaOptions.optimizationLevel),\n )\n .addOption(new Option('--target-avm-version [version]', '').choices(['10', '11']).default(10))\n .addOption(\n new Option(\n '--cli-template-definitions <...definitions>',\n 'Define template vars for use when assembling via --output-bytecode, should be specified without the prefix (see --template-vars-prefix)',\n ),\n )\n .addOption(\n new Option('--template-vars-prefix [prefix]', 'Define the prefix to use with --template-var').default(\n defaultPuyaOptions.templateVarsPrefix,\n ),\n )\n .addOption(\n new Option('--locals-coalescing-strategy', '')\n .default(defaultPuyaOptions.localsCoalescingStrategy)\n .choices([\n LocalsCoalescingStrategy.root_operand,\n LocalsCoalescingStrategy.root_operand_excluding_args,\n LocalsCoalescingStrategy.aggressive,\n ]),\n )\n\n .action((a, o) => {\n using logCtx = LoggingContext.create()\n logger.configure([new ConsoleLogSink(LogLevel.Warning)])\n try {\n const paths = cliArgumentsSchema.parse(a)\n const cliOptions = cliOptionsSchema.parse(o)\n logger.configure([new ConsoleLogSink(cliOptions.logLevel)])\n const compileOptions = buildCompileOptions({\n paths,\n ...cliOptions,\n })\n const passThroughOptions: PuyaPassThroughOptions = cliOptions\n\n if (cliOptions.isolatedFiles) {\n let anyHasErrors = false\n for (const file of compileOptions.filePaths) {\n using logCtx = LoggingContext.create()\n try {\n compile(\n {\n ...compileOptions,\n filePaths: [file],\n },\n passThroughOptions,\n )\n } catch (e) {\n logger.critical(undefined, `Compilation failure: ${e}`)\n }\n anyHasErrors ||= logCtx.hasErrors()\n }\n if (anyHasErrors) {\n process.exit(-1)\n }\n } else {\n compile(compileOptions, passThroughOptions)\n logCtx.exitIfErrors()\n }\n } catch (e) {\n if (e instanceof Error) {\n logger.error(e)\n } else {\n throw e\n }\n }\n })\n\n if (process.argv.length < 3) {\n commander.help()\n } else {\n commander.parse(process.argv)\n }\n}\ncli()\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BO,MAAM,mBAAmB,GAAG,CAAC,EAClC,KAAK,EACL,gBAAgB,GAAG,OAAO,CAAC,GAAG,EAAE,EAChC,MAAM,EACN,GAAG,IAAI,EASR,KAAoB;IACnB,MAAM,SAAS,GAAe,EAAE;AAEhC,IAAA,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;AACrB,QAAA,IAAI,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;AAC1B,YAAA,IAAI,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;gBACpB,MAAM,UAAU,GAAG,aAAa,CAAC,CAAC,EAAE,gBAAgB,CAAC;gBAErD,SAAS,CAAC,IAAI,CAAC;AACb,oBAAA,YAAY,EAAE,CAAC;AACf,oBAAA,UAAU,EAAE,UAAU;AACtB,oBAAA,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;AAC3G,iBAAA,CAAC;;iBACG;gBACL,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,CAAQ,KAAA,EAAA,CAAC,CAAqB,mBAAA,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V;AACL,oBAAA,MAAM,CAAC;;;;;;;;;;;AAGZ,KAAA,CAAC;IAEJ,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;QAC3B,SAAS,CAAC,IAAI,EAAE;;SACX;AACL,QAAA,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;;AAEjC;AACA,GAAG,EAAE"}
@@ -8,6 +8,7 @@ import { TextDecoder } from 'node:util';
8
8
  import upath from 'upath';
9
9
  import { classes } from 'polytype';
10
10
  import { __addDisposableResource, __disposeResources } from 'tslib';
11
+ import * as A from 'arcsecond';
11
12
  import { randomUUID } from 'crypto';
12
13
  import fs$1 from 'fs';
13
14
  import 'glob';
@@ -2419,6 +2420,8 @@ var wtypes;
2419
2420
  nativeType: n <= 64 ? wtypes.uint64WType : wtypes.biguintWType,
2420
2421
  arc4Name: arc4Name ?? `uint${n}`,
2421
2422
  });
2423
+ invariant(n >= 8n && n <= 512n, 'Invalid uint: n must be between 8 and 512');
2424
+ invariant(n % 8n === 0n, 'Invalid uint: n must be multiple of 8');
2422
2425
  this.n = n;
2423
2426
  }
2424
2427
  }
@@ -2433,6 +2436,9 @@ var wtypes;
2433
2436
  nativeType: n <= 64 ? wtypes.uint64WType : wtypes.biguintWType,
2434
2437
  arc4Name: `ufixed${n}x${m}`,
2435
2438
  });
2439
+ invariant(n >= 8n && n <= 512n, 'Invalid ufixed: n must be between 8 and 512');
2440
+ invariant(n % 8n === 0n, 'Invalid ufixed: n must be multiple of 8');
2441
+ invariant(m >= 0n && m <= 160n, 'Invalid ufixed: m must be between 0 and 160');
2436
2442
  this.n = n;
2437
2443
  this.m = m;
2438
2444
  }
@@ -2876,8 +2882,9 @@ class ToCodeVisitor {
2876
2882
  return `emit("${expression.signature}", ${expression.value.accept(this)})`;
2877
2883
  }
2878
2884
  visitContractMethod(statement) {
2885
+ const args = statement.args.map((a) => `${a.name}: ${a.wtype}`).join(', ');
2879
2886
  const prefix = statement.cref.id === this.currentContract.at(-1)?.id ? '' : `${statement.cref.className}::`;
2880
- return [`${prefix}${statement.memberName}(): ${statement.returnType}`, '{', ...indent(statement.body.accept(this)), '}', ''];
2887
+ return [`${prefix}${statement.memberName}(${args}): ${statement.returnType}`, '{', ...indent(statement.body.accept(this)), '}', ''];
2881
2888
  }
2882
2889
  visitLogicSignature(moduleStatement) {
2883
2890
  return ['', `logicsig ${moduleStatement.id} {`, ...indent(moduleStatement.program.body.accept(this)), '}'];
@@ -5308,12 +5315,12 @@ const ARC4StrClass = new LibClassType({
5308
5315
  name: 'Str',
5309
5316
  module: Constants.arc4EncodedTypesModuleName,
5310
5317
  });
5311
- const ARC4BooleanType = new ARC4InstanceType({
5318
+ const arc4BooleanType = new ARC4InstanceType({
5312
5319
  name: 'Bool',
5313
5320
  wtype: wtypes.arc4BooleanWType,
5314
5321
  nativeType: boolPType,
5315
5322
  });
5316
- const ARC4StringType = new ARC4InstanceType({
5323
+ const arc4StringType = new ARC4InstanceType({
5317
5324
  name: 'Str',
5318
5325
  wtype: wtypes.arc4StringAliasWType,
5319
5326
  nativeType: stringPType,
@@ -8854,7 +8861,7 @@ function ptypeToArc4EncodedType(ptype, sourceLocation) {
8854
8861
  if (ptype instanceof ARC4EncodedType)
8855
8862
  return ptype;
8856
8863
  if (ptype.equals(boolPType))
8857
- return ARC4BooleanType;
8864
+ return arc4BooleanType;
8858
8865
  if (ptype.equals(uint64PType))
8859
8866
  return new UintNType({ n: 64n });
8860
8867
  if (ptype.equals(biguintPType))
@@ -8862,7 +8869,7 @@ function ptypeToArc4EncodedType(ptype, sourceLocation) {
8862
8869
  if (ptype.equals(bytesPType))
8863
8870
  return DynamicBytesType;
8864
8871
  if (ptype.equals(stringPType))
8865
- return ARC4StringType;
8872
+ return arc4StringType;
8866
8873
  if (ptype instanceof NativeNumericType) {
8867
8874
  throw new CodeError(numberPType.expressionMessage, { sourceLocation });
8868
8875
  }
@@ -10867,6 +10874,167 @@ function buildAwst({ program, sourceFiles }, options) {
10867
10874
  return [moduleAwst, awstBuildContext.compilationSet];
10868
10875
  }
10869
10876
 
10877
+ const peek = A.lookAhead(A.regex(/^./));
10878
+ const integer = A.regex(/^\d+/).map((x) => BigInt(x));
10879
+ const uint = A.sequenceOf([A.str('uint'), integer]).map(([_, n]) => new UintNType({ n: n }));
10880
+ const ufixed = A.sequenceOf([A.str('ufixed'), integer, A.char('x'), integer]).map(([_, n, __, m]) => new UFixedNxMType({ n, m }));
10881
+ const simpleType = (name, ptype) => A.str(name).map(() => ptype);
10882
+ const scalarType = A.choice([
10883
+ uint,
10884
+ ufixed,
10885
+ simpleType('byte', arc4ByteAlias),
10886
+ simpleType('string', arc4StringType),
10887
+ simpleType('bool', arc4BooleanType),
10888
+ simpleType('address', arc4AddressAlias),
10889
+ simpleType('account', new UintNType({ n: 8n })),
10890
+ simpleType('asset', new UintNType({ n: 8n })),
10891
+ simpleType('application', new UintNType({ n: 8n })),
10892
+ ]);
10893
+ class TypeBuilder {
10894
+ #stack = [[]];
10895
+ get workingSet() {
10896
+ return this.#stack[this.#stack.length - 1];
10897
+ }
10898
+ get hasOpenTuple() {
10899
+ return this.#stack.length > 1;
10900
+ }
10901
+ enterTuple() {
10902
+ this.#stack.push([]);
10903
+ }
10904
+ exitTuple() {
10905
+ if (this.#stack.length === 1) {
10906
+ throw new Error('Invalid operation, no tuple has been entered');
10907
+ }
10908
+ const tupleType = new ARC4TupleType({ types: this.workingSet });
10909
+ this.#stack.pop();
10910
+ this.workingSet.push(tupleType);
10911
+ }
10912
+ get result() {
10913
+ if (this.#stack.length > 1) {
10914
+ throw new Error(`Tuple has not been closed`);
10915
+ }
10916
+ return this.workingSet;
10917
+ }
10918
+ push(ptype) {
10919
+ this.workingSet.push(ptype);
10920
+ }
10921
+ replaceLast(replacer) {
10922
+ if (this.workingSet.length === 0) {
10923
+ throw new Error('Invalid operation, no type to replace');
10924
+ }
10925
+ const latest = this.workingSet.pop();
10926
+ this.workingSet.push(replacer(latest));
10927
+ }
10928
+ }
10929
+ const arc4Type = A.coroutine((parse) => {
10930
+ try {
10931
+ let States;
10932
+ (function (States) {
10933
+ States[States["BeginTuple"] = 0] = "BeginTuple";
10934
+ States[States["EndTuple"] = 1] = "EndTuple";
10935
+ States[States["ArrayBrackets"] = 2] = "ArrayBrackets";
10936
+ States[States["TypeOrBeginTuple"] = 3] = "TypeOrBeginTuple";
10937
+ States[States["AfterType"] = 4] = "AfterType";
10938
+ })(States || (States = {}));
10939
+ let state = States.TypeOrBeginTuple;
10940
+ const typeBuilder = new TypeBuilder();
10941
+ while (true) {
10942
+ const next = parse(A.possibly(peek));
10943
+ if (next === null) {
10944
+ return typeBuilder.result;
10945
+ }
10946
+ switch (state) {
10947
+ case States.TypeOrBeginTuple: {
10948
+ if (next === '(') {
10949
+ state = States.BeginTuple;
10950
+ }
10951
+ else {
10952
+ const type = parse(scalarType);
10953
+ typeBuilder.push(type);
10954
+ state = States.AfterType;
10955
+ }
10956
+ break;
10957
+ }
10958
+ case States.BeginTuple: {
10959
+ parse(A.char('('));
10960
+ typeBuilder.enterTuple();
10961
+ state = States.TypeOrBeginTuple;
10962
+ break;
10963
+ }
10964
+ case States.EndTuple: {
10965
+ parse(A.char(')'));
10966
+ if (!typeBuilder.hasOpenTuple) {
10967
+ return parse(A.fail("Char ')' has no matching opening '('"));
10968
+ }
10969
+ typeBuilder.exitTuple();
10970
+ state = States.AfterType;
10971
+ break;
10972
+ }
10973
+ case States.ArrayBrackets: {
10974
+ parse(A.char('['));
10975
+ const size = parse(A.possibly(integer));
10976
+ parse(A.char(']'));
10977
+ typeBuilder.replaceLast((previous) => size === null
10978
+ ? new DynamicArrayType({ elementType: previous })
10979
+ : new StaticArrayType({ elementType: previous, arraySize: size }));
10980
+ state = States.AfterType;
10981
+ break;
10982
+ }
10983
+ case States.AfterType: {
10984
+ switch (next) {
10985
+ case ',':
10986
+ parse(A.char(','));
10987
+ state = States.TypeOrBeginTuple;
10988
+ continue;
10989
+ case '[':
10990
+ state = States.ArrayBrackets;
10991
+ continue;
10992
+ case ')':
10993
+ state = States.EndTuple;
10994
+ continue;
10995
+ default:
10996
+ // Parse the next char rather than just peeking at it so the fail below happens at the right position
10997
+ parse(A.anyChar);
10998
+ parse(A.fail(`Expecting ',', '[', or ')', but got ${next}`));
10999
+ }
11000
+ }
11001
+ }
11002
+ }
11003
+ }
11004
+ catch (e) {
11005
+ if (e instanceof Error) {
11006
+ return parse(A.fail(e.message));
11007
+ }
11008
+ else {
11009
+ throw e;
11010
+ }
11011
+ }
11012
+ });
11013
+ class Arc4ParseError extends Error {
11014
+ index;
11015
+ constructor(message, index) {
11016
+ super(message);
11017
+ this.index = index;
11018
+ }
11019
+ }
11020
+ const parseArc4Type = (signature) => {
11021
+ const parseResult = arc4Type.run(signature);
11022
+ if (parseResult.isError) {
11023
+ const maybeErrorMessage = /^ParseError \(position \d+\): (.*)/.exec(parseResult.error);
11024
+ const message = maybeErrorMessage ? maybeErrorMessage[1] : parseResult.error;
11025
+ throw new Arc4ParseError(message, parseResult.index);
11026
+ }
11027
+ else {
11028
+ if (parseResult.result.length === 0) {
11029
+ throw new Arc4ParseError('Signature contained no types', 0);
11030
+ }
11031
+ else if (parseResult.result.length > 1) {
11032
+ throw new Arc4ParseError('Signature contained more than one type. Wrap multiple types in parentheses to declare a tuple type', 0);
11033
+ }
11034
+ return parseResult.result[0];
11035
+ }
11036
+ };
11037
+
10870
11038
  class Arc28EmitFunctionBuilder extends FunctionBuilder {
10871
11039
  ptype = arc28EmitFunction;
10872
11040
  call(args, typeArgs, sourceLocation) {
@@ -10879,14 +11047,18 @@ class Arc28EmitFunctionBuilder extends FunctionBuilder {
10879
11047
  argSpec: (a) => [a.required(), ...args.slice(1).map(() => a.required())],
10880
11048
  });
10881
11049
  if (nameOrObj.ptype.equals(stringPType)) {
10882
- const name = requireStringConstant(nameOrObj).value;
10883
11050
  const thisModule = nameOrObj.sourceLocation.file ?? '';
10884
11051
  const fields = {};
10885
11052
  const values = new Map();
10886
- for (const [index, prop] of Object.entries(props)) {
11053
+ const { name, propTypes } = parseEventName(nameOrObj);
11054
+ for (const [index, prop] of props.entries()) {
10887
11055
  const arc4Type = ptypeToArc4EncodedType(prop.ptype, prop.sourceLocation);
11056
+ const expectedType = propTypes?.[index];
11057
+ if (expectedType) {
11058
+ codeInvariant(expectedType.wtype.equals(arc4Type.wtype), `Expected type ${expectedType} does not match actual type ${arc4Type}`, prop.sourceLocation);
11059
+ }
10888
11060
  fields[index] = arc4Type;
10889
- values.set(index, prop.ptype instanceof ARC4EncodedType
11061
+ values.set(index.toString(), prop.ptype instanceof ARC4EncodedType
10890
11062
  ? prop.resolve()
10891
11063
  : nodeFactory.aRC4Encode({
10892
11064
  value: prop.resolve(),
@@ -10894,8 +11066,13 @@ class Arc28EmitFunctionBuilder extends FunctionBuilder {
10894
11066
  sourceLocation: prop.sourceLocation,
10895
11067
  }));
10896
11068
  }
11069
+ if (propTypes && propTypes.length !== values.size) {
11070
+ throw new CodeError(`Event signature length (${propTypes.length}) does not match number of provided values (${values.size}).`, {
11071
+ sourceLocation: sourceLocation,
11072
+ });
11073
+ }
10897
11074
  const structType = new ARC4StructType({
10898
- name,
11075
+ name: name.value,
10899
11076
  module: thisModule,
10900
11077
  fields,
10901
11078
  description: undefined,
@@ -10936,6 +11113,41 @@ function emitStruct(ptype, expression, sourceLocation) {
10936
11113
  sourceLocation,
10937
11114
  }), voidPType);
10938
11115
  }
11116
+ function parseEventName(nameBuilder) {
11117
+ const name = requireStringConstant(nameBuilder);
11118
+ const parenthesisIndex = name.value.indexOf('(');
11119
+ if (parenthesisIndex === -1) {
11120
+ return {
11121
+ name,
11122
+ };
11123
+ }
11124
+ const signature = name.value.substring(parenthesisIndex);
11125
+ try {
11126
+ const signatureType = parseArc4Type(signature);
11127
+ codeInvariant(signatureType instanceof ARC4TupleType, 'Event signature must be a tuple type', name.sourceLocation);
11128
+ return {
11129
+ name: nodeFactory.stringConstant({
11130
+ value: name.value.substring(0, parenthesisIndex),
11131
+ sourceLocation: name.sourceLocation,
11132
+ }),
11133
+ propTypes: signatureType.items,
11134
+ };
11135
+ }
11136
+ catch (e) {
11137
+ if (e instanceof Arc4ParseError) {
11138
+ // Assumes StringConstant is all on one line
11139
+ throw new CodeError(`Invalid signature: ${e.message}`, {
11140
+ sourceLocation: new SourceLocation({
11141
+ ...name.sourceLocation,
11142
+ column: name.sourceLocation.column + parenthesisIndex + e.index,
11143
+ }),
11144
+ });
11145
+ }
11146
+ else {
11147
+ throw e;
11148
+ }
11149
+ }
11150
+ }
10939
11151
 
10940
11152
  function requireConstantValue(builder, sourceLocation) {
10941
11153
  if (builder instanceof BigIntLiteralExpressionBuilder) {
@@ -12115,7 +12327,7 @@ class BoolClassBuilder extends ClassBuilder {
12115
12327
  }
12116
12328
  class BoolExpressionBuilder extends Arc4EncodedBaseExpressionBuilder {
12117
12329
  constructor(expression) {
12118
- super(expression, ARC4BooleanType);
12330
+ super(expression, arc4BooleanType);
12119
12331
  }
12120
12332
  }
12121
12333
 
@@ -12156,7 +12368,7 @@ class StrClassBuilder extends ClassBuilder {
12156
12368
  }
12157
12369
  class StrExpressionBuilder extends Arc4EncodedBaseExpressionBuilder {
12158
12370
  constructor(expression) {
12159
- super(expression, ARC4StringType);
12371
+ super(expression, arc4StringType);
12160
12372
  }
12161
12373
  }
12162
12374
 
@@ -18134,7 +18346,7 @@ const OP_METADATA = {
18134
18346
  {
18135
18347
  argNames: ['a'],
18136
18348
  immediateArgs: ['VoterBalance'],
18137
- stackArgs: [{ name: 'a', ptypes: [uint64PType, bytesPType] }],
18349
+ stackArgs: [{ name: 'a', ptypes: [accountPType, uint64PType] }],
18138
18350
  returnType: new TuplePType({ items: [uint64PType, boolPType] }),
18139
18351
  },
18140
18352
  ],
@@ -18146,7 +18358,7 @@ const OP_METADATA = {
18146
18358
  {
18147
18359
  argNames: ['a'],
18148
18360
  immediateArgs: ['VoterIncentiveEligible'],
18149
- stackArgs: [{ name: 'a', ptypes: [uint64PType, bytesPType] }],
18361
+ stackArgs: [{ name: 'a', ptypes: [accountPType, uint64PType] }],
18150
18362
  returnType: new TuplePType({ items: [boolPType, boolPType] }),
18151
18363
  },
18152
18364
  ],
@@ -19396,8 +19608,8 @@ function registerPTypes(typeRegistry) {
19396
19608
  typeRegistry.register({ ptype: arc4AddressAlias, instanceEb: AddressExpressionBuilder });
19397
19609
  typeRegistry.register({ ptype: AddressClass, singletonEb: AddressClassBuilder });
19398
19610
  typeRegistry.register({ ptype: ARC4BoolClass, singletonEb: BoolClassBuilder });
19399
- typeRegistry.register({ ptype: ARC4BooleanType, instanceEb: BoolExpressionBuilder });
19400
- typeRegistry.register({ ptype: ARC4StringType, instanceEb: StrExpressionBuilder });
19611
+ typeRegistry.register({ ptype: arc4BooleanType, instanceEb: BoolExpressionBuilder });
19612
+ typeRegistry.register({ ptype: arc4StringType, instanceEb: StrExpressionBuilder });
19401
19613
  typeRegistry.register({ ptype: ARC4StrClass, singletonEb: StrClassBuilder });
19402
19614
  typeRegistry.register({ ptype: Arc4TupleClass, singletonEb: Arc4TupleClassBuilder });
19403
19615
  typeRegistry.registerGeneric({ generic: Arc4TupleGeneric, ptype: ARC4TupleType, instanceEb: Arc4TupleExpressionBuilder });
@@ -19771,11 +19983,9 @@ var forExport = /*#__PURE__*/Object.freeze({
19771
19983
  __proto__: null,
19772
19984
  ALL_OP_ENUMS: ALL_OP_ENUMS,
19773
19985
  ARC4BoolClass: ARC4BoolClass,
19774
- ARC4BooleanType: ARC4BooleanType,
19775
19986
  ARC4EncodedType: ARC4EncodedType,
19776
19987
  ARC4InstanceType: ARC4InstanceType,
19777
19988
  ARC4StrClass: ARC4StrClass,
19778
- ARC4StringType: ARC4StringType,
19779
19989
  ARC4StructClass: ARC4StructClass,
19780
19990
  ARC4StructType: ARC4StructType,
19781
19991
  ARC4TupleType: ARC4TupleType,
@@ -19893,7 +20103,9 @@ var forExport = /*#__PURE__*/Object.freeze({
19893
20103
  arc4AddressAlias: arc4AddressAlias,
19894
20104
  arc4BareMethodDecorator: arc4BareMethodDecorator,
19895
20105
  arc4BaseContractType: arc4BaseContractType,
20106
+ arc4BooleanType: arc4BooleanType,
19896
20107
  arc4ByteAlias: arc4ByteAlias,
20108
+ arc4StringType: arc4StringType,
19897
20109
  arc4StructBaseType: arc4StructBaseType,
19898
20110
  assertFunction: assertFunction,
19899
20111
  assertMatchFunction: assertMatchFunction,
@@ -20015,4 +20227,4 @@ function compile(options, passThroughOptions, hooks) {
20015
20227
  }
20016
20228
 
20017
20229
  export { LoggingContext as L, PuyaError as P, SourceLocation as S, TypeResolver as T, LogLevel as a, LocalsCoalescingStrategy as b, compile as c, defaultPuyaOptions as d, encodingUtil as e, forExport as f, logger as l, normalisePath as n, registerPTypes as r, typeRegistry as t };
20018
- //# sourceMappingURL=index-D4-4PUG7.js.map
20230
+ //# sourceMappingURL=index-Cg8BBwmU.js.map