diff --git a/app/test_setup.go b/app/test_setup.go index 6bc413342..4eef74201 100644 --- a/app/test_setup.go +++ b/app/test_setup.go @@ -239,39 +239,39 @@ func initAccountWithCoins(app *ElysApp, ctx sdk.Context, addr sdk.AccAddress, co } // Add testing commitments -func AddTestCommitment(app *ElysApp, ctx sdk.Context, address sdk.AccAddress, committed []sdk.Coins, uncommitted []sdk.Coins) { +func AddTestCommitment(app *ElysApp, ctx sdk.Context, address sdk.AccAddress, committed []sdk.Coins, rewardsUnclaimed []sdk.Coins) { commitment, found := app.CommitmentKeeper.GetCommitments(ctx, address.String()) if !found { commitment = ctypes.Commitments{ - Creator: address.String(), - CommittedTokens: []*types.CommittedTokens{}, - UncommittedTokens: []*types.UncommittedTokens{}, + Creator: address.String(), + CommittedTokens: []*types.CommittedTokens{}, + RewardsUnclaimed: []*types.RewardsUnclaimed{}, } } - // Loop uncommitted tokens - for _, uc := range uncommitted { + // Loop unclaimed rewards + for _, uc := range rewardsUnclaimed { Denom := uc.GetDenomByIndex(0) - // Get the uncommitted tokens for the creator - uncommittedToken, _ := commitment.GetUncommittedTokensForDenom(Denom) + // Get the unclaimed rewards for the creator + rewardUnclaimed, _ := commitment.GetRewardsUnclaimedForDenom(Denom) if !found { - uncommittedTokens := commitment.GetUncommittedTokens() - uncommittedToken = &types.UncommittedTokens{ + rewardsUnclaimed := commitment.GetRewardsUnclaimed() + rewardUnclaimed = &types.RewardsUnclaimed{ Denom: Denom, Amount: sdk.ZeroInt(), } - uncommittedTokens = append(uncommittedTokens, uncommittedToken) - commitment.UncommittedTokens = uncommittedTokens + rewardsUnclaimed = append(rewardsUnclaimed, rewardUnclaimed) + commitment.RewardsUnclaimed = rewardsUnclaimed } - // Update the uncommitted tokens amount - uncommittedToken.Amount = uncommittedToken.Amount.Add(uc.AmountOf(Denom)) + // Update the unclaimed tokens amount + rewardUnclaimed.Amount = rewardUnclaimed.Amount.Add(uc.AmountOf(Denom)) } for _, c := range committed { Denom := c.GetDenomByIndex(0) - // Get the uncommitted tokens for the creator + // Get the committed tokens for the creator committedToken, _ := commitment.GetCommittedTokensForDenom(Denom) if !found { committedTokens := commitment.GetCommittedTokens() @@ -282,7 +282,7 @@ func AddTestCommitment(app *ElysApp, ctx sdk.Context, address sdk.AccAddress, co committedTokens = append(committedTokens, committedToken) commitment.CommittedTokens = committedTokens } - // Update the uncommitted tokens amount + // Update the committed tokens amount committedToken.Amount = committedToken.Amount.Add(c.AmountOf(Denom)) } diff --git a/config.yml b/config.yml index 59b8947fb..b34f3e874 100644 --- a/config.yml +++ b/config.yml @@ -229,7 +229,7 @@ genesis: denom: ueden - amount: "10000" denom: uedenb - uncommitted_tokens: + rewards_unclaimed: - amount: "10000" denom: uusdc - amount: "10000" diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index 44f53b28b..6d9ef9268 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -38850,7 +38850,17 @@ paths: type: string amount: type: string - uncommitted_tokens: + lockups: + type: array + items: + type: object + properties: + amount: + type: string + unlock_timestamp: + type: string + format: uint64 + rewards_unclaimed: type: array items: type: object @@ -82965,7 +82975,17 @@ definitions: type: string amount: type: string - uncommitted_tokens: + lockups: + type: array + items: + type: object + properties: + amount: + type: string + unlock_timestamp: + type: string + format: uint64 + rewards_unclaimed: type: array items: type: object @@ -83001,11 +83021,29 @@ definitions: type: string amount: type: string + lockups: + type: array + items: + type: object + properties: + amount: + type: string + unlock_timestamp: + type: string + format: uint64 + elys.commitment.Lockup: + type: object + properties: + amount: + type: string + unlock_timestamp: + type: string + format: uint64 elys.commitment.MsgCancelVestResponse: type: object elys.commitment.MsgCommitLiquidTokensResponse: type: object - elys.commitment.MsgCommitTokensResponse: + elys.commitment.MsgCommitUnclaimedRewardsResponse: type: object elys.commitment.MsgUncommitTokensResponse: type: object @@ -83086,7 +83124,17 @@ definitions: type: string amount: type: string - uncommitted_tokens: + lockups: + type: array + items: + type: object + properties: + amount: + type: string + unlock_timestamp: + type: string + format: uint64 + rewards_unclaimed: type: array items: type: object @@ -83115,7 +83163,7 @@ definitions: type: string format: int64 description: GenesisState defines the commitment module's genesis state. - elys.commitment.UncommittedTokens: + elys.commitment.RewardsUnclaimed: type: object properties: denom: diff --git a/proto/elys/commitment/commitments.proto b/proto/elys/commitment/commitments.proto index fddf60efc..b47426af5 100644 --- a/proto/elys/commitment/commitments.proto +++ b/proto/elys/commitment/commitments.proto @@ -12,37 +12,46 @@ option go_package = "github.com/elys-network/elys/x/commitment/types"; message Commitments { string creator = 1; repeated CommittedTokens committed_tokens = 2; - repeated UncommittedTokens uncommitted_tokens = 3; + repeated RewardsUnclaimed rewards_unclaimed = 3; repeated VestingTokens vesting_tokens = 4; } +message Lockup { + string amount = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; + uint64 unlock_timestamp = 2; +} + message CommittedTokens { - string denom = 1; - string amount = 2 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", - (gogoproto.nullable) = false - ]; + string denom = 1; + string amount = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; + repeated Lockup lockups = 3 [ (gogoproto.nullable) = false ]; } -message UncommittedTokens { - string denom = 1; - string amount = 2 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", - (gogoproto.nullable) = false - ]; +message RewardsUnclaimed { + string denom = 1; + string amount = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; } message VestingTokens { - string denom = 1; - string total_amount = 2 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", - (gogoproto.nullable) = false - ]; - string unvested_amount = 3 [ + string denom = 1; + string total_amount = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; + string unvested_amount = 3 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false - ]; - string epoch_identifier = 4; - int64 num_epochs = 5; - int64 current_epoch = 6; + ]; + string epoch_identifier = 4; + int64 num_epochs = 5; + int64 current_epoch = 6; } \ No newline at end of file diff --git a/proto/elys/commitment/query.proto b/proto/elys/commitment/query.proto index 1fecac67a..45ea7f38a 100644 --- a/proto/elys/commitment/query.proto +++ b/proto/elys/commitment/query.proto @@ -12,17 +12,14 @@ option go_package = "github.com/elys-network/elys/x/commitment/types"; // Query defines the gRPC querier service. service Query { - // Parameters queries the parameters of the module. rpc Params (QueryParamsRequest) returns (QueryParamsResponse) { option (google.api.http).get = "/elys-network/elys/commitment/params"; - } // Queries a list of ShowCommitments items. rpc ShowCommitments (QueryShowCommitmentsRequest) returns (QueryShowCommitmentsResponse) { option (google.api.http).get = "/elys-network/elys/commitment/show_commitments/{creator}"; - } } // QueryParamsRequest is request type for the Query/Params RPC method. @@ -30,7 +27,6 @@ message QueryParamsRequest {} // QueryParamsResponse is response type for the Query/Params RPC method. message QueryParamsResponse { - // params holds all the parameters of this module. Params params = 1 [(gogoproto.nullable) = false]; } @@ -42,4 +38,3 @@ message QueryShowCommitmentsRequest { message QueryShowCommitmentsResponse { Commitments commitments = 1; } - diff --git a/proto/elys/commitment/tx.proto b/proto/elys/commitment/tx.proto index 003680457..7970e8de1 100644 --- a/proto/elys/commitment/tx.proto +++ b/proto/elys/commitment/tx.proto @@ -8,23 +8,35 @@ option go_package = "github.com/elys-network/elys/x/commitment/types"; // Msg defines the Msg service. service Msg { - rpc CommitTokens (MsgCommitTokens ) returns (MsgCommitTokensResponse ); - rpc UncommitTokens (MsgUncommitTokens ) returns (MsgUncommitTokensResponse ); - rpc WithdrawTokens (MsgWithdrawTokens ) returns (MsgWithdrawTokensResponse ); - rpc CommitLiquidTokens (MsgCommitLiquidTokens) returns (MsgCommitLiquidTokensResponse); - rpc Vest (MsgVest ) returns (MsgVestResponse ); - rpc CancelVest (MsgCancelVest ) returns (MsgCancelVestResponse ); - rpc VestNow (MsgVestNow ) returns (MsgVestNowResponse ); - rpc UpdateVestingInfo (MsgUpdateVestingInfo ) returns (MsgUpdateVestingInfoResponse ); - rpc VestLiquid (MsgVestLiquid ) returns (MsgVestLiquidResponse ); + // CommitLiquidTokens commit the tokens from user's balance + rpc CommitLiquidTokens(MsgCommitLiquidTokens) returns (MsgCommitLiquidTokensResponse); + // CommitUnclaimedRewards commit the tokens on unclaimed store to committed + rpc CommitUnclaimedRewards(MsgCommitUnclaimedRewards) returns (MsgCommitUnclaimedRewardsResponse); + // UncommitTokens uncommits the tokens from committed store and make it liquid immediately + rpc UncommitTokens(MsgUncommitTokens) returns (MsgUncommitTokensResponse ); + // WithdrawTokens withdraw first from unclaimed and if it requires more, withdraw from committed store + rpc WithdrawTokens(MsgWithdrawTokens) returns (MsgWithdrawTokensResponse); + // Vest converts user's commitment to vesting - start with unclaimed rewards and if it's not enough deduct from committed bucket + // mainly utilized for Eden + rpc Vest(MsgVest) returns (MsgVestResponse); + // VestNow provides functionality to get the token immediately but lower amount than original + // e.g. user can burn 1000 ueden and get 800 uelys when the ratio is 80% + rpc VestNow(MsgVestNow) returns (MsgVestNowResponse); + // VestLiquid converts user's balance to vesting to be utilized for normal tokens vesting like ATOM vesting + rpc VestLiquid(MsgVestLiquid) returns (MsgVestLiquidResponse); + // CancelVest cancel the user's vesting and the user reject to get vested tokens + rpc CancelVest(MsgCancelVest) returns (MsgCancelVestResponse); + // UpdateVestingInfo add/update specific vesting info by denom on Params + rpc UpdateVestingInfo(MsgUpdateVestingInfo) returns (MsgUpdateVestingInfoResponse ); } -message MsgCommitTokens { + +message MsgCommitUnclaimedRewards { string creator = 1; string amount = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false]; string denom = 3; } -message MsgCommitTokensResponse {} +message MsgCommitUnclaimedRewardsResponse {} message MsgUncommitTokens { string creator = 1; @@ -46,6 +58,7 @@ message MsgCommitLiquidTokens { string creator = 1; string amount = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false]; string denom = 3; + uint64 minLock = 4; // minimum lock duration to wait until it is claimable } message MsgCommitLiquidTokensResponse {} diff --git a/x/amm/client/wasm/query_balance_of_denom.go b/x/amm/client/wasm/query_balance_of_denom.go index 48d19c216..534e96ebe 100644 --- a/x/amm/client/wasm/query_balance_of_denom.go +++ b/x/amm/client/wasm/query_balance_of_denom.go @@ -22,12 +22,12 @@ func (oq *Querier) queryBalanceOfDenom(ctx sdk.Context, query *wasmbindingstypes if !found { balance = sdk.NewCoin(denom, sdk.ZeroInt()) } else { - uncommittedToken, found := commitment.GetUncommittedTokensForDenom(denom) + rewardUnclaimed, found := commitment.GetRewardsUnclaimedForDenom(denom) if !found { return nil, errorsmod.Wrap(nil, "invalid denom") } - balance = sdk.NewCoin(denom, uncommittedToken.Amount) + balance = sdk.NewCoin(denom, rewardUnclaimed.Amount) } } diff --git a/x/amm/keeper/apply_exit_pool_state_change.go b/x/amm/keeper/apply_exit_pool_state_change.go index 3f772a3ad..8ce1c9e09 100644 --- a/x/amm/keeper/apply_exit_pool_state_change.go +++ b/x/amm/keeper/apply_exit_pool_state_change.go @@ -7,21 +7,21 @@ import ( ctypes "github.com/elys-network/elys/x/commitment/types" ) -func (k Keeper) applyExitPoolStateChange(ctx sdk.Context, pool types.Pool, exiter sdk.AccAddress, numShares sdk.Int, exitCoins sdk.Coins) error { +func (k Keeper) ApplyExitPoolStateChange(ctx sdk.Context, pool types.Pool, exiter sdk.AccAddress, numShares sdk.Int, exitCoins sdk.Coins) error { // Withdraw exit amount of token from commitment module to exiter's wallet. msgServer := commitmentkeeper.NewMsgServerImpl(*k.commitmentKeeper) poolShareDenom := types.GetPoolShareDenom(pool.GetPoolId()) // Withdraw token message - msgWithdrawToken := &ctypes.MsgWithdrawTokens{ + msgWithdrawTokens := &ctypes.MsgWithdrawTokens{ Creator: exiter.String(), Amount: numShares, Denom: poolShareDenom, } - // Withdraw committed LP token - _, err := msgServer.WithdrawTokens(sdk.WrapSDKContext(ctx), msgWithdrawToken) + // Withdraw committed LP tokens + _, err := msgServer.WithdrawTokens(sdk.WrapSDKContext(ctx), msgWithdrawTokens) if err != nil { return err } diff --git a/x/amm/keeper/apply_exit_pool_state_change_test.go b/x/amm/keeper/apply_exit_pool_state_change_test.go index 370aae79c..e449db2a3 100644 --- a/x/amm/keeper/apply_exit_pool_state_change_test.go +++ b/x/amm/keeper/apply_exit_pool_state_change_test.go @@ -1,82 +1,78 @@ package keeper_test import ( - "fmt" - "testing" - - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" simapp "github.com/elys-network/elys/app" "github.com/elys-network/elys/x/amm/types" atypes "github.com/elys-network/elys/x/amm/types" ptypes "github.com/elys-network/elys/x/parameter/types" - "github.com/stretchr/testify/require" ) -func TestWithdrawCommitedLPTokenFromCommitmentModule(t *testing.T) { - app := simapp.InitElysTestApp(initChain) - ctx := app.BaseApp.NewContext(initChain, tmproto.Header{}) - amm, bk := app.AmmKeeper, app.BankKeeper +func (suite *KeeperTestSuite) TestApplyExitPoolStateChange_WithdrawFromCommitmentModule() { + suite.SetupStableCoinPrices() - // Create Pool + app := suite.app + amm, bk := app.AmmKeeper, app.BankKeeper + ctx := suite.ctx // Generate 1 random account with 1000stake balanced - addr := simapp.AddTestAddrs(app, ctx, 1, sdk.NewInt(1000000)) - transferAmt := sdk.NewCoin(ptypes.Elys, sdk.NewInt(100)) + addrs := simapp.AddTestAddrs(app, ctx, 1, sdk.NewInt(1000000)) - // Deposit 100elys to FeeCollectorName wallet - err := bk.SendCoinsFromAccountToModule(ctx, addr[0], authtypes.FeeCollectorName, sdk.NewCoins(transferAmt)) - require.NoError(t, err) - - // Create a pool - // Mint 100000USDC - usdcToken := sdk.NewCoins(sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(100000))) - - err = app.BankKeeper.MintCoins(ctx, types.ModuleName, usdcToken) - require.NoError(t, err) - err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, addr[0], usdcToken) - require.NoError(t, err) + // Mint 100000USDC+100000USDT + coins := sdk.NewCoins(sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(100000)), sdk.NewCoin("uusdt", sdk.NewInt(100000))) + err := app.BankKeeper.MintCoins(ctx, types.ModuleName, coins) + suite.Require().NoError(err) + err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, addrs[0], coins) + suite.Require().NoError(err) poolAssets := []atypes.PoolAsset{ { Weight: sdk.NewInt(50), - Token: sdk.NewCoin(ptypes.Elys, sdk.NewInt(100000)), + Token: sdk.NewCoin("uusdt", sdk.NewInt(100000)), }, { Weight: sdk.NewInt(50), - Token: sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(10000)), + Token: sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(100000)), }, } - argSwapFee, err := sdk.NewDecFromStr("0.1") - require.NoError(t, err) + swapFee, err := sdk.NewDecFromStr("0.1") + suite.Require().NoError(err) - argExitFee, err := sdk.NewDecFromStr("0.1") - require.NoError(t, err) + exitFee, err := sdk.NewDecFromStr("0.1") + suite.Require().NoError(err) poolParams := &atypes.PoolParams{ - SwapFee: argSwapFee, - ExitFee: argExitFee, + SwapFee: swapFee, + ExitFee: exitFee, + UseOracle: true, + WeightBreakingFeeMultiplier: sdk.ZeroDec(), + ExternalLiquidityRatio: sdk.NewDec(1), + LpFeePortion: sdk.ZeroDec(), + StakingFeePortion: sdk.ZeroDec(), + WeightRecoveryFeePortion: sdk.ZeroDec(), + ThresholdWeightDifference: sdk.ZeroDec(), + FeeDenom: ptypes.BaseCurrency, } msg := types.NewMsgCreatePool( - addr[0].String(), + addrs[0].String(), poolParams, poolAssets, ) - // Create a Elys+USDC pool + // Create a USDT+USDC pool poolId, err := amm.CreatePool(ctx, msg) - require.NoError(t, err) - require.Equal(t, poolId, uint64(1)) - // + suite.Require().NoError(err) + suite.Require().Equal(poolId, uint64(1)) - _, found := amm.GetPool(ctx, poolId) - require.True(t, found) + pool, found := amm.GetPool(ctx, poolId) + suite.Require().True(found) lpTokenDenom := types.GetPoolShareDenom(poolId) - lpTokenBalance := bk.GetBalance(ctx, addr[0], lpTokenDenom) - fmt.Println("lpTokenBalance") - fmt.Println(lpTokenBalance) + lpTokenBalance := bk.GetBalance(ctx, addrs[0], lpTokenDenom) + suite.Require().True(lpTokenBalance.Amount.Equal(sdk.ZeroInt())) + + err = app.AmmKeeper.ApplyExitPoolStateChange(ctx, pool, addrs[0], pool.TotalShares.Amount, coins) + suite.Require().NoError(err) } diff --git a/x/amm/keeper/fee.go b/x/amm/keeper/fee.go index a8e340d60..dd5bce4b1 100644 --- a/x/amm/keeper/fee.go +++ b/x/amm/keeper/fee.go @@ -27,7 +27,14 @@ func (k Keeper) OnCollectFee(ctx sdk.Context, pool types.Pool, fee sdk.Coins) er if err != nil { return nil } - return k.SwapFeesToRevenueToken(ctx, pool, revenueAmount) + + // handling the case, pool does not enough liquidity to swap fees to revenue token when liquidity is being fully removed + cacheCtx, write := ctx.CacheContext() + err = k.SwapFeesToRevenueToken(cacheCtx, pool, revenueAmount) + if err == nil { + write() + } + return nil } // No fee management required when doing swap from fees to revenue token diff --git a/x/amm/keeper/keeper_exit_pool.go b/x/amm/keeper/keeper_exit_pool.go index 0fa875f39..64fe03f80 100644 --- a/x/amm/keeper/keeper_exit_pool.go +++ b/x/amm/keeper/keeper_exit_pool.go @@ -35,7 +35,7 @@ func (k Keeper) ExitPool( exitCoins, tokenOutMins) } - err = k.applyExitPoolStateChange(ctx, pool, sender, shareInAmount, exitCoins) + err = k.ApplyExitPoolStateChange(ctx, pool, sender, shareInAmount, exitCoins) if err != nil { return sdk.Coins{}, err } diff --git a/x/amm/keeper/mint_pool_share_to_account.go b/x/amm/keeper/mint_pool_share_to_account.go index f8721df1d..3ac1c798f 100644 --- a/x/amm/keeper/mint_pool_share_to_account.go +++ b/x/amm/keeper/mint_pool_share_to_account.go @@ -1,6 +1,8 @@ package keeper import ( + "time" + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/elys-network/elys/x/amm/types" @@ -64,14 +66,20 @@ func (k Keeper) MintPoolShareToAccount(ctx sdk.Context, pool types.Pool, addr sd // Commit LP token minted msgServer := commitmentkeeper.NewMsgServerImpl(*k.commitmentKeeper) - // Create a commit LP token liquidated message + minLock := uint64(ctx.BlockTime().Unix()) + if pool.PoolParams.UseOracle { + minLock += uint64(time.Hour.Seconds()) + } + + // Create a commit LP token message msgLiquidCommitLPToken := &ctypes.MsgCommitLiquidTokens{ Creator: addr.String(), Denom: poolShareDenom, Amount: amount, + MinLock: minLock, } - // Commit LP token liquidated + // Commit LP token _, err = msgServer.CommitLiquidTokens(sdk.WrapSDKContext(ctx), msgLiquidCommitLPToken) if err != nil { return err diff --git a/x/amm/keeper/mint_pool_share_to_account_test.go b/x/amm/keeper/mint_pool_share_to_account_test.go index 8f7c15c52..584c15e94 100644 --- a/x/amm/keeper/mint_pool_share_to_account_test.go +++ b/x/amm/keeper/mint_pool_share_to_account_test.go @@ -72,13 +72,11 @@ func TestCommitMintedLPTokenToCommitmentModule(t *testing.T) { poolId, err := amm.CreatePool(ctx, msg) require.NoError(t, err) require.Equal(t, poolId, uint64(1)) - // _, found := amm.GetPool(ctx, poolId) require.True(t, found) lpTokenDenom := types.GetPoolShareDenom(poolId) lpTokenBalance := bk.GetBalance(ctx, addr[0], lpTokenDenom) - fmt.Println("lpTokenBalance") - fmt.Println(lpTokenBalance) + fmt.Println("lpTokenBalance", lpTokenBalance.String()) } diff --git a/x/commitment/client/cli/tx.go b/x/commitment/client/cli/tx.go index 3959cdd93..39cb20b23 100644 --- a/x/commitment/client/cli/tx.go +++ b/x/commitment/client/cli/tx.go @@ -30,7 +30,7 @@ func GetTxCmd() *cobra.Command { RunE: client.ValidateCmd, } - cmd.AddCommand(CmdCommitTokens()) + cmd.AddCommand(CmdCommitUnclaimedRewards()) cmd.AddCommand(CmdCommitLiquidTokens()) cmd.AddCommand(CmdUncommitTokens()) cmd.AddCommand(CmdVest()) diff --git a/x/commitment/client/cli/tx_commit_tokens.go b/x/commitment/client/cli/tx_commit_tokens.go index 3891b19cf..66d197b12 100644 --- a/x/commitment/client/cli/tx_commit_tokens.go +++ b/x/commitment/client/cli/tx_commit_tokens.go @@ -15,9 +15,9 @@ import ( var _ = strconv.Itoa(0) -func CmdCommitTokens() *cobra.Command { +func CmdCommitUnclaimedRewards() *cobra.Command { cmd := &cobra.Command{ - Use: "commit-tokens [amount] [denom]", + Use: "commit-unclaimed-rewards [amount] [denom]", Short: "Broadcast message commit-tokens", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -32,7 +32,7 @@ func CmdCommitTokens() *cobra.Command { return err } - msg := types.NewMsgCommitTokens( + msg := types.NewMsgCommitUnclaimedRewards( clientCtx.GetFromAddress().String(), argAmount, argDenom, diff --git a/x/commitment/client/wasm/msg_stake.go b/x/commitment/client/wasm/msg_stake.go index 885b05114..920cf31c4 100644 --- a/x/commitment/client/wasm/msg_stake.go +++ b/x/commitment/client/wasm/msg_stake.go @@ -80,13 +80,13 @@ func performMsgCommit(f *commitmentkeeper.Keeper, ctx sdk.Context, contractAddr return nil, wasmvmtypes.InvalidRequest{Err: "Invalid staking parameter"} } msgServer := commitmentkeeper.NewMsgServerImpl(*f) - msgMsgCommit := commitmenttypes.NewMsgCommitTokens(msgStake.Address, msgStake.Amount, msgStake.Asset) + msgMsgCommit := commitmenttypes.NewMsgCommitUnclaimedRewards(msgStake.Address, msgStake.Amount, msgStake.Asset) if err := msgMsgCommit.ValidateBasic(); err != nil { return nil, errorsmod.Wrap(err, "failed validating msgMsgCommit") } - _, err := msgServer.CommitTokens(ctx, msgMsgCommit) // Discard the response because it's empty + _, err := msgServer.CommitUnclaimedRewards(ctx, msgMsgCommit) // Discard the response because it's empty if err != nil { return nil, errorsmod.Wrap(err, "commit msg") } diff --git a/x/commitment/keeper/commitments.go b/x/commitment/keeper/commitments.go index caf72a9bb..ac1e67d7c 100644 --- a/x/commitment/keeper/commitments.go +++ b/x/commitment/keeper/commitments.go @@ -79,32 +79,28 @@ func (k Keeper) DeductCommitments(ctx sdk.Context, creator string, denom string, return commitments, nil } - // Get user's uncommitted balance - uncommittedToken, found := commitments.GetUncommittedTokensForDenom(denom) + // Get user's unclaimed reward + rewardUnclaimed, found := commitments.GetRewardsUnclaimedForDenom(denom) if !found { - uncommittedToken = &types.UncommittedTokens{Denom: denom, Amount: sdk.ZeroInt()} + rewardUnclaimed = &types.RewardsUnclaimed{Denom: denom, Amount: sdk.ZeroInt()} } - requestedAmount := amount - - // Check if there are enough uncommitted tokens to withdraw - if uncommittedToken.Amount.LT(requestedAmount) { - // Calculate the difference between the requested amount and the available uncommitted balance - difference := requestedAmount.Sub(uncommittedToken.Amount) - - committedToken, found := commitments.GetCommittedTokensForDenom(denom) - if found { - if committedToken.Amount.GTE(difference) { - // Uncommit the required committed tokens - committedToken.Amount = committedToken.Amount.Sub(difference) - requestedAmount = requestedAmount.Sub(difference) - } else { - return types.Commitments{}, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "not enough tokens to withdraw") - } + unclaimedRemovalAmount := amount + + // Check if there are enough unclaimed rewards to withdraw + if rewardUnclaimed.Amount.LT(unclaimedRemovalAmount) { + // Calculate the difference between the requested amount and the available unclaimed balance + difference := unclaimedRemovalAmount.Sub(rewardUnclaimed.Amount) + + err := commitments.DeductFromCommitted(denom, difference, uint64(ctx.BlockTime().Unix())) + if err != nil { + return types.Commitments{}, err } + + unclaimedRemovalAmount = rewardUnclaimed.Amount } - // Subtract the withdrawn amount from the uncommitted balance - uncommittedToken.Amount = uncommittedToken.Amount.Sub(requestedAmount) + // Subtract the withdrawn amount from the unclaimed balance + rewardUnclaimed.Amount = rewardUnclaimed.Amount.Sub(unclaimedRemovalAmount) return commitments, nil } diff --git a/x/commitment/keeper/deposit_liquid_tokens.go b/x/commitment/keeper/deposit_liquid_tokens.go index 0afcb317d..2e45a2f37 100644 --- a/x/commitment/keeper/deposit_liquid_tokens.go +++ b/x/commitment/keeper/deposit_liquid_tokens.go @@ -9,8 +9,8 @@ import ( "github.com/elys-network/elys/x/commitment/types" ) -// accounting the liquid token as a uncommitted token in commitment module. -func (k Keeper) DepositLiquidTokensUncommitted(ctx sdk.Context, denom string, amount sdk.Int, creator string) error { +// accounting the liquid token as a unclaimed token in commitment module. +func (k Keeper) DepositLiquidTokensUnclaimed(ctx sdk.Context, denom string, amount sdk.Int, creator string) error { assetProfile, found := k.apKeeper.GetEntry(ctx, denom) if !found { return sdkerrors.Wrapf(aptypes.ErrAssetProfileNotFound, "denom: %s", denom) @@ -42,25 +42,25 @@ func (k Keeper) DepositLiquidTokensUncommitted(ctx sdk.Context, denom string, am commitments, found := k.GetCommitments(ctx, creator) if !found { commitments = types.Commitments{ - Creator: creator, - CommittedTokens: []*types.CommittedTokens{}, - UncommittedTokens: []*types.UncommittedTokens{}, + Creator: creator, + CommittedTokens: []*types.CommittedTokens{}, + RewardsUnclaimed: []*types.RewardsUnclaimed{}, } } - // Get the uncommitted tokens for the creator - uncommittedToken, found := commitments.GetUncommittedTokensForDenom(denom) + // Get the unclaimed rewards for the creator + rewardUnclaimed, found := commitments.GetRewardsUnclaimedForDenom(denom) if !found { - uncommittedTokens := commitments.GetUncommittedTokens() - uncommittedToken = &types.UncommittedTokens{ + rewardsUnclaimed := commitments.GetRewardsUnclaimed() + rewardUnclaimed = &types.RewardsUnclaimed{ Denom: denom, Amount: sdk.ZeroInt(), } - uncommittedTokens = append(uncommittedTokens, uncommittedToken) - commitments.UncommittedTokens = uncommittedTokens + rewardsUnclaimed = append(rewardsUnclaimed, rewardUnclaimed) + commitments.RewardsUnclaimed = rewardsUnclaimed } - // Update the uncommitted tokens amount - uncommittedToken.Amount = uncommittedToken.Amount.Add(amount) + // Update the unclaimed rewards amount + rewardUnclaimed.Amount = rewardUnclaimed.Amount.Add(amount) // Update the commitments k.SetCommitments(ctx, commitments) diff --git a/x/commitment/keeper/deposit_liquid_tokens_test.go b/x/commitment/keeper/deposit_liquid_tokens_test.go index 443a57bd7..7469c3f7d 100644 --- a/x/commitment/keeper/deposit_liquid_tokens_test.go +++ b/x/commitment/keeper/deposit_liquid_tokens_test.go @@ -44,7 +44,7 @@ func TestDepositLiquidTokens(t *testing.T) { Amount: sdk.NewInt(50), }, }, - UncommittedTokens: []*types.UncommittedTokens{ + RewardsUnclaimed: []*types.RewardsUnclaimed{ { Denom: ptypes.Eden, Amount: sdk.NewInt(150), @@ -53,16 +53,16 @@ func TestDepositLiquidTokens(t *testing.T) { } keeper.SetCommitments(ctx, commitments) - // Deposit liquid eden to become uncommitted state - keeper.DepositLiquidTokensUncommitted(ctx, ptypes.Eden, sdk.NewInt(100), creator.String()) + // Deposit liquid eden to become unclaimed state + keeper.DepositLiquidTokensUnclaimed(ctx, ptypes.Eden, sdk.NewInt(100), creator.String()) // Check if the deposit tokens were added to commitments newCommitments, found := keeper.GetCommitments(ctx, creator.String()) require.True(t, found, "commitments not found") - // Check if the uncommitted tokens were updated correctly - uncommittedToken := newCommitments.GetUncommittedAmountForDenom(ptypes.Eden) - require.Equal(t, sdk.NewInt(250), uncommittedToken, "uncommitted tokens were not updated correctly") + // Check if the unclaimed tokens were updated correctly + rewardUnclaimed := newCommitments.GetUnclaimedAmountForDenom(ptypes.Eden) + require.Equal(t, sdk.NewInt(250), rewardUnclaimed, "unclaimed tokens were not updated correctly") // Check if the committed tokens were updated correctly committedToken := newCommitments.GetCommittedAmountForDenom(ptypes.Eden) diff --git a/x/commitment/keeper/keeper.go b/x/commitment/keeper/keeper.go index 1f19b175b..07cda6ca1 100644 --- a/x/commitment/keeper/keeper.go +++ b/x/commitment/keeper/keeper.go @@ -128,21 +128,21 @@ func (k Keeper) StandardStakingToken(ctx sdk.Context, delegator string, validato commitments, found := k.GetCommitments(ctx, delegator) if !found { commitments = types.Commitments{ - Creator: delegator, - CommittedTokens: []*types.CommittedTokens{}, - UncommittedTokens: []*types.UncommittedTokens{}, + Creator: delegator, + CommittedTokens: []*types.CommittedTokens{}, + RewardsUnclaimed: []*types.RewardsUnclaimed{}, } } - // Get the uncommitted tokens for the delegator - uncommittedToken, _ := commitments.GetUncommittedTokensForDenom(denom) + // Get the unclaimed tokens for the delegator + rewardUnclaimed, _ := commitments.GetRewardsUnclaimedForDenom(denom) if !found { - uncommittedTokens := commitments.GetUncommittedTokens() - uncommittedToken = &types.UncommittedTokens{ + rewardsUnclaimed := commitments.GetRewardsUnclaimed() + rewardUnclaimed = &types.RewardsUnclaimed{ Denom: denom, Amount: sdk.ZeroInt(), } - uncommittedTokens = append(uncommittedTokens, uncommittedToken) - commitments.UncommittedTokens = uncommittedTokens + rewardsUnclaimed = append(rewardsUnclaimed, rewardUnclaimed) + commitments.RewardsUnclaimed = rewardsUnclaimed } // Update the commitments @@ -164,21 +164,21 @@ func (k Keeper) StandardStakingToken(ctx sdk.Context, delegator string, validato commitments, found = k.GetCommitments(ctx, validator) if !found { commitments = types.Commitments{ - Creator: validator, - CommittedTokens: []*types.CommittedTokens{}, - UncommittedTokens: []*types.UncommittedTokens{}, + Creator: validator, + CommittedTokens: []*types.CommittedTokens{}, + RewardsUnclaimed: []*types.RewardsUnclaimed{}, } } - // Get the uncommitted tokens for the validator - uncommittedToken, _ = commitments.GetUncommittedTokensForDenom(denom) + // Get the unclaimed tokens for the validator + rewardUnclaimed, _ = commitments.GetRewardsUnclaimedForDenom(denom) if !found { - uncommittedTokens := commitments.GetUncommittedTokens() - uncommittedToken = &types.UncommittedTokens{ + rewardsUnclaimed := commitments.GetRewardsUnclaimed() + rewardUnclaimed = &types.RewardsUnclaimed{ Denom: denom, Amount: sdk.ZeroInt(), } - uncommittedTokens = append(uncommittedTokens, uncommittedToken) - commitments.UncommittedTokens = uncommittedTokens + rewardsUnclaimed = append(rewardsUnclaimed, rewardUnclaimed) + commitments.RewardsUnclaimed = rewardsUnclaimed } // Update the commitments @@ -351,7 +351,7 @@ func (k Keeper) ProcessWithdrawUSDC(ctx sdk.Context, creator string, denom strin // Vesting token // Check if vesting entity count is not exceeding the maximum and if it is fine, creates a new vesting entity -// Deduct from uncommitted bucket. If it is insufficent, deduct from committed bucket as well. +// Deduct from unclaimed bucket. If it is insufficent, deduct from committed bucket as well. func (k Keeper) ProcessTokenVesting(ctx sdk.Context, denom string, amount sdk.Int, creator string) error { vestingInfo, _ := k.GetVestingInfo(ctx, denom) diff --git a/x/commitment/keeper/msg_server_cancel_vest.go b/x/commitment/keeper/msg_server_cancel_vest.go index e33eea99e..ba805f4d4 100644 --- a/x/commitment/keeper/msg_server_cancel_vest.go +++ b/x/commitment/keeper/msg_server_cancel_vest.go @@ -9,11 +9,11 @@ import ( "github.com/elys-network/elys/x/commitment/types" ) +// CancelVest cancel the user's vesting and the user reject to get vested tokens func (k msgServer) CancelVest(goCtx context.Context, msg *types.MsgCancelVest) (*types.MsgCancelVestResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) vestingInfo, _ := k.GetVestingInfo(ctx, msg.Denom) - if vestingInfo == nil { return nil, sdkerrors.Wrapf(types.ErrInvalidDenom, "denom: %s", msg.Denom) } @@ -49,18 +49,18 @@ func (k msgServer) CancelVest(goCtx context.Context, msg *types.MsgCancelVest) ( return nil, sdkerrors.Wrapf(types.ErrInsufficientVestingTokens, "denom: %s, amount: %s", msg.Denom, msg.Amount) } - // Update the uncommitted tokens amount - uncommittedToken, found := commitments.GetUncommittedTokensForDenom(msg.Denom) + // Update the unclaimed tokens amount + rewardUnclaimed, found := commitments.GetRewardsUnclaimedForDenom(msg.Denom) if found { - uncommittedToken.Amount = uncommittedToken.Amount.Add(msg.Amount) + rewardUnclaimed.Amount = rewardUnclaimed.Amount.Add(msg.Amount) } else { - uncommittedTokens := commitments.GetUncommittedTokens() - uncommittedTokens = append(uncommittedTokens, &types.UncommittedTokens{ + rewardsUnclaimed := commitments.GetRewardsUnclaimed() + rewardsUnclaimed = append(rewardsUnclaimed, &types.RewardsUnclaimed{ Denom: msg.Denom, Amount: msg.Amount, }) - commitments.UncommittedTokens = uncommittedTokens + commitments.RewardsUnclaimed = rewardsUnclaimed } k.SetCommitments(ctx, commitments) diff --git a/x/commitment/keeper/msg_server_cancel_vest_test.go b/x/commitment/keeper/msg_server_cancel_vest_test.go index 983519cef..2d73a6d5b 100644 --- a/x/commitment/keeper/msg_server_cancel_vest_test.go +++ b/x/commitment/keeper/msg_server_cancel_vest_test.go @@ -80,8 +80,8 @@ func TestCancelVest(t *testing.T) { require.Len(t, newCommitments.VestingTokens, 1, "vesting tokens were not updated correctly") require.Equal(t, sdk.NewInt(75), newCommitments.VestingTokens[0].TotalAmount, "total amount was not updated correctly") require.Equal(t, sdk.NewInt(75), newCommitments.VestingTokens[0].UnvestedAmount, "unvested amount was not updated correctly") - // check if the uncommitted tokens were updated correctly - require.Equal(t, sdk.NewInt(25), newCommitments.GetUncommittedAmountForDenom(ptypes.Eden)) + // check if the unclaimed tokens were updated correctly + require.Equal(t, sdk.NewInt(25), newCommitments.GetUnclaimedAmountForDenom(ptypes.Eden)) // Try to cancel an amount that exceeds the unvested amount cancelVestMsg.Amount = sdk.NewInt(101) diff --git a/x/commitment/keeper/msg_server_commit_liquid_tokens.go b/x/commitment/keeper/msg_server_commit_liquid_tokens.go index 9fc9921a5..824f1e162 100644 --- a/x/commitment/keeper/msg_server_commit_liquid_tokens.go +++ b/x/commitment/keeper/msg_server_commit_liquid_tokens.go @@ -10,6 +10,7 @@ import ( "github.com/elys-network/elys/x/commitment/types" ) +// CommitLiquidTokens commit the tokens from user's balance func (k msgServer) CommitLiquidTokens(goCtx context.Context, msg *types.MsgCommitLiquidTokens) (*types.MsgCommitLiquidTokensResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -44,27 +45,14 @@ func (k msgServer) CommitLiquidTokens(goCtx context.Context, msg *types.MsgCommi commitments, found := k.GetCommitments(ctx, msg.Creator) if !found { commitments = types.Commitments{ - Creator: msg.Creator, - CommittedTokens: []*types.CommittedTokens{}, - UncommittedTokens: []*types.UncommittedTokens{}, + Creator: msg.Creator, + CommittedTokens: []*types.CommittedTokens{}, + RewardsUnclaimed: []*types.RewardsUnclaimed{}, } } - // Get the committed tokens for the creator - committedToken, found := commitments.GetCommittedTokensForDenom(msg.Denom) - if !found { - committedTokens := commitments.GetCommittedTokens() - committedToken = &types.CommittedTokens{ - Denom: msg.Denom, - Amount: sdk.ZeroInt(), - } - committedTokens = append(committedTokens, committedToken) - commitments.CommittedTokens = committedTokens - } - - // Update the committed tokens amount - committedToken.Amount = committedToken.Amount.Add(msg.Amount) // Update the commitments + commitments.AddCommitedTokens(msg.Denom, msg.Amount, uint64(ctx.BlockTime().Unix())+msg.MinLock) k.SetCommitments(ctx, commitments) // Emit Hook commitment changed diff --git a/x/commitment/keeper/msg_server_commit_liquid_tokens_test.go b/x/commitment/keeper/msg_server_commit_liquid_tokens_test.go index 81b7fa0ed..a88e3cb98 100644 --- a/x/commitment/keeper/msg_server_commit_liquid_tokens_test.go +++ b/x/commitment/keeper/msg_server_commit_liquid_tokens_test.go @@ -51,7 +51,7 @@ func TestCommitLiquidTokens(t *testing.T) { _, err = msgServer.CommitLiquidTokens(ctx, commitMsg) require.NoError(t, err) - // Check if the tokens were deposited and uncommitted balance was updated + // Check if the tokens were deposited and unclaimed balance was updated commitments, found := keeper.GetCommitments(ctx, commitMsg.Creator) require.True(t, found, "commitments not found") diff --git a/x/commitment/keeper/msg_server_commit_tokens.go b/x/commitment/keeper/msg_server_commit_unclaimed_rewards.go similarity index 67% rename from x/commitment/keeper/msg_server_commit_tokens.go rename to x/commitment/keeper/msg_server_commit_unclaimed_rewards.go index b88c4b1ef..fef3d0b8e 100644 --- a/x/commitment/keeper/msg_server_commit_tokens.go +++ b/x/commitment/keeper/msg_server_commit_unclaimed_rewards.go @@ -9,7 +9,8 @@ import ( "github.com/elys-network/elys/x/commitment/types" ) -func (k msgServer) CommitTokens(goCtx context.Context, msg *types.MsgCommitTokens) (*types.MsgCommitTokensResponse, error) { +// CommitUnclaimedRewards commit the tokens on unclaimed store to committed +func (k msgServer) CommitUnclaimedRewards(goCtx context.Context, msg *types.MsgCommitUnclaimedRewards) (*types.MsgCommitUnclaimedRewardsResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) assetProfile, found := k.apKeeper.GetEntry(ctx, msg.Denom) @@ -27,18 +28,18 @@ func (k msgServer) CommitTokens(goCtx context.Context, msg *types.MsgCommitToken return nil, sdkerrors.Wrapf(types.ErrCommitmentsNotFound, "creator: %s", msg.Creator) } - // Check if the uncommitted tokens have enough amount to be committed - uncommittedToken, found := commitments.GetUncommittedTokensForDenom(msg.Denom) + // Check if the unclaimed tokens have enough amount to be committed + rewardUnclaimed, found := commitments.GetRewardsUnclaimedForDenom(msg.Denom) if !found { - return nil, sdkerrors.Wrapf(types.ErrInsufficientUncommittedTokens, "creator: %s", msg.Creator) + return nil, sdkerrors.Wrapf(types.ErrInsufficientRewardsUnclaimed, "creator: %s", msg.Creator) } - if uncommittedToken.Amount.LT(msg.Amount) { - return nil, sdkerrors.Wrapf(types.ErrInsufficientUncommittedTokens, "creator: %s, denom: %s", msg.Creator, msg.Denom) + if rewardUnclaimed.Amount.LT(msg.Amount) { + return nil, sdkerrors.Wrapf(types.ErrInsufficientRewardsUnclaimed, "creator: %s, denom: %s", msg.Creator, msg.Denom) } - // Update the uncommitted tokens amount - uncommittedToken.Amount = uncommittedToken.Amount.Sub(msg.Amount) + // Update the unclaimed tokens amount + rewardUnclaimed.Amount = rewardUnclaimed.Amount.Sub(msg.Amount) // Update the committed tokens amount committedToken, found := commitments.GetCommittedTokensForDenom(msg.Denom) @@ -69,5 +70,5 @@ func (k msgServer) CommitTokens(goCtx context.Context, msg *types.MsgCommitToken ), ) - return &types.MsgCommitTokensResponse{}, nil + return &types.MsgCommitUnclaimedRewardsResponse{}, nil } diff --git a/x/commitment/keeper/msg_server_commit_tokens_test.go b/x/commitment/keeper/msg_server_commit_unclaimed_rewards_test.go similarity index 78% rename from x/commitment/keeper/msg_server_commit_tokens_test.go rename to x/commitment/keeper/msg_server_commit_unclaimed_rewards_test.go index 62199e7f9..f813e99c0 100644 --- a/x/commitment/keeper/msg_server_commit_tokens_test.go +++ b/x/commitment/keeper/msg_server_commit_unclaimed_rewards_test.go @@ -14,7 +14,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestCommitTokens(t *testing.T) { +func TestCommitUnclaimedRewards(t *testing.T) { // Create a test context and keeper app := app.InitElysTestApp(true) @@ -26,18 +26,18 @@ func TestCommitTokens(t *testing.T) { // Define the test data creator := "test_creator" denom := "test_denom" - initialUncommitted := sdk.NewInt(500) + initialUnclaimed := sdk.NewInt(500) commitAmount := sdk.NewInt(100) - // Set up initial commitments object with sufficient uncommitted tokens - uncommittedTokens := types.UncommittedTokens{ + // Set up initial commitments object with sufficient unclaimed tokens + rewardsUnclaimed := types.RewardsUnclaimed{ Denom: denom, - Amount: initialUncommitted, + Amount: initialUnclaimed, } initialCommitments := types.Commitments{ - Creator: creator, - UncommittedTokens: []*types.UncommittedTokens{&uncommittedTokens}, + Creator: creator, + RewardsUnclaimed: []*types.RewardsUnclaimed{&rewardsUnclaimed}, } keeper.SetCommitments(ctx, initialCommitments) @@ -45,13 +45,13 @@ func TestCommitTokens(t *testing.T) { // Set assetprofile entry for denom app.AssetprofileKeeper.SetEntry(ctx, aptypes.Entry{BaseDenom: denom, CommitEnabled: true}) - // Call the CommitTokens function - msg := types.MsgCommitTokens{ + // Call the CommitUnclaimedRewards function + msg := types.MsgCommitUnclaimedRewards{ Creator: creator, Amount: commitAmount, Denom: denom, } - _, err := msgServer.CommitTokens(ctx, &msg) + _, err := msgServer.CommitUnclaimedRewards(ctx, &msg) require.NoError(t, err) // Check if the committed tokens have been added to the store diff --git a/x/commitment/keeper/msg_server_uncommit_tokens.go b/x/commitment/keeper/msg_server_uncommit_tokens.go index 3cbb6e72a..c1e6434c7 100644 --- a/x/commitment/keeper/msg_server_uncommit_tokens.go +++ b/x/commitment/keeper/msg_server_uncommit_tokens.go @@ -10,7 +10,7 @@ import ( ptypes "github.com/elys-network/elys/x/parameter/types" ) -// uncommit the committed one and make it liquid immediately. +// UncommitTokens uncommits the tokens from committed store and make it liquid immediately. func (k msgServer) UncommitTokens(goCtx context.Context, msg *types.MsgUncommitTokens) (*types.MsgUncommitTokensResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -29,22 +29,17 @@ func (k msgServer) UncommitTokens(goCtx context.Context, msg *types.MsgUncommitT return nil, sdkerrors.Wrapf(types.ErrCommitmentsNotFound, "creator: %s", msg.Creator) } - // Check if the committed tokens have enough amount to be uncommitted - committedToken, _ := commitments.GetCommittedTokensForDenom(msg.Denom) - if committedToken.Amount.LT(msg.Amount) { - return nil, sdkerrors.Wrapf(types.ErrInsufficientCommittedTokens, "creator: %s, denom: %s", msg.Creator, msg.Denom) + // Deduct from committed tokens + err := commitments.DeductFromCommitted(msg.Denom, msg.Amount, uint64(ctx.BlockTime().Unix())) + if err != nil { + return nil, err } - - // Update the committed tokens amount - committedToken.Amount = committedToken.Amount.Sub(msg.Amount) - - // Update the commitments k.SetCommitments(ctx, commitments) liquidCoins := sdk.NewCoins(sdk.NewCoin(msg.Denom, msg.Amount)) // Mint the withdrawn tokens to the module account - err := k.bankKeeper.MintCoins(ctx, types.ModuleName, liquidCoins) + err = k.bankKeeper.MintCoins(ctx, types.ModuleName, liquidCoins) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "unable to mint liquid tokens") } diff --git a/x/commitment/keeper/msg_server_uncommit_tokens_test.go b/x/commitment/keeper/msg_server_uncommit_tokens_test.go index b2be8ffa1..3d1fac630 100644 --- a/x/commitment/keeper/msg_server_uncommit_tokens_test.go +++ b/x/commitment/keeper/msg_server_uncommit_tokens_test.go @@ -29,14 +29,14 @@ func TestUncommitTokens(t *testing.T) { // Define the test data creator := addr[0].String() denom := "test_denom" - initialUncommitted := sdk.NewInt(400) + initialUnclaimed := sdk.NewInt(400) initialCommitted := sdk.NewInt(100) uncommitAmount := sdk.NewInt(100) - // Set up initial commitments object with sufficient uncommitted & committed tokens - uncommittedTokens := types.UncommittedTokens{ + // Set up initial commitments object with sufficient unclaimed & committed tokens + rewardsUnclaimed := types.RewardsUnclaimed{ Denom: denom, - Amount: initialUncommitted, + Amount: initialUnclaimed, } committedTokens := types.CommittedTokens{ @@ -45,9 +45,9 @@ func TestUncommitTokens(t *testing.T) { } initialCommitments := types.Commitments{ - Creator: creator, - UncommittedTokens: []*types.UncommittedTokens{&uncommittedTokens}, - CommittedTokens: []*types.CommittedTokens{&committedTokens}, + Creator: creator, + RewardsUnclaimed: []*types.RewardsUnclaimed{&rewardsUnclaimed}, + CommittedTokens: []*types.CommittedTokens{&committedTokens}, } keeper.SetCommitments(ctx, initialCommitments) @@ -74,8 +74,8 @@ func TestUncommitTokens(t *testing.T) { assert.Equal(t, denom, commitments.CommittedTokens[0].Denom, "Incorrect denom") assert.Equal(t, sdk.ZeroInt(), commitments.CommittedTokens[0].Amount, "Incorrect amount") - uncommittedToken := sdk.NewCoins(sdk.NewCoin(denom, uncommitAmount)) + rewardUnclaimed := sdk.NewCoins(sdk.NewCoin(denom, uncommitAmount)) edenCoin := app.BankKeeper.GetBalance(ctx, addr[0], denom) - require.Equal(t, sdk.Coins{edenCoin}, uncommittedToken) + require.Equal(t, sdk.Coins{edenCoin}, rewardUnclaimed) } diff --git a/x/commitment/keeper/msg_server_update_vesting_info.go b/x/commitment/keeper/msg_server_update_vesting_info.go index 107eb178b..920069031 100644 --- a/x/commitment/keeper/msg_server_update_vesting_info.go +++ b/x/commitment/keeper/msg_server_update_vesting_info.go @@ -9,6 +9,7 @@ import ( "github.com/elys-network/elys/x/commitment/types" ) +// UpdateVestingInfo add/update specific vesting info by denom on Params func (k msgServer) UpdateVestingInfo(goCtx context.Context, msg *types.MsgUpdateVestingInfo) (*types.MsgUpdateVestingInfoResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) diff --git a/x/commitment/keeper/msg_server_update_vesting_info_test.go b/x/commitment/keeper/msg_server_update_vesting_info_test.go index a6071fa4b..95c0a56ec 100644 --- a/x/commitment/keeper/msg_server_update_vesting_info_test.go +++ b/x/commitment/keeper/msg_server_update_vesting_info_test.go @@ -73,7 +73,7 @@ func TestUpdateVestingInfo(t *testing.T) { vestingInfo, _ = keeper.GetVestingInfo(ctx, "test_denom") assert.Equal(t, vestingInfo.BaseDenom, "test_denom", "Incorrect denom") - // Call the UncommitTokens function + // Call the UpdateVestingInfo function msg := types.MsgUpdateVestingInfo{ Authority: signer, BaseDenom: "test_denom", diff --git a/x/commitment/keeper/msg_server_vest.go b/x/commitment/keeper/msg_server_vest.go index 00c0eda49..f76cd55d8 100644 --- a/x/commitment/keeper/msg_server_vest.go +++ b/x/commitment/keeper/msg_server_vest.go @@ -8,6 +8,8 @@ import ( "github.com/elys-network/elys/x/commitment/types" ) +// Vest converts user's commitment to vesting - start with unclaimed rewards and if it's not enough deduct from committed bucket +// mainly utilized for Eden func (k msgServer) Vest(goCtx context.Context, msg *types.MsgVest) (*types.MsgVestResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) if err := k.ProcessTokenVesting(ctx, msg.Denom, msg.Amount, msg.Creator); err != nil { diff --git a/x/commitment/keeper/msg_server_vest_liquid.go b/x/commitment/keeper/msg_server_vest_liquid.go index 65f7e4a64..51d3b0e4e 100644 --- a/x/commitment/keeper/msg_server_vest_liquid.go +++ b/x/commitment/keeper/msg_server_vest_liquid.go @@ -7,9 +7,10 @@ import ( "github.com/elys-network/elys/x/commitment/types" ) +// VestLiquid converts user's balance to vesting to be utilized for normal tokens vesting like ATOM vesting func (k msgServer) VestLiquid(goCtx context.Context, msg *types.MsgVestLiquid) (*types.MsgVestLiquidResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - if err := k.DepositLiquidTokensUncommitted(ctx, msg.Denom, msg.Amount, msg.Creator); err != nil { + if err := k.DepositLiquidTokensUnclaimed(ctx, msg.Denom, msg.Amount, msg.Creator); err != nil { return &types.MsgVestLiquidResponse{}, err } diff --git a/x/commitment/keeper/msg_server_vest_liquid_test.go b/x/commitment/keeper/msg_server_vest_liquid_test.go index c5f819ffd..9a7ae82f1 100644 --- a/x/commitment/keeper/msg_server_vest_liquid_test.go +++ b/x/commitment/keeper/msg_server_vest_liquid_test.go @@ -68,7 +68,7 @@ func TestLiquidVestWithExceed(t *testing.T) { Amount: sdk.NewInt(50), }, }, - UncommittedTokens: []*types.UncommittedTokens{ + RewardsUnclaimed: []*types.RewardsUnclaimed{ { Denom: ptypes.Eden, Amount: sdk.NewInt(150), @@ -89,9 +89,9 @@ func TestLiquidVestWithExceed(t *testing.T) { require.True(t, found, "commitments not found") require.Len(t, newCommitments.VestingTokens, 1, "vesting tokens were not added") - // Check if the uncommitted tokens were updated correctly - uncommittedToken := newCommitments.GetUncommittedAmountForDenom(vestMsg.Denom) - require.Equal(t, sdk.NewInt(150), uncommittedToken, "uncommitted tokens were not updated correctly") + // Check if the unclaimed tokens were updated correctly + rewardUnclaimed := newCommitments.GetUnclaimedAmountForDenom(vestMsg.Denom) + require.Equal(t, sdk.NewInt(150), rewardUnclaimed, "unclaimed tokens were not updated correctly") // Check if the committed tokens were updated correctly committedToken := newCommitments.GetCommittedAmountForDenom(vestMsg.Denom) diff --git a/x/commitment/keeper/msg_server_vest_now.go b/x/commitment/keeper/msg_server_vest_now.go index 42e9b474c..c467c658a 100644 --- a/x/commitment/keeper/msg_server_vest_now.go +++ b/x/commitment/keeper/msg_server_vest_now.go @@ -8,11 +8,19 @@ import ( "github.com/elys-network/elys/x/commitment/types" ) +// VestNow is not enabled at this stage +var VestNowEnabled = false + +// VestNow provides functionality to get the token immediately but lower amount than original +// e.g. user can burn 1000 ueden and get 800 uelys when the ratio is 80% func (k msgServer) VestNow(goCtx context.Context, msg *types.MsgVestNow) (*types.MsgVestNowResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - vestingInfo, _ := k.GetVestingInfo(ctx, msg.Denom) + if !VestNowEnabled { + return nil, types.ErrVestNowIsNotEnabled + } + vestingInfo, _ := k.GetVestingInfo(ctx, msg.Denom) if vestingInfo == nil { return nil, sdkerrors.Wrapf(types.ErrInvalidDenom, "denom: %s", msg.Denom) } @@ -23,7 +31,6 @@ func (k msgServer) VestNow(goCtx context.Context, msg *types.MsgVestNow) (*types } vestAmount := msg.Amount.Quo(vestingInfo.VestNowFactor) - withdrawCoins := sdk.NewCoins(sdk.NewCoin(vestingInfo.VestingDenom, vestAmount)) // Mint the vested tokens to the module account diff --git a/x/commitment/keeper/msg_server_vest_now_test.go b/x/commitment/keeper/msg_server_vest_now_test.go index d83781457..7b98ce861 100644 --- a/x/commitment/keeper/msg_server_vest_now_test.go +++ b/x/commitment/keeper/msg_server_vest_now_test.go @@ -18,6 +18,9 @@ import ( func TestVestNow(t *testing.T) { app := app.InitElysTestApp(true) + // Enable VestNow for test + commitmentkeeper.VestNowEnabled = true + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) // Create a test context and keeper keeper := app.CommitmentKeeper @@ -28,7 +31,7 @@ func TestVestNow(t *testing.T) { // Define the test data creator := creatorAddr.String() denom := ptypes.Eden - initialUncommitted := sdk.NewInt(5000) + initialUnclaimed := sdk.NewInt(5000) initialCommitted := sdk.NewInt(10000) vestingInfos := []*types.VestingInfo{ @@ -48,10 +51,10 @@ func TestVestNow(t *testing.T) { keeper.SetParams(ctx, params) - // Set up initial commitments object with sufficient uncommitted & committed tokens - uncommittedTokens := types.UncommittedTokens{ + // Set up initial commitments object with sufficient unclaimed & committed tokens + rewardsUnclaimed := types.RewardsUnclaimed{ Denom: denom, - Amount: initialUncommitted, + Amount: initialUnclaimed, } committedTokens := types.CommittedTokens{ @@ -60,14 +63,14 @@ func TestVestNow(t *testing.T) { } initialCommitments := types.Commitments{ - Creator: creator, - UncommittedTokens: []*types.UncommittedTokens{&uncommittedTokens}, - CommittedTokens: []*types.CommittedTokens{&committedTokens}, + Creator: creator, + RewardsUnclaimed: []*types.RewardsUnclaimed{&rewardsUnclaimed}, + CommittedTokens: []*types.CommittedTokens{&committedTokens}, } keeper.SetCommitments(ctx, initialCommitments) - // Test scenario 1: Withdraw within uncommitted balance + // Test scenario 1: Withdraw within unclaimed balance msg := &types.MsgVestNow{ Creator: creator, Amount: sdk.NewInt(3000), @@ -80,13 +83,13 @@ func TestVestNow(t *testing.T) { updatedCommitments, found := keeper.GetCommitments(ctx, creator) require.True(t, found) - uncommittedBalance := updatedCommitments.GetUncommittedAmountForDenom(denom) - assert.Equal(t, sdk.NewInt(2000), uncommittedBalance) + unclaimedBalance := updatedCommitments.GetUnclaimedAmountForDenom(denom) + assert.Equal(t, sdk.NewInt(2000), unclaimedBalance) // Check if the vested tokens were received creatorBalance := app.BankKeeper.GetBalance(ctx, creatorAddr, vestingInfos[0].VestingDenom) require.Equal(t, sdk.NewInt(33), creatorBalance.Amount, "tokens were not vested correctly") - // Test scenario 2: Withdraw more than uncommitted balance but within total balance + // Test scenario 2: Withdraw more than unclaimed balance but within total balance msg = &types.MsgVestNow{ Creator: creator, Amount: sdk.NewInt(7000), @@ -99,8 +102,8 @@ func TestVestNow(t *testing.T) { updatedCommitments, found = keeper.GetCommitments(ctx, creator) require.True(t, found) - uncommittedBalance = updatedCommitments.GetUncommittedAmountForDenom(denom) - assert.Equal(t, sdk.NewInt(0), uncommittedBalance) + unclaimedBalance = updatedCommitments.GetUnclaimedAmountForDenom(denom) + assert.Equal(t, sdk.NewInt(0), unclaimedBalance) committedBalance := updatedCommitments.GetCommittedAmountForDenom(denom) assert.Equal(t, sdk.NewInt(5000), committedBalance) diff --git a/x/commitment/keeper/msg_server_vest_test.go b/x/commitment/keeper/msg_server_vest_test.go index 257710db4..56dc3b1ee 100644 --- a/x/commitment/keeper/msg_server_vest_test.go +++ b/x/commitment/keeper/msg_server_vest_test.go @@ -64,7 +64,7 @@ func TestVest(t *testing.T) { Amount: sdk.NewInt(50), }, }, - UncommittedTokens: []*types.UncommittedTokens{ + RewardsUnclaimed: []*types.RewardsUnclaimed{ { Denom: ptypes.Eden, Amount: sdk.NewInt(150), @@ -82,9 +82,9 @@ func TestVest(t *testing.T) { require.True(t, found, "commitments not found") require.Len(t, newCommitments.VestingTokens, 1, "vesting tokens were not added") - // Check if the uncommitted tokens were updated correctly - uncommittedToken := newCommitments.GetUncommittedAmountForDenom(vestMsg.Denom) - require.Equal(t, sdk.NewInt(50), uncommittedToken, "uncommitted tokens were not updated correctly") + // Check if the unclaimed tokens were updated correctly + rewardUnclaimed := newCommitments.GetUnclaimedAmountForDenom(vestMsg.Denom) + require.Equal(t, sdk.NewInt(50), rewardUnclaimed, "unclaimed tokens were not updated correctly") // Check if the committed tokens were updated correctly committedToken := newCommitments.GetCommittedAmountForDenom(vestMsg.Denom) @@ -98,9 +98,9 @@ func TestVest(t *testing.T) { require.True(t, found, "commitments not found") require.Len(t, newCommitments.VestingTokens, 2, "vesting tokens were not added") - // Check if the uncommitted tokens were updated correctly - uncommittedToken = newCommitments.GetUncommittedAmountForDenom(vestMsg.Denom) - require.Equal(t, sdk.NewInt(0), uncommittedToken, "uncommitted tokens were not updated correctly") + // Check if the unclaimed tokens were updated correctly + rewardUnclaimed = newCommitments.GetUnclaimedAmountForDenom(vestMsg.Denom) + require.Equal(t, sdk.NewInt(0), rewardUnclaimed, "unclaimed tokens were not updated correctly") // Check if the committed tokens were updated correctly committedToken = newCommitments.GetCommittedAmountForDenom(vestMsg.Denom) @@ -157,7 +157,7 @@ func TestExceedVesting(t *testing.T) { Amount: sdk.NewInt(50), }, }, - UncommittedTokens: []*types.UncommittedTokens{ + RewardsUnclaimed: []*types.RewardsUnclaimed{ { Denom: ptypes.Eden, Amount: sdk.NewInt(150), @@ -175,9 +175,9 @@ func TestExceedVesting(t *testing.T) { require.True(t, found, "commitments not found") require.Len(t, newCommitments.VestingTokens, 1, "vesting tokens were not added") - // Check if the uncommitted tokens were updated correctly - uncommittedToken := newCommitments.GetUncommittedAmountForDenom(vestMsg.Denom) - require.Equal(t, sdk.NewInt(50), uncommittedToken, "uncommitted tokens were not updated correctly") + // Check if the unclaimed tokens were updated correctly + rewardUnclaimed := newCommitments.GetUnclaimedAmountForDenom(vestMsg.Denom) + require.Equal(t, sdk.NewInt(50), rewardUnclaimed, "unclaimed tokens were not updated correctly") // Check if the committed tokens were updated correctly committedToken := newCommitments.GetCommittedAmountForDenom(vestMsg.Denom) diff --git a/x/commitment/keeper/msg_server_withdraw_tokens.go b/x/commitment/keeper/msg_server_withdraw_tokens.go index 5ee606af1..3268804d2 100644 --- a/x/commitment/keeper/msg_server_withdraw_tokens.go +++ b/x/commitment/keeper/msg_server_withdraw_tokens.go @@ -7,6 +7,7 @@ import ( "github.com/elys-network/elys/x/commitment/types" ) +// WithdrawTokens withdraw first from unclaimed and if it requires more, withdraw from committed store func (k msgServer) WithdrawTokens(goCtx context.Context, msg *types.MsgWithdrawTokens) (*types.MsgWithdrawTokensResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) // Withdraw tokens diff --git a/x/commitment/keeper/msg_server_withdraw_tokens_test.go b/x/commitment/keeper/msg_server_withdraw_tokens_test.go index c30dc8fc1..d0b966682 100644 --- a/x/commitment/keeper/msg_server_withdraw_tokens_test.go +++ b/x/commitment/keeper/msg_server_withdraw_tokens_test.go @@ -30,13 +30,13 @@ func TestWithdrawTokens(t *testing.T) { // Define the test data creator := creatorAddr.String() denom := ptypes.Eden - initialUncommitted := sdk.NewInt(50) + initialUnclaimed := sdk.NewInt(50) initialCommitted := sdk.NewInt(100) - // Set up initial commitments object with sufficient uncommitted & committed tokens - uncommittedTokens := types.UncommittedTokens{ + // Set up initial commitments object with sufficient unclaimed & committed tokens + rewardsUnclaimed := types.RewardsUnclaimed{ Denom: denom, - Amount: initialUncommitted, + Amount: initialUnclaimed, } committedTokens := types.CommittedTokens{ @@ -45,9 +45,9 @@ func TestWithdrawTokens(t *testing.T) { } initialCommitments := types.Commitments{ - Creator: creator, - UncommittedTokens: []*types.UncommittedTokens{&uncommittedTokens}, - CommittedTokens: []*types.CommittedTokens{&committedTokens}, + Creator: creator, + RewardsUnclaimed: []*types.RewardsUnclaimed{&rewardsUnclaimed}, + CommittedTokens: []*types.CommittedTokens{&committedTokens}, } keeper.SetCommitments(ctx, initialCommitments) @@ -55,7 +55,7 @@ func TestWithdrawTokens(t *testing.T) { // Set assetprofile entry for denom app.AssetprofileKeeper.SetEntry(ctx, aptypes.Entry{BaseDenom: denom, WithdrawEnabled: true}) - // Test scenario 1: Withdraw within uncommitted balance + // Test scenario 1: Withdraw within unclaimed balance msg := &types.MsgWithdrawTokens{ Creator: creator, Amount: sdk.NewInt(30), @@ -68,14 +68,14 @@ func TestWithdrawTokens(t *testing.T) { updatedCommitments, found := keeper.GetCommitments(ctx, creator) require.True(t, found) - uncommittedBalance := updatedCommitments.GetUncommittedAmountForDenom(denom) - assert.Equal(t, sdk.NewInt(20), uncommittedBalance) + unclaimedBalance := updatedCommitments.GetUnclaimedAmountForDenom(denom) + assert.Equal(t, sdk.NewInt(20), unclaimedBalance) // Check if the withdrawn tokens were received creatorBalance := app.BankKeeper.GetBalance(ctx, creatorAddr, denom) require.Equal(t, sdk.NewInt(30), creatorBalance.Amount, "tokens were not withdrawn correctly") - // Test scenario 2: Withdraw more than uncommitted balance but within total balance + // Test scenario 2: Withdraw more than unclaimed balance but within total balance msg = &types.MsgWithdrawTokens{ Creator: creator, Amount: sdk.NewInt(70), @@ -88,8 +88,8 @@ func TestWithdrawTokens(t *testing.T) { updatedCommitments, found = keeper.GetCommitments(ctx, creator) require.True(t, found) - uncommittedBalance = updatedCommitments.GetUncommittedAmountForDenom(denom) - assert.Equal(t, sdk.NewInt(0), uncommittedBalance) + unclaimedBalance = updatedCommitments.GetUnclaimedAmountForDenom(denom) + assert.Equal(t, sdk.NewInt(0), unclaimedBalance) committedBalance := updatedCommitments.GetCommittedAmountForDenom(denom) assert.Equal(t, sdk.NewInt(50), committedBalance) diff --git a/x/commitment/module_simulation.go b/x/commitment/module_simulation.go index 91b9ae45c..bff7baeb8 100644 --- a/x/commitment/module_simulation.go +++ b/x/commitment/module_simulation.go @@ -22,9 +22,9 @@ var ( ) const ( - opWeightMsgCommitTokens = "op_weight_msg_commit_tokens" + opWeightMsgCommitUnclaimedRewards = "op_weight_msg_commit_tokens" // TODO: Determine the simulation weight value - defaultWeightMsgCommitTokens int = 100 + defaultWeightMsgCommitUnclaimedRewards int = 100 opWeightMsgUncommitTokens = "op_weight_msg_uncommit_tokens" // TODO: Determine the simulation weight value @@ -86,15 +86,15 @@ func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { operations := make([]simtypes.WeightedOperation, 0) - var weightMsgCommitTokens int - simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgCommitTokens, &weightMsgCommitTokens, nil, + var weightMsgCommitUnclaimedRewards int + simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgCommitUnclaimedRewards, &weightMsgCommitUnclaimedRewards, nil, func(_ *rand.Rand) { - weightMsgCommitTokens = defaultWeightMsgCommitTokens + weightMsgCommitUnclaimedRewards = defaultWeightMsgCommitUnclaimedRewards }, ) operations = append(operations, simulation.NewWeightedOperation( - weightMsgCommitTokens, - commitmentsimulation.SimulateMsgCommitTokens(am.accountKeeper, am.bankKeeper, am.keeper), + weightMsgCommitUnclaimedRewards, + commitmentsimulation.SimulateMsgCommitUnclaimedRewards(am.accountKeeper, am.bankKeeper, am.keeper), )) var weightMsgUncommitTokens int diff --git a/x/commitment/simulation/commit_tokens.go b/x/commitment/simulation/commit_tokens.go index a801dedda..db98fab91 100644 --- a/x/commitment/simulation/commit_tokens.go +++ b/x/commitment/simulation/commit_tokens.go @@ -10,7 +10,7 @@ import ( "github.com/elys-network/elys/x/commitment/types" ) -func SimulateMsgCommitTokens( +func SimulateMsgCommitUnclaimedRewards( ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, @@ -18,12 +18,12 @@ func SimulateMsgCommitTokens( return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { simAccount, _ := simtypes.RandomAcc(r, accs) - msg := &types.MsgCommitTokens{ + msg := &types.MsgCommitUnclaimedRewards{ Creator: simAccount.Address.String(), } - // TODO: Handling the CommitTokens simulation + // TODO: Handling the CommitUnclaimedRewards simulation - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "CommitTokens simulation not implemented"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "CommitUnclaimedRewards simulation not implemented"), nil, nil } } diff --git a/x/commitment/types/codec.go b/x/commitment/types/codec.go index 9dff8c061..00da1ecd8 100644 --- a/x/commitment/types/codec.go +++ b/x/commitment/types/codec.go @@ -8,7 +8,7 @@ import ( ) func RegisterCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&MsgCommitTokens{}, "commitment/CommitTokens", nil) + cdc.RegisterConcrete(&MsgCommitUnclaimedRewards{}, "commitment/CommitUnclaimedRewards", nil) cdc.RegisterConcrete(&MsgUncommitTokens{}, "commitment/UncommitTokens", nil) cdc.RegisterConcrete(&MsgWithdrawTokens{}, "commitment/WithdrawTokens", nil) cdc.RegisterConcrete(&MsgCommitLiquidTokens{}, "commitment/CommitLiquidTokens", nil) @@ -22,7 +22,7 @@ func RegisterCodec(cdc *codec.LegacyAmino) { func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), - &MsgCommitTokens{}, + &MsgCommitUnclaimedRewards{}, ) registry.RegisterImplementations((*sdk.Msg)(nil), &MsgUncommitTokens{}, diff --git a/x/commitment/types/commitments.go b/x/commitment/types/commitments.go index 2a9c5e6b4..a7e0011fd 100644 --- a/x/commitment/types/commitments.go +++ b/x/commitment/types/commitments.go @@ -4,13 +4,13 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -func (c *Commitments) GetUncommittedTokensForDenom(denom string) (*UncommittedTokens, bool) { - for _, token := range c.UncommittedTokens { +func (c *Commitments) GetRewardsUnclaimedForDenom(denom string) (*RewardsUnclaimed, bool) { + for _, token := range c.RewardsUnclaimed { if token.Denom == denom { return token, true } } - return &UncommittedTokens{}, false + return &RewardsUnclaimed{}, false } func (c *Commitments) GetCommittedTokensForDenom(denom string) (*CommittedTokens, bool) { @@ -22,8 +22,8 @@ func (c *Commitments) GetCommittedTokensForDenom(denom string) (*CommittedTokens return &CommittedTokens{}, false } -func (c *Commitments) GetUncommittedAmountForDenom(denom string) sdk.Int { - for _, token := range c.UncommittedTokens { +func (c *Commitments) GetUnclaimedAmountForDenom(denom string) sdk.Int { + for _, token := range c.RewardsUnclaimed { if token.Denom == denom { return token.Amount } @@ -39,3 +39,81 @@ func (c *Commitments) GetCommittedAmountForDenom(denom string) sdk.Int { } return sdk.NewInt(0) } + +func (c *Commitments) AddCommitedTokens(denom string, amount sdk.Int, unlockTime uint64) { + for i, token := range c.CommittedTokens { + if token.Denom == denom { + c.CommittedTokens[i].Amount = token.Amount.Add(amount) + c.CommittedTokens[i].Lockups = append(token.Lockups, Lockup{ + Amount: amount, + UnlockTimestamp: unlockTime, + }) + + li := int(0) + for _, lockup := range token.Lockups { + if lockup.UnlockTimestamp < unlockTime { + li++ + continue + } else if lockup.UnlockTimestamp == unlockTime { + c.CommittedTokens[i].Lockups[li].Amount = lockup.Amount.Add(amount) + return + } else { + break + } + } + c.CommittedTokens[i].Lockups = append(token.Lockups[:li+1], token.Lockups[li:]...) + c.CommittedTokens[i].Lockups[li] = Lockup{ + Amount: amount, + UnlockTimestamp: unlockTime, + } + return + } + } + c.CommittedTokens = append(c.CommittedTokens, &CommittedTokens{ + Denom: denom, + Amount: amount, + Lockups: []Lockup{ + { + Amount: amount, + UnlockTimestamp: unlockTime, + }, + }, + }) +} + +func (c *Commitments) DeductFromCommitted(denom string, amount sdk.Int, currTime uint64) error { + for i, token := range c.CommittedTokens { + if token.Denom == denom { + c.CommittedTokens[i].Amount = token.Amount.Sub(amount) + if c.CommittedTokens[i].Amount.IsNegative() { + return ErrInsufficientCommittedTokens + } + + withdrawnTokens := sdk.ZeroInt() + newLockups := []Lockup{} + + for _, lockup := range token.Lockups { + if withdrawnTokens.LT(amount) { + if lockup.UnlockTimestamp <= currTime { + withdrawAmount := lockup.Amount + if withdrawAmount.GT(amount.Sub(withdrawnTokens)) { + withdrawAmount = amount.Sub(withdrawnTokens) + newLockups = append(newLockups, Lockup{ + Amount: lockup.Amount.Sub(withdrawAmount), + UnlockTimestamp: lockup.UnlockTimestamp, + }) + } + withdrawnTokens = withdrawnTokens.Add(withdrawAmount) + } else { + return ErrInsufficientWithdrawableTokens + } + } else { + newLockups = append(newLockups, lockup) + } + } + c.CommittedTokens[i].Lockups = newLockups + return nil + } + } + return ErrInsufficientCommittedTokens +} diff --git a/x/commitment/types/commitments.pb.go b/x/commitment/types/commitments.pb.go index aa01a2477..b17225884 100644 --- a/x/commitment/types/commitments.pb.go +++ b/x/commitment/types/commitments.pb.go @@ -28,10 +28,10 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the commitment module's genesis state. type Commitments struct { - Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` - CommittedTokens []*CommittedTokens `protobuf:"bytes,2,rep,name=committed_tokens,json=committedTokens,proto3" json:"committed_tokens,omitempty"` - UncommittedTokens []*UncommittedTokens `protobuf:"bytes,3,rep,name=uncommitted_tokens,json=uncommittedTokens,proto3" json:"uncommitted_tokens,omitempty"` - VestingTokens []*VestingTokens `protobuf:"bytes,4,rep,name=vesting_tokens,json=vestingTokens,proto3" json:"vesting_tokens,omitempty"` + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + CommittedTokens []*CommittedTokens `protobuf:"bytes,2,rep,name=committed_tokens,json=committedTokens,proto3" json:"committed_tokens,omitempty"` + RewardsUnclaimed []*RewardsUnclaimed `protobuf:"bytes,3,rep,name=rewards_unclaimed,json=rewardsUnclaimed,proto3" json:"rewards_unclaimed,omitempty"` + VestingTokens []*VestingTokens `protobuf:"bytes,4,rep,name=vesting_tokens,json=vestingTokens,proto3" json:"vesting_tokens,omitempty"` } func (m *Commitments) Reset() { *m = Commitments{} } @@ -81,9 +81,9 @@ func (m *Commitments) GetCommittedTokens() []*CommittedTokens { return nil } -func (m *Commitments) GetUncommittedTokens() []*UncommittedTokens { +func (m *Commitments) GetRewardsUnclaimed() []*RewardsUnclaimed { if m != nil { - return m.UncommittedTokens + return m.RewardsUnclaimed } return nil } @@ -95,16 +95,62 @@ func (m *Commitments) GetVestingTokens() []*VestingTokens { return nil } +type Lockup struct { + Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` + UnlockTimestamp uint64 `protobuf:"varint,2,opt,name=unlock_timestamp,json=unlockTimestamp,proto3" json:"unlock_timestamp,omitempty"` +} + +func (m *Lockup) Reset() { *m = Lockup{} } +func (m *Lockup) String() string { return proto.CompactTextString(m) } +func (*Lockup) ProtoMessage() {} +func (*Lockup) Descriptor() ([]byte, []int) { + return fileDescriptor_47379c930fe66ed6, []int{1} +} +func (m *Lockup) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Lockup) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Lockup.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Lockup) XXX_Merge(src proto.Message) { + xxx_messageInfo_Lockup.Merge(m, src) +} +func (m *Lockup) XXX_Size() int { + return m.Size() +} +func (m *Lockup) XXX_DiscardUnknown() { + xxx_messageInfo_Lockup.DiscardUnknown(m) +} + +var xxx_messageInfo_Lockup proto.InternalMessageInfo + +func (m *Lockup) GetUnlockTimestamp() uint64 { + if m != nil { + return m.UnlockTimestamp + } + return 0 +} + type CommittedTokens struct { - Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` - Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` + Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` + Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` + Lockups []Lockup `protobuf:"bytes,3,rep,name=lockups,proto3" json:"lockups"` } func (m *CommittedTokens) Reset() { *m = CommittedTokens{} } func (m *CommittedTokens) String() string { return proto.CompactTextString(m) } func (*CommittedTokens) ProtoMessage() {} func (*CommittedTokens) Descriptor() ([]byte, []int) { - return fileDescriptor_47379c930fe66ed6, []int{1} + return fileDescriptor_47379c930fe66ed6, []int{2} } func (m *CommittedTokens) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -140,23 +186,30 @@ func (m *CommittedTokens) GetDenom() string { return "" } -type UncommittedTokens struct { +func (m *CommittedTokens) GetLockups() []Lockup { + if m != nil { + return m.Lockups + } + return nil +} + +type RewardsUnclaimed struct { Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` } -func (m *UncommittedTokens) Reset() { *m = UncommittedTokens{} } -func (m *UncommittedTokens) String() string { return proto.CompactTextString(m) } -func (*UncommittedTokens) ProtoMessage() {} -func (*UncommittedTokens) Descriptor() ([]byte, []int) { - return fileDescriptor_47379c930fe66ed6, []int{2} +func (m *RewardsUnclaimed) Reset() { *m = RewardsUnclaimed{} } +func (m *RewardsUnclaimed) String() string { return proto.CompactTextString(m) } +func (*RewardsUnclaimed) ProtoMessage() {} +func (*RewardsUnclaimed) Descriptor() ([]byte, []int) { + return fileDescriptor_47379c930fe66ed6, []int{3} } -func (m *UncommittedTokens) XXX_Unmarshal(b []byte) error { +func (m *RewardsUnclaimed) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *UncommittedTokens) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *RewardsUnclaimed) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_UncommittedTokens.Marshal(b, m, deterministic) + return xxx_messageInfo_RewardsUnclaimed.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -166,19 +219,19 @@ func (m *UncommittedTokens) XXX_Marshal(b []byte, deterministic bool) ([]byte, e return b[:n], nil } } -func (m *UncommittedTokens) XXX_Merge(src proto.Message) { - xxx_messageInfo_UncommittedTokens.Merge(m, src) +func (m *RewardsUnclaimed) XXX_Merge(src proto.Message) { + xxx_messageInfo_RewardsUnclaimed.Merge(m, src) } -func (m *UncommittedTokens) XXX_Size() int { +func (m *RewardsUnclaimed) XXX_Size() int { return m.Size() } -func (m *UncommittedTokens) XXX_DiscardUnknown() { - xxx_messageInfo_UncommittedTokens.DiscardUnknown(m) +func (m *RewardsUnclaimed) XXX_DiscardUnknown() { + xxx_messageInfo_RewardsUnclaimed.DiscardUnknown(m) } -var xxx_messageInfo_UncommittedTokens proto.InternalMessageInfo +var xxx_messageInfo_RewardsUnclaimed proto.InternalMessageInfo -func (m *UncommittedTokens) GetDenom() string { +func (m *RewardsUnclaimed) GetDenom() string { if m != nil { return m.Denom } @@ -198,7 +251,7 @@ func (m *VestingTokens) Reset() { *m = VestingTokens{} } func (m *VestingTokens) String() string { return proto.CompactTextString(m) } func (*VestingTokens) ProtoMessage() {} func (*VestingTokens) Descriptor() ([]byte, []int) { - return fileDescriptor_47379c930fe66ed6, []int{3} + return fileDescriptor_47379c930fe66ed6, []int{4} } func (m *VestingTokens) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -257,45 +310,51 @@ func (m *VestingTokens) GetCurrentEpoch() int64 { func init() { proto.RegisterType((*Commitments)(nil), "elys.commitment.Commitments") + proto.RegisterType((*Lockup)(nil), "elys.commitment.Lockup") proto.RegisterType((*CommittedTokens)(nil), "elys.commitment.CommittedTokens") - proto.RegisterType((*UncommittedTokens)(nil), "elys.commitment.UncommittedTokens") + proto.RegisterType((*RewardsUnclaimed)(nil), "elys.commitment.RewardsUnclaimed") proto.RegisterType((*VestingTokens)(nil), "elys.commitment.VestingTokens") } func init() { proto.RegisterFile("elys/commitment/commitments.proto", fileDescriptor_47379c930fe66ed6) } var fileDescriptor_47379c930fe66ed6 = []byte{ - // 480 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0xc7, 0xe3, 0xa4, 0x2d, 0xea, 0xa6, 0xa9, 0xdb, 0x55, 0x0f, 0x56, 0x05, 0x4e, 0x08, 0x12, - 0x0a, 0x87, 0xda, 0x12, 0x3c, 0x01, 0xad, 0x8a, 0x14, 0x71, 0xaa, 0xc5, 0x87, 0xc4, 0x25, 0x72, - 0xec, 0xad, 0x6b, 0x25, 0xbb, 0x63, 0x76, 0x67, 0x0b, 0x7d, 0x09, 0xc4, 0x23, 0x71, 0xec, 0xb1, - 0x47, 0xc4, 0xa1, 0x42, 0xc9, 0x8b, 0x20, 0xaf, 0xd7, 0x34, 0x75, 0xc4, 0x05, 0xc4, 0xc9, 0x3b, - 0xff, 0xfd, 0xcf, 0x6f, 0x3e, 0xe4, 0x25, 0x8f, 0xd9, 0xfc, 0x4a, 0x85, 0x09, 0x70, 0x9e, 0x23, - 0x67, 0x02, 0x57, 0x8e, 0x2a, 0x28, 0x24, 0x20, 0x50, 0xb7, 0xb4, 0x04, 0x77, 0xfa, 0x61, 0x3f, - 0x03, 0xc8, 0xe6, 0x2c, 0x34, 0xd7, 0x53, 0x7d, 0x1e, 0x62, 0xce, 0x99, 0xc2, 0x98, 0x17, 0x55, - 0xc6, 0xa1, 0xdf, 0x34, 0xa4, 0x5a, 0xc6, 0x98, 0x83, 0xb0, 0xf7, 0x07, 0x19, 0x64, 0x60, 0x8e, - 0x61, 0x79, 0xb2, 0xea, 0xc3, 0x66, 0x2b, 0x45, 0x2c, 0x63, 0x6e, 0xbb, 0x18, 0x7e, 0x69, 0x93, - 0xee, 0xc9, 0x5d, 0x6f, 0xd4, 0x23, 0x0f, 0x12, 0xc9, 0x62, 0x04, 0xe9, 0x39, 0x03, 0x67, 0xb4, - 0x1d, 0xd5, 0x21, 0x7d, 0x4d, 0xf6, 0x2a, 0x08, 0xb2, 0x74, 0x82, 0x30, 0x63, 0x42, 0x79, 0xed, - 0x41, 0x67, 0xd4, 0x7d, 0x3e, 0x08, 0x1a, 0xa3, 0x04, 0x27, 0xb5, 0xf1, 0x8d, 0xf1, 0x45, 0x6e, - 0x72, 0x5f, 0xa0, 0x67, 0x84, 0x6a, 0xb1, 0x86, 0xeb, 0x18, 0xdc, 0x70, 0x0d, 0xf7, 0x56, 0x34, - 0xf2, 0xa3, 0x7d, 0xdd, 0x94, 0xe8, 0x29, 0xd9, 0xbd, 0x64, 0x0a, 0x73, 0x91, 0xd5, 0xb8, 0x0d, - 0x83, 0xf3, 0xd7, 0x70, 0xef, 0x2a, 0x9b, 0x45, 0xf5, 0x2e, 0x57, 0xc3, 0x21, 0x10, 0xb7, 0xd1, - 0x3d, 0x3d, 0x20, 0x9b, 0x29, 0x13, 0xc0, 0xed, 0x46, 0xaa, 0x80, 0xbe, 0x22, 0x5b, 0x31, 0x07, - 0x2d, 0xd0, 0x6b, 0x97, 0xf2, 0x71, 0x70, 0x7d, 0xdb, 0x6f, 0xfd, 0xb8, 0xed, 0x3f, 0xcd, 0x72, - 0xbc, 0xd0, 0xd3, 0xb2, 0x60, 0x98, 0x80, 0xe2, 0xa0, 0xec, 0xe7, 0x48, 0xa5, 0xb3, 0x10, 0xaf, - 0x0a, 0xa6, 0x82, 0xb1, 0xc0, 0xc8, 0x66, 0x0f, 0x3f, 0x92, 0xfd, 0xb5, 0xf9, 0xfe, 0x73, 0xc9, - 0x6f, 0x6d, 0xd2, 0xbb, 0xb7, 0x84, 0x3f, 0xd4, 0x3b, 0x23, 0x3b, 0x08, 0x18, 0xcf, 0x27, 0xff, - 0x54, 0xb5, 0x6b, 0x18, 0x2f, 0x0d, 0x82, 0xbe, 0x27, 0xae, 0x16, 0xe5, 0xc6, 0x59, 0x5a, 0x53, - 0x3b, 0x7f, 0x45, 0xdd, 0xad, 0x31, 0x16, 0xfc, 0x8c, 0xec, 0xb1, 0x02, 0x92, 0x8b, 0x49, 0x9e, - 0x32, 0x81, 0xf9, 0x79, 0xce, 0xa4, 0xb7, 0x61, 0x86, 0x71, 0x8d, 0x3e, 0xfe, 0x2d, 0xd3, 0x47, - 0x84, 0x08, 0xcd, 0x27, 0x46, 0x56, 0xde, 0xe6, 0xc0, 0x19, 0x75, 0xa2, 0x6d, 0xa1, 0xf9, 0xa9, - 0x11, 0xe8, 0x13, 0xd2, 0x4b, 0xb4, 0x94, 0x4c, 0x60, 0x65, 0xf1, 0xb6, 0x8c, 0x63, 0xc7, 0x8a, - 0xc6, 0x75, 0x3c, 0xbe, 0x5e, 0xf8, 0xce, 0xcd, 0xc2, 0x77, 0x7e, 0x2e, 0x7c, 0xe7, 0xeb, 0xd2, - 0x6f, 0xdd, 0x2c, 0xfd, 0xd6, 0xf7, 0xa5, 0xdf, 0xfa, 0x10, 0xae, 0x0c, 0x50, 0xfe, 0x79, 0x47, - 0x82, 0xe1, 0x27, 0x90, 0x33, 0x13, 0x84, 0x9f, 0x57, 0x5f, 0xa2, 0x99, 0x66, 0xba, 0x65, 0x5e, - 0xe2, 0x8b, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x23, 0x9d, 0x32, 0xff, 0x34, 0x04, 0x00, 0x00, + // 553 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x4f, 0x6f, 0xd3, 0x30, + 0x1c, 0x6d, 0xda, 0xae, 0xd3, 0xdc, 0x75, 0x29, 0xd6, 0x24, 0xa2, 0x09, 0xd2, 0xae, 0x48, 0xa8, + 0x1c, 0x96, 0x48, 0x70, 0xe0, 0xbc, 0x4e, 0x43, 0xaa, 0x40, 0x48, 0x44, 0x03, 0x24, 0x2e, 0x51, + 0x9a, 0x78, 0x59, 0xd4, 0xd8, 0x8e, 0xfc, 0x67, 0x63, 0xe2, 0x23, 0x70, 0xe1, 0x63, 0xf0, 0x31, + 0x38, 0xee, 0xb8, 0x23, 0xe2, 0x30, 0xa1, 0xf6, 0x8b, 0xa0, 0xd8, 0x49, 0x97, 0xa5, 0xe2, 0xc2, + 0xc4, 0x29, 0xfe, 0xbd, 0x3c, 0x3f, 0xbf, 0xdf, 0xfb, 0x59, 0x06, 0xfb, 0x28, 0xbd, 0xe4, 0x6e, + 0x48, 0x31, 0x4e, 0x04, 0x46, 0x44, 0x54, 0x96, 0xdc, 0xc9, 0x18, 0x15, 0x14, 0x9a, 0x39, 0xc5, + 0xb9, 0xc5, 0xf7, 0x06, 0x31, 0xa5, 0x71, 0x8a, 0x5c, 0xf5, 0x7b, 0x26, 0x4f, 0x5d, 0x91, 0x60, + 0xc4, 0x45, 0x80, 0x33, 0xbd, 0x63, 0xcf, 0xae, 0x13, 0x22, 0xc9, 0x02, 0x91, 0x50, 0x52, 0xfc, + 0xdf, 0x8d, 0x69, 0x4c, 0xd5, 0xd2, 0xcd, 0x57, 0x05, 0xfa, 0xa8, 0x6e, 0x25, 0x0b, 0x58, 0x80, + 0x0b, 0x17, 0xa3, 0xaf, 0x4d, 0xd0, 0x3d, 0xba, 0xf5, 0x06, 0x2d, 0xb0, 0x19, 0x32, 0x14, 0x08, + 0xca, 0x2c, 0x63, 0x68, 0x8c, 0xb7, 0xbc, 0xb2, 0x84, 0xaf, 0x41, 0x5f, 0x8b, 0x08, 0x14, 0xf9, + 0x82, 0xce, 0x11, 0xe1, 0x56, 0x73, 0xd8, 0x1a, 0x77, 0x9f, 0x0f, 0x9d, 0x5a, 0x2b, 0xce, 0x51, + 0x49, 0x3c, 0x51, 0x3c, 0xcf, 0x0c, 0xef, 0x02, 0xf0, 0x2d, 0x78, 0xc0, 0xd0, 0x45, 0xc0, 0x22, + 0xee, 0x4b, 0x12, 0xa6, 0x41, 0x82, 0x51, 0x64, 0xb5, 0x94, 0xda, 0xfe, 0x9a, 0x9a, 0xa7, 0x99, + 0xef, 0x4b, 0xa2, 0xd7, 0x67, 0x35, 0x04, 0x1e, 0x83, 0x9d, 0x73, 0xc4, 0x45, 0x42, 0xe2, 0xd2, + 0x5a, 0x5b, 0x89, 0xd9, 0x6b, 0x62, 0x1f, 0x34, 0xad, 0x30, 0xd6, 0x3b, 0xaf, 0x96, 0xa3, 0x2f, + 0xa0, 0xf3, 0x86, 0x86, 0x73, 0x99, 0xc1, 0x57, 0xa0, 0x13, 0x60, 0x2a, 0x89, 0xd0, 0x31, 0x4c, + 0x9c, 0xab, 0x9b, 0x41, 0xe3, 0xd7, 0xcd, 0xe0, 0x69, 0x9c, 0x88, 0x33, 0x39, 0xcb, 0x15, 0xdd, + 0x90, 0x72, 0x4c, 0x79, 0xf1, 0x39, 0xe0, 0xd1, 0xdc, 0x15, 0x97, 0x19, 0xe2, 0xce, 0x94, 0x08, + 0xaf, 0xd8, 0x0d, 0x9f, 0x81, 0xbe, 0x24, 0x29, 0x0d, 0xe7, 0xfe, 0x6a, 0x9a, 0x56, 0x73, 0x68, + 0x8c, 0xdb, 0x9e, 0xa9, 0xf1, 0x93, 0x12, 0x1e, 0x7d, 0x37, 0x80, 0x59, 0x0b, 0x0e, 0xee, 0x82, + 0x8d, 0x08, 0x11, 0x8a, 0x8b, 0x61, 0xe8, 0xa2, 0x62, 0xae, 0x79, 0x2f, 0x73, 0x2f, 0xc1, 0x66, + 0xaa, 0xda, 0xe5, 0x45, 0xf6, 0x0f, 0xd7, 0xe2, 0xd2, 0x71, 0x4c, 0xda, 0xf9, 0x09, 0x5e, 0xc9, + 0x1e, 0x65, 0xa0, 0x5f, 0x1f, 0xca, 0xff, 0xb5, 0x3a, 0xfa, 0xd1, 0x04, 0xbd, 0x3b, 0xa3, 0xfb, + 0xcb, 0x79, 0xef, 0xc0, 0xb6, 0xa0, 0x22, 0x48, 0xfd, 0x7b, 0x9d, 0xda, 0x55, 0x1a, 0x87, 0x3a, + 0xa5, 0x8f, 0xc0, 0x94, 0x24, 0xbf, 0x27, 0x28, 0x2a, 0x55, 0x5b, 0xff, 0xa4, 0xba, 0x53, 0xca, + 0x1c, 0xae, 0xee, 0x06, 0xca, 0x68, 0x78, 0xe6, 0x27, 0x11, 0x22, 0x22, 0x39, 0x4d, 0x10, 0xb3, + 0xda, 0xaa, 0x19, 0x53, 0xe1, 0xd3, 0x15, 0x0c, 0x1f, 0x03, 0x40, 0x24, 0xf6, 0x15, 0xcc, 0xad, + 0x8d, 0xa1, 0x31, 0x6e, 0x79, 0x5b, 0x44, 0xe2, 0x63, 0x05, 0xc0, 0x27, 0xa0, 0x17, 0x4a, 0xc6, + 0x10, 0x11, 0x9a, 0x62, 0x75, 0x14, 0x63, 0xbb, 0x00, 0x15, 0x6b, 0x32, 0xbd, 0x5a, 0xd8, 0xc6, + 0xf5, 0xc2, 0x36, 0x7e, 0x2f, 0x6c, 0xe3, 0xdb, 0xd2, 0x6e, 0x5c, 0x2f, 0xed, 0xc6, 0xcf, 0xa5, + 0xdd, 0xf8, 0xe4, 0x56, 0x1a, 0xc8, 0x2f, 0xc0, 0x01, 0x41, 0xe2, 0x82, 0xb2, 0xb9, 0x2a, 0xdc, + 0xcf, 0xd5, 0xc7, 0x43, 0x75, 0x33, 0xeb, 0xa8, 0xc7, 0xe3, 0xc5, 0x9f, 0x00, 0x00, 0x00, 0xff, + 0xff, 0x8c, 0xb2, 0xc6, 0x11, 0xe7, 0x04, 0x00, 0x00, } func (m *Commitments) Marshal() (dAtA []byte, err error) { @@ -332,10 +391,10 @@ func (m *Commitments) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x22 } } - if len(m.UncommittedTokens) > 0 { - for iNdEx := len(m.UncommittedTokens) - 1; iNdEx >= 0; iNdEx-- { + if len(m.RewardsUnclaimed) > 0 { + for iNdEx := len(m.RewardsUnclaimed) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.UncommittedTokens[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.RewardsUnclaimed[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -370,6 +429,44 @@ func (m *Commitments) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *Lockup) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Lockup) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Lockup) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.UnlockTimestamp != 0 { + i = encodeVarintCommitments(dAtA, i, uint64(m.UnlockTimestamp)) + i-- + dAtA[i] = 0x10 + } + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintCommitments(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func (m *CommittedTokens) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -390,6 +487,20 @@ func (m *CommittedTokens) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Lockups) > 0 { + for iNdEx := len(m.Lockups) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Lockups[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCommitments(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } { size := m.Amount.Size() i -= size @@ -410,7 +521,7 @@ func (m *CommittedTokens) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *UncommittedTokens) Marshal() (dAtA []byte, err error) { +func (m *RewardsUnclaimed) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -420,12 +531,12 @@ func (m *UncommittedTokens) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *UncommittedTokens) MarshalTo(dAtA []byte) (int, error) { +func (m *RewardsUnclaimed) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *UncommittedTokens) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *RewardsUnclaimed) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -544,8 +655,8 @@ func (m *Commitments) Size() (n int) { n += 1 + l + sovCommitments(uint64(l)) } } - if len(m.UncommittedTokens) > 0 { - for _, e := range m.UncommittedTokens { + if len(m.RewardsUnclaimed) > 0 { + for _, e := range m.RewardsUnclaimed { l = e.Size() n += 1 + l + sovCommitments(uint64(l)) } @@ -559,6 +670,20 @@ func (m *Commitments) Size() (n int) { return n } +func (m *Lockup) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Amount.Size() + n += 1 + l + sovCommitments(uint64(l)) + if m.UnlockTimestamp != 0 { + n += 1 + sovCommitments(uint64(m.UnlockTimestamp)) + } + return n +} + func (m *CommittedTokens) Size() (n int) { if m == nil { return 0 @@ -571,10 +696,16 @@ func (m *CommittedTokens) Size() (n int) { } l = m.Amount.Size() n += 1 + l + sovCommitments(uint64(l)) + if len(m.Lockups) > 0 { + for _, e := range m.Lockups { + l = e.Size() + n += 1 + l + sovCommitments(uint64(l)) + } + } return n } -func (m *UncommittedTokens) Size() (n int) { +func (m *RewardsUnclaimed) Size() (n int) { if m == nil { return 0 } @@ -719,7 +850,7 @@ func (m *Commitments) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field UncommittedTokens", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field RewardsUnclaimed", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -746,8 +877,8 @@ func (m *Commitments) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.UncommittedTokens = append(m.UncommittedTokens, &UncommittedTokens{}) - if err := m.UncommittedTokens[len(m.UncommittedTokens)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.RewardsUnclaimed = append(m.RewardsUnclaimed, &RewardsUnclaimed{}) + if err := m.RewardsUnclaimed[len(m.RewardsUnclaimed)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -806,6 +937,109 @@ func (m *Commitments) Unmarshal(dAtA []byte) error { } return nil } +func (m *Lockup) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCommitments + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Lockup: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Lockup: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCommitments + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCommitments + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCommitments + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UnlockTimestamp", wireType) + } + m.UnlockTimestamp = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCommitments + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.UnlockTimestamp |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipCommitments(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCommitments + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *CommittedTokens) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -901,6 +1135,40 @@ func (m *CommittedTokens) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Lockups", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCommitments + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCommitments + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCommitments + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Lockups = append(m.Lockups, Lockup{}) + if err := m.Lockups[len(m.Lockups)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipCommitments(dAtA[iNdEx:]) @@ -922,7 +1190,7 @@ func (m *CommittedTokens) Unmarshal(dAtA []byte) error { } return nil } -func (m *UncommittedTokens) Unmarshal(dAtA []byte) error { +func (m *RewardsUnclaimed) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -945,10 +1213,10 @@ func (m *UncommittedTokens) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: UncommittedTokens: wiretype end group for non-group") + return fmt.Errorf("proto: RewardsUnclaimed: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: UncommittedTokens: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: RewardsUnclaimed: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: diff --git a/x/commitment/types/commitments_test.go b/x/commitment/types/commitments_test.go new file mode 100644 index 000000000..930a0567c --- /dev/null +++ b/x/commitment/types/commitments_test.go @@ -0,0 +1,51 @@ +package types_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/elys-network/elys/x/commitment/types" + "github.com/stretchr/testify/require" +) + +func TestCommitments_AddCommitedTokens(t *testing.T) { + commitments := types.Commitments{ + Creator: "", + CommittedTokens: []*types.CommittedTokens{}, + RewardsUnclaimed: []*types.RewardsUnclaimed{}, + VestingTokens: []*types.VestingTokens{}, + } + + commitments.AddCommitedTokens("lp/1", sdk.NewInt(100), 100) + commitments.AddCommitedTokens("lp/1", sdk.NewInt(100), 150) + commitments.AddCommitedTokens("lp/1", sdk.NewInt(100), 200) + commitments.AddCommitedTokens("lp/2", sdk.NewInt(100), 100) + + require.Len(t, commitments.CommittedTokens, 2) + require.Len(t, commitments.CommittedTokens[0].Lockups, 3) + require.Equal(t, commitments.CommittedTokens[0].Lockups[0].Amount.String(), "100") + require.Equal(t, commitments.CommittedTokens[0].Lockups[0].UnlockTimestamp, uint64(100)) + require.Len(t, commitments.CommittedTokens[1].Lockups, 1) +} +func TestCommitments_WithdrawCommitedTokens(t *testing.T) { + commitments := types.Commitments{ + Creator: "", + CommittedTokens: []*types.CommittedTokens{}, + RewardsUnclaimed: []*types.RewardsUnclaimed{}, + VestingTokens: []*types.VestingTokens{}, + } + + commitments.AddCommitedTokens("lp/1", sdk.NewInt(100), 100) + commitments.AddCommitedTokens("lp/1", sdk.NewInt(100), 150) + commitments.AddCommitedTokens("lp/1", sdk.NewInt(100), 200) + commitments.AddCommitedTokens("lp/2", sdk.NewInt(100), 100) + + err := commitments.DeductFromCommitted("lp/1", sdk.NewInt(100), 100) + require.NoError(t, err) + + err = commitments.DeductFromCommitted("lp/1", sdk.NewInt(100), 100) + require.Error(t, err) + + err = commitments.DeductFromCommitted("lp/2", sdk.NewInt(200), 100) + require.Error(t, err) +} diff --git a/x/commitment/types/errors.go b/x/commitment/types/errors.go index 61d023db1..9e3c680e9 100644 --- a/x/commitment/types/errors.go +++ b/x/commitment/types/errors.go @@ -8,13 +8,15 @@ import ( // x/commitment module sentinel errors var ( - ErrCommitmentsNotFound = sdkerrors.Register(ModuleName, 1001, "commitments not found for creator") - ErrInsufficientUncommittedTokens = sdkerrors.Register(ModuleName, 1002, "insufficient uncommitted tokens for creator and denom") - ErrInsufficientCommittedTokens = sdkerrors.Register(ModuleName, 1003, "insufficient committed tokens for creator and denom") - ErrInvalidAmount = sdkerrors.Register(ModuleName, 1004, "invalid amount") - ErrInvalidDenom = sdkerrors.Register(ModuleName, 1005, "invalid denom") - ErrInsufficientVestingTokens = sdkerrors.Register(ModuleName, 1006, "insufficient vesting tokens for creator and denom") - ErrCommitDisabled = sdkerrors.Register(ModuleName, 1007, "commitment disabled for denom") - ErrWithdrawDisabled = sdkerrors.Register(ModuleName, 1008, "withdraw disabled for denom") - ErrExceedMaxVestings = sdkerrors.Register(ModuleName, 1009, "exceed maximum allowed vestings") + ErrCommitmentsNotFound = sdkerrors.Register(ModuleName, 1001, "commitments not found for creator") + ErrInsufficientRewardsUnclaimed = sdkerrors.Register(ModuleName, 1002, "insufficient unclaimed tokens for creator and denom") + ErrInsufficientCommittedTokens = sdkerrors.Register(ModuleName, 1003, "insufficient committed tokens for creator and denom") + ErrInvalidAmount = sdkerrors.Register(ModuleName, 1004, "invalid amount") + ErrInvalidDenom = sdkerrors.Register(ModuleName, 1005, "invalid denom") + ErrInsufficientVestingTokens = sdkerrors.Register(ModuleName, 1006, "insufficient vesting tokens for creator and denom") + ErrCommitDisabled = sdkerrors.Register(ModuleName, 1007, "commitment disabled for denom") + ErrWithdrawDisabled = sdkerrors.Register(ModuleName, 1008, "withdraw disabled for denom") + ErrExceedMaxVestings = sdkerrors.Register(ModuleName, 1009, "exceed maximum allowed vestings") + ErrInsufficientWithdrawableTokens = sdkerrors.Register(ModuleName, 1010, "insufficient withdrawable tokens") + ErrVestNowIsNotEnabled = sdkerrors.Register(ModuleName, 1011, "instant vesting is not enabled at this stage") ) diff --git a/x/commitment/types/message_commit_tokens.go b/x/commitment/types/message_commit_tokens.go index d8b133a37..7466b5946 100644 --- a/x/commitment/types/message_commit_tokens.go +++ b/x/commitment/types/message_commit_tokens.go @@ -5,27 +5,27 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -const TypeMsgCommitTokens = "commit_tokens" +const TypeMsgCommitUnclaimedRewards = "commit_tokens" -var _ sdk.Msg = &MsgCommitTokens{} +var _ sdk.Msg = &MsgCommitUnclaimedRewards{} -func NewMsgCommitTokens(creator string, amount sdk.Int, denom string) *MsgCommitTokens { - return &MsgCommitTokens{ +func NewMsgCommitUnclaimedRewards(creator string, amount sdk.Int, denom string) *MsgCommitUnclaimedRewards { + return &MsgCommitUnclaimedRewards{ Creator: creator, Amount: amount, Denom: denom, } } -func (msg *MsgCommitTokens) Route() string { +func (msg *MsgCommitUnclaimedRewards) Route() string { return RouterKey } -func (msg *MsgCommitTokens) Type() string { - return TypeMsgCommitTokens +func (msg *MsgCommitUnclaimedRewards) Type() string { + return TypeMsgCommitUnclaimedRewards } -func (msg *MsgCommitTokens) GetSigners() []sdk.AccAddress { +func (msg *MsgCommitUnclaimedRewards) GetSigners() []sdk.AccAddress { creator, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { panic(err) @@ -33,12 +33,12 @@ func (msg *MsgCommitTokens) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{creator} } -func (msg *MsgCommitTokens) GetSignBytes() []byte { +func (msg *MsgCommitUnclaimedRewards) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(msg) return sdk.MustSortJSON(bz) } -func (msg *MsgCommitTokens) ValidateBasic() error { +func (msg *MsgCommitUnclaimedRewards) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid creator address: %v", err) diff --git a/x/commitment/types/message_commit_tokens_test.go b/x/commitment/types/message_commit_tokens_test.go index 6abdf1f0b..5c4da29e1 100644 --- a/x/commitment/types/message_commit_tokens_test.go +++ b/x/commitment/types/message_commit_tokens_test.go @@ -9,22 +9,22 @@ import ( "github.com/stretchr/testify/require" ) -func TestMsgCommitTokens_ValidateBasic(t *testing.T) { +func TestMsgCommitUnclaimedRewards_ValidateBasic(t *testing.T) { tests := []struct { name string - msg MsgCommitTokens + msg MsgCommitUnclaimedRewards err error }{ { name: "invalid address", - msg: MsgCommitTokens{ + msg: MsgCommitUnclaimedRewards{ Creator: "invalid_address", Amount: sdk.ZeroInt(), }, err: sdkerrors.ErrInvalidAddress, }, { name: "valid address", - msg: MsgCommitTokens{ + msg: MsgCommitUnclaimedRewards{ Creator: sample.AccAddress(), Amount: sdk.ZeroInt(), }, diff --git a/x/commitment/types/query.pb.gw.go b/x/commitment/types/query.pb.gw.go index de5026737..228e19d02 100644 --- a/x/commitment/types/query.pb.gw.go +++ b/x/commitment/types/query.pb.gw.go @@ -20,7 +20,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -31,7 +30,6 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage -var _ = metadata.Join func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryParamsRequest @@ -108,14 +106,12 @@ func local_request_Query_ShowCommitments_0(ctx context.Context, marshaler runtim // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -123,7 +119,6 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -137,8 +132,6 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_ShowCommitments_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -146,7 +139,6 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_ShowCommitments_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) diff --git a/x/commitment/types/tx.pb.go b/x/commitment/types/tx.pb.go index 116453226..317502770 100644 --- a/x/commitment/types/tx.pb.go +++ b/x/commitment/types/tx.pb.go @@ -29,24 +29,24 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -type MsgCommitTokens struct { +type MsgCommitUnclaimedRewards struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` Denom string `protobuf:"bytes,3,opt,name=denom,proto3" json:"denom,omitempty"` } -func (m *MsgCommitTokens) Reset() { *m = MsgCommitTokens{} } -func (m *MsgCommitTokens) String() string { return proto.CompactTextString(m) } -func (*MsgCommitTokens) ProtoMessage() {} -func (*MsgCommitTokens) Descriptor() ([]byte, []int) { +func (m *MsgCommitUnclaimedRewards) Reset() { *m = MsgCommitUnclaimedRewards{} } +func (m *MsgCommitUnclaimedRewards) String() string { return proto.CompactTextString(m) } +func (*MsgCommitUnclaimedRewards) ProtoMessage() {} +func (*MsgCommitUnclaimedRewards) Descriptor() ([]byte, []int) { return fileDescriptor_eda78aafe7eb119c, []int{0} } -func (m *MsgCommitTokens) XXX_Unmarshal(b []byte) error { +func (m *MsgCommitUnclaimedRewards) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgCommitTokens) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgCommitUnclaimedRewards) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgCommitTokens.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgCommitUnclaimedRewards.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -56,47 +56,47 @@ func (m *MsgCommitTokens) XXX_Marshal(b []byte, deterministic bool) ([]byte, err return b[:n], nil } } -func (m *MsgCommitTokens) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgCommitTokens.Merge(m, src) +func (m *MsgCommitUnclaimedRewards) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCommitUnclaimedRewards.Merge(m, src) } -func (m *MsgCommitTokens) XXX_Size() int { +func (m *MsgCommitUnclaimedRewards) XXX_Size() int { return m.Size() } -func (m *MsgCommitTokens) XXX_DiscardUnknown() { - xxx_messageInfo_MsgCommitTokens.DiscardUnknown(m) +func (m *MsgCommitUnclaimedRewards) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCommitUnclaimedRewards.DiscardUnknown(m) } -var xxx_messageInfo_MsgCommitTokens proto.InternalMessageInfo +var xxx_messageInfo_MsgCommitUnclaimedRewards proto.InternalMessageInfo -func (m *MsgCommitTokens) GetCreator() string { +func (m *MsgCommitUnclaimedRewards) GetCreator() string { if m != nil { return m.Creator } return "" } -func (m *MsgCommitTokens) GetDenom() string { +func (m *MsgCommitUnclaimedRewards) GetDenom() string { if m != nil { return m.Denom } return "" } -type MsgCommitTokensResponse struct { +type MsgCommitUnclaimedRewardsResponse struct { } -func (m *MsgCommitTokensResponse) Reset() { *m = MsgCommitTokensResponse{} } -func (m *MsgCommitTokensResponse) String() string { return proto.CompactTextString(m) } -func (*MsgCommitTokensResponse) ProtoMessage() {} -func (*MsgCommitTokensResponse) Descriptor() ([]byte, []int) { +func (m *MsgCommitUnclaimedRewardsResponse) Reset() { *m = MsgCommitUnclaimedRewardsResponse{} } +func (m *MsgCommitUnclaimedRewardsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCommitUnclaimedRewardsResponse) ProtoMessage() {} +func (*MsgCommitUnclaimedRewardsResponse) Descriptor() ([]byte, []int) { return fileDescriptor_eda78aafe7eb119c, []int{1} } -func (m *MsgCommitTokensResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgCommitUnclaimedRewardsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgCommitTokensResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgCommitUnclaimedRewardsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgCommitTokensResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgCommitUnclaimedRewardsResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -106,17 +106,17 @@ func (m *MsgCommitTokensResponse) XXX_Marshal(b []byte, deterministic bool) ([]b return b[:n], nil } } -func (m *MsgCommitTokensResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgCommitTokensResponse.Merge(m, src) +func (m *MsgCommitUnclaimedRewardsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCommitUnclaimedRewardsResponse.Merge(m, src) } -func (m *MsgCommitTokensResponse) XXX_Size() int { +func (m *MsgCommitUnclaimedRewardsResponse) XXX_Size() int { return m.Size() } -func (m *MsgCommitTokensResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgCommitTokensResponse.DiscardUnknown(m) +func (m *MsgCommitUnclaimedRewardsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCommitUnclaimedRewardsResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgCommitTokensResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgCommitUnclaimedRewardsResponse proto.InternalMessageInfo type MsgUncommitTokens struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` @@ -300,6 +300,7 @@ type MsgCommitLiquidTokens struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` Denom string `protobuf:"bytes,3,opt,name=denom,proto3" json:"denom,omitempty"` + MinLock uint64 `protobuf:"varint,4,opt,name=minLock,proto3" json:"minLock,omitempty"` } func (m *MsgCommitLiquidTokens) Reset() { *m = MsgCommitLiquidTokens{} } @@ -349,6 +350,13 @@ func (m *MsgCommitLiquidTokens) GetDenom() string { return "" } +func (m *MsgCommitLiquidTokens) GetMinLock() uint64 { + if m != nil { + return m.MinLock + } + return 0 +} + type MsgCommitLiquidTokensResponse struct { } @@ -870,8 +878,8 @@ func (m *MsgVestLiquidResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgVestLiquidResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*MsgCommitTokens)(nil), "elys.commitment.MsgCommitTokens") - proto.RegisterType((*MsgCommitTokensResponse)(nil), "elys.commitment.MsgCommitTokensResponse") + proto.RegisterType((*MsgCommitUnclaimedRewards)(nil), "elys.commitment.MsgCommitUnclaimedRewards") + proto.RegisterType((*MsgCommitUnclaimedRewardsResponse)(nil), "elys.commitment.MsgCommitUnclaimedRewardsResponse") proto.RegisterType((*MsgUncommitTokens)(nil), "elys.commitment.MsgUncommitTokens") proto.RegisterType((*MsgUncommitTokensResponse)(nil), "elys.commitment.MsgUncommitTokensResponse") proto.RegisterType((*MsgWithdrawTokens)(nil), "elys.commitment.MsgWithdrawTokens") @@ -893,49 +901,51 @@ func init() { func init() { proto.RegisterFile("elys/commitment/tx.proto", fileDescriptor_eda78aafe7eb119c) } var fileDescriptor_eda78aafe7eb119c = []byte{ - // 665 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x96, 0xcd, 0x4e, 0xdb, 0x40, - 0x10, 0xc7, 0xb3, 0x7c, 0x24, 0x62, 0xc4, 0x87, 0x58, 0xa5, 0xc2, 0x18, 0x6a, 0xa2, 0xb4, 0x8d, - 0xa2, 0x4a, 0xd8, 0x52, 0xfb, 0x06, 0x94, 0x22, 0x45, 0x6d, 0x38, 0x44, 0xb4, 0x95, 0x38, 0xd5, - 0xd8, 0x8b, 0x63, 0x81, 0x77, 0x53, 0xef, 0x9a, 0xc0, 0xb1, 0x52, 0xa5, 0xaa, 0x6a, 0xa5, 0xf6, - 0x7d, 0xfa, 0x02, 0x1c, 0x39, 0x56, 0x3d, 0xa0, 0x0a, 0x5e, 0xa4, 0x5a, 0x3b, 0xd9, 0xd8, 0xc6, - 0x01, 0x6e, 0xe1, 0x94, 0x78, 0xfe, 0x7f, 0xcf, 0xfc, 0x3c, 0xf6, 0x8c, 0x0d, 0x1a, 0x39, 0x3e, - 0xe3, 0x96, 0xc3, 0x82, 0xc0, 0x17, 0x01, 0xa1, 0xc2, 0x12, 0xa7, 0x66, 0x2f, 0x64, 0x82, 0xe1, - 0x25, 0xa9, 0x98, 0x23, 0x45, 0xaf, 0x7a, 0xcc, 0x63, 0xb1, 0x66, 0xc9, 0x7f, 0x89, 0xad, 0xfe, - 0x0d, 0xc1, 0x52, 0x9b, 0x7b, 0xaf, 0x62, 0xdf, 0x1e, 0x3b, 0x22, 0x94, 0x63, 0x0d, 0x2a, 0x4e, - 0x48, 0x6c, 0xc1, 0x42, 0x0d, 0xd5, 0x50, 0x73, 0xae, 0x33, 0x3c, 0xc4, 0x3b, 0x50, 0xb6, 0x03, - 0x16, 0x51, 0xa1, 0x4d, 0x49, 0x61, 0xcb, 0x3c, 0xbf, 0xdc, 0x28, 0xfd, 0xbd, 0xdc, 0x68, 0x78, - 0xbe, 0xe8, 0x46, 0x07, 0xb2, 0x9c, 0xe5, 0x30, 0x1e, 0x30, 0x3e, 0xf8, 0xd9, 0xe4, 0xee, 0x91, - 0x25, 0xce, 0x7a, 0x84, 0x9b, 0x2d, 0x2a, 0x3a, 0x83, 0xb3, 0x71, 0x15, 0x66, 0x5d, 0x42, 0x59, - 0xa0, 0x4d, 0xc7, 0xf9, 0x93, 0x83, 0xfa, 0x2a, 0xac, 0xe4, 0x50, 0x3a, 0x84, 0xf7, 0x18, 0xe5, - 0xa4, 0xfe, 0x1d, 0xc1, 0x72, 0x9b, 0x7b, 0xef, 0xa8, 0xf3, 0x10, 0x40, 0xd7, 0x60, 0xf5, 0x06, - 0x4c, 0x1e, 0xf5, 0x83, 0x2f, 0xba, 0x6e, 0x68, 0xf7, 0x1f, 0x04, 0x6a, 0x16, 0x46, 0xa1, 0xfe, - 0x44, 0xf0, 0x48, 0x75, 0xfc, 0xad, 0xff, 0x29, 0xf2, 0xdd, 0x09, 0xe3, 0x6e, 0xc0, 0xe3, 0x42, - 0x20, 0x85, 0xfc, 0x19, 0x41, 0xa5, 0xcd, 0xbd, 0xf7, 0x84, 0x8b, 0x89, 0x41, 0x2e, 0xc7, 0x23, - 0x23, 0x11, 0x14, 0xd6, 0x57, 0x04, 0x0b, 0x12, 0xdc, 0xa6, 0x0e, 0x39, 0x9e, 0x28, 0xdc, 0x4a, - 0x72, 0x4b, 0x15, 0x88, 0x42, 0xfc, 0x82, 0x00, 0x06, 0xd8, 0xbb, 0xac, 0x3f, 0x31, 0xbe, 0x2a, - 0xe0, 0x11, 0x85, 0x82, 0xfb, 0x31, 0x05, 0x55, 0x39, 0x52, 0x3d, 0xd7, 0x16, 0x44, 0x8a, 0x3e, - 0xf5, 0x5a, 0xf4, 0x90, 0xe1, 0x75, 0x98, 0xb3, 0x23, 0xd1, 0x65, 0xa1, 0x2f, 0xce, 0x06, 0xa0, - 0xa3, 0x80, 0x54, 0x0f, 0x6c, 0x4e, 0xb6, 0xe3, 0x32, 0x53, 0x89, 0xaa, 0x02, 0xb8, 0x0e, 0xf3, - 0x27, 0x49, 0xaa, 0xed, 0x14, 0x47, 0x26, 0x86, 0x9b, 0xb0, 0x44, 0x7a, 0xcc, 0xe9, 0xb6, 0x5c, - 0x42, 0x85, 0x7f, 0xe8, 0x93, 0x50, 0x9b, 0x89, 0x6d, 0xf9, 0xb0, 0xac, 0x45, 0xa3, 0xe0, 0xb5, - 0x8c, 0x72, 0x6d, 0xb6, 0x86, 0x9a, 0xd3, 0x9d, 0x51, 0x00, 0x3f, 0x85, 0x85, 0x93, 0xe4, 0x9a, - 0x76, 0x6c, 0x47, 0x36, 0xb5, 0x1c, 0x3b, 0xb2, 0x41, 0xdc, 0x80, 0x45, 0x1a, 0x05, 0x6d, 0xfb, - 0x74, 0x70, 0x89, 0x5c, 0xab, 0xc4, 0xb6, 0x5c, 0xb4, 0x6e, 0xc0, 0x7a, 0x51, 0x37, 0xf2, 0x8f, - 0x9b, 0x94, 0x92, 0x29, 0x99, 0xf0, 0xe3, 0x36, 0x02, 0x19, 0x22, 0xbe, 0xf8, 0x5d, 0x86, 0xe9, - 0x36, 0xf7, 0xf0, 0x3e, 0xcc, 0x67, 0x5e, 0x2e, 0x35, 0x33, 0xf7, 0x62, 0x32, 0x73, 0x3b, 0x5f, - 0x6f, 0xde, 0xe5, 0x18, 0xd6, 0xc0, 0x1f, 0x61, 0x31, 0xf7, 0x46, 0xa8, 0x17, 0x9d, 0x9b, 0xf5, - 0xe8, 0xcf, 0xef, 0xf6, 0xa4, 0x2b, 0xe4, 0x16, 0x79, 0x61, 0x85, 0xac, 0xa7, 0xb8, 0x42, 0xf1, - 0x0e, 0xc6, 0xc7, 0x80, 0x0b, 0xf6, 0x6f, 0x63, 0x7c, 0x0f, 0xd2, 0x3e, 0xdd, 0xbc, 0x9f, 0x4f, - 0x55, 0xdb, 0x82, 0x99, 0x64, 0x3b, 0x15, 0x9d, 0x27, 0x15, 0xbd, 0x36, 0x4e, 0x51, 0x39, 0xf6, - 0x00, 0x52, 0x7b, 0xce, 0x28, 0x24, 0x50, 0xba, 0xde, 0xb8, 0x5d, 0x57, 0x59, 0xdf, 0x40, 0x65, - 0xb8, 0x9a, 0xd6, 0xc6, 0x21, 0xec, 0xb2, 0xbe, 0xfe, 0xe4, 0x16, 0x51, 0x25, 0xf3, 0x61, 0xf9, - 0xe6, 0x2a, 0x79, 0x56, 0x78, 0xdf, 0xf3, 0x36, 0x7d, 0xf3, 0x5e, 0xb6, 0x74, 0x37, 0x52, 0x63, - 0x68, 0x8c, 0xa3, 0x4b, 0xf4, 0xe2, 0x6e, 0xdc, 0x9c, 0x9e, 0xad, 0xd6, 0xf9, 0x95, 0x81, 0x2e, - 0xae, 0x0c, 0xf4, 0xef, 0xca, 0x40, 0xbf, 0xae, 0x8d, 0xd2, 0xc5, 0xb5, 0x51, 0xfa, 0x73, 0x6d, - 0x94, 0xf6, 0xad, 0xd4, 0xd8, 0xca, 0x5c, 0x9b, 0x94, 0x88, 0x3e, 0x0b, 0x8f, 0xe2, 0x03, 0xeb, - 0x34, 0xf3, 0x2d, 0x28, 0x67, 0xf8, 0xa0, 0x1c, 0x7f, 0xe8, 0xbd, 0xfc, 0x1f, 0x00, 0x00, 0xff, - 0xff, 0x1a, 0xe4, 0xe1, 0x03, 0x2b, 0x0a, 0x00, 0x00, + // 699 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x96, 0xcf, 0x6e, 0xd3, 0x4a, + 0x14, 0xc6, 0x33, 0xfd, 0x93, 0xa8, 0x47, 0xb7, 0xad, 0x3a, 0xca, 0x05, 0xe3, 0x16, 0x37, 0xb8, + 0x10, 0x45, 0x95, 0x6a, 0x4b, 0xe5, 0x0d, 0x4a, 0xa9, 0x14, 0xd1, 0x74, 0x61, 0xb5, 0x20, 0xb1, + 0xc2, 0xb5, 0xa7, 0x8e, 0x95, 0x78, 0x26, 0x78, 0x26, 0x4d, 0xba, 0x44, 0x42, 0x62, 0x01, 0x0b, + 0x24, 0x9e, 0x82, 0x37, 0xe9, 0xb2, 0x4b, 0x60, 0x51, 0xa1, 0xf6, 0x45, 0xd0, 0xd8, 0x89, 0x13, + 0xbb, 0x4e, 0xc9, 0x2e, 0xac, 0x92, 0x39, 0xdf, 0xe7, 0x73, 0x7e, 0x33, 0x9e, 0x39, 0x63, 0x50, + 0x48, 0xfb, 0x82, 0x9b, 0x0e, 0x0b, 0x02, 0x5f, 0x04, 0x84, 0x0a, 0x53, 0xf4, 0x8d, 0x4e, 0xc8, + 0x04, 0xc3, 0xab, 0x52, 0x31, 0x46, 0x8a, 0x5a, 0xf6, 0x98, 0xc7, 0x22, 0xcd, 0x94, 0xff, 0x62, + 0x9b, 0xfe, 0x0d, 0xc1, 0xa3, 0x06, 0xf7, 0x5e, 0x44, 0xbe, 0x13, 0xea, 0xb4, 0x6d, 0x3f, 0x20, + 0xae, 0x45, 0x7a, 0x76, 0xe8, 0x72, 0xac, 0x40, 0xc9, 0x09, 0x89, 0x2d, 0x58, 0xa8, 0xa0, 0x0a, + 0xaa, 0x2d, 0x59, 0xc3, 0x21, 0x3e, 0x80, 0xa2, 0x1d, 0xb0, 0x2e, 0x15, 0xca, 0x9c, 0x14, 0xf6, + 0x8c, 0xcb, 0xeb, 0xcd, 0xc2, 0xaf, 0xeb, 0xcd, 0xaa, 0xe7, 0x8b, 0x66, 0xf7, 0x54, 0x16, 0x36, + 0x1d, 0xc6, 0x03, 0xc6, 0x07, 0x3f, 0x3b, 0xdc, 0x6d, 0x99, 0xe2, 0xa2, 0x43, 0xb8, 0x51, 0xa7, + 0xc2, 0x1a, 0x3c, 0x8d, 0xcb, 0xb0, 0xe8, 0x12, 0xca, 0x02, 0x65, 0x3e, 0xca, 0x1f, 0x0f, 0xf4, + 0x2d, 0x78, 0x32, 0x11, 0xca, 0x22, 0xbc, 0xc3, 0x28, 0x27, 0xfa, 0x67, 0x04, 0x6b, 0x0d, 0xee, + 0x9d, 0xd0, 0x78, 0x92, 0xc7, 0xac, 0x45, 0xe8, 0xec, 0x90, 0xd7, 0xa3, 0x75, 0x4c, 0xc3, 0x64, + 0x51, 0xdf, 0xf8, 0xa2, 0xe9, 0x86, 0x76, 0xef, 0x9f, 0x40, 0x4d, 0xc3, 0x24, 0xa8, 0xdf, 0x11, + 0xfc, 0x9f, 0xac, 0xfd, 0xa1, 0xff, 0xbe, 0xeb, 0xbb, 0xb3, 0xc5, 0x95, 0x75, 0x03, 0x9f, 0x1e, + 0x32, 0xa7, 0xa5, 0x2c, 0x54, 0x50, 0x6d, 0xc1, 0x1a, 0x0e, 0xf5, 0x4d, 0x78, 0x9c, 0x8b, 0x9a, + 0x4c, 0xe6, 0x03, 0x82, 0x52, 0x83, 0x7b, 0xaf, 0x09, 0x17, 0x33, 0x5b, 0xed, 0x35, 0x58, 0x1d, + 0x20, 0x24, 0x58, 0x9f, 0x10, 0x2c, 0x4b, 0x70, 0x9b, 0x3a, 0xa4, 0x3d, 0x53, 0xb8, 0x87, 0xf1, + 0xcb, 0x4e, 0x40, 0x12, 0xc4, 0x8f, 0x08, 0x60, 0x80, 0x7d, 0xc4, 0x7a, 0x33, 0xe3, 0x2b, 0x03, + 0x1e, 0x51, 0x24, 0x70, 0x5f, 0xe6, 0xa0, 0x2c, 0x0f, 0x5b, 0xc7, 0xb5, 0x05, 0x91, 0xa2, 0x4f, + 0xbd, 0x3a, 0x3d, 0x63, 0x78, 0x03, 0x96, 0xec, 0xae, 0x68, 0xb2, 0xd0, 0x17, 0x17, 0x03, 0xd0, + 0x51, 0x40, 0xaa, 0xa7, 0x36, 0x27, 0xfb, 0x51, 0x99, 0xb9, 0x58, 0x4d, 0x02, 0x58, 0x87, 0xff, + 0xce, 0xe3, 0x54, 0xfb, 0x63, 0x1c, 0xa9, 0x18, 0xae, 0xc1, 0x2a, 0xe9, 0x30, 0xa7, 0x59, 0x77, + 0x09, 0x15, 0xfe, 0x99, 0x4f, 0xc2, 0x68, 0x4b, 0x2e, 0x59, 0xd9, 0xb0, 0xac, 0x45, 0xbb, 0xc1, + 0x4b, 0x19, 0xe5, 0xca, 0x62, 0x05, 0xd5, 0xe6, 0xad, 0x51, 0x00, 0x3f, 0x85, 0xe5, 0xf3, 0x78, + 0x4e, 0x07, 0xb6, 0x23, 0x17, 0xb5, 0x18, 0x39, 0xd2, 0x41, 0x5c, 0x85, 0x15, 0xda, 0x0d, 0x1a, + 0x76, 0x7f, 0x30, 0x45, 0xae, 0x94, 0x22, 0x5b, 0x26, 0xaa, 0x6b, 0xb0, 0x91, 0xb7, 0x1a, 0xd9, + 0xed, 0x26, 0xa5, 0xf8, 0x94, 0xcc, 0x78, 0xbb, 0x8d, 0x40, 0x86, 0x88, 0xbb, 0x3f, 0x8b, 0x30, + 0xdf, 0xe0, 0x1e, 0x6e, 0x03, 0xce, 0xe9, 0x3c, 0x55, 0x23, 0x73, 0x99, 0x19, 0xb9, 0xc7, 0x5e, + 0x35, 0xa6, 0xf3, 0x0d, 0xab, 0xe2, 0x3e, 0x3c, 0x98, 0x70, 0xf1, 0x6d, 0x4f, 0xce, 0x94, 0xf5, + 0xaa, 0xbb, 0xd3, 0x7b, 0x93, 0xca, 0xef, 0x60, 0x25, 0x73, 0x6f, 0xe9, 0x79, 0x59, 0xd2, 0x1e, + 0x75, 0xfb, 0xef, 0x9e, 0xf1, 0x0a, 0x99, 0xeb, 0x26, 0xb7, 0x42, 0xda, 0x93, 0x5f, 0x21, 0xff, + 0xa6, 0xc0, 0x7b, 0xb0, 0x10, 0xf7, 0xae, 0xbc, 0x67, 0xa4, 0xa2, 0x56, 0x26, 0x29, 0x49, 0x8e, + 0x57, 0x50, 0x1a, 0xb6, 0x98, 0xf5, 0x49, 0xe6, 0x23, 0xd6, 0x53, 0xb7, 0xee, 0x11, 0x93, 0x64, + 0xc7, 0x00, 0x63, 0x7b, 0x5c, 0x9b, 0xf4, 0x48, 0xac, 0xab, 0xd5, 0xfb, 0xf5, 0xf1, 0xac, 0x63, + 0x8d, 0x3a, 0x37, 0xeb, 0x48, 0xcf, 0xcf, 0x7a, 0xb7, 0xbf, 0x62, 0x1f, 0xd6, 0xee, 0xb6, 0xaf, + 0x67, 0xb9, 0xef, 0x37, 0x6b, 0x53, 0x77, 0xa6, 0xb2, 0x0d, 0x4b, 0xed, 0xd5, 0x2f, 0x6f, 0x34, + 0x74, 0x75, 0xa3, 0xa1, 0xdf, 0x37, 0x1a, 0xfa, 0x7a, 0xab, 0x15, 0xae, 0x6e, 0xb5, 0xc2, 0x8f, + 0x5b, 0xad, 0xf0, 0xd6, 0x1c, 0x3b, 0xd4, 0x32, 0xe5, 0x0e, 0x25, 0xa2, 0xc7, 0xc2, 0x56, 0x34, + 0x30, 0xfb, 0xa9, 0xef, 0x4a, 0x79, 0xc2, 0x4f, 0x8b, 0xd1, 0x47, 0xe3, 0xf3, 0x3f, 0x01, 0x00, + 0x00, 0xff, 0xff, 0x7d, 0x0e, 0xde, 0x91, 0x77, 0x0a, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -950,15 +960,26 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { - CommitTokens(ctx context.Context, in *MsgCommitTokens, opts ...grpc.CallOption) (*MsgCommitTokensResponse, error) + // CommitLiquidTokens commit the tokens from user's balance + CommitLiquidTokens(ctx context.Context, in *MsgCommitLiquidTokens, opts ...grpc.CallOption) (*MsgCommitLiquidTokensResponse, error) + // CommitUnclaimedRewards commit the tokens on unclaimed store to committed + CommitUnclaimedRewards(ctx context.Context, in *MsgCommitUnclaimedRewards, opts ...grpc.CallOption) (*MsgCommitUnclaimedRewardsResponse, error) + // UncommitTokens uncommits the tokens from committed store and make it liquid immediately UncommitTokens(ctx context.Context, in *MsgUncommitTokens, opts ...grpc.CallOption) (*MsgUncommitTokensResponse, error) + // WithdrawTokens withdraw first from unclaimed and if it requires more, withdraw from committed store WithdrawTokens(ctx context.Context, in *MsgWithdrawTokens, opts ...grpc.CallOption) (*MsgWithdrawTokensResponse, error) - CommitLiquidTokens(ctx context.Context, in *MsgCommitLiquidTokens, opts ...grpc.CallOption) (*MsgCommitLiquidTokensResponse, error) + // Vest converts user's commitment to vesting - start with unclaimed rewards and if it's not enough deduct from committed bucket + // mainly utilized for Eden Vest(ctx context.Context, in *MsgVest, opts ...grpc.CallOption) (*MsgVestResponse, error) - CancelVest(ctx context.Context, in *MsgCancelVest, opts ...grpc.CallOption) (*MsgCancelVestResponse, error) + // VestNow provides functionality to get the token immediately but lower amount than original + // e.g. user can burn 1000 ueden and get 800 uelys when the ratio is 80% VestNow(ctx context.Context, in *MsgVestNow, opts ...grpc.CallOption) (*MsgVestNowResponse, error) - UpdateVestingInfo(ctx context.Context, in *MsgUpdateVestingInfo, opts ...grpc.CallOption) (*MsgUpdateVestingInfoResponse, error) + // VestLiquid converts user's balance to vesting to be utilized for normal tokens vesting like ATOM vesting VestLiquid(ctx context.Context, in *MsgVestLiquid, opts ...grpc.CallOption) (*MsgVestLiquidResponse, error) + // CancelVest cancel the user's vesting and the user reject to get vested tokens + CancelVest(ctx context.Context, in *MsgCancelVest, opts ...grpc.CallOption) (*MsgCancelVestResponse, error) + // UpdateVestingInfo add/update specific vesting info by denom on Params + UpdateVestingInfo(ctx context.Context, in *MsgUpdateVestingInfo, opts ...grpc.CallOption) (*MsgUpdateVestingInfoResponse, error) } type msgClient struct { @@ -969,36 +990,36 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } -func (c *msgClient) CommitTokens(ctx context.Context, in *MsgCommitTokens, opts ...grpc.CallOption) (*MsgCommitTokensResponse, error) { - out := new(MsgCommitTokensResponse) - err := c.cc.Invoke(ctx, "/elys.commitment.Msg/CommitTokens", in, out, opts...) +func (c *msgClient) CommitLiquidTokens(ctx context.Context, in *MsgCommitLiquidTokens, opts ...grpc.CallOption) (*MsgCommitLiquidTokensResponse, error) { + out := new(MsgCommitLiquidTokensResponse) + err := c.cc.Invoke(ctx, "/elys.commitment.Msg/CommitLiquidTokens", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *msgClient) UncommitTokens(ctx context.Context, in *MsgUncommitTokens, opts ...grpc.CallOption) (*MsgUncommitTokensResponse, error) { - out := new(MsgUncommitTokensResponse) - err := c.cc.Invoke(ctx, "/elys.commitment.Msg/UncommitTokens", in, out, opts...) +func (c *msgClient) CommitUnclaimedRewards(ctx context.Context, in *MsgCommitUnclaimedRewards, opts ...grpc.CallOption) (*MsgCommitUnclaimedRewardsResponse, error) { + out := new(MsgCommitUnclaimedRewardsResponse) + err := c.cc.Invoke(ctx, "/elys.commitment.Msg/CommitUnclaimedRewards", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *msgClient) WithdrawTokens(ctx context.Context, in *MsgWithdrawTokens, opts ...grpc.CallOption) (*MsgWithdrawTokensResponse, error) { - out := new(MsgWithdrawTokensResponse) - err := c.cc.Invoke(ctx, "/elys.commitment.Msg/WithdrawTokens", in, out, opts...) +func (c *msgClient) UncommitTokens(ctx context.Context, in *MsgUncommitTokens, opts ...grpc.CallOption) (*MsgUncommitTokensResponse, error) { + out := new(MsgUncommitTokensResponse) + err := c.cc.Invoke(ctx, "/elys.commitment.Msg/UncommitTokens", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *msgClient) CommitLiquidTokens(ctx context.Context, in *MsgCommitLiquidTokens, opts ...grpc.CallOption) (*MsgCommitLiquidTokensResponse, error) { - out := new(MsgCommitLiquidTokensResponse) - err := c.cc.Invoke(ctx, "/elys.commitment.Msg/CommitLiquidTokens", in, out, opts...) +func (c *msgClient) WithdrawTokens(ctx context.Context, in *MsgWithdrawTokens, opts ...grpc.CallOption) (*MsgWithdrawTokensResponse, error) { + out := new(MsgWithdrawTokensResponse) + err := c.cc.Invoke(ctx, "/elys.commitment.Msg/WithdrawTokens", in, out, opts...) if err != nil { return nil, err } @@ -1014,36 +1035,36 @@ func (c *msgClient) Vest(ctx context.Context, in *MsgVest, opts ...grpc.CallOpti return out, nil } -func (c *msgClient) CancelVest(ctx context.Context, in *MsgCancelVest, opts ...grpc.CallOption) (*MsgCancelVestResponse, error) { - out := new(MsgCancelVestResponse) - err := c.cc.Invoke(ctx, "/elys.commitment.Msg/CancelVest", in, out, opts...) +func (c *msgClient) VestNow(ctx context.Context, in *MsgVestNow, opts ...grpc.CallOption) (*MsgVestNowResponse, error) { + out := new(MsgVestNowResponse) + err := c.cc.Invoke(ctx, "/elys.commitment.Msg/VestNow", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *msgClient) VestNow(ctx context.Context, in *MsgVestNow, opts ...grpc.CallOption) (*MsgVestNowResponse, error) { - out := new(MsgVestNowResponse) - err := c.cc.Invoke(ctx, "/elys.commitment.Msg/VestNow", in, out, opts...) +func (c *msgClient) VestLiquid(ctx context.Context, in *MsgVestLiquid, opts ...grpc.CallOption) (*MsgVestLiquidResponse, error) { + out := new(MsgVestLiquidResponse) + err := c.cc.Invoke(ctx, "/elys.commitment.Msg/VestLiquid", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *msgClient) UpdateVestingInfo(ctx context.Context, in *MsgUpdateVestingInfo, opts ...grpc.CallOption) (*MsgUpdateVestingInfoResponse, error) { - out := new(MsgUpdateVestingInfoResponse) - err := c.cc.Invoke(ctx, "/elys.commitment.Msg/UpdateVestingInfo", in, out, opts...) +func (c *msgClient) CancelVest(ctx context.Context, in *MsgCancelVest, opts ...grpc.CallOption) (*MsgCancelVestResponse, error) { + out := new(MsgCancelVestResponse) + err := c.cc.Invoke(ctx, "/elys.commitment.Msg/CancelVest", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *msgClient) VestLiquid(ctx context.Context, in *MsgVestLiquid, opts ...grpc.CallOption) (*MsgVestLiquidResponse, error) { - out := new(MsgVestLiquidResponse) - err := c.cc.Invoke(ctx, "/elys.commitment.Msg/VestLiquid", in, out, opts...) +func (c *msgClient) UpdateVestingInfo(ctx context.Context, in *MsgUpdateVestingInfo, opts ...grpc.CallOption) (*MsgUpdateVestingInfoResponse, error) { + out := new(MsgUpdateVestingInfoResponse) + err := c.cc.Invoke(ctx, "/elys.commitment.Msg/UpdateVestingInfo", in, out, opts...) if err != nil { return nil, err } @@ -1052,23 +1073,37 @@ func (c *msgClient) VestLiquid(ctx context.Context, in *MsgVestLiquid, opts ...g // MsgServer is the server API for Msg service. type MsgServer interface { - CommitTokens(context.Context, *MsgCommitTokens) (*MsgCommitTokensResponse, error) + // CommitLiquidTokens commit the tokens from user's balance + CommitLiquidTokens(context.Context, *MsgCommitLiquidTokens) (*MsgCommitLiquidTokensResponse, error) + // CommitUnclaimedRewards commit the tokens on unclaimed store to committed + CommitUnclaimedRewards(context.Context, *MsgCommitUnclaimedRewards) (*MsgCommitUnclaimedRewardsResponse, error) + // UncommitTokens uncommits the tokens from committed store and make it liquid immediately UncommitTokens(context.Context, *MsgUncommitTokens) (*MsgUncommitTokensResponse, error) + // WithdrawTokens withdraw first from unclaimed and if it requires more, withdraw from committed store WithdrawTokens(context.Context, *MsgWithdrawTokens) (*MsgWithdrawTokensResponse, error) - CommitLiquidTokens(context.Context, *MsgCommitLiquidTokens) (*MsgCommitLiquidTokensResponse, error) + // Vest converts user's commitment to vesting - start with unclaimed rewards and if it's not enough deduct from committed bucket + // mainly utilized for Eden Vest(context.Context, *MsgVest) (*MsgVestResponse, error) - CancelVest(context.Context, *MsgCancelVest) (*MsgCancelVestResponse, error) + // VestNow provides functionality to get the token immediately but lower amount than original + // e.g. user can burn 1000 ueden and get 800 uelys when the ratio is 80% VestNow(context.Context, *MsgVestNow) (*MsgVestNowResponse, error) - UpdateVestingInfo(context.Context, *MsgUpdateVestingInfo) (*MsgUpdateVestingInfoResponse, error) + // VestLiquid converts user's balance to vesting to be utilized for normal tokens vesting like ATOM vesting VestLiquid(context.Context, *MsgVestLiquid) (*MsgVestLiquidResponse, error) + // CancelVest cancel the user's vesting and the user reject to get vested tokens + CancelVest(context.Context, *MsgCancelVest) (*MsgCancelVestResponse, error) + // UpdateVestingInfo add/update specific vesting info by denom on Params + UpdateVestingInfo(context.Context, *MsgUpdateVestingInfo) (*MsgUpdateVestingInfoResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. type UnimplementedMsgServer struct { } -func (*UnimplementedMsgServer) CommitTokens(ctx context.Context, req *MsgCommitTokens) (*MsgCommitTokensResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method CommitTokens not implemented") +func (*UnimplementedMsgServer) CommitLiquidTokens(ctx context.Context, req *MsgCommitLiquidTokens) (*MsgCommitLiquidTokensResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CommitLiquidTokens not implemented") +} +func (*UnimplementedMsgServer) CommitUnclaimedRewards(ctx context.Context, req *MsgCommitUnclaimedRewards) (*MsgCommitUnclaimedRewardsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CommitUnclaimedRewards not implemented") } func (*UnimplementedMsgServer) UncommitTokens(ctx context.Context, req *MsgUncommitTokens) (*MsgUncommitTokensResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UncommitTokens not implemented") @@ -1076,97 +1111,94 @@ func (*UnimplementedMsgServer) UncommitTokens(ctx context.Context, req *MsgUncom func (*UnimplementedMsgServer) WithdrawTokens(ctx context.Context, req *MsgWithdrawTokens) (*MsgWithdrawTokensResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method WithdrawTokens not implemented") } -func (*UnimplementedMsgServer) CommitLiquidTokens(ctx context.Context, req *MsgCommitLiquidTokens) (*MsgCommitLiquidTokensResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method CommitLiquidTokens not implemented") -} func (*UnimplementedMsgServer) Vest(ctx context.Context, req *MsgVest) (*MsgVestResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Vest not implemented") } -func (*UnimplementedMsgServer) CancelVest(ctx context.Context, req *MsgCancelVest) (*MsgCancelVestResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method CancelVest not implemented") -} func (*UnimplementedMsgServer) VestNow(ctx context.Context, req *MsgVestNow) (*MsgVestNowResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method VestNow not implemented") } -func (*UnimplementedMsgServer) UpdateVestingInfo(ctx context.Context, req *MsgUpdateVestingInfo) (*MsgUpdateVestingInfoResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method UpdateVestingInfo not implemented") -} func (*UnimplementedMsgServer) VestLiquid(ctx context.Context, req *MsgVestLiquid) (*MsgVestLiquidResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method VestLiquid not implemented") } +func (*UnimplementedMsgServer) CancelVest(ctx context.Context, req *MsgCancelVest) (*MsgCancelVestResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CancelVest not implemented") +} +func (*UnimplementedMsgServer) UpdateVestingInfo(ctx context.Context, req *MsgUpdateVestingInfo) (*MsgUpdateVestingInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateVestingInfo not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } -func _Msg_CommitTokens_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgCommitTokens) +func _Msg_CommitLiquidTokens_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCommitLiquidTokens) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).CommitTokens(ctx, in) + return srv.(MsgServer).CommitLiquidTokens(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/elys.commitment.Msg/CommitTokens", + FullMethod: "/elys.commitment.Msg/CommitLiquidTokens", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).CommitTokens(ctx, req.(*MsgCommitTokens)) + return srv.(MsgServer).CommitLiquidTokens(ctx, req.(*MsgCommitLiquidTokens)) } return interceptor(ctx, in, info, handler) } -func _Msg_UncommitTokens_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgUncommitTokens) +func _Msg_CommitUnclaimedRewards_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCommitUnclaimedRewards) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).UncommitTokens(ctx, in) + return srv.(MsgServer).CommitUnclaimedRewards(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/elys.commitment.Msg/UncommitTokens", + FullMethod: "/elys.commitment.Msg/CommitUnclaimedRewards", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).UncommitTokens(ctx, req.(*MsgUncommitTokens)) + return srv.(MsgServer).CommitUnclaimedRewards(ctx, req.(*MsgCommitUnclaimedRewards)) } return interceptor(ctx, in, info, handler) } -func _Msg_WithdrawTokens_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgWithdrawTokens) +func _Msg_UncommitTokens_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUncommitTokens) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).WithdrawTokens(ctx, in) + return srv.(MsgServer).UncommitTokens(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/elys.commitment.Msg/WithdrawTokens", + FullMethod: "/elys.commitment.Msg/UncommitTokens", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).WithdrawTokens(ctx, req.(*MsgWithdrawTokens)) + return srv.(MsgServer).UncommitTokens(ctx, req.(*MsgUncommitTokens)) } return interceptor(ctx, in, info, handler) } -func _Msg_CommitLiquidTokens_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgCommitLiquidTokens) +func _Msg_WithdrawTokens_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgWithdrawTokens) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).CommitLiquidTokens(ctx, in) + return srv.(MsgServer).WithdrawTokens(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/elys.commitment.Msg/CommitLiquidTokens", + FullMethod: "/elys.commitment.Msg/WithdrawTokens", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).CommitLiquidTokens(ctx, req.(*MsgCommitLiquidTokens)) + return srv.(MsgServer).WithdrawTokens(ctx, req.(*MsgWithdrawTokens)) } return interceptor(ctx, in, info, handler) } @@ -1189,74 +1221,74 @@ func _Msg_Vest_Handler(srv interface{}, ctx context.Context, dec func(interface{ return interceptor(ctx, in, info, handler) } -func _Msg_CancelVest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgCancelVest) +func _Msg_VestNow_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgVestNow) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).CancelVest(ctx, in) + return srv.(MsgServer).VestNow(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/elys.commitment.Msg/CancelVest", + FullMethod: "/elys.commitment.Msg/VestNow", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).CancelVest(ctx, req.(*MsgCancelVest)) + return srv.(MsgServer).VestNow(ctx, req.(*MsgVestNow)) } return interceptor(ctx, in, info, handler) } -func _Msg_VestNow_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgVestNow) +func _Msg_VestLiquid_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgVestLiquid) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).VestNow(ctx, in) + return srv.(MsgServer).VestLiquid(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/elys.commitment.Msg/VestNow", + FullMethod: "/elys.commitment.Msg/VestLiquid", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).VestNow(ctx, req.(*MsgVestNow)) + return srv.(MsgServer).VestLiquid(ctx, req.(*MsgVestLiquid)) } return interceptor(ctx, in, info, handler) } -func _Msg_UpdateVestingInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgUpdateVestingInfo) +func _Msg_CancelVest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCancelVest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).UpdateVestingInfo(ctx, in) + return srv.(MsgServer).CancelVest(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/elys.commitment.Msg/UpdateVestingInfo", + FullMethod: "/elys.commitment.Msg/CancelVest", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).UpdateVestingInfo(ctx, req.(*MsgUpdateVestingInfo)) + return srv.(MsgServer).CancelVest(ctx, req.(*MsgCancelVest)) } return interceptor(ctx, in, info, handler) } -func _Msg_VestLiquid_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgVestLiquid) +func _Msg_UpdateVestingInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateVestingInfo) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).VestLiquid(ctx, in) + return srv.(MsgServer).UpdateVestingInfo(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/elys.commitment.Msg/VestLiquid", + FullMethod: "/elys.commitment.Msg/UpdateVestingInfo", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).VestLiquid(ctx, req.(*MsgVestLiquid)) + return srv.(MsgServer).UpdateVestingInfo(ctx, req.(*MsgUpdateVestingInfo)) } return interceptor(ctx, in, info, handler) } @@ -1266,8 +1298,12 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "CommitTokens", - Handler: _Msg_CommitTokens_Handler, + MethodName: "CommitLiquidTokens", + Handler: _Msg_CommitLiquidTokens_Handler, + }, + { + MethodName: "CommitUnclaimedRewards", + Handler: _Msg_CommitUnclaimedRewards_Handler, }, { MethodName: "UncommitTokens", @@ -1277,36 +1313,32 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "WithdrawTokens", Handler: _Msg_WithdrawTokens_Handler, }, - { - MethodName: "CommitLiquidTokens", - Handler: _Msg_CommitLiquidTokens_Handler, - }, { MethodName: "Vest", Handler: _Msg_Vest_Handler, }, - { - MethodName: "CancelVest", - Handler: _Msg_CancelVest_Handler, - }, { MethodName: "VestNow", Handler: _Msg_VestNow_Handler, }, - { - MethodName: "UpdateVestingInfo", - Handler: _Msg_UpdateVestingInfo_Handler, - }, { MethodName: "VestLiquid", Handler: _Msg_VestLiquid_Handler, }, + { + MethodName: "CancelVest", + Handler: _Msg_CancelVest_Handler, + }, + { + MethodName: "UpdateVestingInfo", + Handler: _Msg_UpdateVestingInfo_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "elys/commitment/tx.proto", } -func (m *MsgCommitTokens) Marshal() (dAtA []byte, err error) { +func (m *MsgCommitUnclaimedRewards) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1316,12 +1348,12 @@ func (m *MsgCommitTokens) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgCommitTokens) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgCommitUnclaimedRewards) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgCommitTokens) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgCommitUnclaimedRewards) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1353,7 +1385,7 @@ func (m *MsgCommitTokens) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgCommitTokensResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgCommitUnclaimedRewardsResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1363,12 +1395,12 @@ func (m *MsgCommitTokensResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgCommitTokensResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgCommitUnclaimedRewardsResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgCommitTokensResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgCommitUnclaimedRewardsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1536,6 +1568,11 @@ func (m *MsgCommitLiquidTokens) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.MinLock != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.MinLock)) + i-- + dAtA[i] = 0x20 + } if len(m.Denom) > 0 { i -= len(m.Denom) copy(dAtA[i:], m.Denom) @@ -1966,7 +2003,7 @@ func encodeVarintTx(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *MsgCommitTokens) Size() (n int) { +func (m *MsgCommitUnclaimedRewards) Size() (n int) { if m == nil { return 0 } @@ -1985,7 +2022,7 @@ func (m *MsgCommitTokens) Size() (n int) { return n } -func (m *MsgCommitTokensResponse) Size() (n int) { +func (m *MsgCommitUnclaimedRewardsResponse) Size() (n int) { if m == nil { return 0 } @@ -2066,6 +2103,9 @@ func (m *MsgCommitLiquidTokens) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } + if m.MinLock != 0 { + n += 1 + sovTx(uint64(m.MinLock)) + } return n } @@ -2239,7 +2279,7 @@ func sovTx(x uint64) (n int) { func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *MsgCommitTokens) Unmarshal(dAtA []byte) error { +func (m *MsgCommitUnclaimedRewards) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2262,10 +2302,10 @@ func (m *MsgCommitTokens) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgCommitTokens: wiretype end group for non-group") + return fmt.Errorf("proto: MsgCommitUnclaimedRewards: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCommitTokens: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgCommitUnclaimedRewards: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -2387,7 +2427,7 @@ func (m *MsgCommitTokens) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgCommitTokensResponse) Unmarshal(dAtA []byte) error { +func (m *MsgCommitUnclaimedRewardsResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2410,10 +2450,10 @@ func (m *MsgCommitTokensResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgCommitTokensResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgCommitUnclaimedRewardsResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCommitTokensResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgCommitUnclaimedRewardsResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: @@ -2960,6 +3000,25 @@ func (m *MsgCommitLiquidTokens) Unmarshal(dAtA []byte) error { } m.Denom = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MinLock", wireType) + } + m.MinLock = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MinLock |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/x/epochs/types/query.pb.gw.go b/x/epochs/types/query.pb.gw.go index 4c4b168c3..d7657c657 100644 --- a/x/epochs/types/query.pb.gw.go +++ b/x/epochs/types/query.pb.gw.go @@ -20,7 +20,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -31,7 +30,6 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage -var _ = metadata.Join var ( filter_Query_EpochInfos_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} @@ -108,14 +106,12 @@ func local_request_Query_CurrentEpoch_0(ctx context.Context, marshaler runtime.M // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { mux.Handle("GET", pattern_Query_EpochInfos_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -123,7 +119,6 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_EpochInfos_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -137,8 +132,6 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_CurrentEpoch_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -146,7 +139,6 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_CurrentEpoch_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) diff --git a/x/incentive/keeper/abci_test.go b/x/incentive/keeper/abci_test.go index d808bf78a..cc9487ab2 100644 --- a/x/incentive/keeper/abci_test.go +++ b/x/incentive/keeper/abci_test.go @@ -18,13 +18,13 @@ func TestABCI_EndBlocker(t *testing.T) { ik := app.IncentiveKeeper var committed []sdk.Coins - var uncommitted []sdk.Coins + var unclaimed []sdk.Coins - // Prepare uncommitted tokens + // Prepare unclaimed tokens uedenToken := sdk.NewCoins(sdk.NewCoin(ptypes.Eden, sdk.NewInt(2000))) uedenBToken := sdk.NewCoins(sdk.NewCoin(ptypes.EdenB, sdk.NewInt(2000))) - uncommitted = append(uncommitted, uedenToken) - uncommitted = append(uncommitted, uedenBToken) + unclaimed = append(unclaimed, uedenToken) + unclaimed = append(unclaimed, uedenBToken) // Eden err := app.BankKeeper.MintCoins(ctx, ctypes.ModuleName, uedenToken) @@ -39,7 +39,7 @@ func TestABCI_EndBlocker(t *testing.T) { require.NoError(t, err) // Add testing commitment - simapp.AddTestCommitment(app, ctx, genAccount, committed, uncommitted) + simapp.AddTestCommitment(app, ctx, genAccount, committed, unclaimed) // Update Elys staked amount ik.EndBlocker(ctx) diff --git a/x/incentive/keeper/hooks_commitment.go b/x/incentive/keeper/hooks_commitment.go index 638b18500..5e8643aee 100644 --- a/x/incentive/keeper/hooks_commitment.go +++ b/x/incentive/keeper/hooks_commitment.go @@ -11,7 +11,7 @@ func (k Keeper) CommitmentChanged(ctx sdk.Context, creator string, amount sdk.Co // Process eden uncommitted hook func (k Keeper) EdenUncommitted(ctx sdk.Context, creator string, amount sdk.Coin) { - k.BurnEdenBFromEdenUncommitted(ctx, creator, amount.Amount) + k.BurnEdenBFromEdenUnclaimed(ctx, creator, amount.Amount) } // ___________________________________________________________________________________________________ diff --git a/x/incentive/keeper/hooks_epoch.go b/x/incentive/keeper/hooks_epoch.go index 81e46753e..0c9bfd607 100644 --- a/x/incentive/keeper/hooks_epoch.go +++ b/x/incentive/keeper/hooks_epoch.go @@ -20,8 +20,8 @@ func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, _ int64) return } - // Update uncommitted token amount - k.UpdateUncommittedTokens(ctx, epochIdentifier, stakeIncentive, lpIncentive) + // Update unclaimed token amount + k.UpdateRewardsUnclaimed(ctx, epochIdentifier, stakeIncentive, lpIncentive) } // ___________________________________________________________________________________________________ diff --git a/x/incentive/keeper/keeper.go b/x/incentive/keeper/keeper.go index 44bdd2a53..43232ab24 100644 --- a/x/incentive/keeper/keeper.go +++ b/x/incentive/keeper/keeper.go @@ -74,9 +74,9 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } -// Update uncommitted token amount +// Update unclaimed token amount // Called back through epoch hook -func (k Keeper) UpdateUncommittedTokens(ctx sdk.Context, epochIdentifier string, stakeIncentive types.IncentiveInfo, lpIncentive types.IncentiveInfo) { +func (k Keeper) UpdateRewardsUnclaimed(ctx sdk.Context, epochIdentifier string, stakeIncentive types.IncentiveInfo, lpIncentive types.IncentiveInfo) { // Recalculate total committed info k.UpdateTotalCommitmentInfo(ctx) @@ -138,49 +138,49 @@ func (k Keeper) UpdateUncommittedTokens(ctx sdk.Context, epochIdentifier string, // Calculate delegated amount per delegator delegatedAmt := k.CalculateDelegatedAmount(ctx, creator) - // Calculate new uncommitted Eden tokens from Eden & Eden boost committed, Dex rewards distribution + // Calculate new unclaimed Eden tokens from Eden & Eden boost committed, Dex rewards distribution // Distribute gas fees to stakers - // Calculate new uncommitted Eden tokens from Elys staked - newUncommittedEdenTokens, dexRewards, dexRewardsByStakers := k.CalculateRewardsForStakersByElysStaked(ctx, delegatedAmt, edenAmountPerEpochStakers, dexRevenueStakersAmt) - totalEdenGiven = totalEdenGiven.Add(newUncommittedEdenTokens) + // Calculate new unclaimed Eden tokens from Elys staked + newUnclaimedEdenTokens, dexRewards, dexRewardsByStakers := k.CalculateRewardsForStakersByElysStaked(ctx, delegatedAmt, edenAmountPerEpochStakers, dexRevenueStakersAmt) + totalEdenGiven = totalEdenGiven.Add(newUnclaimedEdenTokens) totalRewardsGiven = totalRewardsGiven.Add(dexRewards) - // Calculate new uncommitted Eden tokens from Eden committed + // Calculate new unclaimed Eden tokens from Eden committed edenCommitted := commitments.GetCommittedAmountForDenom(ptypes.Eden) - newUncommittedEdenTokens, dexRewards = k.CalculateRewardsForStakersByCommitted(ctx, edenCommitted, edenAmountPerEpochStakers, dexRevenueStakersAmt) - totalEdenGiven = totalEdenGiven.Add(newUncommittedEdenTokens) + newUnclaimedEdenTokens, dexRewards = k.CalculateRewardsForStakersByCommitted(ctx, edenCommitted, edenAmountPerEpochStakers, dexRevenueStakersAmt) + totalEdenGiven = totalEdenGiven.Add(newUnclaimedEdenTokens) totalRewardsGiven = totalRewardsGiven.Add(dexRewards) - // Calculate new uncommitted Eden tokens from Eden Boost committed + // Calculate new unclaimed Eden tokens from Eden Boost committed edenBoostCommitted := commitments.GetCommittedAmountForDenom(ptypes.EdenB) - newUncommittedEdenTokens, dexRewards = k.CalculateRewardsForStakersByCommitted(ctx, edenBoostCommitted, edenAmountPerEpochStakers, dexRevenueStakersAmt) - totalEdenGiven = totalEdenGiven.Add(newUncommittedEdenTokens) + newUnclaimedEdenTokens, dexRewards = k.CalculateRewardsForStakersByCommitted(ctx, edenBoostCommitted, edenAmountPerEpochStakers, dexRevenueStakersAmt) + totalEdenGiven = totalEdenGiven.Add(newUnclaimedEdenTokens) totalRewardsGiven = totalRewardsGiven.Add(dexRewards) - // Calculate new uncommitted Eden tokens from LpTokens committed, Dex rewards distribution + // Calculate new unclaimed Eden tokens from LpTokens committed, Dex rewards distribution // Distribute gas fees to LPs - newUncommittedEdenTokensLp, dexRewardsLp := k.CalculateRewardsForLPs(ctx, totalProxyTVL, commitments, edenAmountPerEpochLPs, gasFeesLPsAmt) - totalEdenGivenLP = totalEdenGivenLP.Add(newUncommittedEdenTokensLp) + newUnclaimedEdenTokensLp, dexRewardsLp := k.CalculateRewardsForLPs(ctx, totalProxyTVL, commitments, edenAmountPerEpochLPs, gasFeesLPsAmt) + totalEdenGivenLP = totalEdenGivenLP.Add(newUnclaimedEdenTokensLp) totalRewardsGivenLP = totalRewardsGivenLP.Add(dexRewardsLp) - // Calculate the total Eden uncommitted amount - newUncommittedEdenTokens = newUncommittedEdenTokens.Add(newUncommittedEdenTokensLp) + // Calculate the total Eden unclaimed amount + newUnclaimedEdenTokens = newUnclaimedEdenTokens.Add(newUnclaimedEdenTokensLp) // Give commission to validators ( Eden from stakers and Dex rewards from stakers. ) - edenCommissionGiven, dexRewardsCommissionGiven := k.GiveCommissionToValidators(ctx, creator, delegatedAmt, newUncommittedEdenTokens, dexRewardsByStakers) + edenCommissionGiven, dexRewardsCommissionGiven := k.GiveCommissionToValidators(ctx, creator, delegatedAmt, newUnclaimedEdenTokens, dexRewardsByStakers) // Minus the given amount and increase with the remains only - newUncommittedEdenTokens = newUncommittedEdenTokens.Sub(edenCommissionGiven) + newUnclaimedEdenTokens = newUnclaimedEdenTokens.Sub(edenCommissionGiven) // Plus LpDexRewards and minus commission given dexRewards = dexRewards.Add(dexRewardsLp).Sub(dexRewardsCommissionGiven) - // Calculate new uncommitted Eden-Boost tokens for staker and Eden token holders - newUncommittedEdenBoostTokens := k.CalculateEdenBoostRewards(ctx, delegatedAmt, commitments, epochIdentifier, edenBoostAPR) + // Calculate new unclaimed Eden-Boost tokens for staker and Eden token holders + newUnclaimedEdenBoostTokens := k.CalculateEdenBoostRewards(ctx, delegatedAmt, commitments, epochIdentifier, edenBoostAPR) - // Update Commitments with new uncommitted token amounts - k.UpdateCommitments(ctx, creator, &commitments, newUncommittedEdenTokens, newUncommittedEdenBoostTokens, dexRewards) + // Update Commitments with new unclaimed token amounts + k.UpdateCommitments(ctx, creator, &commitments, newUnclaimedEdenTokens, newUnclaimedEdenBoostTokens, dexRewards) return false }, @@ -206,11 +206,11 @@ func (k Keeper) UpdateUncommittedTokens(ctx sdk.Context, epochIdentifier string, // ---------------------------------- } -func (k Keeper) UpdateCommitments(ctx sdk.Context, creator string, commitments *ctypes.Commitments, newUncommittedEdenTokens sdk.Int, newUncommittedEdenBoostTokens sdk.Int, dexRewards sdk.Int) { - // Update uncommitted Eden balances in the Commitments structure - k.UpdateTokensCommitment(commitments, newUncommittedEdenTokens, ptypes.Eden) - // Update uncommitted Eden-Boost token balances in the Commitments structure - k.UpdateTokensCommitment(commitments, newUncommittedEdenBoostTokens, ptypes.EdenB) +func (k Keeper) UpdateCommitments(ctx sdk.Context, creator string, commitments *ctypes.Commitments, newUnclaimedEdenTokens sdk.Int, newUnclaimedEdenBoostTokens sdk.Int, dexRewards sdk.Int) { + // Update unclaimed Eden balances in the Commitments structure + k.UpdateTokensCommitment(commitments, newUnclaimedEdenTokens, ptypes.Eden) + // Update unclaimed Eden-Boost token balances in the Commitments structure + k.UpdateTokensCommitment(commitments, newUnclaimedEdenBoostTokens, ptypes.EdenB) // All dex revenue are collected to incentive module in USDC // Gas fees (Elys) are also converted into USDC and collected into total dex revenue wallet of incentive module. @@ -224,18 +224,18 @@ func (k Keeper) UpdateCommitments(ctx sdk.Context, creator string, commitments * k.cmk.SetCommitments(ctx, *commitments) } -// Update the uncommitted Eden token balance -func (k Keeper) UpdateTokensCommitment(commitments *ctypes.Commitments, new_uncommitted_eden_tokens sdk.Int, denom string) { - uncommittedEden, found := commitments.GetUncommittedTokensForDenom(denom) +// Update the unclaimed Eden token balance +func (k Keeper) UpdateTokensCommitment(commitments *ctypes.Commitments, newUnclaimedEdenTokens sdk.Int, denom string) { + unclaimedEden, found := commitments.GetRewardsUnclaimedForDenom(denom) if !found { - uncommittedTokens := commitments.GetUncommittedTokens() - uncommittedTokens = append(uncommittedTokens, &ctypes.UncommittedTokens{ + rewardsUnclaimed := commitments.GetRewardsUnclaimed() + rewardsUnclaimed = append(rewardsUnclaimed, &ctypes.RewardsUnclaimed{ Denom: denom, - Amount: new_uncommitted_eden_tokens, + Amount: newUnclaimedEdenTokens, }) - commitments.UncommittedTokens = uncommittedTokens + commitments.RewardsUnclaimed = rewardsUnclaimed } else { - uncommittedEden.Amount = uncommittedEden.Amount.Add(new_uncommitted_eden_tokens) + unclaimedEden.Amount = unclaimedEden.Amount.Add(newUnclaimedEdenTokens) } } diff --git a/x/incentive/keeper/keeper_burn_edenB.go b/x/incentive/keeper/keeper_burn_edenB.go index b3d06fb29..02c2e1f81 100644 --- a/x/incentive/keeper/keeper_burn_edenB.go +++ b/x/incentive/keeper/keeper_burn_edenB.go @@ -35,10 +35,10 @@ func (k Keeper) BurnEdenBFromElysUnstaking(ctx sdk.Context, delegator sdk.AccAdd //Total EdenB amount edenBCommitted := commitments.GetCommittedAmountForDenom(ptypes.EdenB) - edenBUncommitted := commitments.GetUncommittedAmountForDenom(ptypes.EdenB) + edenBUnclaimed := commitments.GetUnclaimedAmountForDenom(ptypes.EdenB) // Total EdenB amount - totalEdenB := edenBCommitted.Add(edenBUncommitted) + totalEdenB := edenBCommitted.Add(edenBUnclaimed) // Unstaked unstakedElys := prevElysStaked.Amount.Sub(delegatedAmt) @@ -55,8 +55,8 @@ func (k Keeper) BurnEdenBFromElysUnstaking(ctx sdk.Context, delegator sdk.AccAdd return err } -// Burn EdenBoost from Eden uncommitted -func (k Keeper) BurnEdenBFromEdenUncommitted(ctx sdk.Context, delegator string, uncommittedAmt sdk.Int) error { +// Burn EdenBoost from Eden unclaimed +func (k Keeper) BurnEdenBFromEdenUnclaimed(ctx sdk.Context, delegator string, unclaimedAmt sdk.Int) error { // Get elys staked amount elysStaked, found := k.GetElysStaked(ctx, delegator) if !found { @@ -73,16 +73,16 @@ func (k Keeper) BurnEdenBFromEdenUncommitted(ctx sdk.Context, delegator string, //Total EdenB amount edenBCommitted := commitments.GetCommittedAmountForDenom(ptypes.EdenB) - edenBUncommitted := commitments.GetUncommittedAmountForDenom(ptypes.EdenB) + edenBUnclaimed := commitments.GetUnclaimedAmountForDenom(ptypes.EdenB) // Total EdenB amount - totalEdenB := edenBCommitted.Add(edenBUncommitted) + totalEdenB := edenBCommitted.Add(edenBUnclaimed) - uncommittedAmtDec := sdk.NewDecFromInt(uncommittedAmt) + unclaimedAmtDec := sdk.NewDecFromInt(unclaimedAmt) edenCommittedAndElysStakedDec := sdk.NewDecFromInt(edenCommitted.Add(elysStaked.Amount)) totalEdenBDec := sdk.NewDecFromInt(totalEdenB) - edenBToBurn := uncommittedAmtDec.Quo(edenCommittedAndElysStakedDec).Mul(totalEdenBDec) + edenBToBurn := unclaimedAmtDec.Quo(edenCommittedAndElysStakedDec).Mul(totalEdenBDec) // Burn EdenB ( Deduction EdenB in commitment module) commitment, err := k.cmk.DeductCommitments(ctx, delegator, ptypes.EdenB, edenBToBurn.TruncateInt()) diff --git a/x/incentive/keeper/keeper_burn_edenB_test.go b/x/incentive/keeper/keeper_burn_edenB_test.go index 7b37fb811..835951fd7 100644 --- a/x/incentive/keeper/keeper_burn_edenB_test.go +++ b/x/incentive/keeper/keeper_burn_edenB_test.go @@ -20,13 +20,13 @@ func TestBurnEdenBFromElysUnstaked(t *testing.T) { ik, sk := app.IncentiveKeeper, app.StakingKeeper var committed []sdk.Coins - var uncommitted []sdk.Coins + var unclaimed []sdk.Coins - // Prepare uncommitted tokens + // Prepare unclaimed tokens uedenToken := sdk.NewCoins(sdk.NewCoin(ptypes.Eden, sdk.NewInt(2000))) uedenBToken := sdk.NewCoins(sdk.NewCoin(ptypes.EdenB, sdk.NewInt(20000))) - uncommitted = append(uncommitted, uedenToken) - uncommitted = append(uncommitted, uedenBToken) + unclaimed = append(unclaimed, uedenToken) + unclaimed = append(unclaimed, uedenBToken) // Eden err := app.BankKeeper.MintCoins(ctx, ctypes.ModuleName, uedenToken) @@ -59,12 +59,12 @@ func TestBurnEdenBFromElysUnstaked(t *testing.T) { require.NoError(t, err) // Add testing commitment - simapp.AddTestCommitment(app, ctx, genAccount, committed, uncommitted) + simapp.AddTestCommitment(app, ctx, genAccount, committed, unclaimed) commitment, found := app.CommitmentKeeper.GetCommitments(ctx, genAccount.String()) require.True(t, found) - require.Equal(t, commitment.UncommittedTokens[1].Denom, ptypes.EdenB) - require.Equal(t, commitment.UncommittedTokens[1].Amount, sdk.NewInt(20000)) + require.Equal(t, commitment.RewardsUnclaimed[1].Denom, ptypes.EdenB) + require.Equal(t, commitment.RewardsUnclaimed[1].Amount, sdk.NewInt(20000)) // Track Elys staked amount ik.EndBlocker(ctx) @@ -76,24 +76,24 @@ func TestBurnEdenBFromElysUnstaked(t *testing.T) { commitment, found = app.CommitmentKeeper.GetCommitments(ctx, genAccount.String()) require.True(t, found) - require.Equal(t, commitment.UncommittedTokens[1].Denom, ptypes.EdenB) - require.Equal(t, commitment.UncommittedTokens[1].Amount, sdk.NewInt(17525)) + require.Equal(t, commitment.RewardsUnclaimed[1].Denom, ptypes.EdenB) + require.Equal(t, commitment.RewardsUnclaimed[1].Amount, sdk.NewInt(17525)) } -func TestBurnEdenBFromEdenUncommitted(t *testing.T) { +func TestBurnEdenBFromEdenUnclaimed(t *testing.T) { app, genAccount, _ := simapp.InitElysTestAppWithGenAccount() ctx := app.BaseApp.NewContext(initChain, tmproto.Header{}) ik, cmk := app.IncentiveKeeper, app.CommitmentKeeper var committed []sdk.Coins - var uncommitted []sdk.Coins + var unclaimed []sdk.Coins - // Prepare uncommitted tokens + // Prepare unclaimed tokens uedenToken := sdk.NewCoins(sdk.NewCoin(ptypes.Eden, sdk.NewInt(2000))) uedenBToken := sdk.NewCoins(sdk.NewCoin(ptypes.EdenB, sdk.NewInt(20000))) - uncommitted = append(uncommitted, uedenToken) - uncommitted = append(uncommitted, uedenBToken) + unclaimed = append(unclaimed, uedenToken) + unclaimed = append(unclaimed, uedenBToken) // Eden err := app.BankKeeper.MintCoins(ctx, ctypes.ModuleName, uedenToken) @@ -126,12 +126,12 @@ func TestBurnEdenBFromEdenUncommitted(t *testing.T) { require.NoError(t, err) // Add testing commitment - simapp.AddTestCommitment(app, ctx, genAccount, committed, uncommitted) + simapp.AddTestCommitment(app, ctx, genAccount, committed, unclaimed) commitment, found := app.CommitmentKeeper.GetCommitments(ctx, genAccount.String()) require.True(t, found) - require.Equal(t, commitment.UncommittedTokens[1].Denom, ptypes.EdenB) - require.Equal(t, commitment.UncommittedTokens[1].Amount, sdk.NewInt(20000)) + require.Equal(t, commitment.RewardsUnclaimed[1].Denom, ptypes.EdenB) + require.Equal(t, commitment.RewardsUnclaimed[1].Amount, sdk.NewInt(20000)) // Track Elys staked amount ik.EndBlocker(ctx) @@ -149,10 +149,10 @@ func TestBurnEdenBFromEdenUncommitted(t *testing.T) { _, err = msgServer.UncommitTokens(sdk.WrapSDKContext(ctx), msg) require.NoError(t, err) - // burn amount = 1000 (uncommitted amt) / (1000000 (elys staked) + 10000 (Eden committed)) * (20000 EdenB + 5000 EdenB committed) + // burn amount = 1000 (unclaimed amt) / (1000000 (elys staked) + 10000 (Eden committed)) * (20000 EdenB + 5000 EdenB committed) commitment, found = app.CommitmentKeeper.GetCommitments(ctx, genAccount.String()) require.True(t, found) - require.Equal(t, commitment.UncommittedTokens[1].Denom, ptypes.EdenB) - require.Equal(t, commitment.UncommittedTokens[1].Amount, sdk.NewInt(19976)) + require.Equal(t, commitment.RewardsUnclaimed[1].Denom, ptypes.EdenB) + require.Equal(t, commitment.RewardsUnclaimed[1].Amount, sdk.NewInt(19976)) } diff --git a/x/incentive/keeper/keeper_lps_test.go b/x/incentive/keeper/keeper_lps_test.go index 368eb7986..53067b418 100644 --- a/x/incentive/keeper/keeper_lps_test.go +++ b/x/incentive/keeper/keeper_lps_test.go @@ -83,11 +83,11 @@ func TestCalculateRewardsForLPs(t *testing.T) { addr := simapp.AddTestAddrs(app, ctx, 1, sdk.NewInt(100010)) var committed []sdk.Coins - var uncommitted []sdk.Coins + var unclaimed []sdk.Coins - // Prepare uncommitted tokens + // Prepare unclaimed tokens uedenToken := sdk.NewCoins(sdk.NewCoin(ptypes.Eden, sdk.NewInt(2000))) - uncommitted = append(uncommitted, uedenToken) + unclaimed = append(unclaimed, uedenToken) err := app.BankKeeper.MintCoins(ctx, ctypes.ModuleName, uedenToken) require.NoError(t, err) @@ -117,7 +117,7 @@ func TestCalculateRewardsForLPs(t *testing.T) { err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, ctypes.ModuleName, addr[0], lpToken2) require.NoError(t, err) - simapp.AddTestCommitment(app, ctx, addr[0], committed, uncommitted) + simapp.AddTestCommitment(app, ctx, addr[0], committed, unclaimed) // Create a pool // Mint 100000USDC @@ -193,8 +193,8 @@ func TestCalculateRewardsForLPs(t *testing.T) { gasFeesLPsAmt := sdk.NewDec(1000) // Calculate rewards for LPs - newUncommittedEdenTokensLp, dexRewardsLp := ik.CalculateRewardsForLPs(ctx, totalProxyTVL, commitments, edenAmountPerEpochLp, gasFeesLPsAmt) + newUnclaimedEdenTokensLp, dexRewardsLp := ik.CalculateRewardsForLPs(ctx, totalProxyTVL, commitments, edenAmountPerEpochLp, gasFeesLPsAmt) - require.Equal(t, newUncommittedEdenTokensLp, sdk.NewInt(1000000)) + require.Equal(t, newUnclaimedEdenTokensLp, sdk.NewInt(1000000)) require.Equal(t, dexRewardsLp, sdk.NewInt(1000)) } diff --git a/x/incentive/keeper/keeper_shares_test.go b/x/incentive/keeper/keeper_shares_test.go index da4170ce7..dc670cd08 100644 --- a/x/incentive/keeper/keeper_shares_test.go +++ b/x/incentive/keeper/keeper_shares_test.go @@ -21,13 +21,13 @@ func TestCalculateTotalShareOfStaking(t *testing.T) { addr := simapp.AddTestAddrs(app, ctx, 2, sdk.NewInt(1000)) var committed []sdk.Coins - var uncommitted []sdk.Coins + var unclaimed []sdk.Coins - // Prepare uncommitted tokens + // Prepare unclaimed tokens uedenToken := sdk.NewCoins(sdk.NewCoin(ptypes.Eden, sdk.NewInt(1000))) uedenBToken := sdk.NewCoins(sdk.NewCoin(ptypes.EdenB, sdk.NewInt(1000))) - uncommitted = append(uncommitted, uedenToken) - uncommitted = append(uncommitted, uedenBToken) + unclaimed = append(unclaimed, uedenToken) + unclaimed = append(unclaimed, uedenBToken) // Eden err := app.BankKeeper.MintCoins(ctx, ctypes.ModuleName, uedenToken) @@ -76,17 +76,17 @@ func TestCalculateTotalShareOfStaking(t *testing.T) { err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, ctypes.ModuleName, addr[1], uedenBToken) // Add testing commitment - simapp.AddTestCommitment(app, ctx, addr[0], committed, uncommitted) - simapp.AddTestCommitment(app, ctx, addr[1], committed, uncommitted) + simapp.AddTestCommitment(app, ctx, addr[0], committed, unclaimed) + simapp.AddTestCommitment(app, ctx, addr[1], committed, unclaimed) commitment, found := app.CommitmentKeeper.GetCommitments(ctx, addr[0].String()) require.True(t, found) - require.Equal(t, commitment.UncommittedTokens[0].Denom, ptypes.Eden) - require.Equal(t, commitment.UncommittedTokens[0].Amount, sdk.NewInt(1000)) + require.Equal(t, commitment.RewardsUnclaimed[0].Denom, ptypes.Eden) + require.Equal(t, commitment.RewardsUnclaimed[0].Amount, sdk.NewInt(1000)) - require.Equal(t, commitment.UncommittedTokens[1].Denom, ptypes.EdenB) - require.Equal(t, commitment.UncommittedTokens[1].Amount, sdk.NewInt(1000)) + require.Equal(t, commitment.RewardsUnclaimed[1].Denom, ptypes.EdenB) + require.Equal(t, commitment.RewardsUnclaimed[1].Amount, sdk.NewInt(1000)) require.Equal(t, commitment.CommittedTokens[0].Denom, ptypes.Eden) require.Equal(t, commitment.CommittedTokens[0].Amount, sdk.NewInt(1000)) diff --git a/x/incentive/keeper/keeper_stakers.go b/x/incentive/keeper/keeper_stakers.go index 455c99d9d..f679fcb0d 100644 --- a/x/incentive/keeper/keeper_stakers.go +++ b/x/incentive/keeper/keeper_stakers.go @@ -6,7 +6,7 @@ import ( ptypes "github.com/elys-network/elys/x/parameter/types" ) -// Calculate new Eden token amounts based on the given conditions and user's current uncommitted token balance +// Calculate new Eden token amounts based on the given conditions and user's current unclaimed token balance func (k Keeper) CalculateRewardsForStakersByElysStaked(ctx sdk.Context, delegatedAmt sdk.Int, edenAmountPerEpoch sdk.Int, dexRevenueAmtForStakers sdk.Dec) (sdk.Int, sdk.Int, sdk.Dec) { // -----------Eden calculation --------------------- // -------------------------------------------------------------- @@ -35,7 +35,7 @@ func (k Keeper) CalculateRewardsForStakersByElysStaked(ctx sdk.Context, delegate return newEdenAllocated.TruncateInt(), dexRewards, dexRewardsByStakeOnly } -// Calculate new Eden token amounts based on the given conditions and user's current uncommitted token balance +// Calculate new Eden token amounts based on the given conditions and user's current unclaimed token balance func (k Keeper) CalculateRewardsForStakersByCommitted(ctx sdk.Context, amt sdk.Int, edenAmountPerEpoch sdk.Int, dexRevenueAmtForStakers sdk.Dec) (sdk.Int, sdk.Int) { // -----------Eden calculation --------------------- // -------------------------------------------------------------- @@ -60,7 +60,7 @@ func (k Keeper) CalculateRewardsForStakersByCommitted(ctx sdk.Context, amt sdk.I return newEdenAllocated.TruncateInt(), dexRewards } -// Calculate new Eden-Boost token amounts based on the given conditions and user's current uncommitted token balance +// Calculate new Eden-Boost token amounts based on the given conditions and user's current unclaimed token balance func (k Keeper) CalculateEdenBoostRewards(ctx sdk.Context, delegatedAmt sdk.Int, commitments ctypes.Commitments, epochIdentifier string, edenBoostAPR int64) sdk.Int { // Get eden commitments edenCommitted := commitments.GetCommittedAmountForDenom(ptypes.Eden) diff --git a/x/incentive/keeper/keeper_stakers_test.go b/x/incentive/keeper/keeper_stakers_test.go index c4a03e5ed..b097b1a63 100644 --- a/x/incentive/keeper/keeper_stakers_test.go +++ b/x/incentive/keeper/keeper_stakers_test.go @@ -21,13 +21,13 @@ func TestCalculateRewardsForStakers(t *testing.T) { addr := simapp.AddTestAddrs(app, ctx, 2, sdk.NewInt(10000)) var committed []sdk.Coins - var uncommitted []sdk.Coins + var unclaimed []sdk.Coins - // Prepare uncommitted tokens + // Prepare unclaimed tokens uedenToken := sdk.NewCoins(sdk.NewCoin(ptypes.Eden, sdk.NewInt(2000))) uedenBToken := sdk.NewCoins(sdk.NewCoin(ptypes.EdenB, sdk.NewInt(2000))) - uncommitted = append(uncommitted, uedenToken) - uncommitted = append(uncommitted, uedenBToken) + unclaimed = append(unclaimed, uedenToken) + unclaimed = append(unclaimed, uedenBToken) // Eden err := app.BankKeeper.MintCoins(ctx, ctypes.ModuleName, uedenToken) @@ -80,17 +80,17 @@ func TestCalculateRewardsForStakers(t *testing.T) { require.NoError(t, err) // Add testing commitment - simapp.AddTestCommitment(app, ctx, addr[0], committed, uncommitted) - simapp.AddTestCommitment(app, ctx, addr[1], committed, uncommitted) + simapp.AddTestCommitment(app, ctx, addr[0], committed, unclaimed) + simapp.AddTestCommitment(app, ctx, addr[1], committed, unclaimed) commitment, found := app.CommitmentKeeper.GetCommitments(ctx, addr[0].String()) require.True(t, found) - require.Equal(t, commitment.UncommittedTokens[0].Denom, ptypes.Eden) - require.Equal(t, commitment.UncommittedTokens[0].Amount, sdk.NewInt(2000)) + require.Equal(t, commitment.RewardsUnclaimed[0].Denom, ptypes.Eden) + require.Equal(t, commitment.RewardsUnclaimed[0].Amount, sdk.NewInt(2000)) - require.Equal(t, commitment.UncommittedTokens[1].Denom, ptypes.EdenB) - require.Equal(t, commitment.UncommittedTokens[1].Amount, sdk.NewInt(2000)) + require.Equal(t, commitment.RewardsUnclaimed[1].Denom, ptypes.EdenB) + require.Equal(t, commitment.RewardsUnclaimed[1].Amount, sdk.NewInt(2000)) require.Equal(t, commitment.CommittedTokens[0].Denom, ptypes.Eden) require.Equal(t, commitment.CommittedTokens[0].Amount, sdk.NewInt(1500)) @@ -108,19 +108,19 @@ func TestCalculateRewardsForStakers(t *testing.T) { edenAmountPerEpochStakers := sdk.NewInt(100000) // Calculate delegated amount per delegator delegatedAmt := sdk.NewInt(1000) - // Calculate new uncommitted Eden tokens from Elys staked Eden & Eden boost committed, Dex rewards distribution - newUncommittedEdenTokens, dexRewards, _ := ik.CalculateRewardsForStakersByElysStaked(ctx, delegatedAmt, edenAmountPerEpochStakers, dexRevenueStakersAmt) - totalEdenGiven = totalEdenGiven.Add(newUncommittedEdenTokens) + // Calculate new unclaimed Eden tokens from Elys staked Eden & Eden boost committed, Dex rewards distribution + newUnclaimedEdenTokens, dexRewards, _ := ik.CalculateRewardsForStakersByElysStaked(ctx, delegatedAmt, edenAmountPerEpochStakers, dexRevenueStakersAmt) + totalEdenGiven = totalEdenGiven.Add(newUnclaimedEdenTokens) totalRewardsGiven = totalRewardsGiven.Add(dexRewards) - // Calculate new uncommitted Eden tokens from Eden committed, Dex rewards distribution - newUncommittedEdenTokens, dexRewards = ik.CalculateRewardsForStakersByCommitted(ctx, delegatedAmt, edenAmountPerEpochStakers, dexRevenueStakersAmt) - totalEdenGiven = totalEdenGiven.Add(newUncommittedEdenTokens) + // Calculate new unclaimed Eden tokens from Eden committed, Dex rewards distribution + newUnclaimedEdenTokens, dexRewards = ik.CalculateRewardsForStakersByCommitted(ctx, delegatedAmt, edenAmountPerEpochStakers, dexRevenueStakersAmt) + totalEdenGiven = totalEdenGiven.Add(newUnclaimedEdenTokens) totalRewardsGiven = totalRewardsGiven.Add(dexRewards) - // Calculate new uncommitted Eden tokens from Eden boost committed, Dex rewards distribution - newUncommittedEdenTokens, dexRewards = ik.CalculateRewardsForStakersByCommitted(ctx, delegatedAmt, edenAmountPerEpochStakers, dexRevenueStakersAmt) - totalEdenGiven = totalEdenGiven.Add(newUncommittedEdenTokens) + // Calculate new unclaimed Eden tokens from Eden boost committed, Dex rewards distribution + newUnclaimedEdenTokens, dexRewards = ik.CalculateRewardsForStakersByCommitted(ctx, delegatedAmt, edenAmountPerEpochStakers, dexRevenueStakersAmt) + totalEdenGiven = totalEdenGiven.Add(newUnclaimedEdenTokens) totalRewardsGiven = totalRewardsGiven.Add(dexRewards) require.Equal(t, totalEdenGiven, sdk.NewInt(291)) diff --git a/x/incentive/keeper/keeper_withdraw.go b/x/incentive/keeper/keeper_withdraw.go index 83fa57f03..195a49b1a 100644 --- a/x/incentive/keeper/keeper_withdraw.go +++ b/x/incentive/keeper/keeper_withdraw.go @@ -8,15 +8,15 @@ import ( ptypes "github.com/elys-network/elys/x/parameter/types" ) -// Increase uncommitted token amount for the corresponding validator -func (k Keeper) UpdateTokensForValidator(ctx sdk.Context, validator string, new_uncommitted_eden_tokens sdk.Int, dexRewards sdk.Dec) { +// Increase unclaimed token amount for the corresponding validator +func (k Keeper) UpdateTokensForValidator(ctx sdk.Context, validator string, newUnclaimedEdenTokens sdk.Int, dexRewards sdk.Dec) { commitments, bfound := k.cmk.GetCommitments(ctx, validator) if !bfound { return } // Update Eden amount - k.UpdateTokensCommitment(&commitments, new_uncommitted_eden_tokens, ptypes.Eden) + k.UpdateTokensCommitment(&commitments, newUnclaimedEdenTokens, ptypes.Eden) // Update USDC amount k.UpdateTokensCommitment(&commitments, dexRewards.TruncateInt(), ptypes.BaseCurrency) @@ -26,7 +26,7 @@ func (k Keeper) UpdateTokensForValidator(ctx sdk.Context, validator string, new_ } // Give commissions to validators -func (k Keeper) GiveCommissionToValidators(ctx sdk.Context, delegator string, totalDelegationAmt sdk.Int, newUncommittedAmt sdk.Int, dexRewards sdk.Dec) (sdk.Int, sdk.Int) { +func (k Keeper) GiveCommissionToValidators(ctx sdk.Context, delegator string, totalDelegationAmt sdk.Int, newUnclaimedAmt sdk.Int, dexRewards sdk.Dec) (sdk.Int, sdk.Int) { delAdr, err := sdk.AccAddressFromBech32(delegator) if err != nil { return sdk.ZeroInt(), sdk.ZeroInt() @@ -57,7 +57,7 @@ func (k Keeper) GiveCommissionToValidators(ctx sdk.Context, delegator string, to // Eden commission //----------------------------- // to give = delegated amount / total delegation * newly minted eden * commission rate - edenCommission := delegatedAmt.QuoInt(totalDelegationAmt).MulInt(newUncommittedAmt).Mul(comm_rate) + edenCommission := delegatedAmt.QuoInt(totalDelegationAmt).MulInt(newUnclaimedAmt).Mul(comm_rate) // Sum total commission given totalEdenGiven = totalEdenGiven.Add(edenCommission.TruncateInt()) @@ -97,10 +97,10 @@ func (k Keeper) ProcessWithdrawRewards(ctx sdk.Context, delegator string, denom // Eden if denom == ptypes.Eden { - uncommittedEden, bfound := commitments.GetUncommittedTokensForDenom(ptypes.Eden) + unclaimedEden, bfound := commitments.GetRewardsUnclaimedForDenom(ptypes.Eden) if bfound { // Withdraw Eden - return k.cmk.ProcessWithdrawTokens(ctx, delegator, ptypes.Eden, uncommittedEden.Amount) + return k.cmk.ProcessWithdrawTokens(ctx, delegator, ptypes.Eden, unclaimedEden.Amount) } return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "balance not available") } @@ -110,7 +110,7 @@ func (k Keeper) ProcessWithdrawRewards(ctx sdk.Context, delegator string, denom } // USDC - uncommittedUsdc, bfound := commitments.GetUncommittedTokensForDenom(ptypes.BaseCurrency) + unclaimedUsdc, bfound := commitments.GetRewardsUnclaimedForDenom(ptypes.BaseCurrency) if bfound { // Get dex revenue wallet revenueCollector := k.authKeeper.GetModuleAccount(ctx, k.dexRevCollectorName) @@ -119,17 +119,17 @@ func (k Keeper) ProcessWithdrawRewards(ctx sdk.Context, delegator string, denom usdcBalance := k.bankKeeper.GetBalance(ctx, revenueCollector.GetAddress(), ptypes.BaseCurrency) // Balance check - if uncommittedUsdc.Amount.GT(usdcBalance.Amount) { - return sdkerrors.Wrapf(types.ErrIntOverflowTx, "Amount excceed: %d", uncommittedUsdc.Amount) + if unclaimedUsdc.Amount.GT(usdcBalance.Amount) { + return sdkerrors.Wrapf(types.ErrIntOverflowTx, "Amount excceed: %d", unclaimedUsdc.Amount) } // All dex rewards are only paid in USDC // TODO: // USDC denom is still dummy until we have real USDC in our chain. // This function call will deduct the accounting in commitment module only. - err = k.cmk.ProcessWithdrawUSDC(ctx, delegator, ptypes.BaseCurrency, uncommittedUsdc.Amount) + err = k.cmk.ProcessWithdrawUSDC(ctx, delegator, ptypes.BaseCurrency, unclaimedUsdc.Amount) if err != nil { - return sdkerrors.Wrapf(types.ErrIntOverflowTx, "Internal error with amount: %d", uncommittedUsdc.Amount) + return sdkerrors.Wrapf(types.ErrIntOverflowTx, "Internal error with amount: %d", unclaimedUsdc.Amount) } // Get Bech32 address for creator @@ -141,7 +141,7 @@ func (k Keeper) ProcessWithdrawRewards(ctx sdk.Context, delegator string, denom // Set withdraw usdc amount // TODO // USDC denom is still dummy - revenue := sdk.NewCoin(ptypes.BaseCurrency, uncommittedUsdc.Amount) + revenue := sdk.NewCoin(ptypes.BaseCurrency, unclaimedUsdc.Amount) // Transfer revenue from a single wallet of DEX revenue wallet to user. err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, k.dexRevCollectorName, addr, sdk.NewCoins(revenue)) if err != nil { @@ -176,10 +176,10 @@ func (k Keeper) ProcessWithdrawValidatorCommission(ctx sdk.Context, delegator st // Eden if denom == ptypes.Eden { - uncommittedEden, bfound := commitments.GetUncommittedTokensForDenom(ptypes.Eden) + unclaimedEden, bfound := commitments.GetRewardsUnclaimedForDenom(ptypes.Eden) if bfound { // Withdraw Eden - return k.cmk.ProcessWithdrawValidatorCommission(ctx, delegator, validator, ptypes.Eden, uncommittedEden.Amount) + return k.cmk.ProcessWithdrawValidatorCommission(ctx, delegator, validator, ptypes.Eden, unclaimedEden.Amount) } return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "balance not available") } @@ -189,7 +189,7 @@ func (k Keeper) ProcessWithdrawValidatorCommission(ctx sdk.Context, delegator st } // USDC - uncommittedUsdc, bfound := commitments.GetUncommittedTokensForDenom(ptypes.BaseCurrency) + unclaimedUsdc, bfound := commitments.GetRewardsUnclaimedForDenom(ptypes.BaseCurrency) if bfound { // Get dex revenue wallet revenueCollector := k.authKeeper.GetModuleAccount(ctx, k.dexRevCollectorName) @@ -198,16 +198,16 @@ func (k Keeper) ProcessWithdrawValidatorCommission(ctx sdk.Context, delegator st usdcBalance := k.bankKeeper.GetBalance(ctx, revenueCollector.GetAddress(), ptypes.BaseCurrency) // Balance check - if uncommittedUsdc.Amount.GT(usdcBalance.Amount) { - return sdkerrors.Wrapf(types.ErrIntOverflowTx, "Amount excceed: %d", uncommittedUsdc.Amount) + if unclaimedUsdc.Amount.GT(usdcBalance.Amount) { + return sdkerrors.Wrapf(types.ErrIntOverflowTx, "Amount excceed: %d", unclaimedUsdc.Amount) } // TODO: // USDC denom is still dummy until we have real USDC in our chain. // This function call will deduct the accounting in commitment module only. - err = k.cmk.ProcessWithdrawUSDC(ctx, validator, ptypes.BaseCurrency, uncommittedUsdc.Amount) + err = k.cmk.ProcessWithdrawUSDC(ctx, validator, ptypes.BaseCurrency, unclaimedUsdc.Amount) if err != nil { - return sdkerrors.Wrapf(types.ErrIntOverflowTx, "Internal error with amount: %d", uncommittedUsdc.Amount) + return sdkerrors.Wrapf(types.ErrIntOverflowTx, "Internal error with amount: %d", unclaimedUsdc.Amount) } // Get Bech32 address for delegator @@ -219,7 +219,7 @@ func (k Keeper) ProcessWithdrawValidatorCommission(ctx sdk.Context, delegator st // Set withdraw usdc amount // TODO // USDC denom is still dummy - revenue := sdk.NewCoin(ptypes.BaseCurrency, uncommittedUsdc.Amount) + revenue := sdk.NewCoin(ptypes.BaseCurrency, unclaimedUsdc.Amount) // Transfer revenue from a single wallet of DEX revenue wallet to user's wallet. err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, k.dexRevCollectorName, addr, sdk.NewCoins(revenue)) if err != nil { diff --git a/x/incentive/keeper/keeper_withdraw_test.go b/x/incentive/keeper/keeper_withdraw_test.go index 1a8f028dc..8315805d9 100644 --- a/x/incentive/keeper/keeper_withdraw_test.go +++ b/x/incentive/keeper/keeper_withdraw_test.go @@ -28,10 +28,10 @@ func TestGiveCommissionToValidators(t *testing.T) { delegator := genAccount.String() // Calculate delegated amount per delegator delegatedAmt := ik.CalculateDelegatedAmount(ctx, delegator) - newUncommittedEdenTokens := sdk.NewInt(10000) + newUnclaimedEdenTokens := sdk.NewInt(10000) dexRewardsByStakers := sdk.NewDec(1000) // Give commission to validators ( Eden from stakers and Dex rewards from stakers. ) - edenCommissionGiven, dexRewardsCommissionGiven := ik.GiveCommissionToValidators(ctx, delegator, delegatedAmt, newUncommittedEdenTokens, dexRewardsByStakers) + edenCommissionGiven, dexRewardsCommissionGiven := ik.GiveCommissionToValidators(ctx, delegator, delegatedAmt, newUnclaimedEdenTokens, dexRewardsByStakers) require.Equal(t, edenCommissionGiven, sdk.NewInt(500)) require.Equal(t, dexRewardsCommissionGiven, sdk.NewInt(50)) @@ -47,18 +47,18 @@ func TestProcessWithdrawRewards(t *testing.T) { addr := simapp.AddTestAddrs(app, ctx, 2, sdk.NewInt(10000)) var committed []sdk.Coins - var uncommitted []sdk.Coins + var unclaimed []sdk.Coins - // Prepare uncommitted tokens + // Prepare unclaimed tokens uedenToken := sdk.NewCoins(sdk.NewCoin(ptypes.Eden, sdk.NewInt(2000))) uedenBToken := sdk.NewCoins(sdk.NewCoin(ptypes.EdenB, sdk.NewInt(2000))) lpToken := sdk.NewCoins(sdk.NewCoin("lp-elys-usdc", sdk.NewInt(500))) usdcToken := sdk.NewCoins(sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(500))) - uncommitted = append(uncommitted, uedenToken) - uncommitted = append(uncommitted, uedenBToken) - uncommitted = append(uncommitted, lpToken) - uncommitted = append(uncommitted, usdcToken) + unclaimed = append(unclaimed, uedenToken) + unclaimed = append(unclaimed, uedenBToken) + unclaimed = append(unclaimed, lpToken) + unclaimed = append(unclaimed, usdcToken) // Set assetprofile entry for denom app.AssetprofileKeeper.SetEntry(ctx, aptypes.Entry{BaseDenom: ptypes.BaseCurrency, CommitEnabled: false, WithdrawEnabled: true}) @@ -73,8 +73,8 @@ func TestProcessWithdrawRewards(t *testing.T) { committed = append(committed, uedenBTokenC) // Add testing commitment - simapp.AddTestCommitment(app, ctx, addr[0], committed, uncommitted) - simapp.AddTestCommitment(app, ctx, addr[1], committed, uncommitted) + simapp.AddTestCommitment(app, ctx, addr[0], committed, unclaimed) + simapp.AddTestCommitment(app, ctx, addr[1], committed, unclaimed) _, found := app.CommitmentKeeper.GetCommitments(ctx, addr[0].String()) require.True(t, found) @@ -127,7 +127,7 @@ func TestProcessWithdrawValidatorCommission(t *testing.T) { delegator := genAccount.String() // Calculate delegated amount per delegator delegatedAmt := ik.CalculateDelegatedAmount(ctx, delegator) - newUncommittedEdenTokens := sdk.NewInt(10000) + newUnclaimedEdenTokens := sdk.NewInt(10000) dexRewardsByStakers := sdk.NewDec(1000) // Create an entity in commitment module for validator @@ -139,7 +139,7 @@ func TestProcessWithdrawValidatorCommission(t *testing.T) { app.AssetprofileKeeper.SetEntry(ctx, aptypes.Entry{BaseDenom: ptypes.EdenB, CommitEnabled: true, WithdrawEnabled: true}) // Give commission to validators ( Eden from stakers and Dex rewards from stakers. ) - edenCommissionGiven, dexRewardsCommissionGiven := ik.GiveCommissionToValidators(ctx, delegator, delegatedAmt, newUncommittedEdenTokens, dexRewardsByStakers) + edenCommissionGiven, dexRewardsCommissionGiven := ik.GiveCommissionToValidators(ctx, delegator, delegatedAmt, newUnclaimedEdenTokens, dexRewardsByStakers) _, found := app.CommitmentKeeper.GetCommitments(ctx, valAddress.String()) require.True(t, found) diff --git a/x/incentive/spec/01_concepts.md b/x/incentive/spec/01_concepts.md index 16883c1df..e3de04702 100644 --- a/x/incentive/spec/01_concepts.md +++ b/x/incentive/spec/01_concepts.md @@ -4,15 +4,18 @@ order: 1 # Concepts -The Incentive module is designed to reward the ecosystem participants including liquidity providers (LPs), Elys stakers, and Eden committers. We have 2 kinds of rewards in Elys ecosystem - inflationary reward and non-inflationary rewards. +The Incentive module is designed to reward the ecosystem participants including liquidity providers (LPs), Elys stakers, and Eden committers. We have 2 kinds of rewards in Elys ecosystem - inflationary reward and non-inflationary rewards. 1. Inflationary rewards -- Given the amount in each epoch, incentive module distribute it to stakers and LPs by increasing uncommitted token balances periodically. It utilizes the commitment module and updates accounting for both Eden tokens and Eden-Boost tokens of each Elys staker and LP. + +- Given the amount in each epoch, incentive module distribute it to stakers and LPs by increasing unclaimed rewards balances periodically. It utilizes the commitment module and updates accounting for both Eden tokens and Eden-Boost tokens of each Elys staker and LP. 2. Non-inflationary rewards + - Fees that are collected from amm, margin and transaction gas fees. 3. Functions + - Distribute inflationary rewards and non-inflationary rewards to stakers and LPs. - It distributes Eden and Eden boost tokens as inflationary rewards. - It distributes only USDC as non-inflationary rewards. Fees collected from different parts will be converted into USDC using amm module.