Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add burn liquidity handler #48

Merged
merged 5 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions frontend/src/components/Liquidity/FeeSwitch/FeeSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ export const FeeSwitch: React.FC<IFeeSwitch> = ({
singleTabClasses.root,
index === bestTierIndex ? singleTabClasses.best : undefined
),
selected: singleTabClasses.selected,
disabled: singleTabClasses.disabled
selected: singleTabClasses.selected
}}
disabled={index !== bestTierIndex}
/>
))}
</Tabs>
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/components/Liquidity/FeeSwitch/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ export const useSingleTabStyles = makeStyles()(() => {
'&:hover': {
color: colors.white.main
}
},
disabled: {
...typography.heading4,
color: '#3a466b' + ' !important'
}
}
})
Expand Down
40 changes: 15 additions & 25 deletions frontend/src/components/Liquidity/Liquidity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SwapToken } from '@store/selectors/wallet'
import React, { useEffect, useMemo, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import useStyles from './style'
import { FormatNumberThreshold, TokenPriceData } from '@store/consts/types'
import { TokenPriceData } from '@store/consts/types'
import { TooltipHover } from '@components/TooltipHover/TooltipHover'
import { INoConnected, NoConnected } from '@components/NoConnected/NoConnected'
import { ProgressState } from '@components/AnimatedButton/AnimatedButton'
Expand Down Expand Up @@ -37,7 +37,7 @@ export interface ILiquidity {
midPrice: any
setMidPrice: (mid: any) => void
addLiquidityHandler: (tokenXDeposit: BN, tokenYDeposit: BN) => void
removeLiquidityHandler: (xAmount: number, yAmount: FormatNumberThreshold) => void
removeLiquidityHandler: () => void
onChangePositionTokens: (
tokenAIndex: number | null,
tokenBindex: number | null,
Expand Down Expand Up @@ -81,7 +81,7 @@ export const Liquidity: React.FC<ILiquidity> = ({
tokens,
// setMidPrice,
addLiquidityHandler,
// removeLiquidityHandler,
removeLiquidityHandler,
onChangePositionTokens,
calcAmount,
feeTiers,
Expand All @@ -93,7 +93,7 @@ export const Liquidity: React.FC<ILiquidity> = ({
tickSpacing,
// isWaitingForNewPool,
poolIndex,
// bestTiers,
bestTiers,
// canCreateNewPool,
handleAddToken,
commonTokens,
Expand Down Expand Up @@ -182,19 +182,16 @@ export const Liquidity: React.FC<ILiquidity> = ({
return trimLeadingZeros(printBN(result, tokens[printIndex].decimals))
}

// const bestTierIndex =
// tokenAIndex === null || tokenBIndex === null
// ? undefined
// : (bestTiers.find(
// tier =>
// (tier.tokenX.equals(tokens[tokenAIndex].assetAddress) &&
// tier.tokenY.equals(tokens[tokenBIndex].assetAddress)) ||
// (tier.tokenX.equals(tokens[tokenBIndex].assetAddress) &&
// tier.tokenY.equals(tokens[tokenAIndex].assetAddress))
// )?.bestTierIndex ?? undefined)

// Temporary set best tier index as only available
const bestTierIndex = 2
const bestTierIndex =
tokenAIndex === null || tokenBIndex === null
? undefined
: (bestTiers.find(
tier =>
(tier.tokenX.equals(tokens[tokenAIndex].assetAddress) &&
tier.tokenY.equals(tokens[tokenBIndex].assetAddress)) ||
(tier.tokenX.equals(tokens[tokenBIndex].assetAddress) &&
tier.tokenY.equals(tokens[tokenAIndex].assetAddress))
)?.bestTierIndex ?? undefined)

const updatePath = (
index1: number | null,
Expand Down Expand Up @@ -285,11 +282,6 @@ export const Liquidity: React.FC<ILiquidity> = ({
return '0'
}, [tokenADeposit, tokenBDeposit, poolIndex])

useEffect(() => {
if (bestTierIndex) {
setPositionTokens(tokenAIndex, tokenBIndex, bestTierIndex, true)
}
}, [bestTierIndex])
return (
<Grid container className={classes.wrapper} direction='column'>
{showNoConnected && <NoConnected {...noConnectedBlockerProps} />}
Expand Down Expand Up @@ -464,9 +456,7 @@ export const Liquidity: React.FC<ILiquidity> = ({
) : (
<RemoveLiquidity
tokens={tokens}
onRemoveLiquidity={() => {
//TODO
}}
onRemoveLiquidity={removeLiquidityHandler}
LPTokenInputState={{
value: LPTokenDeposit,
setValue: value => {
Expand Down
17 changes: 14 additions & 3 deletions frontend/src/containers/LiquidityWrapper/LiquidityWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ export const LiquidityWrapper: React.FC<IProps> = ({
}
}, [allLpPools])

console.log(lpPoolIndex)

useEffect(() => {
isMountedRef.current = true
return () => {
Expand Down Expand Up @@ -252,7 +250,20 @@ export const LiquidityWrapper: React.FC<IProps> = ({
)
}
}}
removeLiquidityHandler={() => {}}
removeLiquidityHandler={() => {
if (tokenAIndex !== null && tokenBIndex !== null) {
dispatch(
poolsActions.burn({
pair: new Pair(
tokens[tokenAIndex].address,
tokens[tokenBIndex].address,
FEE_TIERS[feeIndex]
),
liquidityDelta: new BN(10000)
})
)
}
}}
onChangePositionTokens={(tokenA, tokenB, feeTierIndex) => {
setTokenAIndex(tokenA)
setTokenBIndex(tokenB)
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/store/consts/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BN } from '@project-serum/anchor'
import { PublicKey } from '@solana/web3.js'
import { FormatNumberThreshold, PrefixConfig } from './types'
import { FEE_TIERS } from '@invariant-labs/sdk-eclipse/lib/utils'
import { ISnackbar } from '@store/reducers/snackbars'
export interface FeeTier {
fee: BN
tickSpacing?: number
Expand Down Expand Up @@ -277,3 +278,9 @@ export const addressTickerMap: { [key: string]: string } = {
USDC: '5gFSyxjNsuQsZKn9g5L9Ky3cSUvJ6YXqWVuPzmSi8Trx',
ETH: 'So11111111111111111111111111111111111111112'
}

export const SIGNING_SNACKBAR_CONFIG: Omit<ISnackbar, 'open'> = {
message: 'Signing transactions',
variant: 'pending',
persist: true
}
8 changes: 8 additions & 0 deletions frontend/src/store/reducers/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ export interface MintData {
lpPoolExists: boolean
}

export interface BurnData {
pair: Pair
liquidityDelta: BN
}

export const poolsSliceName = 'pools'
const poolsSlice = createSlice({
name: poolsSliceName,
Expand Down Expand Up @@ -151,6 +156,9 @@ const poolsSlice = createSlice({
},
mint(state, _action: PayloadAction<MintData>) {
return state
},
burn(state, _action: PayloadAction<BurnData>) {
return state
}
}
})
Expand Down
Loading
Loading