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

fix: clawback before vesting start time #483

Merged
merged 4 commits into from
Apr 15, 2022
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

- (fees) [\#436](https://github.com/tharsis/evmos/pull/436) Add `x/fees` module.

### Bug Fixes

- (vesting) [\#483](https://github.com/tharsis/evmos/pull/483) Fix balance clawback when vesting start time is in the future

## [v3.0.0] - 2022-04-05

### State Machine Breaking
Expand Down
7 changes: 6 additions & 1 deletion x/vesting/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (k Keeper) Clawback(
)
}

// Chech if account exists
// Check if account exists
acc := ak.GetAccount(ctx, addr)
if acc == nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrNotFound, "account %s does not exist", msg.AccountAddress)
Expand All @@ -188,6 +188,11 @@ func (k Keeper) Clawback(
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "clawback can only be requested by original funder %s", va.FunderAddress)
}

// Return error if clawback is attempted before start time
if ctx.BlockTime().Before(va.StartTime) {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "clawback can only be executed after vesting begins: %s", va.FunderAddress)
}

// Perform clawback transfer
if err := k.transferClawback(ctx, *va, dest); err != nil {
return nil, err
Expand Down
20 changes: 18 additions & 2 deletions x/vesting/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func (suite *KeeperTestSuite) TestMsgClawback() {
funder sdk.AccAddress
addr sdk.AccAddress
dest sdk.AccAddress
startTime time.Time
expectedPass bool
}{
{
Expand All @@ -232,6 +233,7 @@ func (suite *KeeperTestSuite) TestMsgClawback() {
addr,
sdk.AccAddress(tests.GenerateAddress().Bytes()),
addr3,
suite.ctx.BlockTime(),
false,
},
{
Expand All @@ -244,6 +246,7 @@ func (suite *KeeperTestSuite) TestMsgClawback() {
addr,
addr4,
addr3,
suite.ctx.BlockTime(),
false,
},
{
Expand All @@ -252,6 +255,17 @@ func (suite *KeeperTestSuite) TestMsgClawback() {
addr3,
addr2,
addr3,
suite.ctx.BlockTime(),
false,
},
{
"before start time",
func() {
},
addr,
addr2,
addr3,
suite.ctx.BlockTime().Add(time.Hour),
false,
},
{
Expand All @@ -261,6 +275,7 @@ func (suite *KeeperTestSuite) TestMsgClawback() {
addr,
addr2,
addr3,
suite.ctx.BlockTime(),
true,
},
{
Expand All @@ -270,6 +285,7 @@ func (suite *KeeperTestSuite) TestMsgClawback() {
addr,
addr2,
sdk.AccAddress([]byte{}),
suite.ctx.BlockTime(),
true,
},
}
Expand All @@ -283,8 +299,8 @@ func (suite *KeeperTestSuite) TestMsgClawback() {
suite.app.AccountKeeper.SetAccount(suite.ctx, funder)
testutil.FundAccount(suite.app.BankKeeper, suite.ctx, addr, balances)

// Create Clawnback Vesting Account
createMsg := types.NewMsgCreateClawbackVestingAccount(addr, addr2, suite.ctx.BlockTime(), lockupPeriods, vestingPeriods, false)
// Create Clawback Vesting Account
createMsg := types.NewMsgCreateClawbackVestingAccount(addr, addr2, tc.startTime, lockupPeriods, vestingPeriods, false)
createRes, err := suite.app.VestingKeeper.CreateClawbackVestingAccount(ctx, createMsg)
suite.Require().NoError(err)
suite.Require().NotNil(createRes)
Expand Down
9 changes: 8 additions & 1 deletion x/vesting/types/clawback_vesting_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,17 @@ func (va ClawbackVestingAccount) GetPassedPeriodCount(blockTime time.Time) int {
func (va ClawbackVestingAccount) ComputeClawback(
clawbackTime int64,
) (ClawbackVestingAccount, sdk.Coins) {
// if the clawback time is before the vesting start time, perform a no-op
// as there is nothing to clawback
// NOTE: error must be checked during message execution
if clawbackTime < va.GetStartTime() {
return va, sdk.Coins{}
}

totalVested := va.GetVestedOnly(time.Unix(clawbackTime, 0))
totalUnvested := va.GetUnvestedOnly(time.Unix(clawbackTime, 0))

// Remove all unvested periods from the schdule
// Remove all unvested periods from the schedule
passedPeriodID := va.GetPassedPeriodCount(time.Unix(clawbackTime, 0))
newVestingPeriods := va.VestingPeriods[:passedPeriodID]

Expand Down
8 changes: 8 additions & 0 deletions x/vesting/types/clawback_vesting_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,14 @@ func (suite *VestingAccountTestSuite) TestComputeClawback() {
expLockupPeriods []sdkvesting.Period
expVestingPeriods []sdkvesting.Period
}{
{
"clawback before start time, no-op",
now.Add(-time.Hour).Unix(),
sdk.Coins{},
origCoins,
lockupPeriods,
vestingPeriods,
},
{
"clawback everything before any period passes",
now.Unix(),
Expand Down