Skip to content

feat: add DeFi portfolio actions#11801

Draft
zhaono1 wants to merge 41 commits into
xfrom
feat/defi-portfolio-actions
Draft

feat: add DeFi portfolio actions#11801
zhaono1 wants to merge 41 commits into
xfrom
feat/defi-portfolio-actions

Conversation

@zhaono1

@zhaono1 zhaono1 commented May 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add DeFi position action support driven by /earn/v1/defi/supported-protocols.
  • Add build-transaction wiring and action dialogs for withdraw, claim, claimWithdrawal, and remove liquidity.
  • Preserve portfolio/account identity through grouped positions so action routing and post-action refresh use the same account context.
  • Refresh the Home DeFi list after a successful action submission path.

Intent & Context

The wallet Home DeFi module exposes portfolio operations based on the Earn service contract. The UI renders only actions returned by /earn/v1/defi/supported-protocols and hides actions when required build-transaction metadata is missing.

Design Decisions

  • Resolve available actions from protocolId, networkId, position category, asset/reward category, and server-provided action metadata.
  • Preserve source DeFi positions through grouped display rows so action parameters can be derived from the original payload.
  • Preserve accountId and indexedAccountId on transformed protocol data so detail pages and Aave Borrow Manage route handoffs do not fall back to a different current selector account.
  • Treat unsupported or incomplete action metadata as fail-closed instead of rendering a broken transaction entry point.
  • Implement the Lido withdraw permit sequence only: build permit, sign typed data, then build the withdraw transaction with signature and deadline.
  • Reject approvalTx responses until a dedicated approval UX exists.
  • For Uniswap remove-liquidity, keep every source LP/NFT action asset selectable when grouped rows contain multiple positions.
  • For Polygon claimWithdrawal, submit a single unbondNonces[0] per transaction to match the current service handler behavior.

Changes Detail

  • ServiceDeFi: fetch supported DeFi actions and build action transactions through the Earn API.
  • Shared DeFi types/utils: add action/build-transaction contracts, execution metadata preservation, and account identity preservation.
  • Home DeFi module: fetch supported actions, render action controls, and force refresh after successful submission.
  • DeFi details page: render the same action controls for protocol position details.
  • DeFi action components: add shared action button and transaction dialog UI.
  • Borrow manage handoff: pass indexed account identity from DeFi positions into Aave manage route params.
  • Tests: cover resolver behavior for Morpho, Uniswap groupId/tokenId, grouped Uniswap remove-liquidity assets, Polygon claimWithdrawal nonce handling, Ethena claimWithdrawal metadata, pool-address fail-closed behavior, and DeFi transform account identity.

Risk Assessment

  • Risk Level: Medium
  • Affected Platforms: Desktop / Web / Mobile / Extension surfaces that use the shared DeFi views
  • Risk Areas: Backend transaction contract compatibility, grouped-position metadata preservation, account route identity, and action visibility matching the service-supported scope.

Test plan

  • npx jest packages/shared/src/utils/defiActionUtils.test.ts packages/shared/src/utils/defiUtils.test.ts --runInBand
  • npx oxlint --tsconfig ./tsconfig.json --type-aware --deny-warnings packages/shared/types/defi.ts packages/shared/src/utils/defiUtils.ts packages/kit-bg/src/services/ServiceDeFi.ts packages/kit/src/views/Home/components/DeFiListBlock/DeFiListBlock.tsx packages/kit/src/views/Home/components/DeFiListBlock/Protocol.tsx packages/kit/src/views/Home/components/DeFiListBlock/ProtocolCategoryGroup.tsx packages/kit/src/views/Home/components/DeFiListBlock/ProtocolUnifiedTable.tsx packages/kit/src/views/AssetDetails/pages/DeFiProtocolDetails.tsx packages/kit/src/components/DeFi/ProtocolPositionActionButton.tsx packages/kit/src/components/DeFi/ProtocolPositionActionDialog.tsx packages/shared/src/utils/defiActionUtils.ts packages/shared/src/utils/defiActionUtils.test.ts packages/shared/src/utils/defiUtils.test.ts
  • git diff --cached --check
  • yarn lint:staged
  • yarn tsc:staged currently blocked by existing unrelated errors in packages/kit/src/views/Perp/components/OrderBook/AnimatedDepthBlock.native.tsx and packages/shared/src/errors/**ThirdParty* (ThirdPartyHwErrorCode.NetworkError).
  • Runtime transaction flow should be validated against a service environment with supported DeFi positions.

Runtime Validation Targets

  • Aave Manage from a DeFi position with debt opens the Borrow manage page using the same accountId / indexedAccountId.
  • Uniswap V3/V4 grouped rows with multiple LP/NFT positions show a selector and submit the selected tokenId.
  • Polygon claimWithdrawal submits one nonce per transaction.
  • Lido withdraw runs permit -> typed-data sign -> withdraw.
  • Missing poolAddress remains fail-closed.

@revan-zhang

revan-zhang commented May 27, 2026

Copy link
Copy Markdown
Contributor

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@zhaono1 zhaono1 force-pushed the feat/defi-portfolio-actions branch 2 times, most recently from 153843a to f609dd3 Compare May 28, 2026 08:43
@zhaono1 zhaono1 force-pushed the feat/defi-portfolio-actions branch 2 times, most recently from ea708de to f8fd310 Compare June 11, 2026 02:03
@zhaono1 zhaono1 force-pushed the feat/defi-portfolio-actions branch from f8fd310 to e72024e Compare June 11, 2026 06:07
labrinyang and others added 17 commits June 17, 2026 11:21
# Conflicts:
#	packages/shared/src/locale/json/bn.json
#	packages/shared/src/locale/json/de.json
#	packages/shared/src/locale/json/es.json
#	packages/shared/src/locale/json/fr_FR.json
#	packages/shared/src/locale/json/hi_IN.json
#	packages/shared/src/locale/json/id.json
#	packages/shared/src/locale/json/it_IT.json
#	packages/shared/src/locale/json/ja_JP.json
#	packages/shared/src/locale/json/ko_KR.json
#	packages/shared/src/locale/json/pt.json
#	packages/shared/src/locale/json/pt_BR.json
#	packages/shared/src/locale/json/ru.json
#	packages/shared/src/locale/json/th_TH.json
#	packages/shared/src/locale/json/uk_UA.json
#	packages/shared/src/locale/json/vi.json
#	packages/shared/src/locale/json/zh_HK.json
#	packages/shared/src/locale/json/zh_TW.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants