文件 1 的 8:Address.sol
pragma solidity ^0.8.0;
library Address {
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly { size := extcodesize(account) }
return size > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 2 的 8:DistributorZaps.sol
pragma solidity 0.8.9;
import "SafeERC20.sol";
import "IStrategyZaps.sol";
import "IGenericDistributor.sol";
contract DistributorZaps {
using SafeERC20 for IERC20;
address public immutable zaps;
address public vault;
IGenericDistributor public distributor;
constructor(
address _strategyZaps,
address _distributor,
address _vault
) {
zaps = _strategyZaps;
distributor = IGenericDistributor(_distributor);
vault = _vault;
}
function setApprovals() external {
IERC20(vault).safeApprove(zaps, 0);
IERC20(vault).safeApprove(zaps, type(uint256).max);
}
function _claim(
uint256 index,
address account,
uint256 amount,
bytes32[] calldata merkleProof
) internal {
distributor.claim(index, account, amount, merkleProof);
IERC20(vault).safeTransferFrom(msg.sender, address(this), amount);
}
function claimFromDistributorAsUnderlying(
uint256 index,
address account,
uint256 amount,
bytes32[] calldata merkleProof,
uint256 assetIndex,
uint256 minAmountOut,
address to
) external returns (uint256) {
_claim(index, account, amount, merkleProof);
return
IStrategyZaps(zaps).claimFromVaultAsUnderlying(
amount,
assetIndex,
minAmountOut,
to
);
}
function claimFromDistributorAsUsdt(
uint256 index,
address account,
uint256 amount,
bytes32[] calldata merkleProof,
uint256 minAmountOut,
address to
) external returns (uint256) {
_claim(index, account, amount, merkleProof);
return
IStrategyZaps(zaps).claimFromVaultAsUsdt(amount, minAmountOut, to);
}
function claimFromDistributorViaUniV2EthPair(
uint256 index,
address account,
uint256 amount,
bytes32[] calldata merkleProof,
uint256 minAmountOut,
address router,
address outputToken,
address to
) external {
_claim(index, account, amount, merkleProof);
IStrategyZaps(zaps).claimFromVaultViaUniV2EthPair(
amount,
minAmountOut,
router,
outputToken,
to
);
}
function claimFromDistributorAsEth(
uint256 index,
address account,
uint256 amount,
bytes32[] calldata merkleProof,
uint256 minAmountOut,
address to
) external {
_claim(index, account, amount, merkleProof);
IStrategyZaps(zaps).claimFromVaultAsEth(amount, minAmountOut, to);
}
function claimFromDistributorAsCvx(
uint256 index,
address account,
uint256 amount,
bytes32[] calldata merkleProof,
uint256 minAmountOut,
address to,
bool lock
) external {
_claim(index, account, amount, merkleProof);
IStrategyZaps(zaps).claimFromVaultAsCvx(amount, minAmountOut, to, lock);
}
}
文件 3 的 8:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 4 的 8:IGenericDistributor.sol
pragma solidity 0.8.9;
interface IGenericDistributor {
function vault() external view returns (address);
function merkleRoot() external view returns (bytes32);
function week() external view returns (uint32);
function frozen() external view returns (bool);
function isClaimed(uint256 index) external view returns (bool);
function setApprovals() external;
function claim(
uint256 index,
address account,
uint256 amount,
bytes32[] calldata merkleProof
) external;
function freeze() external;
function unfreeze() external;
function stake() external;
function updateMerkleRoot(bytes32 newMerkleRoot, bool unfreeze) external;
function updateDepositor(address newDepositor) external;
function updateAdmin(address newAdmin) external;
function updateVault(address newVault) external;
event DepositorUpdated(
address indexed oldDepositor,
address indexed newDepositor
);
event AdminUpdated(address indexed oldAdmin, address indexed newAdmin);
event VaultUpdated(address indexed oldVault, address indexed newVault);
event MerkleRootUpdated(bytes32 indexed merkleRoot, uint32 indexed week);
}
文件 5 的 8:IGenericVault.sol
pragma solidity 0.8.9;
interface IGenericVault {
function withdraw(address _to, uint256 _shares)
external
returns (uint256 withdrawn);
function withdrawAll(address _to) external returns (uint256 withdrawn);
function depositAll(address _to) external returns (uint256 _shares);
function deposit(address _to, uint256 _amount)
external
returns (uint256 _shares);
function harvest() external;
function balanceOfUnderlying(address user)
external
view
returns (uint256 amount);
function totalUnderlying() external view returns (uint256 total);
function totalSupply() external view returns (uint256 total);
function underlying() external view returns (address);
function strategy() external view returns (address);
function platform() external view returns (address);
function setPlatform(address _platform) external;
function setPlatformFee(uint256 _fee) external;
function setCallIncentive(uint256 _incentive) external;
function setWithdrawalPenalty(uint256 _penalty) external;
function setApprovals() external;
function callIncentive() external view returns (uint256);
function withdrawalPenalty() external view returns (uint256);
function platformFee() external view returns (uint256);
function balanceOf(address owner) external view returns (uint256);
function allowance(address owner, address spender)
external
view
returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(
address from,
address to,
uint256 value
) external returns (bool);
}
文件 6 的 8:IStrategyZaps.sol
pragma solidity 0.8.9;
interface IStrategyZaps {
function claimFromVaultAsUnderlying(
uint256 amount,
uint256 assetIndex,
uint256 minAmountOut,
address to
) external returns (uint256);
function claimFromVaultAsFxs(
uint256 amount,
uint256 minAmountOut,
address to
) external returns (uint256);
function claimFromVaultAsEth(
uint256 amount,
uint256 minAmountOut,
address to
) external returns (uint256);
function claimFromVaultViaUniV2EthPair(
uint256 amount,
uint256 minAmountOut,
address router,
address outputToken,
address to
) external;
function claimFromVaultAsUsdt(
uint256 amount,
uint256 minAmountOut,
address to
) external returns (uint256);
function claimFromVaultAsCvx(
uint256 amount,
uint256 minAmountOut,
address to,
bool lock
) external returns (uint256);
function claimFromVaultAsCvx(
uint256 amount,
uint256 minAmountOut,
address to
) external returns (uint256);
function claimFromVaultAsCrv(
uint256 amount,
uint256 minAmountOut,
address to
) external returns (uint256);
function claimFromVaultAsCvxCrv(
uint256 amount,
uint256 minAmountOut,
address to
) external returns (uint256);
function claimFromVaultAndStakeIn3PoolConvex(
uint256 amount,
uint256 minAmountOut,
address to
) external returns (uint256);
}
文件 7 的 8:SafeERC20.sol
pragma solidity ^0.8.0;
import "IERC20.sol";
import "Address.sol";
library SafeERC20 {
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(IERC20 token, address spender, uint256 value) internal {
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
文件 8 的 8:stkCvxCrvDistributorZaps.sol
pragma solidity 0.8.9;
import "SafeERC20.sol";
import "DistributorZaps.sol";
import "IGenericVault.sol";
contract stkCvxCrvDistributorZaps is DistributorZaps {
using SafeERC20 for IERC20;
constructor(
address _strategyZaps,
address _distributor,
address _vault
) DistributorZaps(_strategyZaps, _distributor, _vault) {}
function claimFromDistributorAsUnderlying(
uint256 index,
address account,
uint256 amount,
bytes32[] calldata merkleProof,
address to
) external returns (uint256) {
_claim(index, account, amount, merkleProof);
return IGenericVault(vault).withdrawAll(to);
}
function claimFromDistributorAsCrv(
uint256 index,
address account,
uint256 amount,
bytes32[] calldata merkleProof,
uint256 minAmountOut,
address to
) external {
_claim(index, account, amount, merkleProof);
IStrategyZaps(zaps).claimFromVaultAsCrv(amount, minAmountOut, to);
}
function claimFromDistributorAndStakeIn3PoolConvex(
uint256 index,
address account,
uint256 amount,
bytes32[] calldata merkleProof,
uint256 minAmountOut,
address to
) external {
_claim(index, account, amount, merkleProof);
IStrategyZaps(zaps).claimFromVaultAndStakeIn3PoolConvex(
amount,
minAmountOut,
to
);
}
}
{
"compilationTarget": {
"stkCvxCrvDistributorZaps.sol": "stkCvxCrvDistributorZaps"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_strategyZaps","type":"address"},{"internalType":"address","name":"_distributor","type":"address"},{"internalType":"address","name":"_vault","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32[]","name":"merkleProof","type":"bytes32[]"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"claimFromDistributorAndStakeIn3PoolConvex","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32[]","name":"merkleProof","type":"bytes32[]"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"claimFromDistributorAsCrv","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32[]","name":"merkleProof","type":"bytes32[]"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"bool","name":"lock","type":"bool"}],"name":"claimFromDistributorAsCvx","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32[]","name":"merkleProof","type":"bytes32[]"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"claimFromDistributorAsEth","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32[]","name":"merkleProof","type":"bytes32[]"},{"internalType":"uint256","name":"assetIndex","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"claimFromDistributorAsUnderlying","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32[]","name":"merkleProof","type":"bytes32[]"},{"internalType":"address","name":"to","type":"address"}],"name":"claimFromDistributorAsUnderlying","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32[]","name":"merkleProof","type":"bytes32[]"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"claimFromDistributorAsUsdt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32[]","name":"merkleProof","type":"bytes32[]"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"address","name":"router","type":"address"},{"internalType":"address","name":"outputToken","type":"address"},{"internalType":"address","name":"to","type":"address"}],"name":"claimFromDistributorViaUniV2EthPair","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"distributor","outputs":[{"internalType":"contract IGenericDistributor","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"setApprovals","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"zaps","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]