Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Arc4 encode/decode of native arrays #182

Merged
merged 5 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/ci-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
set -e # Exit on error
[ $diffExitCode -ne 0 ] && (echo "$thisVersion has not been published yet"; exit 0;) || echo "$thisVersion already published, checking diff against local build"
diffTextLen=${#diffText}
[ $diffTextLen -eq 0 ] && echo 'No changes' || (echo 'ERROR: Code differs to published version. Please bump package version or revert changes'; echo $diffText; exit 1;)
[ $diffTextLen -eq 0 ] && echo 'No changes' || (echo 'ERROR: Code differs to published version. Please bump package version or revert changes'; echo "::group::diff"; echo $diffText; echo "::endgroup::";exit 1;)

ci-puya-ts:
name: 'Build @algorandfoundation/puya-ts'
Expand Down
46 changes: 26 additions & 20 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dev:examples": "tsx src/cli.ts examples --output-awst --output-awst-json",
"dev:approvals": "tsx src/cli.ts tests/approvals --dry-run",
"dev:expected-output": "tsx src/cli.ts tests/expected-output --dry-run",
"dev:testing": "tsx src/cli.ts tests/approvals/precompiled-typed.algo.ts --no-output-source-map --log-level=debug --out-dir out/unoptimized/[name] --optimization-level=0 --output-awst --output-awst-json --output-ssa-ir",
"dev:testing": "tsx src/cli.ts tests/approvals/arc4-encode-decode.algo.ts --no-output-source-map --log-level=info --out-dir out/unoptimized/[name] --optimization-level=0 --output-awst --output-awst-json --output-ssa-ir",
"audit": "better-npm-audit audit",
"format": "prettier --write .",
"lint": "eslint \"src/**/*.ts\"",
Expand Down Expand Up @@ -41,21 +41,21 @@
"author": "Algorand foundation",
"license": "MIT",
"devDependencies": {
"@algorandfoundation/algokit-utils": "^8.2.2",
"@algorandfoundation/algokit-utils": "^9.0.0",
"@algorandfoundation/algorand-typescript": "file:packages/algo-ts/dist",
"@commitlint/cli": "^19.8.0",
"@commitlint/config-conventional": "^19.8.0",
"@makerx/eslint-config": "4.1.0",
"@makerx/eslint-config": "4.2.0",
"@makerx/prettier-config": "2.0.1",
"@makerx/ts-toolkit": "^4.0.0-beta.22",
"@makerx/ts-toolkit": "^4.0.0-beta.24",
"@rollup/plugin-commonjs": "28.0.3",
"@rollup/plugin-json": "6.1.0",
"@rollup/plugin-node-resolve": "16.0.1",
"@rollup/plugin-typescript": "^12.1.2",
"@tsconfig/node20": "20.1.5",
"@types/argparse": "^2.0.17",
"@types/cross-spawn": "^6.0.6",
"@types/node": "22.13.13",
"@types/node": "22.13.14",
"@types/tar": "^6.1.13",
"@types/which": "^3.0.4",
"@typescript-eslint/eslint-plugin": "8.28.0",
Expand Down
28 changes: 14 additions & 14 deletions packages/algo-ts/package-lock.json

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

8 changes: 4 additions & 4 deletions packages/algo-ts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@algorandfoundation/algorand-typescript",
"version": "1.0.0-beta.32",
"version": "1.0.0-beta.33",
"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 All @@ -23,15 +23,15 @@
"devDependencies": {
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.23.0",
"@makerx/eslint-config": "4.1.0",
"@makerx/eslint-config": "4.2.0",
"@makerx/prettier-config": "2.0.1",
"@makerx/ts-toolkit": "^4.0.0-beta.22",
"@makerx/ts-toolkit": "^4.0.0-beta.24",
"@rollup/plugin-commonjs": "28.0.3",
"@rollup/plugin-json": "6.1.0",
"@rollup/plugin-node-resolve": "16.0.1",
"@rollup/plugin-typescript": "12.1.2",
"@tsconfig/node20": "20.1.5",
"@types/node": "22.13.13",
"@types/node": "22.13.14",
"@typescript-eslint/eslint-plugin": "8.28.0",
"@typescript-eslint/parser": "8.28.0",
"@vitest/coverage-v8": "3.0.9",
Expand Down
16 changes: 15 additions & 1 deletion packages/algo-ts/src/arc4/encoded-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NoImplementation } from '../internal/errors'
import { biguint, BigUintCompat, bytes, BytesBacked, StringCompat, uint64, Uint64Compat } from '../primitives'
import { biguint, BigUintCompat, bytes, BytesBacked, BytesCompat, NTuple, StringCompat, uint64, Uint64Compat } from '../primitives'
import { Account } from '../reference'

/**
Expand Down Expand Up @@ -335,6 +335,13 @@ export class StaticArray<TItem extends ARC4Encoded, TLength extends number> exte
concat(other: Arc4ArrayBase<TItem>): DynamicArray<TItem> {
throw new NoImplementation()
}

/**
* Return the array items as a native tuple
*/
get native(): NTuple<TItem, TLength> {
throw new NoImplementation()
}
}

/**
Expand Down Expand Up @@ -382,6 +389,13 @@ export class DynamicArray<TItem extends ARC4Encoded> extends Arc4ArrayBase<TItem
concat(other: Arc4ArrayBase<TItem>): DynamicArray<TItem> {
throw new NoImplementation()
}

/**
* Return the array items as a native immutable array
*/
get native(): TItem[] {
throw new NoImplementation()
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions packages/algo-ts/src/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,13 @@ export interface BytesBacked {
*/
get bytes(): bytes
}

/**
* Declare a homogeneous tuple with the item type T and length N.
*
* Eg.
* NTuple<uint64, 3> === [uint64, uint64, uint64]
*/
export type NTuple<T, N extends number> = N extends N ? (number extends N ? T[] : _TupleOf<T, N, readonly []>) : never

type _TupleOf<T, N extends number, R extends readonly unknown[]> = R['length'] extends N ? R : _TupleOf<T, N, readonly [T, ...R]>
Loading