Skip to content

Instantly share code, notes, and snippets.

@Reecepbcups
Created February 22, 2024 20:44
Show Gist options
  • Save Reecepbcups/9223b82dea076b836fded88792a678fb to your computer and use it in GitHub Desktop.
Save Reecepbcups/9223b82dea076b836fded88792a678fb to your computer and use it in GitHub Desktop.
Blocks vesting accounts from delegating their tokens to validators.
package decorators
// reference: https://x.com/gtx360ti/status/1760400114361725279
// Stratos VC sells $1,609,926 by staking their "locked" tokens ($DYM), earnings rewards on these vested funds
// and selling the rewards. Recouping their entire investment within 3 weeks of mainnet despite not touching
// any of the locked funds.
import (
"fmt"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// ante handler decorator
type MsgFilterDecorator struct {
AuthKeeper authkeeper.AccountKeeper
}
// AnteHandle performs an AnteHandler check that returns an error if the tx contains a message that is not allowed
func (mfd MsgFilterDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
if mfd.isInsiderTryingToDumpOnRetailWithQuoteLockedFundsUnQuote(ctx, tx.GetMsgs()) {
currHeight := ctx.BlockHeight()
return ctx, fmt.Errorf("tx contains unsupported message types at height %d", currHeight)
}
return next(ctx, tx, simulate)
}
// block from delegating with vesting accounts.
func (mfd MsgFilterDecorator) isInsiderTryingToDumpOnRetailWithQuoteLockedFundsUnQuote(ctx sdk.Context, msgs []sdk.Msg) bool {
for _, msg := range msgs {
for _, signer := range msg.GetSigners() {
accType := mfd.AuthKeeper.GetAccount(ctx, signer)
isVesting := false
switch accType.(type) {
case *vestingtypes.ContinuousVestingAccount:
isVesting = true
case *vestingtypes.DelayedVestingAccount:
isVesting = true
case *vestingtypes.PeriodicVestingAccount:
isVesting = true
}
// TODO: nested Authz msg check here
if isVesting {
if _, ok := msg.(*stakingtypes.MsgDelegate); ok {
return true
}
}
}
}
return false
}
@Reecepbcups
Copy link
Author

Reecepbcups commented Jul 21, 2024

Add a vacc.GetVestingCoins(sdkCtx.BlockTime()).IsZero() check instead of blank disable from https://github.com/alexanderbez/novestingyield/tree/main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment