Skip to content

Commit 6f32ea1

Browse files
authored
Merge pull request #40 from algorandfoundation/refactor/import
refactor: use import replacement to swap in stub implementations
2 parents 2040373 + 01b3738 commit 6f32ea1

File tree

99 files changed

+825
-702
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+825
-702
lines changed

.tstoolkitrc.ts

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const config: TsToolkitConfig = {
1010
exports: {
1111
'.': 'index.ts',
1212
'./runtime-helpers': 'runtime-helpers.ts',
13+
'./internal': 'internal.ts',
14+
'./internal/arc4': 'internal-arc4.ts',
15+
'./internal/op': 'internal-op.ts',
1316
'./test-transformer': 'test-transformer/index.ts',
1417
},
1518
},

eslint.config.mjs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { FlatCompat } from '@eslint/eslintrc'
2+
import js from '@eslint/js'
13
import globals from 'globals'
24
import path from 'node:path'
35
import { fileURLToPath } from 'node:url'
4-
import js from '@eslint/js'
5-
import { FlatCompat } from '@eslint/eslintrc'
66

77
const __filename = fileURLToPath(import.meta.url)
88
const __dirname = path.dirname(__filename)
@@ -33,5 +33,8 @@ export default [
3333
...globals.node,
3434
},
3535
},
36+
rules: {
37+
'@typescript-eslint/consistent-type-imports': 'error',
38+
},
3639
},
3740
]

examples/calculator/contract.algo.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { assert, BaseContract, Bytes, err, log, op, Txn, uint64, Uint64 } from '@algorandfoundation/algorand-typescript'
1+
import type { uint64 } from '@algorandfoundation/algorand-typescript'
2+
import { assert, BaseContract, Bytes, err, log, op, Txn, Uint64 } from '@algorandfoundation/algorand-typescript'
23

34
const ADD = Uint64(1)
45
const SUB = Uint64(2)

examples/htlc-logicsig/signature.algo.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Account, Bytes, Global, LogicSig, op, TransactionType, Txn, Uint64, uint64 } from '@algorandfoundation/algorand-typescript'
1+
import type { uint64 } from '@algorandfoundation/algorand-typescript'
2+
import { Account, Bytes, Global, LogicSig, op, TransactionType, Txn, Uint64 } from '@algorandfoundation/algorand-typescript'
23

34
export default class HashedTimeLockedLogicSig extends LogicSig {
45
program(): boolean | uint64 {

examples/scratch-storage/contract.algo.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { arc4, assert, BaseContract, Bytes, op, uint64, Uint64 } from '@algorandfoundation/algorand-typescript'
1+
import type { uint64 } from '@algorandfoundation/algorand-typescript'
2+
import { arc4, assert, BaseContract, Bytes, op, Uint64 } from '@algorandfoundation/algorand-typescript'
23

34
export class ScratchSlotsContract extends arc4.Contract {
45
@arc4.abimethod()

examples/zk-whitelist/contract.algo.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { uint64 } from '@algorandfoundation/algorand-typescript'
12
import {
23
abimethod,
34
Account,
@@ -13,7 +14,6 @@ import {
1314
OpUpFeeSource,
1415
TemplateVar,
1516
Txn,
16-
uint64,
1717
} from '@algorandfoundation/algorand-typescript'
1818

1919
const curveMod = 21888242871839275222246405745257275088548364400416034343698204186575808495617n

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"tslib": "^2.6.2"
6565
},
6666
"dependencies": {
67-
"@algorandfoundation/algorand-typescript": "^1.0.0-beta.9",
67+
"@algorandfoundation/algorand-typescript": "^1.0.0-beta.10",
6868
"@algorandfoundation/puya-ts": "^1.0.0-beta.13",
6969
"elliptic": "^6.5.7",
7070
"js-sha256": "^0.11.0",

rollup.config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const config: RollupOptions = {
88
input: {
99
index: 'src/index.ts',
1010
'runtime-helpers': 'src/runtime-helpers.ts',
11+
'internal': 'src/internal.ts',
12+
'internal/arc4': 'src/internal-arc4.ts',
13+
'internal/op': 'src/internal-op.ts',
1114
'test-transformer/index': 'src/test-transformer/index.ts',
1215
},
1316
output: [

src/abi-metadata.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { BaseContract, Contract } from '@algorandfoundation/algorand-typescript'
2-
import { AbiMethodConfig, BareMethodConfig, CreateOptions, OnCompleteActionStr } from '@algorandfoundation/algorand-typescript/arc4'
1+
import type { BaseContract, Contract } from '@algorandfoundation/algorand-typescript'
2+
import type { AbiMethodConfig, BareMethodConfig, CreateOptions, OnCompleteActionStr } from '@algorandfoundation/algorand-typescript/arc4'
33
import js_sha512 from 'js-sha512'
4-
import { TypeInfo } from './encoders'
4+
import type { TypeInfo } from './encoders'
55
import { getArc4TypeName as getArc4TypeNameForARC4Encoded } from './impl/encoded-types'
6-
import { DeliberateAny } from './typescript-helpers'
6+
import type { DeliberateAny } from './typescript-helpers'
77

88
export interface AbiMetadata {
99
methodName: string

src/collections/custom-key-map.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { Account, internal } from '@algorandfoundation/algorand-typescript'
2-
import { DeliberateAny } from '../typescript-helpers'
1+
import type { Account } from '@algorandfoundation/algorand-typescript'
2+
import { internal } from '@algorandfoundation/algorand-typescript'
3+
import type { DeliberateAny } from '../typescript-helpers'
34
import { asBytesCls, asUint64Cls } from '../util'
45

56
type Primitive = number | bigint | string | boolean

src/context-helpers/context-util.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { internal, uint64 } from '@algorandfoundation/algorand-typescript'
2-
import { AbiMetadata } from '../abi-metadata'
1+
import type { uint64 } from '@algorandfoundation/algorand-typescript'
2+
import { internal } from '@algorandfoundation/algorand-typescript'
3+
import type { AbiMetadata } from '../abi-metadata'
34
import { ApplicationTransaction } from '../impl/transactions'
45
import { lazyContext } from './internal-context'
56

src/context-helpers/internal-context.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { Account, BaseContract, internal } from '@algorandfoundation/algorand-typescript'
2-
import { AccountData } from '../impl/account'
3-
import { ApplicationData } from '../impl/application'
4-
import { AssetData } from '../impl/asset'
5-
import { VoterData } from '../impl/voter-params'
6-
import { TransactionGroup } from '../subcontexts/transaction-context'
7-
import { TestExecutionContext } from '../test-execution-context'
1+
import type { Account } from '@algorandfoundation/algorand-typescript'
2+
import { BaseContract, internal } from '@algorandfoundation/algorand-typescript'
3+
import type { AccountData, ApplicationData, AssetData } from '../impl/reference'
4+
import type { VoterData } from '../impl/voter-params'
5+
import type { TransactionGroup } from '../subcontexts/transaction-context'
6+
import type { TestExecutionContext } from '../test-execution-context'
87

98
/**
109
* For accessing implementation specific functions, with a convenient single entry

src/decode-logs.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { bytes, op } from '@algorandfoundation/algorand-typescript'
1+
import type { bytes } from '@algorandfoundation/algorand-typescript'
2+
import { op } from '@algorandfoundation/algorand-typescript'
23
import { ABI_RETURN_VALUE_LOG_PREFIX } from './constants'
34
import { asNumber } from './util'
45

src/encoders.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { biguint, BigUint, bytes, internal, TransactionType, uint64, Uint64 } from '@algorandfoundation/algorand-typescript'
2-
import { ARC4Encoded, OnCompleteAction } from '@algorandfoundation/algorand-typescript/arc4'
3-
import { AccountCls } from './impl/account'
4-
import { ApplicationCls } from './impl/application'
5-
import { AssetCls } from './impl/asset'
1+
import type { biguint, bytes, TransactionType, uint64 } from '@algorandfoundation/algorand-typescript'
2+
import { BigUint, internal, Uint64 } from '@algorandfoundation/algorand-typescript'
3+
import type { OnCompleteAction } from '@algorandfoundation/algorand-typescript/arc4'
4+
import { ARC4Encoded } from '@algorandfoundation/algorand-typescript/arc4'
65
import { BytesBackedCls, Uint64BackedCls } from './impl/base'
76
import { arc4Encoders, encodeArc4Impl, getArc4Encoder } from './impl/encoded-types'
8-
import { DeliberateAny } from './typescript-helpers'
7+
import { AccountCls, ApplicationCls, AssetCls } from './impl/reference'
8+
import type { DeliberateAny } from './typescript-helpers'
99
import { asBytes, asMaybeBigUintCls, asMaybeBytesCls, asMaybeUint64Cls, asUint64Cls, asUint8Array, nameOfType } from './util'
1010

1111
export type TypeInfo = {

src/impl/account.ts

-105
This file was deleted.

src/impl/acct-params.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Account, Application, gtxn, internal, uint64 } from '@algorandfoundation/algorand-typescript'
1+
import type { gtxn, internal, uint64 } from '@algorandfoundation/algorand-typescript'
2+
import type { Account, Application } from '@algorandfoundation/algorand-typescript'
23
import { lazyContext } from '../context-helpers/internal-context'
34
import { asMaybeUint64Cls } from '../util'
45
import { getApp } from './app-params'

src/impl/app-global.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Application, Bytes, bytes, internal, Uint64, uint64 } from '@algorandfoundation/algorand-typescript'
1+
import type { Application, bytes, internal, uint64 } from '@algorandfoundation/algorand-typescript'
2+
import { Bytes, Uint64 } from '@algorandfoundation/algorand-typescript'
23
import { lazyContext } from '../context-helpers/internal-context'
34
import { toBytes } from '../encoders'
45
import { asBytes } from '../util'

src/impl/app-local.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Account, Application, Bytes, bytes, internal, Uint64, uint64 } from '@algorandfoundation/algorand-typescript'
1+
import type { bytes, internal, uint64, Account, Application } from '@algorandfoundation/algorand-typescript'
2+
import { Bytes, Uint64 } from '@algorandfoundation/algorand-typescript'
23
import { lazyContext } from '../context-helpers/internal-context'
34
import { toBytes } from '../encoders'
45
import { asBytes } from '../util'

src/impl/app-params.ts

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
import { Account, Application, Bytes, bytes, gtxn, internal, Uint64, uint64 } from '@algorandfoundation/algorand-typescript'
1+
import type {
2+
bytes,
3+
gtxn,
4+
internal,
5+
uint64,
6+
Account as AccountType,
7+
Application as ApplicationType,
8+
} from '@algorandfoundation/algorand-typescript'
9+
import { Bytes, Uint64 } from '@algorandfoundation/algorand-typescript'
210
import { lazyContext } from '../context-helpers/internal-context'
311
import { asMaybeUint64Cls, asUint64 } from '../util'
12+
import { Account } from './reference'
413

514
const resolveAppIndex = (appIdOrIndex: internal.primitives.StubUint64Compat): uint64 => {
615
const input = asUint64(appIdOrIndex)
@@ -11,52 +20,52 @@ const resolveAppIndex = (appIdOrIndex: internal.primitives.StubUint64Compat): ui
1120
return txn.apps(input).id
1221
}
1322

14-
export const getApp = (app: Application | internal.primitives.StubUint64Compat): Application | undefined => {
23+
export const getApp = (app: ApplicationType | internal.primitives.StubUint64Compat): ApplicationType | undefined => {
1524
try {
1625
const appId = asMaybeUint64Cls(app)
1726
if (appId !== undefined) {
1827
return lazyContext.ledger.getApplication(resolveAppIndex(appId))
1928
}
20-
return app as Application
29+
return app as ApplicationType
2130
} catch {
2231
return undefined
2332
}
2433
}
2534

2635
export const AppParams: internal.opTypes.AppParamsType = {
27-
appApprovalProgram(a: Application | internal.primitives.StubUint64Compat): readonly [bytes, boolean] {
36+
appApprovalProgram(a: ApplicationType | internal.primitives.StubUint64Compat): readonly [bytes, boolean] {
2837
const app = getApp(a)
2938
return app === undefined ? [Bytes(), false] : [app.approvalProgram, true]
3039
},
31-
appClearStateProgram(a: Application | internal.primitives.StubUint64Compat): readonly [bytes, boolean] {
40+
appClearStateProgram(a: ApplicationType | internal.primitives.StubUint64Compat): readonly [bytes, boolean] {
3241
const app = getApp(a)
3342
return app === undefined ? [Bytes(), false] : [app.clearStateProgram, true]
3443
},
35-
appGlobalNumUint(a: Application | internal.primitives.StubUint64Compat): readonly [uint64, boolean] {
44+
appGlobalNumUint(a: ApplicationType | internal.primitives.StubUint64Compat): readonly [uint64, boolean] {
3645
const app = getApp(a)
3746
return app === undefined ? [Uint64(0), false] : [app.globalNumUint, true]
3847
},
39-
appGlobalNumByteSlice(a: Application | internal.primitives.StubUint64Compat): readonly [uint64, boolean] {
48+
appGlobalNumByteSlice(a: ApplicationType | internal.primitives.StubUint64Compat): readonly [uint64, boolean] {
4049
const app = getApp(a)
4150
return app === undefined ? [Uint64(0), false] : [app.globalNumBytes, true]
4251
},
43-
appLocalNumUint(a: Application | internal.primitives.StubUint64Compat): readonly [uint64, boolean] {
52+
appLocalNumUint(a: ApplicationType | internal.primitives.StubUint64Compat): readonly [uint64, boolean] {
4453
const app = getApp(a)
4554
return app === undefined ? [Uint64(0), false] : [app.localNumUint, true]
4655
},
47-
appLocalNumByteSlice(a: Application | internal.primitives.StubUint64Compat): readonly [uint64, boolean] {
56+
appLocalNumByteSlice(a: ApplicationType | internal.primitives.StubUint64Compat): readonly [uint64, boolean] {
4857
const app = getApp(a)
4958
return app === undefined ? [Uint64(0), false] : [app.localNumBytes, true]
5059
},
51-
appExtraProgramPages(a: Application | internal.primitives.StubUint64Compat): readonly [uint64, boolean] {
60+
appExtraProgramPages(a: ApplicationType | internal.primitives.StubUint64Compat): readonly [uint64, boolean] {
5261
const app = getApp(a)
5362
return app === undefined ? [Uint64(0), false] : [app.extraProgramPages, true]
5463
},
55-
appCreator(a: Application | internal.primitives.StubUint64Compat): readonly [Account, boolean] {
64+
appCreator(a: ApplicationType | internal.primitives.StubUint64Compat): readonly [AccountType, boolean] {
5665
const app = getApp(a)
5766
return app === undefined ? [Account(), false] : [app.creator, true]
5867
},
59-
appAddress(a: Application | internal.primitives.StubUint64Compat): readonly [Account, boolean] {
68+
appAddress(a: ApplicationType | internal.primitives.StubUint64Compat): readonly [AccountType, boolean] {
6069
const app = getApp(a)
6170
return app === undefined ? [Account(), false] : [app.address, true]
6271
},

0 commit comments

Comments
 (0)