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

feat: add wethIsEth option for V3 nested and boosted pools #445

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 2 additions & 6 deletions packages/lib/modules/pool/actions/LiquidityActionHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
isUnbalancedLiquidityDisabled,
isV2Pool,
isV3Pool,
isV3NotSupportingWethIsEth,
supportsWethIsEth,
getActionableTokenSymbol,
hasNestedPools,
} from '../pool.helpers'
Expand Down Expand Up @@ -392,11 +392,7 @@ export function emptyTokenAmounts(pool: Pool): TokenAmount[] {
}

export function shouldShowNativeWrappedSelector(token: ApiToken, pool: Pool) {
return (
!isV3NotSupportingWethIsEth(pool) && // V3 boosted/nested actions don't support wethIsEth currently
!isCowAmmPool(pool.type) && // Cow AMM pools don't support wethIsEth
isNativeOrWrappedNative(token.address as Address, token.chain)
)
return supportsWethIsEth(pool) && isNativeOrWrappedNative(token.address as Address, token.chain)
}

export function replaceWrappedWithNativeAsset(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { useTotalUsdValue } from '@repo/lib/modules/tokens/useTotalUsdValue'
import { HumanTokenAmountWithAddress } from '@repo/lib/modules/tokens/token.types'
import { isUnhandledAddPriceImpactError } from '@repo/lib/modules/price-impact/price-impact.utils'
import { useModalWithPoolRedirect } from '../../useModalWithPoolRedirect'
import { getPoolActionableTokens, isV3NotSupportingWethIsEth } from '../../pool.helpers'
import { getPoolActionableTokens, supportsWethIsEth } from '../../pool.helpers'
import { useUserSettings } from '@repo/lib/modules/user/settings/UserSettingsProvider'
import { isUnbalancedAddErrorMessage } from '@repo/lib/shared/utils/error-filters'
import { getDefaultProportionalSlippagePercentage } from '@repo/lib/shared/utils/slippage'
Expand Down Expand Up @@ -207,7 +207,7 @@ export function _useAddLiquidity(urlTxHash?: Hash) {
return {
transactionSteps,
humanAmountsIn,
tokens: wethIsEth && !isV3NotSupportingWethIsEth(pool) ? tokensWithNativeAsset : tokens,
tokens: wethIsEth && supportsWethIsEth(pool) ? tokensWithNativeAsset : tokens,
validTokens,
totalUSDValue,
simulationQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import { useTokens } from '@repo/lib/modules/tokens/TokensProvider'
import { AddLiquidityFormTabs } from './AddLiquidityFormTabs'
import { UnbalancedAddError } from '@repo/lib/shared/components/errors/UnbalancedAddError'
import { isUnbalancedAddError } from '@repo/lib/shared/utils/error-filters'
import { isV3NotSupportingWethIsEth } from '../../../pool.helpers'
import { supportsWethIsEth } from '../../../pool.helpers'
import { UnbalancedNestedAddError } from '@repo/lib/shared/components/errors/UnbalancedNestedAddError'
import { ApiToken } from '@repo/lib/modules/tokens/token.types'

Expand Down Expand Up @@ -147,7 +147,7 @@ function AddLiquidityMainForm() {

// if native asset balance is higher set that asset as the 'default'
useEffect(() => {
if (!isBalancesLoading && nativeAsset && wNativeAsset && !isV3NotSupportingWethIsEth(pool)) {
if (!isBalancesLoading && nativeAsset && wNativeAsset && supportsWethIsEth(pool)) {
const nativeAssetBalance = balanceFor(nativeAsset.address)
const wNativeAssetBalance = balanceFor(wNativeAsset.address)
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class BoostedUnbalancedAddLiquidityV3Handler extends BaseUnbalancedAddLiq
}),
protocolVersion: 3,
userData: '0x' as Hex,
wethIsEth: this.helpers.isNativeAssetIn(humanAmountsIn),
}

const { callData, to, value } = permit2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ export class NestedAddLiquidityV3Handler implements AddLiquidityHandler {
slippagePercent,
queryOutput,
permit2,
humanAmountsIn,
}: NestedBuildAddLiquidityInputV3): Promise<TransactionConfig> {
const addLiquidity = new AddLiquidityNested()

const buildCallParams: AddLiquidityNestedCallInputV3 = {
...queryOutput.sdkQueryOutput,
slippage: Slippage.fromPercentage(`${Number(slippagePercent)}`),
amountsIn: queryOutput.sdkQueryOutput.amountsIn,
wethIsEth: this.helpers.isNativeAssetIn(humanAmountsIn),
}

const { callData, to, value } = permit2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class ProportionalBoostedAddLiquidityV3 implements AddLiquidityHandler {
}),
protocolVersion: 3,
userData: '0x' as Hex,
wethIsEth: this.helpers.isNativeAssetIn(humanAmountsIn),
}

const { callData, to, value } = permit2
Expand Down
8 changes: 6 additions & 2 deletions packages/lib/modules/pool/pool.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,12 @@ export function isV3WithNestedActionsPool(pool: Pool): boolean {
return supportsNestedActions(pool) && isV3Pool(pool)
}

export function isV3NotSupportingWethIsEth(pool: Pool): boolean {
return (supportsNestedActions(pool) || isBoosted(pool)) && isV3Pool(pool)
export function supportsWethIsEth(pool: Pool): boolean {
/*
Currently all SDK handlers support wethIsEth
and Cow AMM pools is the only scenario that doesn't support wethIsEth
*/
return !isCowAmmPool(pool.type)
}

export function requiresPermit2Approval(pool: Pool): boolean {
Expand Down
Loading