Skip to content

Commit

Permalink
Commitment module enhancement + 1 hr lock addition (#241)
Browse files Browse the repository at this point in the history
commitment module refactoring, 1 hr lock addition, amm module enhancement
  • Loading branch information
jelysn authored Nov 9, 2023
1 parent 7e6cbb6 commit 83d045d
Show file tree
Hide file tree
Showing 63 changed files with 1,269 additions and 755 deletions.
32 changes: 16 additions & 16 deletions app/test_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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))
}

Expand Down
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ genesis:
denom: ueden
- amount: "10000"
denom: uedenb
uncommitted_tokens:
rewards_unclaimed:
- amount: "10000"
denom: uusdc
- amount: "10000"
Expand Down
58 changes: 53 additions & 5 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
53 changes: 31 additions & 22 deletions proto/elys/commitment/commitments.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
5 changes: 0 additions & 5 deletions proto/elys/commitment/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,21 @@ 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.
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];
}
Expand All @@ -42,4 +38,3 @@ message QueryShowCommitmentsRequest {
message QueryShowCommitmentsResponse {
Commitments commitments = 1;
}

35 changes: 24 additions & 11 deletions proto/elys/commitment/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {}
Expand Down
4 changes: 2 additions & 2 deletions x/amm/client/wasm/query_balance_of_denom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions x/amm/keeper/apply_exit_pool_state_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit 83d045d

Please sign in to comment.