Skip to content

feat: implement multi-asset collateral support#111

Merged
Smartdevs17 merged 7 commits intoSmartdevs17:mainfrom
olathedev:feat/issue-86-multi-asset-collateral
Mar 24, 2026
Merged

feat: implement multi-asset collateral support#111
Smartdevs17 merged 7 commits intoSmartdevs17:mainfrom
olathedev:feat/issue-86-multi-asset-collateral

Conversation

@olathedev
Copy link
Copy Markdown
Contributor

Summary

Closes #86

  • Per-asset collateral tracking: Added UserAssetCollateral(user, asset) and UserAssetList(user) storage keys to track each asset independently alongside the existing aggregate CollateralBalance
  • Multi-collateral module: New multi_collateral.rs with get_user_asset_collateral, get_user_asset_list, calculate_total_collateral_value (oracle-priced, collateral-factor weighted), and has_multi_asset_collateral
  • Health factor integration: borrow.rs and liquidate.rs now branch on has_multi_asset_collateral — multi-asset users get oracle-priced total collateral value; legacy single-asset users retain existing aggregate path
  • Backward compatibility: Aggregate CollateralBalance(user) is always maintained so existing single-asset users are unaffected
  • Public API: get_user_asset_collateral, get_user_asset_list, get_user_total_collateral_value exposed on HelloContract

Test plan

  • 15 new tests in multi_collateral_test.rs covering: per-asset deposit/withdrawal tracking, asset list deduplication and cleanup, total collateral value with collateral factors, borrow health factor with multi-asset collateral, user isolation
  • Full test suite (51 tests) passes: cargo test

- Add UserAssetCollateral(user, asset) and UserAssetList(user) storage keys to DepositDataKey
- Add record_asset_deposit and record_asset_withdrawal helpers in deposit.rs
- Update deposit_collateral to track per-asset balances alongside aggregate balance
- Update withdraw_collateral to update per-asset records on each withdrawal
- Add multi_collateral.rs module with get_user_asset_collateral, get_user_asset_list,
  calculate_total_collateral_value (oracle-priced, collateral-factor weighted), and
  has_multi_asset_collateral helpers
- Update borrow.rs health factor check to use oracle-priced total for multi-asset users
- Update liquidate.rs to use per-asset collateral records and oracle-priced total for check
- Expose get_user_asset_collateral, get_user_asset_list, get_user_total_collateral_value
  on HelloContract in lib.rs
- Add comprehensive multi_collateral_test.rs covering per-asset tracking, asset list
  management, withdrawal updates, total collateral value calculation, and borrow health
- Maintain full backward compatibility: aggregate CollateralBalance always updated
- Guard token transfer calls with #[cfg(not(test))] in deposit.rs and withdraw.rs
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 24, 2026

@olathedev is attempting to deploy a commit to the smartdevs17's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 24, 2026

@olathedev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Smartdevs17
Copy link
Copy Markdown
Owner

fix conflicts

olathedev and others added 6 commits March 24, 2026 12:17
…collateral

- Resolved lib.rs conflict: kept both treasury (Smartdevs17#101) and multi-asset collateral (Smartdevs17#86) sections
- Fixed auto-merge duplicate enum variants in oracle.rs (PrimaryOracle, FallbackFeed)
- Fixed auto-merge duplicate enum variant in storage.rs (MultisigAdmins)
- Fixed duplicate imports in multisig.rs (GovernanceError, Proposal types)
- Added missing imports in governance.rs (ProposalCreatedEvent, ProposalExecutedEvent,
  ProposalFailedEvent, MIN_TIMELOCK_DELAY, risk_params, risk_management, interest_rate)
@Smartdevs17 Smartdevs17 merged commit 620bbcf into Smartdevs17:main Mar 24, 2026
4 of 7 checks passed
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.

Feature: Add multi-asset collateral support to smart contracts

2 participants