Skip to content

Commit

Permalink
Merge pull request #62 from algorandfoundation/feat-arg-op
Browse files Browse the repository at this point in the history
feat: implement arg op code via context manager
  • Loading branch information
boblat authored Dec 22, 2024
2 parents 895dfbb + abd2c3f commit a8c08c7
Show file tree
Hide file tree
Showing 356 changed files with 9,661 additions and 8,953 deletions.
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 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.22",
"version": "0.0.1-alpha.23",
"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
6 changes: 6 additions & 0 deletions packages/algo-ts/src/op.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ctxMgr } from './execution-context'

import {
AddwType,
AppOptedInType,
ArgType,
BalanceType,
Base64DecodeType,
BitLengthType,
Expand Down Expand Up @@ -37,6 +39,7 @@ import {
ITxnType,
JsonRefType,
Keccak256Type,
LenType,
MulwType,
OnlineStakeType,
OpsNamespace,
Expand Down Expand Up @@ -82,6 +85,8 @@ const createObjectProxy = <TName extends ObjectKeys>(name: TName) => {
}

export const addw: AddwType = createFunctionProxy('addw')
export const appOptedIn: AppOptedInType = createFunctionProxy('appOptedIn')
export const arg: ArgType = createFunctionProxy('arg')
export const balance: BalanceType = createFunctionProxy('balance')
export const base64Decode: Base64DecodeType = createFunctionProxy('base64Decode')
export const bitLength: BitLengthType = createFunctionProxy('bitLength')
Expand Down Expand Up @@ -109,6 +114,7 @@ export const gloadBytes: GloadBytesType = createFunctionProxy('gloadBytes')
export const gloadUint64: GloadUint64Type = createFunctionProxy('gloadUint64')
export const itob: ItobType = createFunctionProxy('itob')
export const keccak256: Keccak256Type = createFunctionProxy('keccak256')
export const len: LenType = createFunctionProxy('len')
export const minBalance: BalanceType = createFunctionProxy('minBalance')
export const mulw: MulwType = createFunctionProxy('mulw')
export const replace: ReplaceType = createFunctionProxy('replace')
Expand Down
160 changes: 83 additions & 77 deletions tests/approvals/out/abi-decorators/AbiDecorators.approval.teal
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
#pragma version 10
#pragma typetrack false

tests/approvals/abi-decorators.algo.ts::AbiDecorators.approvalProgram:
// @algorandfoundation/algorand-typescript/arc4/index.d.ts::Contract.approvalProgram() -> uint64:
main:
intcblock 0 1
bytecblock 0x151f7c75
txn ApplicationID
bnz main_after_if_else@2

main_if_body@1:
callsub constructor

main_after_if_else@2:
callsub __puya_arc4_router__
return


// tests/approvals/abi-decorators.algo.ts::AbiDecorators.constructor() -> void:
constructor:
// tests/approvals/abi-decorators.algo.ts:4
// export default class AbiDecorators extends Contract {
proto 0 0
// tests/approvals/abi-decorators.algo.ts:16
// globalValue = GlobalState({ initialValue: Uint64(123) })
pushbytes "globalValue"
pushint 123 // 123
app_global_put
retsub


// tests/approvals/abi-decorators.algo.ts::AbiDecorators.__puya_arc4_router__() -> uint64:
__puya_arc4_router__:
main_block@3:
// tests/approvals/abi-decorators.algo.ts:4
// export default class AbiDecorators extends Contract {
proto 0 1
txn NumAppArgs
intc_0 // 0
!=
bz __puya_arc4_router___bare_routing@9
bz main_bare_routing@12

main_abi_routing@4:
// tests/approvals/abi-decorators.algo.ts:4
// export default class AbiDecorators extends Contract {
txna ApplicationArgs 0
pushbytes 0xf9020d5a // method "justNoop()void"
pushbytes 0xe179f9d4 // method "createMethod()void"
pushbytes 0x63c27aba // method "allActions()void"
pushbytes 0x14d1b6ea // method "overrideReadonlyName()uint64"
pushbytes 0xc1367374 // method "methodWithDefaults(uint64,uint64,uint64)uint64"
uncover 5
match __puya_arc4_router___justNoop_route@2 __puya_arc4_router___createMethod_route@3 __puya_arc4_router___allActions_route@4 __puya_arc4_router___overrideReadonlyName_route@5 __puya_arc4_router___methodWithDefaults_route@6
b __puya_arc4_router___switch_case_default@7
match main_justNoop_route@5 main_createMethod_route@6 main_allActions_route@7 main_overrideReadonlyName_route@8 main_methodWithDefaults_route@9

__puya_arc4_router___justNoop_route@2:
// tests/approvals/abi-decorators.algo.ts:5
// @abimethod({ allowActions: 'NoOp' })
main_switch_case_default@10:

main_switch_case_next@11:

main_after_if_else@13:
// tests/approvals/abi-decorators.algo.ts:4
// export default class AbiDecorators extends Contract {
intc_0 // 0

main_after_inlined_tests/approvals/abi-decorators.algo.ts::AbiDecorators.__puya_arc4_router__@14:
return

main_methodWithDefaults_route@9:
// tests/approvals/abi-decorators.algo.ts:18
// @abimethod({ defaultArguments: { a: { from: 'globalValue' }, b: { from: 'readonly' }, c: { constant: 145 } } })
txn OnCompletion
intc_0 // NoOp
==
Expand All @@ -55,26 +56,49 @@ __puya_arc4_router___justNoop_route@2:
intc_0 // 0
!=
assert // can only call when not creating
callsub justNoop
// tests/approvals/abi-decorators.algo.ts:4
// export default class AbiDecorators extends Contract {
txna ApplicationArgs 1
btoi
txna ApplicationArgs 2
btoi
txna ApplicationArgs 3
btoi
// tests/approvals/abi-decorators.algo.ts:18
// @abimethod({ defaultArguments: { a: { from: 'globalValue' }, b: { from: 'readonly' }, c: { constant: 145 } } })
uncover 2
uncover 2
uncover 2
callsub methodWithDefaults
itob
bytec_0 // 0x151f7c75
swap
concat
log
intc_1 // 1
retsub
b main_after_inlined_tests/approvals/abi-decorators.algo.ts::AbiDecorators.__puya_arc4_router__@14

__puya_arc4_router___createMethod_route@3:
// tests/approvals/abi-decorators.algo.ts:7
// @abimethod({ onCreate: 'require' })
main_overrideReadonlyName_route@8:
// tests/approvals/abi-decorators.algo.ts:11
// @abimethod({ readonly: true, name: 'overrideReadonlyName' })
txn OnCompletion
intc_0 // NoOp
==
assert // OnCompletion is not NoOp
txn ApplicationID
intc_0 // 0
==
assert // can only call when creating
callsub createMethod
!=
assert // can only call when not creating
callsub readonly
itob
bytec_0 // 0x151f7c75
swap
concat
log
intc_1 // 1
retsub
b main_after_inlined_tests/approvals/abi-decorators.algo.ts::AbiDecorators.__puya_arc4_router__@14

__puya_arc4_router___allActions_route@4:
main_allActions_route@7:
// tests/approvals/abi-decorators.algo.ts:9
// @abimethod({ allowActions: ['NoOp', 'OptIn', 'CloseOut', 'DeleteApplication', 'UpdateApplication'] })
txn ApplicationID
Expand All @@ -83,31 +107,26 @@ __puya_arc4_router___allActions_route@4:
assert // can only call when not creating
callsub allActions
intc_1 // 1
retsub
b main_after_inlined_tests/approvals/abi-decorators.algo.ts::AbiDecorators.__puya_arc4_router__@14

__puya_arc4_router___overrideReadonlyName_route@5:
// tests/approvals/abi-decorators.algo.ts:11
// @abimethod({ readonly: true, name: 'overrideReadonlyName' })
main_createMethod_route@6:
// tests/approvals/abi-decorators.algo.ts:7
// @abimethod({ onCreate: 'require' })
txn OnCompletion
intc_0 // NoOp
==
assert // OnCompletion is not NoOp
txn ApplicationID
intc_0 // 0
!=
assert // can only call when not creating
callsub readonly
itob
bytec_0 // 0x151f7c75
swap
concat
log
==
assert // can only call when creating
callsub createMethod
intc_1 // 1
retsub
b main_after_inlined_tests/approvals/abi-decorators.algo.ts::AbiDecorators.__puya_arc4_router__@14

__puya_arc4_router___methodWithDefaults_route@6:
// tests/approvals/abi-decorators.algo.ts:18
// @abimethod({ defaultArguments: { a: { from: 'globalValue' }, b: { from: 'readonly' }, c: { constant: 145 } } })
main_justNoop_route@5:
// tests/approvals/abi-decorators.algo.ts:5
// @abimethod({ allowActions: 'NoOp' })
txn OnCompletion
intc_0 // NoOp
==
Expand All @@ -116,37 +135,24 @@ __puya_arc4_router___methodWithDefaults_route@6:
intc_0 // 0
!=
assert // can only call when not creating
// tests/approvals/abi-decorators.algo.ts:4
// export default class AbiDecorators extends Contract {
txna ApplicationArgs 1
btoi
txna ApplicationArgs 2
btoi
txna ApplicationArgs 3
btoi
// tests/approvals/abi-decorators.algo.ts:18
// @abimethod({ defaultArguments: { a: { from: 'globalValue' }, b: { from: 'readonly' }, c: { constant: 145 } } })
uncover 2
uncover 2
uncover 2
callsub methodWithDefaults
itob
bytec_0 // 0x151f7c75
swap
concat
log
callsub justNoop
intc_1 // 1
retsub
b main_after_inlined_tests/approvals/abi-decorators.algo.ts::AbiDecorators.__puya_arc4_router__@14

__puya_arc4_router___switch_case_default@7:
b __puya_arc4_router___after_if_else@10
main_bare_routing@12:
b main_after_if_else@13

__puya_arc4_router___bare_routing@9:

__puya_arc4_router___after_if_else@10:
// tests/approvals/abi-decorators.algo.ts::AbiDecorators.constructor() -> void:
constructor:
// tests/approvals/abi-decorators.algo.ts:4
// export default class AbiDecorators extends Contract {
intc_0 // 0
proto 0 0
// tests/approvals/abi-decorators.algo.ts:16
// globalValue = GlobalState({ initialValue: Uint64(123) })
pushbytes "globalValue"
pushint 123 // 123
app_global_put
retsub


Expand Down
4 changes: 2 additions & 2 deletions tests/approvals/out/abi-decorators/AbiDecorators.arc32.json

Large diffs are not rendered by default.

34 changes: 23 additions & 11 deletions tests/approvals/out/abi-decorators/AbiDecorators.arc56.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion tests/approvals/out/abi-decorators/AbiDecorators.clear.teal
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma version 10
#pragma typetrack false

tests/approvals/abi-decorators.algo.ts::AbiDecorators.clearStateProgram:
// @algorandfoundation/algorand-typescript/base-contract.d.ts::BaseContract.clearStateProgram() -> uint64:
main:
pushint 1 // 1
return
Loading

0 comments on commit a8c08c7

Please sign in to comment.