Skip to content

Commit

Permalink
Commitment updates - vesting, committing, and uncommitting (#211)
Browse files Browse the repository at this point in the history
* chore: update commit ment module to liquid vesting, uncommit to liquid, direct commit

* chore: fix LP token commit

* chore: fix bug in deduct commitment function

---------

Co-authored-by: Cosmic Vagabond <[email protected]>
  • Loading branch information
kenta-elys and cosmic-vagabond authored Oct 5, 2023
1 parent aff786d commit 15cb82a
Show file tree
Hide file tree
Showing 32 changed files with 1,246 additions and 262 deletions.
6 changes: 4 additions & 2 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82479,14 +82479,16 @@ definitions:
type: string
elys.commitment.MsgCancelVestResponse:
type: object
elys.commitment.MsgCommitTokensResponse:
elys.commitment.MsgCommitLiquidTokensResponse:
type: object
elys.commitment.MsgDepositTokensResponse:
elys.commitment.MsgCommitTokensResponse:
type: object
elys.commitment.MsgUncommitTokensResponse:
type: object
elys.commitment.MsgUpdateVestingInfoResponse:
type: object
elys.commitment.MsgVestLiquidResponse:
type: object
elys.commitment.MsgVestNowResponse:
type: object
elys.commitment.MsgVestResponse:
Expand Down
37 changes: 23 additions & 14 deletions proto/elys/commitment/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ 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 DepositTokens (MsgDepositTokens ) returns (MsgDepositTokensResponse );
rpc Vest (MsgVest ) returns (MsgVestResponse );
rpc CancelVest (MsgCancelVest ) returns (MsgCancelVestResponse );
rpc VestNow (MsgVestNow ) returns (MsgVestNowResponse );
rpc UpdateVestingInfo (MsgUpdateVestingInfo) returns (MsgUpdateVestingInfoResponse);
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 );
}
message MsgCommitTokens {
string creator = 1;
Expand All @@ -41,13 +42,13 @@ message MsgWithdrawTokens {

message MsgWithdrawTokensResponse {}

message MsgDepositTokens {
message MsgCommitLiquidTokens {
string creator = 1;
string amount = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
string denom = 3;
}

message MsgDepositTokensResponse {}
message MsgCommitLiquidTokensResponse {}

message MsgVest {
string creator = 1;
Expand All @@ -74,14 +75,22 @@ message MsgVestNow {
message MsgVestNowResponse {}

message MsgUpdateVestingInfo {
string authority = 1;
string authority = 1;
string baseDenom = 2;
string vestingDenom = 3;
string epochIdentifier = 4;
int64 numEpochs = 5;
int64 vestNowFactor = 6;
int64 numMaxVestings = 7;
int64 numEpochs = 5;
int64 vestNowFactor = 6;
int64 numMaxVestings = 7;
}

message MsgUpdateVestingInfoResponse {}

message MsgVestLiquid {
string creator = 1;
string amount = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
string denom = 3;
}

message MsgVestLiquidResponse {}

23 changes: 5 additions & 18 deletions x/amm/keeper/mint_pool_share_to_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,18 @@ func (k Keeper) MintPoolShareToAccount(ctx sdk.Context, pool types.Pool, addr sd
k.apKeeper.SetEntry(ctx, entry)
}

// Deposit and commit LP token minted
// Commit LP token minted
msgServer := commitmentkeeper.NewMsgServerImpl(*k.commitmentKeeper)

// Create a deposit token message
msgDepositToken := &ctypes.MsgDepositTokens{
// Create a commit LP token liquidated message
msgLiquidCommitLPToken := &ctypes.MsgCommitLiquidTokens{
Creator: addr.String(),
Denom: poolShareDenom,
Amount: amount,
}

// Deposit LP token
_, err = msgServer.DepositTokens(sdk.WrapSDKContext(ctx), msgDepositToken)
if err != nil {
return err
}

// Create a commit token message
msgCommitToken := &ctypes.MsgCommitTokens{
Creator: addr.String(),
Denom: poolShareDenom,
Amount: amount,
}

// Commit LP token
_, err = msgServer.CommitTokens(sdk.WrapSDKContext(ctx), msgCommitToken)
// Commit LP token liquidated
_, err = msgServer.CommitLiquidTokens(sdk.WrapSDKContext(ctx), msgLiquidCommitLPToken)
if err != nil {
return err
}
Expand Down
19 changes: 18 additions & 1 deletion x/amm/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion x/commitment/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ func GetTxCmd() *cobra.Command {
}

cmd.AddCommand(CmdCommitTokens())
cmd.AddCommand(CmdCommitLiquidTokens())
cmd.AddCommand(CmdUncommitTokens())
cmd.AddCommand(CmdWithdrawTokens())
cmd.AddCommand(CmdDepositTokens())
cmd.AddCommand(CmdVest())
cmd.AddCommand(CmdCancelVest())
cmd.AddCommand(CmdVestNow())
cmd.AddCommand(CmdUpdateVestingInfo())
cmd.AddCommand(CmdVestLiquid())
// this line is used by starport scaffolding # 1

return cmd
Expand Down
50 changes: 50 additions & 0 deletions x/commitment/client/cli/tx_commit_liquid_tokens.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package cli

import (
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/elys-network/elys/x/commitment/types"
"github.com/spf13/cobra"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

var _ = strconv.Itoa(0)

func CmdCommitLiquidTokens() *cobra.Command {
cmd := &cobra.Command{
Use: "commit-liquid-tokens [amount] [denom]",
Short: "Broadcast message commit-liquid-tokens",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argAmount, found := sdk.NewIntFromString(args[0])
if !found {
return sdkerrors.Wrap(sdkerrors.ErrInvalidType, "cannot convert string to int")
}
argDenom := args[1]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgCommitLiquidTokens(
clientCtx.GetFromAddress().String(),
argAmount,
argDenom,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/elys-network/elys/x/commitment/types"
"github.com/spf13/cobra"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/elys-network/elys/x/commitment/types"
"github.com/spf13/cobra"
)

var _ = strconv.Itoa(0)

func CmdDepositTokens() *cobra.Command {
func CmdVestLiquid() *cobra.Command {
cmd := &cobra.Command{
Use: "deposit-tokens [amount] [denom]",
Short: "Broadcast message deposit-tokens",
Use: "vest-liquid [amount] [denom]",
Short: "Broadcast message vest-liquid",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argAmount, found := sdk.NewIntFromString(args[0])
Expand All @@ -32,7 +31,7 @@ func CmdDepositTokens() *cobra.Command {
return err
}

msg := types.NewMsgDepositTokens(
msg := types.NewMsgVestLiquid(
clientCtx.GetFromAddress().String(),
argAmount,
argDenom,
Expand Down
7 changes: 6 additions & 1 deletion x/commitment/keeper/commitments.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ func (k Keeper) DeductCommitments(ctx sdk.Context, creator string, denom string,
return types.Commitments{}, sdkerrors.Wrapf(types.ErrCommitmentsNotFound, "creator: %s", creator)
}

// if deduction amount is zero
if amount.Equal(sdk.ZeroInt()) {
return commitments, nil
}

// Get user's uncommitted balance
uncommittedToken, found := commitments.GetUncommittedTokensForDenom(denom)
if !found {
return types.Commitments{}, sdkerrors.Wrapf(types.ErrCommitmentsNotFound, "creator: %s", creator)
uncommittedToken = &types.UncommittedTokens{Denom: denom, Amount: sdk.ZeroInt()}
}

requestedAmount := amount
Expand Down
Loading

0 comments on commit 15cb82a

Please sign in to comment.