Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"contracts/strategies/CharmStrategyUSD1.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ISwapRouter } from "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
import { IStrategy } from "../interfaces/IStrategy.sol";
/**
* @title CharmStrategyUSD1
* @notice Production-ready strategy for Charm Finance USD1/WLFI Alpha Vault
*
* @dev SPECIFIC CONFIGURATION:
* Pool: USD1/WLFI Uniswap V3
* Fee Tier: 1% (10000)
* Network: Ethereum Mainnet
* Charm Vault: 0x22828Dbf15f5FBa2394Ba7Cf8fA9A96BdB444B71
*
* @dev STRATEGY FEATURES:
* ✅ Smart auto-rebalancing (matches Charm's ratio before deposit)
* ✅ Uniswap V3 integration for swaps (USD1 ↔ WLFI)
* ✅ Works with existing Charm USD1/WLFI vault
* ✅ Returns unused tokens to vault
* ✅ Comprehensive slippage protection
* ✅ Security: onlyVault modifier + reentrancy guards
* ✅ Accounts for idle tokens (no waste!)
*
* @dev FLOW:
* 1. Receive USD1 + WLFI from EagleOVault
* 2. Check Charm vault's current ratio (e.g., 20% USD1 / 80% WLFI)
* 3. Auto-swap tokens to match that exact ratio
* 4. Deposit matched amounts to Charm
* 5. Return any unused tokens to vault
* 6. Receive Charm LP shares (held by strategy, earning fees)
*
* @dev SIMPLER than CharmStrategy.sol - NO WETH conversion needed!
* This vault uses USD1/WLFI directly (both are vault's native tokens)
*/
interface ICharmVault {
// Charm AlphaProVault deposit function (from docs)
function deposit(
uint256 amount0Desired, // USD1
uint256 amount1Desired, // WLFI
uint256 amount0Min,
uint256 amount1Min,
address to
) external returns (uint256 shares, uint256 amount0, uint256 amount1);
function withdraw(
uint256 shares,
uint256 amount0Min,
uint256 amount1Min,
address to
) external returns (uint256 amount0, uint256 amount1);
function getTotalAmounts() external view returns (uint256 total0, uint256 total1);
function balanceOf(address account) external view returns (uint256);
function totalSupply() external view returns (uint256);
function token0() external view returns (address);
function token1() external view returns (address);
}
interface IEagleOVault {
function wlfiPerUsd1() external view returns (uint256);
}
contract CharmStrategyUSD1 is IStrategy, ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
// =================================
// IMMUTABLES
// =================================
address public immutable EAGLE_VAULT;
IERC20 public immutable USD1;
IERC20 public immutable WLFI;
ISwapRouter public immutable UNISWAP_ROUTER;
// =================================
// STATE VARIABLES
// =================================
ICharmVault public charmVault;
bool public active;
uint24 public constant POOL_FEE = 10000; // 1% fee tier (USD1/WLFI pool on Ethereum)
uint256 public maxSlippage = 500; // 5% (configurable by owner)
uint256 public lastRebalance;
// Pool configuration for reference
string public constant POOL_DESCRIPTION = "USD1/WLFI 1%";
address public constant CHARM_VAULT_ADDRESS = 0x22828Dbf15f5FBa2394Ba7Cf8fA9A96BdB444B71;
// =================================
// EVENTS (Additional to IStrategy)
// =================================
event CharmVaultSet(address indexed charmVault);
event TokensSwapped(address indexed tokenIn, address indexed tokenOut, uint256 amountIn, uint256 amountOut);
event UnusedTokensReturned(uint256 usd1Amount, uint256 wlfiAmount);
// =================================
// ERRORS
// =================================
error OnlyVault();
error ZeroAddress();
error NotInitialized();
error StrategyPaused();
error InsufficientBalance();
error SlippageExceeded();
// =================================
// MODIFIERS
// =================================
modifier onlyVault() {
if (msg.sender != EAGLE_VAULT) revert OnlyVault();
_;
}
modifier whenActive() {
if (!active) revert StrategyPaused();
_;
}
// =================================
// CONSTRUCTOR
// =================================
/**
* @notice Creates CharmStrategyUSD1 for USD1/WLFI Charm pool
* @param _vaultAddress EagleOVault address
* @param _charmVault Charm Alpha Vault address (USD1/WLFI)
* @param _wlfi WLFI token address
* @param _usd1 USD1 token address
* @param _uniswapRouter Uniswap V3 SwapRouter address
* @param _owner Strategy owner
*/
constructor(
address _vaultAddress,
address _charmVault,
address _wlfi,
address _usd1,
address _uniswapRouter,
address _owner
) Ownable(_owner) {
if (_vaultAddress == address(0) || _wlfi == address(0) ||
_usd1 == address(0) || _uniswapRouter == address(0)) {
revert ZeroAddress();
}
EAGLE_VAULT = _vaultAddress;
WLFI = IERC20(_wlfi);
USD1 = IERC20(_usd1);
UNISWAP_ROUTER = ISwapRouter(_uniswapRouter);
// Initialize with Charm vault if provided
if (_charmVault != address(0)) {
charmVault = ICharmVault(_charmVault);
active = true;
emit CharmVaultSet(_charmVault);
}
lastRebalance = block.timestamp;
}
// =================================
// INITIALIZATION
// =================================
/**
* @notice Set Charm vault (if not set in constructor)
* @param _charmVault Address of Charm Alpha Vault
*/
function setCharmVault(address _charmVault) external onlyOwner {
if (_charmVault == address(0)) revert ZeroAddress();
charmVault = ICharmVault(_charmVault);
active = true;
emit CharmVaultSet(_charmVault);
}
/**
* @notice Initialize all required approvals for strategy to work
* @dev Call this once after deployment
*/
function initializeApprovals() external onlyOwner {
// Approve Uniswap router for swaps
WLFI.forceApprove(address(UNISWAP_ROUTER), type(uint256).max);
USD1.forceApprove(address(UNISWAP_ROUTER), type(uint256).max);
// Approve Charm vault for deposits
if (address(charmVault) != address(0)) {
WLFI.forceApprove(address(charmVault), type(uint256).max);
USD1.forceApprove(address(charmVault), type(uint256).max);
}
}
// =================================
// STRATEGY FUNCTIONS (IStrategy)
// =================================
/**
* @notice Deposit with smart auto-rebalancing
* @dev Automatically matches Charm vault's current USD1:WLFI ratio
*/
function deposit(uint256 wlfiAmount, uint256 usd1Amount)
external
onlyVault
whenActive
nonReentrant
returns (uint256 shares)
{
if (address(charmVault) == address(0)) revert NotInitialized();
// Try to pull tokens from vault (backward compatible)
// If vault already transferred, this will just be a no-op or small amount
if (wlfiAmount > 0) {
try WLFI.transferFrom(EAGLE_VAULT, address(this), wlfiAmount) {
// Transfer succeeded
} catch {
// Transfer failed - vault might have already sent tokens
}
}
if (usd1Amount > 0) {
try USD1.transferFrom(EAGLE_VAULT, address(this), usd1Amount) {
// Transfer succeeded
} catch {
// Transfer failed - vault might have already sent tokens
}
}
// Check TOTAL tokens available (handles both PUSH and PULL patterns)
uint256 totalWlfi = WLFI.balanceOf(address(this));
uint256 totalUsd1 = USD1.balanceOf(address(this));
// Return early if we got nothing
if (totalWlfi == 0 && totalUsd1 == 0) return 0;
// STEP 1: Get Charm's EXACT ratio to match
(uint256 charmUsd1, uint256 charmWlfi) = charmVault.getTotalAmounts();
uint256 finalUsd1;
uint256 finalWlfi;
if (charmUsd1 > 0 && charmWlfi > 0) {
// STEP 2: Match Charm's TOKEN QUANTITY ratio
// If Charm has 1000 USD1 : 5000 WLFI ratio (1:5)
// For our 100 WLFI, we need: 100 * 1000 / 5000 = 20 USD1
uint256 usd1Needed = (totalWlfi * charmUsd1) / charmWlfi;
if (totalUsd1 >= usd1Needed) {
// We have enough USD1 - use all WLFI
finalWlfi = totalWlfi;
finalUsd1 = usd1Needed;
// Swap excess USD1 → WLFI to maximize capital efficiency
uint256 excessUsd1 = totalUsd1 - usd1Needed;
if (excessUsd1 > 0) {
uint256 moreWlfi = _swapUsd1ToWlfi(excessUsd1);
finalWlfi += moreWlfi;
finalUsd1 = USD1.balanceOf(address(this));
}
} else {
// Not enough USD1 - swap some WLFI → USD1
uint256 usd1Shortfall = usd1Needed - totalUsd1;
// FIX: Use oracle price from vault to determine swap amount
// Get WLFI per USD1 from vault's oracle
uint256 wlfiPer1Usd1 = IEagleOVault(EAGLE_VAULT).wlfiPerUsd1();
// Calculate WLFI to swap based on MARKET PRICE (not Charm's ratio)
// To get X USD1, we need: X * wlfiPer1Usd1 WLFI
uint256 wlfiToSwap = (usd1Shortfall * wlfiPer1Usd1) / 1e18;
if (wlfiToSwap < totalWlfi) {
uint256 moreUsd1 = _swapWlfiToUsd1(wlfiToSwap);
finalUsd1 = totalUsd1 + moreUsd1;
finalWlfi = totalWlfi - wlfiToSwap;
} else {
// Not enough to swap - use what we have
finalUsd1 = totalUsd1;
finalWlfi = totalWlfi;
}
}
} else {
// Charm empty - deposit 1:1 ratio or whatever we have
finalUsd1 = totalUsd1;
finalWlfi = totalWlfi;
}
// Note: Approvals are handled by initializeApprovals() - max approvals set once
// Deposit to Charm - it returns shares and actual amounts used
uint256 amount0Used;
uint256 amount1Used;
(shares, amount0Used, amount1Used) = charmVault.deposit(
finalUsd1,
finalWlfi,
0, // amount0Min
0, // amount1Min
address(this)
);
// Return any unused tokens to vault
{
uint256 leftoverUsd1 = USD1.balanceOf(address(this));
uint256 leftoverWlfi = WLFI.balanceOf(address(this));
if (leftoverUsd1 > 0) {
USD1.safeTransfer(EAGLE_VAULT, leftoverUsd1);
}
if (leftoverWlfi > 0) {
WLFI.safeTransfer(EAGLE_VAULT, leftoverWlfi);
}
if (leftoverUsd1 > 0 || leftoverWlfi > 0) {
emit UnusedTokensReturned(leftoverUsd1, leftoverWlfi);
}
}
// Emit in correct order: (WLFI, USD1, shares)
// Charm returns (shares, amount0=USD1, amount1=WLFI)
emit StrategyDeposit(amount1Used, amount0Used, shares);
}
/**
* @notice Withdraw from Charm vault
* @param value USD value to withdraw (simplified - treats USD1 and WLFI as equal value)
* @return wlfiAmount WLFI withdrawn (FIRST - matches IStrategy interface)
* @return usd1Amount USD1 withdrawn (SECOND - matches IStrategy interface)
* @dev Returns (WLFI, USD1) to match IStrategy interface - CRITICAL ORDER!
*/
function withdraw(uint256 value)
external
onlyVault
nonReentrant
returns (uint256 wlfiAmount, uint256 usd1Amount)
{
if (value == 0) return (0, 0);
if (address(charmVault) == address(0)) return (0, 0);
uint256 ourShares = charmVault.balanceOf(address(this));
if (ourShares == 0) return (0, 0);
// Calculate shares to withdraw
(uint256 totalWlfi, uint256 totalUsd1) = getTotalAmounts();
uint256 totalValue = totalWlfi + totalUsd1; // Simplified: assume 1 USD1 ≈ 1 WLFI value
uint256 sharesToWithdraw;
if (value >= totalValue) {
sharesToWithdraw = ourShares; // Withdraw all
} else {
sharesToWithdraw = (ourShares * value) / totalValue;
}
// Calculate expected amounts for slippage protection
uint256 expectedUsd1 = (totalUsd1 * sharesToWithdraw) / ourShares;
uint256 expectedWlfi = (totalWlfi * sharesToWithdraw) / ourShares;
// Withdraw from Charm
// Charm returns (amount0, amount1) where token0=USD1, token1=WLFI
(usd1Amount, wlfiAmount) = charmVault.withdraw(
sharesToWithdraw,
(expectedUsd1 * (10000 - maxSlippage)) / 10000,
(expectedWlfi * (10000 - maxSlippage)) / 10000,
EAGLE_VAULT // Send directly back to vault
);
// Emit in correct order (shares, wlfi, usd1)
emit StrategyWithdraw(sharesToWithdraw, wlfiAmount, usd1Amount);
}
/**
* @notice Rebalance strategy (Charm handles this internally)
*/
function rebalance() external onlyVault {
if (address(charmVault) == address(0)) return;
(uint256 totalWlfi, uint256 totalUsd1) = getTotalAmounts();
lastRebalance = block.timestamp;
// Emit in correct order (WLFI, USD1)
emit StrategyRebalanced(totalWlfi, totalUsd1);
}
// =================================
// TOKEN SWAP FUNCTIONS
// =================================
/**
* @notice Swap USD1 to WLFI using Uniswap V3
*/
function _swapUsd1ToWlfi(uint256 amountIn) internal returns (uint256 amountOut) {
if (amountIn == 0) return 0;
// Note: Approval already set by initializeApprovals()
ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({
tokenIn: address(USD1),
tokenOut: address(WLFI),
fee: POOL_FEE, // 1% fee tier for USD1/WLFI pool
recipient: address(this),
deadline: block.timestamp,
amountIn: amountIn,
amountOutMinimum: 0, // Accept market rate (Charm will return unused)
sqrtPriceLimitX96: 0
});
amountOut = UNISWAP_ROUTER.exactInputSingle(params);
emit TokensSwapped(address(USD1), address(WLFI), amountIn, amountOut);
}
/**
* @notice Swap WLFI to USD1 using Uniswap V3
*/
function _swapWlfiToUsd1(uint256 amountIn) internal returns (uint256 amountOut) {
if (amountIn == 0) return 0;
// Note: Approval already set by initializeApprovals()
ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({
tokenIn: address(WLFI),
tokenOut: address(USD1),
fee: POOL_FEE, // 1% fee tier for WLFI/USD1 pool
recipient: address(this),
deadline: block.timestamp,
amountIn: amountIn,
amountOutMinimum: 0, // Accept market rate
sqrtPriceLimitX96: 0
});
amountOut = UNISWAP_ROUTER.exactInputSingle(params);
emit TokensSwapped(address(WLFI), address(USD1), amountIn, amountOut);
}
// =================================
// VIEW FUNCTIONS (IStrategy)
// =================================
/**
* @notice Get total amounts managed by strategy (proportional to our shares)
* @dev Returns (WLFI, USD1) to match IStrategy interface - CRITICAL ORDER!
*/
function getTotalAmounts() public view returns (uint256 wlfiAmount, uint256 usd1Amount) {
if (!active || address(charmVault) == address(0)) {
return (0, 0);
}
uint256 ourShares = charmVault.balanceOf(address(this));
if (ourShares == 0) {
return (0, 0);
}
(uint256 totalUsd1, uint256 totalWlfi) = charmVault.getTotalAmounts();
uint256 totalShares = charmVault.totalSupply();
if (totalShares == 0) return (0, 0);
// Calculate our proportional share
// ⚠️ CRITICAL: Return order must match IStrategy interface (WLFI first, USD1 second)
wlfiAmount = (totalWlfi * ourShares) / totalShares;
usd1Amount = (totalUsd1 * ourShares) / totalShares;
}
/**
* @notice Check if strategy is initialized
*/
function isInitialized() external view returns (bool) {
return active && address(charmVault) != address(0);
}
/**
* @notice Get Charm LP share balance
*/
function getShareBalance() external view returns (uint256) {
if (address(charmVault) == address(0)) return 0;
return charmVault.balanceOf(address(this));
}
// =================================
// ADMIN FUNCTIONS
// =================================
/**
* @notice Update strategy parameters
*/
function updateParameters(uint256 _maxSlippage) external onlyOwner {
require(_maxSlippage <= 1000, "Slippage too high"); // Max 10%
maxSlippage = _maxSlippage;
}
/**
* @notice Emergency pause
*/
function pause() external onlyOwner {
active = false;
}
/**
* @notice Resume strategy
*/
function resume() external onlyOwner {
if (address(charmVault) == address(0)) revert NotInitialized();
active = true;
}
/**
* @notice Rescue idle tokens (not in Charm vault)
* @dev Returns any tokens sitting idle in this contract back to vault
*/
function rescueIdleTokens() external onlyVault {
uint256 wlfiBalance = WLFI.balanceOf(address(this));
uint256 usd1Balance = USD1.balanceOf(address(this));
if (wlfiBalance > 0) {
WLFI.safeTransfer(EAGLE_VAULT, wlfiBalance);
}
if (usd1Balance > 0) {
USD1.safeTransfer(EAGLE_VAULT, usd1Balance);
}
if (wlfiBalance > 0 || usd1Balance > 0) {
emit UnusedTokensReturned(usd1Balance, wlfiBalance);
}
}
/**
* @notice Emergency token recovery (owner only)
*/
function rescueToken(address token, uint256 amount, address to) external onlyOwner {
if (to == address(0)) revert ZeroAddress();
IERC20(token).safeTransfer(to, amount);
}
/**
* @notice Set token approval (owner only) - for fixing approval issues
*/
function setTokenApproval(address token, address spender, uint256 amount) external onlyOwner {
IERC20(token).forceApprove(spender, amount);
}
}
"
},
"node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
"
},
"node_modules/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}
"
},
"node_modules/@openzeppelin/contracts/utils/ReentrancyGuard.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
"
},
"node_modules/@openzeppelin/contracts/access/Ownable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
"
},
"node_modules/@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol": {
"content": "// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;
import '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol';
/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter is IUniswapV3SwapCallback {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
/// @notice Swaps `amountIn` of one token for as much as possible of another token
/// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
/// @return amountOut The amount of the received token
function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);
struct ExactInputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
}
/// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
/// @return amountOut The amount of the received token
function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);
struct ExactOutputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
uint160 sqrtPriceLimitX96;
}
/// @notice Swaps as little as possible of one token for `amountOut` of another token
/// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
/// @return amountIn The amount of the input token
function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);
struct ExactOutputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
}
/// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
/// @return amountIn The amount of the input token
function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}
"
},
"contracts/interfaces/IStrategy.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
/**
* @title IStrategy
* @notice Interface for yield-generating strategies that can be used by EagleOVault
* @dev All strategies must implement this interface for standardized integration
*/
interface IStrategy {
// =================================
// VIEW FUNCTIONS
// =================================
/**
* @notice Get strategy's total value in underlying tokens
* @return wlfiAmount Total WLFI managed by strategy
* @return usd1Amount Total USD1 managed by strategy
*/
function getTotalAmounts() external view returns (uint256 wlfiAmount, uint256 usd1Amount);
/**
* @notice Check if strategy is active and ready for operations
* @return True if strategy is active
*/
function isInitialized() external view returns (bool);
// =================================
// STRATEGY OPERATIONS
// =================================
/**
* @notice Deposit tokens into the strategy
* @param wlfiAmount Amount of WLFI to deposit
* @param usd1Amount Amount of USD1 to deposit
* @return shares Strategy-specific shares or receipt tokens (if any)
*/
function deposit(uint256 wlfiAmount, uint256 usd1Amount) external returns (uint256 shares);
/**
* @notice Withdraw tokens from the strategy
* @param shares Amount of strategy shares to withdraw (or proportional amount)
* @return wlfiAmount Amount of WLFI withdrawn
* @return usd1Amount Amount of USD1 withdrawn
*/
function withdraw(uint256 shares) external returns (uint256 wlfiAmount, uint256 usd1Amount);
/**
* @notice Rebalance the strategy position if needed
*/
function rebalance() external;
// =================================
// EVENTS
// =================================
event StrategyDeposit(uint256 wlfiAmount, uint256 usd1Amount, uint256 shares);
event StrategyWithdraw(uint256 shares, uint256 wlfiAmount, uint256 usd1Amount);
event StrategyRebalanced(uint256 newTotal0, uint256 newTotal1);
}
"
},
"node_modules/@openzeppelin/contracts/interfaces/IERC1363.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)
pragma solidity >=0.6.2;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
"
},
"node_modules/@openzeppelin/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
"
},
"node_modules/@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol": {
"content": "// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
/// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
/// @dev In the implementation you must pay the pool tokens owed for the swap.
/// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
/// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
/// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
/// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
/// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
/// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
/// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
function uniswapV3SwapCallback(
int256 amount0Delta,
int256 amount1Delta,
bytes calldata data
) external;
}
"
},
"node_modules/@openzeppelin/contracts/interfaces/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)
pragma solidity >=0.4.16;
import {IERC20} from "../token/ERC20/IERC20.sol";
"
},
"node_modules/@openzeppelin/contracts/interfaces/IERC165.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)
pragma solidity >=0.4.16;
import {IERC165} from "../utils/introspection/IERC165.sol";
"
},
"node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
"
}
},
"settings": {
"remappings": [
"@openzeppelin/=node_modules/@openzeppelin/",
"@uniswap/=node_modules/@uniswap/",
"@layerzerolabs/=node_modules/@layerzerolabs/",
"base64-sol/=node_modules/base64-sol/",
"eth-gas-reporter/=node_modules/eth-gas-reporter/",
"forge-std/=lib/forge-std/src/",
"hardhat-deploy/=node_modules/hardhat-deploy/",
"hardhat/=node_modules/hardhat/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "paris",
"viaIR": true
}
}}
Submitted on: 2025-10-29 16:52:00
Comments
Log in to comment.
No comments yet.