Skip to content

Commit ac5bdf5

Browse files
committed
feat: add v11 acct params functions
1 parent fa44172 commit ac5bdf5

File tree

54 files changed

+2466
-2140
lines changed

Some content is hidden

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

54 files changed

+2466
-2140
lines changed

src/impl/account.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export class AssetHolding {
2020
export class AccountData {
2121
optedAssets = new Uint64Map<AssetHolding>()
2222
optedApplications = new Uint64Map<Application>()
23+
incentiveEligible = false
24+
lastProposed?: uint64
25+
lastHeartbeat?: uint64
2326
account: Mutable<Omit<Account, 'bytes' | 'isOptedIn'>>
2427

2528
constructor() {

src/impl/acct-params.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Account, Application, gtxn, internal, uint64 } from '@algorandfoundatio
22
import { lazyContext } from '../context-helpers/internal-context'
33
import { asMaybeUint64Cls } from '../util'
44
import { getApp } from './app-params'
5+
import { Global } from './global'
56

67
export const getAccount = (acct: Account | internal.primitives.StubUint64Compat): Account => {
78
const acctId = asMaybeUint64Cls(acct)
@@ -84,14 +85,19 @@ export const AcctParams: internal.opTypes.AcctParamsType = {
8485
const acct = getAccount(a)
8586
return [acct.totalBoxBytes, acct.balance !== 0]
8687
},
87-
// TODO: implement v11 methods
88-
acctIncentiveEligible: function (_a: Account | uint64): readonly [boolean, boolean] {
89-
throw new Error('Function not implemented.')
88+
acctIncentiveEligible: function (a: Account | internal.primitives.StubUint64Compat): readonly [boolean, boolean] {
89+
const acct = getAccount(a)
90+
const accountData = lazyContext.ledger.accountDataMap.get(acct)
91+
return [accountData?.incentiveEligible ?? false, acct.balance !== 0]
9092
},
91-
acctLastProposed: function (_a: Account | uint64): readonly [uint64, boolean] {
92-
throw new Error('Function not implemented.')
93+
acctLastProposed: function (a: Account | internal.primitives.StubUint64Compat): readonly [uint64, boolean] {
94+
const acct = getAccount(a)
95+
const accountData = lazyContext.ledger.accountDataMap.get(acct)
96+
return [accountData?.lastProposed ?? Global.round, acct.balance !== 0]
9397
},
94-
acctLastHeartbeat: function (_a: Account | uint64): readonly [uint64, boolean] {
95-
throw new Error('Function not implemented.')
98+
acctLastHeartbeat: function (a: Account | internal.primitives.StubUint64Compat): readonly [uint64, boolean] {
99+
const acct = getAccount(a)
100+
const accountData = lazyContext.ledger.accountDataMap.get(acct)
101+
return [accountData?.lastHeartbeat ?? Global.round, acct.balance !== 0]
96102
},
97103
}

src/impl/transactions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ export class KeyRegistrationTransaction extends TransactionBase implements gtxn.
117117
this.voteKeyDilution = fields.voteKeyDilution ?? Uint64(0)
118118
this.nonparticipation = fields.nonparticipation ?? false
119119
this.stateProofKey = fields.stateProofKey ?? Bytes()
120+
const globalData = lazyContext.ledger.globalData
121+
if (this.fee >= globalData.payoutsGoOnlineFee && globalData.payoutsEnabled) {
122+
lazyContext.ledger.patchAccountData(this.sender, {
123+
incentiveEligible: true,
124+
})
125+
}
120126
}
121127

122128
readonly voteKey: bytes

src/subcontexts/ledger-context.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ export class LedgerContext {
112112
}
113113
}
114114

115+
patchAccountData(account: Account, data: Partial<AccountData>) {
116+
const accountData = this.accountDataMap.get(account) ?? new AccountData()
117+
this.accountDataMap.set(account, {
118+
...accountData,
119+
...data,
120+
account: {
121+
...accountData?.account,
122+
...data.account,
123+
},
124+
})
125+
}
126+
115127
setBlock(
116128
index: internal.primitives.StubUint64Compat,
117129
seed: internal.primitives.StubUint64Compat,

src/value-generators/avm.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { asBigInt, asUint64Cls, getRandomBigInt, getRandomBytes } from '../util'
99

1010
type AccountContextData = Partial<AccountData['account']> & {
1111
address?: Account
12+
incentiveEligible?: boolean
1213
optedAssetBalances?: Map<internal.primitives.StubUint64Compat, internal.primitives.StubUint64Compat>
1314
optedApplications?: Application[]
1415
}
@@ -56,7 +57,8 @@ export class AvmValueGenerator {
5657
}
5758

5859
const data = new AccountData()
59-
const { address, optedAssetBalances, optedApplications, ...accountData } = input ?? {}
60+
const { address, optedAssetBalances, optedApplications, incentiveEligible, ...accountData } = input ?? {}
61+
data.incentiveEligible = incentiveEligible ?? false
6062
data.account = {
6163
...data.account,
6264
...accountData,

tests/artifacts/state-ops/contract.algo.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ export class StateAcctParamsGetContract extends arc4.Contract {
137137
assert(funded === funded_index, 'expected funded by index to match')
138138
return value
139139
}
140+
141+
@arc4.abimethod()
142+
public verify_acct_incentive_eligible(a: Account): boolean {
143+
const [value, funded] = op.AcctParams.acctIncentiveEligible(a)
144+
const [value_index, funded_index] = op.AcctParams.acctIncentiveEligible(get_1st_ref_index())
145+
assert(value === value_index, 'expected value by index to match')
146+
assert(funded === funded_index, 'expected funded by index to match')
147+
return value
148+
}
140149
}
141150

142151
export class StateAssetHoldingContract extends arc4.Contract {

0 commit comments

Comments
 (0)