feat(rewarding): add AutoDeposit compound bridge for IIP-59 (PR 4.6)#4922
Draft
envestcc wants to merge 1 commit into
Draft
feat(rewarding): add AutoDeposit compound bridge for IIP-59 (PR 4.6)#4922envestcc wants to merge 1 commit into
envestcc wants to merge 1 commit into
Conversation
…ound routing
Introduce a read-only bridge to the on-chain AutoDeposit contract so PR 3'
(distributeVoterReward rework) can decide per-voter compound-vs-credit
routing at epoch reward distribution time per IIP-59 §3.6.
- New action/protocol/rewarding/autodeposit package:
* Bridge: stateless wrapper around the pinned AutoDeposit contract,
exposing LookupBucket(ctx, reader, voter) → (bucketID, present, err).
* ContractReader: package-local view-call primitive so unit tests can
stand in a fake without pulling the EVM simulator into scope.
* Route / Decision types with wire format shared with PR 4.7's
DelegateDistributed.routings[] encoding.
* IsBucketEligibleForCompound helper applies §3.6 preconditions 2-4
(bucket exists, native bucket, AutoStake=true, active, Owner==voter).
* Structurally mirrors PR 4.5's delegateprofile.Bridge so both bridges
present a uniform surface to callers.
- Per-item fallback semantic (IIP-59 §3.6): malformed on-chain data
(negative int256, oversized-for-uint64 value) silent-fallbacks to
RouteCredit rather than erroring the block. Only wiring bugs (nil
reader, nil voter, ABI drift, RPC error) hard-error.
- New genesis field Blockchain.AutoDepositContractAddress with empty
default (compound routing inactive → every voter share → unclaimedBalance).
- New exported staking.VoteBucket.IsUnstaked() and IsNative() wrappers so
the autodeposit package can gate eligibility without duplicating the
staking-internal invariants.
AutoDeposit is read live at drain time, not frozen at PutPollResult
(unlike DelegateProfile) — see IIP-59 §3.6.
Ships independently of the earlier stack (PR 4.5 / PR 2') since it shares
no code with them.
|
This was referenced Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Adds a read-only bridge to the on-chain AutoDeposit contract so the (upcoming) PR 3' rework of
distributeVoterRewardcan decide per-voter compound-vs-credit routing at epoch reward distribution time, per IIP-59 §3.6.Structural clone of PR 4.5's
delegateprofile.Bridge— same shape, same ContractReader interface, same per-item fallback discipline — so both on-chain reads present a uniform surface.What lands
New package
action/protocol/rewarding/autodepositBridgewraps a pinned contract deployment;LookupBucket(ctx, reader, voter)returns(bucketID, present, err).ContractReaderis package-local so tests can supply a fake without pulling the EVM simulator into scope.Route/Decisiontypes match IIP-59 §3.5'sDelegateDistributed.routings[]wire encoding, giving PR 4.7 a single source of truth.IsBucketEligibleForCompoundapplies §3.6 preconditions 2–4 (bucket exists, is native,AutoStake==true, currently active,Owner==voter). Precondition 1 (positive bucket ID) is enforced insideLookupBucket.Semantics
Per IIP-59 §3.6 the drain path must not halt on a single voter's malformed registration:
LookupBucketresult(id, true, nil)(0, false, nil)— silent fallback to credit(0, false, err)— wiring bug, hard errorGenesis
Blockchain.AutoDepositContractAddressfield, default empty. Empty means compound routing is inactive and every voter share is credited tounclaimedBalancefor pull-claim — functionally identical to legacy behaviour, so no fork gate churn.Staking
VoteBucket.IsUnstaked()andIsNative()wrappers on top of the existing unexported predicates, so theautodepositeligibility helper doesn't have to duplicate staking-internal invariants.Explicit non-goals
AddDepositinvocation. Applying the compound (mutating bucket state) is PR 3''s job via staking's nativehandler_stake_add_deposit.gopath.PutPollResult.paused()/registrants()reads. Neither affects routing (paused()blocks writes; view calls always succeed;registrants()is redundant becausebucket(voter)==0already means unregistered).LookupBucketper voter; total volume is bounded (~2k reads/epoch per spec).Feature-flag matrix
NoVoterRewardDistributionAutoDepositContractAddressunclaimedBalance.bucket(voter)+ eligibility → compound; else credit.Test plan
go build ./...cleangofmt -lclean on touched filesgo vetclean on touched packagesgo test ./action/protocol/rewarding/autodeposit/... -count=1 -v— 20 tests, all greengo test ./action/protocol/rewarding/... ./action/protocol/staking/... ./blockchain/genesis/... -count=1— 426 tests, all greenbridge_test.goTestLookupBucket_CallDataShapeguards against ABI drift by asserting selectorkeccak256("bucket(address)")[:4]and address layout in the encoded call data.Stack
Branched from
upstream/masterdirectly rather than stacking on the earlier IIP-59 PRs — this PR shares no code with them, so a flat branch means cleaner review and no rebase pressure if PR 4.5 / PR 2' churn.distributeVoterReward), PR 4.7 (batchedDelegateDistributedlog).🤖 Generated with Claude Code