From ed1695bb841c8144fe459220996f20aeab243868 Mon Sep 17 00:00:00 2001 From: Walter White <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Tue, 24 May 2022 11:17:27 -0400 Subject: [PATCH] refactor(perp): Refactor perp state proto (#479) * Remove LiquidityHistoryIndex * Refactor position address to sdk.AccAddress type * Remove VirtualPoolInfo proto * Replace string address with sdk.AccAddress --- proto/perp/v1/state.proto | 47 ++- proto/perp/v1/tx.proto | 17 +- x/perp/client/cli/cli.go | 6 +- x/perp/events/events.go | 18 +- x/perp/keeper/calc_test.go | 8 +- x/perp/keeper/calc_unit_test.go | 10 +- x/perp/keeper/clearing_house.go | 31 +- x/perp/keeper/clearing_house_test.go | 310 +++++++-------- x/perp/keeper/liquidate.go | 19 +- x/perp/keeper/liquidate_test.go | 22 +- x/perp/keeper/liquidate_unit_test.go | 18 +- x/perp/keeper/margin.go | 36 +- x/perp/keeper/margin_test.go | 40 +- x/perp/keeper/margin_unit_test.go | 38 +- x/perp/keeper/msg_server.go | 19 +- x/perp/keeper/perp.go | 25 +- x/perp/keeper/perp_test.go | 50 +-- x/perp/keeper/perp_unit_test.go | 36 +- x/perp/keeper/state.go | 14 +- x/perp/types/msgs.go | 15 +- x/perp/types/msgs_test.go | 14 +- x/perp/types/state.pb.go | 571 +++++++-------------------- x/perp/types/tx.pb.go | 184 +++++---- x/perp/types/types.go | 7 +- 24 files changed, 620 insertions(+), 935 deletions(-) diff --git a/proto/perp/v1/state.proto b/proto/perp/v1/state.proto index 11d19b202..ae9fdb3ca 100644 --- a/proto/perp/v1/state.proto +++ b/proto/perp/v1/state.proto @@ -44,28 +44,36 @@ message GenesisState { // the virtual liquidity pools. message Position { // address identifies the address owner of this position - string address = 1; + bytes trader_address = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; + // pair identifies the pair associated with this position string pair = 2; + // Position size. string size = 3 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; // signed int + + // Amount of margin remaining in the position. string margin = 4 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; // OpenNotional is the quote denom value of the position when opening. + // Used to calculate PnL. string open_notional = 5 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + + // The last cumulative funding payment this position has applied. + // Used to calculate the next funding payment. string last_update_cumulative_premium_fraction = 6 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; // int - int64 liquidity_history_index = 7; // BlockNumber is the block number of the change to the position. - int64 block_number = 8; + int64 block_number = 7; } message PositionResp { @@ -94,38 +102,30 @@ message PositionResp { (gogoproto.nullable) = false]; } -message LiquidateResp{ +message LiquidateResp { // Amount of bad debt created by the liquidation event - string bad_debt = 1[ + string bad_debt = 1 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; // Fee paid to the liquidator - string fee_to_liquidator = 2[ + string fee_to_liquidator = 2 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; // Fee paid to the Perp EF fund - string fee_to_perp_ecosystem_fund = 3[ + string fee_to_perp_ecosystem_fund = 3 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; // Address of the liquidator - bytes liquidator = 4[ + bytes liquidator = 4 [ (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; // Position response from the close or open reverse position PositionResp position_resp = 5; } -message VirtualPoolInfo { - string pair = 1; - int64 last_restriction_block = 2; - repeated string cumulative_premium_fractions = 3 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", - (gogoproto.nullable) = false]; -} - enum Side { BUY = 0; SELL = 1; @@ -156,38 +156,51 @@ message PairMetadata { } message PositionChangedEvent { - string trader = 1; + bytes trader_address = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; + string pair = 2; + string margin = 3 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + string position_notional = 4 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + string exchanged_position_size = 5 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + string fee = 6 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false]; + string position_size_after = 7 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + string realized_pnl = 8 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + string unrealized_pnl_after = 9 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + string bad_debt = 10 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + string liquidation_penalty = 11 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + string spot_price = 12 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + string funding_payment = 13 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; diff --git a/proto/perp/v1/tx.proto b/proto/perp/v1/tx.proto index 772fa3554..fae025164 100644 --- a/proto/perp/v1/tx.proto +++ b/proto/perp/v1/tx.proto @@ -36,8 +36,11 @@ service Msg { /* MsgRemoveMargin: Msg to remove margin. */ message MsgRemoveMargin { - string sender = 1; + bytes sender = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; + string token_pair = 2; + cosmos.base.v1beta1.Coin margin = 3 [(gogoproto.nullable) = false]; } @@ -53,7 +56,9 @@ message MsgRemoveMarginResponse { /* MsgAddMargin: Msg to remove margin. */ message MsgAddMargin { - string sender = 1; + bytes sender = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; + string token_pair = 2; cosmos.base.v1beta1.Coin margin = 3 [(gogoproto.nullable) = false]; } @@ -66,7 +71,9 @@ message MsgAddMarginResponse { message MsgLiquidate { // Sender is the liquidator address - string sender = 1; + bytes sender = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; + // TokenPair is the identifier for the position's virtual pool string token_pair = 2; // Trader is the address of the owner of the position @@ -80,7 +87,9 @@ message MsgLiquidate { // -------------------------- OpenPosition -------------------------- message MsgOpenPosition { - string sender = 1; + bytes sender = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; + string token_pair = 2; nibiru.perp.v1.Side side = 3; string quote_asset_amount = 4 [ diff --git a/x/perp/client/cli/cli.go b/x/perp/client/cli/cli.go index 864f7bfe2..80e842165 100644 --- a/x/perp/client/cli/cli.go +++ b/x/perp/client/cli/cli.go @@ -136,7 +136,7 @@ func OpenPositionCmd() *cobra.Command { } msg := &types.MsgOpenPosition{ - Sender: clientCtx.GetFromAddress().String(), + Sender: clientCtx.GetFromAddress(), TokenPair: args[1], Side: side, QuoteAssetAmount: amount, @@ -185,7 +185,7 @@ func RemoveMarginCmd() *cobra.Command { } msg := &types.MsgRemoveMargin{ - Sender: clientCtx.GetFromAddress().String(), + Sender: clientCtx.GetFromAddress(), TokenPair: args[0], Margin: marginToRemove, } @@ -227,7 +227,7 @@ func AddMarginCmd() *cobra.Command { } msg := &types.MsgAddMargin{ - Sender: clientCtx.GetFromAddress().String(), + Sender: clientCtx.GetFromAddress(), TokenPair: args[0], Margin: marginToAdd, } diff --git a/x/perp/events/events.go b/x/perp/events/events.go index 3150390f9..754d8bc09 100644 --- a/x/perp/events/events.go +++ b/x/perp/events/events.go @@ -29,20 +29,20 @@ const ( ) func NewTransferEvent( - coin sdk.Coin, from string, to string, + coin sdk.Coin, from sdk.AccAddress, to sdk.AccAddress, ) sdk.Event { const EventTypeTransfer = "transfer" return sdk.NewEvent( EventTypeTransfer, - sdk.NewAttribute(AttributeFromAddr, from), - sdk.NewAttribute(AttributeToAddr, to), + sdk.NewAttribute(AttributeFromAddr, from.String()), + sdk.NewAttribute(AttributeToAddr, to.String()), sdk.NewAttribute(AttributeTokenDenom, coin.Denom), sdk.NewAttribute(AttributeTokenAmount, coin.Amount.String()), ) } func EmitTransfer( - ctx sdk.Context, coin sdk.Coin, from string, to string, + ctx sdk.Context, coin sdk.Coin, from sdk.AccAddress, to sdk.AccAddress, ) { ctx.EventManager().EmitEvent(NewTransferEvent(coin, from, to)) } @@ -264,18 +264,18 @@ Args: */ func EmitMarginChange( ctx sdk.Context, - owner sdk.AccAddress, + traderAddr sdk.AccAddress, vpool string, marginAmt sdk.Int, fundingPayment sdk.Dec, ) { ctx.EventManager().EmitEvent(NewMarginChangeEvent( - owner, vpool, marginAmt, fundingPayment), + traderAddr, vpool, marginAmt, fundingPayment), ) } func NewMarginChangeEvent( - owner sdk.AccAddress, + traderAddr sdk.AccAddress, vpool string, marginAmt sdk.Int, fundingPayment sdk.Dec, @@ -283,7 +283,7 @@ func NewMarginChangeEvent( const EventTypeMarginChange = "margin_change" return sdk.NewEvent( EventTypeMarginChange, - sdk.NewAttribute(AttributePositionOwner, owner.String()), + sdk.NewAttribute(AttributePositionOwner, traderAddr.String()), sdk.NewAttribute(AttributeVpool, vpool), sdk.NewAttribute("margin_amt", marginAmt.String()), sdk.NewAttribute("funding_payment", fundingPayment.String()), @@ -313,7 +313,7 @@ func NewInternalPositionResponseEvent( pos := positionResp.Position return sdk.NewEvent( "internal_position_response", - sdk.NewAttribute(AttributePositionOwner, pos.Address), + sdk.NewAttribute(AttributePositionOwner, pos.TraderAddress.String()), sdk.NewAttribute(AttributeVpool, pos.Pair), sdk.NewAttribute("pos_margin", pos.Margin.String()), sdk.NewAttribute("pos_open_notional", pos.OpenNotional.String()), diff --git a/x/perp/keeper/calc_test.go b/x/perp/keeper/calc_test.go index 727b8c1c1..1f038d1e8 100644 --- a/x/perp/keeper/calc_test.go +++ b/x/perp/keeper/calc_test.go @@ -61,7 +61,7 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { sdk.MustNewDecFromStr("0.9"), // 0.9 ratio /* y */ sdk.NewDec(1_000_000), // /* x */ sdk.NewDec(1_000_000), // - /* fluctLim */ sdk.MustNewDecFromStr("1.0"), // 100% + /* fluctuationLimit */ sdk.MustNewDecFromStr("1.0"), // 100% /* maxOracleSpreadRatio */ sdk.MustNewDecFromStr("1.0"), // 100% ) premiumFractions := []sdk.Dec{sdk.ZeroDec()} // fPayment -> 0 @@ -75,7 +75,7 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { }) pos := &types.Position{ - Address: alice.String(), Pair: pair.String(), + TraderAddress: alice, Pair: pair.String(), Margin: sdk.NewDec(100), Size_: sdk.NewDec(200), LastUpdateCumulativePremiumFraction: premiumFractions[0], } @@ -110,7 +110,7 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { sdk.MustNewDecFromStr("0.9"), // 0.9 ratio /* y */ sdk.NewDec(1_000_000), // /* x */ sdk.NewDec(1_000_000), // - /* fluctLim */ sdk.MustNewDecFromStr("1.0"), // 100% + /* fluctuationLimit */ sdk.MustNewDecFromStr("1.0"), // 100% /* maxOracleSpreadRatio */ sdk.MustNewDecFromStr("1.0"), // 100% ) premiumFractions := []sdk.Dec{ @@ -128,7 +128,7 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { }) pos := &types.Position{ - Address: alice.String(), Pair: pair.String(), + TraderAddress: alice, Pair: pair.String(), Margin: sdk.NewDec(100), Size_: sdk.NewDec(200), LastUpdateCumulativePremiumFraction: premiumFractions[1], } diff --git a/x/perp/keeper/calc_unit_test.go b/x/perp/keeper/calc_unit_test.go index 761d9b48a..178b48e61 100644 --- a/x/perp/keeper/calc_unit_test.go +++ b/x/perp/keeper/calc_unit_test.go @@ -23,7 +23,7 @@ func Test_calcFreeCollateral(t *testing.T) { fundingPayment := sdk.ZeroDec() the3pool := "dai:usdc:usdt" alice := sample.AccAddress() - pos := types.ZeroPosition(ctx, common.TokenPair(the3pool), alice.String()) + pos := types.ZeroPosition(ctx, common.TokenPair(the3pool), alice) _, err := k.calcFreeCollateral(ctx, *pos, fundingPayment) assert.Error(t, err) assert.ErrorContains(t, err, common.ErrInvalidTokenPair.Error()) @@ -37,7 +37,7 @@ func Test_calcFreeCollateral(t *testing.T) { fundingPayment := sdk.ZeroDec() validPair := common.TokenPair("xxx:yyy") alice := sample.AccAddress() - pos := types.ZeroPosition(ctx, validPair, alice.String()) + pos := types.ZeroPosition(ctx, validPair, alice) mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, validPair). Return(false) _, err := k.calcFreeCollateral(ctx, *pos, fundingPayment) @@ -53,7 +53,7 @@ func Test_calcFreeCollateral(t *testing.T) { fundingPayment := sdk.ZeroDec() validPair := common.TokenPair("xxx:yyy") alice := sample.AccAddress() - pos := types.ZeroPosition(ctx, validPair, alice.String()) + pos := types.ZeroPosition(ctx, validPair, alice) mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, validPair). Return(true) freeCollateral, err := k.calcFreeCollateral(ctx, *pos, fundingPayment) @@ -69,7 +69,7 @@ func Test_calcFreeCollateral(t *testing.T) { fundingPayment := sdk.NewDec(10) validPair := common.TokenPair("xxx:yyy") alice := sample.AccAddress() - pos := types.ZeroPosition(ctx, validPair, alice.String()) + pos := types.ZeroPosition(ctx, validPair, alice) mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, validPair). Return(true) freeCollateral, err := k.calcFreeCollateral(ctx, *pos, fundingPayment) @@ -85,7 +85,7 @@ func Test_calcFreeCollateral(t *testing.T) { fundingPayment := sdk.NewDec(-100) validPair := common.TokenPair("xxx:yyy") alice := sample.AccAddress() - pos := types.ZeroPosition(ctx, validPair, alice.String()) + pos := types.ZeroPosition(ctx, validPair, alice) mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, validPair). Return(true) freeCollateral, err := k.calcFreeCollateral(ctx, *pos, fundingPayment) diff --git a/x/perp/keeper/clearing_house.go b/x/perp/keeper/clearing_house.go index 5c3bcc50c..5747e38a3 100644 --- a/x/perp/keeper/clearing_house.go +++ b/x/perp/keeper/clearing_house.go @@ -32,11 +32,11 @@ func (k Keeper) OpenPosition( params := k.GetParams(ctx) // TODO: missing checks - position, err := k.GetPosition(ctx, pair, traderAddr.String()) + position, err := k.GetPosition(ctx, pair, traderAddr) var isNewPosition bool = errors.Is(err, types.ErrPositionNotFound) if isNewPosition { - position = types.ZeroPosition(ctx, pair, traderAddr.String()) - k.SetPosition(ctx, pair, traderAddr.String(), position) + position = types.ZeroPosition(ctx, pair, traderAddr) + k.SetPosition(ctx, pair, traderAddr, position) } else if err != nil && !isNewPosition { return err } @@ -76,7 +76,7 @@ func (k Keeper) OpenPosition( } // update position in state - k.SetPosition(ctx, pair, traderAddr.String(), positionResp.Position) + k.SetPosition(ctx, pair, traderAddr, positionResp.Position) if !isNewPosition && !positionResp.Position.Size_.IsZero() { marginRatio, err := k.GetMarginRatio( @@ -107,8 +107,8 @@ func (k Keeper) OpenPosition( } events.EmitTransfer(ctx, /* coin */ coinToSend, - /* from */ traderAddr.String(), - /* to */ k.AccountKeeper.GetModuleAddress(types.VaultModuleAccount).String()) + /* from */ traderAddr, + /* to */ k.AccountKeeper.GetModuleAddress(types.VaultModuleAccount)) case marginToVaultInt.IsNegative(): coinToSend := sdk.NewCoin(pair.GetQuoteTokenDenom(), marginToVaultInt.Abs()) err = k.BankKeeper.SendCoinsFromModuleToAccount( @@ -118,8 +118,8 @@ func (k Keeper) OpenPosition( } events.EmitTransfer(ctx, /* coin */ coinToSend, - /* from */ k.AccountKeeper.GetModuleAddress(types.VaultModuleAccount).String(), - /* to */ traderAddr.String(), + /* from */ k.AccountKeeper.GetModuleAddress(types.VaultModuleAccount), + /* to */ traderAddr, ) } @@ -135,7 +135,7 @@ func (k Keeper) OpenPosition( } return ctx.EventManager().EmitTypedEvent(&types.PositionChangedEvent{ - Trader: traderAddr.String(), + TraderAddress: traderAddr, Pair: pair.String(), Margin: positionResp.Position.Margin, PositionNotional: positionResp.ExchangedPositionSize, @@ -227,13 +227,12 @@ func (k Keeper) increasePosition( positionResp.FundingPayment = remaining.FundingPayment positionResp.BadDebt = remaining.BadDebt positionResp.Position = &types.Position{ - Address: currentPosition.Address, + TraderAddress: currentPosition.TraderAddress, Pair: currentPosition.Pair, Size_: currentPosition.Size_.Add(positionResp.ExchangedPositionSize), Margin: remaining.Margin, OpenNotional: currentPosition.OpenNotional.Add(increasedNotional), LastUpdateCumulativePremiumFraction: remaining.LatestCumulativePremiumFraction, - LiquidityHistoryIndex: currentPosition.LiquidityHistoryIndex, BlockNumber: ctx.BlockHeight(), } @@ -483,13 +482,12 @@ func (k Keeper) decreasePosition( } positionResp.Position = &types.Position{ - Address: currentPosition.Address, + TraderAddress: currentPosition.TraderAddress, Pair: currentPosition.Pair, Size_: currentPosition.Size_.Add(positionResp.ExchangedPositionSize), Margin: remaining.Margin, OpenNotional: remainOpenNotional, LastUpdateCumulativePremiumFraction: remaining.LatestCumulativePremiumFraction, - LiquidityHistoryIndex: currentPosition.LiquidityHistoryIndex, BlockNumber: ctx.BlockHeight(), } events.EmitInternalPositionResponseEvent(ctx, positionResp, "decrease_position") @@ -560,7 +558,7 @@ func (k Keeper) closeAndOpenReversePosition( newPosition := types.ZeroPosition( ctx, common.TokenPair(existingPosition.Pair), - existingPosition.Address, + existingPosition.TraderAddress, ) increasePositionResp, err := k.increasePosition( ctx, @@ -663,20 +661,19 @@ func (k Keeper) closePositionEntirely( positionResp.ExchangedQuoteAssetAmount = exchangedQuoteAssetAmount positionResp.Position = &types.Position{ - Address: currentPosition.Address, + TraderAddress: currentPosition.TraderAddress, Pair: currentPosition.Pair, Size_: sdk.ZeroDec(), Margin: sdk.ZeroDec(), OpenNotional: sdk.ZeroDec(), LastUpdateCumulativePremiumFraction: remaining.LatestCumulativePremiumFraction, - LiquidityHistoryIndex: currentPosition.LiquidityHistoryIndex, BlockNumber: ctx.BlockHeight(), } if err = k.ClearPosition( ctx, common.TokenPair(currentPosition.Pair), - currentPosition.Address, + currentPosition.TraderAddress, ); err != nil { return nil, err } diff --git a/x/perp/keeper/clearing_house_test.go b/x/perp/keeper/clearing_house_test.go index 8fd7a2f75..804679bde 100644 --- a/x/perp/keeper/clearing_house_test.go +++ b/x/perp/keeper/clearing_house_test.go @@ -155,11 +155,11 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { t.Log("Setting up initial position") oldPosition := types.Position{ - Address: sample.AccAddress().String(), - Pair: "BTC:NUSD", - Size_: sdk.NewDec(10), - OpenNotional: sdk.NewDec(10), - Margin: sdk.NewDec(1), + TraderAddress: sample.AccAddress(), + Pair: "BTC:NUSD", + Size_: sdk.NewDec(10), + OpenNotional: sdk.NewDec(10), + Margin: sdk.NewDec(1), } t.Log("Mocking price of vpool") @@ -191,11 +191,11 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { t.Log("Setting up initial position") oldPosition := types.Position{ - Address: sample.AccAddress().String(), - Pair: "BTC:NUSD", - Size_: sdk.NewDec(10), - OpenNotional: sdk.NewDec(10), - Margin: sdk.NewDec(1), + TraderAddress: sample.AccAddress(), + Pair: "BTC:NUSD", + Size_: sdk.NewDec(10), + OpenNotional: sdk.NewDec(10), + Margin: sdk.NewDec(1), } t.Log("Mocking price of vpool") @@ -227,11 +227,11 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { t.Log("Setting up initial position") oldPosition := types.Position{ - Address: sample.AccAddress().String(), - Pair: "BTC:NUSD", - Size_: sdk.NewDec(10), - OpenNotional: sdk.NewDec(10), - Margin: sdk.NewDec(1), + TraderAddress: sample.AccAddress(), + Pair: "BTC:NUSD", + Size_: sdk.NewDec(10), + OpenNotional: sdk.NewDec(10), + Margin: sdk.NewDec(1), } t.Log("Mocking price of vpool") @@ -264,11 +264,11 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { t.Log("Setting up initial position") oldPosition := types.Position{ - Address: sample.AccAddress().String(), - Pair: "BTC:NUSD", - Size_: sdk.NewDec(10), - OpenNotional: sdk.NewDec(10), - Margin: sdk.NewDec(1), + TraderAddress: sample.AccAddress(), + Pair: "BTC:NUSD", + Size_: sdk.NewDec(10), + OpenNotional: sdk.NewDec(10), + Margin: sdk.NewDec(1), } t.Log("Mocking price of vpool") @@ -301,11 +301,11 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { t.Log("Setting up initial position") oldPosition := types.Position{ - Address: sample.AccAddress().String(), - Pair: "BTC:NUSD", - Size_: sdk.NewDec(10), - OpenNotional: sdk.NewDec(10), - Margin: sdk.NewDec(1), + TraderAddress: sample.AccAddress(), + Pair: "BTC:NUSD", + Size_: sdk.NewDec(10), + OpenNotional: sdk.NewDec(10), + Margin: sdk.NewDec(1), } t.Log("Mocking price of vpool") @@ -335,11 +335,11 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { t.Log("Setting up initial position") oldPosition := types.Position{ - Address: sample.AccAddress().String(), - Pair: "BTC:NUSD", - Size_: sdk.NewDec(10), - OpenNotional: sdk.NewDec(10), - Margin: sdk.NewDec(1), + TraderAddress: sample.AccAddress(), + Pair: "BTC:NUSD", + Size_: sdk.NewDec(10), + OpenNotional: sdk.NewDec(10), + Margin: sdk.NewDec(1), } t.Log("Mocking price of vpool") @@ -369,11 +369,11 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { t.Log("Setting up initial position") oldPosition := types.Position{ - Address: sample.AccAddress().String(), - Pair: "BTC:NUSD", - Size_: sdk.NewDec(-10), - OpenNotional: sdk.NewDec(10), - Margin: sdk.NewDec(1), + TraderAddress: sample.AccAddress(), + Pair: "BTC:NUSD", + Size_: sdk.NewDec(-10), + OpenNotional: sdk.NewDec(10), + Margin: sdk.NewDec(1), } t.Log("Mocking price of vpool") @@ -405,11 +405,11 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { t.Log("Setting up initial position") oldPosition := types.Position{ - Address: sample.AccAddress().String(), - Pair: "BTC:NUSD", - Size_: sdk.NewDec(-10), - OpenNotional: sdk.NewDec(10), - Margin: sdk.NewDec(1), + TraderAddress: sample.AccAddress(), + Pair: "BTC:NUSD", + Size_: sdk.NewDec(-10), + OpenNotional: sdk.NewDec(10), + Margin: sdk.NewDec(1), } t.Log("Mocking price of vpool") @@ -441,11 +441,11 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { t.Log("Setting up initial position") oldPosition := types.Position{ - Address: sample.AccAddress().String(), - Pair: "BTC:NUSD", - Size_: sdk.NewDec(-10), - OpenNotional: sdk.NewDec(10), - Margin: sdk.NewDec(1), + TraderAddress: sample.AccAddress(), + Pair: "BTC:NUSD", + Size_: sdk.NewDec(-10), + OpenNotional: sdk.NewDec(10), + Margin: sdk.NewDec(1), } t.Log("Mocking price of vpool") @@ -478,11 +478,11 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { t.Log("Setting up initial position") oldPosition := types.Position{ - Address: sample.AccAddress().String(), - Pair: "BTC:NUSD", - Size_: sdk.NewDec(-10), - OpenNotional: sdk.NewDec(10), - Margin: sdk.NewDec(1), + TraderAddress: sample.AccAddress(), + Pair: "BTC:NUSD", + Size_: sdk.NewDec(-10), + OpenNotional: sdk.NewDec(10), + Margin: sdk.NewDec(1), } t.Log("Mocking price of vpool") @@ -515,11 +515,11 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { t.Log("Setting up initial position") oldPosition := types.Position{ - Address: sample.AccAddress().String(), - Pair: "BTC:NUSD", - Size_: sdk.NewDec(-10), - OpenNotional: sdk.NewDec(10), - Margin: sdk.NewDec(1), + TraderAddress: sample.AccAddress(), + Pair: "BTC:NUSD", + Size_: sdk.NewDec(-10), + OpenNotional: sdk.NewDec(10), + Margin: sdk.NewDec(1), } t.Log("Mocking price of vpool") @@ -549,11 +549,11 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { t.Log("Setting up initial position") oldPosition := types.Position{ - Address: sample.AccAddress().String(), - Pair: "BTC:NUSD", - Size_: sdk.NewDec(-10), - OpenNotional: sdk.NewDec(10), - Margin: sdk.NewDec(1), + TraderAddress: sample.AccAddress(), + Pair: "BTC:NUSD", + Size_: sdk.NewDec(-10), + OpenNotional: sdk.NewDec(10), + Margin: sdk.NewDec(1), } t.Log("Mocking price of vpool") @@ -672,11 +672,11 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnl(t *testing.T) { t.Log("Setting up initial position") oldPosition := types.Position{ - Address: sample.AccAddress().String(), - Pair: "BTC:NUSD", - Size_: sdk.NewDec(10), - OpenNotional: sdk.NewDec(10), - Margin: sdk.NewDec(1), + TraderAddress: sample.AccAddress(), + Pair: "BTC:NUSD", + Size_: sdk.NewDec(10), + OpenNotional: sdk.NewDec(10), + Margin: sdk.NewDec(1), } t.Log("Mock vpool spot price") @@ -718,11 +718,11 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnl(t *testing.T) { t.Log("Setting up initial position") oldPosition := types.Position{ - Address: sample.AccAddress().String(), - Pair: "BTC:NUSD", - Size_: sdk.NewDec(10), - OpenNotional: sdk.NewDec(10), - Margin: sdk.NewDec(1), + TraderAddress: sample.AccAddress(), + Pair: "BTC:NUSD", + Size_: sdk.NewDec(10), + OpenNotional: sdk.NewDec(10), + Margin: sdk.NewDec(1), } t.Log("Mock vpool spot price") @@ -764,11 +764,11 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnl(t *testing.T) { t.Log("Setting up initial position") oldPosition := types.Position{ - Address: sample.AccAddress().String(), - Pair: "BTC:NUSD", - Size_: sdk.NewDec(10), - OpenNotional: sdk.NewDec(10), - Margin: sdk.NewDec(1), + TraderAddress: sample.AccAddress(), + Pair: "BTC:NUSD", + Size_: sdk.NewDec(10), + OpenNotional: sdk.NewDec(10), + Margin: sdk.NewDec(1), } t.Log("Mock vpool spot price") @@ -810,11 +810,11 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnl(t *testing.T) { t.Log("Setting up initial position") oldPosition := types.Position{ - Address: sample.AccAddress().String(), - Pair: "BTC:NUSD", - Size_: sdk.NewDec(10), - OpenNotional: sdk.NewDec(10), - Margin: sdk.NewDec(1), + TraderAddress: sample.AccAddress(), + Pair: "BTC:NUSD", + Size_: sdk.NewDec(10), + OpenNotional: sdk.NewDec(10), + Margin: sdk.NewDec(1), } t.Log("Mock vpool spot price") @@ -874,13 +874,12 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } @@ -931,13 +930,12 @@ func TestIncreasePosition(t *testing.T) { assert.True(t, sdk.NewDec(10).Equal(resp.MarginToVault)) assert.EqualValues(t, sdk.NewDec(100), resp.UnrealizedPnlAfter) - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.NewDec(150), resp.Position.Size_) // 100 + 50 assert.True(t, sdk.NewDec(18).Equal(resp.Position.Margin)) // 10(old) + 10(new) - 2(funding payment) assert.EqualValues(t, sdk.NewDec(200), resp.Position.OpenNotional) // 100(old) + 100(new) assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -951,13 +949,12 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } @@ -1008,13 +1005,12 @@ func TestIncreasePosition(t *testing.T) { assert.True(t, sdk.NewDec(10).Equal(resp.MarginToVault)) // openNotional / leverage assert.EqualValues(t, sdk.NewDec(-1), resp.UnrealizedPnlAfter) // 99 - 100 - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.NewDec(201), resp.Position.Size_) // 100 + 101 assert.True(t, sdk.NewDec(18).Equal(resp.Position.Margin)) // 10(old) + 10(new) - 2(funding payment) assert.EqualValues(t, sdk.NewDec(200), resp.Position.OpenNotional) // 100(old) + 100(new) assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -1031,13 +1027,12 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(110), // 110 BTC Margin: sdk.NewDec(11), // 11 NUSD OpenNotional: sdk.NewDec(110), // 110 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } @@ -1089,13 +1084,12 @@ func TestIncreasePosition(t *testing.T) { assert.EqualValues(t, sdk.NewDec(-10), resp.UnrealizedPnlAfter) // 90 - 100 assert.EqualValues(t, sdk.NewDec(1), resp.BadDebt) // 11(old) + 10(new) - 22(funding payment) - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.NewDec(220), resp.Position.Size_) // 110 + 110 assert.EqualValues(t, sdk.ZeroDec(), resp.Position.Margin) // 11(old) + 10(new) - 22(funding payment) --> zero margin left assert.EqualValues(t, sdk.NewDec(210), resp.Position.OpenNotional) // 100(old) + 100(new) assert.EqualValues(t, sdk.MustNewDecFromStr("0.2"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -1110,13 +1104,12 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } @@ -1167,13 +1160,12 @@ func TestIncreasePosition(t *testing.T) { assert.EqualValues(t, sdk.NewDec(10), resp.MarginToVault) // open notional / leverage assert.EqualValues(t, sdk.NewDec(50), resp.UnrealizedPnlAfter) // 100 - 50 - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.NewDec(-300), resp.Position.Size_) // -100 - 200 assert.EqualValues(t, sdk.NewDec(22), resp.Position.Margin) // 10(old) + 10(new) - (-2)(funding payment) assert.EqualValues(t, sdk.NewDec(200), resp.Position.OpenNotional) // 100(old) + 100(new) assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -1188,13 +1180,12 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(-100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } @@ -1245,13 +1236,12 @@ func TestIncreasePosition(t *testing.T) { assert.EqualValues(t, sdk.NewDec(10), resp.MarginToVault) // openNotional / leverage assert.EqualValues(t, sdk.NewDec(-1), resp.UnrealizedPnlAfter) // 100 - 101 - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.NewDec(-199), resp.Position.Size_) // -100 - 99 assert.EqualValues(t, sdk.NewDec(22), resp.Position.Margin) // 10(old) + 10(new) - (-2)(funding payment) assert.EqualValues(t, sdk.NewDec(200), resp.Position.OpenNotional) // 100(old) + 100(new) assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -1269,13 +1259,12 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(-100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } @@ -1327,13 +1316,12 @@ func TestIncreasePosition(t *testing.T) { assert.EqualValues(t, sdk.NewDec(-5), resp.UnrealizedPnlAfter) // 100 - 105 assert.EqualValues(t, sdk.MustNewDecFromStr("9.5").String(), resp.BadDebt.String()) // 10(old) + 10.5(new) - (30)(funding payment) - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.NewDec(-200), resp.Position.Size_) // -100 + (-100) assert.EqualValues(t, sdk.ZeroDec(), resp.Position.Margin) // 10(old) + 10.5(new) - (30)(funding payment) --> zero margin left assert.EqualValues(t, sdk.NewDec(205), resp.Position.OpenNotional) // 100(old) + 105(new) assert.EqualValues(t, sdk.MustNewDecFromStr("-0.3"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -1364,19 +1352,18 @@ func TestClosePositionEntirely(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } perpKeeper.SetPosition( ctx, common.TokenPair(currentPosition.Pair), - currentPosition.Address, + currentPosition.TraderAddress, ¤tPosition, ) @@ -1424,13 +1411,12 @@ func TestClosePositionEntirely(t *testing.T) { assert.EqualValues(t, sdk.NewDec(100), resp.RealizedPnl) assert.EqualValues(t, sdk.ZeroDec(), resp.UnrealizedPnlAfter) // always zero when closing a position entirely - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.ZeroDec(), resp.Position.Size_) // always zero assert.EqualValues(t, sdk.ZeroDec(), resp.Position.Margin) // always zero assert.EqualValues(t, sdk.ZeroDec(), resp.Position.OpenNotional) // always zero assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -1445,19 +1431,18 @@ func TestClosePositionEntirely(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(12), // 10.5 NUSD OpenNotional: sdk.NewDec(120), // 105 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } perpKeeper.SetPosition( ctx, common.TokenPair(currentPosition.Pair), - currentPosition.Address, + currentPosition.TraderAddress, ¤tPosition, ) @@ -1505,13 +1490,12 @@ func TestClosePositionEntirely(t *testing.T) { assert.EqualValues(t, sdk.NewDec(-20), resp.RealizedPnl) assert.EqualValues(t, sdk.ZeroDec(), resp.UnrealizedPnlAfter) // always zero when closing a position entirely - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.ZeroDec(), resp.Position.Size_) // always zero assert.EqualValues(t, sdk.ZeroDec(), resp.Position.Margin) // always zero assert.EqualValues(t, sdk.ZeroDec(), resp.Position.OpenNotional) // always zero assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -1526,19 +1510,18 @@ func TestClosePositionEntirely(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } perpKeeper.SetPosition( ctx, common.TokenPair(currentPosition.Pair), - currentPosition.Address, + currentPosition.TraderAddress, ¤tPosition, ) @@ -1586,13 +1569,12 @@ func TestClosePositionEntirely(t *testing.T) { assert.EqualValues(t, sdk.ZeroDec(), resp.UnrealizedPnlAfter) // always zero when closing a position entirely assert.EqualValues(t, sdk.NewDec(37), resp.BadDebt) // 15(oldMargin) + (-50)(unrealzedPnL) - 2(fundingPayment) - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.ZeroDec(), resp.Position.Size_) // always zero assert.EqualValues(t, sdk.ZeroDec(), resp.Position.Margin) // always zero assert.EqualValues(t, sdk.ZeroDec(), resp.Position.OpenNotional) // always zero assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -1609,19 +1591,18 @@ func TestClosePositionEntirely(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(-150), // -150 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } perpKeeper.SetPosition( ctx, common.TokenPair(currentPosition.Pair), - currentPosition.Address, + currentPosition.TraderAddress, ¤tPosition, ) @@ -1669,13 +1650,12 @@ func TestClosePositionEntirely(t *testing.T) { assert.EqualValues(t, sdk.ZeroDec(), resp.UnrealizedPnlAfter) assert.EqualValues(t, sdk.NewDec(-68), resp.MarginToVault) // ( 15(oldMargin) + 50(PnL) - (-3)(fundingPayment) ) * -1 - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.ZeroDec(), resp.Position.Size_) // always zero assert.EqualValues(t, sdk.ZeroDec(), resp.Position.Margin) // always zero assert.EqualValues(t, sdk.ZeroDec(), resp.Position.OpenNotional) // always zero assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -1690,19 +1670,18 @@ func TestClosePositionEntirely(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } perpKeeper.SetPosition( ctx, common.TokenPair(currentPosition.Pair), - currentPosition.Address, + currentPosition.TraderAddress, ¤tPosition, ) @@ -1750,13 +1729,12 @@ func TestClosePositionEntirely(t *testing.T) { assert.EqualValues(t, sdk.NewDec(-7), resp.MarginToVault) // ( 10(oldMargin) + (-5)(PnL) - (-2)(fundingPayment) ) * -1 assert.EqualValues(t, sdk.ZeroDec(), resp.BadDebt) - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.ZeroDec(), resp.Position.Size_) // always zero assert.EqualValues(t, sdk.ZeroDec(), resp.Position.Margin) // always zero assert.EqualValues(t, sdk.ZeroDec(), resp.Position.OpenNotional) // always zero assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -1771,19 +1749,18 @@ func TestClosePositionEntirely(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } perpKeeper.SetPosition( ctx, common.TokenPair(currentPosition.Pair), - currentPosition.Address, + currentPosition.TraderAddress, ¤tPosition, ) @@ -1831,13 +1808,12 @@ func TestClosePositionEntirely(t *testing.T) { assert.EqualValues(t, sdk.ZeroDec(), resp.MarginToVault) // ( 10(oldMargin) + (-50)(PnL) - (-2)(fundingPayment) ) * -1 --> clipped to zero assert.EqualValues(t, sdk.NewDec(38), resp.BadDebt) // 10(oldMargin) + (-50)(PnL) - (-2)(fundingPayment) - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.ZeroDec(), resp.Position.Size_) // always zero assert.EqualValues(t, sdk.ZeroDec(), resp.Position.Margin) // always zero assert.EqualValues(t, sdk.ZeroDec(), resp.Position.OpenNotional) // always zero assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -1870,13 +1846,12 @@ func TestDecreasePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } @@ -1926,13 +1901,12 @@ func TestDecreasePosition(t *testing.T) { assert.EqualValues(t, sdk.NewDec(50), resp.RealizedPnl) assert.EqualValues(t, sdk.NewDec(50), resp.UnrealizedPnlAfter) - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.NewDec(50), resp.Position.Size_) // 100 - 50 assert.EqualValues(t, sdk.NewDec(58), resp.Position.Margin) // 10(old) + 50(realized PnL) - 2(funding payment) assert.EqualValues(t, sdk.NewDec(50), resp.Position.OpenNotional) // 200(position notional) - 100(notional sold) - 50(unrealized PnL) assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -1950,13 +1924,12 @@ func TestDecreasePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(105), // 105 BTC Margin: sdk.NewDec(11), // 10.5 NUSD OpenNotional: sdk.NewDec(110), // 105 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } @@ -2008,7 +1981,7 @@ func TestDecreasePosition(t *testing.T) { assert.EqualValues(t, sdk.MustNewDecFromStr("-9.5").String(), resp.UnrealizedPnlAfter.String()) // (-5)(unrealizedPnL) - (-0.25)(realizedPnL) assert.EqualValues(t, sdk.ZeroDec().String(), resp.MarginToVault.String()) // always zero for decreasePosition - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.MustNewDecFromStr("99.75"), resp.Position.Size_) // 105 - 5.25 assert.EqualValues(t, sdk.MustNewDecFromStr("8.4").String(), resp.Position.Margin.String()) // 10(old) + (-0.25)(realized PnL) - 2.1(funding payment) @@ -2016,7 +1989,6 @@ func TestDecreasePosition(t *testing.T) { sdk.MustNewDecFromStr("104.5").String(), resp.Position.OpenNotional.String()) // 100(position notional) - 5(notional sold) - (-4.75)(unrealized PnL) assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -2036,13 +2008,12 @@ func TestDecreasePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(-105), // -105 BTC Margin: sdk.NewDec(11), // 10.5 NUSD OpenNotional: sdk.NewDec(110), // 105 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } @@ -2092,13 +2063,12 @@ func TestDecreasePosition(t *testing.T) { assert.EqualValues(t, sdk.MustNewDecFromStr("9.5"), resp.UnrealizedPnlAfter) // (-5)(unrealizedPnL) - (-0.25)(realizedPnL) assert.EqualValues(t, sdk.ZeroDec().String(), resp.MarginToVault.String()) // always zero for decreasePosition - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.MustNewDecFromStr("-99.75"), resp.Position.Size_) // -105 + 5.25 assert.EqualValues(t, sdk.MustNewDecFromStr("13.6").String(), resp.Position.Margin.String()) // 10.5(old) + 0.25(realized PnL) - (-2.1)(funding payment) assert.EqualValues(t, sdk.MustNewDecFromStr("104.5").String(), resp.Position.OpenNotional.String()) // 100(position notional) - 5(notional sold) + 4.75(unrealized PnL) assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -2116,13 +2086,12 @@ func TestDecreasePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } @@ -2172,13 +2141,12 @@ func TestDecreasePosition(t *testing.T) { assert.EqualValues(t, sdk.MustNewDecFromStr("-0.25"), resp.RealizedPnl) assert.EqualValues(t, sdk.MustNewDecFromStr("-4.75"), resp.UnrealizedPnlAfter) - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.NewDec(-95), resp.Position.Size_) // -100 + 5 assert.EqualValues(t, sdk.MustNewDecFromStr("11.75").String(), resp.Position.Margin.String()) // 10(old) + (-0.25)(realized PnL) - (-2)(funding payment) assert.EqualValues(t, sdk.NewDec(95), resp.Position.OpenNotional) // 105(position notional) - 5.25(notional sold) + (-4.75)(unrealized PnL) assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -2211,19 +2179,18 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } perpKeeper.SetPosition( ctx, common.TokenPair(currentPosition.Pair), - currentPosition.Address, + currentPosition.TraderAddress, ¤tPosition, ) @@ -2282,13 +2249,12 @@ func TestCloseAndOpenReversePosition(t *testing.T) { assert.EqualValues(t, sdk.NewDec(100), resp.RealizedPnl) assert.EqualValues(t, sdk.ZeroDec(), resp.UnrealizedPnlAfter) // always zero - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.NewDec(-50), resp.Position.Size_) assert.EqualValues(t, sdk.NewDec(10).String(), resp.Position.Margin.String()) assert.EqualValues(t, sdk.NewDec(100), resp.Position.OpenNotional) assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -2304,19 +2270,18 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(11), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } perpKeeper.SetPosition( ctx, common.TokenPair(currentPosition.Pair), - currentPosition.Address, + currentPosition.TraderAddress, ¤tPosition, ) @@ -2379,13 +2344,12 @@ func TestCloseAndOpenReversePosition(t *testing.T) { assert.EqualValues(t, sdk.NewDec(-5), resp.RealizedPnl) assert.EqualValues(t, sdk.ZeroDec(), resp.UnrealizedPnlAfter) // always zero - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.NewDec(-100), resp.Position.Size_) assert.EqualValues(t, sdk.NewDec(10).String(), resp.Position.Margin.String()) assert.EqualValues(t, sdk.NewDec(100), resp.Position.OpenNotional) assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -2401,19 +2365,18 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } perpKeeper.SetPosition( ctx, common.TokenPair(currentPosition.Pair), - currentPosition.Address, + currentPosition.TraderAddress, ¤tPosition, ) @@ -2472,19 +2435,18 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(-150), // -150 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } perpKeeper.SetPosition( ctx, common.TokenPair(currentPosition.Pair), - currentPosition.Address, + currentPosition.TraderAddress, ¤tPosition, ) @@ -2543,13 +2505,12 @@ func TestCloseAndOpenReversePosition(t *testing.T) { assert.EqualValues(t, sdk.ZeroDec(), resp.UnrealizedPnlAfter) assert.EqualValues(t, sdk.NewDec(-58).String(), resp.MarginToVault.String()) // -1 * ( 15(oldMargin) + 50(PnL) - (-3)(fundingPayment) ) + 10 - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.NewDec(150), resp.Position.Size_) assert.EqualValues(t, sdk.NewDec(10).String(), resp.Position.Margin.String()) assert.EqualValues(t, sdk.NewDec(100), resp.Position.OpenNotional) assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -2565,19 +2526,18 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } perpKeeper.SetPosition( ctx, common.TokenPair(currentPosition.Pair), - currentPosition.Address, + currentPosition.TraderAddress, ¤tPosition, ) @@ -2636,13 +2596,12 @@ func TestCloseAndOpenReversePosition(t *testing.T) { assert.EqualValues(t, sdk.ZeroDec(), resp.UnrealizedPnlAfter) assert.EqualValues(t, sdk.MustNewDecFromStr("3.5").String(), resp.MarginToVault.String()) // -1 * ( 10(oldMargin) + (-5))(PnL) - (-2)(fundingPayment) ) + 10.5 - assert.EqualValues(t, currentPosition.Address, resp.Position.Address) + assert.EqualValues(t, currentPosition.TraderAddress, resp.Position.TraderAddress) assert.EqualValues(t, currentPosition.Pair, resp.Position.Pair) assert.EqualValues(t, sdk.NewDec(100), resp.Position.Size_) assert.EqualValues(t, sdk.MustNewDecFromStr("10.5").String(), resp.Position.Margin.String()) assert.EqualValues(t, sdk.NewDec(105), resp.Position.OpenNotional) assert.EqualValues(t, sdk.MustNewDecFromStr("0.02"), resp.Position.LastUpdateCumulativePremiumFraction) - assert.EqualValues(t, 0, resp.Position.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }, }, @@ -2658,19 +2617,18 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: 0, } perpKeeper.SetPosition( ctx, common.TokenPair(currentPosition.Pair), - currentPosition.Address, + currentPosition.TraderAddress, ¤tPosition, ) diff --git a/x/perp/keeper/liquidate.go b/x/perp/keeper/liquidate.go index 12a0d665e..741bbc263 100644 --- a/x/perp/keeper/liquidate.go +++ b/x/perp/keeper/liquidate.go @@ -22,8 +22,7 @@ func (k Keeper) Liquidate( ctx := sdk.UnwrapSDKContext(goCtx) // validate liquidator (msg.Sender) - liquidator, err := sdk.AccAddressFromBech32(msg.Sender) - if err != nil { + if err = sdk.VerifyAddressFormat(msg.Sender); err != nil { return res, err } @@ -43,7 +42,7 @@ func (k Keeper) Liquidate( return res, err } - position, err := k.GetPosition(ctx, pair, trader.String()) + position, err := k.GetPosition(ctx, pair, trader) if err != nil { return res, err } @@ -82,12 +81,12 @@ func (k Keeper) Liquidate( ) if marginRatioBasedOnSpot.GTE(params.GetPartialLiquidationRatioAsDec()) { - _, err = k.ExecuteFullLiquidation(ctx, liquidator, position) + _, err = k.ExecuteFullLiquidation(ctx, msg.Sender, position) if err != nil { return res, err } } else { - err = k.ExecutePartialLiquidation(ctx, liquidator, position) + err = k.ExecutePartialLiquidation(ctx, msg.Sender, position) if err != nil { return res, err } @@ -99,7 +98,7 @@ func (k Keeper) Liquidate( /* owner */ trader, /* notional */ liquidateResp.PositionResp.ExchangedQuoteAssetAmount, /* vsize */ liquidateResp.PositionResp.ExchangedPositionSize, - /* liquidator */ liquidator, + /* liquidator */ msg.Sender, /* liquidationFee */ liquidateResp.FeeToLiquidator.TruncateInt(), /* badDebt */ liquidateResp.BadDebt, ) @@ -229,8 +228,8 @@ func (k Keeper) distributeLiquidateRewards( } events.EmitTransfer(ctx, /* coin */ coinToPerpEF, - /* from */ vaultAddr.String(), - /* to */ perpEFAddr.String(), + /* from */ vaultAddr, + /* to */ perpEFAddr, ) } @@ -250,8 +249,8 @@ func (k Keeper) distributeLiquidateRewards( } events.EmitTransfer(ctx, /* coin */ coinToLiquidator, - /* from */ perpEFAddr.String(), - /* to */ liquidateResp.Liquidator.String(), + /* from */ perpEFAddr, + /* to */ liquidateResp.Liquidator, ) } diff --git a/x/perp/keeper/liquidate_test.go b/x/perp/keeper/liquidate_test.go index c1eef9020..0475b5803 100644 --- a/x/perp/keeper/liquidate_test.go +++ b/x/perp/keeper/liquidate_test.go @@ -97,7 +97,7 @@ func TestExecuteFullLiquidation_EmptyPosition(t *testing.T) { require.NoError(t, err) t.Log("Get the position") - position, err := nibiruApp.PerpKeeper.GetPosition(ctx, pair, alice.String()) + position, err := nibiruApp.PerpKeeper.GetPosition(ctx, pair, alice) require.NoError(t, err) t.Log("Artificially populate Vault and PerpEF to prevent BankKeeper errors") @@ -115,7 +115,7 @@ func TestExecuteFullLiquidation_EmptyPosition(t *testing.T) { require.Error(t, err) // No change in the position - newPosition, _ := nibiruApp.PerpKeeper.GetPosition(ctx, pair, alice.String()) + newPosition, _ := nibiruApp.PerpKeeper.GetPosition(ctx, pair, alice) require.Equal(t, position.Size_, newPosition.Size_) require.Equal(t, position.Margin, newPosition.Margin) require.Equal(t, position.OpenNotional, newPosition.OpenNotional) @@ -159,7 +159,7 @@ func TestExecuteFullLiquidation(t *testing.T) { expectedEvent: events.NewInternalPositionResponseEvent( &types.PositionResp{ Position: &types.Position{ - Address: alice.String(), Pair: pair.String(), + TraderAddress: alice, Pair: pair.String(), Margin: sdk.ZeroDec(), OpenNotional: sdk.ZeroDec(), }, ExchangedQuoteAssetAmount: sdk.NewDec(50_000), @@ -191,7 +191,7 @@ func TestExecuteFullLiquidation(t *testing.T) { expectedEvent: events.NewInternalPositionResponseEvent( &types.PositionResp{ Position: &types.Position{ - Address: alice.String(), Pair: pair.String(), + TraderAddress: alice, Pair: pair.String(), Margin: sdk.ZeroDec(), OpenNotional: sdk.ZeroDec(), }, ExchangedQuoteAssetAmount: sdk.NewDec(50_000), @@ -228,10 +228,10 @@ func TestExecuteFullLiquidation(t *testing.T) { expectedEvent: events.NewInternalPositionResponseEvent( &types.PositionResp{ Position: &types.Position{ - Address: alice.String(), - Pair: pair.String(), - Margin: sdk.ZeroDec(), - OpenNotional: sdk.ZeroDec(), + TraderAddress: alice, + Pair: pair.String(), + Margin: sdk.ZeroDec(), + OpenNotional: sdk.ZeroDec(), }, ExchangedQuoteAssetAmount: sdk.NewDec(500_000), BadDebt: sdk.ZeroDec(), @@ -263,7 +263,7 @@ func TestExecuteFullLiquidation(t *testing.T) { expectedEvent: events.NewInternalPositionResponseEvent( &types.PositionResp{ Position: &types.Position{ - Address: alice.String(), Pair: pair.String(), + TraderAddress: alice, Pair: pair.String(), Margin: sdk.ZeroDec(), OpenNotional: sdk.ZeroDec(), }, ExchangedQuoteAssetAmount: sdk.NewDec(500_000), @@ -319,7 +319,7 @@ func TestExecuteFullLiquidation(t *testing.T) { ctx, pair, tc.positionSide, alice, tc.quoteAmount, tc.leverage, tc.baseAssetLimit)) t.Log("Get the position") - position, err := nibiruApp.PerpKeeper.GetPosition(ctx, pair, alice.String()) + position, err := nibiruApp.PerpKeeper.GetPosition(ctx, pair, alice) require.NoError(t, err) t.Log("Fund vault and PerpEF") @@ -339,7 +339,7 @@ func TestExecuteFullLiquidation(t *testing.T) { assert.Contains(t, ctx.EventManager().Events(), tc.expectedEvent) t.Log("Check new position") - newPosition, _ := nibiruApp.PerpKeeper.GetPosition(ctx, pair, alice.String()) + newPosition, _ := nibiruApp.PerpKeeper.GetPosition(ctx, pair, alice) assert.True(t, newPosition.Size_.IsZero()) assert.True(t, newPosition.Margin.IsZero()) assert.True(t, newPosition.OpenNotional.IsZero()) diff --git a/x/perp/keeper/liquidate_unit_test.go b/x/perp/keeper/liquidate_unit_test.go index a1f5243b1..fb6b8a0a4 100644 --- a/x/perp/keeper/liquidate_unit_test.go +++ b/x/perp/keeper/liquidate_unit_test.go @@ -144,13 +144,13 @@ func Test_distributeLiquidateRewards_Happy(t *testing.T) { expectedEvents := []sdk.Event{ events.NewTransferEvent( /* coin */ sdk.NewCoin("NUSD", sdk.OneInt()), - /* from */ vaultAddr.String(), - /* to */ perpEFAddr.String(), + /* from */ vaultAddr, + /* to */ perpEFAddr, ), events.NewTransferEvent( /* coin */ sdk.NewCoin("NUSD", sdk.OneInt()), - /* from */ vaultAddr.String(), - /* to */ liquidator.String(), + /* from */ vaultAddr, + /* to */ liquidator, ), } for _, event := range expectedEvents { @@ -472,16 +472,15 @@ func TestExecuteFullLiquidation_UnitWithMocks(t *testing.T) { t.Log("create and set the initial position") position := types.Position{ - Address: traderAddr.String(), + TraderAddress: traderAddr, Pair: pair.String(), Size_: tc.initialPositionSize, Margin: tc.initialMargin, OpenNotional: tc.initialOpenNotional, LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: ctx.BlockHeight(), } - perpKeeper.SetPosition(ctx, pair, traderAddr.String(), &position) + perpKeeper.SetPosition(ctx, pair, traderAddr, &position) t.Log("execute full liquidation") liquidationResp, err := perpKeeper.ExecuteFullLiquidation( @@ -501,7 +500,7 @@ func TestExecuteFullLiquidation_UnitWithMocks(t *testing.T) { positionResp.ExchangedQuoteAssetAmount) // amount of quote exchanged // Initial position size is sold back to to vpool assert.EqualValues(t, tc.initialPositionSize.Neg(), positionResp.ExchangedPositionSize) - // ( oldMargin + unrealzedPnL - fundingPayment ) * -1 + // ( oldMargin + unrealizedPnL - fundingPayment ) * -1 assert.EqualValues(t, tc.expectedMarginToVault, positionResp.MarginToVault) assert.EqualValues(t, tc.expectedPositionBadDebt, positionResp.BadDebt) assert.EqualValues(t, tc.expectedPositionRealizedPnl, positionResp.RealizedPnl) @@ -511,13 +510,12 @@ func TestExecuteFullLiquidation_UnitWithMocks(t *testing.T) { t.Log("assert new position fields") newPosition := positionResp.Position - assert.EqualValues(t, traderAddr.String(), newPosition.Address) + assert.EqualValues(t, traderAddr, newPosition.TraderAddress) assert.EqualValues(t, pair.String(), newPosition.Pair) assert.True(t, newPosition.Size_.IsZero()) // always zero assert.True(t, newPosition.Margin.IsZero()) // always zero assert.True(t, newPosition.OpenNotional.IsZero()) // always zero assert.True(t, newPosition.LastUpdateCumulativePremiumFraction.IsZero()) - assert.EqualValues(t, 0, newPosition.LiquidityHistoryIndex) assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) }) } diff --git a/x/perp/keeper/margin.go b/x/perp/keeper/margin.go index 0e4d920c9..38dcfea3d 100644 --- a/x/perp/keeper/margin.go +++ b/x/perp/keeper/margin.go @@ -21,12 +21,6 @@ func (k Keeper) AddMargin( ctx := sdk.UnwrapSDKContext(goCtx) - // validate trader - trader, err := sdk.AccAddressFromBech32(msg.Sender) - if err != nil { - return res, err - } - // validate margin amount addedMargin := msg.Margin.Amount if !addedMargin.IsPositive() { @@ -50,7 +44,7 @@ func (k Keeper) AddMargin( // ------------- AddMargin ------------- - position, err := k.Positions().Get(ctx, pair, trader.String()) + position, err := k.Positions().Get(ctx, pair, msg.Sender) if err != nil { return res, err } @@ -60,20 +54,20 @@ func (k Keeper) AddMargin( coinToSend := sdk.NewCoin(pair.GetQuoteTokenDenom(), addedMargin) vaultAddr := k.AccountKeeper.GetModuleAddress(types.VaultModuleAccount) if err = k.BankKeeper.SendCoinsFromAccountToModule( - ctx, trader, types.VaultModuleAccount, sdk.NewCoins(coinToSend), + ctx, msg.Sender, types.VaultModuleAccount, sdk.NewCoins(coinToSend), ); err != nil { return res, err } events.EmitTransfer(ctx, /* coin */ coinToSend, - /* from */ vaultAddr.String(), - /* to */ trader.String(), + /* from */ vaultAddr, + /* to */ msg.Sender, ) - k.Positions().Set(ctx, pair, trader.String(), position) + k.Positions().Set(ctx, pair, msg.Sender, position) fPayment := sdk.ZeroDec() - events.EmitMarginChange(ctx, trader, pair.String(), addedMargin, fPayment) + events.EmitMarginChange(ctx, msg.Sender, pair.String(), addedMargin, fPayment) return &types.MsgAddMarginResponse{}, nil } @@ -89,9 +83,9 @@ func (k Keeper) RemoveMargin( ctx := sdk.UnwrapSDKContext(goCtx) // validate trader - trader, err := sdk.AccAddressFromBech32(msg.Sender) - if err != nil { - return res, err + + if err = sdk.VerifyAddressFormat(msg.Sender); err != nil { + return nil, err } // validate margin amount @@ -117,7 +111,7 @@ func (k Keeper) RemoveMargin( // ------------- RemoveMargin ------------- - position, err := k.Positions().Get(ctx, pair, trader.String()) + position, err := k.Positions().Get(ctx, pair, msg.Sender) if err != nil { return res, err } @@ -142,11 +136,11 @@ func (k Keeper) RemoveMargin( return res, fmt.Errorf("not enough free collateral") } - k.Positions().Set(ctx, pair, trader.String(), position) + k.Positions().Set(ctx, pair, msg.Sender, position) coinToSend := sdk.NewCoin(pair.GetQuoteTokenDenom(), margin) err = k.BankKeeper.SendCoinsFromModuleToAccount( - ctx, types.VaultModuleAccount, trader, sdk.NewCoins(coinToSend)) + ctx, types.VaultModuleAccount, msg.Sender, sdk.NewCoins(coinToSend)) if err != nil { return res, err } @@ -154,11 +148,11 @@ func (k Keeper) RemoveMargin( events.EmitTransfer(ctx, /* coin */ coinToSend, - /* from */ vaultAddr.String(), - /* to */ trader.String(), + /* from */ vaultAddr, + /* to */ msg.Sender, ) - events.EmitMarginChange(ctx, trader, pair.String(), margin, remaining.FundingPayment) + events.EmitMarginChange(ctx, msg.Sender, pair.String(), margin, remaining.FundingPayment) return &types.MsgRemoveMarginResponse{ MarginOut: coinToSend, FundingPayment: remaining.FundingPayment, diff --git a/x/perp/keeper/margin_test.go b/x/perp/keeper/margin_test.go index 262cc3a56..9db2a7e1e 100644 --- a/x/perp/keeper/margin_test.go +++ b/x/perp/keeper/margin_test.go @@ -159,7 +159,7 @@ func TestAddMargin_ShouldRaiseError(t *testing.T) { t.Log("create msg for MsgAddMargin with invalid denom") traderAddr := sample.AccAddress() msg := &types.MsgAddMargin{ - Sender: traderAddr.String(), + Sender: traderAddr, TokenPair: tokenPair.String(), Margin: sdk.NewCoin("notADenom", sdk.NewInt(400)), } @@ -239,18 +239,18 @@ func TestAddMargin_HappyPath(t *testing.T) { nibiruApp.PerpKeeper.SetPosition( ctx, tokenPair, - traderAddr.String(), + traderAddr, &types.Position{ - Address: traderAddr.String(), - Pair: tokenPair.String(), - Size_: sdk.NewDec(9999), - Margin: tc.initialMargin.ToDec(), + TraderAddress: traderAddr, + Pair: tokenPair.String(), + Size_: sdk.NewDec(9999), + Margin: tc.initialMargin.ToDec(), }, ) goCtx := sdk.WrapSDKContext(ctx) msg := &types.MsgAddMargin{ - Sender: traderAddr.String(), TokenPair: tokenPair.String(), + Sender: traderAddr, TokenPair: tokenPair.String(), Margin: sdk.Coin{ Denom: tokenPair.GetQuoteTokenDenom(), Amount: tc.addedMargin}} @@ -258,9 +258,9 @@ func TestAddMargin_HappyPath(t *testing.T) { require.NoError(t, err) position, err := nibiruApp.PerpKeeper.GetPosition( - ctx, tokenPair, traderAddr.String()) + ctx, tokenPair, traderAddr) require.NoError(t, err) - require.Equal(t, tc.expectedMargin.String(), position.Margin.TruncateInt().String()) + require.EqualValues(t, tc.expectedMargin, position.Margin.TruncateInt()) }) } } @@ -280,7 +280,7 @@ func TestRemoveMargin(t *testing.T) { pair := common.TokenPair("osmo:nusd") goCtx := sdk.WrapSDKContext(ctx) msg := &types.MsgRemoveMargin{ - Sender: alice.String(), TokenPair: pair.String(), + Sender: alice, TokenPair: pair.String(), Margin: sdk.Coin{Denom: common.StableDenom, Amount: removeAmt}} _, err := nibiruApp.PerpKeeper.RemoveMargin(goCtx, msg) require.Error(t, err) @@ -297,7 +297,7 @@ func TestRemoveMargin(t *testing.T) { pair := common.TokenPair("osmo:nusd") goCtx := sdk.WrapSDKContext(ctx) msg := &types.MsgRemoveMargin{ - Sender: alice.String(), TokenPair: pair.String(), + Sender: alice, TokenPair: pair.String(), Margin: sdk.Coin{Denom: common.StableDenom, Amount: removeAmt}} _, err := nibiruApp.PerpKeeper.RemoveMargin(goCtx, msg) require.Error(t, err) @@ -314,7 +314,7 @@ func TestRemoveMargin(t *testing.T) { pair := common.TokenPair("osmo:nusd") goCtx := sdk.WrapSDKContext(ctx) msg := &types.MsgRemoveMargin{ - Sender: alice.String(), TokenPair: pair.String(), + Sender: alice, TokenPair: pair.String(), Margin: sdk.Coin{Denom: common.StableDenom, Amount: removeAmt}} _, err := nibiruApp.PerpKeeper.RemoveMargin(goCtx, msg) require.Error(t, err) @@ -338,14 +338,14 @@ func TestRemoveMargin(t *testing.T) { sdk.MustNewDecFromStr("0.9"), // 0.9 ratio /* y */ sdk.NewDec(1_000_000), // /* x */ sdk.NewDec(1_000_000), // - /* fluctLim */ sdk.MustNewDecFromStr("1.0"), // 100% + /* fluctuationLimit */ sdk.MustNewDecFromStr("1.0"), // 100% /* maxOracleSpreadRatio */ sdk.MustNewDecFromStr("1.0"), // 100% ) removeAmt := sdk.NewInt(5) goCtx := sdk.WrapSDKContext(ctx) msg := &types.MsgRemoveMargin{ - Sender: alice.String(), TokenPair: pair.String(), + Sender: alice, TokenPair: pair.String(), Margin: sdk.Coin{Denom: pair.GetQuoteTokenDenom(), Amount: removeAmt}} _, err := perpKeeper.RemoveMargin( goCtx, msg) @@ -371,7 +371,7 @@ func TestRemoveMargin(t *testing.T) { /* tradeLimitRatio */ sdk.MustNewDecFromStr("0.9"), // 0.9 ratio /* y */ quoteReserves, /* x */ baseReserves, - /* fluctLim */ sdk.MustNewDecFromStr("1.0"), // 0.9 ratio + /* fluctuationLimit */ sdk.MustNewDecFromStr("1.0"), // 0.9 ratio /* maxOracleSpreadRatio */ sdk.MustNewDecFromStr("0.4"), // 0.9 ratio ) require.True(t, vpoolKeeper.ExistsPool(ctx, pair)) @@ -407,16 +407,16 @@ func TestRemoveMargin(t *testing.T) { require.NoError(t, err) t.Log("Position should be accessible following 'OpenPosition'") - _, err = nibiruApp.PerpKeeper.GetPosition(ctx, pair, alice.String()) + _, err = nibiruApp.PerpKeeper.GetPosition(ctx, pair, alice) require.NoError(t, err) t.Log("Verify correct events emitted for 'OpenPosition'") expectedEvents := []sdk.Event{ events.NewTransferEvent( /* coin */ sdk.NewCoin(pair.GetQuoteTokenDenom(), quote), - /* from */ alice.String(), + /* from */ alice, /* to */ nibiruApp.AccountKeeper.GetModuleAddress( - types.VaultModuleAccount).String(), + types.VaultModuleAccount), ), // events.NewPositionChangeEvent(), TODO } @@ -428,7 +428,7 @@ func TestRemoveMargin(t *testing.T) { removeAmt := sdk.NewInt(6) goCtx := sdk.WrapSDKContext(ctx) msg := &types.MsgRemoveMargin{ - Sender: alice.String(), TokenPair: pair.String(), + Sender: alice, TokenPair: pair.String(), Margin: sdk.Coin{Denom: pair.GetQuoteTokenDenom(), Amount: removeAmt}} t.Log("'RemoveMargin' from the position") @@ -448,7 +448,7 @@ func TestRemoveMargin(t *testing.T) { events.NewTransferEvent( /* coin */ msg.Margin, /* from */ nibiruApp.AccountKeeper.GetModuleAddress( - types.VaultModuleAccount).String(), + types.VaultModuleAccount), /* to */ msg.Sender, ), } diff --git a/x/perp/keeper/margin_unit_test.go b/x/perp/keeper/margin_unit_test.go index 3e453fd1d..fb39fcf76 100644 --- a/x/perp/keeper/margin_unit_test.go +++ b/x/perp/keeper/margin_unit_test.go @@ -108,7 +108,7 @@ func TestGetMarginRatio_Unit(t *testing.T) { { name: "margin without price changes", position: types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), @@ -121,7 +121,7 @@ func TestGetMarginRatio_Unit(t *testing.T) { { name: "margin with price changes", position: types.Position{ - Address: sample.AccAddress().String(), + TraderAddress: sample.AccAddress(), Pair: "BTC:NUSD", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), @@ -182,11 +182,9 @@ func TestRemoveMargin_Unit(t *testing.T) { k, _, ctx := getKeeper(t) goCtx := sdk.WrapSDKContext(ctx) - invalidSender := "notABech32" - msg := &types.MsgRemoveMargin{Sender: invalidSender} + msg := &types.MsgRemoveMargin{Sender: []byte("")} _, err := k.RemoveMargin(goCtx, msg) require.Error(t, err) - require.ErrorContains(t, err, "decoding bech32 failed") }, }, { @@ -197,7 +195,8 @@ func TestRemoveMargin_Unit(t *testing.T) { alice := sample.AccAddress() the3pool := "dai:usdc:usdt" - msg := &types.MsgRemoveMargin{Sender: alice.String(), + msg := &types.MsgRemoveMargin{ + Sender: alice, TokenPair: the3pool, Margin: sdk.NewCoin(common.StableDenom, sdk.NewInt(5))} _, err := k.RemoveMargin(goCtx, msg) @@ -214,7 +213,8 @@ func TestRemoveMargin_Unit(t *testing.T) { t.Log("Build msg that specifies an impossible margin removal (too high)") alice := sample.AccAddress() pair := common.TokenPair("osmo:nusd") - msg := &types.MsgRemoveMargin{Sender: alice.String(), + msg := &types.MsgRemoveMargin{ + Sender: alice, TokenPair: pair.String(), Margin: sdk.NewCoin(pair.GetQuoteTokenDenom(), sdk.NewInt(600)), } @@ -230,8 +230,8 @@ func TestRemoveMargin_Unit(t *testing.T) { }) t.Log("Set an underwater position, positive bad debt due to excessive margin request") - k.SetPosition(ctx, pair, alice.String(), &types.Position{ - Address: alice.String(), + k.SetPosition(ctx, pair, alice, &types.Position{ + TraderAddress: alice, Pair: pair.String(), Size_: sdk.NewDec(1_000), OpenNotional: sdk.NewDec(1000), @@ -251,7 +251,8 @@ func TestRemoveMargin_Unit(t *testing.T) { goCtx := sdk.WrapSDKContext(ctx) alice := sample.AccAddress() - msg := &types.MsgRemoveMargin{Sender: alice.String(), + msg := &types.MsgRemoveMargin{ + Sender: alice, TokenPair: "osmo:nusd", Margin: sdk.NewCoin("nusd", sdk.NewInt(100)), } @@ -269,8 +270,8 @@ func TestRemoveMargin_Unit(t *testing.T) { }) t.Log("Set position a healthy position that has 0 unrealized funding") - k.SetPosition(ctx, pair, alice.String(), &types.Position{ - Address: alice.String(), + k.SetPosition(ctx, pair, alice, &types.Position{ + TraderAddress: alice, Pair: pair.String(), Size_: sdk.NewDec(1_000), OpenNotional: sdk.NewDec(1000), @@ -305,7 +306,8 @@ func TestRemoveMargin_Unit(t *testing.T) { goCtx := sdk.WrapSDKContext(ctx) alice := sample.AccAddress() - msg := &types.MsgRemoveMargin{Sender: alice.String(), + msg := &types.MsgRemoveMargin{ + Sender: alice, TokenPair: "osmo:nusd", Margin: sdk.NewCoin("nusd", sdk.NewInt(100)), } @@ -323,8 +325,8 @@ func TestRemoveMargin_Unit(t *testing.T) { }) t.Log("Set position a healthy position that has 0 unrealized funding") - k.SetPosition(ctx, pair, alice.String(), &types.Position{ - Address: alice.String(), + k.SetPosition(ctx, pair, alice, &types.Position{ + TraderAddress: alice, Pair: pair.String(), Size_: sdk.NewDec(1_000), OpenNotional: sdk.NewDec(1000), @@ -365,7 +367,7 @@ func TestRemoveMargin_Unit(t *testing.T) { ), events.NewTransferEvent( /* coin */ msg.Margin, - /* from */ vaultAddr.String(), + /* from */ vaultAddr, /* to */ msg.Sender, ), } @@ -373,11 +375,11 @@ func TestRemoveMargin_Unit(t *testing.T) { assert.Contains(t, ctx.EventManager().Events(), event) } - pos, err := k.GetPosition(ctx, pair, alice.String()) + pos, err := k.GetPosition(ctx, pair, alice) require.NoError(t, err) assert.EqualValues(t, sdk.NewDec(400).String(), pos.Margin.String()) assert.EqualValues(t, sdk.NewDec(1000).String(), pos.Size_.String()) - assert.EqualValues(t, alice.String(), pos.Address) + assert.EqualValues(t, alice, pos.TraderAddress) }, }, } diff --git a/x/perp/keeper/msg_server.go b/x/perp/keeper/msg_server.go index e6d225b39..06d84b8e7 100644 --- a/x/perp/keeper/msg_server.go +++ b/x/perp/keeper/msg_server.go @@ -29,19 +29,22 @@ func (k msgServer) AddMargin(ctx context.Context, margin *types.MsgAddMargin) (* return k.k.AddMargin(ctx, margin) } -func (k msgServer) OpenPosition(ctx context.Context, req *types.MsgOpenPosition) (*types.MsgOpenPositionResponse, error) { +func (k msgServer) OpenPosition(goCtx context.Context, req *types.MsgOpenPosition) (*types.MsgOpenPositionResponse, error) { pair, err := common.NewTokenPairFromStr(req.TokenPair) if err != nil { panic(err) // must not happen } - addr, err := sdk.AccAddressFromBech32(req.Sender) - if err != nil { - panic(err) // must not happen - } - - sdkCtx := sdk.UnwrapSDKContext(ctx) - err = k.k.OpenPosition(sdkCtx, pair, req.Side, addr, req.QuoteAssetAmount, req.Leverage, req.BaseAssetAmountLimit.ToDec()) + ctx := sdk.UnwrapSDKContext(goCtx) + err = k.k.OpenPosition( + ctx, + pair, + req.Side, + req.Sender, + req.QuoteAssetAmount, + req.Leverage, + req.BaseAssetAmountLimit.ToDec(), + ) if err != nil { return nil, err } diff --git a/x/perp/keeper/perp.go b/x/perp/keeper/perp.go index debdfaf51..0fe54c841 100644 --- a/x/perp/keeper/perp.go +++ b/x/perp/keeper/perp.go @@ -9,29 +9,28 @@ import ( ) // TODO test: ClearPosition | https://github.com/NibiruChain/nibiru/issues/299 -func (k Keeper) ClearPosition(ctx sdk.Context, pair common.TokenPair, trader string) error { +func (k Keeper) ClearPosition(ctx sdk.Context, pair common.TokenPair, traderAddr sdk.AccAddress) error { return k.Positions().Update(ctx, &types.Position{ - Address: trader, + TraderAddress: traderAddr, Pair: pair.String(), Size_: sdk.ZeroDec(), Margin: sdk.ZeroDec(), OpenNotional: sdk.ZeroDec(), LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: ctx.BlockHeight(), }) } func (k Keeper) GetPosition( - ctx sdk.Context, pair common.TokenPair, owner string, + ctx sdk.Context, pair common.TokenPair, traderAddr sdk.AccAddress, ) (*types.Position, error) { - return k.Positions().Get(ctx, pair, owner) + return k.Positions().Get(ctx, pair, traderAddr) } func (k Keeper) SetPosition( - ctx sdk.Context, pair common.TokenPair, owner string, + ctx sdk.Context, pair common.TokenPair, traderAddr sdk.AccAddress, position *types.Position) { - k.Positions().Set(ctx, pair, owner, position) + k.Positions().Set(ctx, pair, traderAddr, position) } // SettlePosition settles a trader position @@ -51,7 +50,7 @@ func (k Keeper) SettlePosition( err = k.ClearPosition( ctx, tokenPair, - currentPosition.Address, + currentPosition.TraderAddress, ) if err != nil { return @@ -82,11 +81,15 @@ func (k Keeper) SettlePosition( if settledValueInt.IsPositive() { toTransfer := sdk.NewCoin(tokenPair.GetQuoteTokenDenom(), settledValueInt) transferredCoins = sdk.NewCoins(toTransfer) - addr, err := sdk.AccAddressFromBech32(currentPosition.Address) if err != nil { panic(err) // NOTE(mercilex): must never happen } - err = k.BankKeeper.SendCoinsFromModuleToAccount(ctx, types.VaultModuleAccount, addr, transferredCoins) + err = k.BankKeeper.SendCoinsFromModuleToAccount( + ctx, + types.VaultModuleAccount, + currentPosition.TraderAddress, + transferredCoins, + ) if err != nil { panic(err) // NOTE(mercilex): must never happen } @@ -95,7 +98,7 @@ func (k Keeper) SettlePosition( events.EmitPositionSettle( ctx, tokenPair.String(), - currentPosition.Address, + currentPosition.TraderAddress.String(), transferredCoins, ) diff --git a/x/perp/keeper/perp_test.go b/x/perp/keeper/perp_test.go index 4b1d3243a..03042680a 100644 --- a/x/perp/keeper/perp_test.go +++ b/x/perp/keeper/perp_test.go @@ -26,7 +26,7 @@ func TestGetAndSetPosition(t *testing.T) { nibiruApp, ctx := testutil.NewNibiruApp(true) _, err := nibiruApp.PerpKeeper.GetPosition( - ctx, "osmo:nusd", trader.String()) + ctx, "osmo:nusd", trader) require.Error(t, err) require.ErrorContains(t, err, types.ErrPositionNotFound.Error()) }, @@ -37,24 +37,24 @@ func TestGetAndSetPosition(t *testing.T) { vpoolPair, err := common.NewTokenPairFromStr("osmo:nusd") require.NoError(t, err) - trader := sample.AccAddress() + traderAddr := sample.AccAddress() nibiruApp, ctx := testutil.NewNibiruApp(true) _, err = nibiruApp.PerpKeeper.GetPosition( - ctx, vpoolPair, trader.String()) + ctx, vpoolPair, traderAddr) require.Error(t, err) require.ErrorContains(t, err, types.ErrPositionNotFound.Error()) dummyPosition := &types.Position{ - Address: trader.String(), - Pair: vpoolPair.String(), - Size_: sdk.OneDec(), - Margin: sdk.OneDec(), + TraderAddress: traderAddr, + Pair: vpoolPair.String(), + Size_: sdk.OneDec(), + Margin: sdk.OneDec(), } nibiruApp.PerpKeeper.SetPosition( - ctx, vpoolPair, trader.String(), dummyPosition) + ctx, vpoolPair, traderAddr, dummyPosition) outPosition, err := nibiruApp.PerpKeeper.GetPosition( - ctx, vpoolPair, trader.String()) + ctx, vpoolPair, traderAddr) require.NoError(t, err) require.EqualValues(t, dummyPosition, outPosition) }, @@ -88,27 +88,27 @@ func TestClearPosition(t *testing.T) { t.Log("vpool contains no positions to start") for _, trader := range traders { _, err := nibiruApp.PerpKeeper.GetPosition( - ctx, vpoolPair, trader.String()) + ctx, vpoolPair, trader) require.Error(t, err) require.ErrorContains(t, err, types.ErrPositionNotFound.Error()) } var dummyPositions []*types.Position - for _, trader := range traders { + for _, traderAddr := range traders { dummyPosition := &types.Position{ - Address: trader.String(), - Pair: vpoolPair.String(), - Size_: sdk.OneDec(), - Margin: sdk.OneDec(), + TraderAddress: traderAddr, + Pair: vpoolPair.String(), + Size_: sdk.OneDec(), + Margin: sdk.OneDec(), } nibiruApp.PerpKeeper.SetPosition( - ctx, vpoolPair, trader.String(), dummyPosition) + ctx, vpoolPair, traderAddr, dummyPosition) outPosition, err := nibiruApp.PerpKeeper.GetPosition( - ctx, vpoolPair, trader.String()) + ctx, vpoolPair, traderAddr) require.NoError(t, err) require.EqualValues(t, dummyPosition, outPosition) t.Logf("position created successfully on vpool, %v, for trader %v", - vpoolPair, trader.String()) + vpoolPair, traderAddr.String()) dummyPositions = append(dummyPositions, dummyPosition) } @@ -116,19 +116,19 @@ func TestClearPosition(t *testing.T) { require.NoError(t, nibiruApp.PerpKeeper.ClearPosition( - ctx, vpoolPair, traders[0].String()), + ctx, vpoolPair, traders[0]), ) outPosition, err := nibiruApp.PerpKeeper.GetPosition( - ctx, vpoolPair, traders[0].String()) + ctx, vpoolPair, traders[0]) require.NoError(t, err) require.EqualValues(t, - types.ZeroPosition(ctx, vpoolPair, traders[0].String()), + types.ZeroPosition(ctx, vpoolPair, traders[0]), outPosition, ) outPosition, err = nibiruApp.PerpKeeper.GetPosition( - ctx, vpoolPair, traders[1].String()) + ctx, vpoolPair, traders[1]) require.NoError(t, err) require.EqualValues(t, dummyPositions[1], outPosition) t.Log("trader 1 has a position and trader 0 does not.") @@ -136,13 +136,13 @@ func TestClearPosition(t *testing.T) { t.Log("clearing position of trader 1...") require.NoError(t, nibiruApp.PerpKeeper.ClearPosition( - ctx, vpoolPair, traders[1].String()), + ctx, vpoolPair, traders[1]), ) outPosition, err = nibiruApp.PerpKeeper.GetPosition( - ctx, vpoolPair, traders[1].String()) + ctx, vpoolPair, traders[1]) require.NoError(t, err) require.EqualValues(t, - types.ZeroPosition(ctx, vpoolPair, traders[1].String()), + types.ZeroPosition(ctx, vpoolPair, traders[1]), outPosition, ) t.Log("Success, all trader positions have been cleared.") diff --git a/x/perp/keeper/perp_unit_test.go b/x/perp/keeper/perp_unit_test.go index e533b3020..022814fe4 100644 --- a/x/perp/keeper/perp_unit_test.go +++ b/x/perp/keeper/perp_unit_test.go @@ -15,7 +15,7 @@ import ( func TestSettlePosition(t *testing.T) { t.Run("success - settlement price zero", func(t *testing.T) { k, dep, ctx := getKeeper(t) - addr := sample.AccAddress() + traderAddr := sample.AccAddress() pair, err := common.NewTokenPairFromStr("LUNA:UST") require.NoError(t, err) @@ -26,17 +26,17 @@ func TestSettlePosition(t *testing.T) { dep.mockBankKeeper.EXPECT(). SendCoinsFromModuleToAccount( - ctx, types.VaultModuleAccount, addr, + ctx, types.VaultModuleAccount, traderAddr, sdk.NewCoins(sdk.NewCoin("UST", sdk.NewInt(100))), ). Return(error(nil)) pos := types.Position{ - Address: addr.String(), - Pair: pair.String(), - Size_: sdk.NewDec(10), - Margin: sdk.NewDec(100), - OpenNotional: sdk.NewDec(1000), + TraderAddress: traderAddr, + Pair: pair.String(), + Size_: sdk.NewDec(10), + Margin: sdk.NewDec(100), + OpenNotional: sdk.NewDec(1000), } err = k.Positions().Create(ctx, &pos) require.NoError(t, err) @@ -51,7 +51,7 @@ func TestSettlePosition(t *testing.T) { t.Run("success - settlement price not zero", func(t *testing.T) { k, dep, ctx := getKeeper(t) - addr := sample.AccAddress() + traderAddr := sample.AccAddress() pair, err := common.NewTokenPairFromStr("LUNA:UST") // memeing require.NoError(t, err) @@ -62,7 +62,7 @@ func TestSettlePosition(t *testing.T) { dep.mockBankKeeper.EXPECT(). SendCoinsFromModuleToAccount( - ctx, types.VaultModuleAccount, addr, sdk.NewCoins(sdk.NewCoin("UST", sdk.NewInt(99_100)))). + ctx, types.VaultModuleAccount, traderAddr, sdk.NewCoins(sdk.NewCoin("UST", sdk.NewInt(99_100)))). Return(error(nil)) // this means that the user @@ -76,11 +76,11 @@ func TestSettlePosition(t *testing.T) { // we also need to return margin which is 100coin // so total is 99_100 coin pos := types.Position{ - Address: addr.String(), - Pair: pair.String(), - Size_: sdk.NewDec(100), - Margin: sdk.NewDec(100), - OpenNotional: sdk.NewDec(1000), + TraderAddress: traderAddr, + Pair: pair.String(), + Size_: sdk.NewDec(100), + Margin: sdk.NewDec(100), + OpenNotional: sdk.NewDec(1000), } err = k.Positions().Create(ctx, &pos) require.NoError(t, err) @@ -93,14 +93,14 @@ func TestSettlePosition(t *testing.T) { t.Run("position size is zero", func(t *testing.T) { k, _, ctx := getKeeper(t) - addr := sample.AccAddress() + traderAddr := sample.AccAddress() pair, err := common.NewTokenPairFromStr("LUNA:UST") require.NoError(t, err) pos := types.Position{ - Address: addr.String(), - Pair: pair.String(), - Size_: sdk.ZeroDec(), + TraderAddress: traderAddr, + Pair: pair.String(), + Size_: sdk.ZeroDec(), } err = k.Positions().Create(ctx, &pos) require.NoError(t, err) diff --git a/x/perp/keeper/state.go b/x/perp/keeper/state.go index 8ca31614f..a9d0135de 100644 --- a/x/perp/keeper/state.go +++ b/x/perp/keeper/state.go @@ -79,12 +79,12 @@ func (p PositionsState) getKV(ctx sdk.Context) sdk.KVStore { } func (p PositionsState) keyFromType(position *types.Position) []byte { - return p.keyFromRaw(common.TokenPair(position.Pair), position.Address) + return p.keyFromRaw(common.TokenPair(position.Pair), position.TraderAddress) } -func (p PositionsState) keyFromRaw(pair common.TokenPair, address string) []byte { +func (p PositionsState) keyFromRaw(pair common.TokenPair, address sdk.AccAddress) []byte { // TODO(mercilex): not sure if namespace overlap safe | update(mercilex) it is not overlap safe - return []byte(pair.String() + address) + return []byte(pair.String() + address.String()) } func (p PositionsState) Create(ctx sdk.Context, position *types.Position) error { @@ -98,10 +98,10 @@ func (p PositionsState) Create(ctx sdk.Context, position *types.Position) error return nil } -func (p PositionsState) Get(ctx sdk.Context, pair common.TokenPair, address string) (*types.Position, error) { +func (p PositionsState) Get(ctx sdk.Context, pair common.TokenPair, traderAddr sdk.AccAddress) (*types.Position, error) { kv := p.getKV(ctx) - key := p.keyFromRaw(pair, address) + key := p.keyFromRaw(pair, traderAddr) valueBytes := kv.Get(key) if valueBytes == nil { return nil, types.ErrPositionNotFound @@ -126,9 +126,9 @@ func (p PositionsState) Update(ctx sdk.Context, position *types.Position) error } func (p PositionsState) Set( - ctx sdk.Context, pair common.TokenPair, owner string, position *types.Position, + ctx sdk.Context, pair common.TokenPair, traderAddr sdk.AccAddress, position *types.Position, ) { - positionID := p.keyFromRaw(pair, owner) + positionID := p.keyFromRaw(pair, traderAddr) kvStore := p.getKV(ctx) kvStore.Set(positionID, p.cdc.MustMarshal(position)) } diff --git a/x/perp/types/msgs.go b/x/perp/types/msgs.go index 42ab9900f..9b842da2f 100644 --- a/x/perp/types/msgs.go +++ b/x/perp/types/msgs.go @@ -26,8 +26,7 @@ func (m MsgRemoveMargin) GetSignBytes() []byte { } func (m MsgRemoveMargin) GetSigners() []sdk.AccAddress { - sender, _ := sdk.AccAddressFromBech32(m.Sender) - return []sdk.AccAddress{sender} + return []sdk.AccAddress{m.Sender} } // MsgAddMargin @@ -44,8 +43,7 @@ func (m MsgAddMargin) GetSignBytes() []byte { } func (m MsgAddMargin) GetSigners() []sdk.AccAddress { - sender, _ := sdk.AccAddressFromBech32(m.Sender) - return []sdk.AccAddress{sender} + return []sdk.AccAddress{m.Sender} } func (m *MsgOpenPosition) ValidateBasic() error { @@ -55,7 +53,7 @@ func (m *MsgOpenPosition) ValidateBasic() error { if _, err := common.NewTokenPairFromStr(m.TokenPair); err != nil { return err } - if _, err := sdk.AccAddressFromBech32(m.Sender); err != nil { + if err := sdk.VerifyAddressFormat(m.Sender); err != nil { return err } if !m.Leverage.GT(sdk.ZeroDec()) { @@ -72,10 +70,5 @@ func (m *MsgOpenPosition) ValidateBasic() error { } func (m *MsgOpenPosition) GetSigners() []sdk.AccAddress { - addr, err := sdk.AccAddressFromBech32(m.Sender) - if err != nil { - panic(err) - } - - return []sdk.AccAddress{addr} + return []sdk.AccAddress{m.Sender} } diff --git a/x/perp/types/msgs_test.go b/x/perp/types/msgs_test.go index 8b1734e90..b895f39f8 100644 --- a/x/perp/types/msgs_test.go +++ b/x/perp/types/msgs_test.go @@ -17,7 +17,7 @@ func TestMsgOpenPosition_ValidateBasic(t *testing.T) { cases := map[string]test{ "ok": { msg: &MsgOpenPosition{ - Sender: sample.AccAddress().String(), + Sender: sample.AccAddress(), TokenPair: "NIBI:USDN", Side: Side_BUY, QuoteAssetAmount: sdk.NewInt(100), @@ -29,7 +29,7 @@ func TestMsgOpenPosition_ValidateBasic(t *testing.T) { "invalid side": { msg: &MsgOpenPosition{ - Sender: sample.AccAddress().String(), + Sender: sample.AccAddress(), TokenPair: "NIBI:USDN", Side: 2, QuoteAssetAmount: sdk.NewInt(100), @@ -40,7 +40,7 @@ func TestMsgOpenPosition_ValidateBasic(t *testing.T) { }, "invalid address": { msg: &MsgOpenPosition{ - Sender: "", + Sender: []byte(""), TokenPair: "NIBI:USDN", Side: Side_SELL, QuoteAssetAmount: sdk.NewInt(100), @@ -51,7 +51,7 @@ func TestMsgOpenPosition_ValidateBasic(t *testing.T) { }, "invalid leverage": { msg: &MsgOpenPosition{ - Sender: sample.AccAddress().String(), + Sender: sample.AccAddress(), TokenPair: "NIBI:USDN", Side: Side_BUY, QuoteAssetAmount: sdk.NewInt(100), @@ -62,7 +62,7 @@ func TestMsgOpenPosition_ValidateBasic(t *testing.T) { }, "invalid quote asset amount": { msg: &MsgOpenPosition{ - Sender: sample.AccAddress().String(), + Sender: sample.AccAddress(), TokenPair: "NIBI:USDN", Side: Side_BUY, QuoteAssetAmount: sdk.NewInt(0), @@ -73,7 +73,7 @@ func TestMsgOpenPosition_ValidateBasic(t *testing.T) { }, "invalid token pair": { msg: &MsgOpenPosition{ - Sender: sample.AccAddress().String(), + Sender: sample.AccAddress(), TokenPair: "NIBI-USDN", Side: Side_BUY, QuoteAssetAmount: sdk.NewInt(0), @@ -84,7 +84,7 @@ func TestMsgOpenPosition_ValidateBasic(t *testing.T) { }, "invalid base asset amount limit": { msg: &MsgOpenPosition{ - Sender: sample.AccAddress().String(), + Sender: sample.AccAddress(), TokenPair: "NIBI:USDN", Side: Side_BUY, QuoteAssetAmount: sdk.NewInt(0), diff --git a/x/perp/types/state.pb.go b/x/perp/types/state.pb.go index 3d6422396..17873bc91 100644 --- a/x/perp/types/state.pb.go +++ b/x/perp/types/state.pb.go @@ -273,17 +273,21 @@ func (m *GenesisState) GetModuleAccountBalance() types.Coin { // the virtual liquidity pools. type Position struct { // address identifies the address owner of this position - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + TraderAddress github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=trader_address,json=traderAddress,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"trader_address,omitempty"` // pair identifies the pair associated with this position - Pair string `protobuf:"bytes,2,opt,name=pair,proto3" json:"pair,omitempty"` - Size_ github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=size,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"size"` + Pair string `protobuf:"bytes,2,opt,name=pair,proto3" json:"pair,omitempty"` + // Position size. + Size_ github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=size,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"size"` + // Amount of margin remaining in the position. Margin github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=margin,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"margin"` // OpenNotional is the quote denom value of the position when opening. - OpenNotional github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=open_notional,json=openNotional,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"open_notional"` + // Used to calculate PnL. + OpenNotional github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=open_notional,json=openNotional,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"open_notional"` + // The last cumulative funding payment this position has applied. + // Used to calculate the next funding payment. LastUpdateCumulativePremiumFraction github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,6,opt,name=last_update_cumulative_premium_fraction,json=lastUpdateCumulativePremiumFraction,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"last_update_cumulative_premium_fraction"` - LiquidityHistoryIndex int64 `protobuf:"varint,7,opt,name=liquidity_history_index,json=liquidityHistoryIndex,proto3" json:"liquidity_history_index,omitempty"` // BlockNumber is the block number of the change to the position. - BlockNumber int64 `protobuf:"varint,8,opt,name=block_number,json=blockNumber,proto3" json:"block_number,omitempty"` + BlockNumber int64 `protobuf:"varint,7,opt,name=block_number,json=blockNumber,proto3" json:"block_number,omitempty"` } func (m *Position) Reset() { *m = Position{} } @@ -319,11 +323,11 @@ func (m *Position) XXX_DiscardUnknown() { var xxx_messageInfo_Position proto.InternalMessageInfo -func (m *Position) GetAddress() string { +func (m *Position) GetTraderAddress() github_com_cosmos_cosmos_sdk_types.AccAddress { if m != nil { - return m.Address + return m.TraderAddress } - return "" + return nil } func (m *Position) GetPair() string { @@ -333,13 +337,6 @@ func (m *Position) GetPair() string { return "" } -func (m *Position) GetLiquidityHistoryIndex() int64 { - if m != nil { - return m.LiquidityHistoryIndex - } - return 0 -} - func (m *Position) GetBlockNumber() int64 { if m != nil { return m.BlockNumber @@ -458,59 +455,6 @@ func (m *LiquidateResp) GetPositionResp() *PositionResp { return nil } -type VirtualPoolInfo struct { - Pair string `protobuf:"bytes,1,opt,name=pair,proto3" json:"pair,omitempty"` - LastRestrictionBlock int64 `protobuf:"varint,2,opt,name=last_restriction_block,json=lastRestrictionBlock,proto3" json:"last_restriction_block,omitempty"` - CumulativePremiumFractions []github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,rep,name=cumulative_premium_fractions,json=cumulativePremiumFractions,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"cumulative_premium_fractions"` -} - -func (m *VirtualPoolInfo) Reset() { *m = VirtualPoolInfo{} } -func (m *VirtualPoolInfo) String() string { return proto.CompactTextString(m) } -func (*VirtualPoolInfo) ProtoMessage() {} -func (*VirtualPoolInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_0416b6ef16ef80be, []int{5} -} -func (m *VirtualPoolInfo) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *VirtualPoolInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_VirtualPoolInfo.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *VirtualPoolInfo) XXX_Merge(src proto.Message) { - xxx_messageInfo_VirtualPoolInfo.Merge(m, src) -} -func (m *VirtualPoolInfo) XXX_Size() int { - return m.Size() -} -func (m *VirtualPoolInfo) XXX_DiscardUnknown() { - xxx_messageInfo_VirtualPoolInfo.DiscardUnknown(m) -} - -var xxx_messageInfo_VirtualPoolInfo proto.InternalMessageInfo - -func (m *VirtualPoolInfo) GetPair() string { - if m != nil { - return m.Pair - } - return "" -} - -func (m *VirtualPoolInfo) GetLastRestrictionBlock() int64 { - if m != nil { - return m.LastRestrictionBlock - } - return 0 -} - type PairMetadata struct { Pair string `protobuf:"bytes,1,opt,name=pair,proto3" json:"pair,omitempty"` CumulativePremiumFractions []github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,rep,name=cumulative_premium_fractions,json=cumulativePremiumFractions,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"cumulative_premium_fractions"` @@ -520,7 +464,7 @@ func (m *PairMetadata) Reset() { *m = PairMetadata{} } func (m *PairMetadata) String() string { return proto.CompactTextString(m) } func (*PairMetadata) ProtoMessage() {} func (*PairMetadata) Descriptor() ([]byte, []int) { - return fileDescriptor_0416b6ef16ef80be, []int{6} + return fileDescriptor_0416b6ef16ef80be, []int{5} } func (m *PairMetadata) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -557,26 +501,26 @@ func (m *PairMetadata) GetPair() string { } type PositionChangedEvent struct { - Trader string `protobuf:"bytes,1,opt,name=trader,proto3" json:"trader,omitempty"` - Pair string `protobuf:"bytes,2,opt,name=pair,proto3" json:"pair,omitempty"` - Margin github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=margin,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"margin"` - PositionNotional github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=position_notional,json=positionNotional,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"position_notional"` - ExchangedPositionSize github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=exchanged_position_size,json=exchangedPositionSize,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"exchanged_position_size"` - Fee github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,6,opt,name=fee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"fee"` - PositionSizeAfter github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,7,opt,name=position_size_after,json=positionSizeAfter,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"position_size_after"` - RealizedPnl github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,8,opt,name=realized_pnl,json=realizedPnl,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"realized_pnl"` - UnrealizedPnlAfter github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,9,opt,name=unrealized_pnl_after,json=unrealizedPnlAfter,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"unrealized_pnl_after"` - BadDebt github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,10,opt,name=bad_debt,json=badDebt,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"bad_debt"` - LiquidationPenalty github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,11,opt,name=liquidation_penalty,json=liquidationPenalty,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"liquidation_penalty"` - SpotPrice github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,12,opt,name=spot_price,json=spotPrice,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"spot_price"` - FundingPayment github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,13,opt,name=funding_payment,json=fundingPayment,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"funding_payment"` + TraderAddress github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=trader_address,json=traderAddress,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"trader_address,omitempty"` + Pair string `protobuf:"bytes,2,opt,name=pair,proto3" json:"pair,omitempty"` + Margin github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=margin,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"margin"` + PositionNotional github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=position_notional,json=positionNotional,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"position_notional"` + ExchangedPositionSize github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=exchanged_position_size,json=exchangedPositionSize,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"exchanged_position_size"` + Fee github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,6,opt,name=fee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"fee"` + PositionSizeAfter github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,7,opt,name=position_size_after,json=positionSizeAfter,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"position_size_after"` + RealizedPnl github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,8,opt,name=realized_pnl,json=realizedPnl,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"realized_pnl"` + UnrealizedPnlAfter github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,9,opt,name=unrealized_pnl_after,json=unrealizedPnlAfter,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"unrealized_pnl_after"` + BadDebt github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,10,opt,name=bad_debt,json=badDebt,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"bad_debt"` + LiquidationPenalty github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,11,opt,name=liquidation_penalty,json=liquidationPenalty,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"liquidation_penalty"` + SpotPrice github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,12,opt,name=spot_price,json=spotPrice,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"spot_price"` + FundingPayment github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,13,opt,name=funding_payment,json=fundingPayment,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"funding_payment"` } func (m *PositionChangedEvent) Reset() { *m = PositionChangedEvent{} } func (m *PositionChangedEvent) String() string { return proto.CompactTextString(m) } func (*PositionChangedEvent) ProtoMessage() {} func (*PositionChangedEvent) Descriptor() ([]byte, []int) { - return fileDescriptor_0416b6ef16ef80be, []int{7} + return fileDescriptor_0416b6ef16ef80be, []int{6} } func (m *PositionChangedEvent) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -605,11 +549,11 @@ func (m *PositionChangedEvent) XXX_DiscardUnknown() { var xxx_messageInfo_PositionChangedEvent proto.InternalMessageInfo -func (m *PositionChangedEvent) GetTrader() string { +func (m *PositionChangedEvent) GetTraderAddress() github_com_cosmos_cosmos_sdk_types.AccAddress { if m != nil { - return m.Trader + return m.TraderAddress } - return "" + return nil } func (m *PositionChangedEvent) GetPair() string { @@ -629,7 +573,6 @@ func init() { proto.RegisterType((*Position)(nil), "nibiru.perp.v1.Position") proto.RegisterType((*PositionResp)(nil), "nibiru.perp.v1.PositionResp") proto.RegisterType((*LiquidateResp)(nil), "nibiru.perp.v1.LiquidateResp") - proto.RegisterType((*VirtualPoolInfo)(nil), "nibiru.perp.v1.VirtualPoolInfo") proto.RegisterType((*PairMetadata)(nil), "nibiru.perp.v1.PairMetadata") proto.RegisterType((*PositionChangedEvent)(nil), "nibiru.perp.v1.PositionChangedEvent") } @@ -637,91 +580,86 @@ func init() { func init() { proto.RegisterFile("perp/v1/state.proto", fileDescriptor_0416b6ef16ef80be) } var fileDescriptor_0416b6ef16ef80be = []byte{ - // 1342 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x57, 0xcd, 0x6e, 0x1b, 0xb7, - 0x16, 0xd6, 0x58, 0xb6, 0x24, 0x1f, 0xc9, 0xb6, 0x42, 0x3b, 0x8e, 0x6c, 0x38, 0xb2, 0xaf, 0x2e, - 0xee, 0x4d, 0x60, 0x20, 0x12, 0x9c, 0xa6, 0x5d, 0x64, 0x15, 0x49, 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, 0x60, 0x29, 0xe2, 0xa3, 0xc1, 0x62, 0xd2, 0x95, 0x09, 0x33, 0xc7, 0x07, - 0x47, 0x67, 0x58, 0x26, 0x77, 0xeb, 0x0a, 0xa9, 0xf2, 0x53, 0x1a, 0xe6, 0x06, 0x12, 0x4d, 0x35, - 0xa3, 0x47, 0xa9, 0x62, 0x5c, 0x8c, 0x2a, 0x4f, 0xe0, 0x4a, 0x97, 0x52, 0x95, 0x93, 0x41, 0x97, - 0x10, 0xc1, 0x84, 0xdc, 0x5e, 0xe8, 0x52, 0x7a, 0x24, 0xda, 0x43, 0x18, 0xf4, 0x2d, 0xac, 0x26, - 0xd8, 0xea, 0x9e, 0x61, 0x6a, 0x8b, 0xb0, 0x1f, 0x4a, 0xea, 0x61, 0x55, 0xed, 0x09, 0x39, 0xbe, - 0xac, 0x37, 0x31, 0x69, 0xe0, 0xef, 0x0c, 0xe0, 0x76, 0x23, 0xee, 0xa0, 0xfb, 0x00, 0x23, 0x07, - 0x50, 0x2c, 0x2f, 0x34, 0xb6, 0xde, 0x9e, 0xae, 0xdf, 0xfa, 0x17, 0xb8, 0x75, 0xdb, 0xae, 0xc7, - 0x3d, 0xc1, 0x1a, 0x01, 0x41, 0x75, 0x98, 0x1b, 0xde, 0x9d, 0x80, 0x86, 0xbe, 0xe6, 0x76, 0xfe, - 0xf6, 0xda, 0x07, 0xc5, 0x83, 0x86, 0xbe, 0x55, 0xf0, 0x47, 0x46, 0x95, 0x5f, 0x0c, 0x58, 0x78, - 0xc8, 0x02, 0x19, 0x11, 0xd7, 0x14, 0xc2, 0x6d, 0xf1, 0xae, 0x18, 0xb6, 0x1d, 0x63, 0xa4, 0xed, - 0xdc, 0x81, 0x65, 0x2d, 0xca, 0x01, 0x0d, 0x65, 0xc0, 0xb4, 0x44, 0x62, 0xad, 0x69, 0xba, 0x14, - 0x69, 0x6b, 0x49, 0x59, 0xad, 0x33, 0x63, 0x43, 0xd9, 0x90, 0x0f, 0x6b, 0x1f, 0x91, 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74, 0x32, 0xfa, 0x63, 0xf7, 0x93, - 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x8e, 0xde, 0x18, 0xdb, 0x64, 0x0f, 0x00, 0x00, + // 1258 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x97, 0x4f, 0x4f, 0x1b, 0x47, + 0x18, 0xc6, 0xbd, 0xd8, 0x80, 0x79, 0x6d, 0x83, 0x33, 0x50, 0x62, 0x10, 0x31, 0xd4, 0x55, 0x9b, + 0x08, 0x29, 0xb6, 0x48, 0xd3, 0x4b, 0x4e, 0xb1, 0x0d, 0x54, 0x48, 0x06, 0x36, 0x86, 0x24, 0x34, + 0x95, 0x3a, 0x1d, 0xef, 0xbe, 0x86, 0x6d, 0x76, 0x67, 0x36, 0xbb, 0xb3, 0x56, 0xc8, 0xb5, 0xfd, + 0x00, 0x3d, 0xf4, 0x9b, 0xf4, 0xd2, 0x43, 0x3e, 0x40, 0x4e, 0x55, 0x8e, 0x55, 0x0f, 0xa8, 0x4a, + 0xbe, 0x41, 0x8f, 0x3d, 0x55, 0x33, 0xbb, 0x36, 0x8e, 0xf2, 0x47, 0x65, 0x89, 0x7a, 0xb2, 0x67, + 0xe6, 0x9d, 0xdf, 0xce, 0xbc, 0xf3, 0xcc, 0xf3, 0xee, 0xc2, 0xbc, 0x8f, 0x81, 0xdf, 0x18, 0x6c, + 0x34, 0x42, 0xc9, 0x24, 0xd6, 0xfd, 0x40, 0x48, 0x41, 0x66, 0xb9, 0xd3, 0x73, 0x82, 0xa8, 0xae, + 0xc6, 0xea, 0x83, 0x8d, 0xe5, 0x85, 0x63, 0x71, 0x2c, 0xf4, 0x50, 0x43, 0xfd, 0x8b, 0xa3, 0x96, + 0xab, 0x96, 0x08, 0x3d, 0x11, 0x36, 0x7a, 0x2c, 0xc4, 0xc6, 0x60, 0xa3, 0x87, 0x92, 0x6d, 0x34, + 0x2c,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0x11, 0x70, 0xc7, 0x51, 0xde, 0x0e, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -853,11 +791,6 @@ func (m *Position) MarshalToSizedBuffer(dAtA []byte) (int, error) { if m.BlockNumber != 0 { i = encodeVarintState(dAtA, i, uint64(m.BlockNumber)) i-- - dAtA[i] = 0x40 - } - if m.LiquidityHistoryIndex != 0 { - i = encodeVarintState(dAtA, i, uint64(m.LiquidityHistoryIndex)) - i-- dAtA[i] = 0x38 } { @@ -907,10 +840,10 @@ func (m *Position) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - if len(m.Address) > 0 { - i -= len(m.Address) - copy(dAtA[i:], m.Address) - i = encodeVarintState(dAtA, i, uint64(len(m.Address))) + if len(m.TraderAddress) > 0 { + i -= len(m.TraderAddress) + copy(dAtA[i:], m.TraderAddress) + i = encodeVarintState(dAtA, i, uint64(len(m.TraderAddress))) i-- dAtA[i] = 0xa } @@ -1094,55 +1027,6 @@ func (m *LiquidateResp) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *VirtualPoolInfo) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *VirtualPoolInfo) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *VirtualPoolInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.CumulativePremiumFractions) > 0 { - for iNdEx := len(m.CumulativePremiumFractions) - 1; iNdEx >= 0; iNdEx-- { - { - size := m.CumulativePremiumFractions[iNdEx].Size() - i -= size - if _, err := m.CumulativePremiumFractions[iNdEx].MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintState(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - } - if m.LastRestrictionBlock != 0 { - i = encodeVarintState(dAtA, i, uint64(m.LastRestrictionBlock)) - i-- - dAtA[i] = 0x10 - } - if len(m.Pair) > 0 { - i -= len(m.Pair) - copy(dAtA[i:], m.Pair) - i = encodeVarintState(dAtA, i, uint64(len(m.Pair))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func (m *PairMetadata) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1324,10 +1208,10 @@ func (m *PositionChangedEvent) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - if len(m.Trader) > 0 { - i -= len(m.Trader) - copy(dAtA[i:], m.Trader) - i = encodeVarintState(dAtA, i, uint64(len(m.Trader))) + if len(m.TraderAddress) > 0 { + i -= len(m.TraderAddress) + copy(dAtA[i:], m.TraderAddress) + i = encodeVarintState(dAtA, i, uint64(len(m.TraderAddress))) i-- dAtA[i] = 0xa } @@ -1390,7 +1274,7 @@ func (m *Position) Size() (n int) { } var l int _ = l - l = len(m.Address) + l = len(m.TraderAddress) if l > 0 { n += 1 + l + sovState(uint64(l)) } @@ -1406,9 +1290,6 @@ func (m *Position) Size() (n int) { n += 1 + l + sovState(uint64(l)) l = m.LastUpdateCumulativePremiumFraction.Size() n += 1 + l + sovState(uint64(l)) - if m.LiquidityHistoryIndex != 0 { - n += 1 + sovState(uint64(m.LiquidityHistoryIndex)) - } if m.BlockNumber != 0 { n += 1 + sovState(uint64(m.BlockNumber)) } @@ -1465,28 +1346,6 @@ func (m *LiquidateResp) Size() (n int) { return n } -func (m *VirtualPoolInfo) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Pair) - if l > 0 { - n += 1 + l + sovState(uint64(l)) - } - if m.LastRestrictionBlock != 0 { - n += 1 + sovState(uint64(m.LastRestrictionBlock)) - } - if len(m.CumulativePremiumFractions) > 0 { - for _, e := range m.CumulativePremiumFractions { - l = e.Size() - n += 1 + l + sovState(uint64(l)) - } - } - return n -} - func (m *PairMetadata) Size() (n int) { if m == nil { return 0 @@ -1512,7 +1371,7 @@ func (m *PositionChangedEvent) Size() (n int) { } var l int _ = l - l = len(m.Trader) + l = len(m.TraderAddress) if l > 0 { n += 1 + l + sovState(uint64(l)) } @@ -1878,9 +1737,9 @@ func (m *Position) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field TraderAddress", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowState @@ -1890,23 +1749,25 @@ func (m *Position) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthState } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthState } if postIndex > l { return io.ErrUnexpectedEOF } - m.Address = string(dAtA[iNdEx:postIndex]) + m.TraderAddress = append(m.TraderAddress[:0], dAtA[iNdEx:postIndex]...) + if m.TraderAddress == nil { + m.TraderAddress = []byte{} + } iNdEx = postIndex case 2: if wireType != 2 { @@ -2077,25 +1938,6 @@ func (m *Position) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 7: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field LiquidityHistoryIndex", wireType) - } - m.LiquidityHistoryIndex = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowState - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.LiquidityHistoryIndex |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 8: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field BlockNumber", wireType) } @@ -2681,143 +2523,6 @@ func (m *LiquidateResp) Unmarshal(dAtA []byte) error { } return nil } -func (m *VirtualPoolInfo) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowState - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: VirtualPoolInfo: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: VirtualPoolInfo: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pair", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowState - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthState - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthState - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Pair = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field LastRestrictionBlock", wireType) - } - m.LastRestrictionBlock = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowState - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.LastRestrictionBlock |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CumulativePremiumFractions", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowState - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthState - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthState - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var v github_com_cosmos_cosmos_sdk_types.Dec - m.CumulativePremiumFractions = append(m.CumulativePremiumFractions, v) - if err := m.CumulativePremiumFractions[len(m.CumulativePremiumFractions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipState(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthState - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *PairMetadata) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -2967,9 +2672,9 @@ func (m *PositionChangedEvent) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Trader", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field TraderAddress", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowState @@ -2979,23 +2684,25 @@ func (m *PositionChangedEvent) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthState } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthState } if postIndex > l { return io.ErrUnexpectedEOF } - m.Trader = string(dAtA[iNdEx:postIndex]) + m.TraderAddress = append(m.TraderAddress[:0], dAtA[iNdEx:postIndex]...) + if m.TraderAddress == nil { + m.TraderAddress = []byte{} + } iNdEx = postIndex case 2: if wireType != 2 { diff --git a/x/perp/types/tx.pb.go b/x/perp/types/tx.pb.go index 584e6b674..c6b35262c 100644 --- a/x/perp/types/tx.pb.go +++ b/x/perp/types/tx.pb.go @@ -33,9 +33,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // MsgRemoveMargin: Msg to remove margin. type MsgRemoveMargin struct { - Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` - TokenPair string `protobuf:"bytes,2,opt,name=token_pair,json=tokenPair,proto3" json:"token_pair,omitempty"` - Margin types.Coin `protobuf:"bytes,3,opt,name=margin,proto3" json:"margin"` + Sender github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=sender,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"sender,omitempty"` + TokenPair string `protobuf:"bytes,2,opt,name=token_pair,json=tokenPair,proto3" json:"token_pair,omitempty"` + Margin types.Coin `protobuf:"bytes,3,opt,name=margin,proto3" json:"margin"` } func (m *MsgRemoveMargin) Reset() { *m = MsgRemoveMargin{} } @@ -71,11 +71,11 @@ func (m *MsgRemoveMargin) XXX_DiscardUnknown() { var xxx_messageInfo_MsgRemoveMargin proto.InternalMessageInfo -func (m *MsgRemoveMargin) GetSender() string { +func (m *MsgRemoveMargin) GetSender() github_com_cosmos_cosmos_sdk_types.AccAddress { if m != nil { return m.Sender } - return "" + return nil } func (m *MsgRemoveMargin) GetTokenPair() string { @@ -140,9 +140,9 @@ func (m *MsgRemoveMarginResponse) GetMarginOut() types.Coin { // MsgAddMargin: Msg to remove margin. type MsgAddMargin struct { - Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` - TokenPair string `protobuf:"bytes,2,opt,name=token_pair,json=tokenPair,proto3" json:"token_pair,omitempty"` - Margin types.Coin `protobuf:"bytes,3,opt,name=margin,proto3" json:"margin"` + Sender github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=sender,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"sender,omitempty"` + TokenPair string `protobuf:"bytes,2,opt,name=token_pair,json=tokenPair,proto3" json:"token_pair,omitempty"` + Margin types.Coin `protobuf:"bytes,3,opt,name=margin,proto3" json:"margin"` } func (m *MsgAddMargin) Reset() { *m = MsgAddMargin{} } @@ -178,11 +178,11 @@ func (m *MsgAddMargin) XXX_DiscardUnknown() { var xxx_messageInfo_MsgAddMargin proto.InternalMessageInfo -func (m *MsgAddMargin) GetSender() string { +func (m *MsgAddMargin) GetSender() github_com_cosmos_cosmos_sdk_types.AccAddress { if m != nil { return m.Sender } - return "" + return nil } func (m *MsgAddMargin) GetTokenPair() string { @@ -237,7 +237,7 @@ var xxx_messageInfo_MsgAddMarginResponse proto.InternalMessageInfo type MsgLiquidate struct { // Sender is the liquidator address - Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` + Sender github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=sender,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"sender,omitempty"` // TokenPair is the identifier for the position's virtual pool TokenPair string `protobuf:"bytes,2,opt,name=token_pair,json=tokenPair,proto3" json:"token_pair,omitempty"` // Trader is the address of the owner of the position @@ -277,11 +277,11 @@ func (m *MsgLiquidate) XXX_DiscardUnknown() { var xxx_messageInfo_MsgLiquidate proto.InternalMessageInfo -func (m *MsgLiquidate) GetSender() string { +func (m *MsgLiquidate) GetSender() github_com_cosmos_cosmos_sdk_types.AccAddress { if m != nil { return m.Sender } - return "" + return nil } func (m *MsgLiquidate) GetTokenPair() string { @@ -335,12 +335,12 @@ func (m *MsgLiquidateResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgLiquidateResponse proto.InternalMessageInfo type MsgOpenPosition struct { - Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` - TokenPair string `protobuf:"bytes,2,opt,name=token_pair,json=tokenPair,proto3" json:"token_pair,omitempty"` - Side Side `protobuf:"varint,3,opt,name=side,proto3,enum=nibiru.perp.v1.Side" json:"side,omitempty"` - QuoteAssetAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=quote_asset_amount,json=quoteAssetAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"quote_asset_amount"` - Leverage github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=leverage,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"leverage"` - BaseAssetAmountLimit github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,6,opt,name=base_asset_amount_limit,json=baseAssetAmountLimit,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"base_asset_amount_limit"` + Sender github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=sender,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"sender,omitempty"` + TokenPair string `protobuf:"bytes,2,opt,name=token_pair,json=tokenPair,proto3" json:"token_pair,omitempty"` + Side Side `protobuf:"varint,3,opt,name=side,proto3,enum=nibiru.perp.v1.Side" json:"side,omitempty"` + QuoteAssetAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=quote_asset_amount,json=quoteAssetAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"quote_asset_amount"` + Leverage github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=leverage,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"leverage"` + BaseAssetAmountLimit github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,6,opt,name=base_asset_amount_limit,json=baseAssetAmountLimit,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"base_asset_amount_limit"` } func (m *MsgOpenPosition) Reset() { *m = MsgOpenPosition{} } @@ -376,11 +376,11 @@ func (m *MsgOpenPosition) XXX_DiscardUnknown() { var xxx_messageInfo_MsgOpenPosition proto.InternalMessageInfo -func (m *MsgOpenPosition) GetSender() string { +func (m *MsgOpenPosition) GetSender() github_com_cosmos_cosmos_sdk_types.AccAddress { if m != nil { return m.Sender } - return "" + return nil } func (m *MsgOpenPosition) GetTokenPair() string { @@ -447,48 +447,50 @@ func init() { func init() { proto.RegisterFile("perp/v1/tx.proto", fileDescriptor_28f06b306d51dcfb) } var fileDescriptor_28f06b306d51dcfb = []byte{ - // 648 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x54, 0xdd, 0x6a, 0x13, 0x4d, - 0x18, 0xce, 0x36, 0xfd, 0xc2, 0x97, 0xb1, 0xb4, 0x65, 0x0c, 0x6d, 0x1a, 0xea, 0xa6, 0x2c, 0xa2, - 0x45, 0x70, 0x86, 0xd4, 0x03, 0xcf, 0x84, 0xfe, 0x9c, 0x28, 0x8d, 0x2d, 0xeb, 0x81, 0x20, 0xca, - 0x32, 0xc9, 0xbe, 0x6e, 0x87, 0x76, 0x67, 0xb6, 0x3b, 0xb3, 0xa1, 0x85, 0x22, 0xa8, 0x37, 0x20, - 0x78, 0x27, 0x5e, 0x45, 0x0f, 0x0b, 0x9e, 0x88, 0x07, 0x45, 0x5a, 0xef, 0xc0, 0x1b, 0x90, 0x9d, - 0xd9, 0xc4, 0xa4, 0xc4, 0xbf, 0x9c, 0x78, 0xb4, 0xbb, 0xf3, 0x3e, 0xef, 0xf3, 0x3c, 0xf3, 0xfe, - 0x2c, 0x9a, 0x4f, 0x20, 0x4d, 0x68, 0xaf, 0x45, 0xf5, 0x11, 0x49, 0x52, 0xa9, 0x25, 0x9e, 0x15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b7, 0x96, 0xd3, 0x0d, - 0xb9, 0xdd, 0xce, 0xb9, 0xbc, 0x25, 0xb3, 0x48, 0xc3, 0x4d, 0xe8, 0x37, 0x68, 0xed, 0xdb, 0x14, - 0x2a, 0xb7, 0x55, 0x84, 0x4f, 0xd0, 0xcc, 0xc8, 0xb2, 0x37, 0xaf, 0xd6, 0xf7, 0xca, 0x26, 0x36, - 0x6e, 0xff, 0x06, 0x30, 0x18, 0x01, 0xef, 0xcd, 0xc7, 0xaf, 0xef, 0xa7, 0x96, 0xbd, 0x06, 0xb5, - 0x09, 0xd4, 0xfc, 0x6f, 0x52, 0x03, 0x0d, 0xec, 0xd4, 0xe2, 0x04, 0x55, 0x7f, 0xac, 0xcc, 0xf2, - 0x18, 0xe6, 0x41, 0xb4, 0x71, 0xf3, 0x57, 0xd1, 0x81, 0x68, 0xd3, 0x88, 0x2e, 0x79, 0x8b, 0x23, - 0xa2, 0x2c, 0x0c, 0xfb, 0x8a, 0x27, 0x68, 0x66, 0x64, 0x28, 0xc7, 0xdd, 0x77, 0x18, 0x30, 0xf6, - 0xbe, 0xe3, 0x2a, 0xfa, 0x93, 0xfb, 0xca, 0x24, 0x1f, 0xec, 0x02, 0xbb, 0xb1, 0x75, 0x7a, 0xe1, - 0x3a, 0x67, 0x17, 0xae, 0xf3, 0xe5, 0xc2, 0x75, 0xde, 0x5d, 0xba, 0xa5, 0xb3, 0x4b, 0xb7, 0xf4, - 0xe9, 0xd2, 0x2d, 0x3d, 0xbb, 0x33, 0xd4, 0xe8, 0xc7, 0x26, 0x7f, 0x73, 0x8f, 0x71, 0xd1, 0xe7, - 0x3a, 0xb2, 0x6c, 0xa6, 0xe1, 0x9d, 0x8a, 0xf9, 0x57, 0xdf, 0xfb, 0x1e, 0x00, 0x00, 0xff, 0xff, - 0xf0, 0x7d, 0x2f, 0x27, 0x38, 0x06, 0x00, 0x00, + // 674 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 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0xf9, 0x00, 0xba, 0x38, + 0x0e, 0x28, 0x33, 0x37, 0x50, 0x49, 0x00, 0x23, 0x10, 0xd7, 0x8c, 0x65, 0xa3, 0x59, 0xe9, 0xb4, + 0xbe, 0x9f, 0x35, 0x56, 0x02, 0x2a, 0x77, 0x92, 0x9e, 0xd3, 0xe7, 0xa1, 0x9b, 0x65, 0xd7, 0x3f, + 0x2b, 0x82, 0xec, 0xba, 0xf2, 0x30, 0x02, 0xe1, 0xb4, 0xfb, 0xfd, 0x36, 0x21, 0x31, 0x08, 0xe1, + 0x65, 0x04, 0xe6, 0x1d, 0x84, 0x24, 0xdf, 0x05, 0xe6, 0x47, 0x98, 0xc6, 0xb5, 0xa9, 0x65, 0xa3, + 0x59, 0xf6, 0xca, 0x6a, 0x67, 0x1b, 0xd3, 0xd8, 0x7c, 0x84, 0x4a, 0xa1, 0xca, 0x59, 0x2b, 0x2e, + 0x1b, 0xcd, 0x5b, 0xab, 0x8b, 0x8e, 0x26, 0x75, 0x52, 0x67, 0x4e, 0xe6, 0xcc, 0x59, 0xe3, 0x94, + 0x75, 0xa6, 0x4f, 0xce, 0x1a, 0x05, 0x2f, 0x83, 0xdb, 0xef, 0x0c, 0xb4, 0x70, 0x49, 0xb6, 0x07, + 0x22, 0xe2, 0x4c, 0x80, 0xf9, 0x18, 0x21, 0x8d, 0xf2, 0x79, 0x22, 0x95, 0x85, 0x2b, 0x10, 0x97, + 0xf5, 0x91, 0xad, 0x44, 0x9a, 0xcf, 0xd1, 0xec, 0xab, 0x84, 0x11, 0xca, 0x02, 0x3f, 0xc2, 0x87, + 0x21, 0x30, 0xa9, 0x85, 0x77, 0x9c, 0x14, 0xf9, 0xf9, 0xac, 0x71, 0xef, 0x0a, 0xb5, 0x58, 0x87, + 0xbe, 0x37, 0x93, 0xd1, 0x6c, 0x6b, 0x16, 0xfb, 0xad, 0x81, 0x2a, 0x5d, 0x11, 0xb4, 0x09, 0xf9, + 0x77, 0x0a, 0x3d, 0x8f, 0xa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7d, 0xc0, 0x55, 0xaf, 0x67, 0xac, + 0xa0, 0xbe, 0x1e, 0x0e, 0x33, 0x42, 0xe5, 0x9f, 0xc3, 0xbc, 0x34, 0x81, 0x39, 0x8f, 0xd6, 0xef, + 0xfe, 0x2e, 0x9a, 0x27, 0x6d, 0xa8, 0xa4, 0x8b, 0xf6, 0xc2, 0x58, 0x52, 0x4c, 0xc8, 0x30, 0xe3, + 0x11, 0xaa, 0x8c, 0xf5, 0xf1, 0x24, 0xbf, 0xa3, 0x80, 0x89, 0x7e, 0x27, 0x55, 0xf4, 0x17, 0x7e, + 0x79, 0x94, 0x36, 0x76, 0x86, 0xed, 0xac, 0x9f, 0x9c, 0x5b, 0xc6, 0xe9, 0xb9, 0x65, 0x7c, 0x39, + 0xb7, 0x8c, 0xe3, 0x0b, 0xab, 0x70, 0x7a, 0x61, 0x15, 0x3e, 0x5d, 0x58, 0x85, 0x17, 0x0f, 0x46, + 0x2e, 0xfa, 0xa9, 0x3a, 0xbf, 0xb6, 0x83, 0x29, 0x1b, 0x72, 0x1d, 0x68, 0x36, 0x75, 0xe1, 0xbd, + 0x92, 0xfa, 0xf2, 0x3c, 0xfc, 0x11, 0x00, 0x00, 0xff, 0xff, 0x7a, 0x7f, 0x59, 0x09, 0x06, 0x07, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1140,7 +1142,7 @@ func (m *MsgRemoveMargin) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1150,23 +1152,25 @@ func (m *MsgRemoveMargin) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.Sender = string(dAtA[iNdEx:postIndex]) + m.Sender = append(m.Sender[:0], dAtA[iNdEx:postIndex]...) + if m.Sender == nil { + m.Sender = []byte{} + } iNdEx = postIndex case 2: if wireType != 2 { @@ -1404,7 +1408,7 @@ func (m *MsgAddMargin) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1414,23 +1418,25 @@ func (m *MsgAddMargin) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.Sender = string(dAtA[iNdEx:postIndex]) + m.Sender = append(m.Sender[:0], dAtA[iNdEx:postIndex]...) + if m.Sender == nil { + m.Sender = []byte{} + } iNdEx = postIndex case 2: if wireType != 2 { @@ -1601,7 +1607,7 @@ func (m *MsgLiquidate) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1611,23 +1617,25 @@ func (m *MsgLiquidate) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.Sender = string(dAtA[iNdEx:postIndex]) + m.Sender = append(m.Sender[:0], dAtA[iNdEx:postIndex]...) + if m.Sender == nil { + m.Sender = []byte{} + } iNdEx = postIndex case 2: if wireType != 2 { @@ -1797,7 +1805,7 @@ func (m *MsgOpenPosition) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1807,23 +1815,25 @@ func (m *MsgOpenPosition) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.Sender = string(dAtA[iNdEx:postIndex]) + m.Sender = append(m.Sender[:0], dAtA[iNdEx:postIndex]...) + if m.Sender == nil { + m.Sender = []byte{} + } iNdEx = postIndex case 2: if wireType != 2 { diff --git a/x/perp/types/types.go b/x/perp/types/types.go index 55e3ed5ba..42c02de08 100644 --- a/x/perp/types/types.go +++ b/x/perp/types/types.go @@ -26,15 +26,14 @@ var ( ErrPositionZero = errors.New("position is zero") ) -func ZeroPosition(ctx sdk.Context, vpair common.TokenPair, trader string) *Position { +func ZeroPosition(ctx sdk.Context, tokenPair common.TokenPair, traderAddr sdk.AccAddress) *Position { return &Position{ - Address: trader, - Pair: vpair.String(), + TraderAddress: traderAddr, + Pair: tokenPair.String(), Size_: sdk.ZeroDec(), Margin: sdk.ZeroDec(), OpenNotional: sdk.ZeroDec(), LastUpdateCumulativePremiumFraction: sdk.ZeroDec(), - LiquidityHistoryIndex: 0, BlockNumber: ctx.BlockHeight(), } }