Skip to content

Commit

Permalink
feat: AVM11 Support
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmenzel committed Dec 6, 2024
1 parent 74412c5 commit 4eb3bab
Show file tree
Hide file tree
Showing 67 changed files with 13,115 additions and 8,206 deletions.
16,149 changes: 8,208 additions & 7,941 deletions langspec.puya.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dev:examples": "tsx src/cli.ts build examples --output-awst --output-awst-json",
"dev:approvals": "rimraf tests/approvals/out && tsx src/cli.ts build tests/approvals --dry-run",
"dev:expected-output": "tsx src/cli.ts build tests/expected-output --dry-run",
"dev:testing": "tsx src/cli.ts build tests/approvals/arc28-events.algo.ts --output-awst --output-awst-json --output-ssa-ir --log-level=info --out-dir out/[name] --optimization-level=0",
"dev:testing": "tsx src/cli.ts build tests/approvals/avm11.algo.ts --output-awst --output-awst-json --output-ssa-ir --log-level=info --out-dir out/[name] --optimization-level=0",
"audit": "better-npm-audit audit",
"format": "prettier --write .",
"lint": "eslint \"src/**/*.ts\"",
Expand Down
2 changes: 1 addition & 1 deletion packages/algo-ts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@algorandfoundation/algorand-typescript",
"version": "0.0.1-alpha.17",
"version": "0.0.1-alpha.18",
"description": "This package contains definitions for the types which comprise Algorand TypeScript which can be compiled to run on the Algorand Virtual Machine using the Puya compiler.",
"private": false,
"main": "index.js",
Expand Down
68 changes: 68 additions & 0 deletions packages/algo-ts/src/base-contract.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,76 @@
import { Contract } from './arc4'
import { uint64 } from './primitives'
import { ConstructorFor } from './typescript-helpers'

export abstract class BaseContract {
public abstract approvalProgram(): boolean | uint64
public clearStateProgram(): boolean | uint64 {
return true
}
}

type NumberRange = { from: number; to: number }

/**
* Options class to manually define the total amount of global and local state contract will use.
*
* This is not required when all state is assigned to `this.`, but is required if a
* contract dynamically interacts with state via `AppGlobal.getBytes` etc, or if you want
* to reserve additional state storage for future contract updates, since the Algorand protocol
* doesn't allow increasing them after creation.
*/
type StateTotals = {
globalUints?: number
globalBytes?: number
localUints?: number
localBytes?: number
}

type ContractOptions = {
/**
* Determines which AVM version to use, this affects what operations are supported.
* Defaults to value provided supplied on command line (which defaults to current mainnet version)
*/
avmVersion?: 10 | 11

/**
* Override the name of the logic signature when generating build artifacts.
* Defaults to the class name
*/
name?: string
/**
* Allows you to mark a slot ID or range of slot IDs as "off limits" to Puya.
* These slot ID(s) will never be written to or otherwise manipulating by the compiler itself.
* This is particularly useful in combination with `op.gload_bytes` / `op.gload_uint64`
* which lets a contract in a group transaction read from the scratch slots of another contract
* that occurs earlier in the transaction group.
*
* In the case of inheritance, scratch slots reserved become cumulative. It is not an error
* to have overlapping ranges or values either, so if a base class contract reserves slots
* 0-5 inclusive and the derived contract reserves 5-10 inclusive, then within the derived
* contract all slots 0-10 will be marked as reserved.
*/
scratchSlots?: Array<number | NumberRange>
/**
* Allows defining what values should be used for global and local uint and bytes storage
* values when creating a contract. Used when outputting ARC-32 application.json schemas.
*
* If let unspecified, the totals will be determined by the compiler based on state
* variables assigned to `this`.
*
* This setting is not inherited, and only applies to the exact `Contract` it is specified
* on. If a base class does specify this setting, and a derived class does not, a warning
* will be emitted for the derived class. To resolve this warning, `state_totals` must be
* specified. An empty object may be provided in order to indicate that this contract should
* revert to the default behaviour
*/
stateTotals?: StateTotals
}

/**
* The contract decorator can be used to specify additional configuration options for a smart contract
* @param options An object containing the configuration options
*/
export function contract(options: ContractOptions) {
return <TContract extends Contract>(contract: ConstructorFor<TContract>) => contract
}
4 changes: 2 additions & 2 deletions packages/algo-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export { Txn, Global } from './op'
export * as internal from './internal'
export * as arc4 from './arc4'
export { Contract, abimethod } from './arc4'
export { BaseContract } from './base-contract'
export { BaseContract, contract } from './base-contract'
export { BoxRef, BoxMap, Box } from './box'
export * from './state'
export * as itxn from './itxn'
export * as gtxn from './gtxn'
export { TransactionType } from './transactions'
export { LogicSig } from './logic-sig'
export { LogicSig, logicsig } from './logic-sig'
export { TemplateVar } from './template-var'
export { Base64, Ec, Ecdsa, VrfVerify } from './op-types'
export { compile, CompiledContract, CompiledLogicSig } from './compiled'
Expand Down
25 changes: 25 additions & 0 deletions packages/algo-ts/src/logic-sig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import { uint64 } from './primitives'
import { ConstructorFor } from './typescript-helpers'

export abstract class LogicSig {
abstract program(): boolean | uint64
}

/**
* Defines optional configuration for a logic signature
*/
type LogicSigOptions = {
/**
* Determines which AVM version to use, this affects what operations are supported.
* Defaults to value provided supplied on command line (which defaults to current mainnet version)
*/
avmVersion?: 10 | 11
/**
* Override the name of the logic signature when generating build artifacts.
* Defaults to the class name
*/
name?: string
}

/**
* The logicsig decorator can be used to specify additional configuration options for a logic signature
* @param options An object containing the configuration options
*/
export function logicsig(options: LogicSigOptions) {
return <TLogicSig extends LogicSig>(logicSig: ConstructorFor<TLogicSig>) => logicSig
}
Loading

0 comments on commit 4eb3bab

Please sign in to comment.