fix: reset LDO approvals (#7345)
* fix: reset LDO approvals * fix: constant file, better name * Update src/components/swap/constants.ts Co-authored-by: Charles Bachmeier <charles@bachmeier.io> --------- Co-authored-by: Charles Bachmeier <charles@bachmeier.io>
This commit is contained in:
parent
e81b0a4d1f
commit
15c510b742
@ -12,7 +12,6 @@ import Badge from 'components/Badge'
|
||||
import Modal, { MODAL_TRANSITION_DURATION } from 'components/Modal'
|
||||
import { RowFixed } from 'components/Row'
|
||||
import { getChainInfo } from 'constants/chainInfo'
|
||||
import { USDT as USDT_MAINNET } from 'constants/tokens'
|
||||
import { TransactionStatus } from 'graphql/data/__generated__/types-and-hooks'
|
||||
import { useMaxAmountIn } from 'hooks/useMaxAmountIn'
|
||||
import { Allowance, AllowanceState } from 'hooks/usePermit2Allowance'
|
||||
@ -35,6 +34,7 @@ import { didUserReject } from 'utils/swapErrorToUserReadableMessage'
|
||||
import { tradeMeaningfullyDiffers } from 'utils/tradeMeaningFullyDiffer'
|
||||
|
||||
import { ConfirmationModalContent } from '../TransactionConfirmationModal'
|
||||
import { RESET_APPROVAL_TOKENS } from './constants'
|
||||
import { PendingConfirmModalState, PendingModalContent } from './PendingModalContent'
|
||||
import { ErrorModalContent, PendingModalError } from './PendingModalContent/ErrorModalContent'
|
||||
import SwapModalFooter from './SwapModalFooter'
|
||||
@ -43,7 +43,7 @@ import SwapModalHeader from './SwapModalHeader'
|
||||
export enum ConfirmModalState {
|
||||
REVIEWING,
|
||||
WRAPPING,
|
||||
RESETTING_USDT,
|
||||
RESETTING_TOKEN_ALLOWANCE,
|
||||
APPROVING_TOKEN,
|
||||
PERMITTING,
|
||||
PENDING_CONFIRMATION,
|
||||
@ -60,7 +60,7 @@ const StyledL2Logo = styled.img`
|
||||
|
||||
function isInApprovalPhase(confirmModalState: ConfirmModalState) {
|
||||
return (
|
||||
confirmModalState === ConfirmModalState.RESETTING_USDT ||
|
||||
confirmModalState === ConfirmModalState.RESETTING_TOKEN_ALLOWANCE ||
|
||||
confirmModalState === ConfirmModalState.APPROVING_TOKEN ||
|
||||
confirmModalState === ConfirmModalState.PERMITTING
|
||||
)
|
||||
@ -94,15 +94,13 @@ function useConfirmModalState({
|
||||
if (trade.fillType === TradeFillType.UniswapX && trade.wrapInfo.needsWrap) {
|
||||
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 (
|
||||
allowance.state === AllowanceState.REQUIRED &&
|
||||
allowance.needsSetupApproval &&
|
||||
allowance.token.equals(USDT_MAINNET) &&
|
||||
RESET_APPROVAL_TOKENS.some((token) => token.equals(allowance.token)) &&
|
||||
allowance.allowedAmount.greaterThan(0)
|
||||
) {
|
||||
steps.push(ConfirmModalState.RESETTING_USDT)
|
||||
steps.push(ConfirmModalState.RESETTING_TOKEN_ALLOWANCE)
|
||||
}
|
||||
if (allowance.state === AllowanceState.REQUIRED && allowance.needsSetupApproval) {
|
||||
steps.push(ConfirmModalState.APPROVING_TOKEN)
|
||||
@ -159,8 +157,8 @@ function useConfirmModalState({
|
||||
})
|
||||
.catch((e) => catchUserReject(e, PendingModalError.WRAP_ERROR))
|
||||
break
|
||||
case ConfirmModalState.RESETTING_USDT:
|
||||
setConfirmModalState(ConfirmModalState.RESETTING_USDT)
|
||||
case ConfirmModalState.RESETTING_TOKEN_ALLOWANCE:
|
||||
setConfirmModalState(ConfirmModalState.RESETTING_TOKEN_ALLOWANCE)
|
||||
invariant(allowance.state === AllowanceState.REQUIRED, 'Allowance should be required')
|
||||
allowance.revoke().catch((e) => catchUserReject(e, PendingModalError.TOKEN_APPROVAL_ERROR))
|
||||
break
|
||||
|
@ -97,7 +97,7 @@ export type PendingConfirmModalState = Extract<
|
||||
| ConfirmModalState.PERMITTING
|
||||
| ConfirmModalState.PENDING_CONFIRMATION
|
||||
| ConfirmModalState.WRAPPING
|
||||
| ConfirmModalState.RESETTING_USDT
|
||||
| ConfirmModalState.RESETTING_TOKEN_ALLOWANCE
|
||||
>
|
||||
|
||||
interface PendingModalStep {
|
||||
@ -207,9 +207,9 @@ function useStepContents(args: ContentArgs): Record<PendingConfirmModalState, Pe
|
||||
),
|
||||
bottomLabel: wrapPending ? t`Pending...` : t`Proceed in your wallet`,
|
||||
},
|
||||
[ConfirmModalState.RESETTING_USDT]: {
|
||||
title: t`Reset USDT`,
|
||||
subtitle: t`USDT requires resetting approval when spending limits are too low.`,
|
||||
[ConfirmModalState.RESETTING_TOKEN_ALLOWANCE]: {
|
||||
title: t`Reset ${approvalCurrency?.symbol}`,
|
||||
subtitle: t`${approvalCurrency?.symbol} requires resetting approval when spending limits are too low.`,
|
||||
bottomLabel: revocationPending ? t`Pending...` : t`Proceed in your wallet`,
|
||||
},
|
||||
[ConfirmModalState.APPROVING_TOKEN]: {
|
||||
|
5
src/components/swap/constants.ts
Normal file
5
src/components/swap/constants.ts
Normal file
@ -0,0 +1,5 @@
|
||||
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
|
||||
|
||||
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 } = {
|
||||
...(WETH9 as Record<ChainId, Token>),
|
||||
[ChainId.OPTIMISM]: new Token(
|
||||
|
Loading…
Reference in New Issue
Block a user