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

feat: Vesting account cannot delegate #181

Merged
merged 9 commits into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 15 additions & 27 deletions app/ante/vesting.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func NewEthVestingTransactionDecorator(ak evmtypes.AccountKeeper) EthVestingTran
// vesting cliff and lockup period.
//
// This AnteHandler decorator will fail if:
// - the message is not a MsgEthereumTx
// - sender account cannot be found
// - sender account is not a ClawbackvestingAccount
// - blocktime is before surpassing vesting cliff end (with zero vested coins) AND
// - blocktime is before surpassing all lockup periods (with non-zero locked coins)
// - the message is not a MsgEthereumTx
// - sender account cannot be found
// - sender account is not a ClawbackvestingAccount
// - blocktime is before surpassing vesting cliff end (with zero vested coins) AND
// - blocktime is before surpassing all lockup periods (with non-zero locked coins)
func (vtd EthVestingTransactionDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
for _, msg := range tx.GetMsgs() {
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
Expand Down Expand Up @@ -132,9 +132,14 @@ func (vdd VestingDelegationDecorator) validateAuthz(ctx sdk.Context, execMsg *au

// validateMsg checks that the only vested coins can be delegated
func (vdd VestingDelegationDecorator) validateMsg(ctx sdk.Context, msg sdk.Msg) error {
delegateMsg, ok := msg.(*stakingtypes.MsgDelegate)
_, ok := msg.(*stakingtypes.MsgDelegate)
msgError := "Vesting account cannot delegate"
if !ok {
return nil
_, isMsgCreateValidator := msg.(*stakingtypes.MsgCreateValidator)
if !isMsgCreateValidator {
return nil
}
msgError = "Vesting account cannot create validator"
}

for _, addr := range msg.GetSigners() {
Expand All @@ -146,30 +151,13 @@ func (vdd VestingDelegationDecorator) validateMsg(ctx sdk.Context, msg sdk.Msg)
)
}

clawbackAccount, isClawback := acc.(*vestingtypes.ClawbackVestingAccount)
_, isClawback := acc.(*vestingtypes.ClawbackVestingAccount)
if !isClawback {
// continue to next decorator as this logic only applies to vesting
return nil
}

// error if bond amount is > vested coins
bondDenom := vdd.sk.BondDenom(ctx)
coins := clawbackAccount.GetVestedOnly(ctx.BlockTime())
if coins == nil || coins.Empty() {
return sdkerrors.Wrap(
vestingtypes.ErrInsufficientVestedCoins,
"account has no vested coins",
)
continue
}

vested := coins.AmountOf(bondDenom)
if vested.LT(delegateMsg.Amount.Amount) {
return sdkerrors.Wrapf(
vestingtypes.ErrInsufficientVestedCoins,
"cannot delegate unvested coins. coins vested < delegation amount (%s < %s)",
vested, delegateMsg.Amount.Amount,
)
}
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, msgError)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions tests/vesting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (suite *KeeperTestSuite) TestCrawbackVestingAccounts() {
suite.Require().Equal(expVested, vested)

err := suite.delegate(clawbackAccount, 1)
suite.Require().NoError(err, "can delegate vested tokens")
suite.Require().Error(err, "cannot delegate vested tokens")

err = suite.app.BankKeeper.SendCoins(
suite.ctx,
Expand Down Expand Up @@ -385,7 +385,7 @@ func (suite *KeeperTestSuite) TestCrawbackVestingAccounts() {
suite.Require().Equal(expVested, vested)

err := suite.delegate(clawbackAccount, 1)
suite.Require().NoError(err, "can delegate vested tokens")
suite.Require().Error(err, "cannot delegate vested tokens")

err = suite.delegate(clawbackAccount, 30)
suite.Require().Error(err, "cannot delegate unvested tokens")
Expand Down
16 changes: 8 additions & 8 deletions x/mint/spec/01_concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ the minting mechanism presented below, with an initial inflation set to 10%.
At the genesis launch, there is a total of 1,200,000,000 ASAs distributed to Genesis Partners, Strategic Partners (Backers),
Astra Foundation, Core Team, and the Community Pool. Here are the details:

| | % | #ASAs | Minted at genesis | Vesting schedule |
|:-----------------------|-----:|--------------:|------------------:|--------------------------------------------------------------------------------------------------:|
| **Genesis Partners** | 39% | 468,000,000 | 468,000,000 | 100% minted and unlocked at genesis |
| **Strategic Partners** | 36% | 432,000,000 | 432,000,000 | 100% minted and unlocked at genesis |
| **Astra Foundation** | 10% | 120,000,000 | 120,000,000 | 100% minted and unlocked at genesis |
| **Core Team** | 10% | 120,000,000 | 120,000,000 | 50% unlocked at genesis, 50% unlocked after 1 year |
| **Community Pool** | 5% | 60,000,000 | 60,000,000 | 100% minted & locked at genesis, unlocked with GOV rules |
| **Total** | 100% | 1,200,000,000 | 1,200,000,000 | |
| | % | #ASAs | Minted at genesis | Vesting schedule |
|:-----------------------|-----:|--------------:|------------------:|---------------------------------------------------------:|
| **Genesis Partners** | 39% | 468,000,000 | 468,000,000 | 100% minted and unlocked at genesis |
| **Strategic Partners** | 36% | 432,000,000 | 432,000,000 | 100% minted and unlocked at genesis |
| **Astra Foundation** | 10% | 120,000,000 | 120,000,000 | 100% minted and unlocked at genesis |
| **Core Team** | 10% | 120,000,000 | 120,000,000 | 100* minted and unlocked at genesis |
| **Community Pool** | 5% | 60,000,000 | 60,000,000 | 100% minted & locked at genesis, unlocked with GOV rules |
| **Total** | 100% | 1,200,000,000 | 1,200,000,000 | |

## The Minting Mechanism

Expand Down