-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add msg_server_withdraw_tip_legacy for tips before
upgrade
- Loading branch information
1 parent
acb3267
commit 77d55ab
Showing
10 changed files
with
1,614 additions
and
144 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
layertypes "github.com/tellor-io/layer/types" | ||
"github.com/tellor-io/layer/x/reporter/types" | ||
|
||
"cosmossdk.io/math" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
||
// Msg: WithdrawTipLegacy, allows selectors to directly withdraw reporting rewards and stake them with a BONDED validator | ||
func (k msgServer) WithdrawTipLegacy(goCtx context.Context, msg *types.MsgWithdrawTipLegacy) (*types.MsgWithdrawTipLegacyResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
delAddr := sdk.MustAccAddressFromBech32(msg.SelectorAddress) | ||
shares, err := k.Keeper.SelectorTips.Get(ctx, delAddr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) | ||
if err != nil { | ||
return nil, err | ||
} | ||
val, err := k.stakingKeeper.GetValidator(ctx, valAddr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if !val.IsBonded() { | ||
return nil, errors.New("chosen validator must be bonded") | ||
} | ||
amtToDelegate := shares.TruncateInt() | ||
if amtToDelegate.IsZero() { | ||
return nil, errors.New("no tips to withdraw") | ||
} | ||
_, err = k.Keeper.stakingKeeper.Delegate(ctx, delAddr, amtToDelegate, val.Status, val, false) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// isolate decimals from shares | ||
remainder := shares.Sub(shares.TruncateDec()) | ||
if remainder.IsZero() { | ||
err = k.Keeper.SelectorTips.Remove(ctx, delAddr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
err = k.Keeper.SelectorTips.Set(ctx, delAddr, remainder) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
// send coins | ||
err = k.Keeper.bankKeeper.SendCoinsFromModuleToModule(ctx, types.TipsEscrowPool, stakingtypes.BondedPoolName, sdk.NewCoins(sdk.NewCoin(layertypes.BondDenom, math.NewInt(int64(amtToDelegate.Uint64()))))) | ||
if err != nil { | ||
return nil, err | ||
} | ||
ctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
"tip_withdrawn", | ||
sdk.NewAttribute("selector", msg.SelectorAddress), | ||
sdk.NewAttribute("validator", msg.ValidatorAddress), | ||
sdk.NewAttribute("amount", amtToDelegate.String()), | ||
), | ||
}) | ||
return &types.MsgWithdrawTipLegacyResponse{}, nil | ||
} |
Oops, something went wrong.