Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add claim rewards ica #961

Merged
merged 19 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
18b3e3e
airdrop testing
riley-stride Mar 28, 2023
db50e48
merge
riley-stride May 2, 2023
c5a94dd
Merge branch 'main' of ssh://github.com/Stride-Labs/stride
riley-stride May 27, 2023
4509194
Merge branch 'main' of ssh://github.com/Stride-Labs/stride
riley-stride Aug 21, 2023
d85a004
Merge branch 'main' of ssh://github.com/Stride-Labs/stride
riley-stride Sep 14, 2023
64b4dbb
Merge branch 'main' of ssh://github.com/Stride-Labs/stride
riley-stride Sep 20, 2023
6ff129b
Merge branch 'main' of ssh://github.com/Stride-Labs/stride
riley-stride Oct 25, 2023
aeaf4ef
feat: claim accrued staking rewards epochly
riley-stride Oct 25, 2023
6f1c436
claim working
riley-stride Nov 7, 2023
b3c2c88
Merge branch 'main' into add-claim-rewards-ica
riley-stride Nov 7, 2023
393708b
batch claimReward ICAs
riley-stride Nov 30, 2023
8479b3f
address sam pr comments
riley-stride Nov 30, 2023
35e7498
refactor batching
riley-stride Dec 6, 2023
8b9393a
only submit claim msgs if any exist
riley-stride Dec 6, 2023
8326927
Merge branch 'main' into add-claim-rewards-ica
riley-stride Dec 6, 2023
3f7aacd
reference actual ClaimRewardsICABatchSize in test
riley-stride Dec 6, 2023
d308057
Merge branch 'add-claim-rewards-ica' of ssh://github.com/Stride-Labs/…
riley-stride Dec 6, 2023
1141cf7
Merge branch 'main' into add-claim-rewards-ica
riley-stride Dec 7, 2023
cff7d45
Merge branch 'main' into add-claim-rewards-ica
riley-stride Dec 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions x/stakeibc/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochInfo epochstypes.EpochInf
delegationInterval := k.GetParam(ctx, types.KeyDelegateInterval)
reinvestInterval := k.GetParam(ctx, types.KeyReinvestInterval)

// Claim accrued staking rewards at the beginning of the epoch
k.ClaimAccruedStakingRewards(ctx)

// Create a new deposit record for each host zone and the grab all deposit records
k.CreateDepositRecordsForEpoch(ctx, epochNumber)
depositRecords := k.RecordsKeeper.GetAllDepositRecord(ctx)
Expand Down Expand Up @@ -148,6 +151,18 @@ func (k Keeper) SetWithdrawalAddress(ctx sdk.Context) {
}
}

// Claim staking rewards for each host zone
func (k Keeper) ClaimAccruedStakingRewards(ctx sdk.Context) {
k.Logger(ctx).Info("Claiming Accrued Staking Rewards...")

for _, hostZone := range k.GetAllActiveHostZone(ctx) {
err := k.ClaimAccruedStakingRewardsOnHost(ctx, hostZone)
if err != nil {
k.Logger(ctx).Error(fmt.Sprintf("Unable to claim accrued staking rewards on %s, err: %s", hostZone.ChainId, err))
}
}
}

// Updates the redemption rate for each host zone
// At a high level, the redemption rate is equal to the amount of native tokens locked divided by the stTokens in existence.
// The equation is broken down further into the following sub-components:
Expand Down
49 changes: 49 additions & 0 deletions x/stakeibc/keeper/msg_server_submit_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,55 @@ func (k Keeper) SetWithdrawalAddressOnHost(ctx sdk.Context, hostZone types.HostZ
return nil
}

func (k Keeper) ClaimAccruedStakingRewardsOnHost(ctx sdk.Context, hostZone types.HostZone) error {
// The relevant ICA is the delegate account
owner := types.FormatICAAccountOwner(hostZone.ChainId, types.ICAAccountType_DELEGATION)
portID, err := icatypes.NewControllerPortID(owner)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "%s has no associated portId", owner)
}
connectionId, err := k.GetConnectionId(ctx, portID)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidChainID, "%s has no associated connection", portID)
}
sampocs marked this conversation as resolved.
Show resolved Hide resolved

// Fetch the relevant ICA
if hostZone.DelegationIcaAddress == "" {
k.Logger(ctx).Error(fmt.Sprintf("Zone %s is missing a delegation address!", hostZone.ChainId))
return nil
}

if hostZone.WithdrawalIcaAddress == "" {
k.Logger(ctx).Error(fmt.Sprintf("Zone %s is missing a withdrawal address!", hostZone.ChainId))
return nil
}
sampocs marked this conversation as resolved.
Show resolved Hide resolved
k.Logger(ctx).Info(utils.LogWithHostZone(hostZone.ChainId, "Withdrawal Address: %s, Delegator Address: %s",
hostZone.WithdrawalIcaAddress, hostZone.DelegationIcaAddress))

validators := hostZone.Validators
// build multi-message transaction to withdraw rewards from each validator
msgs := make([]proto.Message, 0, len(validators))
sampocs marked this conversation as resolved.
Show resolved Hide resolved
for _, Val := range validators {
sampocs marked this conversation as resolved.
Show resolved Hide resolved

// skip withdrawing rewards
if Val.Delegation.IsZero() {
continue
}
msg := &distributiontypes.MsgWithdrawDelegatorReward{
DelegatorAddress: hostZone.DelegationIcaAddress,
ValidatorAddress: Val.Address,
}
msgs = append(msgs, msg)
}

_, err = k.SubmitTxsStrideEpoch(ctx, connectionId, msgs, types.ICAAccountType_DELEGATION, "", nil)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to SubmitTxs for %s, %s, %s", connectionId, hostZone.ChainId, msgs)
sampocs marked this conversation as resolved.
Show resolved Hide resolved
}

return nil
}

// Submits an ICQ for the withdrawal account balance
func (k Keeper) UpdateWithdrawalBalance(ctx sdk.Context, hostZone types.HostZone) error {
k.Logger(ctx).Info(utils.LogWithHostZone(hostZone.ChainId, "Submitting ICQ for withdrawal account balance"))
Expand Down
Loading