Skip to content

Commit

Permalink
refactor: remove n and m parameters from UFixedNxM constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
boblat committed Nov 20, 2024
1 parent be7cc30 commit 334848f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"algo-ts:build": "cd packages/algo-ts && npm run build",
"algo-ts:build:watch": "cd packages/algo-ts && npm run build:3-build:watch",
"algo-ts:install": "npm i -D @algorandfoundation/algorand-typescript@./packages/algo-ts/dist",
"npm-install-all": "cd packages/algo-ts && npm i && npm run build && cd ../algo-ts-testing && npm i && npm run build && cd ../../ && npm i",
"npm-install-all": "cd packages/algo-ts && npm i && npm run build && cd ../../ && npm i",
"script:op-types": "tsx ./scripts/generate-op-types.ts packages/algo-ts/src/op-types.ts && cd packages/algo-ts && eslint src/op-types.ts --fix",
"script:op-metadata": "tsx ./scripts/generate-op-metadata.ts src/awst_build/op-metadata.ts && eslint src/awst_build/op-metadata.ts --fix",
"script:op-ptypes": "tsx ./scripts/generate-op-ptypes.ts src/awst_build/ptypes/op-ptypes.ts && eslint src/awst_build/ptypes/op-ptypes.ts --fix"
Expand Down
10 changes: 5 additions & 5 deletions packages/algo-ts/src/arc4/encoded-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export abstract class ARC4Encoded implements BytesBacked {
return this.bytes.equals(other.bytes)
}

static fromBytes<T extends ARC4Encoded>(this: { new(...args: DeliberateAny): T }, bytes: BytesCompat): T {
static fromBytes<T extends ARC4Encoded>(this: { new (...args: DeliberateAny): T }, bytes: BytesCompat): T {
throw new Error('todo')
}

static fromLog<T extends ARC4Encoded>(this: { new(...args: DeliberateAny): T }, log: BytesCompat): T {
static fromLog<T extends ARC4Encoded>(this: { new (...args: DeliberateAny): T }, log: BytesCompat): T {
throw new Error('todo')
}
}
Expand Down Expand Up @@ -51,7 +51,7 @@ export class UintN<N extends BitSize> extends ARC4Encoded {
}
export class UFixedNxM<N extends BitSize, M extends number> extends ARC4Encoded {
__type?: `arc4.UFixedNxM<${N}x${M}>`
constructor(v: `${number}.${number}`, n?: N, m?: M) {
constructor(v: `${number}.${number}`) {
super()
}

Expand Down Expand Up @@ -218,8 +218,8 @@ export class DynamicArray<TItem extends ARC4Encoded> extends Arc4ReadonlyArray<T
}
type ExpandTupleType<T extends ARC4Encoded[]> = T extends [infer T1 extends ARC4Encoded, ...infer TRest extends ARC4Encoded[]]
? TRest extends []
? `${T1['__type']}`
: `${T1['__type']},${ExpandTupleType<TRest>}`
? `${T1['__type']}`
: `${T1['__type']},${ExpandTupleType<TRest>}`
: ''

export class Tuple<TTuple extends [ARC4Encoded, ...ARC4Encoded[]]> extends ARC4Encoded {
Expand Down
2 changes: 1 addition & 1 deletion packages/algo-ts/src/impl/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class BytesCls extends AlgoTsPrimitiveCls {
return new BytesCls(arrayUtil.arrayAt(this.#v, i))
}

slice(start: undefined | StubUint64Compat, end: undefined | StubUint64Compat): BytesCls {
slice(start?: StubUint64Compat, end?: StubUint64Compat): BytesCls {
const sliced = arrayUtil.arraySlice(this.#v, start, end)
return new BytesCls(sliced)
}
Expand Down
1 change: 0 additions & 1 deletion src/awst_build/context/awst-build-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { TypeResolver } from '../type-resolver'
import { EvaluationContext } from './evaluation-context'
import { SwitchLoopContext } from './switch-loop-context'
import { UniqueNameResolver } from './unique-name-resolver'
import type { LogicSigClassModel } from '../models/logic-sig-class-model'

export interface AwstBuildContext {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/awst_build/eb/arc4/ufixed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { SourceLocation } from '../../../awst/source-location'
import { CodeError } from '../../../errors'
import { codeInvariant, invariant } from '../../../util'
import type { PType } from '../../ptypes'
import { numberPType, NumericLiteralPType, stringPType } from '../../ptypes'
import { NumericLiteralPType, stringPType } from '../../ptypes'
import { UFixedNxMClass, UFixedNxMType } from '../../ptypes/arc4-types'
import { type InstanceBuilder, type NodeBuilder } from '../index'
import { isValidLiteralForPType, requireStringConstant } from '../util'
Expand All @@ -23,7 +23,7 @@ export class UFixedNxMClassBuilder extends Arc4EncodedBaseClassBuilder {
typeArgs,
genericTypeArgs: 2,
funcName: this.typeDescription,
argSpec: (a) => [a.optional(stringPType), a.optional(numberPType), a.optional(numberPType)],
argSpec: (a) => [a.optional(stringPType)],
callLocation: sourceLocation,
})
codeInvariant(
Expand Down
3 changes: 2 additions & 1 deletion tests/approvals/arc4-types.algo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { assert, BaseContract, Bytes, Txn } from '@algorandfoundation/algorand-t
import { Address, Byte, DynamicArray, StaticArray, Str, Tuple, UFixedNxM, UintN } from '@algorandfoundation/algorand-typescript/arc4'

function testUFixed() {
const a = new UFixedNxM('1.244', 32, 4)
const a = new UFixedNxM<32, 4>('1.244')
const c = new UFixedNxM<32, 4>('1.244')

assert(a.equals(c))
Expand Down Expand Up @@ -84,6 +84,7 @@ export class Arc4TypesTestContract extends BaseContract {
const x = new ARC4Uint64()
testStr()
test(1, 2n, new UintN<256>(4))
testUFixed()
testByte()
testArrays(new UintN<64>(65))
testAddress()
Expand Down

0 comments on commit 334848f

Please sign in to comment.