Description:
ERC20 token contract with Factory capabilities. Standard implementation for fungible tokens on Ethereum.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.23;
// lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
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 amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` 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 amount) external returns (bool);
}
// src/interfaces/ICvgCvxStaking.sol
/**
* @title ICvgCvxStaking
* @notice Interface for CVG cvgCVX Staking Position Service
* @dev Contract: 0x2c1D293c50C6d1a4370ebb442A02c5956bbAb119
*/
interface ICvgCvxStaking {
// Enums
enum IN_TOKEN_TYPE {
cvgCVX, // 0
CVX, // 1
CVX1, // 2
ETH // 3
}
enum OUT_TOKEN_TYPE {
cvgCVX, // 0
CVX1, // 1
CVX // 2
}
struct TokenAmount {
IERC20 token;
uint256 amount;
}
// Events
event Deposit(address indexed user, uint256 indexed cycleId, uint256 amount);
event Withdraw(address indexed user, uint256 indexed cycleId, uint256 amount);
// Core functions
function deposit(
uint256 amountIn,
IN_TOKEN_TYPE inTokenType,
uint256 minCvgCvxAmountOut,
uint256 minCvxAmountOut,
bool isLock
) external payable;
function withdraw(
uint256 amount,
OUT_TOKEN_TYPE tokenType,
uint256 minCvx1AmountOut
) external;
function claimCvgRewards(address account) external;
function claimCvgCvxRewards(address account, uint256 minCvgCvxAmountOut, bool isConvert) external;
function claimCvgCvxMultiple(address operator) external returns (uint256, TokenAmount[] memory);
function getAllClaimableAmounts(address account) external view returns (uint256, TokenAmount[] memory);
// State views
function balanceOf(address account) external view returns (uint256);
function stakingCycle() external view returns (uint256);
function depositPaused() external view returns (bool);
// Getters
function cvgCVX() external view returns (address);
function cvx1() external view returns (address);
function CVX() external view returns (address);
}
// src/CVGCVXStrategyTrigger.sol
/**
* @title Custom Strategy Trigger Base
* @author Yearn.finance
*/
abstract contract CustomStrategyTriggerBase {
function reportTrigger(
address _strategy
) external view virtual returns (bool, bytes memory);
}
interface IStrategy {
function isShutdown() external view returns (bool);
function totalAssets() external view returns (uint256);
function lastReport() external view returns (uint256);
function profitMaxUnlockTime() external view returns (uint256);
}
interface IBaseFee {
function basefee_global() external view returns (uint256);
}
interface ICommonReportTrigger {
function baseFeeProvider() external view returns (address);
function acceptableBaseFee() external view returns (uint256);
}
/**
* @title CVGCVXStrategyTrigger
* @notice Custom report trigger for cvgCVX strategy
* @dev Only triggers harvest when claimable rewards exist
* Respects strategy's profitMaxUnlockTime to prevent excessive reporting
* Uses CommonReportTrigger's base fee settings to prevent expensive harvests
*/
contract CVGCVXStrategyTrigger is CustomStrategyTriggerBase {
// CVG staking contract to check claimable rewards
ICvgCvxStaking public constant STAKING = ICvgCvxStaking(0x2c1D293c50C6d1a4370ebb442A02c5956bbAb119);
// Yearn's CommonReportTrigger for base fee checks
ICommonReportTrigger public constant COMMON_TRIGGER = ICommonReportTrigger(0xA045D4dAeA28BA7Bfe234c96eAa03daFae85A147);
/**
* @notice Determines if strategy should report based on claimable rewards
* @param _strategy Address of the cvgCVX strategy
* @return . True if strategy should report
* @return . Encoded call data or reason for not reporting
*/
function reportTrigger(
address _strategy
) external view override returns (bool, bytes memory) {
IStrategy strategy = IStrategy(_strategy);
// Don't report if strategy is shutdown
if (strategy.isShutdown()) {
return (false, bytes("Strategy is shutdown"));
}
// Don't report if no assets deployed
if (strategy.totalAssets() == 0) {
return (false, bytes("No assets deployed"));
}
// Ensure profit unlock time has passed since last report
uint256 timeSinceLastReport = block.timestamp - strategy.lastReport();
if (timeSinceLastReport <= strategy.profitMaxUnlockTime()) {
return (false, bytes("Profit unlock time not reached"));
}
// Check base fee if provider is configured
address baseFeeProvider = COMMON_TRIGGER.baseFeeProvider();
if (baseFeeProvider != address(0)) {
uint256 currentBaseFee = IBaseFee(baseFeeProvider).basefee_global();
uint256 acceptableBaseFee = COMMON_TRIGGER.acceptableBaseFee();
if (currentBaseFee > acceptableBaseFee) {
return (false, bytes("Base fee too high"));
}
}
// Check if there are claimable rewards
(uint256 cvgAmount, ICvgCvxStaking.TokenAmount[] memory cvxRewards) =
STAKING.getAllClaimableAmounts(_strategy);
// Check if cvgCVX rewards exist and are non-zero
bool hasRewards = false;
for (uint256 i = 0; i < cvxRewards.length; i++) {
if (cvxRewards[i].amount > 0) {
hasRewards = true;
break;
}
}
if (!hasRewards && cvgAmount == 0) {
return (false, bytes("No rewards available"));
}
// All checks passed - rewards exist, time to report!
return (true, abi.encodeWithSignature("report()"));
}
}
Submitted on: 2025-10-20 15:29:17
Comments
Log in to comment.
No comments yet.