Skip to content

feat: legacy vaults migration#261

Open
bergusman wants to merge 16 commits intomainfrom
legacy-vaults-migration
Open

feat: legacy vaults migration#261
bergusman wants to merge 16 commits intomainfrom
legacy-vaults-migration

Conversation

@bergusman
Copy link

@bergusman bergusman commented Feb 11, 2026

This PR introduces two new transaction types for WLD and USD vaults migration to ERC4626 vaults.

@bergusman bergusman marked this pull request as ready for review February 17, 2026 08:04
@bergusman bergusman requested a review from Dzejkop as a code owner February 17, 2026 08:04
jamierumbelow
jamierumbelow previously approved these changes Feb 17, 2026
@karankurbur
Copy link
Collaborator

lets make some variable namings clearer - use legacy_wld_vault and legacy_usd_vault to distinguish from the 4626 vaults. gets hard to keep track

Copy link
Contributor

@thomas-waite thomas-waite left a comment

Choose a reason for hiding this comment

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

  1. UsdVault::migrate seems to have a permit2 allowance call on the wrong token, or isn't converting units correctly
  2. WldVault::migrate doesn't seem to account for the user earning interest on their legacy vault position, and will underfund the deposit into Morpho, resulting in WLD left over in their wallet
  3. UsdVault::migrate has zero slippage tolerance on the redeemSDAICall. A small exchange rate difference in the time this takes to go on chain will result in it reverting
  4. fetch_sdai_balance in transaction_usd_vault_migrate seems to be fetching the sdai balance on the wrong thing (user wallet, not their sDAI balance in the vault)

Less concerning:

  1. We don't need network passing, everything is deployed on worldchain?
  2. Need more docs and better naming throughout. Use legacy to refer to the old vaults so we don't get mixed up with Morpho
  3. Hardcode more addresses - there's only one WLD vault on Morpho for example - so client doesn't need to find all the addresses. Where would it get them from?

Copy link
Contributor

@thomas-waite thomas-waite left a comment

Choose a reason for hiding this comment

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

Tests need to be more thorough with negative test cases added

let morpho_shares_after = morpho_vault.balanceOf(safe_address).call().await?;
println!("MorphoVault shares after migration: {morpho_shares_after}");

assert!(
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests are a start, but they need to be way, way more thorough. They only test the main happy path.

We need negative test cases: test what happens if a user with zero balance in the vaults attempts a migration, test an asset/vault mismatch (attempting to migrate WLD to the USDC Morpho vault), test trying to migrate more than the user has in the legacy vault etc.

/// ERC-20 approve for Permit2 contract
Permit2Approve = 138,
/// WLD Vault migration to ERC-4626 vault
WLDVaultMigration = 139,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
WLDVaultMigration = 139,
WldVaultMigration = 139,

nit. rust convention

Ok(())
}

pub async fn set_erc20_balance_with_slot<P>(
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems quite useful, there were other places where we where doing this operation, perhaps worth updating it to use the same helper tool?

Copy link
Author

Choose a reason for hiding this comment

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

We already have set_erc20_balance_for_safe but it is tied to slot 0 for example for USDC is not 0 slot


/// Permit2 data for secure token transfers.
#[derive(Debug, Clone)]
pub struct Permit2Data {
Copy link
Contributor

Choose a reason for hiding this comment

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

don't we already have a permit2 module with the relevant definitions?

Copy link
Author

Choose a reason for hiding this comment

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

We not have permit2 structure with signature, I composed it together because we have some clippy function arguments limitation


/// Represents a USD Vault migration transaction bundle.
#[derive(Debug)]
pub struct UsdLegacyVault {
Copy link
Contributor

Choose a reason for hiding this comment

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

This struct seems the same as a transaction, do we need another definition?

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.

5 participants

Comments