Skip to content

Commit

Permalink
chore: add guard and use correct address for earn execution
Browse files Browse the repository at this point in the history
  • Loading branch information
kenta-elys committed Nov 30, 2023
1 parent 98f0a27 commit 4016d0e
Show file tree
Hide file tree
Showing 16 changed files with 1,795 additions and 200 deletions.
32 changes: 28 additions & 4 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38324,7 +38324,7 @@ paths:
method

signatures required by gogoproto.
swapFee:
swap_fee:
type: string
discount:
type: string
Expand Down Expand Up @@ -38423,7 +38423,7 @@ paths:
method

signatures required by gogoproto.
swapFee:
swap_fee:
type: string
discount:
type: string
Expand Down Expand Up @@ -83564,7 +83564,7 @@ definitions:

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
swapFee:
swap_fee:
type: string
discount:
type: string
Expand Down Expand Up @@ -83597,7 +83597,7 @@ definitions:

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
swapFee:
swap_fee:
type: string
discount:
type: string
Expand Down Expand Up @@ -85728,6 +85728,18 @@ definitions:
id:
type: string
format: uint64
amount:
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
elys.margin.MsgBrokerOpenResponse:
type: object
properties:
Expand All @@ -85740,6 +85752,18 @@ definitions:
id:
type: string
format: uint64
amount:
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
elys.margin.MsgDewhitelistResponse:
type: object
elys.margin.MsgOpenResponse:
Expand Down
28 changes: 22 additions & 6 deletions proto/elys/commitment/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ message MsgVest {
string denom = 3;
}

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

message MsgVestResponse {}

message MsgCancelVest {
Expand All @@ -86,6 +93,13 @@ message MsgCancelVest {
string denom = 3;
}

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

message MsgCancelVestResponse {}

message MsgVestNow {
Expand Down Expand Up @@ -124,9 +138,10 @@ message MsgClaimRewardsResponse {}

message MsgStake {
string creator = 1;
string amount = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
string asset = 3;
string validator_address = 4;
string address = 2;
string amount = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
string asset = 4;
string validator_address = 5;
}

message MsgStakeResponse {
Expand All @@ -136,9 +151,10 @@ message MsgStakeResponse {

message MsgUnstake {
string creator = 1;
string amount = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
string asset = 3;
string validator_address = 4;
string address = 2;
string amount = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
string asset = 4;
string validator_address = 5;
}

message MsgUnstakeResponse {
Expand Down
34 changes: 30 additions & 4 deletions proto/elys/incentive/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package elys.incentive;
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "elys/commitment/params.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/elys-network/elys/x/incentive/types";

Expand All @@ -25,8 +26,9 @@ service Msg {
message MsgWithdrawRewards {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
elys.commitment.EarnType withdraw_type = 2;
string creator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string delegator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
elys.commitment.EarnType withdraw_type = 3;
}

// MsgWithdrawDelegatorRewardResponse defines the Msg/WithdrawDelegatorReward response type.
Expand All @@ -37,8 +39,9 @@ message MsgWithdrawRewardsResponse {}
message MsgWithdrawValidatorCommission {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string creator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string delegator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string validator_address = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgWithdrawValidatorCommissionResponse defines the Msg/WithdrawValidatorCommission response type.
Expand Down Expand Up @@ -70,3 +73,26 @@ message MsgUpdateIncentiveParams {

message MsgUpdateIncentiveParamsResponse {}

message MsgBeginRedelegate {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string creator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string delegator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string validator_src_address = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string validator_dst_address = 4 [(cosmos_proto.scalar) = "cosmos.AddressString"];
cosmos.base.v1beta1.Coin amount = 5 [(gogoproto.nullable) = false];
}

message MsgCancelUnbondingDelegation{
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string creator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string delegator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string validator_address = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// amount is always less than or equal to unbonding delegation entry balance
cosmos.base.v1beta1.Coin amount = 4 [(gogoproto.nullable) = false];
// creation_height is the height which the unbonding took place.
int64 creation_height = 5;
}
9 changes: 4 additions & 5 deletions wasmbindings/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
accountedpoolkeeper "github.com/elys-network/elys/x/accountedpool/keeper"
accountedpooltypes "github.com/elys-network/elys/x/accountedpool/types"
ammkeeper "github.com/elys-network/elys/x/amm/keeper"
Expand Down Expand Up @@ -263,19 +262,19 @@ type ElysMsg struct {
CommitmentCommitLiquidTokens *commitmenttypes.MsgCommitLiquidTokens `json:"commitment_commit_liquid_tokens,omitempty"`
CommitmentCommitUnclaimedRewards *commitmenttypes.MsgCommitClaimedRewards `json:"commitment_commit_unclaimed_rewards,omitempty"`
CommitmentUncommitTokens *commitmenttypes.MsgUncommitTokens `json:"commitment_uncommit_tokens,omitempty"`
CommitmentVest *commitmenttypes.MsgVest `json:"commitment_vest"`
CommitmentVest *commitmenttypes.MsgVestCW `json:"commitment_vest"`
CommitmentVestNow *commitmenttypes.MsgVestNow `json:"commitment_vest_now"`
CommitmentVestLiquid *commitmenttypes.MsgVestLiquid `json:"commitment_vest_liquid"`
CommitmentCancelVest *commitmenttypes.MsgCancelVest `json:"commitment_cancel_vest"`
CommitmentCancelVest *commitmenttypes.MsgCancelVestCW `json:"commitment_cancel_vest"`
CommitmentUpdateVestingInfo *commitmenttypes.MsgUpdateVestingInfo `json:"commitment_update_vesting_info"`
CommitmentStake *commitmenttypes.MsgStake `json:"commitment_stake,omitempty"`
CommitmentUnstake *commitmenttypes.MsgUnstake `json:"commitment_unstake,omitempty"`

// epochs messages

// incentive messages
IncentiveBeginRedelegate *stakingtypes.MsgBeginRedelegate `json:"incentive_begin_redelegate,omitempty"`
IncentiveCancelUnbondingDelegation *stakingtypes.MsgCancelUnbondingDelegation `json:"incentive_cancel_unbonding_delegation"`
IncentiveBeginRedelegate *incentivetypes.MsgBeginRedelegate `json:"incentive_begin_redelegate,omitempty"`
IncentiveCancelUnbondingDelegation *incentivetypes.MsgCancelUnbondingDelegation `json:"incentive_cancel_unbonding_delegation"`
IncentiveWithdrawRewards *incentivetypes.MsgWithdrawRewards `json:"incentive_withdraw_rewards"`
IncentiveWithdrawValidatorCommission *incentivetypes.MsgWithdrawValidatorCommission `json:"incentive_withdraw_validator_commission"`

Expand Down
6 changes: 3 additions & 3 deletions x/commitment/client/wasm/msg_cancel_vest.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
paramtypes "github.com/elys-network/elys/x/parameter/types"
)

func (m *Messenger) msgCancelVest(ctx sdk.Context, contractAddr sdk.AccAddress, msgCancelVest *commitmenttypes.MsgCancelVest) ([]sdk.Event, [][]byte, error) {
func (m *Messenger) msgCancelVest(ctx sdk.Context, contractAddr sdk.AccAddress, msgCancelVest *commitmenttypes.MsgCancelVestCW) ([]sdk.Event, [][]byte, error) {
if msgCancelVest == nil {
return nil, nil, wasmvmtypes.InvalidRequest{Err: "cancel vest null msg"}
}
Expand Down Expand Up @@ -42,13 +42,13 @@ func (m *Messenger) msgCancelVest(ctx sdk.Context, contractAddr sdk.AccAddress,
return nil, resp, nil
}

func performMsgCancelVestEden(f *commitmentkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, msgCancelVest *commitmenttypes.MsgCancelVest) (*wasmbindingstypes.RequestResponse, error) {
func performMsgCancelVestEden(f *commitmentkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, msgCancelVest *commitmenttypes.MsgCancelVestCW) (*wasmbindingstypes.RequestResponse, error) {
if msgCancelVest == nil {
return nil, wasmvmtypes.InvalidRequest{Err: "Invalid cancel vesting parameter"}
}

msgServer := commitmentkeeper.NewMsgServerImpl(*f)
msgMsgCancelVest := commitmenttypes.NewMsgCancelVest(msgCancelVest.Creator, msgCancelVest.Amount, msgCancelVest.Denom)
msgMsgCancelVest := commitmenttypes.NewMsgCancelVest(msgCancelVest.Address, msgCancelVest.Amount, msgCancelVest.Denom)

if err := msgMsgCancelVest.ValidateBasic(); err != nil {
return nil, errorsmod.Wrap(err, "failed validating msgMsgCancelVest")
Expand Down
4 changes: 2 additions & 2 deletions x/commitment/client/wasm/msg_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (m *Messenger) msgStake(ctx sdk.Context, contractAddr sdk.AccAddress, msgSt
// USDC
if msgStake.Asset == baseCurrency {
msgServer := stablekeeper.NewMsgServerImpl(*m.stableKeeper)
msgMsgBond := stabletypes.NewMsgBond(msgStake.Creator, msgStake.Amount)
msgMsgBond := stabletypes.NewMsgBond(msgStake.Address, msgStake.Amount)

if err = msgMsgBond.ValidateBasic(); err != nil {
return nil, nil, errorsmod.Wrap(err, "failed validating msgMsgBond")
Expand All @@ -50,7 +50,7 @@ func (m *Messenger) msgStake(ctx sdk.Context, contractAddr sdk.AccAddress, msgSt
} else {
// Elys, Eden, Eden Boost
msgServer := commitmentkeeper.NewMsgServerImpl(*m.keeper)
msgMsgStake := commitmenttypes.NewMsgStake(msgStake.Creator, msgStake.Amount, msgStake.Asset, msgStake.ValidatorAddress)
msgMsgStake := commitmenttypes.NewMsgStake(msgStake.Address, msgStake.Amount, msgStake.Asset, msgStake.ValidatorAddress)

if err = msgMsgStake.ValidateBasic(); err != nil {
return nil, nil, errorsmod.Wrap(err, "failed validating msgMsgStake")
Expand Down
4 changes: 2 additions & 2 deletions x/commitment/client/wasm/msg_unstake.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (m *Messenger) msgUnstake(ctx sdk.Context, contractAddr sdk.AccAddress, msg
// USDC
if msgUnstake.Asset == baseCurrency {
msgServer := stablekeeper.NewMsgServerImpl(*m.stableKeeper)
msgMsgUnBond := stabletypes.NewMsgUnbond(msgUnstake.Creator, msgUnstake.Amount)
msgMsgUnBond := stabletypes.NewMsgUnbond(msgUnstake.Address, msgUnstake.Amount)

if err = msgMsgUnBond.ValidateBasic(); err != nil {
return nil, nil, errorsmod.Wrap(err, "failed validating msgMsgBond")
Expand All @@ -49,7 +49,7 @@ func (m *Messenger) msgUnstake(ctx sdk.Context, contractAddr sdk.AccAddress, msg
}
} else {
msgServer := commitmentkeeper.NewMsgServerImpl(*m.keeper)
msgMsgUnstake := commitmenttypes.NewMsgUnstake(msgUnstake.Creator, msgUnstake.Amount, msgUnstake.Asset, msgUnstake.ValidatorAddress)
msgMsgUnstake := commitmenttypes.NewMsgUnstake(msgUnstake.Address, msgUnstake.Amount, msgUnstake.Asset, msgUnstake.ValidatorAddress)

if err = msgMsgUnstake.ValidateBasic(); err != nil {
return nil, nil, errorsmod.Wrap(err, "failed validating msgMsgUnstake")
Expand Down
6 changes: 3 additions & 3 deletions x/commitment/client/wasm/msg_vest.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
paramtypes "github.com/elys-network/elys/x/parameter/types"
)

func (m *Messenger) msgVest(ctx sdk.Context, contractAddr sdk.AccAddress, msgVest *commitmenttypes.MsgVest) ([]sdk.Event, [][]byte, error) {
func (m *Messenger) msgVest(ctx sdk.Context, contractAddr sdk.AccAddress, msgVest *commitmenttypes.MsgVestCW) ([]sdk.Event, [][]byte, error) {
if msgVest == nil {
return nil, nil, wasmvmtypes.InvalidRequest{Err: "Vest null msg"}
}
Expand Down Expand Up @@ -42,13 +42,13 @@ func (m *Messenger) msgVest(ctx sdk.Context, contractAddr sdk.AccAddress, msgVes
return nil, resp, nil
}

func performMsgVestEden(f *commitmentkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, msgVest *commitmenttypes.MsgVest) (*wasmbindingstypes.RequestResponse, error) {
func performMsgVestEden(f *commitmentkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, msgVest *commitmenttypes.MsgVestCW) (*wasmbindingstypes.RequestResponse, error) {
if msgVest == nil {
return nil, wasmvmtypes.InvalidRequest{Err: "Invalid vesting parameter"}
}

msgServer := commitmentkeeper.NewMsgServerImpl(*f)
msgMsgVest := commitmenttypes.NewMsgVest(msgVest.Creator, msgVest.Amount, msgVest.Denom)
msgMsgVest := commitmenttypes.NewMsgVest(msgVest.Address, msgVest.Amount, msgVest.Denom)

if err := msgMsgVest.ValidateBasic(); err != nil {
return nil, errorsmod.Wrap(err, "failed validating msgVest")
Expand Down
4 changes: 2 additions & 2 deletions x/commitment/keeper/msg_server_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (k msgServer) performStakeElys(ctx sdk.Context, msg *types.MsgStake) error

msgServer := stakingkeeper.NewMsgServerImpl(stakingKeeper)

address, err := sdk.AccAddressFromBech32(msg.Creator)
address, err := sdk.AccAddressFromBech32(msg.Address)
if err != nil {
return errorsmod.Wrap(err, "invalid address")
}
Expand All @@ -63,7 +63,7 @@ func (k msgServer) performStakeElys(ctx sdk.Context, msg *types.MsgStake) error
}

func (k msgServer) performCommit(ctx sdk.Context, msg *types.MsgStake) error {
msgMsgCommit := types.NewMsgCommitClaimedRewards(msg.Creator, msg.Amount, msg.Asset)
msgMsgCommit := types.NewMsgCommitClaimedRewards(msg.Address, msg.Amount, msg.Asset)

if err := msgMsgCommit.ValidateBasic(); err != nil {
return errorsmod.Wrap(err, "failed validating msgMsgCommit")
Expand Down
4 changes: 2 additions & 2 deletions x/commitment/keeper/msg_server_unstake.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (k msgServer) performUnstakeElys(ctx sdk.Context, msg *types.MsgUnstake) er

msgServer := stakingkeeper.NewMsgServerImpl(stakingKeeper)

address, err := sdk.AccAddressFromBech32(msg.Creator)
address, err := sdk.AccAddressFromBech32(msg.Address)
if err != nil {
return errorsmod.Wrap(err, "invalid address")
}
Expand All @@ -64,7 +64,7 @@ func (k msgServer) performUnstakeElys(ctx sdk.Context, msg *types.MsgUnstake) er
}

func (k msgServer) performUncommit(ctx sdk.Context, msg *types.MsgUnstake) error {
msgMsgUncommit := types.NewMsgUncommitTokens(msg.Creator, msg.Amount, msg.Asset)
msgMsgUncommit := types.NewMsgUncommitTokens(msg.Address, msg.Amount, msg.Asset)

if err := msgMsgUncommit.ValidateBasic(); err != nil {
return errorsmod.Wrap(err, "failed validating msgMsgUncommit")
Expand Down
Loading

0 comments on commit 4016d0e

Please sign in to comment.