1- import type { Account , Application , Asset , bytes , contract , LocalState } from '@algorandfoundation/algorand-typescript'
1+ import type { Account , Application , Asset , contract , LocalState } from '@algorandfoundation/algorand-typescript'
2+ import type { ARC4Encoded } from '@algorandfoundation/algorand-typescript/arc4'
23import type { AbiMetadata } from '../abi-metadata'
34import { copyAbiMetadatas , getArc4Selector , getContractAbiMetadata , getContractMethodAbiMetadata , isContractProxy } from '../abi-metadata'
45import { BytesMap } from '../collections/custom-key-map'
56import { checkRoutingConditions } from '../context-helpers/context-util'
67import { lazyContext } from '../context-helpers/internal-context'
7- import { toBytes , type TypeInfo } from '../encoders'
8+ import { type TypeInfo } from '../encoders'
89import { CodeError } from '../errors'
910import { BaseContract , ContractOptionsSymbol } from '../impl/base-contract'
1011import { Contract } from '../impl/contract'
12+ import { getArc4Encoded , UintNImpl } from '../impl/encoded-types'
1113import { Bytes } from '../impl/primitives'
1214import { AccountCls , ApplicationCls , AssetCls } from '../impl/reference'
1315import { BoxCls , BoxMapCls , BoxRefCls , GlobalStateCls } from '../impl/state'
@@ -22,7 +24,6 @@ import {
2224} from '../impl/transactions'
2325import { getGenericTypeInfo } from '../runtime-helpers'
2426import type { DeliberateAny , IConstructor } from '../typescript-helpers'
25-
2627type ContractOptionsParameter = Parameters < typeof contract > [ 0 ]
2728
2829type StateTotals = Pick < Application , 'globalNumBytes' | 'globalNumUint' | 'localNumBytes' | 'localNumUint' >
@@ -80,28 +81,43 @@ const extractStates = (contract: BaseContract, contractOptions: ContractOptionsP
8081 return states
8182}
8283
84+ const getUintN8Impl = ( value : number ) => new UintNImpl ( { name : 'UintN<8>' , genericArgs : [ { name : '8' } ] } , value )
85+
8386const extractArraysFromArgs = ( app : Application , methodSelector : Uint8Array , args : DeliberateAny [ ] ) => {
8487 const transactions : Transaction [ ] = [ ]
85- const accounts : Account [ ] = [ ]
88+ const accounts : Account [ ] = [ lazyContext . defaultSender ]
8689 const apps : Application [ ] = [ app ]
8790 const assets : Asset [ ] = [ ]
88- const appArgs : bytes [ ] = [ ]
91+ let appArgs : ARC4Encoded [ ] = [ ]
8992
9093 for ( const arg of args ) {
9194 if ( isTransaction ( arg ) ) {
9295 transactions . push ( arg )
9396 } else if ( arg instanceof AccountCls ) {
94- appArgs . push ( toBytes ( accounts . length ) )
97+ appArgs . push ( getUintN8Impl ( accounts . length ) )
9598 accounts . push ( arg as Account )
9699 } else if ( arg instanceof ApplicationCls ) {
97- appArgs . push ( toBytes ( apps . length ) )
100+ appArgs . push ( getUintN8Impl ( apps . length ) )
98101 apps . push ( arg as Application )
99102 } else if ( arg instanceof AssetCls ) {
100- appArgs . push ( toBytes ( assets . length ) )
103+ appArgs . push ( getUintN8Impl ( assets . length ) )
101104 assets . push ( arg as Asset )
105+ } else {
106+ appArgs . push ( arg )
102107 }
103108 }
104- return { accounts, apps, assets, transactions, appArgs : [ Bytes ( methodSelector ) , ...appArgs ] }
109+
110+ if ( appArgs . length > 15 ) {
111+ const packed = getArc4Encoded ( appArgs . slice ( 14 ) )
112+ appArgs = [ ...appArgs . slice ( 0 , 14 ) , packed ]
113+ }
114+ return {
115+ accounts,
116+ apps,
117+ assets,
118+ transactions,
119+ appArgs : [ Bytes ( methodSelector ) , ...appArgs . filter ( ( a ) => a !== undefined ) . map ( ( a ) => a . bytes ) ] ,
120+ }
105121}
106122
107123function isTransaction ( obj : unknown ) : obj is Transaction {
0 commit comments