From 2d16ac3065ad346b7ae462ff76be9693538b92af Mon Sep 17 00:00:00 2001 From: hoanguyenkh Date: Fri, 17 Mar 2023 14:13:45 +0700 Subject: [PATCH 1/9] fix: fix validate vesting account --- app/ante/vesting.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/ante/vesting.go b/app/ante/vesting.go index 146a931..0dbe8f1 100644 --- a/app/ante/vesting.go +++ b/app/ante/vesting.go @@ -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) @@ -163,12 +163,14 @@ func (vdd VestingDelegationDecorator) validateMsg(ctx sdk.Context, msg sdk.Msg) } vested := coins.AmountOf(bondDenom) - if vested.LT(delegateMsg.Amount.Amount) { + delegatedAmount := vdd.sk.GetDelegatorBonded(ctx, addr) + targetDelegateAmount := delegateMsg.Amount.Amount.Add(delegatedAmount) + + if vested.LT(targetDelegateAmount) { return sdkerrors.Wrapf( vestingtypes.ErrInsufficientVestedCoins, "cannot delegate unvested coins. coins vested < delegation amount (%s < %s)", - vested, delegateMsg.Amount.Amount, - ) + vested, targetDelegateAmount) } } From a5b9529defb443f10529b3d048d730119ac17152 Mon Sep 17 00:00:00 2001 From: hoanguyenkh Date: Fri, 17 Mar 2023 14:43:04 +0700 Subject: [PATCH 2/9] refactor: update error code --- app/ante/vesting.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/ante/vesting.go b/app/ante/vesting.go index 0dbe8f1..d255858 100644 --- a/app/ante/vesting.go +++ b/app/ante/vesting.go @@ -169,7 +169,7 @@ func (vdd VestingDelegationDecorator) validateMsg(ctx sdk.Context, msg sdk.Msg) if vested.LT(targetDelegateAmount) { return sdkerrors.Wrapf( vestingtypes.ErrInsufficientVestedCoins, - "cannot delegate unvested coins. coins vested < delegation amount (%s < %s)", + "cannot delegate unvested coins. coins vested < target delegation amount (%s < %s)", vested, targetDelegateAmount) } } From 8b7001cf6c86e16b15d1398a7b2359bf1f5e5c11 Mon Sep 17 00:00:00 2001 From: hoanguyenkh Date: Fri, 17 Mar 2023 16:10:20 +0700 Subject: [PATCH 3/9] feat: account vesting cannot delegate --- app/ante/vesting.go | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/app/ante/vesting.go b/app/ante/vesting.go index d255858..c6674a3 100644 --- a/app/ante/vesting.go +++ b/app/ante/vesting.go @@ -132,7 +132,7 @@ 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) if !ok { return nil } @@ -146,32 +146,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", - ) - } - - vested := coins.AmountOf(bondDenom) - delegatedAmount := vdd.sk.GetDelegatorBonded(ctx, addr) - targetDelegateAmount := delegateMsg.Amount.Amount.Add(delegatedAmount) - - if vested.LT(targetDelegateAmount) { - return sdkerrors.Wrapf( - vestingtypes.ErrInsufficientVestedCoins, - "cannot delegate unvested coins. coins vested < target delegation amount (%s < %s)", - vested, targetDelegateAmount) - } + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account vesting cannot delegate") } return nil From 18967e0886e4e9ebe1f3d1f34be1b32944cfa27c Mon Sep 17 00:00:00 2001 From: hoanguyenkh Date: Fri, 17 Mar 2023 16:14:35 +0700 Subject: [PATCH 4/9] chore: update typo --- app/ante/vesting.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/ante/vesting.go b/app/ante/vesting.go index c6674a3..11fa70f 100644 --- a/app/ante/vesting.go +++ b/app/ante/vesting.go @@ -152,7 +152,7 @@ func (vdd VestingDelegationDecorator) validateMsg(ctx sdk.Context, msg sdk.Msg) return nil } - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account vesting cannot delegate") + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Vesting account cannot delegate") } return nil From d25b5e05e0507fbe04617e0050d392facce77f8a Mon Sep 17 00:00:00 2001 From: hoanguyenkh Date: Fri, 17 Mar 2023 18:36:12 +0700 Subject: [PATCH 5/9] fix: fix test vesting --- integration_tests/test_vesting_staking.py | 2 ++ tests/vesting_test.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/integration_tests/test_vesting_staking.py b/integration_tests/test_vesting_staking.py index 872e26e..1b5f56e 100644 --- a/integration_tests/test_vesting_staking.py +++ b/integration_tests/test_vesting_staking.py @@ -40,12 +40,14 @@ def test_staking_vesting_redelegate(astra): signer1_address, "0.025aastra", ) + print(rsp) assert rsp["code"] == 0, rsp["raw_log"] wait_for_block(astra.cosmos_cli(0), 2) assert astra.cosmos_cli(0).staking_pool() == old_bonded + 2009999498 rsp = astra.cosmos_cli(0).delegate_amount( validator2_operator_address, "1aastra", signer1_address, "0.025aastra" ) + print(rsp) assert rsp["code"] == 0, rsp["raw_log"] wait_for_block(astra.cosmos_cli(0), 2) assert astra.cosmos_cli(0).staking_pool() == old_bonded + 2009999499 diff --git a/tests/vesting_test.go b/tests/vesting_test.go index b4e666a..7f70cf7 100644 --- a/tests/vesting_test.go +++ b/tests/vesting_test.go @@ -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, @@ -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") From 8559db02a1f73fb9ccbf527ab84d3449f59b7d12 Mon Sep 17 00:00:00 2001 From: hoanguyenkh Date: Sat, 18 Mar 2023 08:51:30 +0700 Subject: [PATCH 6/9] test: remove print log --- integration_tests/test_vesting_staking.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/integration_tests/test_vesting_staking.py b/integration_tests/test_vesting_staking.py index 1b5f56e..872e26e 100644 --- a/integration_tests/test_vesting_staking.py +++ b/integration_tests/test_vesting_staking.py @@ -40,14 +40,12 @@ def test_staking_vesting_redelegate(astra): signer1_address, "0.025aastra", ) - print(rsp) assert rsp["code"] == 0, rsp["raw_log"] wait_for_block(astra.cosmos_cli(0), 2) assert astra.cosmos_cli(0).staking_pool() == old_bonded + 2009999498 rsp = astra.cosmos_cli(0).delegate_amount( validator2_operator_address, "1aastra", signer1_address, "0.025aastra" ) - print(rsp) assert rsp["code"] == 0, rsp["raw_log"] wait_for_block(astra.cosmos_cli(0), 2) assert astra.cosmos_cli(0).staking_pool() == old_bonded + 2009999499 From 723a93f57d7ff72d62b0fde07a4f08eabeb01c8a Mon Sep 17 00:00:00 2001 From: hoanguyenkh Date: Sat, 18 Mar 2023 16:16:46 +0700 Subject: [PATCH 7/9] feat: vesting account cannot create validator --- app/ante/vesting.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/ante/vesting.go b/app/ante/vesting.go index 11fa70f..4aece4f 100644 --- a/app/ante/vesting.go +++ b/app/ante/vesting.go @@ -133,8 +133,13 @@ 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 { _, 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() { @@ -152,7 +157,7 @@ func (vdd VestingDelegationDecorator) validateMsg(ctx sdk.Context, msg sdk.Msg) return nil } - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Vesting account cannot delegate") + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, msgError) } return nil From 29ce0e052aedbb2833d16454397c38901c929b24 Mon Sep 17 00:00:00 2001 From: hoanguyenkh Date: Sat, 18 Mar 2023 16:18:17 +0700 Subject: [PATCH 8/9] feat: check other addr --- app/ante/vesting.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/ante/vesting.go b/app/ante/vesting.go index 4aece4f..5c2d482 100644 --- a/app/ante/vesting.go +++ b/app/ante/vesting.go @@ -154,7 +154,7 @@ func (vdd VestingDelegationDecorator) validateMsg(ctx sdk.Context, msg sdk.Msg) _, isClawback := acc.(*vestingtypes.ClawbackVestingAccount) if !isClawback { // continue to next decorator as this logic only applies to vesting - return nil + continue } return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, msgError) From bcb907148431c730d2fc322f25927dee01e9a2ca Mon Sep 17 00:00:00 2001 From: LampardNguyen234 Date: Sat, 18 Mar 2023 20:36:37 +0700 Subject: [PATCH 9/9] docs: update mint specs --- x/mint/spec/01_concepts.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/x/mint/spec/01_concepts.md b/x/mint/spec/01_concepts.md index a0c064c..667455b 100644 --- a/x/mint/spec/01_concepts.md +++ b/x/mint/spec/01_concepts.md @@ -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