diff --git a/package-lock.json b/package-lock.json index fa626e4c..4a42fcdd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", "@invariant-labs/bonds-sdk": "0.1.0", - "@invariant-labs/sdk": "^0.9.69", + "@invariant-labs/sdk": "^0.9.70", "@invariant-labs/staker-sdk": "0.2.11", "@mui/icons-material": "^5.15.15", "@mui/material": "^5.15.15", @@ -2977,9 +2977,9 @@ } }, "node_modules/@invariant-labs/sdk": { - "version": "0.9.69", - "resolved": "https://registry.npmjs.org/@invariant-labs/sdk/-/sdk-0.9.69.tgz", - "integrity": "sha512-eI5rDR2eIrdJNT9lxB36WxDQ86wFvZ0WZYbLOMgX9B02misxlhA+/Dtx1qYixU02CGtr+DIqT5KwvKNg0Nahig==", + "version": "0.9.70", + "resolved": "https://registry.npmjs.org/@invariant-labs/sdk/-/sdk-0.9.70.tgz", + "integrity": "sha512-XmWfAtBwFTkEdga9bITHlJgD61b5dY6piJ0sIKsZPo2xNEwUD1l2RYA291DnlJ9wO4BYyxHRtjsVtgzAecK/Vw==", "dependencies": { "@project-serum/anchor": "0.21.0", "@solana/spl-token-registry": "^0.2.4484", diff --git a/package.json b/package.json index 03f73196..95322b49 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", "@invariant-labs/bonds-sdk": "0.1.0", - "@invariant-labs/sdk": "^0.9.69", + "@invariant-labs/sdk": "^0.9.70", "@invariant-labs/staker-sdk": "0.2.11", "@mui/icons-material": "^5.15.15", "@mui/material": "^5.15.15", diff --git a/src/components/Stats/PoolListItem/PoolListItem.tsx b/src/components/Stats/PoolListItem/PoolListItem.tsx index ad034a39..e0ec4079 100644 --- a/src/components/Stats/PoolListItem/PoolListItem.tsx +++ b/src/components/Stats/PoolListItem/PoolListItem.tsx @@ -72,6 +72,7 @@ const PoolListItem: React.FC = ({ const { classes } = useStyles() const navigate = useNavigate() + const isSm = useMediaQuery(theme.breakpoints.down('sm')) const isSmd = useMediaQuery('(max-width:780px)') const isMd = useMediaQuery(theme.breakpoints.down('md')) @@ -154,9 +155,11 @@ const PoolListItem: React.FC = ({ - - {shortenAddress(symbolFrom ?? '')}/{shortenAddress(symbolTo ?? '')} - + {!isSm && ( + + {shortenAddress(symbolFrom ?? '')}/{shortenAddress(symbolTo ?? '')} + + )} = ({ // const isNegative = priceChange < 0 const isMd = useMediaQuery(theme.breakpoints.down('md')) + const isXs = useMediaQuery(theme.breakpoints.down('xs')) + const isSm = useMediaQuery(theme.breakpoints.down('sm')) const networkUrl = useMemo(() => { switch (network) { @@ -79,6 +81,7 @@ const TokenListItem: React.FC = ({ copyAddressHandler('Failed to copy token address to Clipboard', 'error') }) } + const shouldShowText = icon === icons.unknownToken || !isSm return ( @@ -99,7 +102,15 @@ const TokenListItem: React.FC = ({ }}> {isUnknown && } - + {shouldShowText && ( + + {isXs ? shortenAddress(symbol) : name} + {!isXs && ( + {` (${shortenAddress(symbol)})`} + )} + + )} + {/* {!isMd ? ( <> {name} @@ -108,7 +119,7 @@ const TokenListItem: React.FC = ({ ) : ( shortenAddress(symbol) )} - + */} = ({ {`~$${formatNumber(price)}`} - {/* {!hideName && ( + {/* {!isXs && ( {isNegative ? `${priceChange.toFixed(2)}%` : `+${priceChange.toFixed(2)}%`} @@ -185,7 +196,7 @@ const TokenListItem: React.FC = ({ ) : null} - {/* {!hideName && ( + {/* {!isXs && ( { diff --git a/src/components/Swap/Swap.tsx b/src/components/Swap/Swap.tsx index 66c5208b..3914c25f 100644 --- a/src/components/Swap/Swap.tsx +++ b/src/components/Swap/Swap.tsx @@ -41,7 +41,7 @@ import { useNavigate } from 'react-router-dom' import { PoolWithAddress } from '@store/reducers/pools' import { PublicKey } from '@solana/web3.js' import { Decimal, Tick, Tickmap } from '@invariant-labs/sdk/lib/market' -import { fromFee } from '@invariant-labs/sdk/lib/utils' +import { fromFee, SimulationStatus } from '@invariant-labs/sdk/lib/utils' import { TooltipHover } from '@components/TooltipHover/TooltipHover' export interface Pools { @@ -447,9 +447,8 @@ export const Swap: React.FC = ({ } if ( - isError('At the end of price range') || - isError('Price would cross swap limit') || - isError('Too large liquidity gap') + isError(SimulationStatus.SwapStepLimitReached) || + isError(SimulationStatus.PriceLimitReached) ) { return 'Insufficient liquidity' } @@ -478,9 +477,8 @@ export const Swap: React.FC = ({ } if ( - (convertBalanceToBN(amountFrom, tokens[tokenFrom.toString()].decimals).eqn(0) || - isError('Amount out is zero')) && - !simulateResult.error.length + convertBalanceToBN(amountFrom, tokens[tokenFrom.toString()].decimals).eqn(0) || + isError(SimulationStatus.NoGainSwap) ) { return 'Insufficient amount' } @@ -497,6 +495,11 @@ export const Swap: React.FC = ({ return 'RPC connection error' } + // Fallback error + if (simulateResult.error.length !== 0) { + return 'Not enough liquidity' + } + return 'Exchange' } const hasShowRateMessage = () => { diff --git a/src/store/consts/static.ts b/src/store/consts/static.ts index 59878332..dd8e4ab2 100644 --- a/src/store/consts/static.ts +++ b/src/store/consts/static.ts @@ -8,6 +8,7 @@ import Dog1 from '@static/svg/SolanaCreator/Dog1.svg' import Dog2 from '@static/svg/SolanaCreator/Dog2.svg' import Cat1 from '@static/svg/SolanaCreator/Cat1.svg' import Cat2 from '@static/svg/SolanaCreator/Cat2.svg' +import { TICK_CROSSES_PER_IX } from '@invariant-labs/sdk/lib/market' export enum NetworkType { Local = 'Local', @@ -331,6 +332,7 @@ export const airdropQuantities: Record = { } export const WRAPPED_SOL_ADDRESS = 'So11111111111111111111111111111111111111112' +export const NATIVE_TICK_CROSSES_PER_IX = TICK_CROSSES_PER_IX - 5 export const WSOL_MIN_DEPOSIT_SWAP_FROM_AMOUNT = new BN(9200961) diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 3784eaf4..29f93171 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,7 +1,12 @@ import { calculateSellPrice } from '@invariant-labs/bonds-sdk/lib/math' import { BondSaleStruct } from '@invariant-labs/bonds-sdk/lib/sale' import { calculatePriceSqrt, MAX_TICK, MIN_TICK, Pair } from '@invariant-labs/sdk' -import { Market, TICK_CROSSES_PER_IX, Tickmap } from '@invariant-labs/sdk/lib/market' +import { + Market, + TICK_CROSSES_PER_IX, + TICK_VIRTUAL_CROSSES_PER_IX, + Tickmap +} from '@invariant-labs/sdk/lib/market' import { getMaxTick, getMinTick, PRICE_SCALE, Range } from '@invariant-labs/sdk/lib/utils' import { Decimal, PoolStructure, Tick } from '@invariant-labs/sdk/src/market' import { @@ -44,7 +49,9 @@ import { WSOL_DEV, SNY_MAIN, WEN_MAIN, - SUI_MAIN + SUI_MAIN, + WRAPPED_SOL_ADDRESS, + NATIVE_TICK_CROSSES_PER_IX } from '@store/consts/static' import mainnetList from '@store/consts/tokenLists/mainnet.json' import { FormatConfig, subNumbers } from '@store/consts/static' @@ -745,6 +752,13 @@ export const handleSimulate = async ( for (const tick of poolTicks[pool.address.toString()]) { ticks.set(tick.index, tick) } + let maxCrosses = TICK_CROSSES_PER_IX + if ( + fromToken.toString() === WRAPPED_SOL_ADDRESS || + toToken.toString() === WRAPPED_SOL_ADDRESS + ) { + maxCrosses = NATIVE_TICK_CROSSES_PER_IX + } try { const swapSimulateResult = simulateSwap({ @@ -754,11 +768,10 @@ export const handleSimulate = async ( slippage: slippage, pool: pool, ticks: ticks, - tickmap: tickmaps[pool.tickmap.toString()] + tickmap: tickmaps[pool.tickmap.toString()], + maxCrosses, + maxVirtualCrosses: TICK_VIRTUAL_CROSSES_PER_IX }) - if (swapSimulateResult.amountPerTick.length > TICK_CROSSES_PER_IX) { - errorMessage.push('Too large amount') - } if (!byAmountIn) { result = swapSimulateResult.accumulatedAmountIn.add(swapSimulateResult.accumulatedFee) @@ -781,7 +794,11 @@ export const handleSimulate = async ( okChanges += 1 } else if ( - byAmountIn ? allFailedData.amountOut.lt(result) : allFailedData.amountOut.gt(result) + byAmountIn + ? allFailedData.amountOut.lt(result) + : allFailedData.amountOut.eq(MAX_U64) + ? true + : allFailedData.amountOut.lt(result) ) { allFailedData = { amountOut: result,