MangroveVaultV2 is a sophisticated DeFi vault that enables users to deposit funds and participate in automated market making through Kandel strategies on the Mangrove decentralized exchange.
Mangrove Vault v2 is a vault that enables people to deposit funds in a vault that manages a Kandel position on Mangrove. Kandel is an Automated Market Maker (AMM) built on top of Mangrove, a CLOB.
- 🏦 ERC20 Vault Token: Users receive transferable shares representing their proportional ownership
- 🤖 Automated Market Making: Manages Kandel strategies for continuous liquidity provision
- 🔮 Oracle Integration: Supports both static and dynamic price oracles with deviation controls
- 🛡️ Security Features: Guardian oversight, timelocks, and whitelisted rebalancing
- 💰 Fee Management: Built-in management fee accrual system
- ⚖️ Rebalancing: Automated portfolio rebalancing through whitelisted protocols
The vault is built using Solady libraries for gas-efficient and secure implementations of:
ERC20
- Token standard implementationFixedPointMathLib
- Precise mathematical operationsSafeTransferLib
- Secure token transfersReentrancyGuardTransient
- Reentrancy protection
MangroveVaultV2 (Main Vault Contract)
├── KandelManagementRebalancing
│ ├── KandelManagement
│ │ └── OracleRange
│ └── ReentrancyGuardTransient
└── ERC20
The main vault contract that combines ERC20 functionality with Kandel strategy management.
Key Functions:
mint()
- Deposit tokens to receive vault sharesburn()
- Redeem shares for underlying tokensgetMintAmounts()
- Calculate optimal deposit amountsfeeData()
- View current fee configuration and pending fees
Manages oracle updates with a timelock mechanism and guardian oversight.
Features:
- Two-step oracle update process (propose → accept)
- Guardian can reject malicious proposals
- Supports both static price values and dynamic oracle feeds
- Configurable timelock periods for security
Key Functions:
proposeOracle()
- Propose new oracle configurationacceptOracle()
- Accept proposal after timelockrejectOracle()
- Guardian can reject proposalsgetCurrentTickInfo()
- Get current price, oracle type, and deviation limits
Manages Kandel market-making strategies with oracle-based position validation.
Features:
- Deploys and manages GeometricKandel instances
- Validates all positions against oracle constraints
- Separates operational control (manager) from governance (owner)
- Tracks funds in vault vs. active in Kandel strategy
Key Functions:
populateFromOffset()
- Deploy Kandel offers with oracle validationretractOffers()
- Remove offers and optionally withdraw fundswithdrawFunds()
- Move funds from Kandel back to vaulttotalBalances()
- View combined vault + Kandel balances
Extends KandelManagement with whitelist functionality for authorized rebalancing operations.
Features:
- Timelock-based address whitelisting system
- Guardian oversight for whitelist proposals
- Secure rebalancing through approved protocols
- Oracle-validated trade execution
Key Functions:
proposeWhitelistAddress()
- Propose address for whitelistingacceptWhitelistAddress()
- Accept after timelock periodrebalance()
- Execute trades through whitelisted protocols
Comprehensive library for oracle data management and price validation.
Features:
- Supports both static and dynamic price oracles
- Multiple validation methods (
accepts()
,withinDeviation()
) - Timelock enforcement for oracle updates
- Gas-optimized packed struct design
Standard interface for external price oracle integration.
MangroveVaultV2.VaultInitParams params = MangroveVaultV2.VaultInitParams({
seeder: kandelSeeder,
base: baseToken,
quote: quoteToken,
tickSpacing: 1,
manager: managerAddress,
managementFee: 200, // 2% annual fee
oracle: initialOracleConfig,
owner: ownerAddress,
guardian: guardianAddress,
name: "Mangrove ETH-USDC Vault",
symbol: "mgvETH-USDC",
decimals: 18,
quoteOffsetDecimals: 6
});
MangroveVaultV2 vault = new MangroveVaultV2(params);
// Deposit tokens and receive vault shares
(uint256 shares, uint256 baseIn, uint256 quoteIn) = vault.mint(
user,
1000e18, // max base tokens
2000e6, // max quote tokens
950e18 // min shares out
);
// Redeem shares for underlying tokens
(uint256 baseOut, uint256 quoteOut) = vault.burn(
user,
recipient,
500e18, // shares to burn
400e18, // min base out
800e6 // min quote out
);
forge build
forge test
forge fmt
forge snapshot
- Guardian System: Multi-signature guardian can reject malicious oracle proposals
- Timelock Mechanisms: All sensitive operations have configurable delays
- Oracle Validation: All trading positions validated against price oracles
- Whitelisted Rebalancing: Only approved protocols can be used for rebalancing
- Reentrancy Protection: Uses Solady's transient reentrancy guard
- Management Separation: Operational control separated from governance
MIT License - see LICENSE for details.