From 91ff5cfd8ad79ddc34386b69c1df61b662735e1d Mon Sep 17 00:00:00 2001 From: jelysn Date: Fri, 1 Dec 2023 23:37:55 +0800 Subject: [PATCH] update for wasmbinding permission check --- .../client/register_custom_plugins.go | 10 ++++----- wasmbindings/externals/auth/query_accounts.go | 2 +- x/commitment/client/wasm/messenger.go | 21 +++++++++++-------- x/commitment/client/wasm/msg_cancel_vest.go | 5 +++-- .../client/wasm/msg_commit_liquid_tokens.go | 3 ++- .../wasm/msg_commit_unclaimed_rewards.go | 3 ++- x/commitment/client/wasm/msg_stake.go | 7 ++++--- .../client/wasm/msg_uncommit_tokens.go | 3 ++- x/commitment/client/wasm/msg_unstake.go | 7 ++++--- .../client/wasm/msg_update_vesting_info.go | 3 ++- x/commitment/client/wasm/msg_vest.go | 5 +++-- x/commitment/client/wasm/msg_vest_now.go | 3 ++- x/commitment/client/wasm/query_params.go | 2 +- x/incentive/client/wasm/messenger.go | 9 +++++++- .../client/wasm/msg_begin_redelegate.go | 8 ++++++- .../wasm/msg_cancel_unbonding_delegation.go | 8 ++++++- .../client/wasm/msg_withdraw_rewards.go | 7 ++++++- .../wasm/msg_withdraw_validator_commission.go | 7 ++++++- x/leveragelp/client/wasm/messenger.go | 14 ++++++++++--- x/leveragelp/client/wasm/msg_close.go | 5 +++-- x/leveragelp/client/wasm/msg_open.go | 5 +++-- x/margin/client/wasm/messenger.go | 14 ++++++++++--- x/margin/client/wasm/msg_broker_close.go | 5 +++-- x/margin/client/wasm/msg_broker_open.go | 5 +++-- x/margin/client/wasm/msg_close.go | 5 +++-- x/margin/client/wasm/msg_open.go | 5 +++-- x/stablestake/client/wasm/messenger.go | 11 +++++++--- x/stablestake/client/wasm/msg_bond.go | 4 ++-- x/stablestake/client/wasm/msg_unbond.go | 3 ++- 29 files changed, 129 insertions(+), 60 deletions(-) diff --git a/wasmbindings/client/register_custom_plugins.go b/wasmbindings/client/register_custom_plugins.go index f5ae557dc..ae46e16a0 100644 --- a/wasmbindings/client/register_custom_plugins.go +++ b/wasmbindings/client/register_custom_plugins.go @@ -79,19 +79,19 @@ func RegisterCustomPlugins( clockMessenger := clockclientwasm.NewMessenger(clock) commitmentQuerier := commitmentclientwasm.NewQuerier(commitment, staking, epochs) - commitmentMessenger := commitmentclientwasm.NewMessenger(commitment, staking, assetprofile, stablestake) + commitmentMessenger := commitmentclientwasm.NewMessenger(commitment, staking, assetprofile, stablestake, parameter) epochsQuerier := epochsclientwasm.NewQuerier(epochs) epochsMessenger := epochsclientwasm.NewMessenger(epochs) incentiveQuerier := incentiveclientwasm.NewQuerier(incentive, staking) - incentiveMessenger := incentiveclientwasm.NewMessenger(incentive, staking, commitment) + incentiveMessenger := incentiveclientwasm.NewMessenger(incentive, staking, commitment, parameter) leveragelpQuerier := leveragelpclientwasm.NewQuerier(leveragelp) - leveragelpMessenger := leveragelpclientwasm.NewMessenger(leveragelp) + leveragelpMessenger := leveragelpclientwasm.NewMessenger(leveragelp, parameter) marginQuerier := marginclientwasm.NewQuerier(margin) - marginMessenger := marginclientwasm.NewMessenger(margin) + marginMessenger := marginclientwasm.NewMessenger(margin, parameter) oracleQuerier := oracleclientwasm.NewQuerier(oracle) oracleMessenger := oracleclientwasm.NewMessenger(oracle) @@ -100,7 +100,7 @@ func RegisterCustomPlugins( parameterMessenger := parameterclientwasm.NewMessenger(parameter) stablestakeQuerier := stablestakeclientwasm.NewQuerier(stablestake) - stablestakeMessenger := stablestakeclientwasm.NewMessenger(stablestake) + stablestakeMessenger := stablestakeclientwasm.NewMessenger(stablestake, parameter) tokenomicsQuerier := tokenomicsclientwasm.NewQuerier(tokenomics) tokenomicsMessenger := tokenomicsclientwasm.NewMessenger(tokenomics) diff --git a/wasmbindings/externals/auth/query_accounts.go b/wasmbindings/externals/auth/query_accounts.go index 4c4c9c80c..adfd1cffd 100644 --- a/wasmbindings/externals/auth/query_accounts.go +++ b/wasmbindings/externals/auth/query_accounts.go @@ -9,7 +9,7 @@ import ( ) func (oq *Querier) queryAccounts(ctx sdk.Context, req *types.QueryAccountsRequest) ([]byte, error) { - res, err := oq.keeper.Accounts(ctx, req) + res, err := oq.keeper.Accounts(sdk.WrapSDKContext(ctx), req) if err != nil { return nil, errorsmod.Wrap(err, "failed to get accounts") } diff --git a/x/commitment/client/wasm/messenger.go b/x/commitment/client/wasm/messenger.go index fb8ee1f03..230114eb9 100644 --- a/x/commitment/client/wasm/messenger.go +++ b/x/commitment/client/wasm/messenger.go @@ -6,23 +6,26 @@ import ( wasmbindingstypes "github.com/elys-network/elys/wasmbindings/types" apKeeper "github.com/elys-network/elys/x/assetprofile/keeper" "github.com/elys-network/elys/x/commitment/keeper" + parameterkeeper "github.com/elys-network/elys/x/parameter/keeper" stableKeeper "github.com/elys-network/elys/x/stablestake/keeper" ) // Messenger handles messages for the Commitment module. type Messenger struct { - keeper *keeper.Keeper - stakingKeeper *stakingkeeper.Keeper - apKeeper *apKeeper.Keeper - stableKeeper *stableKeeper.Keeper + keeper *keeper.Keeper + stakingKeeper *stakingkeeper.Keeper + apKeeper *apKeeper.Keeper + stableKeeper *stableKeeper.Keeper + parameterKeeper *parameterkeeper.Keeper } -func NewMessenger(keeper *keeper.Keeper, stakingKeeper *stakingkeeper.Keeper, apKeeper *apKeeper.Keeper, stableKeeper *stableKeeper.Keeper) *Messenger { +func NewMessenger(keeper *keeper.Keeper, stakingKeeper *stakingkeeper.Keeper, apKeeper *apKeeper.Keeper, stableKeeper *stableKeeper.Keeper, parameterKeeper *parameterkeeper.Keeper) *Messenger { return &Messenger{ - keeper: keeper, - stakingKeeper: stakingKeeper, - apKeeper: apKeeper, - stableKeeper: stableKeeper, + keeper: keeper, + stakingKeeper: stakingKeeper, + apKeeper: apKeeper, + stableKeeper: stableKeeper, + parameterKeeper: parameterKeeper, } } diff --git a/x/commitment/client/wasm/msg_cancel_vest.go b/x/commitment/client/wasm/msg_cancel_vest.go index 2c842a52e..2948a2ea3 100644 --- a/x/commitment/client/wasm/msg_cancel_vest.go +++ b/x/commitment/client/wasm/msg_cancel_vest.go @@ -17,7 +17,8 @@ func (m *Messenger) msgCancelVest(ctx sdk.Context, contractAddr sdk.AccAddress, return nil, nil, wasmvmtypes.InvalidRequest{Err: "cancel vest null msg"} } - if msgCancelVest.Creator != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msgCancelVest.Creator != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "cancel vest wrong sender"} } @@ -54,7 +55,7 @@ func performMsgCancelVestEden(f *commitmentkeeper.Keeper, ctx sdk.Context, contr return nil, errorsmod.Wrap(err, "failed validating msgMsgCancelVest") } - _, err := msgServer.CancelVest(ctx, msgMsgCancelVest) // Discard the response because it's empty + _, err := msgServer.CancelVest(sdk.WrapSDKContext(ctx), msgMsgCancelVest) // Discard the response because it's empty if err != nil { return nil, errorsmod.Wrap(err, "eden vesting msg") } diff --git a/x/commitment/client/wasm/msg_commit_liquid_tokens.go b/x/commitment/client/wasm/msg_commit_liquid_tokens.go index 8012af2c9..1c945d007 100644 --- a/x/commitment/client/wasm/msg_commit_liquid_tokens.go +++ b/x/commitment/client/wasm/msg_commit_liquid_tokens.go @@ -15,7 +15,8 @@ func (m *Messenger) msgCommitLiquidTokens(ctx sdk.Context, contractAddr sdk.AccA return nil, nil, wasmvmtypes.InvalidRequest{Err: "CommitLiquidTokens null msg"} } - if msg.Creator != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msg.Creator != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "commit liquid tokens wrong sender"} } diff --git a/x/commitment/client/wasm/msg_commit_unclaimed_rewards.go b/x/commitment/client/wasm/msg_commit_unclaimed_rewards.go index df3b24512..d58ee6aa4 100644 --- a/x/commitment/client/wasm/msg_commit_unclaimed_rewards.go +++ b/x/commitment/client/wasm/msg_commit_unclaimed_rewards.go @@ -15,7 +15,8 @@ func (m *Messenger) msgCommitClaimedRewards(ctx sdk.Context, contractAddr sdk.Ac return nil, nil, wasmvmtypes.InvalidRequest{Err: "CommitUnclaimedRewards null msg"} } - if msg.Creator != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msg.Creator != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "commit unclaimed rewards wrong sender"} } diff --git a/x/commitment/client/wasm/msg_stake.go b/x/commitment/client/wasm/msg_stake.go index 682f88a04..d27662e95 100644 --- a/x/commitment/client/wasm/msg_stake.go +++ b/x/commitment/client/wasm/msg_stake.go @@ -18,7 +18,8 @@ func (m *Messenger) msgStake(ctx sdk.Context, contractAddr sdk.AccAddress, msgSt return nil, nil, wasmvmtypes.InvalidRequest{Err: "Invalid staking parameter"} } - if msgStake.Creator != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msgStake.Creator != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "stake wrong sender"} } @@ -39,7 +40,7 @@ func (m *Messenger) msgStake(ctx sdk.Context, contractAddr sdk.AccAddress, msgSt return nil, nil, errorsmod.Wrap(err, "failed validating msgMsgBond") } - _, err = msgServer.Bond(ctx, msgMsgBond) + _, err = msgServer.Bond(sdk.WrapSDKContext(ctx), msgMsgBond) if err != nil { // Discard the response because it's empty return nil, nil, errorsmod.Wrap(err, "usdc staking msg") } @@ -56,7 +57,7 @@ func (m *Messenger) msgStake(ctx sdk.Context, contractAddr sdk.AccAddress, msgSt return nil, nil, errorsmod.Wrap(err, "failed validating msgMsgStake") } - res, err = msgServer.Stake(ctx, msgMsgStake) + res, err = msgServer.Stake(sdk.WrapSDKContext(ctx), msgMsgStake) if err != nil { // Discard the response because it's empty return nil, nil, errorsmod.Wrap(err, "elys staking msg") } diff --git a/x/commitment/client/wasm/msg_uncommit_tokens.go b/x/commitment/client/wasm/msg_uncommit_tokens.go index 650bf70e1..77530e5af 100644 --- a/x/commitment/client/wasm/msg_uncommit_tokens.go +++ b/x/commitment/client/wasm/msg_uncommit_tokens.go @@ -15,7 +15,8 @@ func (m *Messenger) msgUncommitTokens(ctx sdk.Context, contractAddr sdk.AccAddre return nil, nil, wasmvmtypes.InvalidRequest{Err: "UncommitTokens null msg"} } - if msg.Creator != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msg.Creator != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "uncommit tokens wrong sender"} } diff --git a/x/commitment/client/wasm/msg_unstake.go b/x/commitment/client/wasm/msg_unstake.go index 8f35b0753..1c64af3a5 100644 --- a/x/commitment/client/wasm/msg_unstake.go +++ b/x/commitment/client/wasm/msg_unstake.go @@ -18,7 +18,8 @@ func (m *Messenger) msgUnstake(ctx sdk.Context, contractAddr sdk.AccAddress, msg return nil, nil, wasmvmtypes.InvalidRequest{Err: "Invalid unstaking parameter"} } - if msgUnstake.Creator != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msgUnstake.Creator != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "unstake wrong sender"} } @@ -39,7 +40,7 @@ func (m *Messenger) msgUnstake(ctx sdk.Context, contractAddr sdk.AccAddress, msg return nil, nil, errorsmod.Wrap(err, "failed validating msgMsgBond") } - _, err = msgServer.Unbond(ctx, msgMsgUnBond) + _, err = msgServer.Unbond(sdk.WrapSDKContext(ctx), msgMsgUnBond) if err != nil { // Discard the response because it's empty return nil, nil, errorsmod.Wrap(err, "usdc unstaking msg") } @@ -55,7 +56,7 @@ func (m *Messenger) msgUnstake(ctx sdk.Context, contractAddr sdk.AccAddress, msg return nil, nil, errorsmod.Wrap(err, "failed validating msgMsgUnstake") } - res, err = msgServer.Unstake(ctx, msgMsgUnstake) + res, err = msgServer.Unstake(sdk.WrapSDKContext(ctx), msgMsgUnstake) if err != nil { // Discard the response because it's empty return nil, nil, errorsmod.Wrap(err, "elys unstaking msg") } diff --git a/x/commitment/client/wasm/msg_update_vesting_info.go b/x/commitment/client/wasm/msg_update_vesting_info.go index bf2e38719..76425951d 100644 --- a/x/commitment/client/wasm/msg_update_vesting_info.go +++ b/x/commitment/client/wasm/msg_update_vesting_info.go @@ -15,7 +15,8 @@ func (m *Messenger) msgUpdateVestingInfo(ctx sdk.Context, contractAddr sdk.AccAd return nil, nil, wasmvmtypes.InvalidRequest{Err: "UpdateVestingInfo null msg"} } - if msg.Authority != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msg.Authority != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "update vesting info wrong sender"} } diff --git a/x/commitment/client/wasm/msg_vest.go b/x/commitment/client/wasm/msg_vest.go index d50e0b179..51908c36c 100644 --- a/x/commitment/client/wasm/msg_vest.go +++ b/x/commitment/client/wasm/msg_vest.go @@ -17,7 +17,8 @@ func (m *Messenger) msgVest(ctx sdk.Context, contractAddr sdk.AccAddress, msgVes return nil, nil, wasmvmtypes.InvalidRequest{Err: "Vest null msg"} } - if msgVest.Creator != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msgVest.Creator != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "vest wrong sender"} } @@ -54,7 +55,7 @@ func performMsgVestEden(f *commitmentkeeper.Keeper, ctx sdk.Context, contractAdd return nil, errorsmod.Wrap(err, "failed validating msgVest") } - _, err := msgServer.Vest(ctx, msgMsgVest) // Discard the response because it's empty + _, err := msgServer.Vest(sdk.WrapSDKContext(ctx), msgMsgVest) // Discard the response because it's empty if err != nil { return nil, errorsmod.Wrap(err, "eden vesting msg") } diff --git a/x/commitment/client/wasm/msg_vest_now.go b/x/commitment/client/wasm/msg_vest_now.go index 4d89f2321..981d65119 100644 --- a/x/commitment/client/wasm/msg_vest_now.go +++ b/x/commitment/client/wasm/msg_vest_now.go @@ -15,7 +15,8 @@ func (m *Messenger) msgVestNow(ctx sdk.Context, contractAddr sdk.AccAddress, msg return nil, nil, wasmvmtypes.InvalidRequest{Err: "VestNow null msg"} } - if msg.Creator != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msg.Creator != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "vest now wrong sender"} } diff --git a/x/commitment/client/wasm/query_params.go b/x/commitment/client/wasm/query_params.go index 7956f2608..eaf890880 100644 --- a/x/commitment/client/wasm/query_params.go +++ b/x/commitment/client/wasm/query_params.go @@ -9,7 +9,7 @@ import ( ) func (oq *Querier) queryParams(ctx sdk.Context, req *types.QueryParamsRequest) ([]byte, error) { - res, err := oq.keeper.Params(ctx, req) + res, err := oq.keeper.Params(sdk.WrapSDKContext(ctx), req) if err != nil { return nil, errorsmod.Wrap(err, "failed to get params") } diff --git a/x/incentive/client/wasm/messenger.go b/x/incentive/client/wasm/messenger.go index cb191fe49..e178ba820 100644 --- a/x/incentive/client/wasm/messenger.go +++ b/x/incentive/client/wasm/messenger.go @@ -6,6 +6,7 @@ import ( wasmbindingstypes "github.com/elys-network/elys/wasmbindings/types" commitmentkeeper "github.com/elys-network/elys/x/commitment/keeper" "github.com/elys-network/elys/x/incentive/keeper" + parameterkeeper "github.com/elys-network/elys/x/parameter/keeper" ) // Messenger handles messages for the Incentive module. @@ -13,9 +14,15 @@ type Messenger struct { keeper *keeper.Keeper stakingKeeper *stakingkeeper.Keeper commitmentKeeper *commitmentkeeper.Keeper + parameterKeeper *parameterkeeper.Keeper } -func NewMessenger(keeper *keeper.Keeper, stakingKeeper *stakingkeeper.Keeper, commitmentKeeper *commitmentkeeper.Keeper) *Messenger { +func NewMessenger( + keeper *keeper.Keeper, + stakingKeeper *stakingkeeper.Keeper, + commitmentKeeper *commitmentkeeper.Keeper, + parameterKeeper *parameterkeeper.Keeper, +) *Messenger { return &Messenger{ keeper: keeper, stakingKeeper: stakingKeeper, diff --git a/x/incentive/client/wasm/msg_begin_redelegate.go b/x/incentive/client/wasm/msg_begin_redelegate.go index 7d5334483..a599cd6fb 100644 --- a/x/incentive/client/wasm/msg_begin_redelegate.go +++ b/x/incentive/client/wasm/msg_begin_redelegate.go @@ -15,6 +15,12 @@ import ( func (m *Messenger) msgBeginRedelegate(ctx sdk.Context, contractAddr sdk.AccAddress, msgRedelegate *stakingtypes.MsgBeginRedelegate) ([]sdk.Event, [][]byte, error) { var res *wasmbindingstypes.RequestResponse var err error + + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msgRedelegate.DelegatorAddress != contractAddr.String() && contractAddr.String() != brokerAddress { + return nil, nil, wasmvmtypes.InvalidRequest{Err: "wrong sender"} + } + if msgRedelegate.Amount.Denom != paramtypes.Elys { return nil, nil, errorsmod.Wrap(err, "invalid asset!") } @@ -61,7 +67,7 @@ func performMsgRedelegateElys(f *stakingkeeper.Keeper, ctx sdk.Context, contract return nil, errorsmod.Wrap(err, "failed validating msgMsgDelegate") } - _, err = msgServer.BeginRedelegate(ctx, msgMsgRedelegate) // Discard the response because it's empty + _, err = msgServer.BeginRedelegate(sdk.WrapSDKContext(ctx), msgMsgRedelegate) // Discard the response because it's empty if err != nil { return nil, errorsmod.Wrap(err, "elys redelegation msg") } diff --git a/x/incentive/client/wasm/msg_cancel_unbonding_delegation.go b/x/incentive/client/wasm/msg_cancel_unbonding_delegation.go index 97224c389..dd3215a95 100644 --- a/x/incentive/client/wasm/msg_cancel_unbonding_delegation.go +++ b/x/incentive/client/wasm/msg_cancel_unbonding_delegation.go @@ -15,6 +15,12 @@ import ( func (m *Messenger) msgCancelUnbondingDelegation(ctx sdk.Context, contractAddr sdk.AccAddress, msgCancelUnbonding *stakingtypes.MsgCancelUnbondingDelegation) ([]sdk.Event, [][]byte, error) { var res *wasmbindingstypes.RequestResponse var err error + + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msgCancelUnbonding.DelegatorAddress != contractAddr.String() && contractAddr.String() != brokerAddress { + return nil, nil, wasmvmtypes.InvalidRequest{Err: "wrong sender"} + } + if msgCancelUnbonding.Amount.Denom != paramtypes.Elys { return nil, nil, errorsmod.Wrap(err, "invalid asset!") } @@ -56,7 +62,7 @@ func performMsgCancelUnbondingElys(f *stakingkeeper.Keeper, ctx sdk.Context, con return nil, errorsmod.Wrap(err, "failed validating msgCancelUnbonding") } - _, err = msgServer.CancelUnbondingDelegation(ctx, msgMsgCancelUnbonding) + _, err = msgServer.CancelUnbondingDelegation(sdk.WrapSDKContext(ctx), msgMsgCancelUnbonding) if err != nil { return nil, errorsmod.Wrap(err, "elys cancel bonding msg") } diff --git a/x/incentive/client/wasm/msg_withdraw_rewards.go b/x/incentive/client/wasm/msg_withdraw_rewards.go index efd2883f5..8ad483fa8 100644 --- a/x/incentive/client/wasm/msg_withdraw_rewards.go +++ b/x/incentive/client/wasm/msg_withdraw_rewards.go @@ -16,6 +16,11 @@ func (m *Messenger) msgWithdrawRewards(ctx sdk.Context, contractAddr sdk.AccAddr var res *wasmbindingstypes.RequestResponse var err error + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msgWithdrawRewards.DelegatorAddress != contractAddr.String() && contractAddr.String() != brokerAddress { + return nil, nil, wasmvmtypes.InvalidRequest{Err: "wrong sender"} + } + res, err = performMsgWithdrawRewards(m.keeper, ctx, contractAddr, msgWithdrawRewards) if err != nil { return nil, nil, errorsmod.Wrap(err, "perform withdraw rewards") @@ -48,7 +53,7 @@ func performMsgWithdrawRewards(f *incentivekeeper.Keeper, ctx sdk.Context, contr return nil, errorsmod.Wrap(err, "failed validating msgMsgWithdrawRewards") } - _, err = msgServer.WithdrawRewards(ctx, msgMsgWithdrawRewards) // Discard the response because it's empty + _, err = msgServer.WithdrawRewards(sdk.WrapSDKContext(ctx), msgMsgWithdrawRewards) // Discard the response because it's empty if err != nil { return nil, errorsmod.Wrap(err, "withdraw rewards msg") } diff --git a/x/incentive/client/wasm/msg_withdraw_validator_commission.go b/x/incentive/client/wasm/msg_withdraw_validator_commission.go index ac0aafba4..739872f1b 100644 --- a/x/incentive/client/wasm/msg_withdraw_validator_commission.go +++ b/x/incentive/client/wasm/msg_withdraw_validator_commission.go @@ -16,6 +16,11 @@ func (m *Messenger) msgWithdrawValidatorCommission(ctx sdk.Context, contractAddr var res *wasmbindingstypes.RequestResponse var err error + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msgWithdrawValidatorCommission.DelegatorAddress != contractAddr.String() && contractAddr.String() != brokerAddress { + return nil, nil, wasmvmtypes.InvalidRequest{Err: "wrong sender"} + } + res, err = performMsgWithdrawValidatorCommissions(m.keeper, ctx, contractAddr, msgWithdrawValidatorCommission) if err != nil { return nil, nil, errorsmod.Wrap(err, "perform withdraw validator commission") @@ -53,7 +58,7 @@ func performMsgWithdrawValidatorCommissions(f *incentivekeeper.Keeper, ctx sdk.C return nil, errorsmod.Wrap(err, "failed validating msgWithdrawValidatorCommission") } - _, err = msgServer.WithdrawValidatorCommission(ctx, msgMsgWithdrawValidatorCommissions) // Discard the response because it's empty + _, err = msgServer.WithdrawValidatorCommission(sdk.WrapSDKContext(ctx), msgMsgWithdrawValidatorCommissions) // Discard the response because it's empty if err != nil { return nil, errorsmod.Wrap(err, "withdraw validator commission msg") } diff --git a/x/leveragelp/client/wasm/messenger.go b/x/leveragelp/client/wasm/messenger.go index 0b518a818..83aeca293 100644 --- a/x/leveragelp/client/wasm/messenger.go +++ b/x/leveragelp/client/wasm/messenger.go @@ -4,15 +4,23 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" wasmbindingstypes "github.com/elys-network/elys/wasmbindings/types" "github.com/elys-network/elys/x/leveragelp/keeper" + parameterkeeper "github.com/elys-network/elys/x/parameter/keeper" ) // Messenger handles messages for the Leverage LP module. type Messenger struct { - keeper *keeper.Keeper + keeper *keeper.Keeper + parameterKeeper *parameterkeeper.Keeper } -func NewMessenger(keeper *keeper.Keeper) *Messenger { - return &Messenger{keeper: keeper} +func NewMessenger( + keeper *keeper.Keeper, + parameterKeeper *parameterkeeper.Keeper, +) *Messenger { + return &Messenger{ + keeper: keeper, + parameterKeeper: parameterKeeper, + } } func (m *Messenger) HandleMsg(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg wasmbindingstypes.ElysMsg) ([]sdk.Event, [][]byte, error) { diff --git a/x/leveragelp/client/wasm/msg_close.go b/x/leveragelp/client/wasm/msg_close.go index ac9d7d01f..240b2026c 100644 --- a/x/leveragelp/client/wasm/msg_close.go +++ b/x/leveragelp/client/wasm/msg_close.go @@ -15,7 +15,8 @@ func (m *Messenger) msgClose(ctx sdk.Context, contractAddr sdk.AccAddress, msgCl return nil, nil, wasmvmtypes.InvalidRequest{Err: "Close null msg"} } - if msgClose.Creator != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msgClose.Creator != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "close wrong sender"} } @@ -46,7 +47,7 @@ func PerformMsgClose(f *leveragelpkeeper.Keeper, ctx sdk.Context, contractAddr s return nil, errorsmod.Wrap(err, "failed validating msgMsgClose") } - _, err := msgServer.Close(ctx, msgMsgClose) // Discard the response because it's empty + _, err := msgServer.Close(sdk.WrapSDKContext(ctx), msgMsgClose) // Discard the response because it's empty if err != nil { return nil, errorsmod.Wrap(err, "leveragelp close msg") diff --git a/x/leveragelp/client/wasm/msg_open.go b/x/leveragelp/client/wasm/msg_open.go index df9271f3f..1141079f3 100644 --- a/x/leveragelp/client/wasm/msg_open.go +++ b/x/leveragelp/client/wasm/msg_open.go @@ -16,7 +16,8 @@ func (m *Messenger) msgOpen(ctx sdk.Context, contractAddr sdk.AccAddress, msgOpe return nil, nil, wasmvmtypes.InvalidRequest{Err: "Open null msg"} } - if msgOpen.Creator != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msgOpen.Creator != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "open wrong sender"} } @@ -47,7 +48,7 @@ func PerformMsgOpen(f *leveragelpkeeper.Keeper, ctx sdk.Context, contractAddr sd return nil, errorsmod.Wrap(err, "failed validating msgMsgOpen") } - _, err := msgServer.Open(ctx, msgMsgOpen) // Discard the response because it's empty + _, err := msgServer.Open(sdk.WrapSDKContext(ctx), msgMsgOpen) // Discard the response because it's empty if err != nil { return nil, errorsmod.Wrap(err, "leveragelp open msg") diff --git a/x/margin/client/wasm/messenger.go b/x/margin/client/wasm/messenger.go index 86d63ae09..7c06cd1b4 100644 --- a/x/margin/client/wasm/messenger.go +++ b/x/margin/client/wasm/messenger.go @@ -4,15 +4,23 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" wasmbindingstypes "github.com/elys-network/elys/wasmbindings/types" "github.com/elys-network/elys/x/margin/keeper" + parameterkeeper "github.com/elys-network/elys/x/parameter/keeper" ) // Messenger handles messages for the Margin module. type Messenger struct { - keeper *keeper.Keeper + keeper *keeper.Keeper + parameterKeeper *parameterkeeper.Keeper } -func NewMessenger(keeper *keeper.Keeper) *Messenger { - return &Messenger{keeper: keeper} +func NewMessenger( + keeper *keeper.Keeper, + parameterKeeper *parameterkeeper.Keeper, +) *Messenger { + return &Messenger{ + keeper: keeper, + parameterKeeper: parameterKeeper, + } } func (m *Messenger) HandleMsg(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg wasmbindingstypes.ElysMsg) ([]sdk.Event, [][]byte, error) { diff --git a/x/margin/client/wasm/msg_broker_close.go b/x/margin/client/wasm/msg_broker_close.go index 3893696c2..1d43d56fa 100644 --- a/x/margin/client/wasm/msg_broker_close.go +++ b/x/margin/client/wasm/msg_broker_close.go @@ -15,7 +15,8 @@ func (m *Messenger) msgBrokerClose(ctx sdk.Context, contractAddr sdk.AccAddress, return nil, nil, wasmvmtypes.InvalidRequest{Err: "Broker Close null msg"} } - if msgBrokerClose.Creator != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msgBrokerClose.Creator != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "broker close wrong sender"} } @@ -46,7 +47,7 @@ func PerformMsgBrokerClose(f *marginkeeper.Keeper, ctx sdk.Context, contractAddr return nil, errorsmod.Wrap(err, "failed validating msgMsgBrokerClose") } - _, err := msgServer.BrokerClose(ctx, msgMsgBrokerClose) // Discard the response because it's empty + _, err := msgServer.BrokerClose(sdk.WrapSDKContext(ctx), msgMsgBrokerClose) // Discard the response because it's empty if err != nil { return nil, errorsmod.Wrap(err, "margin broker close msg") diff --git a/x/margin/client/wasm/msg_broker_open.go b/x/margin/client/wasm/msg_broker_open.go index b02ac0448..899b53e3e 100644 --- a/x/margin/client/wasm/msg_broker_open.go +++ b/x/margin/client/wasm/msg_broker_open.go @@ -16,7 +16,8 @@ func (m *Messenger) msgBrokerOpen(ctx sdk.Context, contractAddr sdk.AccAddress, return nil, nil, wasmvmtypes.InvalidRequest{Err: "Broker Open null msg"} } - if msgBrokerOpen.Creator != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msgBrokerOpen.Creator != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "broker open wrong sender"} } @@ -47,7 +48,7 @@ func PerformMsgBrokerOpen(f *marginkeeper.Keeper, ctx sdk.Context, contractAddr return nil, errorsmod.Wrap(err, "failed validating msgMsgBrokerOpen") } - _, err := msgServer.BrokerOpen(ctx, msgMsgBrokerOpen) // Discard the response because it's empty + _, err := msgServer.BrokerOpen(sdk.WrapSDKContext(ctx), msgMsgBrokerOpen) // Discard the response because it's empty if err != nil { return nil, errorsmod.Wrap(err, "margin broker open msg") diff --git a/x/margin/client/wasm/msg_close.go b/x/margin/client/wasm/msg_close.go index 163117713..114bb7f3a 100644 --- a/x/margin/client/wasm/msg_close.go +++ b/x/margin/client/wasm/msg_close.go @@ -15,7 +15,8 @@ func (m *Messenger) msgClose(ctx sdk.Context, contractAddr sdk.AccAddress, msgCl return nil, nil, wasmvmtypes.InvalidRequest{Err: "Close null msg"} } - if msgClose.Creator != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msgClose.Creator != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "close wrong sender"} } @@ -46,7 +47,7 @@ func PerformMsgClose(f *marginkeeper.Keeper, ctx sdk.Context, contractAddr sdk.A return nil, errorsmod.Wrap(err, "failed validating msgMsgClose") } - _, err := msgServer.Close(ctx, msgMsgClose) // Discard the response because it's empty + _, err := msgServer.Close(sdk.WrapSDKContext(ctx), msgMsgClose) // Discard the response because it's empty if err != nil { return nil, errorsmod.Wrap(err, "margin close msg") diff --git a/x/margin/client/wasm/msg_open.go b/x/margin/client/wasm/msg_open.go index 0437a8091..8e3cf1ec2 100644 --- a/x/margin/client/wasm/msg_open.go +++ b/x/margin/client/wasm/msg_open.go @@ -16,7 +16,8 @@ func (m *Messenger) msgOpen(ctx sdk.Context, contractAddr sdk.AccAddress, msgOpe return nil, nil, wasmvmtypes.InvalidRequest{Err: "Open null msg"} } - if msgOpen.Creator != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msgOpen.Creator != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "open wrong sender"} } @@ -47,7 +48,7 @@ func PerformMsgOpen(f *marginkeeper.Keeper, ctx sdk.Context, contractAddr sdk.Ac return nil, errorsmod.Wrap(err, "failed validating msgMsgOpen") } - _, err := msgServer.Open(ctx, msgMsgOpen) // Discard the response because it's empty + _, err := msgServer.Open(sdk.WrapSDKContext(ctx), msgMsgOpen) // Discard the response because it's empty if err != nil { return nil, errorsmod.Wrap(err, "margin open msg") diff --git a/x/stablestake/client/wasm/messenger.go b/x/stablestake/client/wasm/messenger.go index 791c9ecb7..042a929e4 100644 --- a/x/stablestake/client/wasm/messenger.go +++ b/x/stablestake/client/wasm/messenger.go @@ -3,16 +3,21 @@ package wasm import ( sdk "github.com/cosmos/cosmos-sdk/types" wasmbindingstypes "github.com/elys-network/elys/wasmbindings/types" + parameterkeeper "github.com/elys-network/elys/x/parameter/keeper" "github.com/elys-network/elys/x/stablestake/keeper" ) // Messenger handles messages for the Stable Stake module. type Messenger struct { - keeper *keeper.Keeper + keeper *keeper.Keeper + parameterKeeper *parameterkeeper.Keeper } -func NewMessenger(keeper *keeper.Keeper) *Messenger { - return &Messenger{keeper: keeper} +func NewMessenger(keeper *keeper.Keeper, parameterKeeper *parameterkeeper.Keeper) *Messenger { + return &Messenger{ + keeper: keeper, + parameterKeeper: parameterKeeper, + } } func (m *Messenger) HandleMsg(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg wasmbindingstypes.ElysMsg) ([]sdk.Event, [][]byte, error) { diff --git a/x/stablestake/client/wasm/msg_bond.go b/x/stablestake/client/wasm/msg_bond.go index 4578207f9..c2f52a7f5 100644 --- a/x/stablestake/client/wasm/msg_bond.go +++ b/x/stablestake/client/wasm/msg_bond.go @@ -14,8 +14,8 @@ func (m *Messenger) msgBond(ctx sdk.Context, contractAddr sdk.AccAddress, msg *t if msg == nil { return nil, nil, wasmvmtypes.InvalidRequest{Err: "Bond null msg"} } - - if msg.Creator != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msg.Creator != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "bond wrong sender"} } diff --git a/x/stablestake/client/wasm/msg_unbond.go b/x/stablestake/client/wasm/msg_unbond.go index 06e84a47a..8d66eb071 100644 --- a/x/stablestake/client/wasm/msg_unbond.go +++ b/x/stablestake/client/wasm/msg_unbond.go @@ -15,7 +15,8 @@ func (m *Messenger) msgUnbond(ctx sdk.Context, contractAddr sdk.AccAddress, msg return nil, nil, wasmvmtypes.InvalidRequest{Err: "Unbond null msg"} } - if msg.Creator != contractAddr.String() { + brokerAddress := m.parameterKeeper.GetParams(ctx).BrokerAddress + if msg.Creator != contractAddr.String() && contractAddr.String() != brokerAddress { return nil, nil, wasmvmtypes.InvalidRequest{Err: "unbond wrong sender"} }