Skip to content

Commit

Permalink
remove mentions of bindings for creating the market. (#1757)
Browse files Browse the repository at this point in the history
Co-authored-by: Unique-Divine <[email protected]>
  • Loading branch information
jgimeno and Unique-Divine authored Jan 2, 2024
1 parent 67b889a commit c2a96d5
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 151 deletions.
8 changes: 0 additions & 8 deletions wasmbinding/bindings/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type NibiruMsg struct {
// bindings-perp ExecuteMsg enum types
// MultiLiquidate *MultiLiquidate `json:"multi_liquidate,omitempty"` // TODO
SetMarketEnabled *SetMarketEnabled `json:"set_market_enabled,omitempty"`
CreateMarket *CreateMarket `json:"create_market,omitempty"`

EditOracleParams *EditOracleParams `json:"edit_oracle_params,omitempty"`

Expand All @@ -41,13 +40,6 @@ type SetMarketEnabled struct {
Enabled bool `json:"enabled"`
}

type CreateMarket struct {
Pair string `json:"pair"`
PegMult sdk.Dec `json:"peg_mult,omitempty"`
SqrtDepth sdk.Dec `json:"sqrt_depth,omitempty"`
MarketParams *MarketParams `json:"market_params,omitempty"`
}

type MarketParams struct {
Pair string
Enabled bool `json:"enabled,omitempty"`
Expand Down
45 changes: 0 additions & 45 deletions wasmbinding/exec_perp.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package wasmbinding

import (
"time"

wasmvmtypes "github.com/CosmWasm/wasmvm/types"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -35,46 +33,3 @@ func (exec *ExecutorPerp) SetMarketEnabled(

return exec.PerpV2.Sudo().CloseMarket(ctx, pair)
}

func (exec *ExecutorPerp) CreateMarket(
cwMsg *bindings.CreateMarket, ctx sdk.Context,
) (err error) {
if cwMsg == nil {
return wasmvmtypes.InvalidRequest{Err: "null msg"}
}

pair, err := asset.TryNewPair(cwMsg.Pair)
if err != nil {
return err
}

var market perpv2types.Market
if cwMsg.MarketParams == nil {
market = perpv2types.DefaultMarket(pair)
} else {
mp := cwMsg.MarketParams
market = perpv2types.Market{
Pair: pair,
Enabled: true,
MaintenanceMarginRatio: mp.MaintenanceMarginRatio,
MaxLeverage: mp.MaxLeverage,
LatestCumulativePremiumFraction: mp.LatestCumulativePremiumFraction,
ExchangeFeeRatio: mp.ExchangeFeeRatio,
EcosystemFundFeeRatio: mp.EcosystemFundFeeRatio,
LiquidationFeeRatio: mp.LiquidationFeeRatio,
PartialLiquidationRatio: mp.PartialLiquidationRatio,
FundingRateEpochId: mp.FundingRateEpochId,
MaxFundingRate: mp.MaxFundingRate,
TwapLookbackWindow: time.Duration(mp.TwapLookbackWindow.Int64()),
PrepaidBadDebt: sdk.NewCoin(pair.QuoteDenom(), sdk.ZeroInt()),
OraclePair: asset.MustNewPair(mp.OraclePair),
}
}

return exec.PerpV2.Sudo().CreateMarket(ctx, perpv2keeper.ArgsCreateMarket{
Pair: pair,
PriceMultiplier: cwMsg.PegMult,
SqrtDepth: cwMsg.SqrtDepth,
Market: &market,
})
}
48 changes: 0 additions & 48 deletions wasmbinding/exec_perp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,52 +131,6 @@ func (s *TestSuitePerpExecutor) OnSetupEnd() {
s.ratesMap = SetExchangeRates(&s.Suite, s.nibiru, s.ctx)
}

// Happy path coverage
func (s *TestSuitePerpExecutor) TestPerpExecutorHappy() {
for _, err := range []error{
s.DoCreateMarketTest(asset.MustNewPair("ufoo:ubar")),
s.DoCreateMarketTestWithParams(asset.MustNewPair("ufoo2:ubar")),
} {
s.NoError(err)
}
}

func (s *TestSuitePerpExecutor) DoCreateMarketTest(pair asset.Pair) error {
cwMsg := &bindings.CreateMarket{
Pair: pair.String(),
PegMult: sdk.NewDec(2_500),
SqrtDepth: sdk.NewDec(1_000),
MarketParams: nil,
}

return s.exec.CreateMarket(cwMsg, s.ctx)
}

func (s *TestSuitePerpExecutor) DoCreateMarketTestWithParams(pair asset.Pair) error {
cwMsg := &bindings.CreateMarket{
Pair: pair.String(),
PegMult: sdk.NewDec(2_500),
SqrtDepth: sdk.NewDec(1_000),
MarketParams: &bindings.MarketParams{
Pair: pair.String(),
Enabled: true,
MaintenanceMarginRatio: sdk.OneDec(),
MaxLeverage: sdk.OneDec(),
LatestCumulativePremiumFraction: sdk.OneDec(),
ExchangeFeeRatio: sdk.OneDec(),
EcosystemFundFeeRatio: sdk.OneDec(),
LiquidationFeeRatio: sdk.OneDec(),
PartialLiquidationRatio: sdk.OneDec(),
FundingRateEpochId: "hi",
MaxFundingRate: sdk.OneDec(),
TwapLookbackWindow: sdk.OneInt(),
OraclePair: pair.String(),
},
}

return s.exec.CreateMarket(cwMsg, s.ctx)
}

func (s *TestSuitePerpExecutor) DoSetMarketEnabledTest(
pair asset.Pair, enabled bool,
) error {
Expand All @@ -202,8 +156,6 @@ func (s *TestSuitePerpExecutor) TestSadPaths_InvalidPair() {
for _, err := range []error{
s.DoSetMarketEnabledTest(pair, true),
s.DoSetMarketEnabledTest(pair, false),
s.DoCreateMarketTest(pair),
s.DoCreateMarketTestWithParams(pair),
} {
s.Error(err)
}
Expand Down
42 changes: 0 additions & 42 deletions wasmbinding/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,45 +355,3 @@ func (s *TestSuiteExecutor) TestSetMarketEnabled() {
s.Errorf(err, "contractRespBz: %s", contractRespBz)
s.Contains(err.Error(), "Error parsing into type")
}

func (s *TestSuiteExecutor) TestCreateMarket() {
contract := s.contractController
pair := asset.MustNewPair("bloop:blam")
execMsg := bindings.NibiruMsg{
CreateMarket: &bindings.CreateMarket{
Pair: pair.String(),
PegMult: sdk.NewDec(420),
SqrtDepth: sdk.NewDec(1_000),
MarketParams: nil,
},
}

s.T().Logf("Execute - happy: market: %s", pair)
s.keeper.SetSudoContracts(
[]string{contract.String()}, s.ctx,
)
contractRespBz, err := s.ExecuteAgainstContract(contract, execMsg)
s.NoErrorf(err, "contractRespBz: %s", contractRespBz)

market, err := s.nibiru.PerpKeeperV2.GetMarket(s.ctx, pair)
s.NoError(err)
s.NoError(market.Validate())
s.False(market.Enabled, "by default, we create a market in a disabled state")
s.EqualValues(pair, market.Pair)

s.T().Log("Executing without permission should fail")
s.keeper.SetSudoContracts(
[]string{}, s.ctx,
)
contractRespBz, err = s.ExecuteAgainstContract(contract, execMsg)
s.Errorf(err, "contractRespBz: %s", contractRespBz)

s.T().Log("Executing the wrong contract should fail")
contract = s.contractPerp
s.keeper.SetSudoContracts(
[]string{contract.String()}, s.ctx,
)
contractRespBz, err = s.ExecuteAgainstContract(contract, execMsg)
s.Errorf(err, "contractRespBz: %s", contractRespBz)
s.Contains(err.Error(), "Error parsing into type")
}
8 changes: 0 additions & 8 deletions wasmbinding/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ func (messenger *CustomMessenger) DispatchMsg(

switch {
// Perp module | controller
case contractExecuteMsg.ExecuteMsg.CreateMarket != nil:
if err := messenger.Sudo.CheckPermissions(contractAddr, ctx); err != nil {
return events, data, err
}
cwMsg := contractExecuteMsg.ExecuteMsg.CreateMarket
err = messenger.Perp.CreateMarket(cwMsg, ctx)
return events, data, err

case contractExecuteMsg.ExecuteMsg.SetMarketEnabled != nil:
if err := messenger.Sudo.CheckPermissions(contractAddr, ctx); err != nil {
return events, data, err
Expand Down

0 comments on commit c2a96d5

Please sign in to comment.