Feat/card borrow mode - #1285
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
Code Review: PR #1285 - Card Borrow Mode FeatureThank you for this substantial feature addition! This PR implements borrowing against soUSD collateral via Aave V3. While the implementation shows good architectural patterns, there are several critical security and financial safety issues that must be addressed before merging. 🔴 Critical Issues (Must Fix)1. LTV Ratio Mismatch and HardcodingFile: const soUSDLTV = 79n; // 80% LTV for soUSD (79% to avoid rounding errors)Issues:
Recommendation: Fetch LTV from Aave's pool configuration contract instead of hardcoding. If hardcoding is necessary for performance, add comprehensive documentation and consider periodic validation. 2. Dangerous Default Slippage (5%)File: const dstAmountMin = (borrowAmountWei * 95n) / 100n; // 5% slippageIssues:
Recommendation:
3. Race Condition in Collateral CalculationFile: const rate = await readContract(publicClient(mainnet.id), {
address: ADDRESSES.ethereum.accountant,
abi: ACCOUNTANT_ABI,
functionName: 'getRate',
});
// ... calculations ...
// ... later transaction executionIssues:
Recommendation:
4. Missing Health Factor ValidationFile: const requiredCollateralValueWei =
remainingBorrowWei === 0n
? 0n
: (remainingBorrowWei * TARGET_HEALTH_FACTOR_BPS + (LIQ_THRESHOLD_BPS - 1n)) /
LIQ_THRESHOLD_BPS;Issues:
Recommendation:
5. No Health Factor DisplayMissing: UI doesn't show health factor anywhere Issues:
Recommendation:
6. Uncapped Borrow AmountFile: const maxBorrowAmount = useMemo(() => {
if (soUsdBalanceAmount > 0 && exchangeRate > 0) {
return soUsdBalanceAmount * exchangeRate * 0.8; // 70% of savings value
}
return 0;
}, [soUsdBalanceAmount, exchangeRate]);Issues:
Recommendation:
🟡 High Priority Issues7. Missing Bridge Failure HandlingFile: Issues:
Recommendation:
8. Transaction Atomicity RiskFile: const transactions = [
{ to: ADDRESSES.fuse.vault, data: supplyApproveCalldata },
{ to: ADDRESSES.fuse.aaveV3Pool, data: supplyCalldata },
{ to: ADDRESSES.fuse.aaveV3Pool, data: borrowCalldata },
{ to: USDC_STARGATE, data: approveUSDCCalldata },
{ to: ADDRESSES.fuse.bridgePaymasterAddress, ... },
];Issues:
Recommendation:
9. No Gas EstimationFile: All transaction hooks Issues:
Recommendation:
10. Missing Input ValidationFile: Issues:
Recommendation: .refine(val => Number(val) < Number.MAX_SAFE_INTEGER, {
error: 'Amount too large'
})
.refine(val => {
const decimals = val.split('.')[1]?.length || 0;
return decimals <= 6;
}, {
error: 'USDC supports maximum 6 decimal places'
})
.refine(val => Number(val) >= 0.01, {
error: 'Minimum repay amount is 0.01 USDC'
})🟠 Medium Priority Issues11. Performance: Excessive Re-rendersFile: Issues:
Recommendation:
12. Inconsistent Error HandlingFile: } catch (error) {
setRepayStatus(Status.ERROR);
Toast.show({
type: 'error',
text1: 'Repay failed',
text2: 'Please try again or check your wallet balance',
});
}Issues:
Recommendation:
13. TypeScript: Any TypesFile: const onSubmit = async (data: any) => {Issue: Using Recommendation: const onSubmit = async (data: FormData) => {14. Accessibility MissingFile: Multiple components Issues:
Recommendation: <Pressable
onPress={handlePress}
accessibilityRole="button"
accessibilityLabel="Repay borrowed amount"
accessibilityHint="Opens modal to repay your borrowed USDC"
>15. Magic Numbers and DocumentationFile: const soUSDLTV = 79n;Issues:
Recommendation: Add comprehensive inline documentation explaining financial calculations ✅ Positive Observations
📋 Testing RequirementsBefore merging, please add:
📚 Documentation NeedsPlease add:
SummaryThis is a well-structured feature implementation, but it handles real user funds in a DeFi lending protocol. The critical issues above must be addressed before merging to prevent:
Please prioritize the 🔴 Critical Issues, as they present real financial risks to users. The 🟡 High Priority issues should also be addressed to ensure robust production operation. Happy to discuss any of these points further. Great work on the overall architecture! |
No description provided.