Skip to content

Commit

Permalink
Merge pull request #829 from invariant-labs/dev
Browse files Browse the repository at this point in the history
Update staging env
  • Loading branch information
wojciech-cichocki authored Dec 25, 2024
2 parents 194c52a + e67edf8 commit 4d71e39
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 26 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 6 additions & 3 deletions src/components/Stats/PoolListItem/PoolListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const PoolListItem: React.FC<IProps> = ({
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'))

Expand Down Expand Up @@ -154,9 +155,11 @@ const PoolListItem: React.FC<IProps> = ({
</Box>
</Box>
<Grid className={classes.symbolsContainer}>
<Typography>
{shortenAddress(symbolFrom ?? '')}/{shortenAddress(symbolTo ?? '')}
</Typography>
{!isSm && (
<Typography>
{shortenAddress(symbolFrom ?? '')}/{shortenAddress(symbolTo ?? '')}
</Typography>
)}
<TooltipHover text='Copy pool address'>
<FileCopyOutlinedIcon
onClick={copyToClipboard}
Expand Down
19 changes: 15 additions & 4 deletions src/components/Stats/TokenListItem/TokenListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const TokenListItem: React.FC<IProps> = ({
// 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) {
Expand Down Expand Up @@ -79,6 +81,7 @@ const TokenListItem: React.FC<IProps> = ({
copyAddressHandler('Failed to copy token address to Clipboard', 'error')
})
}
const shouldShowText = icon === icons.unknownToken || !isSm

return (
<Grid>
Expand All @@ -99,7 +102,15 @@ const TokenListItem: React.FC<IProps> = ({
}}></img>
{isUnknown && <img className={classes.warningIcon} src={icons.warningIcon} />}
</Box>
<Typography>
{shouldShowText && (
<Typography>
{isXs ? shortenAddress(symbol) : name}
{!isXs && (
<span className={classes.tokenSymbol}>{` (${shortenAddress(symbol)})`}</span>
)}
</Typography>
)}
{/* <Typography>
{!isMd ? (
<>
<span className={classes.tokenName}>{name}</span>
Expand All @@ -108,7 +119,7 @@ const TokenListItem: React.FC<IProps> = ({
) : (
shortenAddress(symbol)
)}
</Typography>
</Typography> */}
<TooltipHover text='Copy token address'>
<FileCopyOutlinedIcon
onClick={copyToClipboard}
Expand All @@ -118,7 +129,7 @@ const TokenListItem: React.FC<IProps> = ({
</Grid>
<Typography>{`~$${formatNumber(price)}`}</Typography>

{/* {!hideName && (
{/* {!isXs && (
<Typography style={{ color: isNegative ? colors.invariant.Error : colors.green.main }}>
{isNegative ? `${priceChange.toFixed(2)}%` : `+${priceChange.toFixed(2)}%`}
</Typography>
Expand Down Expand Up @@ -185,7 +196,7 @@ const TokenListItem: React.FC<IProps> = ({
<ArrowDropDownIcon className={classes.icon} />
) : null}
</Typography>
{/* {!hideName && (
{/* {!isXs && (
<Typography
style={{ cursor: 'pointer' }}
onClick={() => {
Expand Down
17 changes: 10 additions & 7 deletions src/components/Swap/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -447,9 +447,8 @@ export const Swap: React.FC<ISwap> = ({
}

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'
}
Expand Down Expand Up @@ -478,9 +477,8 @@ export const Swap: React.FC<ISwap> = ({
}

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'
}
Expand All @@ -497,6 +495,11 @@ export const Swap: React.FC<ISwap> = ({
return 'RPC connection error'
}

// Fallback error
if (simulateResult.error.length !== 0) {
return 'Not enough liquidity'
}

return 'Exchange'
}
const hasShowRateMessage = () => {
Expand Down
2 changes: 2 additions & 0 deletions src/store/consts/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -331,6 +332,7 @@ export const airdropQuantities: Record<NetworkType, number[]> = {
}

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)

Expand Down
31 changes: 24 additions & 7 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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({
Expand All @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 4d71e39

Please sign in to comment.