Skip to content

Multiple Collateral Types & Cross-Asset Operations Testing#165

Merged
UlyanaAndrukhiv merged 23 commits intomainfrom
UlianaAndrukhiv/148-multiple-collateral-testing
Mar 3, 2026
Merged

Multiple Collateral Types & Cross-Asset Operations Testing#165
UlyanaAndrukhiv merged 23 commits intomainfrom
UlianaAndrukhiv/148-multiple-collateral-testing

Conversation

@UlyanaAndrukhiv
Copy link
Contributor

@UlyanaAndrukhiv UlyanaAndrukhiv commented Feb 17, 2026

Closes: #148

Description

Adds comprehensive test coverage for positions using multiple collateral types and cross-asset borrowing.

Tests added (fork_multi_collateral_position_test.cdc)

  • test_multi_collateral_positionFLOW + USDF + WETH collateral; weighted health calculation and max borrow capacity
  • test_cross_asset_flow_to_usdf_borrowing — deposit FLOW, borrow USDF
  • test_cross_asset_flow_usdf_weth_borrowingFLOWUSDFWETH chain; netting when borrowing same token held as collateral
  • test_cross_asset_chain — four-asset path FLOWUSDFWETHWBTC, intermediate assets net to zero
  • test_multi_asset_uncorrelated_price_movementsFLOWprice +10%, USDF price -5%, WETH price +20% simultaneously
  • test_multi_asset_partial_withdrawal — partial withdrawal from multi-asset position; verifies remaining balances
  • test_cross_collateral_borrowing_capacity — borrowing same token as collateral caps at credit amount; different token uses health-based formula
  • test_multi_asset_liquidation_collateral_selection — 3 collateral types + 2 debt types; liquidator selects which collateral to seize
  • test_multi_asset_complex_workflow — full lifecycle with price change and auto-rebalance; verifies exact MOET pushed to drawDownSink and health restored to target health

Refactoring

  • Added manualLiquidation, setupGenericVault, transferFungibleTokens and updated createPosition, borrowFromPosition test helpers
  • Moved create_and_store_pool.cdc to tests/transactions/ folder cause pool setup depends on both mocks

@UlyanaAndrukhiv UlyanaAndrukhiv requested a review from a team as a code owner February 17, 2026 15:36
@UlyanaAndrukhiv UlyanaAndrukhiv self-assigned this Feb 17, 2026
Copy link
Member

@jordanschalm jordanschalm left a comment

Choose a reason for hiding this comment

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

Great work with these.

@vishalchangrani vishalchangrani requested a review from a team February 24, 2026 17:20
@UlyanaAndrukhiv
Copy link
Contributor Author

@Kay-Zee, could you please review this PR when you have a chance? Thank you!

Copy link
Member

@Kay-Zee Kay-Zee left a comment

Choose a reason for hiding this comment

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

This is great! pretty much exactly what i was hoping for.

The later scenarios do get quite complicated, wonder if those might belong more as integration tests. But i think it's fine to keep here for now.

transferFungibleTokens(tokenIdentifier: MAINNET_USDF_TOKEN_ID, from: MAINNET_USDF_HOLDER, to: usdfLp, amount: 1000.0)
createPosition(admin: MAINNET_PROTOCOL_ACCOUNT, signer: usdfLp, amount: 1000.0, vaultStoragePath: MAINNET_USDF_STORAGE_PATH, pushToDrawDownSink: false)

// WETH LP (0.05 WETH available)
Copy link
Member

Choose a reason for hiding this comment

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

i guess we're just using such small values since this is forked mainnet and we don't have that much sitting around in the test accounts? This probably isn't a big deal but yeah, if we did want to increase this i feel like there's probably ways for "add liquidity" to these tests. Anyway, maybe for another time, but if we do want to resolve this, let me know, just ping me the addresses and desired tokens/amounts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Kay-Zee, yes, exactly - I am using small values because this is a forked mainnet, and the accounts are limited by what the largest holders have at that time. I aligned the amounts with the biggest available balances there. If needed, we can later extend this test and recalculate expected values (max borrow and position health) with bigger liquidity.

Would it be okay to merge this PR as is for now?

@UlyanaAndrukhiv UlyanaAndrukhiv merged commit a2e8f2b into main Mar 3, 2026
1 check passed
@UlyanaAndrukhiv UlyanaAndrukhiv deleted the UlianaAndrukhiv/148-multiple-collateral-testing branch March 3, 2026 17:34
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.

Multiple Collateral Types & Cross-Asset Operations Testing

4 participants