Skip to content

feat: USDT approve(0) reset flow for Ethereum mainnet swap#1925

Open
piatoss3612 wants to merge 8 commits intodevelopfrom
rowan/KEPLR-1992
Open

feat: USDT approve(0) reset flow for Ethereum mainnet swap#1925
piatoss3612 wants to merge 8 commits intodevelopfrom
rowan/KEPLR-1992

Conversation

@piatoss3612
Copy link
Copy Markdown
Member

Summary

  • Ethereum 메인넷 USDT 스왑 시, 기존 ERC20 allowance가 0이 아닌 경우 approve(0)을 선행하는 "Reset Allowance" 플로우 추가
  • USDT TetherToken의 비표준 approve 구현 (require(!((_value != 0) && (allowed[msg.sender][_spender] != 0)))) 대응
  • On-chain 검증 결과 Ethereum 메인넷만 해당 (L2 USDT/USDT0는 표준 ERC20 호환)

Changes

stores-eth

  • USDT_APPROVE_RESET_REQUIRED 상수 + isApproveResetRequired() 감지 함수
  • ObservableQueryERC20Allowance / ObservableQueryERC20AllowanceMap — MobX observable allowance 조회

hooks / UI

  • useUsdtApprovalReset 훅 — allowance 조회, spender 캐싱, approve(0) tx 전송, gas estimation, pending 상태 관리
  • UsdtAllowanceResetInfo 컴포넌트 — Figma 원본 SVG (도트 패턴 + USDT shield 아이콘) + 안내 텍스트
  • useQueryRouteRefresh — reset 필요 시 route 자동 refresh 차단
  • IBCSwapConfigisApprovalResetPending 상태를 MobX store로 관리 (페이지 이동 간 유지)
  • i18n (en/ko/zh-cn) 번역 추가

UX

  • 에러(insufficient balance 등) 시 reset UI 대신 에러 우선 표시
  • amount가 0/빈 문자열이면 reset UI 숨김
  • approve(0) 컨펌 후 allowance refetch + route refresh + 성공 토스트

⚠️ 테스트용 임시 코드 (머지 전 제거 필요)

  • apps/hooks-internal/src/swap/amount.ts — swap tx data 0xdeadbeef 변조

Tickets

  • KEPLR-1850
  • KEPLR-1992

Test plan

  • Ethereum USDT 스왑: allowance > 0 → Reset Allowance UI 표시 → approve(0) → 컨펌 → 일반 스왑 플로우
  • Ethereum USDT 스왑: allowance == 0 → 기존 플로우 (Reset UI 안 뜸)
  • L2 USDT 스왑 → 기존 플로우 (영향 없음)
  • 비-USDT ERC20 스왑 → 기존 플로우 (영향 없음)
  • insufficient balance 시 → 에러 우선 표시, Reset UI 숨김
  • approve(0) 서명 후 페이지 이탈 → 재진입 시 pending 상태 유지
  • amount 0/빈 문자열 → Reset UI 숨김
  • 임시 코드 (0xdeadbeef) 제거 후 전체 스왑 플로우 E2E 확인

- Introduced `ObservableQueryERC20Allowance` to fetch and compute ERC20 token allowances.
- Added `ObservableQueryERC20AllowanceMap` for managing multiple allowance queries.
- Updated `EthereumQueriesImpl` to include the new allowance query functionality.
- Added a constant for USDT approval reset requirements and a utility function to check if an approval reset is needed based on chain ID and token address.
- Introduced new components and hooks for resetting USDT allowance in the swap process.
- Updated language files to include descriptions and button labels for the allowance reset feature in English, Korean, and Simplified Chinese.
- Implemented logic to handle approval reset requirements and transaction simulation for gas estimation.
- Integrated `useUsdtApprovalReset` hook to manage USDT allowance reset logic.
- Updated `IBCSwapPage` to conditionally display the allowance reset UI and handle reset actions.
- Modified `useQueryRouteRefresh` to account for approval reset state.
- Added state management for approval reset pending status in `IBCSwapConfig`.
@piatoss3612 piatoss3612 requested a review from a team as a code owner April 14, 2026 12:47
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
keplr-wallet-extension Ready Ready Preview, Comment Apr 15, 2026 6:02am

Request Review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e8f3790d29

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/extension/src/pages/ibc-swap/hooks/use-usdt-approval-reset.ts
Comment thread apps/extension/src/pages/ibc-swap/hooks/use-usdt-approval-reset.ts
…g state

- P1: gate requiresApprovalReset by isInputUsdtRequiringReset so a pending
  reset does not block unrelated token/chain swaps
- P2: add on-chain allowance fallback to clear stuck isApprovalResetPending
  when tx fulfill callback is missed (retry exhaustion, delayed receipt)
…cator

- Expose refetchAllowance from useUsdtApprovalReset hook
- Call refetchAllowance in both swap success and failure paths so the
  next attempt evaluates reset UI against fresh on-chain allowance
  (approve(amount) may have succeeded even when swap failed)
- Hide step indicator and "N approvals required" label while
  showApprovalResetUI is active — the reset info block already
  communicates the 2-step requirement
@piatoss3612
Copy link
Copy Markdown
Member Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c3a53e930e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/extension/src/pages/ibc-swap/hooks/use-usdt-approval-reset.ts
Comment thread apps/extension/src/pages/ibc-swap/hooks/use-usdt-approval-reset.ts Outdated
Pre-broadcast failures (gas simulation, tx encoding) were silently
swallowed by the outer catch — the loading button briefly flashed
then reset with no feedback. Call onResetFailed in the catch so the
"transaction-failed" toast surfaces these errors.
@piatoss3612 piatoss3612 changed the base branch from master to develop April 15, 2026 05:26
@piatoss3612
Copy link
Copy Markdown
Member Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 398629c332

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/extension/src/pages/ibc-swap/hooks/use-usdt-approval-reset.ts Outdated
Previously approvalSpenderRef only updated when requiredErc20Approvals[0]
existed. After the user lowered the swap amount below their current
allowance, the new quote returned no approval and the ref kept pointing
to the old spender. The reset UI stayed visible against that stale
spender's allowance, but clicking Reset no-op'd because the live tx had
no approval — leaving the user stuck.

Now the ref is set to null when the ready tx has no approval, only
mutating once a fresh tx is observed (preserves the original transient
null-tx flicker guard).
@piatoss3612
Copy link
Copy Markdown
Member Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 896ae43c27

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/extension/src/pages/ibc-swap/hooks/use-usdt-approval-reset.ts
Comment thread apps/extension/src/pages/ibc-swap/hooks/use-usdt-approval-reset.ts Outdated
sendEthereumTx invokes onBroadcastFailed and then rethrows for any
broadcast error, including the user-initiated "Request rejected"
case. Without filtering, declining the signing prompt produced a
misleading transaction-failed toast.

Match the main swap submit path's behavior: skip onResetFailed when
the error message is "Request rejected", in both the onBroadcastFailed
callback and the outer catch (covers pre-broadcast cancellation paths).
@piatoss3612 piatoss3612 added the mobile-sync Cherry-pick to develop-mobile on merge label Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mobile-sync Cherry-pick to develop-mobile on merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant