Skip to content

Commit fa44172

Browse files
committed
feat: add v11 global fields
1 parent 0853b82 commit fa44172

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

src/impl/global.ts

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export class GlobalData {
2525
assetOptInMinBalance: uint64
2626
genesisHash: bytes
2727
opcodeBudget?: uint64
28+
payoutsEnabled: boolean
29+
payoutsGoOnlineFee: uint64
30+
payoutsPercent: uint64
31+
payoutsMinBalance: uint64
2832

2933
constructor() {
3034
this.minTxnFee = Uint64(MIN_TXN_FEE)
@@ -35,6 +39,10 @@ export class GlobalData {
3539
this.assetCreateMinBalance = Uint64(DEFAULT_ASSET_CREATE_MIN_BALANCE)
3640
this.assetOptInMinBalance = Uint64(DEFAULT_ASSET_OPT_IN_MIN_BALANCE)
3741
this.genesisHash = DEFAULT_GLOBAL_GENESIS_HASH
42+
this.payoutsEnabled = false
43+
this.payoutsGoOnlineFee = Uint64(0)
44+
this.payoutsPercent = Uint64(0)
45+
this.payoutsMinBalance = Uint64(0)
3846
}
3947
}
4048
const getGlobalData = (): GlobalData => {
@@ -184,10 +192,44 @@ export const Global: internal.opTypes.GlobalType = {
184192
get genesisHash(): bytes {
185193
return getGlobalData().genesisHash
186194
},
187-
payoutsEnabled: false,
188-
// TODO: implement v11 fields
189-
payoutsGoOnlineFee: 0,
190-
payoutsPercent: 0,
191-
payoutsMinBalance: 0,
192-
payoutsMaxBalance: 0,
195+
196+
/**
197+
* Whether block proposal payouts are enabled.
198+
* Min AVM version: 11
199+
*/
200+
get payoutsEnabled(): boolean {
201+
return getGlobalData().payoutsEnabled
202+
},
203+
204+
/**
205+
* The fee required in a keyreg transaction to make an account incentive eligible.
206+
* Min AVM version: 11
207+
*/
208+
get payoutsGoOnlineFee(): uint64 {
209+
return getGlobalData().payoutsGoOnlineFee
210+
},
211+
212+
/**
213+
* The percentage of transaction fees in a block that can be paid to the block proposer.
214+
* Min AVM version: 11
215+
*/
216+
get payoutsPercent(): uint64 {
217+
return getGlobalData().payoutsPercent
218+
},
219+
220+
/**
221+
* The minimum algo balance an account must have in the agreement round to receive block payouts in the proposal round.
222+
* Min AVM version: 11
223+
*/
224+
get payoutsMinBalance(): uint64 {
225+
return getGlobalData().payoutsMinBalance
226+
},
227+
228+
/**
229+
* The maximum algo balance an account can have in the agreement round to receive block payouts in the proposal round.
230+
* Min AVM version: 11
231+
*/
232+
get payoutsMaxBalance(): uint64 {
233+
return getGlobalData().payoutsMinBalance
234+
},
193235
}

tests/state-op-codes.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ describe('State op codes', async () => {
272272
})
273273
expect([...asUint8Array(firstGroupId)]).not.toEqual([...asUint8Array(secondGroupId)])
274274
expect(firstTimestamp.valueOf()).not.toEqual(secondTimestamp.valueOf())
275+
276+
ctx.ledger.patchGlobalData({
277+
payoutsEnabled: true,
278+
payoutsGoOnlineFee: 12,
279+
payoutsPercent: 2,
280+
payoutsMinBalance: 42,
281+
})
282+
283+
expect(op.Global.payoutsEnabled).toEqual(true)
284+
expect(op.Global.payoutsGoOnlineFee).toEqual(12)
285+
expect(op.Global.payoutsPercent).toEqual(2)
286+
expect(op.Global.payoutsMinBalance).toEqual(42)
275287
})
276288
})
277289

0 commit comments

Comments
 (0)