diff --git a/package.json b/package.json index e33394de..6a6ce0da 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "pnpm": ">=10.4.0" }, "dependencies": { - "@compolabs/spark-orderbook-ts-sdk": "https://registry.npmjs.org/@compolabs/spark-orderbook-ts-sdk/-/spark-orderbook-ts-sdk-1.16.4.tgz", + "@compolabs/spark-orderbook-ts-sdk": "https://registry.npmjs.org/@compolabs/spark-orderbook-ts-sdk/-/spark-orderbook-ts-sdk-1.16.5.tgz", "@compolabs/tradingview-chart": "^1.0.21", "@emotion/react": "^11.11.3", "@emotion/styled": "^11.11.0", @@ -107,7 +107,7 @@ "last 1 safari version" ] }, - "packageManager": "pnpm@10.4.0+sha512.6b849d0787d97f8f4e1f03a9b8ff8f038e79e153d6f11ae539ae7c435ff9e796df6a862c991502695c7f9e8fac8aeafc1ac5a8dab47e36148d183832d886dd52", + "packageManager": "pnpm@10.6.3+sha512.bb45e34d50a9a76e858a95837301bfb6bd6d35aea2c5d52094fa497a467c43f5c440103ce2511e9e0a2f89c3d6071baac3358fc68ac6fb75e2ceb3d2736065e6", "pnpm": { "overrides": {} } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b48eecc5..df34b68a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: '@compolabs/spark-orderbook-ts-sdk': - specifier: https://registry.npmjs.org/@compolabs/spark-orderbook-ts-sdk/-/spark-orderbook-ts-sdk-1.16.4.tgz - version: https://registry.npmjs.org/@compolabs/spark-orderbook-ts-sdk/-/spark-orderbook-ts-sdk-1.16.4.tgz(@types/react@18.3.18)(fuels@0.97.2(vitest@2.0.5(@types/node@22.13.4)))(graphql@16.10.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + specifier: https://registry.npmjs.org/@compolabs/spark-orderbook-ts-sdk/-/spark-orderbook-ts-sdk-1.16.5.tgz + version: https://registry.npmjs.org/@compolabs/spark-orderbook-ts-sdk/-/spark-orderbook-ts-sdk-1.16.5.tgz(@types/react@18.3.18)(fuels@0.97.2(vitest@2.0.5(@types/node@22.13.4)))(graphql@16.10.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@compolabs/tradingview-chart': specifier: ^1.0.21 version: 1.0.21 @@ -241,8 +241,8 @@ packages: resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==} engines: {node: '>=6.0.0'} - '@apollo/client@3.13.1': - resolution: {integrity: sha512-HaAt62h3jNUXpJ1v5HNgUiCzPP1c5zc2Q/FeTb2cTk/v09YlhoqKKHQFJI7St50VCJ5q8JVIc03I5bRcBrQxsg==} + '@apollo/client@3.13.4': + resolution: {integrity: sha512-Ot3RaN2M/rhIKDqXBdOVlN0dQbHydUrYJ9lTxkvd6x7W1pAjwduUccfoz2gsO4U9by7oWtRj/ySF0MFNUp+9Aw==} peerDependencies: graphql: ^15.0.0 || ^16.0.0 graphql-ws: ^5.5.5 || ^6.0.3 @@ -916,9 +916,9 @@ packages: '@coinbase/wallet-sdk@4.3.0': resolution: {integrity: sha512-T3+SNmiCw4HzDm4we9wCHCxlP0pqCiwKe4sOwPH3YAK2KSKjxPRydKu6UQJrdONFVLG7ujXvbd/6ZqmvJb8rkw==} - '@compolabs/spark-orderbook-ts-sdk@https://registry.npmjs.org/@compolabs/spark-orderbook-ts-sdk/-/spark-orderbook-ts-sdk-1.16.4.tgz': - resolution: {tarball: https://registry.npmjs.org/@compolabs/spark-orderbook-ts-sdk/-/spark-orderbook-ts-sdk-1.16.4.tgz} - version: 1.16.4 + '@compolabs/spark-orderbook-ts-sdk@https://registry.npmjs.org/@compolabs/spark-orderbook-ts-sdk/-/spark-orderbook-ts-sdk-1.16.5.tgz': + resolution: {tarball: https://registry.npmjs.org/@compolabs/spark-orderbook-ts-sdk/-/spark-orderbook-ts-sdk-1.16.5.tgz} + version: 1.16.5 engines: {node: '>=18'} peerDependencies: fuels: '>=0.97.1' @@ -6386,7 +6386,7 @@ snapshots: '@jridgewell/gen-mapping': 0.3.8 '@jridgewell/trace-mapping': 0.3.25 - '@apollo/client@3.13.1(@types/react@18.3.18)(graphql-ws@5.16.2(graphql@16.10.0))(graphql@16.10.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@apollo/client@3.13.4(@types/react@18.3.18)(graphql-ws@5.16.2(graphql@16.10.0))(graphql@16.10.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: '@graphql-typed-document-node/core': 3.2.0(graphql@16.10.0) '@wry/caches': 1.0.1 @@ -7264,9 +7264,9 @@ snapshots: eventemitter3: 5.0.1 preact: 10.26.0 - '@compolabs/spark-orderbook-ts-sdk@https://registry.npmjs.org/@compolabs/spark-orderbook-ts-sdk/-/spark-orderbook-ts-sdk-1.16.4.tgz(@types/react@18.3.18)(fuels@0.97.2(vitest@2.0.5(@types/node@22.13.4)))(graphql@16.10.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@compolabs/spark-orderbook-ts-sdk@https://registry.npmjs.org/@compolabs/spark-orderbook-ts-sdk/-/spark-orderbook-ts-sdk-1.16.5.tgz(@types/react@18.3.18)(fuels@0.97.2(vitest@2.0.5(@types/node@22.13.4)))(graphql@16.10.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: - '@apollo/client': 3.13.1(@types/react@18.3.18)(graphql-ws@5.16.2(graphql@16.10.0))(graphql@16.10.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@apollo/client': 3.13.4(@types/react@18.3.18)(graphql-ws@5.16.2(graphql@16.10.0))(graphql@16.10.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) axios: 1.7.9 bignumber.js: 9.1.2 fuels: 0.97.2(vitest@2.0.5(@types/node@22.13.4)) diff --git a/src/blockchain/FuelNetwork.ts b/src/blockchain/FuelNetwork.ts index 3144783b..f39241de 100644 --- a/src/blockchain/FuelNetwork.ts +++ b/src/blockchain/FuelNetwork.ts @@ -2,9 +2,8 @@ import { Account, B256Address } from "fuels"; import { makeObservable } from "mobx"; import { Nullable } from "tsdef"; -import SparkOrderBookSdk, { OrderType, WriteTransactionResponse } from "@compolabs/spark-orderbook-ts-sdk"; +import SparkOrderBookSdk, { BN, OrderType, WriteTransactionResponse } from "@compolabs/spark-orderbook-ts-sdk"; -import BN from "@utils/BN"; import { CONFIG } from "@utils/getConfig"; import { Token } from "@entity"; @@ -100,12 +99,6 @@ export class FuelNetwork { await this.walletManager.addAsset(assetId); }; - createSpotOrder = async ( - ...params: Parameters - ): Promise => { - return this.orderbookSdk.createOrder(...params); - }; - createSpotOrderWithDeposit = async ( ...params: Parameters ): Promise => { diff --git a/src/blockchain/types/index.ts b/src/blockchain/types/index.ts index 6b9b0daf..8ea89b64 100644 --- a/src/blockchain/types/index.ts +++ b/src/blockchain/types/index.ts @@ -1,4 +1,4 @@ -import BN from "@utils/BN"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; export type FetchTradesParams = { limit: number; diff --git a/src/components/CompressedNumber.tsx b/src/components/CompressedNumber.tsx index d9071e53..2c1b0474 100644 --- a/src/components/CompressedNumber.tsx +++ b/src/components/CompressedNumber.tsx @@ -1,6 +1,6 @@ import React, { useMemo } from "react"; -import BN from "@utils/BN"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; import { SmartFlex } from "./SmartFlex"; import Text from "./Text"; diff --git a/src/components/Modal/AccountInfoSheet.tsx b/src/components/Modal/AccountInfoSheet.tsx index 3005fa63..4c15475b 100644 --- a/src/components/Modal/AccountInfoSheet.tsx +++ b/src/components/Modal/AccountInfoSheet.tsx @@ -2,6 +2,8 @@ import React from "react"; import styled from "@emotion/styled"; import copy from "copy-to-clipboard"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import copyIcon from "@assets/icons/copy.svg"; import linkIcon from "@assets/icons/link.svg"; import logoutIcon from "@assets/icons/logout.svg"; @@ -9,7 +11,6 @@ import logoutIcon from "@assets/icons/logout.svg"; import { useWallet } from "@hooks/useWallet"; import { useStores } from "@stores"; -import BN from "@utils/BN"; import { getExplorerLinkByAddress } from "@utils/getExplorerLink"; import { FuelNetwork } from "@blockchain"; diff --git a/src/components/Modal/SpotOrderSettingsSheet.tsx b/src/components/Modal/SpotOrderSettingsSheet.tsx index c2ba9f34..93f7eb68 100644 --- a/src/components/Modal/SpotOrderSettingsSheet.tsx +++ b/src/components/Modal/SpotOrderSettingsSheet.tsx @@ -1,7 +1,7 @@ import React from "react"; import styled from "@emotion/styled"; -import BN from "@utils/BN"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; import Sheet from "../Sheet"; import { SmartFlex } from "../SmartFlex"; diff --git a/src/components/SelectAssets/AssetBlock.tsx b/src/components/SelectAssets/AssetBlock.tsx index dfeb7ca1..4eef5792 100644 --- a/src/components/SelectAssets/AssetBlock.tsx +++ b/src/components/SelectAssets/AssetBlock.tsx @@ -3,13 +3,14 @@ import { useTheme } from "@emotion/react"; import styled from "@emotion/styled"; import { observer } from "mobx-react"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import { SmartFlex } from "@components/SmartFlex"; import Text from "@components/Text"; import { useStores } from "@stores"; import { DEFAULT_DECIMALS } from "@constants"; -import BN from "@utils/BN"; import { AssetBlockData } from "./SelectAssetsInput"; diff --git a/src/components/SelectAssets/SelectAssetsInput.tsx b/src/components/SelectAssets/SelectAssetsInput.tsx index 18589c10..4bebd4a4 100644 --- a/src/components/SelectAssets/SelectAssetsInput.tsx +++ b/src/components/SelectAssets/SelectAssetsInput.tsx @@ -2,6 +2,8 @@ import React, { HTMLAttributes, useState } from "react"; import { useTheme } from "@emotion/react"; import styled from "@emotion/styled"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import Button from "@components/Button"; import { IAssetBlock } from "@components/SelectAssets/AssetBlock"; import { SmartFlex } from "@components/SmartFlex"; @@ -10,7 +12,6 @@ import { BigNumberInput } from "@components/TokenInput/BigNumberInput"; import { TokenSelect } from "@screens/SwapScreen/TokenSelect"; import { DEFAULT_DECIMALS } from "@constants"; -import BN from "@utils/BN"; import { Token } from "@entity"; diff --git a/src/components/TokenInput/BigNumberInput.tsx b/src/components/TokenInput/BigNumberInput.tsx index b2e8750b..d1d038a3 100644 --- a/src/components/TokenInput/BigNumberInput.tsx +++ b/src/components/TokenInput/BigNumberInput.tsx @@ -2,8 +2,9 @@ import React, { useEffect, useRef, useState } from "react"; import BigNumber from "bignumber.js"; import { Nullable } from "tsdef"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import { DEFAULT_DECIMALS } from "@constants"; -import BN from "@utils/BN"; type HTMLInputProps = React.ClassAttributes & React.InputHTMLAttributes; diff --git a/src/components/TokenInput/TokenInput.tsx b/src/components/TokenInput/TokenInput.tsx index 4e941555..adc04426 100644 --- a/src/components/TokenInput/TokenInput.tsx +++ b/src/components/TokenInput/TokenInput.tsx @@ -2,12 +2,12 @@ import React, { CSSProperties, useEffect, useState } from "react"; import styled from "@emotion/styled"; import { observer } from "mobx-react-lite"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import Chip from "@components/Chip"; import Text, { TEXT_TYPES_MAP } from "@components/Text"; import { media } from "@themes/breakpoints"; -import BN from "@utils/BN"; - import { FuelNetwork } from "@blockchain"; import AmountInput from "./AmountInput"; diff --git a/src/components/WalletButton.tsx b/src/components/WalletButton.tsx index 52f2cdde..0dc0e438 100644 --- a/src/components/WalletButton.tsx +++ b/src/components/WalletButton.tsx @@ -3,6 +3,8 @@ import styled from "@emotion/styled"; import copy from "copy-to-clipboard"; import { observer } from "mobx-react"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import Divider from "@components/Divider"; import { Column, Row } from "@components/Flex"; import Text from "@components/Text"; @@ -15,7 +17,6 @@ import logoutIcon from "@assets/icons/logout.svg"; import { useWallet } from "@hooks/useWallet"; import { useStores } from "@stores"; -import BN from "@utils/BN"; import { getExplorerLinkByAddress } from "@utils/getExplorerLink"; import { FuelNetwork } from "@blockchain"; diff --git a/src/entity/PerpMarket.ts b/src/entity/PerpMarket.ts index d8267b1b..945d5271 100644 --- a/src/entity/PerpMarket.ts +++ b/src/entity/PerpMarket.ts @@ -1,9 +1,10 @@ import { makeAutoObservable } from "mobx"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import { FuelNetwork } from "@blockchain"; import { DEFAULT_DECIMALS } from "../constants"; -import BN from "../utils/BN"; import { Token } from "./Token"; diff --git a/src/entity/PerpMarketTrade.ts b/src/entity/PerpMarketTrade.ts index f74c5d8a..7e1d285f 100644 --- a/src/entity/PerpMarketTrade.ts +++ b/src/entity/PerpMarketTrade.ts @@ -2,8 +2,9 @@ import dayjs, { Dayjs } from "dayjs"; import { Address, isBech32 } from "fuels"; import { Nullable } from "tsdef"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import { DEFAULT_DECIMALS } from "@constants"; -import BN from "@utils/BN"; import { FuelNetwork } from "@blockchain"; diff --git a/src/entity/PerpOrder.ts b/src/entity/PerpOrder.ts index ae7a070b..f69fced5 100644 --- a/src/entity/PerpOrder.ts +++ b/src/entity/PerpOrder.ts @@ -1,12 +1,12 @@ import { makeAutoObservable } from "mobx"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import { DEFAULT_DECIMALS } from "@constants"; import { toCurrency } from "@utils/toCurrency"; import { FuelNetwork } from "@blockchain"; -import BN from "../utils/BN"; - import { Token } from "./Token"; interface PerpOrderParams { diff --git a/src/entity/PerpPosition.ts b/src/entity/PerpPosition.ts index bd199905..8e008b0c 100644 --- a/src/entity/PerpPosition.ts +++ b/src/entity/PerpPosition.ts @@ -1,8 +1,8 @@ import { makeAutoObservable } from "mobx"; -import { FuelNetwork } from "@blockchain"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; -import BN from "../utils/BN"; +import { FuelNetwork } from "@blockchain"; import { Token } from "./Token"; diff --git a/src/entity/SpotMarket.ts b/src/entity/SpotMarket.ts index 44ce9ec8..8eaf34fa 100644 --- a/src/entity/SpotMarket.ts +++ b/src/entity/SpotMarket.ts @@ -1,7 +1,8 @@ import { makeAutoObservable } from "mobx"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import { DEFAULT_DECIMALS } from "@constants"; -import BN from "@utils/BN"; import { Market } from "@utils/getConfig"; import { FuelNetwork } from "@blockchain"; diff --git a/src/entity/SpotMarketOrder.ts b/src/entity/SpotMarketOrder.ts index e3a1da53..0bf6fb07 100644 --- a/src/entity/SpotMarketOrder.ts +++ b/src/entity/SpotMarketOrder.ts @@ -1,9 +1,8 @@ import dayjs, { Dayjs } from "dayjs"; -import { Order } from "@compolabs/spark-orderbook-ts-sdk"; +import { BN, Order } from "@compolabs/spark-orderbook-ts-sdk"; import { DEFAULT_DECIMALS } from "@constants"; -import BN from "@utils/BN"; import { CONFIG } from "@utils/getConfig"; import { FuelNetwork } from "@blockchain"; diff --git a/src/screens/Assets/BalanceBlock/BalanceBlock.tsx b/src/screens/Assets/BalanceBlock/BalanceBlock.tsx index 427471e7..29b27d2a 100644 --- a/src/screens/Assets/BalanceBlock/BalanceBlock.tsx +++ b/src/screens/Assets/BalanceBlock/BalanceBlock.tsx @@ -2,6 +2,8 @@ import React from "react"; import { useTheme } from "@emotion/react"; import styled from "@emotion/styled"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import { AssetBlockData } from "@components/SelectAssets/SelectAssetsInput"; import { SmartFlex } from "@components/SmartFlex"; import Text from "@components/Text"; @@ -9,7 +11,6 @@ import Text from "@components/Text"; import { useStores } from "@stores"; import { DEFAULT_DECIMALS } from "@constants"; -import BN from "@utils/BN"; interface IBalanceBlock { icon: React.ReactElement; diff --git a/src/screens/Assets/DepositAssets/DepositAssets.tsx b/src/screens/Assets/DepositAssets/DepositAssets.tsx index 14e30e1f..d282380f 100644 --- a/src/screens/Assets/DepositAssets/DepositAssets.tsx +++ b/src/screens/Assets/DepositAssets/DepositAssets.tsx @@ -3,6 +3,8 @@ import { useNavigate } from "react-router-dom"; import styled from "@emotion/styled"; import { observer } from "mobx-react"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import Button from "@components/Button"; import { IAssetBlock } from "@components/SelectAssets/AssetBlock"; import SelectAssetsInput from "@components/SelectAssets/SelectAssetsInput"; @@ -20,7 +22,6 @@ import { useStores } from "@stores"; import { BalanceBlock } from "@screens/Assets/BalanceBlock/BalanceBlock"; import { DEFAULT_DECIMALS } from "@constants"; -import BN from "@utils/BN"; interface DepositAssetsProps { setStep: (value: number) => void; diff --git a/src/screens/Assets/MainAssets/MainAssets.tsx b/src/screens/Assets/MainAssets/MainAssets.tsx index a609d27e..680470b7 100644 --- a/src/screens/Assets/MainAssets/MainAssets.tsx +++ b/src/screens/Assets/MainAssets/MainAssets.tsx @@ -4,6 +4,8 @@ import { useTheme } from "@emotion/react"; import styled from "@emotion/styled"; import { observer } from "mobx-react"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import Button from "@components/Button"; import { Column } from "@components/Flex"; import AssetBlock from "@components/SelectAssets/AssetBlock"; @@ -21,7 +23,6 @@ import { MIXPANEL_EVENTS } from "@stores/MixPanelStore"; import { MODAL_TYPE } from "@stores/ModalStore"; import { BRIDGE_LINK } from "@constants"; -import BN from "@utils/BN"; interface MainAssetsProps { setStep: (value: number) => void; diff --git a/src/screens/Assets/WithdrawAssets/WithdrawAssets.tsx b/src/screens/Assets/WithdrawAssets/WithdrawAssets.tsx index b64b710d..b82b7ebd 100644 --- a/src/screens/Assets/WithdrawAssets/WithdrawAssets.tsx +++ b/src/screens/Assets/WithdrawAssets/WithdrawAssets.tsx @@ -2,6 +2,8 @@ import React, { useEffect, useState } from "react"; import styled from "@emotion/styled"; import { observer } from "mobx-react"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import Button from "@components/Button"; import { IAssetBlock } from "@components/SelectAssets/AssetBlock"; import SelectAssetsInput from "@components/SelectAssets/SelectAssetsInput"; @@ -20,7 +22,6 @@ import { BalanceBlock } from "@screens/Assets/BalanceBlock/BalanceBlock"; import { ModalEnums, TypeTransaction } from "@screens/Assets/enums/actionEnums"; import { DEFAULT_DECIMALS } from "@constants"; -import BN from "@utils/BN"; interface WithdrawAssets { setStep: (value: number) => void; diff --git a/src/screens/Competitions/CompetitionsTable/CompetitionsItem.tsx b/src/screens/Competitions/CompetitionsTable/CompetitionsItem.tsx index 5f3ec9f0..b4e33806 100644 --- a/src/screens/Competitions/CompetitionsTable/CompetitionsItem.tsx +++ b/src/screens/Competitions/CompetitionsTable/CompetitionsItem.tsx @@ -4,7 +4,7 @@ import styled from "@emotion/styled"; import copy from "copy-to-clipboard"; import { observer } from "mobx-react"; -import { GetCompetitionResponse } from "@compolabs/spark-orderbook-ts-sdk"; +import { BN, GetCompetitionResponse } from "@compolabs/spark-orderbook-ts-sdk"; import { SmartFlex } from "@components/SmartFlex"; import Text from "@components/Text"; @@ -17,7 +17,6 @@ import three from "@assets/images/3st.png"; import { useStores } from "@stores"; -import BN from "@utils/BN"; import { toCurrency } from "@utils/toCurrency.ts"; const generatePosition = (key: number) => { diff --git a/src/screens/Leaderboard/LeaderboardTable/LeaderboardItem.tsx b/src/screens/Leaderboard/LeaderboardTable/LeaderboardItem.tsx index a9a63165..c38b9b3e 100644 --- a/src/screens/Leaderboard/LeaderboardTable/LeaderboardItem.tsx +++ b/src/screens/Leaderboard/LeaderboardTable/LeaderboardItem.tsx @@ -4,7 +4,7 @@ import styled from "@emotion/styled"; import copy from "copy-to-clipboard"; import { observer } from "mobx-react"; -import { TraderVolumeResponse } from "@compolabs/spark-orderbook-ts-sdk"; +import { BN, TraderVolumeResponse } from "@compolabs/spark-orderbook-ts-sdk"; import { SmartFlex } from "@components/SmartFlex"; import Text, { TEXT_TYPES_MAP } from "@components/Text"; @@ -19,8 +19,6 @@ import { LeaderboardStore, useStores } from "@stores"; import { pnlTimeline } from "@screens/Dashboard/const"; -import BN from "@utils/BN"; - const generatePosition = (key: TraderVolumeResponse["id"]) => { if (key === 1) return 1st; if (key === 2) return 2st; diff --git a/src/screens/SpotScreen/MarketStatistics.tsx b/src/screens/SpotScreen/MarketStatistics.tsx index bee832f1..1402503d 100644 --- a/src/screens/SpotScreen/MarketStatistics.tsx +++ b/src/screens/SpotScreen/MarketStatistics.tsx @@ -3,6 +3,8 @@ import { useTheme } from "@emotion/react"; import styled from "@emotion/styled"; import { observer } from "mobx-react"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import { Column, DesktopRow, Row } from "@components/Flex"; import { SmartFlex } from "@components/SmartFlex"; import Text from "@components/Text"; @@ -18,7 +20,6 @@ import DesktopMarketInfoTooltip from "@screens/SpotScreen/DesktopMarketInfoToolt import { MarketInfoItem } from "@screens/SpotScreen/DesktopMarketInfoTooltip/DesktopMarketInfoTooltip"; import { DEFAULT_DECIMALS, PYTH_LINK } from "@constants"; -import BN from "@utils/BN"; import { toCurrency } from "@utils/toCurrency"; const MarketStatistics: React.FC = observer(() => { @@ -33,10 +34,10 @@ const MarketStatistics: React.FC = observer(() => { const volume = tradeStore.spotMarketInfo.volume.multipliedBy(indexPriceBn); const oraclePrice = tradeStore.market?.priceUnits.toFormat(precision); - const indexPrice = toCurrency(indexPriceBn.toNumber().toFixed(precision), quoteToken?.symbol); - const volume24h = toCurrency(volume.toNumber().toFixed(precision), quoteToken?.symbol); - const high24h = toCurrency(tradeStore.spotMarketInfo.high.toNumber().toFixed(precision), quoteToken?.symbol); - const low24h = toCurrency(tradeStore.spotMarketInfo.low.toNumber().toFixed(precision), quoteToken?.symbol); + const indexPrice = toCurrency(indexPriceBn.toFormat(precision), quoteToken?.symbol); + const volume24h = toCurrency(volume.toFormat(precision), quoteToken?.symbol); + const high24h = toCurrency(tradeStore.spotMarketInfo.high.toFormat(precision), quoteToken?.symbol); + const low24h = toCurrency(tradeStore.spotMarketInfo.low.toFormat(precision), quoteToken?.symbol); const spotStatsArr: MarketInfoItem[] = [ { diff --git a/src/screens/SpotScreen/OrderbookAndTradesInterface/SpotOrderBook/SpotOrderBook.tsx b/src/screens/SpotScreen/OrderbookAndTradesInterface/SpotOrderBook/SpotOrderBook.tsx index ca794868..f0ac5417 100644 --- a/src/screens/SpotScreen/OrderbookAndTradesInterface/SpotOrderBook/SpotOrderBook.tsx +++ b/src/screens/SpotScreen/OrderbookAndTradesInterface/SpotOrderBook/SpotOrderBook.tsx @@ -3,6 +3,8 @@ import { useTheme } from "@emotion/react"; import styled from "@emotion/styled"; import { observer } from "mobx-react"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import { CompressedNumber } from "@components/CompressedNumber"; import { Column, Row } from "@components/Flex"; import { SpotOrderSettingsSheet } from "@components/Modal"; @@ -21,7 +23,6 @@ import { useMedia } from "@hooks/useMedia"; import { useStores } from "@stores"; import { DEFAULT_DECIMALS } from "@constants"; -import BN from "@utils/BN"; import { hexToRgba } from "@utils/hexToRgb"; import { SpotMarketOrder } from "@entity"; diff --git a/src/screens/SpotScreen/RightBlock/CreateOrder/CreateOrderVM.tsx b/src/screens/SpotScreen/RightBlock/CreateOrder/CreateOrderVM.tsx index e363abd4..a08a22d6 100644 --- a/src/screens/SpotScreen/RightBlock/CreateOrder/CreateOrderVM.tsx +++ b/src/screens/SpotScreen/RightBlock/CreateOrder/CreateOrderVM.tsx @@ -4,7 +4,7 @@ import { makeAutoObservable, reaction } from "mobx"; import { Undefinable } from "tsdef"; import { - AssetType, + BN, CompactMarketInfo, CreateOrderWithDepositParams, FulfillOrderManyWithDepositParams, @@ -19,7 +19,6 @@ import { RootStore, useStores } from "@stores"; import { MIXPANEL_EVENTS } from "@stores/MixPanelStore"; import { DEFAULT_DECIMALS } from "@constants"; -import BN from "@utils/BN"; import { ACTION_MESSAGE_TYPE, getActionMessage } from "@utils/getActionMessage"; import { CONFIG } from "@utils/getConfig"; import { getRealFee } from "@utils/getRealFee"; @@ -66,9 +65,6 @@ export enum ORDER_TYPE { interface DepositInfo { amountToSpend: string; amountFee: string; - depositAssetId: string; - feeAssetId: string; - assetType: AssetType; } class CreateOrderVM { @@ -315,28 +311,9 @@ class CreateOrderVM { const deposit: DepositInfo = { amountToSpend: depositAmount.toString(), amountFee: feeAmount.toString(), - depositAssetId: isBuy ? market.quoteToken.assetId : market.baseToken.assetId, - feeAssetId: market.quoteToken.assetId, - assetType: isBuy ? AssetType.Quote : AssetType.Base, }; - const availableMarkets = CONFIG.MARKETS.filter((m) => { - // For a buy operation, we look for markets where either the quote or base asset matches our QUOTE token. - if (isBuy) { - return ( - m.quoteAssetId.toLowerCase() === deposit.feeAssetId.toLowerCase() || - m.baseAssetId.toLowerCase() === deposit.feeAssetId.toLowerCase() - ); - } - - // For a sell operation, we look for markets where either the quote or base asset matches our BASE token. - return ( - m.quoteAssetId.toLowerCase() === deposit.depositAssetId.toLowerCase() || - m.baseAssetId.toLowerCase() === deposit.depositAssetId.toLowerCase() - ); - }); - - const compactMarkets: CompactMarketInfo[] = availableMarkets.map((m) => ({ + const compactMarkets: CompactMarketInfo[] = CONFIG.MARKETS.map((m) => ({ contractId: m.contractId, quoteAssetId: m.quoteAssetId, baseAssetId: m.baseAssetId, diff --git a/src/screens/Stats/StatsAllTime.tsx b/src/screens/Stats/StatsAllTime.tsx index 10cded8c..c604c8ab 100644 --- a/src/screens/Stats/StatsAllTime.tsx +++ b/src/screens/Stats/StatsAllTime.tsx @@ -2,13 +2,14 @@ import React from "react"; import styled from "@emotion/styled"; import { observer } from "mobx-react"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import { SmartFlex } from "@components/SmartFlex"; import Text from "@components/Text"; import { media } from "@themes/breakpoints"; import { useStores } from "@stores"; -import BN from "@utils/BN"; import { toCurrency } from "@utils/toCurrency"; const StatsAllTime = observer(() => { diff --git a/src/screens/Stats/StatsTable/StatsItem.tsx b/src/screens/Stats/StatsTable/StatsItem.tsx index 7b5d46e6..018fe5c2 100644 --- a/src/screens/Stats/StatsTable/StatsItem.tsx +++ b/src/screens/Stats/StatsTable/StatsItem.tsx @@ -3,7 +3,7 @@ import { Theme, useTheme } from "@emotion/react"; import styled from "@emotion/styled"; import { observer } from "mobx-react"; -import { GetTotalStatsTableData } from "@compolabs/spark-orderbook-ts-sdk"; +import { BN, GetTotalStatsTableData } from "@compolabs/spark-orderbook-ts-sdk"; import { Column } from "@components/Flex"; import { SmartFlex } from "@components/SmartFlex"; @@ -12,7 +12,6 @@ import { media } from "@themes/breakpoints"; import { MarketSymbol } from "@screens/Stats/StatsTable/MarketSymbol"; -import BN from "@utils/BN"; import { CONFIG } from "@utils/getConfig"; import { toCurrency } from "@utils/toCurrency"; diff --git a/src/screens/SwapScreen/InfoBlock.tsx b/src/screens/SwapScreen/InfoBlock.tsx index 9b58e05a..abe78396 100644 --- a/src/screens/SwapScreen/InfoBlock.tsx +++ b/src/screens/SwapScreen/InfoBlock.tsx @@ -2,6 +2,8 @@ import React, { useState } from "react"; import { useTheme } from "@emotion/react"; import styled from "@emotion/styled"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import { SmartFlex } from "@components/SmartFlex"; import Text, { TEXT_TYPES_MAP } from "@components/Text"; import { media } from "@themes/breakpoints"; @@ -12,8 +14,6 @@ import LightningIcon from "@assets/icons/lightning.svg?react"; import { useStores } from "@stores"; -import BN from "@utils/BN"; - import { SlippageSettings } from "./SlippageSettings"; interface InfoBlockProps { diff --git a/src/screens/SwapScreen/SwapScreen.tsx b/src/screens/SwapScreen/SwapScreen.tsx index 628e3da5..0038455d 100644 --- a/src/screens/SwapScreen/SwapScreen.tsx +++ b/src/screens/SwapScreen/SwapScreen.tsx @@ -3,6 +3,8 @@ import { keyframes, useTheme } from "@emotion/react"; import styled from "@emotion/styled"; import { observer } from "mobx-react"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import Button from "@components/Button"; import { ConnectWalletButton } from "@components/ConnectWalletButton"; import { AssetBlockData } from "@components/SelectAssets/SelectAssetsInput"; @@ -19,7 +21,6 @@ import { useStores } from "@stores"; import { MIXPANEL_EVENTS } from "@stores/MixPanelStore"; import { DEFAULT_DECIMALS, MINIMAL_ETH_REQUIRED, ROUTES } from "@constants"; -import BN from "@utils/BN"; import { isValidAmountInput, parseNumberWithCommas, replaceComma } from "@utils/swapUtils"; import { Token } from "@entity"; diff --git a/src/stores/BalanceStore.ts b/src/stores/BalanceStore.ts index 87296748..26cee569 100644 --- a/src/stores/BalanceStore.ts +++ b/src/stores/BalanceStore.ts @@ -1,10 +1,9 @@ import { Address } from "fuels"; import { makeAutoObservable, reaction, runInAction } from "mobx"; -import { UserMarketBalance } from "@compolabs/spark-orderbook-ts-sdk"; +import { BN, UserMarketBalance } from "@compolabs/spark-orderbook-ts-sdk"; import { DEFAULT_DECIMALS } from "@constants"; -import BN from "@utils/BN"; import { ACTION_MESSAGE_TYPE, getActionMessage } from "@utils/getActionMessage"; import { CONFIG } from "@utils/getConfig"; import { handleWalletErrors } from "@utils/handleWalletErrors"; diff --git a/src/stores/FaucetStore.ts b/src/stores/FaucetStore.ts index f689dad4..d2a78222 100644 --- a/src/stores/FaucetStore.ts +++ b/src/stores/FaucetStore.ts @@ -1,10 +1,11 @@ import { makeAutoObservable } from "mobx"; import { Nullable } from "tsdef"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import RootStore from "@stores/RootStore"; import { FUEL_FAUCET } from "@constants"; -import BN from "@utils/BN"; import { ACTION_MESSAGE_TYPE, getActionMessage } from "@utils/getActionMessage"; import { handleWalletErrors } from "@utils/handleWalletErrors"; diff --git a/src/stores/LeaderboardStore.ts b/src/stores/LeaderboardStore.ts index fe14e16a..cd052208 100644 --- a/src/stores/LeaderboardStore.ts +++ b/src/stores/LeaderboardStore.ts @@ -2,6 +2,7 @@ import _ from "lodash"; import { makeAutoObservable, reaction } from "mobx"; import { + BN, GetCompetitionResponse, GetSortedLeaderboardQueryParams, GetTotalStatsTableData, @@ -14,7 +15,6 @@ import { FiltersProps } from "@stores/DashboardStore"; import { filters, pnlTimeline } from "@screens/Dashboard/const"; import { DEFAULT_DECIMALS } from "@constants"; -import BN from "@utils/BN"; import { CONFIG } from "@utils/getConfig"; import { FuelNetwork } from "@blockchain"; diff --git a/src/stores/OracleStore.ts b/src/stores/OracleStore.ts index cad0f445..90da4b08 100644 --- a/src/stores/OracleStore.ts +++ b/src/stores/OracleStore.ts @@ -1,9 +1,10 @@ import { HermesClient } from "@pythnetwork/hermes-client"; import { makeAutoObservable } from "mobx"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import RootStore from "@stores/RootStore"; -import BN from "@utils/BN"; import { IntervalUpdater } from "@utils/IntervalUpdater"; import { FuelNetwork } from "@blockchain"; diff --git a/src/stores/SpotOrderBookStore.ts b/src/stores/SpotOrderBookStore.ts index bf9d0e4f..a9b8998c 100644 --- a/src/stores/SpotOrderBookStore.ts +++ b/src/stores/SpotOrderBookStore.ts @@ -2,7 +2,7 @@ import { HistogramData } from "lightweight-charts"; import { makeAutoObservable, reaction } from "mobx"; import { Nullable } from "tsdef"; -import { GetActiveOrdersParams, OrderType } from "@compolabs/spark-orderbook-ts-sdk"; +import { BN, GetActiveOrdersParams, OrderType } from "@compolabs/spark-orderbook-ts-sdk"; import { GetOrdersParams } from "@compolabs/spark-orderbook-ts-sdk"; import { RootStore } from "@stores"; @@ -10,7 +10,6 @@ import { RootStore } from "@stores"; import { SPOT_ORDER_FILTER } from "@screens/SpotScreen/OrderbookAndTradesInterface/SpotOrderBook/SpotOrderBook"; import { DEFAULT_DECIMALS } from "@constants"; -import BN from "@utils/BN"; import { formatSpotMarketOrders } from "@utils/formatSpotMarketOrders"; import { CONFIG, Market } from "@utils/getConfig"; import { getOhlcvData, OhlcvData } from "@utils/getOhlcvData"; diff --git a/src/stores/SwapStore.ts b/src/stores/SwapStore.ts index 3996bfa0..50c5fda0 100644 --- a/src/stores/SwapStore.ts +++ b/src/stores/SwapStore.ts @@ -1,9 +1,8 @@ import { autorun, makeAutoObservable, reaction } from "mobx"; -import { AssetType, GetActiveOrdersParams, LimitType, Order, OrderType } from "@compolabs/spark-orderbook-ts-sdk"; +import { AssetType, BN, GetActiveOrdersParams, LimitType, Order, OrderType } from "@compolabs/spark-orderbook-ts-sdk"; import { DEFAULT_DECIMALS } from "@constants"; -import BN from "@utils/BN"; import { ACTION_MESSAGE_TYPE, getActionMessage } from "@utils/getActionMessage"; import { CONFIG } from "@utils/getConfig"; import { handleWalletErrors } from "@utils/handleWalletErrors"; diff --git a/src/stores/TradeStore.ts b/src/stores/TradeStore.ts index 16abf4e6..4a1980c3 100644 --- a/src/stores/TradeStore.ts +++ b/src/stores/TradeStore.ts @@ -3,10 +3,11 @@ import _ from "lodash"; import { makeAutoObservable, reaction } from "mobx"; import { Nullable } from "tsdef"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import RootStore from "@stores/RootStore"; import { DEFAULT_DECIMALS, DEFAULT_MARKET } from "@constants"; -import BN from "@utils/BN"; import { CONFIG } from "@utils/getConfig"; import { IntervalUpdater } from "@utils/IntervalUpdater"; diff --git a/src/utils/BN.ts b/src/utils/BN.ts deleted file mode 100644 index 26c4e555..00000000 --- a/src/utils/BN.ts +++ /dev/null @@ -1,138 +0,0 @@ -import BigNumber from "bignumber.js"; -import { Undefinable } from "tsdef"; - -BigNumber.config({ EXPONENTIAL_AT: [-100, 100] }); - -type TValue = BN | BigNumber.Value; - -const bigNumberify = (n: any): string | number => { - if (n && n.toString) { - const primitive = n.toString(); - - if (typeof primitive !== "object") { - return primitive; - } - } - - return n; -}; - -class BN extends BigNumber { - static ZERO = new BN(0); - static MaxUint256 = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; - dividedBy = this.div; - exponentiatedBy = this.pow; - modulo = this.mod; - multipliedBy = this.times; - squareRoot = this.sqrt; - - constructor(n: TValue, base?: number) { - super(bigNumberify(n), base); - } - - static clamp(number: TValue, min: TValue, max: TValue): BN { - return BN.min(BN.max(number, min), max); - } - - static max(...n: TValue[]): BN { - return new BN(super.max(...n.map(bigNumberify))); - } - - static min(...n: TValue[]): BN { - return new BN(super.min(...n.map(bigNumberify))); - } - - static toBN(p: Promise): Promise { - return p.then((v) => new BN(v)); - } - - static parseUnits(value: TValue, decimals = 8): BN { - return new BN(10).pow(decimals).times(bigNumberify(value)); - } - - static formatUnits(value: TValue, decimals = 8): BN { - return new BN(value).div(new BN(10).pow(decimals)); - } - - static percentOf(value: TValue, percent: TValue): BN { - return new BN(new BN(value).times(percent).div(100).toFixed(0)); - } - - static ratioOf(valueA: TValue, valueB: TValue): BN { - return new BN(valueA).div(valueB).times(100); - } - - abs(): BN { - return new BN(super.abs()); - } - - div(n: TValue, base?: Undefinable): BN { - return new BN(super.div(bigNumberify(n), base)); - } - - pow(n: TValue, m?: Undefinable): BN { - return new BN(super.pow(bigNumberify(n), bigNumberify(m))); - } - - minus(n: TValue, base?: Undefinable): BN { - return new BN(super.minus(bigNumberify(n), base)); - } - - mod(n: TValue, base?: Undefinable): BN { - return new BN(super.mod(bigNumberify(n), base)); - } - - times(n: TValue, base?: Undefinable): BN { - return new BN(super.times(bigNumberify(n), base)); - } - - negated(): BN { - return new BN(super.negated()); - } - - plus(n: TValue, base?: Undefinable): BN { - return new BN(super.plus(bigNumberify(n), base)); - } - - sqrt(): BN { - return new BN(super.sqrt()); - } - - toDecimalPlaces(decimalPlaces: number, roundingMode: BigNumber.RoundingMode = BigNumber.ROUND_DOWN): BN { - return new BN(super.dp(decimalPlaces, roundingMode)); - } - - toBigFormat(decimalPlaces: number): string { - if (super.toNumber() > 999 && super.toNumber() < 1000000) { - return (super.toNumber() / 1000).toFixed(1) + "K"; - } else if (super.toNumber() > 1000000) { - return (super.toNumber() / 1000000).toFixed(1) + "M"; - } else if (super.toNumber() < 900) { - return super.toFormat(decimalPlaces); // if value < 1000, nothing to do - } - return super.toFormat(decimalPlaces); - } - - /** - * @example - * new BN('1234.5678').toSignificant(2) === 1,234.56 - * new BN('1234.506').toSignificant(2) === 1,234.5 - * new BN('123.0000').toSignificant(2) === 123 - * new BN('0.001234').toSignificant(2) === 0.0012 - */ - toSignificant = ( - significantDigits: number, - roundingMode: BigNumber.RoundingMode = BigNumber.ROUND_DOWN, - format?: BigNumber.Format, - ): string => { - return this.abs().gte(1) || significantDigits === 0 - ? this.toFormat(significantDigits, roundingMode, format).replace(/(\.[0-9]*[1-9])0+$|\.0+$/, "$1") - : super.precision(significantDigits, roundingMode).toString(); - }; - - clamp(min: TValue, max: TValue): BN { - return BN.min(BN.max(this, min), max); - } -} - -export default BN; diff --git a/src/utils/Math.ts b/src/utils/Math.ts index 721c9195..7e260a28 100644 --- a/src/utils/Math.ts +++ b/src/utils/Math.ts @@ -1,4 +1,4 @@ -import BN from "./BN"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; class Math { static adjustDecimals(value: BN, currentDecimals: number, targetDecimals: number): BN { diff --git a/src/utils/getRealFee.ts b/src/utils/getRealFee.ts index df372a04..28bae4b8 100644 --- a/src/utils/getRealFee.ts +++ b/src/utils/getRealFee.ts @@ -1,6 +1,6 @@ -import { SpotMarket } from "@entity"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; -import BN from "./BN"; +import { SpotMarket } from "@entity"; //TODO: Delete this file and make refactor in perp branch export const getRealFee = (market: SpotMarket | undefined, matcherFee: BN, exchangeFee: BN, isSell: boolean) => { diff --git a/src/utils/groupOrders.ts b/src/utils/groupOrders.ts index ce612b74..4962ad3e 100644 --- a/src/utils/groupOrders.ts +++ b/src/utils/groupOrders.ts @@ -1,11 +1,11 @@ import BigNumber from "bignumber.js"; +import { BN } from "@compolabs/spark-orderbook-ts-sdk"; + import { DEFAULT_DECIMALS } from "@constants"; import { SpotMarketOrder } from "@entity"; -import BN from "./BN"; - const roundPrice = (price: BN, decimals: number, rm: BigNumber.RoundingMode): BN => { const factor = new BN(10).pow(decimals); return new BN(price.dividedBy(factor).integerValue(rm).multipliedBy(factor));