diff --git a/package.json b/package.json index a21346eb8..4945afc9d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kwenta", - "version": "7.4.17", + "version": "7.4.19", "description": "Kwenta", "main": "index.js", "scripts": { diff --git a/packages/app/package.json b/packages/app/package.json index 1f90ea217..87598a985 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -1,6 +1,6 @@ { "name": "@kwenta/app", - "version": "7.4.17", + "version": "7.4.19", "scripts": { "dev": "next", "build": "next build", diff --git a/packages/app/src/__tests__/pages/smartMargin.test.tsx b/packages/app/src/__tests__/pages/smartMargin.test.tsx index 3ea217f35..9c3c8be22 100644 --- a/packages/app/src/__tests__/pages/smartMargin.test.tsx +++ b/packages/app/src/__tests__/pages/smartMargin.test.tsx @@ -149,10 +149,15 @@ describe('Futures market page - smart margin', () => { // Update the mock to return some different data sdk.futures.getMarkets = () => Promise.resolve([{ ...SDK_MARKETS[1], marketLimitUsd: wei(100000) } as PerpsMarketV2]) + sdk.futures.getSmartMarginBalanceInfo = () => + Promise.resolve({ + freeMargin: wei('100000'), + keeperEthBal: wei('0.1'), + walletEthBal: wei('1'), + allowance: wei('1000'), + }) - const store = setupStore( - preloadedStateWithSmartMarginAccount(mockSmartMarginAccount('1000000')) - ) + const store = setupStore(preloadedStateWithSmartMarginAccount(mockSmartMarginAccount('100000'))) const { findByTestId, findByText } = render( diff --git a/packages/app/src/sections/futures/TradeConfirmation/TradeConfirmationModal.tsx b/packages/app/src/sections/futures/TradeConfirmation/TradeConfirmationModal.tsx index bef5950fc..cebfd2064 100644 --- a/packages/app/src/sections/futures/TradeConfirmation/TradeConfirmationModal.tsx +++ b/packages/app/src/sections/futures/TradeConfirmation/TradeConfirmationModal.tsx @@ -202,7 +202,7 @@ export default function TradeConfirmationModal({ const disabledReason = useMemo(() => { if (showEthBalWarning) { return t('futures.market.trade.confirmation.modal.disabled-eth-bal', { - depositAmount: stripZeros(keeperFee?.toString()), + depositAmount: formatNumber(stripZeros(keeperFee?.toString()), { suggestDecimals: true }), }) } if (positionDetails?.exceedsPriceProtection && !overridePriceProtection) { diff --git a/packages/app/src/state/__mocks__/sdk.ts b/packages/app/src/state/__mocks__/sdk.ts index a7e8b495a..c72a3e2a0 100644 --- a/packages/app/src/state/__mocks__/sdk.ts +++ b/packages/app/src/state/__mocks__/sdk.ts @@ -17,34 +17,9 @@ export const mockFuturesService = () => ({ getTradesForMarkets: () => [], getAllTrades: () => [], getConditionalOrders: () => [], - getIsolatedMarginTransfers: () => [], + getMarketMarginTransfers: () => [], getDelayedOrders: () => [], - getSmartMarginTransfers: () => [], - getSmartMarginBalanceInfo: () => ({ - freeMargin: wei('1000'), - keeperEthBal: wei('0.1'), - walletEthBal: wei('1'), - allowance: wei('1000'), - }), - getMarkets: () => { - return [...SDK_MARKETS] - }, - submitCrossMarginOrder: mockSubmitCrossMarginOrder, -}) - -export const mockPerpsService = () => ({ - getSmartMarginAccounts: () => ['0x7bCe4eF9d95129011528E502357C7772'], - getPreviousDayPrices: () => [], - getSmartMarginTradePreview: () => { - return { ...MOCK_TRADE_PREVIEW } - }, - getFuturesPositions: () => [], - getTradesForMarkets: () => [], - getAllTrades: () => [], - getConditionalOrders: () => [], - getIsolatedMarginTransfers: () => [], - getDelayedOrders: () => [], - getSmartMarginTransfers: () => [], + getSmartMarginAccountTransfers: () => [], getSmartMarginBalanceInfo: () => ({ freeMargin: wei('1000'), keeperEthBal: wei('0.1'), diff --git a/packages/app/src/state/futures/selectors.ts b/packages/app/src/state/futures/selectors.ts index 292eb2102..11410529f 100644 --- a/packages/app/src/state/futures/selectors.ts +++ b/packages/app/src/state/futures/selectors.ts @@ -9,7 +9,6 @@ import { truncateTimestamp } from '@kwenta/sdk/utils' import { createSelector } from '@reduxjs/toolkit' import { wei } from '@synthetixio/wei' -import { selectSNXUSDBalance, selectSusdBalance } from 'state/balances/selectors' import { selectAllCrossMarginTrades, selectCrossMarginAccountData, @@ -366,7 +365,7 @@ export const selectTradePrice = createSelector( selectSmartMarginOrderPrice, selectMarketIndexPrice, (type, orderPrice, indexPrice) => { - return type === FuturesMarginType.CROSS_MARGIN ? indexPrice : wei(orderPrice || 0) + return type === FuturesMarginType.CROSS_MARGIN ? indexPrice : wei(orderPrice || indexPrice) } ) diff --git a/packages/app/src/state/futures/smartMargin/selectors.ts b/packages/app/src/state/futures/smartMargin/selectors.ts index 63be5bf2d..caf0f8c2d 100644 --- a/packages/app/src/state/futures/smartMargin/selectors.ts +++ b/packages/app/src/state/futures/smartMargin/selectors.ts @@ -512,7 +512,7 @@ export const selectSmartMarginDepositApproved = createSelector( } ) -export const selectMarginInMarkets = (isSuspended: boolean = false) => +export const selectIdleMarginInMarkets = (isSuspended: boolean = false) => createSelector(selectAllSmartMarginPositions, (positions) => { const idleInMarkets = positions .filter((p) => { @@ -523,9 +523,9 @@ export const selectMarginInMarkets = (isSuspended: boolean = false) => return idleInMarkets }) -export const selectAvailableMarginInMarkets = selectMarginInMarkets() +export const selectAvailableMarginInMarkets = selectIdleMarginInMarkets() -export const selectLockedMarginInMarkets = selectMarginInMarkets(true) +export const selectLockedMarginInMarkets = selectIdleMarginInMarkets(true) export const selectIdleAccountMargin = createSelector( selectAvailableMarginInMarkets, @@ -633,9 +633,8 @@ export const selectKeeperDepositExceedsBal = createSelector( export const selectEditPositionModalInfo = createSelector( selectEditPositionModalMarket, selectSmartMarginActivePositions, - selectV2Markets, selectPrices, - (modalMarketKey, smartPositions, markets, prices) => { + (modalMarketKey, smartPositions, prices) => { const position = smartPositions.find((p) => p.market.marketKey === modalMarketKey) if (!position || position.market.version === 3) return { position: null, market: null, marketPrice: wei(0) } diff --git a/packages/app/src/translations/en.json b/packages/app/src/translations/en.json index 7fcd692cb..990da697b 100644 --- a/packages/app/src/translations/en.json +++ b/packages/app/src/translations/en.json @@ -965,7 +965,7 @@ "disabled-min-margin": "Minimum market margin of $50 required", "disabled-eth-bal": "Min ETH {{depositAmount}} balance required", "disabled-exceeds-price-protection": "Price protection exceeded ", - "eth-bal-warning": "The limit order service requires some ETH to cover gas. The 0.01 ETH deposit will cover many orders and you can withdraw any unused balance.", + "eth-bal-warning": "Conditional orders require a small ETH deposit to use for gas when executing", "delayed-disclaimer": "The fee amount will be deposited to cover trade and automated execution fees. If an order is cancelled or not executed, the deposit will be forfeited to the Synthetix debt pool.", "stop-loss-warning": "Stop loss is close to the liquidation price and cannot be guaranteed to execute before you get liquidated, proceed anyway?", "slippage-warning": "This trade incurs high slippage, proceed anyway?" diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 262113ef3..a7344dc28 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@kwenta/sdk", - "version": "1.0.5", + "version": "1.0.6", "description": "SDK for headless interaction with Kwenta", "main": "dist/index.js", "directories": { diff --git a/packages/sdk/src/contracts/PerpsV2MarketInternalV2.ts b/packages/sdk/src/contracts/PerpsV2MarketInternalV2.ts index a535df99c..01fccb70d 100644 --- a/packages/sdk/src/contracts/PerpsV2MarketInternalV2.ts +++ b/packages/sdk/src/contracts/PerpsV2MarketInternalV2.ts @@ -201,8 +201,10 @@ class FuturesMarketInternal { const minInitialMargin = await this._getSetting('minInitialMargin') const positionDecreasing = - oldPos.size.gte(ZERO_BIG_NUM) === newPos.size.gte(ZERO_BIG_NUM) && - newPos.size.abs().lt(oldPos.size.abs()) + newPos.size.eq(ZERO_BIG_NUM) || + (oldPos.size.gte(ZERO_BIG_NUM) === newPos.size.gte(ZERO_BIG_NUM) && + newPos.size.abs().lt(oldPos.size.abs())) + if (!positionDecreasing) { if (newPos.margin.add(fee).lt(minInitialMargin)) { return {