From 3e524b79e766304a4e2957917f7770f8da52859c Mon Sep 17 00:00:00 2001 From: Atul Agarwal <21087753+asquare08@users.noreply.github.com> Date: Fri, 22 Mar 2024 02:19:26 +0530 Subject: [PATCH] resolve comments --- .../orderbook/hubbleutils/data_structures.go | 8 +-- .../evm/orderbook/hubbleutils/margin_math.go | 14 ++--- .../orderbook/hubbleutils/margin_math_test.go | 6 +- precompile/contracts/bibliophile/amm.go | 60 ++++++++----------- .../contracts/bibliophile/clearing_house.go | 39 ++++-------- precompile/contracts/bibliophile/client.go | 12 ++-- .../contracts/bibliophile/client_mock.go | 36 +++++------ precompile/contracts/juror/contract.go | 1 - .../contracts/juror/limit_orders_test.go | 24 ++++---- .../contracts/juror/matching_validation.go | 5 +- .../contracts/juror/notional_position.go | 2 +- .../contracts/jurorv2/matching_validation.go | 2 +- .../jurorv2/matching_validation_test.go | 2 +- .../contracts/traderviewer/limit_orders.go | 10 ++-- .../traderviewer/limit_orders_test.go | 24 +++----- precompile/contracts/traderviewer/viewer.go | 3 +- 16 files changed, 108 insertions(+), 140 deletions(-) diff --git a/plugin/evm/orderbook/hubbleutils/data_structures.go b/plugin/evm/orderbook/hubbleutils/data_structures.go index 04912b27dc..bed91c516b 100644 --- a/plugin/evm/orderbook/hubbleutils/data_structures.go +++ b/plugin/evm/orderbook/hubbleutils/data_structures.go @@ -18,15 +18,13 @@ const ( Min_Allowable_Margin ) -type MarginType = uint8 - const ( - Cross_Margin MarginType = iota - Isolated_Margin + Cross MarginMode = iota + Isolated ) type AccountPreferences struct { - MarginType MarginType + MarginMode MarginMode MarginFraction *big.Int } diff --git a/plugin/evm/orderbook/hubbleutils/margin_math.go b/plugin/evm/orderbook/hubbleutils/margin_math.go index 6551e379e2..747be36010 100644 --- a/plugin/evm/orderbook/hubbleutils/margin_math.go +++ b/plugin/evm/orderbook/hubbleutils/margin_math.go @@ -26,11 +26,11 @@ type HubbleState struct { } type UserState struct { - Positions map[Market]*Position - ReduceOnlyAmounts []*big.Int - Margins []*big.Int - PendingFunding *big.Int - ReservedMargin *big.Int + Positions map[Market]*Position + ReduceOnlyAmounts []*big.Int + Margins []*big.Int + PendingFunding *big.Int + ReservedMargin *big.Int AccountPreferences map[Market]*AccountPreferences } @@ -132,7 +132,7 @@ func GetCrossMarginAccountData(hState *HubbleState, userState *UserState) (*big. requiredMargin := big.NewInt(0) for _, market := range hState.ActiveMarkets { - if userState.AccountPreferences[market].MarginType == Cross_Margin { + if userState.AccountPreferences[market].MarginMode == Cross { _notionalPosition, _unrealizedPnl, _requiredMargin := GetTraderPositionDetails(userState.Positions[market], hState.OraclePrices[market], userState.AccountPreferences[market].MarginFraction) notionalPosition.Add(notionalPosition, _notionalPosition) unrealizedPnl.Add(unrealizedPnl, _unrealizedPnl) @@ -148,7 +148,7 @@ func GetTraderPositionDetails(position *Position, oraclePrice *big.Int, marginFr } // based on oracle price, - notionalPosition, unrealizedPnl, _ := GetPositionMetadata( + notionalPosition, unrealizedPnl, _ := GetPositionMetadata( oraclePrice, position.OpenNotional, position.Size, diff --git a/plugin/evm/orderbook/hubbleutils/margin_math_test.go b/plugin/evm/orderbook/hubbleutils/margin_math_test.go index 33e4342232..d8cffd4275 100644 --- a/plugin/evm/orderbook/hubbleutils/margin_math_test.go +++ b/plugin/evm/orderbook/hubbleutils/margin_math_test.go @@ -56,11 +56,11 @@ var userState = &UserState{ ReservedMargin: big.NewInt(60 * 1e6), // 60 AccountPreferences: map[Market]*AccountPreferences{ 0: { - MarginType: Cross_Margin, + MarginMode: Cross, MarginFraction: big.NewInt(0.2 * 1e6), // 0.2 }, 1: { - MarginType: Isolated_Margin, + MarginMode: Isolated, MarginFraction: big.NewInt(0.1 * 1e6), // 0.1 }, }, @@ -264,7 +264,7 @@ func TestGetNotionalPositionAndRequiredMargin(t *testing.T) { }) t.Run("both markets in cross mode", func(t *testing.T) { - userState.AccountPreferences[1].MarginType = Cross_Margin + userState.AccountPreferences[1].MarginMode = Cross notionalPosition, margin, requiredMargin := GetNotionalPositionAndRequiredMargin(_hState, userState) expectedNotionalPosition := big.NewInt(0) expectedRequiredMargin := big.NewInt(0) diff --git a/precompile/contracts/bibliophile/amm.go b/precompile/contracts/bibliophile/amm.go index 5a1addab08..c06555b40f 100644 --- a/precompile/contracts/bibliophile/amm.go +++ b/precompile/contracts/bibliophile/amm.go @@ -10,26 +10,26 @@ import ( ) const ( - VAR_POSITIONS_SLOT int64 = 1 - VAR_CUMULATIVE_PREMIUM_FRACTION int64 = 2 - MAX_ORACLE_SPREAD_RATIO_SLOT int64 = 3 - MAX_LIQUIDATION_RATIO_SLOT int64 = 4 - MIN_SIZE_REQUIREMENT_SLOT int64 = 5 - UNDERLYING_ASSET_SLOT int64 = 6 - MAX_LIQUIDATION_PRICE_SPREAD int64 = 11 - MULTIPLIER_SLOT int64 = 12 - IMPACT_MARGIN_NOTIONAL_SLOT int64 = 19 - LAST_TRADE_PRICE_SLOT int64 = 20 - BIDS_SLOT int64 = 21 - ASKS_SLOT int64 = 22 - BIDS_HEAD_SLOT int64 = 23 - ASKS_HEAD_SLOT int64 = 24 - TRADE_MARGIN_FRACTION_SLOT int64 = 28 - LIQUIDATION_MARGIN_FRACTION_SLOT int64 = 29 - ISOLATED_TRADE_MARGIN_FRACTION_SLOT int64 = 30 + VAR_POSITIONS_SLOT int64 = 1 + VAR_CUMULATIVE_PREMIUM_FRACTION int64 = 2 + MAX_ORACLE_SPREAD_RATIO_SLOT int64 = 3 + MAX_LIQUIDATION_RATIO_SLOT int64 = 4 + MIN_SIZE_REQUIREMENT_SLOT int64 = 5 + UNDERLYING_ASSET_SLOT int64 = 6 + MAX_LIQUIDATION_PRICE_SPREAD int64 = 11 + MULTIPLIER_SLOT int64 = 12 + IMPACT_MARGIN_NOTIONAL_SLOT int64 = 19 + LAST_TRADE_PRICE_SLOT int64 = 20 + BIDS_SLOT int64 = 21 + ASKS_SLOT int64 = 22 + BIDS_HEAD_SLOT int64 = 23 + ASKS_HEAD_SLOT int64 = 24 + TRADE_MARGIN_FRACTION_SLOT int64 = 28 + LIQUIDATION_MARGIN_FRACTION_SLOT int64 = 29 + ISOLATED_TRADE_MARGIN_FRACTION_SLOT int64 = 30 ISOLATED_LIQUIDATION_MARGIN_FRACTION_SLOT int64 = 31 - ACCOUNT_PREFERENCES_SLOT int64 = 33 - MAX_POSITION_CAP_SLOT int64 = 34 + ACCOUNT_PREFERENCES_SLOT int64 = 33 + MAX_POSITION_CAP_SLOT int64 = 34 ) // AMM State @@ -172,11 +172,11 @@ func accountPreferencesSlot(trader *common.Address) *big.Int { return new(big.Int).SetBytes(crypto.Keccak256(append(common.LeftPadBytes(trader.Bytes(), 32), common.LeftPadBytes(big.NewInt(ACCOUNT_PREFERENCES_SLOT).Bytes(), 32)...))) } -func getMarginType(stateDB contract.StateDB, market common.Address, trader *common.Address) uint8 { +func getMarginMode(stateDB contract.StateDB, market common.Address, trader *common.Address) uint8 { return uint8(stateDB.GetState(market, common.BigToHash(accountPreferencesSlot(trader))).Big().Uint64()) } -func traderMarginFraction(stateDB contract.StateDB, market common.Address, trader *common.Address) *big.Int { +func marginFraction(stateDB contract.StateDB, market common.Address, trader *common.Address) *big.Int { return stateDB.GetState(market, common.BigToHash(new(big.Int).Add(accountPreferencesSlot(trader), big.NewInt(1)))).Big() } @@ -186,7 +186,7 @@ func getMaxPositionCap(stateDB contract.StateDB, market common.Address) *big.Int func getMarginFractionByMode(stateDB contract.StateDB, market common.Address, trader *common.Address, mode uint8) *big.Int { if mode == hu.Maintenance_Margin { - if (getMarginType(stateDB, market, trader) == hu.Isolated_Margin) { + if getMarginMode(stateDB, market, trader) == hu.Isolated { return getIsolatedLiquidationMarginFraction(stateDB, market) } else { return getLiquidationMarginFraction(stateDB, market) @@ -198,26 +198,16 @@ func getMarginFractionByMode(stateDB contract.StateDB, market common.Address, tr } func getTraderMarginFraction(stateDB contract.StateDB, market common.Address, trader *common.Address) *big.Int { - traderMarginFraction_ := traderMarginFraction(stateDB, market, trader) - if (traderMarginFraction_.Cmp(big.NewInt(0)) != 0) { + traderMarginFraction_ := marginFraction(stateDB, market, trader) + if traderMarginFraction_.Sign() != 0 { return traderMarginFraction_ - } else if (getMarginType(stateDB, market, trader) == hu.Isolated_Margin) { + } else if getMarginMode(stateDB, market, trader) == hu.Isolated { return getIsolatedTradeMarginFraction(stateDB, market) } else { return getTradeMarginFraction(stateDB, market) } } -func getRequiredMargin(stateDB contract.StateDB, baseAsset *big.Int, price *big.Int, marketId int64, trader *common.Address) *big.Int { - quoteAsset := hu.Div1e18(hu.Mul(hu.Abs(baseAsset), price)) - return getRequiredMarginForQuote(stateDB, GetMarketAddressFromMarketID(marketId, stateDB), trader, quoteAsset) -} - -func getRequiredMarginForQuote(stateDB contract.StateDB, market common.Address, trader *common.Address, quote *big.Int) *big.Int { - marginFraction := getTraderMarginFraction(stateDB, market, trader) - return hu.Div1e6(hu.Mul(quote, marginFraction)) -} - func getPositionCap(stateDB contract.StateDB, market int64, trader *common.Address) *big.Int { marketAddress := GetMarketAddressFromMarketID(market, stateDB) maxPositionCap := getMaxPositionCap(stateDB, marketAddress) diff --git a/precompile/contracts/bibliophile/clearing_house.go b/precompile/contracts/bibliophile/clearing_house.go index 8a78b2f9b7..1a4a0733e8 100644 --- a/precompile/contracts/bibliophile/clearing_house.go +++ b/precompile/contracts/bibliophile/clearing_house.go @@ -72,7 +72,7 @@ type GetTraderDataForMarketOutput struct { RequiredMargin *big.Int UnrealizedPnl *big.Int PendingFunding *big.Int - IsIsolated bool + IsIsolated bool } func getNotionalPositionAndMargin(stateDB contract.StateDB, input *GetNotionalPositionAndMarginInput, upgradeVersion hu.UpgradeVersion) GetNotionalPositionAndMarginOutput { @@ -114,38 +114,24 @@ func getNotionalPositionAndMargin(stateDB contract.StateDB, input *GetNotionalPo } func getNotionalPositionAndRequiredMargin(stateDB contract.StateDB, input *GetNotionalPositionAndMarginInput) GetNotionalPositionAndMarginOutput { - positions, underlyingPrices, accountPreferences, activeMarketIds := getMarketsDataFromDB(stateDB, &input.Trader, input.Mode) - pendingFunding := big.NewInt(0) + margin := GetNormalizedMargin(stateDB, input.Trader) + accountData := getCrossMarginAccountData(stateDB, &input.Trader, input.Mode) if input.IncludeFundingPayments { - pendingFunding = getTotalFundingForCrossMarginPositions(stateDB, &input.Trader) + margin.Sub(margin, accountData.PendingFunding) } - notionalPosition, margin, requiredMargin := hu.GetNotionalPositionAndRequiredMargin( - &hu.HubbleState{ - Assets: GetCollaterals(stateDB), - OraclePrices: underlyingPrices, - ActiveMarkets: activeMarketIds, - }, - &hu.UserState{ - Positions: positions, - Margins: getMargins(stateDB, input.Trader), - PendingFunding: pendingFunding, - AccountPreferences: accountPreferences, - }, - ) return GetNotionalPositionAndMarginOutput{ - NotionalPosition: notionalPosition, + NotionalPosition: accountData.NotionalPosition, Margin: margin, - RequiredMargin: requiredMargin, + RequiredMargin: accountData.RequiredMargin, } } -func getCrossMarginAccountData(stateDB contract.StateDB, trader *common.Address, mode uint8, upgradeVersion hu.UpgradeVersion) GetTraderDataForMarketOutput { +func getCrossMarginAccountData(stateDB contract.StateDB, trader *common.Address, mode uint8) GetTraderDataForMarketOutput { positions, underlyingPrices, accountPreferences, activeMarketIds := getMarketsDataFromDB(stateDB, trader, mode) notionalPosition, requiredMargin, unrealizedPnl := hu.GetCrossMarginAccountData( &hu.HubbleState{ ActiveMarkets: activeMarketIds, OraclePrices: underlyingPrices, - UpgradeVersion: upgradeVersion, }, &hu.UserState{ Positions: positions, @@ -153,7 +139,7 @@ func getCrossMarginAccountData(stateDB contract.StateDB, trader *common.Address, }, ) pendingFunding := getTotalFundingForCrossMarginPositions(stateDB, trader) - return GetTraderDataForMarketOutput { + return GetTraderDataForMarketOutput{ NotionalPosition: notionalPosition, RequiredMargin: requiredMargin, UnrealizedPnl: unrealizedPnl, @@ -169,11 +155,10 @@ func getMarketsDataFromDB(stateDB contract.StateDB, trader *common.Address, mode accountPreferences = make(map[int]*hu.AccountPreferences, numMarkets) activeMarketIds = make([]int, numMarkets) for i, market := range markets { - // @todo can use `market` instead of `GetMarketAddressFromMarketID`? - positions[i] = getPosition(stateDB, GetMarketAddressFromMarketID(int64(i), stateDB), trader) + positions[i] = getPosition(stateDB, market, trader) underlyingPrices[i] = getUnderlyingPrice(stateDB, market) activeMarketIds[i] = i - accountPreferences[i].MarginType = getMarginType(stateDB, market, trader) + accountPreferences[i].MarginMode = getMarginMode(stateDB, market, trader) accountPreferences[i].MarginFraction = getMarginFractionByMode(stateDB, market, trader, mode) } return positions, underlyingPrices, accountPreferences, activeMarketIds @@ -182,7 +167,7 @@ func getMarketsDataFromDB(stateDB contract.StateDB, trader *common.Address, mode func getTotalFundingForCrossMarginPositions(stateDB contract.StateDB, trader *common.Address) *big.Int { totalFunding := big.NewInt(0) for _, market := range GetMarkets(stateDB) { - if getMarginType(stateDB, market, trader) == hu.Cross_Margin { + if getMarginMode(stateDB, market, trader) == hu.Cross { totalFunding.Add(totalFunding, getPendingFundingPayment(stateDB, market, trader)) } } @@ -196,7 +181,7 @@ func getTraderDataForMarket(stateDB contract.StateDB, trader *common.Address, ma underlyingPrice := getUnderlyingPrice(stateDB, market) notionalPosition, unrealizedPnl, requiredMargin := hu.GetTraderPositionDetails(position, underlyingPrice, marginFraction) pendingFunding := getPendingFundingPayment(stateDB, market, trader) - isIsolated := getMarginType(stateDB, market, trader) == hu.Isolated_Margin + isIsolated := getMarginMode(stateDB, market, trader) == hu.Isolated return GetTraderDataForMarketOutput{ IsIsolated: isIsolated, NotionalPosition: notionalPosition, diff --git a/precompile/contracts/bibliophile/client.go b/precompile/contracts/bibliophile/client.go index ae2b38bab0..731d29fa9f 100644 --- a/precompile/contracts/bibliophile/client.go +++ b/precompile/contracts/bibliophile/client.go @@ -53,14 +53,14 @@ type BibliophileClient interface { GetUpperAndLowerBoundForMarket(marketId int64) (*big.Int, *big.Int) GetAcceptableBoundsForLiquidation(marketId int64) (*big.Int, *big.Int) GetPositionCap(marketId int64, trader common.Address) *big.Int + GetTraderMarginFraction(market common.Address, trader *common.Address) *big.Int GetTimeStamp() uint64 GetNotionalPositionAndMargin(trader common.Address, includeFundingPayments bool, mode uint8, upgradeVersion hu.UpgradeVersion) (*big.Int, *big.Int) GetNotionalPositionAndRequiredMargin(trader common.Address, includeFundingPayments bool, mode uint8) (*big.Int, *big.Int, *big.Int) - GetCrossMarginAccountData(trader common.Address, mode uint8, upgradeVersion hu.UpgradeVersion) (*big.Int, *big.Int, *big.Int, *big.Int) + GetCrossMarginAccountData(trader common.Address, mode uint8) (*big.Int, *big.Int, *big.Int, *big.Int) GetTotalFundingForCrossMarginPositions(trader *common.Address) *big.Int GetTraderDataForMarket(trader common.Address, marketId int64, mode uint8) (bool, *big.Int, *big.Int, *big.Int, *big.Int) - GetRequiredMargin(baseAsset *big.Int, price *big.Int, marketId int64, trader *common.Address) *big.Int HasReferrer(trader common.Address) bool GetActiveMarketsCount() int64 @@ -224,8 +224,8 @@ func (b *bibliophileClient) GetNotionalPositionAndRequiredMargin(trader common.A return output.NotionalPosition, output.Margin, output.RequiredMargin } -func (b *bibliophileClient) GetCrossMarginAccountData(trader common.Address, mode uint8, upgradeVersion hu.UpgradeVersion) (*big.Int, *big.Int, *big.Int, *big.Int) { - output := getCrossMarginAccountData(b.accessibleState.GetStateDB(), &trader, mode, upgradeVersion) +func (b *bibliophileClient) GetCrossMarginAccountData(trader common.Address, mode uint8) (*big.Int, *big.Int, *big.Int, *big.Int) { + output := getCrossMarginAccountData(b.accessibleState.GetStateDB(), &trader, mode) return output.NotionalPosition, output.RequiredMargin, output.UnrealizedPnl, output.PendingFunding } @@ -238,8 +238,8 @@ func (b *bibliophileClient) GetTraderDataForMarket(trader common.Address, market return output.IsIsolated, output.NotionalPosition, output.UnrealizedPnl, output.RequiredMargin, output.PendingFunding } -func (b *bibliophileClient) GetRequiredMargin(baseAsset *big.Int, price *big.Int, marketId int64, trader *common.Address) *big.Int { - return getRequiredMargin(b.accessibleState.GetStateDB(), baseAsset, price, marketId, trader) +func (b *bibliophileClient) GetTraderMarginFraction(market common.Address, trader *common.Address) *big.Int { + return getTraderMarginFraction(b.accessibleState.GetStateDB(), market, trader) } func (b *bibliophileClient) HasReferrer(trader common.Address) bool { diff --git a/precompile/contracts/bibliophile/client_mock.go b/precompile/contracts/bibliophile/client_mock.go index 2a5f0d0007..9634ae2378 100644 --- a/precompile/contracts/bibliophile/client_mock.go +++ b/precompile/contracts/bibliophile/client_mock.go @@ -165,9 +165,9 @@ func (mr *MockBibliophileClientMockRecorder) GetBlockPlaced(orderHash interface{ } // GetCrossMarginAccountData mocks base method. -func (m *MockBibliophileClient) GetCrossMarginAccountData(trader common.Address, mode uint8, upgradeVersion hubbleutils.UpgradeVersion) (*big.Int, *big.Int, *big.Int, *big.Int) { +func (m *MockBibliophileClient) GetCrossMarginAccountData(trader common.Address, mode uint8) (*big.Int, *big.Int, *big.Int, *big.Int) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetCrossMarginAccountData", trader, mode, upgradeVersion) + ret := m.ctrl.Call(m, "GetCrossMarginAccountData", trader, mode) ret0, _ := ret[0].(*big.Int) ret1, _ := ret[1].(*big.Int) ret2, _ := ret[2].(*big.Int) @@ -176,9 +176,9 @@ func (m *MockBibliophileClient) GetCrossMarginAccountData(trader common.Address, } // GetCrossMarginAccountData indicates an expected call of GetCrossMarginAccountData. -func (mr *MockBibliophileClientMockRecorder) GetCrossMarginAccountData(trader, mode, upgradeVersion interface{}) *gomock.Call { +func (mr *MockBibliophileClientMockRecorder) GetCrossMarginAccountData(trader, mode interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCrossMarginAccountData", reflect.TypeOf((*MockBibliophileClient)(nil).GetCrossMarginAccountData), trader, mode, upgradeVersion) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCrossMarginAccountData", reflect.TypeOf((*MockBibliophileClient)(nil).GetCrossMarginAccountData), trader, mode) } // GetImpactMarginNotional mocks base method. @@ -408,20 +408,6 @@ func (mr *MockBibliophileClientMockRecorder) GetReduceOnlyAmount(trader, ammInde return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetReduceOnlyAmount", reflect.TypeOf((*MockBibliophileClient)(nil).GetReduceOnlyAmount), trader, ammIndex) } -// GetRequiredMargin mocks base method. -func (m *MockBibliophileClient) GetRequiredMargin(baseAsset, price *big.Int, marketId int64, trader *common.Address) *big.Int { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetRequiredMargin", baseAsset, price, marketId, trader) - ret0, _ := ret[0].(*big.Int) - return ret0 -} - -// GetRequiredMargin indicates an expected call of GetRequiredMargin. -func (mr *MockBibliophileClientMockRecorder) GetRequiredMargin(baseAsset, price, marketId, trader interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRequiredMargin", reflect.TypeOf((*MockBibliophileClient)(nil).GetRequiredMargin), baseAsset, price, marketId, trader) -} - // GetShortOpenOrdersAmount mocks base method. func (m *MockBibliophileClient) GetShortOpenOrdersAmount(trader common.Address, ammIndex *big.Int) *big.Int { m.ctrl.T.Helper() @@ -538,6 +524,20 @@ func (mr *MockBibliophileClientMockRecorder) GetTraderDataForMarket(trader, mark return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTraderDataForMarket", reflect.TypeOf((*MockBibliophileClient)(nil).GetTraderDataForMarket), trader, marketId, mode) } +// GetTraderMarginFraction mocks base method. +func (m *MockBibliophileClient) GetTraderMarginFraction(market common.Address, trader *common.Address) *big.Int { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTraderMarginFraction", market, trader) + ret0, _ := ret[0].(*big.Int) + return ret0 +} + +// GetTraderMarginFraction indicates an expected call of GetTraderMarginFraction. +func (mr *MockBibliophileClientMockRecorder) GetTraderMarginFraction(market, trader interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTraderMarginFraction", reflect.TypeOf((*MockBibliophileClient)(nil).GetTraderMarginFraction), market, trader) +} + // GetUpperAndLowerBoundForMarket mocks base method. func (m *MockBibliophileClient) GetUpperAndLowerBoundForMarket(marketId int64) (*big.Int, *big.Int) { m.ctrl.T.Helper() diff --git a/precompile/contracts/juror/contract.go b/precompile/contracts/juror/contract.go index 9f6bf2ba20..3957d34c66 100644 --- a/precompile/contracts/juror/contract.go +++ b/precompile/contracts/juror/contract.go @@ -475,7 +475,6 @@ func createJurorPrecompile() contract.StatefulPrecompiledContract { "validateOrdersAndDetermineFillPrice": validateOrdersAndDetermineFillPrice, "validatePlaceIOCOrder": validatePlaceIOCOrder, "validatePlaceLimitOrder": validatePlaceLimitOrder, - // @todo add getRequiredMargin } for name, function := range abiFunctionMap { diff --git a/precompile/contracts/juror/limit_orders_test.go b/precompile/contracts/juror/limit_orders_test.go index 8e93613a15..d070d19bb9 100644 --- a/precompile/contracts/juror/limit_orders_test.go +++ b/precompile/contracts/juror/limit_orders_test.go @@ -810,7 +810,7 @@ func TestValidatePlaceLimitOrder(t *testing.T) { }) t.Run("when available margin is one less than requiredMargin and precompileVersion = 1", func(t *testing.T) { - mockBibliophile.EXPECT().GetMarketAddressFromMarketID(longOrder.AmmIndex.Int64()).Return(ammAddress).Times(1) + mockBibliophile.EXPECT().GetMarketAddressFromMarketID(longOrder.AmmIndex.Int64()).Return(ammAddress).Times(2) mockBibliophile.EXPECT().GetMinSizeRequirement(longOrder.AmmIndex.Int64()).Return(minSizeRequirement).Times(1) orderHash, err := GetLimitOrderHashFromContractStruct(&longOrder) if err != nil { @@ -820,9 +820,9 @@ func TestValidatePlaceLimitOrder(t *testing.T) { mockBibliophile.EXPECT().GetSize(ammAddress, &trader).Return(positionSize).Times(1) mockBibliophile.EXPECT().GetReduceOnlyAmount(trader, longOrder.AmmIndex).Return(reduceOnlyAmount).Times(1) - quoteAsset := big.NewInt(0).Abs(hu.Div(hu.Mul(longOrder.BaseAssetQuantity, upperBound), big.NewInt(1e18))) - requiredMargin := hu.Div(quoteAsset, big.NewInt(10)) // 10x leverage - mockBibliophile.EXPECT().GetRequiredMargin(longOrder.BaseAssetQuantity, longOrder.Price, longOrder.AmmIndex.Int64(), &trader).Return(requiredMargin).Times(1) + quoteAsset := big.NewInt(0).Abs(hu.Div(hu.Mul(longOrder.BaseAssetQuantity, longOrder.Price), big.NewInt(1e18))) + requiredMargin := hu.Div(quoteAsset, big.NewInt(10)) // 10x leverage + mockBibliophile.EXPECT().GetTraderMarginFraction(ammAddress, &trader).Return(big.NewInt(1e5)).Times(1) // 0.1 availableMargin := hu.Sub(requiredMargin, big.NewInt(1)) mockBibliophile.EXPECT().GetTimeStamp().Return(hu.V1ActivationTime).Times(1) mockBibliophile.EXPECT().GetAvailableMargin(trader, hu.V1).Return(availableMargin).Times(1) @@ -899,7 +899,7 @@ func TestValidatePlaceLimitOrder(t *testing.T) { assert.Equal(t, big.NewInt(0), output.Res.ReserveAmount) }) t.Run("when available margin is one less than requiredMargin and precompileVersion = 1", func(t *testing.T) { - mockBibliophile.EXPECT().GetMarketAddressFromMarketID(shortOrder.AmmIndex.Int64()).Return(ammAddress).Times(1) + mockBibliophile.EXPECT().GetMarketAddressFromMarketID(shortOrder.AmmIndex.Int64()).Return(ammAddress).Times(2) mockBibliophile.EXPECT().GetMinSizeRequirement(shortOrder.AmmIndex.Int64()).Return(minSizeRequirement).Times(1) orderHash, err := GetLimitOrderHashFromContractStruct(&shortOrder) if err != nil { @@ -909,9 +909,9 @@ func TestValidatePlaceLimitOrder(t *testing.T) { mockBibliophile.EXPECT().GetSize(ammAddress, &trader).Return(positionSize).Times(1) mockBibliophile.EXPECT().GetReduceOnlyAmount(trader, shortOrder.AmmIndex).Return(reduceOnlyAmount).Times(1) - quoteAsset := big.NewInt(0).Abs(hu.Div(hu.Mul(shortOrder.BaseAssetQuantity, upperBound), big.NewInt(1e18))) - requiredMargin := hu.Div(quoteAsset, big.NewInt(10)) // 10x leverage - mockBibliophile.EXPECT().GetRequiredMargin(shortOrder.BaseAssetQuantity, shortOrder.Price, shortOrder.AmmIndex.Int64(), &trader).Return(requiredMargin).Times(1) + quoteAsset := big.NewInt(0).Abs(hu.Div(hu.Mul(shortOrder.BaseAssetQuantity, shortOrder.Price), big.NewInt(1e18))) + requiredMargin := hu.Div(quoteAsset, big.NewInt(10)) // 10x leverage + mockBibliophile.EXPECT().GetTraderMarginFraction(ammAddress, &trader).Return(big.NewInt(1e5)).Times(1) // 0.1 availableMargin := hu.Sub(requiredMargin, big.NewInt(1)) mockBibliophile.EXPECT().GetTimeStamp().Return(hu.V1ActivationTime).Times(1) mockBibliophile.EXPECT().GetAvailableMargin(trader, hu.V1).Return(availableMargin).Times(1) @@ -1228,7 +1228,7 @@ func TestValidatePlaceLimitOrder(t *testing.T) { requiredMargin := hu.Div(quoteAsset, big.NewInt(10)) // 10x leverage availableMargin := hu.Add(requiredMargin, big.NewInt(1)) - mockBibliophile.EXPECT().GetMarketAddressFromMarketID(longOrder.AmmIndex.Int64()).Return(ammAddress).Times(1) + mockBibliophile.EXPECT().GetMarketAddressFromMarketID(longOrder.AmmIndex.Int64()).Return(ammAddress).Times(2) mockBibliophile.EXPECT().GetMinSizeRequirement(longOrder.AmmIndex.Int64()).Return(minSizeRequirement).Times(1) orderHash, err := GetLimitOrderHashFromContractStruct(&longOrder) if err != nil { @@ -1246,7 +1246,7 @@ func TestValidatePlaceLimitOrder(t *testing.T) { mockBibliophile.EXPECT().GetPrecompileVersion(common.HexToAddress(SelfAddress)).Return(big.NewInt(1)).Times(2) mockBibliophile.EXPECT().GetLongOpenOrdersAmount(trader, longOrder.AmmIndex).Return(big.NewInt(0)).Times(1) mockBibliophile.EXPECT().GetPositionCap(longOrder.AmmIndex.Int64(), trader).Return(hu.Mul(longOrder.BaseAssetQuantity, big.NewInt(2))).Times(1) - mockBibliophile.EXPECT().GetRequiredMargin(longOrder.BaseAssetQuantity, longOrder.Price, longOrder.AmmIndex.Int64(), &trader).Return(requiredMargin).Times(1) + mockBibliophile.EXPECT().GetTraderMarginFraction(ammAddress, &trader).Return(big.NewInt(1e5)).Times(1) // 0.1 output := ValidatePlaceLimitOrder(mockBibliophile, &ValidatePlaceLimitOrderInput{Order: longOrder, Sender: trader}) assert.Equal(t, "", output.Err) assert.Equal(t, orderHash, common.BytesToHash(output.Orderhash[:])) @@ -1259,7 +1259,7 @@ func TestValidatePlaceLimitOrder(t *testing.T) { requiredMargin := hu.Div(quoteAsset, big.NewInt(10)) // 10x leverage availableMargin := hu.Add(requiredMargin, big.NewInt(1)) - mockBibliophile.EXPECT().GetMarketAddressFromMarketID(shortOrder.AmmIndex.Int64()).Return(ammAddress).Times(1) + mockBibliophile.EXPECT().GetMarketAddressFromMarketID(shortOrder.AmmIndex.Int64()).Return(ammAddress).Times(2) mockBibliophile.EXPECT().GetMinSizeRequirement(shortOrder.AmmIndex.Int64()).Return(minSizeRequirement).Times(1) orderHash, err := GetLimitOrderHashFromContractStruct(&shortOrder) if err != nil { @@ -1278,7 +1278,7 @@ func TestValidatePlaceLimitOrder(t *testing.T) { mockBibliophile.EXPECT().GetLongOpenOrdersAmount(trader, shortOrder.AmmIndex).Return(big.NewInt(0)).Times(1) mockBibliophile.EXPECT().GetShortOpenOrdersAmount(trader, shortOrder.AmmIndex).Return(big.NewInt(0)).Times(1) mockBibliophile.EXPECT().GetPositionCap(shortOrder.AmmIndex.Int64(), trader).Return(hu.Mul(shortOrder.BaseAssetQuantity, big.NewInt(-2))).Times(1) - mockBibliophile.EXPECT().GetRequiredMargin(shortOrder.BaseAssetQuantity, shortOrder.Price, shortOrder.AmmIndex.Int64(), &trader).Return(requiredMargin).Times(1) + mockBibliophile.EXPECT().GetTraderMarginFraction(ammAddress, &trader).Return(big.NewInt(1e5)).Times(1) // 0.1 output := ValidatePlaceLimitOrder(mockBibliophile, &ValidatePlaceLimitOrderInput{Order: shortOrder, Sender: trader}) assert.Equal(t, "", output.Err) assert.Equal(t, orderHash, common.BytesToHash(output.Orderhash[:])) diff --git a/precompile/contracts/juror/matching_validation.go b/precompile/contracts/juror/matching_validation.go index 4df229c423..b993b71483 100644 --- a/precompile/contracts/juror/matching_validation.go +++ b/precompile/contracts/juror/matching_validation.go @@ -442,7 +442,10 @@ func getRequiredMargin(bibliophile b.BibliophileClient, order ILimitOrderBookOrd } func getRequiredMarginNew(bibliophile b.BibliophileClient, baseAsset *big.Int, price *big.Int, marketId int64, trader *common.Address) *big.Int { - return bibliophile.GetRequiredMargin(baseAsset, price, marketId, trader) + marketAddress := bibliophile.GetMarketAddressFromMarketID(marketId) + marginFraction := bibliophile.GetTraderMarginFraction(marketAddress,trader) + quoteAsset := hu.Div1e18(hu.Mul(hu.Abs(baseAsset), price)) + return hu.Div1e6(hu.Mul(quoteAsset, marginFraction)) } func getRequiredMarginLegacy(bibliophile b.BibliophileClient, order ILimitOrderBookOrder) *big.Int { diff --git a/precompile/contracts/juror/notional_position.go b/precompile/contracts/juror/notional_position.go index 85396c1907..465353d160 100644 --- a/precompile/contracts/juror/notional_position.go +++ b/precompile/contracts/juror/notional_position.go @@ -5,7 +5,7 @@ import ( b "github.com/ava-labs/subnet-evm/precompile/contracts/bibliophile" ) /** - * Depricated. Use traderviewer.GetNotionalPositionAndMargin instead + * Deprecated. Use traderviewer.GetNotionalPositionAndMargin instead */ func GetNotionalPositionAndMargin(bibliophile b.BibliophileClient, input *GetNotionalPositionAndMarginInput) GetNotionalPositionAndMarginOutput { notionalPosition, margin := bibliophile.GetNotionalPositionAndMargin(input.Trader, input.IncludeFundingPayments, input.Mode, hu.UpgradeVersionV0orV1(bibliophile.GetTimeStamp())) diff --git a/precompile/contracts/jurorv2/matching_validation.go b/precompile/contracts/jurorv2/matching_validation.go index 9611b6416f..6f8e9b6ea9 100644 --- a/precompile/contracts/jurorv2/matching_validation.go +++ b/precompile/contracts/jurorv2/matching_validation.go @@ -498,7 +498,7 @@ func validateLimitOrderLike(bibliophile b.BibliophileClient, order *hu.BaseOrder if bibliophile.GetPrecompileVersion(common.HexToAddress(SelfAddress)).Cmp(big.NewInt(1)) >= 0 { posSize := bibliophile.GetSize(market, &order.Trader) posCap := bibliophile.GetPositionCap(order.AmmIndex.Int64(), order.Trader) - if hu.Abs(hu.Add(posSize, order.BaseAssetQuantity)).Cmp(posCap) == 1 { + if hu.Abs(hu.Add(posSize, fillAmount)).Cmp(posCap) == 1 { return ErrOverPositionCap } } diff --git a/precompile/contracts/jurorv2/matching_validation_test.go b/precompile/contracts/jurorv2/matching_validation_test.go index 982452b33a..c085712a8d 100644 --- a/precompile/contracts/jurorv2/matching_validation_test.go +++ b/precompile/contracts/jurorv2/matching_validation_test.go @@ -105,7 +105,7 @@ func TestValidateLimitOrderLike(t *testing.T) { t.Run("position cap reached", func(t *testing.T) { mockBibliophile.EXPECT().GetPrecompileVersion(common.HexToAddress(SelfAddress)).Return(big.NewInt(1)).Times(1) mockBibliophile.EXPECT().GetSize(common.Address{}, &order.Trader).Return(big.NewInt(1)).Times(1) - mockBibliophile.EXPECT().GetPositionCap(int64(0), order.Trader).Return(order.BaseAssetQuantity).Times(1) + mockBibliophile.EXPECT().GetPositionCap(int64(0), order.Trader).Return(fillAmount).Times(1) err := validateLimitOrderLike(mockBibliophile, order, filledAmount, Placed, Long, fillAmount) assert.EqualError(t, err, ErrOverPositionCap.Error()) }) diff --git a/precompile/contracts/traderviewer/limit_orders.go b/precompile/contracts/traderviewer/limit_orders.go index 3efecee12d..60e53f7c64 100644 --- a/precompile/contracts/traderviewer/limit_orders.go +++ b/precompile/contracts/traderviewer/limit_orders.go @@ -26,8 +26,7 @@ func ValidateCancelLimitOrderV2(bibliophile b.BibliophileClient, inputStruct *Va trader := order.Trader if (!assertLowMargin && trader != sender && !bibliophile.IsTradingAuthority(trader, sender)) || - (assertLowMargin && !bibliophile.IsValidator(sender)) || - (assertOverPositionCap && !bibliophile.IsValidator(sender)) { + (assertLowMargin || assertOverPositionCap) && !bibliophile.IsValidator(sender) { response.Err = ErrUnauthorizedCancellation.Error() return } @@ -51,7 +50,7 @@ func ValidateCancelLimitOrderV2(bibliophile b.BibliophileClient, inputStruct *Va } response.Res.UnfilledAmount = hu.Sub(order.BaseAssetQuantity, bibliophile.GetOrderFilledAmount(orderHash)) response.Res.Amm = bibliophile.GetMarketAddressFromMarketID(order.AmmIndex.Int64()) - if assertLowMargin && bibliophile.GetAvailableMargin(trader, hu.UpgradeVersionV0orV1(bibliophile.GetTimeStamp())).Sign() != -1 { + if assertLowMargin && bibliophile.GetAvailableMargin(trader, hu.V2).Sign() != -1 { response.Err = "Not Low Margin" return } else if assertOverPositionCap { @@ -84,5 +83,8 @@ func GetLimitOrderHashFromContractStruct(o *ILimitOrderBookOrder) (common.Hash, } func GetRequiredMargin(bibliophile b.BibliophileClient, inputStruct *GetRequiredMarginInput) *big.Int { - return bibliophile.GetRequiredMargin(inputStruct.BaseAssetQuantity, inputStruct.Price, inputStruct.AmmIndex.Int64(), &inputStruct.Trader) + marketAddress := bibliophile.GetMarketAddressFromMarketID(inputStruct.AmmIndex.Int64()) + marginFraction := bibliophile.GetTraderMarginFraction(marketAddress, &inputStruct.Trader) + quoteAsset := hu.Div1e18(hu.Mul(hu.Abs(inputStruct.BaseAssetQuantity), inputStruct.Price)) + return hu.Div1e6(hu.Mul(quoteAsset, marginFraction)) } diff --git a/precompile/contracts/traderviewer/limit_orders_test.go b/precompile/contracts/traderviewer/limit_orders_test.go index dca480b1f7..28936fe421 100644 --- a/precompile/contracts/traderviewer/limit_orders_test.go +++ b/precompile/contracts/traderviewer/limit_orders_test.go @@ -132,8 +132,7 @@ func TestValidateCancelLimitOrderV2(t *testing.T) { orderHash := getOrderHash(longOrder) mockBibliophile.EXPECT().GetOrderStatus(orderHash).Return(int64(juror.Placed)).Times(1) - mockBibliophile.EXPECT().GetTimeStamp().Return(hu.V1ActivationTime).Times(1) - mockBibliophile.EXPECT().GetAvailableMargin(longOrder.Trader, hu.V1).Return(big.NewInt(0)).Times(1) + mockBibliophile.EXPECT().GetAvailableMargin(longOrder.Trader, hu.V2).Return(big.NewInt(0)).Times(1) mockBibliophile.EXPECT().IsValidator(longOrder.Trader).Return(true).Times(1) mockBibliophile.EXPECT().GetOrderFilledAmount(orderHash).Return(big.NewInt(0)).Times(1) mockBibliophile.EXPECT().GetMarketAddressFromMarketID(longOrder.AmmIndex.Int64()).Return(ammAddress).Times(1) @@ -149,8 +148,7 @@ func TestValidateCancelLimitOrderV2(t *testing.T) { orderHash := getOrderHash(shortOrder) mockBibliophile.EXPECT().GetOrderStatus(orderHash).Return(int64(juror.Placed)).Times(1) - mockBibliophile.EXPECT().GetTimeStamp().Return(hu.V1ActivationTime).Times(1) - mockBibliophile.EXPECT().GetAvailableMargin(shortOrder.Trader, hu.V1).Return(big.NewInt(0)).Times(1) + mockBibliophile.EXPECT().GetAvailableMargin(shortOrder.Trader, hu.V2).Return(big.NewInt(0)).Times(1) mockBibliophile.EXPECT().IsValidator(shortOrder.Trader).Return(true).Times(1) mockBibliophile.EXPECT().GetOrderFilledAmount(orderHash).Return(big.NewInt(0)).Times(1) mockBibliophile.EXPECT().GetMarketAddressFromMarketID(shortOrder.AmmIndex.Int64()).Return(ammAddress).Times(1) @@ -170,8 +168,7 @@ func TestValidateCancelLimitOrderV2(t *testing.T) { orderHash := getOrderHash(longOrder) mockBibliophile.EXPECT().GetOrderStatus(orderHash).Return(int64(juror.Placed)).Times(1) - mockBibliophile.EXPECT().GetTimeStamp().Return(hu.V1ActivationTime).Times(1) - mockBibliophile.EXPECT().GetAvailableMargin(longOrder.Trader, hu.V1).Return(newMargin).Times(1) + mockBibliophile.EXPECT().GetAvailableMargin(longOrder.Trader, hu.V2).Return(newMargin).Times(1) mockBibliophile.EXPECT().IsValidator(longOrder.Trader).Return(true).Times(1) mockBibliophile.EXPECT().GetOrderFilledAmount(orderHash).Return(big.NewInt(0)).Times(1) mockBibliophile.EXPECT().GetMarketAddressFromMarketID(longOrder.AmmIndex.Int64()).Return(ammAddress).Times(1) @@ -187,8 +184,7 @@ func TestValidateCancelLimitOrderV2(t *testing.T) { orderHash := getOrderHash(shortOrder) mockBibliophile.EXPECT().GetOrderStatus(orderHash).Return(int64(juror.Placed)).Times(1) - mockBibliophile.EXPECT().GetTimeStamp().Return(hu.V1ActivationTime).Times(1) - mockBibliophile.EXPECT().GetAvailableMargin(shortOrder.Trader, hu.V1).Return(newMargin).Times(1) + mockBibliophile.EXPECT().GetAvailableMargin(shortOrder.Trader, hu.V2).Return(newMargin).Times(1) mockBibliophile.EXPECT().IsValidator(shortOrder.Trader).Return(true).Times(1) mockBibliophile.EXPECT().GetOrderFilledAmount(orderHash).Return(big.NewInt(0)).Times(1) mockBibliophile.EXPECT().GetMarketAddressFromMarketID(shortOrder.AmmIndex.Int64()).Return(ammAddress).Times(1) @@ -208,8 +204,7 @@ func TestValidateCancelLimitOrderV2(t *testing.T) { orderHash := getOrderHash(longOrder) mockBibliophile.EXPECT().GetOrderStatus(orderHash).Return(int64(juror.Placed)).Times(1) - mockBibliophile.EXPECT().GetTimeStamp().Return(hu.V1ActivationTime).Times(1) - mockBibliophile.EXPECT().GetAvailableMargin(longOrder.Trader, hu.V1).Return(big.NewInt(-1)).Times(1) + mockBibliophile.EXPECT().GetAvailableMargin(longOrder.Trader, hu.V2).Return(big.NewInt(-1)).Times(1) mockBibliophile.EXPECT().GetOrderFilledAmount(orderHash).Return(big.NewInt(0)).Times(1) mockBibliophile.EXPECT().GetMarketAddressFromMarketID(longOrder.AmmIndex.Int64()).Return(ammAddress).Times(1) mockBibliophile.EXPECT().IsValidator(longOrder.Trader).Return(true).Times(1) @@ -226,8 +221,7 @@ func TestValidateCancelLimitOrderV2(t *testing.T) { orderHash := getOrderHash(shortOrder) mockBibliophile.EXPECT().GetOrderStatus(orderHash).Return(int64(juror.Placed)).Times(1) - mockBibliophile.EXPECT().GetTimeStamp().Return(hu.V1ActivationTime).Times(1) - mockBibliophile.EXPECT().GetAvailableMargin(shortOrder.Trader, hu.V1).Return(big.NewInt(-1)).Times(1) + mockBibliophile.EXPECT().GetAvailableMargin(shortOrder.Trader, hu.V2).Return(big.NewInt(-1)).Times(1) mockBibliophile.EXPECT().GetOrderFilledAmount(orderHash).Return(big.NewInt(0)).Times(1) mockBibliophile.EXPECT().GetMarketAddressFromMarketID(shortOrder.AmmIndex.Int64()).Return(ammAddress).Times(1) mockBibliophile.EXPECT().IsValidator(shortOrder.Trader).Return(true).Times(1) @@ -247,8 +241,7 @@ func TestValidateCancelLimitOrderV2(t *testing.T) { filledAmount := hu.Div(longOrder.BaseAssetQuantity, big.NewInt(2)) mockBibliophile.EXPECT().GetOrderStatus(orderHash).Return(int64(juror.Placed)).Times(1) - mockBibliophile.EXPECT().GetTimeStamp().Return(hu.V1ActivationTime).Times(1) - mockBibliophile.EXPECT().GetAvailableMargin(longOrder.Trader, hu.V1).Return(big.NewInt(-1)).Times(1) + mockBibliophile.EXPECT().GetAvailableMargin(longOrder.Trader, hu.V2).Return(big.NewInt(-1)).Times(1) mockBibliophile.EXPECT().GetOrderFilledAmount(orderHash).Return(filledAmount).Times(1) mockBibliophile.EXPECT().GetMarketAddressFromMarketID(longOrder.AmmIndex.Int64()).Return(ammAddress).Times(1) mockBibliophile.EXPECT().IsValidator(longOrder.Trader).Return(true).Times(1) @@ -267,8 +260,7 @@ func TestValidateCancelLimitOrderV2(t *testing.T) { filledAmount := hu.Div(shortOrder.BaseAssetQuantity, big.NewInt(2)) mockBibliophile.EXPECT().GetOrderStatus(orderHash).Return(int64(juror.Placed)).Times(1) - mockBibliophile.EXPECT().GetTimeStamp().Return(hu.V1ActivationTime).Times(1) - mockBibliophile.EXPECT().GetAvailableMargin(shortOrder.Trader, hu.V1).Return(big.NewInt(-1)).Times(1) + mockBibliophile.EXPECT().GetAvailableMargin(shortOrder.Trader, hu.V2).Return(big.NewInt(-1)).Times(1) mockBibliophile.EXPECT().GetOrderFilledAmount(orderHash).Return(filledAmount).Times(1) mockBibliophile.EXPECT().GetMarketAddressFromMarketID(shortOrder.AmmIndex.Int64()).Return(ammAddress).Times(1) mockBibliophile.EXPECT().IsValidator(shortOrder.Trader).Return(true).Times(1) diff --git a/precompile/contracts/traderviewer/viewer.go b/precompile/contracts/traderviewer/viewer.go index 7c264bc0d5..63b2a42a27 100644 --- a/precompile/contracts/traderviewer/viewer.go +++ b/precompile/contracts/traderviewer/viewer.go @@ -2,7 +2,6 @@ package traderviewer import ( "math/big" - hu "github.com/ava-labs/subnet-evm/plugin/evm/orderbook/hubbleutils" b "github.com/ava-labs/subnet-evm/precompile/contracts/bibliophile" "github.com/ethereum/go-ethereum/common" ) @@ -17,7 +16,7 @@ func GetNotionalPositionAndMargin(bibliophile b.BibliophileClient, input *GetNot } func GetCrossMarginAccountData(bibliophile b.BibliophileClient, input *GetCrossMarginAccountDataInput) GetCrossMarginAccountDataOutput { - notionalPosition, requiredMargin, unrealizedPnl, pendingFunding := bibliophile.GetCrossMarginAccountData(input.Trader, input.Mode, hu.V2) // @todo check if this is the right upgrade version + notionalPosition, requiredMargin, unrealizedPnl, pendingFunding := bibliophile.GetCrossMarginAccountData(input.Trader, input.Mode) return GetCrossMarginAccountDataOutput{ NotionalPosition: notionalPosition, RequiredMargin: requiredMargin,