Skip to content

feat(evm): swap and repay#5360

Merged
david-sun-venus merged 19 commits intomainfrom
feat/swap-repay
Mar 3, 2026
Merged

feat(evm): swap and repay#5360
david-sun-venus merged 19 commits intomainfrom
feat/swap-repay

Conversation

@david-sun-venus
Copy link
Copy Markdown
Contributor

Jira ticket(s)

VPD-571

Changes

  • Upgrade swap and repay with new SwapRouter contracts.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 10, 2026

🦋 Changeset detected

Latest commit: 823436a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@venusprotocol/chains Minor
@venusprotocol/evm Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 10, 2026

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

Project Deployment Actions Updated (UTC)
dapp-preview Ready Ready Preview Mar 3, 2026 7:55am
dapp-testnet Ready Ready Preview Mar 3, 2026 7:55am
venus.io Ready Ready Preview Mar 3, 2026 7:55am

Request Review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 13, 2026

Coverage Report for ./apps/evm

Status Category Percentage Covered / Total
🔵 Lines 77.77% 34906 / 44880
🔵 Statements 77.77% 34906 / 44880
🔵 Functions 60.27% 563 / 934
🔵 Branches 72.52% 4218 / 5816
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
apps/evm/src/clients/api/mutations/useSwapTokensAndRepay/index.ts 98.02% 84.21% 100% 98.02% 1, 141, 149
apps/evm/src/clients/api/mutations/useSwapTokensAndSupply/index.ts 89.85% 50% 100% 89.85% 1, 84-94, 112, 122
apps/evm/src/components/SelectTokenTextField/index.tsx 98.75% 80% 66.66% 98.75% 56
apps/evm/src/components/SelectTokenTextField/styles.ts 95.83% 85.71% 100% 95.83% 1
apps/evm/src/constants/fullRepaymentBuffer.ts 100% 0% 100% 100%
apps/evm/src/hooks/useGetSwapTokenUserBalances/index.ts 96.96% 85.71% 100% 96.96% 1
apps/evm/src/hooks/useIsFeatureEnabled/index.tsx 99.32% 0% 100% 99.32% 1
apps/evm/src/libs/tokens/hooks/useGetSwapTokens/index.ts 85.71% 0% 100% 85.71% 1
apps/evm/src/libs/tokens/infos/disabledTokenActions/bscMainnet.ts 0% 100% 100% 0% 3-8
apps/evm/src/libs/tokens/infos/disabledTokenActions/bscTestnet.ts 0% 100% 100% 0% 3
apps/evm/src/pages/Market/OperationForm/index.tsx 83.69% 25% 25% 83.69% 85-104
apps/evm/src/pages/Market/OperationForm/Repay/index.tsx 100% 100% 100% 100%
apps/evm/src/pages/Market/OperationForm/Repay/RepayWithWalletBalanceForm/index.tsx 97.4% 90.9% 87.5% 97.4% 97, 175, 465-475, 488
apps/evm/src/pages/Market/OperationForm/Repay/RepayWithWalletBalanceForm/getInitialFormValues/index.ts 100% 0% 100% 100%
apps/evm/src/pages/Market/OperationForm/Repay/RepayWithWalletBalanceForm/useForm/index.tsx 95.12% 80% 100% 95.12% 1, 122-127
apps/evm/src/pages/Market/OperationForm/Repay/RepayWithWalletBalanceForm/useForm/useFormValidation/index.ts 91.17% 87.5% 100% 91.17% 1, 90-95
apps/evm/src/pages/Market/OperationForm/SupplyForm/index.tsx 90.77% 85.13% 77.77% 90.77% 100, 189, 327-342, 353-354, 379-380, 437-447, 462, 501-504
apps/evm/src/pages/Market/OperationForm/SupplyForm/useForm/useFormValidation.ts 98.61% 93.33% 100% 98.61% 1
apps/evm/src/pages/Market/OperationForm/useGetOperationFormTokenBalances/index.ts 97.5% 80% 100% 97.5% 3
apps/evm/src/pages/Swap/index.tsx 97.47% 84.21% 100% 97.47% 169-171, 364, 409, 416-419
apps/evm/src/types/index.ts 97.36% 83.33% 100% 97.36% 8
apps/evm/src/utilities/buffer/index.ts 90.9% 0% 100% 90.9% 1
Generated in workflow #12741 for commit 823436a by the Vitest Coverage Report Action

@therealemjy
Copy link
Copy Markdown
Member

@greptile

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Feb 25, 2026

Greptile Summary

This PR upgrades swap and repay functionality to use the new SwapRouterV2 contracts, simplifying the API from 9 function variants to 4. However, it introduces a critical bug in the wrap/unwrap native token feature.

Key Changes

  • Migrated from SwapRouter to SwapRouterV2 with simplified contract calls
  • Changed swap data structure from Swap to SwapQuote with updated field names
  • Removed NativeTokenBalanceWrapper component and consolidated logic into useGetOperationFormTokenBalances
  • Updated buffer logic to use FULL_REPAYMENT_BUFFER_PERCENTAGE constant
  • Simplified token filtering to check specific disabled actions

Critical Issue

The wrap/unwrap native token feature is broken. The useGetSwapTokenUserBalances hook only returns underlying tokens from pool assets, but native tokens (BNB, ETH) are never underlying tokens of vTokens. This means userWalletNativeTokenBalanceTokens is never set, breaking the feature that allows users to wrap native tokens or auto-select the native token when they have more native than wrapped balance. The old NativeTokenBalanceWrapper explicitly fetched the native balance using useGetBalanceOf, but this was removed in the refactor.

Impact

  • Swap and repay upgrades appear functionally correct for the happy path
  • Native token wrap/unwrap functionality is completely broken
  • Tests mock the native token balance, so they pass, but production will fail

Confidence Score: 1/5

  • Not safe to merge - contains critical bug that breaks native token wrap/unwrap feature
  • Score of 1 due to critical logic bug where native token balances are never fetched, completely breaking the wrap/unwrap native token feature. While the core SwapRouterV2 upgrade appears sound, the removal of NativeTokenBalanceWrapper without proper replacement breaks existing functionality. Tests pass because they mock the data, but production will fail.
  • Critical attention needed on useGetSwapTokenUserBalances/index.ts and useGetOperationFormTokenBalances/index.ts to restore native token balance fetching

Important Files Changed

Filename Overview
apps/evm/src/hooks/useGetSwapTokenUserBalances/index.ts Critical bug: never returns native token balances, breaking wrap/unwrap feature
apps/evm/src/pages/Market/OperationForm/useGetOperationFormTokenBalances/index.ts Relies on broken hook, userWalletNativeTokenBalanceTokens always undefined
apps/evm/src/clients/api/mutations/useSwapTokensAndRepay/index.ts Upgraded to SwapRouterV2, simplified from 9 to 4 function variants
apps/evm/src/pages/Market/OperationForm/Repay/RepayWithWalletBalanceForm/index.tsx Refactored to use new token balance hook, but native token balance logic broken
apps/evm/src/pages/Market/OperationForm/SupplyForm/index.tsx Removed NativeTokenBalanceWrapper, relies on broken useGetOperationFormTokenBalances

Last reviewed commit: d811401

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

58 files reviewed, 9 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +110 to +121
// DEV ONLY
const ts = (Math.floor(Date.now() / 1000) + 100).toString(16);
await fetch('https://virtual.binance.eu.rpc.tenderly.co/a18c3519-9972-46ff-9d01-5b2f83a992e2', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
id: 1,
jsonrpc: '2.0',
method: 'tenderly_setNextBlockTimestamp',
params: [`0x${ts}`],
}),
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

DEV ONLY code must be removed before merging to production. This introduces a hardcoded Tenderly RPC call that manipulates block timestamps.

Suggested change
// DEV ONLY
const ts = (Math.floor(Date.now() / 1000) + 100).toString(16);
await fetch('https://virtual.binance.eu.rpc.tenderly.co/a18c3519-9972-46ff-9d01-5b2f83a992e2', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
id: 1,
jsonrpc: '2.0',
method: 'tenderly_setNextBlockTimestamp',
params: [`0x${ts}`],
}),
});
if (!gasless) {
// Estimate gas limit

Comment on lines +8 to +11
iconSrc: iconSrcs.bsc,
explorerUrl: 'https://bscscan.com',
// explorerUrl: 'https://bscscan.com',
explorerUrl:
'https://dashboard.tenderly.co/venus-labs/project/testnet/43b649f5-b426-44f5-8052-c7836bdb67f5',
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Production BSCScan explorer URL commented out in favor of Tenderly dashboard. Revert to production configuration before merging.

Suggested change
iconSrc: iconSrcs.bsc,
explorerUrl: 'https://bscscan.com',
// explorerUrl: 'https://bscscan.com',
explorerUrl:
'https://dashboard.tenderly.co/venus-labs/project/testnet/43b649f5-b426-44f5-8052-c7836bdb67f5',
explorerUrl: 'https://bscscan.com',

Comment on lines +13 to +16
[ChainId.BSC_MAINNET]: [
`https://bsc-mainnet.nodereal.io/v1/${nodeRealApiKey}`,
`https://bnb-mainnet.g.alchemy.com/v2/${alchemyApiKey}`,
// `https://bsc-mainnet.nodereal.io/v1/${nodeRealApiKey}`,
// `https://bnb-mainnet.g.alchemy.com/v2/${alchemyApiKey}`,
'https://virtual.binance.eu.rpc.tenderly.co/0acab753-b3d0-4fa6-91f8-8ca1578a00e3',
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Production RPC URLs (NodeReal, Alchemy) replaced with Tenderly virtual testnet. Must revert to production endpoints before merging.

Suggested change
[ChainId.BSC_MAINNET]: [
`https://bsc-mainnet.nodereal.io/v1/${nodeRealApiKey}`,
`https://bnb-mainnet.g.alchemy.com/v2/${alchemyApiKey}`,
// `https://bsc-mainnet.nodereal.io/v1/${nodeRealApiKey}`,
// `https://bnb-mainnet.g.alchemy.com/v2/${alchemyApiKey}`,
'https://virtual.binance.eu.rpc.tenderly.co/0acab753-b3d0-4fa6-91f8-8ca1578a00e3',
`https://bsc-mainnet.nodereal.io/v1/${nodeRealApiKey}`,
`https://bnb-mainnet.g.alchemy.com/v2/${alchemyApiKey}`,

@therealemjy
Copy link
Copy Markdown
Member

@greptile

Comment thread apps/evm/src/hooks/useGetSwapTokenUserBalances/index.ts Outdated
@therealemjy
Copy link
Copy Markdown
Member

@greptile

Comment thread apps/evm/src/pages/Market/OperationForm/useCommonValidation/index.ts Outdated
Comment thread apps/evm/src/pages/Market/OperationForm/useCommonValidation/index.ts Outdated
Comment thread apps/evm/src/libs/tokens/infos/disabledTokenActions/bscMainnet.ts
@therealemjy
Copy link
Copy Markdown
Member

@greptile

Comment thread apps/evm/src/hooks/useGetSwapTokenUserBalances/index.ts
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.

2 participants