-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Labels
help wantedExtra attention is neededExtra attention is neededwontfixThis will not be worked onThis will not be worked on
Description
Currently we call WithdrawRewards for each staking coin denom, which sends rewards for that denom to the farmer:
farming/x/farming/keeper/staking.go
Lines 280 to 301 in debb2e6
| for _, coin := range amount { | |
| staking, found := k.GetStaking(ctx, coin.Denom, farmerAcc) | |
| if !found { | |
| staking.Amount = sdk.ZeroInt() | |
| } | |
| queuedStaking, found := k.GetQueuedStaking(ctx, coin.Denom, farmerAcc) | |
| if !found { | |
| queuedStaking.Amount = sdk.ZeroInt() | |
| } | |
| availableAmt := staking.Amount.Add(queuedStaking.Amount) | |
| if availableAmt.LT(coin.Amount) { | |
| return sdkerrors.Wrapf( | |
| sdkerrors.ErrInsufficientFunds, "%s%s is smaller than %s%s", availableAmt, coin.Denom, coin.Amount, coin.Denom) | |
| } | |
| queuedStaking.Amount = queuedStaking.Amount.Sub(coin.Amount) | |
| if queuedStaking.Amount.IsNegative() { | |
| if _, err := k.WithdrawRewards(ctx, farmerAcc, coin.Denom); err != nil { | |
| return err | |
| } |
We can optimize this to send total rewards only once at the end of the function.
To do this, we should change WithdrawRewards to not send coins, instead return just sdk.Coins.
But we need to discuss more about this optimization. It just reduces gas cost of MsgUnstake.
Metadata
Metadata
Assignees
Labels
help wantedExtra attention is neededExtra attention is neededwontfixThis will not be worked onThis will not be worked on