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(yield): define token category by default for selection #5018

Merged
merged 111 commits into from
Oct 29, 2024
Merged
Changes from 1 commit
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
01c23f9
feat(yield): setup yield widget
shoom3301 Oct 7, 2024
e8514b5
fix(yield): display correct output amount
shoom3301 Oct 7, 2024
4bde353
feat(trade-quote): support fast quote requests
shoom3301 Oct 7, 2024
cf63214
feat(yield): display trade buttons
shoom3301 Oct 7, 2024
2513c89
feat(yield): display confirm details
shoom3301 Oct 7, 2024
893859f
feat(yield): scope context to trade
shoom3301 Oct 7, 2024
89aeca4
feat(yield): do trade after confirmation
shoom3301 Oct 7, 2024
ca61cbb
feat(yield): display order progress bar
shoom3301 Oct 7, 2024
0e267a9
refactor: move useIsEoaEthFlow to trade module
shoom3301 Oct 8, 2024
2df7b69
refactor: move hooks to tradeSlippage module
shoom3301 Oct 8, 2024
4ff2db5
refactor: rename swapSlippage to tradeSlippage
shoom3301 Oct 8, 2024
f5c45e9
feat(trade-slippage): split slippage state by trade type
shoom3301 Oct 8, 2024
8b8ae26
refactor: unlink TransactionSettings from swap module
shoom3301 Oct 8, 2024
39a95c3
refactor: use reach modal in Settings component
shoom3301 Oct 8, 2024
7c3c559
refactor: move Settings component in trade module
shoom3301 Oct 8, 2024
57d4ad0
feat(yield): add settings widget
shoom3301 Oct 8, 2024
4b8a40d
feat(yield): use deadline value from settings
shoom3301 Oct 8, 2024
2c2ee88
fix(trade-quote): skip fast quote if it slower than optimal
shoom3301 Oct 8, 2024
0bbec8b
refactor: generalise TradeRateDetails from swap module
shoom3301 Oct 8, 2024
fbb9a73
refactor: move TradeRateDetails into tradeWidgetAddons module
shoom3301 Oct 8, 2024
275893e
refactor: move SettingsTab into tradeWidgetAddons module
shoom3301 Oct 8, 2024
452d107
refactor(swap): generalise useHighFeeWarning()
shoom3301 Oct 10, 2024
27407be
refactor(swap): move hooks to trade module
shoom3301 Oct 10, 2024
1073d5f
refactor: move HighFeeWarning to trade widget addons
shoom3301 Oct 10, 2024
11243ee
refactor: make HighFeeWarning independent
shoom3301 Oct 10, 2024
2548e10
feat(yield): display trade warnings
shoom3301 Oct 10, 2024
f9e3d82
refactor(trade): generalise NoImpactWarning
shoom3301 Oct 10, 2024
3c6ed69
refactor(trade): generalise ZeroApprovalWarning
shoom3301 Oct 10, 2024
8070665
refactor(trade): generalise bundle tx banners
shoom3301 Oct 10, 2024
b6d9717
refactor: extract TradeWarnings
shoom3301 Oct 10, 2024
759bc0f
chore: fix yield form displaying
shoom3301 Oct 10, 2024
f320ff7
refactor(swap): generalise trade flow
shoom3301 Oct 10, 2024
057f552
feat(yield): support safe bundle swaps
shoom3301 Oct 10, 2024
b3ac906
chore: hide yield under ff
shoom3301 Oct 10, 2024
fb10141
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Oct 10, 2024
c780d1b
chore: remove lazy loading
shoom3301 Oct 11, 2024
fb63d4e
chore: merge develop
shoom3301 Oct 14, 2024
4c88126
chore: fix imports
shoom3301 Oct 14, 2024
0bf3ba1
fix: generalize smart slippage usage
shoom3301 Oct 14, 2024
78c0b89
fix: don't sync url params while navigating with yield
shoom3301 Oct 14, 2024
1678557
feat: open settings menu on slippage click
shoom3301 Oct 14, 2024
be2e6cc
chore: update btn text
shoom3301 Oct 14, 2024
3b769af
fix: make slippage settings through
shoom3301 Oct 14, 2024
b88e78c
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Oct 15, 2024
b153e9e
chore: merge develop
shoom3301 Oct 15, 2024
bea304e
chore: fix yield widget
shoom3301 Oct 15, 2024
9ecaf57
chore: remove old migration
shoom3301 Oct 15, 2024
2722b3e
feat: add default lp-token lists
shoom3301 Oct 15, 2024
aa53aac
feat(tokens): display custom token selector for Yield widget
shoom3301 Oct 15, 2024
ac0a957
feat(tokens): display lp-token lists
shoom3301 Oct 15, 2024
704d003
feat: display lp-token logo
shoom3301 Oct 16, 2024
bae773d
chore: slippage label
shoom3301 Oct 16, 2024
c01f9b8
fix: fix default trade state in menu
shoom3301 Oct 16, 2024
1af6c9e
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Oct 16, 2024
0253925
chore: fix lint
shoom3301 Oct 16, 2024
170e295
Merge branch 'feat/vampire-attack-setup' of https://github.com/cowpro…
shoom3301 Oct 16, 2024
854d685
feat: fetch lp-token balances
shoom3301 Oct 16, 2024
03da23d
feat: reuse virtual list for lp-tokens list
shoom3301 Oct 16, 2024
7228879
chore: adjust balances updater
shoom3301 Oct 16, 2024
b8b3301
chore: add yield in widget conf
shoom3301 Oct 16, 2024
6d9e416
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Oct 16, 2024
3902abb
chore: reset balances only when account changed
shoom3301 Oct 17, 2024
6060aae
feat: cache balances into localStorage
shoom3301 Oct 17, 2024
20ba5de
feat: display cached token balances
shoom3301 Oct 17, 2024
3fe1727
feat: link to create pool
shoom3301 Oct 17, 2024
629569a
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Oct 17, 2024
4d54103
chore: merge develop
shoom3301 Oct 17, 2024
535a046
chore: fix hooks trade state
shoom3301 Oct 17, 2024
c9df5d2
fix: fix smart slippage displaying
shoom3301 Oct 18, 2024
60c1033
chore: center slippage banner
shoom3301 Oct 18, 2024
cb3f94d
Merge branch 'feat/vampire-attack-setup' of https://github.com/cowpro…
shoom3301 Oct 18, 2024
ee11cb2
chore: condition to displayCreatePoolBanner
shoom3301 Oct 18, 2024
5d5c843
fix: poll lp-token balances only in yield widget
shoom3301 Oct 18, 2024
8e64078
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Oct 18, 2024
9abbf85
feat(yield): persist pools info
shoom3301 Oct 21, 2024
df6f4b1
feat(yield): allow using lp-tokens in widget
shoom3301 Oct 21, 2024
c43fba1
feat(yield): display lp-token logo in widget
shoom3301 Oct 21, 2024
d95fcf1
feat(yield): display pool apy
shoom3301 Oct 21, 2024
564d0b2
chore: fix lp token logo
shoom3301 Oct 21, 2024
eeaa6bb
feat(yield): pool info page
shoom3301 Oct 21, 2024
8061fd4
Merge branch 'develop' into feat/vampire-attack-lp-tokens
fairlighteth Oct 21, 2024
13a664f
Merge branch 'feat/vampire-attack-lp-tokens' of https://github.com/co…
shoom3301 Oct 22, 2024
4488bf7
chore: fix build
shoom3301 Oct 22, 2024
de38227
chore(yield): fix balance loading state
shoom3301 Oct 22, 2024
3d31e80
chore(yield): fix pools info fetching
shoom3301 Oct 22, 2024
0cf8755
chore: fix yield menu link
shoom3301 Oct 22, 2024
36fae46
chore: format pool displayed values
shoom3301 Oct 22, 2024
f246521
chore: always use address for lp-tokens in url
shoom3301 Oct 22, 2024
4092dd7
fix: fix lp-tokens usage
shoom3301 Oct 22, 2024
788c7f7
chore: fix lint
shoom3301 Oct 22, 2024
f0c3621
feat(yield): define token category by default for selection
shoom3301 Oct 22, 2024
930253b
chore: fix lint
shoom3301 Oct 22, 2024
a0bab7b
feat: add isCoWAMM indicator to LpToken
shoom3301 Oct 22, 2024
9c5d5b5
refactor: fix lp tokens segregation
shoom3301 Oct 22, 2024
1149c36
chore: fix apr default value
shoom3301 Oct 23, 2024
e6f28c2
Merge branch 'feat/vampire-attack-pools-info' of https://github.com/c…
shoom3301 Oct 23, 2024
8048049
chore: remove lp tokens duplicates
shoom3301 Oct 23, 2024
0c6f52c
fix: set lp tokens to sell wth cowamm is set as buy
shoom3301 Oct 23, 2024
4e96783
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Oct 23, 2024
51297d9
Merge branch 'feat/vampire-attack-lp-tokens' of https://github.com/co…
shoom3301 Oct 23, 2024
6e59eee
Merge branch 'feat/vampire-attack-pools-info' of https://github.com/c…
shoom3301 Oct 23, 2024
98597c2
feat: modify pool token list layout (#5014)
fairlighteth Oct 24, 2024
5889ea4
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Oct 28, 2024
0350976
chore: link to create pool
shoom3301 Oct 28, 2024
f3f7eac
Merge branch 'feat/vampire-attack-lp-tokens' of https://github.com/co…
shoom3301 Oct 28, 2024
8d33d3b
chore: merge changes
shoom3301 Oct 28, 2024
265b870
chore: fix balances cache
shoom3301 Oct 28, 2024
090b239
Merge branch 'feat/vampire-attack-pools-info' of https://github.com/c…
shoom3301 Oct 28, 2024
115c017
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Oct 29, 2024
17d2230
Merge branch 'feat/vampire-attack-pools-info' of https://github.com/c…
shoom3301 Oct 29, 2024
75e7d90
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Oct 29, 2024
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
Prev Previous commit
Next Next commit
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
… feat/vampire-attack-setup

# Conflicts:
#	apps/cowswap-frontend/src/legacy/components/SwapWarnings/index.tsx
#	apps/cowswap-frontend/src/modules/tradeSlippage/updaters/SmartSlippageUpdater/index.ts
#	apps/cowswap-frontend/src/modules/tradeWidgetAddons/containers/TransactionSettings/index.tsx
#	apps/cowswap-frontend/src/modules/tradeWidgetAddons/pure/Row/RowSlippageContent/index.tsx
shoom3301 committed Oct 15, 2024
commit b88e78c08cb4cb638f7c70e3d546502a8c759eab
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useSetAtom } from 'jotai'
import { useEffect, useMemo } from 'react'
import { useEffect } from 'react'

import { useTradeConfirmState } from 'modules/trade'
import { useHighFeeWarning } from 'modules/tradeWidgetAddons'
@@ -16,8 +16,6 @@ export function SmartSlippageUpdater() {
const setSmartSwapSlippage = useSetAtom(smartTradeSlippageAtom)

const bffSlippageBps = useSmartSlippageFromBff()
// TODO: remove v1
const tradeSizeSlippageBpsV1 = useSmartSlippageFromFeePercentage()
const feeMultiplierSlippageBps = useSmartSlippageFromFeeMultiplier()

const { isOpen: isTradeReviewOpen } = useTradeConfirmState()
@@ -38,48 +36,5 @@ export function SmartSlippageUpdater() {
setSmartSwapSlippage(Math.max(MIN_BPS, Math.min(slippage, MAX_BPS)))
}, [bffSlippageBps, setSmartSwapSlippage, feeMultiplierSlippageBps, isTradeReviewOpen])

// TODO: remove before merging
useEffect(() => {
console.log(`SmartSlippageUpdater`, {
granularSlippage: tradeSizeSlippageBpsV1,
fiftyPercentFeeSlippage: feeMultiplierSlippageBps,
bffSlippageBps,
})
}, [tradeSizeSlippageBpsV1, feeMultiplierSlippageBps])

return null
}

// TODO: remove
/**
* Calculates smart slippage in bps, based on trade size in relation to fee
*/
function useSmartSlippageFromFeePercentage(): number | undefined {
const { feePercentage } = useHighFeeWarning()

const percentage = feePercentage && +feePercentage.toFixed(3)

return useMemo(() => {
if (percentage === undefined) {
// Unset, return undefined
return
}
if (percentage < 1) {
// bigger volume compared to the fee, trust on smart slippage from BFF
return
} else if (percentage < 5) {
// Between 1 and 5, 2%
return 200
} else if (percentage < 10) {
// Between 5 and 10, 5%
return 500
} else if (percentage < 20) {
// Between 10 and 20, 10%
return 1000
}
// TODO: more granularity?

// > 20%, cap it at 20% slippage
return 2000
}, [percentage])
}
Original file line number Diff line number Diff line change
@@ -90,78 +90,84 @@ export function TransactionSettings({ deadlineState }: TransactionSettingsProps)

const placeholderSlippage = isSlippageModified ? defaultSwapSlippage : swapSlippage

function parseSlippageInput(value: string) {
// populate what the user typed and clear the error
setSlippageInput(value)
setSlippageError(false)
const parseSlippageInput = useCallback(
(value: string) => {
// populate what the user typed and clear the error
setSlippageInput(value)
setSlippageError(false)

if (value.length === 0) {
slippageToleranceAnalytics('Default', placeholderSlippage.toFixed(2))
setSwapSlippage(isEoaEthFlow ? percentToBps(minEthFlowSlippage) : null)
} else {
let v = value

// Prevent inserting more than 2 decimal precision
if (value.split('.')[1]?.length > 2) {
// indexOf + 3 because we are cutting it off at `.XX`
v = value.slice(0, value.indexOf('.') + 3)
// Update the input to remove the extra numbers from UI input
setSlippageInput(v)
}
if (value.length === 0) {
slippageToleranceAnalytics('Default', placeholderSlippage.toFixed(2))
setSwapSlippage(isEoaEthFlow ? percentToBps(minEthFlowSlippage) : null)
} else {
let v = value

// Prevent inserting more than 2 decimal precision
if (value.split('.')[1]?.length > 2) {
// indexOf + 3 because we are cutting it off at `.XX`
v = value.slice(0, value.indexOf('.') + 3)
// Update the input to remove the extra numbers from UI input
setSlippageInput(v)
}

const parsed = Math.round(Number.parseFloat(v) * 100)
const parsed = Math.round(Number.parseFloat(v) * 100)

if (
!Number.isInteger(parsed) ||
parsed < (isEoaEthFlow ? minEthFlowSlippageBps : MIN_SLIPPAGE_BPS) ||
parsed > MAX_SLIPPAGE_BPS
) {
if (v !== '.') {
setSlippageError(SlippageError.InvalidInput)
if (
!Number.isInteger(parsed) ||
parsed < (isEoaEthFlow ? minEthFlowSlippageBps : MIN_SLIPPAGE_BPS) ||
parsed > MAX_SLIPPAGE_BPS
) {
if (v !== '.') {
setSlippageError(SlippageError.InvalidInput)
}
}
}

slippageToleranceAnalytics('Custom', parsed)
setSwapSlippage(percentToBps(new Percent(parsed, 10_000)))
}
}
slippageToleranceAnalytics('Custom', parsed)
setSwapSlippage(percentToBps(new Percent(parsed, 10_000)))
}
},
[placeholderSlippage, isEoaEthFlow, minEthFlowSlippage],
)

const tooLow = swapSlippage.lessThan(new Percent(isEoaEthFlow ? minEthFlowSlippageBps : LOW_SLIPPAGE_BPS, 10_000))
const tooHigh = swapSlippage.greaterThan(
new Percent(isEoaEthFlow ? HIGH_ETH_FLOW_SLIPPAGE_BPS : HIGH_SLIPPAGE_BPS, 10_000),
new Percent(isEoaEthFlow ? HIGH_ETH_FLOW_SLIPPAGE_BPS : smartSlippage || HIGH_SLIPPAGE_BPS, 10_000),
)

function parseCustomDeadline(value: string) {
// populate what the user typed and clear the error
setDeadlineInput(value)
setDeadlineError(false)

if (value.length === 0) {
orderExpirationTimeAnalytics('Default', DEFAULT_DEADLINE_FROM_NOW)
setDeadline(DEFAULT_DEADLINE_FROM_NOW)
} else {
try {
const parsed: number = Math.floor(Number.parseFloat(value) * 60)
if (
!Number.isInteger(parsed) || // Check deadline is a number
parsed <
(isEoaEthFlow
? // 10 minute low threshold for eth flow
MINIMUM_ETH_FLOW_DEADLINE_SECONDS
: MINIMUM_ORDER_VALID_TO_TIME_SECONDS) || // Check deadline is not too small
parsed > MAX_DEADLINE_MINUTES * 60 // Check deadline is not too big
) {
const parseCustomDeadline = useCallback(
(value: string) => {
// populate what the user typed and clear the error
setDeadlineInput(value)
setDeadlineError(false)

if (value.length === 0) {
orderExpirationTimeAnalytics('Default', DEFAULT_DEADLINE_FROM_NOW)
setDeadline(DEFAULT_DEADLINE_FROM_NOW)
} else {
try {
const parsed: number = Math.floor(Number.parseFloat(value) * 60)
if (
!Number.isInteger(parsed) || // Check deadline is a number
parsed <
(isEoaEthFlow
? // 10 minute low threshold for eth flow
MINIMUM_ETH_FLOW_DEADLINE_SECONDS
: MINIMUM_ORDER_VALID_TO_TIME_SECONDS) || // Check deadline is not too small
parsed > MAX_DEADLINE_MINUTES * 60 // Check deadline is not too big
) {
setDeadlineError(DeadlineError.InvalidInput)
} else {
orderExpirationTimeAnalytics('Custom', parsed)
setDeadline(parsed)
}
} catch (error: any) {
console.error(error)
setDeadlineError(DeadlineError.InvalidInput)
} else {
orderExpirationTimeAnalytics('Custom', parsed)
setDeadline(parsed)
}
} catch (error: any) {
console.error(error)
setDeadlineError(DeadlineError.InvalidInput)
}
}
}
},
[isEoaEthFlow],
)

const showCustomDeadlineRow = Boolean(chainId)

@@ -185,14 +191,14 @@ export function TransactionSettings({ deadlineState }: TransactionSettingsProps)
<AutoColumn gap="sm">
<RowFixed>
<ThemedText.Black fontWeight={400} fontSize={14}>
<Trans>MEV protected slippage</Trans>
<Trans>MEV-protected slippage</Trans>
</ThemedText.Black>
<HelpTooltip
text={
// <Trans>Your transaction will revert if the price changes unfavorably by more than this percentage.</Trans>
isEoaEthFlow
? getNativeSlippageTooltip(chainId, [nativeCurrency.symbol, getWrappedToken(nativeCurrency).symbol])
: getNonNativeSlippageTooltip()
: getNonNativeSlippageTooltip(true)
}
/>
</RowFixed>
@@ -251,8 +257,8 @@ export function TransactionSettings({ deadlineState }: TransactionSettingsProps)
<HelpTooltip
text={
<Trans>
Based on recent volatility observed for this token pair, it's recommended to leave the default to
account for price changes.
CoW Swap has dynamically selected this slippage amount to account for current gas prices and
volatility. Changes may result in slower execution.
</Trans>
}
/>
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ const DefaultSlippage = styled.span`
`

const SUGGESTED_SLIPPAGE_TOOLTIP =
'Based on recent volatility for the selected token pair, this is the suggested slippage for ensuring quick execution of your order.'
'This is the recommended slippage tolerance based on current gas prices & volatility. A lower amount may result in slower execution.'

export interface RowSlippageContentProps {
chainId: SupportedChainId
@@ -82,7 +82,7 @@ export function RowSlippageContent(props: RowSlippageContentProps) {
<CenteredDots />
) : (
<>
<LinkStyledButton onClick={setAutoSlippage}>(Suggested: {smartSlippage})</LinkStyledButton>
<LinkStyledButton onClick={setAutoSlippage}>(Recommended: {smartSlippage})</LinkStyledButton>
<HoverTooltip wrapInContainer content={SUGGESTED_SLIPPAGE_TOOLTIP}>
<StyledInfoIcon size={16} />
</HoverTooltip>
22 changes: 1 addition & 21 deletions libs/common-const/src/misc.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
import { Percent, Fraction } from '@uniswap/sdk-core'
import { Fraction, Percent } from '@uniswap/sdk-core'

import JSBI from 'jsbi'

export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'

export const NetworkContextName = 'NETWORK'

export const IS_IN_IFRAME = typeof window !== 'undefined' && window.parent !== window

// 30 minutes, denominated in seconds
export const DEFAULT_DEADLINE_FROM_NOW = 60 * 30
export const L2_DEADLINE_FROM_NOW = 60 * 5

// transaction popup dismisal amounts
export const DEFAULT_TXN_DISMISS_MS = 25000
export const L2_TXN_DISMISS_MS = 5000

// used for rewards deadlines
export const BIG_INT_SECONDS_IN_WEEK = JSBI.BigInt(60 * 60 * 24 * 7)

export const BIG_INT_ZERO = JSBI.BigInt(0)

// one basis JSBI.BigInt
const BPS_BASE = JSBI.BigInt(10000)
export const ONE_BPS = new Percent(JSBI.BigInt(1), BPS_BASE)

// used for warning states
export const ALLOWED_PRICE_IMPACT_LOW: Percent = new Percent(JSBI.BigInt(100), BPS_BASE) // 1%
@@ -34,12 +20,6 @@ export const PRICE_IMPACT_WITHOUT_FEE_CONFIRM_MIN: Percent = new Percent(JSBI.Bi
// for non expert mode disable swaps above this
export const BLOCKED_PRICE_IMPACT_NON_EXPERT: Percent = new Percent(JSBI.BigInt(1500), BPS_BASE) // 15%

export const BETTER_TRADE_LESS_HOPS_THRESHOLD = new Percent(JSBI.BigInt(50), BPS_BASE)

export const ZERO_PERCENT = new Percent('0')
export const TWO_PERCENT = new Percent(JSBI.BigInt(200), BPS_BASE)
export const ONE_HUNDRED_PERCENT = new Percent('1')

export const IS_SIDE_BANNER_VISIBLE_KEY = 'IS_SIDEBAR_BANNER_VISIBLE'

export const ONE_FRACTION = new Fraction(1, 1)
You are viewing a condensed version of this merge commit. You can view the full changes here.