Skip to content

Conversation

@shinchann221
Copy link
Contributor

@shinchann221 shinchann221 commented Dec 30, 2025

Add Midas Vault Integration Module

Summary

Adds MidasModule to enable EtherFi Safes to interact with Midas Liquid Reserve Vaults. Supports multiple vaults, depositing USDC/USDT to mint Midas tokens, instant withdrawals, and async withdrawals via Cash Module integration.

Changes

  • MidasModule.sol: Module contract supporting multiple Midas vaults with:

    • Deposit/withdraw operations for any configured Midas token
    • Admin functions to add/remove vaults and supported assets (requires MIDAS_MODULE_ADMIN role)
    • Signature-based authorization for all operations
    • Dynamic decimal scaling between assets
    • Async withdrawal integration with Cash Module
    • Reentrancy protection
  • IMidasVault.sol: Interface for Midas Vault operations (depositInstant, redeemInstant, redeemRequest)

  • DeployMidasModule.s.sol: Deployment script that configures module, price oracle, collateral settings (90% LTV, 95% liquidation threshold), and withdrawable assets

  • scripts/gnosis-txs/DeployMidasModule.s.sol: Gnosis Safe deployment script for Midas module

  • scripts/gnosis-txs/SetMidasConfig.s.sol: Gnosis Safe configuration script that sets up module permissions, price oracle, collateral/borrow config, and withdrawable assets

  • MidasModule.t.sol: Comprehensive test suite covering deposits, withdrawals, async flows, multi-vault scenarios, and error cases

Files Changed

  • src/modules/midas/MidasModule.sol (new)
  • src/interfaces/IMidasVault.sol (new)
  • scripts/DeployMidasModule.s.sol (new)
  • scripts/gnosis-txs/DeployMidasModule.s.sol (new)
  • scripts/gnosis-txs/SetMidasConfig.s.sol (new)
  • test/safe/modules/midas/MidasModule.t.sol (new)
  • remappings.txt (new)
  • deployments/dev/534352/deployments.json (modified)
  • foundry.toml (modified)

Copy link

@certora-run certora-run bot left a comment

Choose a reason for hiding this comment

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

Verification Results

  • Group ID: 6b7fb3fe-6efa-454d-bbc5-7e6c6bba3a6c
Job Result VERIFIED Link
EtherFiSafe.conf 0 Link
CashModuleCore.conf --rule "p03" 2 Link

//price provider set oracle
PriceProvider(priceProvider).setTokenConfig(tokens, midasConfigs);

IDebtManager.CollateralTokenConfig memory collateralConfig = IDebtManager.CollateralTokenConfig({ ltv: 90e18, liquidationThreshold: 95e18, liquidationBonus: 1e18 });
Copy link
Contributor

Choose a reason for hiding this comment

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

Check with Chaos for config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've put a message

@shinchann221 shinchann221 marked this pull request as ready for review January 2, 2026 21:13
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e8c8f91ba9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link

@certora-run certora-run bot left a comment

Choose a reason for hiding this comment

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

Verification Results

  • Group ID: 7b72f814-7c25-46ab-803f-745badff75e9
Job Result VERIFIED Link
EtherFiSafe.conf 14 Link
CashModuleCore.conf --rule "p03" 2 Link

Copy link

@certora-run certora-run bot left a comment

Choose a reason for hiding this comment

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

Verification Results

  • Group ID: 959d9742-ce99-4b04-a528-fa4afb0d59ae
Job Result VERIFIED Link
EtherFiSafe.conf 0 Link
CashModuleCore.conf --rule "p03" 2 Link

Copy link

@certora-run certora-run bot left a comment

Choose a reason for hiding this comment

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

Verification Results

  • Group ID: 464c73b1-15d7-4501-a6f6-287a6b2bd103
Job Result VERIFIED Link
EtherFiSafe.conf 14 Link
CashModuleCore.conf --rule "p03" 2 Link

@shinchann221
Copy link
Contributor Author

Audit Changes - MidasModule

Commit: 9daccfb - feat: changed withdraw implementation and fixed audit issues

Summary

This commit simplifies the MidasModule by removing the async withdrawal flow and switching to a direct async withdrawal request pattern. The module now directly calls redeemRequest on the Midas vault instead of managing withdrawal state internally.


Major Changes

1. Withdrawal Implementation Simplified

Removed Functions:

  • requestWithdrawal() - Removed async withdrawal request function
  • executeWithdraw() - Removed async withdrawal execution function
  • getPendingWithdrawal() - Removed function to retrieve pending withdrawals
  • _requestAsyncWithdraw() - Removed internal async withdrawal request logic
  • _executeWithdraw() - Removed internal async withdrawal execution logic
  • _getRequestWithdrawDigestHash() - Removed digest hash function for async withdrawals

Modified Function:

  • withdraw() - Now directly calls redeemRequest instead of redeemInstant
    • Removed parameter: minReceiveAmount (uint256)
    • Changed behavior: Creates async withdrawal request via IMidasVault.redeemRequest() instead of synchronous redeemInstant()
    • Updated documentation: Clarifies that withdrawal completion is handled by the Midas vault

Impact:

  • Withdrawals are now fully async - the Midas vault handles completion
  • No internal state tracking for pending withdrawals
  • No integration with CashModule's withdrawal delay system
  • Simpler codebase with reduced attack surface

2. Removed State Variables and Structs

  • Removed: AsyncWithdrawal struct
  • Removed: withdrawals mapping (tracked pending withdrawals per Safe)
  • Removed: REQUEST_WITHDRAW_SIG constant

3. Removed Errors

  • NoWithdrawalQueued() - No longer needed without async withdrawal tracking
  • CannotFindMatchingWithdrawalForSafe() - No longer needed without async withdrawal tracking
  • UnsupportedAsset() - Was defined but never used

4. Added Error

  • InvalidDecimals() - Added validation in _scaleAmount() to ensure token decimals don't exceed 18

5. Event Changes

Removed Events:

  • WithdrawalRequested(address indexed safe, uint256 amount, address asset, address midasToken)
  • WithdrawalExecuted(address indexed safe, uint256 amount, address asset, address midasToken)

Modified Event:

  • Withdrawal - Changed signature from:
    // Old
    event Withdrawal(address indexed safe, address indexed inputToken, uint256 inputAmount, address indexed outputToken, uint256 outputAmount);
    
    // New
    event Withdrawal(address indexed safe, uint256 amount, address asset, address midasToken);

6. Code Quality Improvements

Removed Unused Imports:

  • WithdrawalRequest from ICashModule.sol
  • SafeCast usage (import remains but using statement removed)

Documentation Updates:

  • Updated withdraw() documentation to clarify async behavior
  • Removed references to UnsupportedAsset error
  • Fixed parameter documentation in _deposit() (clarified amount is in asset decimals, not midasToken decimals)
  • Added @custom:throws InvalidDecimals documentation

Constructor Changes:

  • Removed redundant _etherFiDataProvider == address(0) check (already handled by ModuleBase)

Testing Updates

All test cases related to async withdrawal flows have been removed:

  • test_requestWithdrawAndExecuteWithdraw_success
  • test_requestWithdrawal_createsWithdrawal
  • test_requestWithdrawal_executesWithdrawal_whenTheWithdrawDelayIsZero
  • test_executeWithdrawal_reverts_ifWithdrawalDelayIsNotOver
  • test_executeWithdrawal_reverts_whenNoWithdrawalQueued
  • test_requestWithdrawal_insufficientAmount
  • test_requestAsyncWithdrawal_invalidInput
  • test_requestWithdrawal_revertsWithUnsupportedMidasToken
  • test_getPendingWithdrawal_returnsCorrectData
  • test_getPendingWithdrawal_returnsEmptyWhenNoWithdrawal

All withdraw() tests updated to:

  • Remove minReceiveAmount parameter
  • Update event expectations
  • Remove return amount assertions (async completion handled by vault)

Files Changed

  1. src/modules/midas/MidasModule.sol - Core implementation changes
  2. test/safe/modules/midas/MidasModule.t.sol - Test updates to match new implementation

Copy link

@certora-run certora-run bot left a comment

Choose a reason for hiding this comment

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

Verification Results

  • Group ID: 9b30e6fe-5111-4e6b-91ac-05a7795d4476
Job Result VERIFIED Link
EtherFiSafe.conf 14 Link
CashModuleCore.conf --rule "p03" 2 Link

Copy link

@certora-run certora-run bot left a comment

Choose a reason for hiding this comment

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

Verification Results

  • Group ID: 0bee659b-a8ee-4ae4-a785-4246bf2bc90e
Job Result VERIFIED Link
EtherFiSafe.conf 14 Link
CashModuleCore.conf --rule "p03" 2 Link

Copy link

@certora-run certora-run bot left a comment

Choose a reason for hiding this comment

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

Verification Results

  • Group ID: caa39c34-e1e3-472a-aa6c-bfe22cb85f92
  • Commit: 4bea39a
Job Result VERIFIED Link
EtherFiSafe.conf 14 Link
CashModuleCore.conf --rule "p03" 2 Link

Copy link

@certora-run certora-run bot left a comment

Choose a reason for hiding this comment

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

Verification Results

  • Group ID: a5c2a7b5-88aa-44be-af79-ff378d8a4362
  • Commit: 5add4bc
Job Result VERIFIED Link
EtherFiSafe.conf 14 Link
CashModuleCore.conf --rule "p03" 2 Link

Copy link

@certora-run certora-run bot left a comment

Choose a reason for hiding this comment

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

Verification Results

  • Group ID: 3b385b85-1663-4a4e-abb3-599d5ecc5f6b
  • Commit: bcc68a4
Job Result VERIFIED Link
EtherFiSafe.conf 14 Link
CashModuleCore.conf --rule "p03" 2 Link

Copy link

@certora-run certora-run bot left a comment

Choose a reason for hiding this comment

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

Verification Results

  • Group ID: 97739c3d-c347-481f-8609-db31c6d2f3ff
  • Commit: 0e43e58
Job Result VERIFIED Link
EtherFiSafe.conf 14 Link
CashModuleCore.conf --rule "p03" 2 Link

Copy link

@certora-run certora-run bot left a comment

Choose a reason for hiding this comment

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

Verification Results

  • Group ID: 881355cf-d842-4dec-b3d9-dab1960cc5dd
  • Commit: 17031fe
Job Result VERIFIED Link
EtherFiSafe.conf 14 Link
CashModuleCore.conf --rule "p03" 2 Link

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.

3 participants