Commit 15c510b7 authored by eddie's avatar eddie Committed by GitHub

fix: reset LDO approvals (#7345)

* fix: reset LDO approvals

* fix: constant file, better name

* Update src/components/swap/constants.ts
Co-authored-by: default avatarCharles Bachmeier <charles@bachmeier.io>

---------
Co-authored-by: default avatarCharles Bachmeier <charles@bachmeier.io>
parent e81b0a4d
...@@ -12,7 +12,6 @@ import Badge from 'components/Badge' ...@@ -12,7 +12,6 @@ import Badge from 'components/Badge'
import Modal, { MODAL_TRANSITION_DURATION } from 'components/Modal' import Modal, { MODAL_TRANSITION_DURATION } from 'components/Modal'
import { RowFixed } from 'components/Row' import { RowFixed } from 'components/Row'
import { getChainInfo } from 'constants/chainInfo' import { getChainInfo } from 'constants/chainInfo'
import { USDT as USDT_MAINNET } from 'constants/tokens'
import { TransactionStatus } from 'graphql/data/__generated__/types-and-hooks' import { TransactionStatus } from 'graphql/data/__generated__/types-and-hooks'
import { useMaxAmountIn } from 'hooks/useMaxAmountIn' import { useMaxAmountIn } from 'hooks/useMaxAmountIn'
import { Allowance, AllowanceState } from 'hooks/usePermit2Allowance' import { Allowance, AllowanceState } from 'hooks/usePermit2Allowance'
...@@ -35,6 +34,7 @@ import { didUserReject } from 'utils/swapErrorToUserReadableMessage' ...@@ -35,6 +34,7 @@ import { didUserReject } from 'utils/swapErrorToUserReadableMessage'
import { tradeMeaningfullyDiffers } from 'utils/tradeMeaningFullyDiffer' import { tradeMeaningfullyDiffers } from 'utils/tradeMeaningFullyDiffer'
import { ConfirmationModalContent } from '../TransactionConfirmationModal' import { ConfirmationModalContent } from '../TransactionConfirmationModal'
import { RESET_APPROVAL_TOKENS } from './constants'
import { PendingConfirmModalState, PendingModalContent } from './PendingModalContent' import { PendingConfirmModalState, PendingModalContent } from './PendingModalContent'
import { ErrorModalContent, PendingModalError } from './PendingModalContent/ErrorModalContent' import { ErrorModalContent, PendingModalError } from './PendingModalContent/ErrorModalContent'
import SwapModalFooter from './SwapModalFooter' import SwapModalFooter from './SwapModalFooter'
...@@ -43,7 +43,7 @@ import SwapModalHeader from './SwapModalHeader' ...@@ -43,7 +43,7 @@ import SwapModalHeader from './SwapModalHeader'
export enum ConfirmModalState { export enum ConfirmModalState {
REVIEWING, REVIEWING,
WRAPPING, WRAPPING,
RESETTING_USDT, RESETTING_TOKEN_ALLOWANCE,
APPROVING_TOKEN, APPROVING_TOKEN,
PERMITTING, PERMITTING,
PENDING_CONFIRMATION, PENDING_CONFIRMATION,
...@@ -60,7 +60,7 @@ const StyledL2Logo = styled.img` ...@@ -60,7 +60,7 @@ const StyledL2Logo = styled.img`
function isInApprovalPhase(confirmModalState: ConfirmModalState) { function isInApprovalPhase(confirmModalState: ConfirmModalState) {
return ( return (
confirmModalState === ConfirmModalState.RESETTING_USDT || confirmModalState === ConfirmModalState.RESETTING_TOKEN_ALLOWANCE ||
confirmModalState === ConfirmModalState.APPROVING_TOKEN || confirmModalState === ConfirmModalState.APPROVING_TOKEN ||
confirmModalState === ConfirmModalState.PERMITTING confirmModalState === ConfirmModalState.PERMITTING
) )
...@@ -94,15 +94,13 @@ function useConfirmModalState({ ...@@ -94,15 +94,13 @@ function useConfirmModalState({
if (trade.fillType === TradeFillType.UniswapX && trade.wrapInfo.needsWrap) { if (trade.fillType === TradeFillType.UniswapX && trade.wrapInfo.needsWrap) {
steps.push(ConfirmModalState.WRAPPING) steps.push(ConfirmModalState.WRAPPING)
} }
// Any existing USDT allowance needs to be reset before we can approve the new amount (mainnet only).
// See the `approve` function here: https://etherscan.io/address/0xdAC17F958D2ee523a2206206994597C13D831ec7#code
if ( if (
allowance.state === AllowanceState.REQUIRED && allowance.state === AllowanceState.REQUIRED &&
allowance.needsSetupApproval && allowance.needsSetupApproval &&
allowance.token.equals(USDT_MAINNET) && RESET_APPROVAL_TOKENS.some((token) => token.equals(allowance.token)) &&
allowance.allowedAmount.greaterThan(0) allowance.allowedAmount.greaterThan(0)
) { ) {
steps.push(ConfirmModalState.RESETTING_USDT) steps.push(ConfirmModalState.RESETTING_TOKEN_ALLOWANCE)
} }
if (allowance.state === AllowanceState.REQUIRED && allowance.needsSetupApproval) { if (allowance.state === AllowanceState.REQUIRED && allowance.needsSetupApproval) {
steps.push(ConfirmModalState.APPROVING_TOKEN) steps.push(ConfirmModalState.APPROVING_TOKEN)
...@@ -159,8 +157,8 @@ function useConfirmModalState({ ...@@ -159,8 +157,8 @@ function useConfirmModalState({
}) })
.catch((e) => catchUserReject(e, PendingModalError.WRAP_ERROR)) .catch((e) => catchUserReject(e, PendingModalError.WRAP_ERROR))
break break
case ConfirmModalState.RESETTING_USDT: case ConfirmModalState.RESETTING_TOKEN_ALLOWANCE:
setConfirmModalState(ConfirmModalState.RESETTING_USDT) setConfirmModalState(ConfirmModalState.RESETTING_TOKEN_ALLOWANCE)
invariant(allowance.state === AllowanceState.REQUIRED, 'Allowance should be required') invariant(allowance.state === AllowanceState.REQUIRED, 'Allowance should be required')
allowance.revoke().catch((e) => catchUserReject(e, PendingModalError.TOKEN_APPROVAL_ERROR)) allowance.revoke().catch((e) => catchUserReject(e, PendingModalError.TOKEN_APPROVAL_ERROR))
break break
......
...@@ -97,7 +97,7 @@ export type PendingConfirmModalState = Extract< ...@@ -97,7 +97,7 @@ export type PendingConfirmModalState = Extract<
| ConfirmModalState.PERMITTING | ConfirmModalState.PERMITTING
| ConfirmModalState.PENDING_CONFIRMATION | ConfirmModalState.PENDING_CONFIRMATION
| ConfirmModalState.WRAPPING | ConfirmModalState.WRAPPING
| ConfirmModalState.RESETTING_USDT | ConfirmModalState.RESETTING_TOKEN_ALLOWANCE
> >
interface PendingModalStep { interface PendingModalStep {
...@@ -207,9 +207,9 @@ function useStepContents(args: ContentArgs): Record<PendingConfirmModalState, Pe ...@@ -207,9 +207,9 @@ function useStepContents(args: ContentArgs): Record<PendingConfirmModalState, Pe
), ),
bottomLabel: wrapPending ? t`Pending...` : t`Proceed in your wallet`, bottomLabel: wrapPending ? t`Pending...` : t`Proceed in your wallet`,
}, },
[ConfirmModalState.RESETTING_USDT]: { [ConfirmModalState.RESETTING_TOKEN_ALLOWANCE]: {
title: t`Reset USDT`, title: t`Reset ${approvalCurrency?.symbol}`,
subtitle: t`USDT requires resetting approval when spending limits are too low.`, subtitle: t`${approvalCurrency?.symbol} requires resetting approval when spending limits are too low.`,
bottomLabel: revocationPending ? t`Pending...` : t`Proceed in your wallet`, bottomLabel: revocationPending ? t`Pending...` : t`Proceed in your wallet`,
}, },
[ConfirmModalState.APPROVING_TOKEN]: { [ConfirmModalState.APPROVING_TOKEN]: {
......
import { LDO, USDT as USDT_MAINNET } from 'constants/tokens'
// List of tokens that require existing allowance to be reset before approving the new amount (mainnet only).
// See the `approve` function here: https://etherscan.io/address/0xdAC17F958D2ee523a2206206994597C13D831ec7#code
export const RESET_APPROVAL_TOKENS = [USDT_MAINNET, LDO]
...@@ -260,6 +260,8 @@ export const ARB = new Token(ChainId.ARBITRUM_ONE, '0x912CE59144191C1204E64559FE ...@@ -260,6 +260,8 @@ export const ARB = new Token(ChainId.ARBITRUM_ONE, '0x912CE59144191C1204E64559FE
export const OP = new Token(ChainId.OPTIMISM, '0x4200000000000000000000000000000000000042', 18, 'OP', 'Optimism') export const OP = new Token(ChainId.OPTIMISM, '0x4200000000000000000000000000000000000042', 18, 'OP', 'Optimism')
export const LDO = new Token(ChainId.MAINNET, '0x5A98FcBEA516Cf06857215779Fd812CA3beF1B32', 18, 'LDO', 'Lido DAO Token')
export const WRAPPED_NATIVE_CURRENCY: { [chainId: number]: Token | undefined } = { export const WRAPPED_NATIVE_CURRENCY: { [chainId: number]: Token | undefined } = {
...(WETH9 as Record<ChainId, Token>), ...(WETH9 as Record<ChainId, Token>),
[ChainId.OPTIMISM]: new Token( [ChainId.OPTIMISM]: new Token(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment