编译器
0.8.11+commit.d7f03943
文件 1 的 9: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
) internal 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 的 9:AuraClaimZapV3.sol
pragma solidity 0.8.11;
import { IERC20 } from "@openzeppelin/contracts-0.8/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts-0.8/token/ERC20/utils/SafeERC20.sol";
import { AuraMath } from "../utils/AuraMath.sol";
import { ICrvDepositorWrapper } from "../interfaces/ICrvDepositorWrapper.sol";
import { IAuraLocker } from "../interfaces/IAuraLocker.sol";
import { IRewardStaking } from "../interfaces/IRewardStaking.sol";
import { IRewardPool4626 } from "../interfaces/IRewardPool4626.sol";
contract AuraClaimZapV3 {
using SafeERC20 for IERC20;
using AuraMath for uint256;
address public immutable crv;
address public immutable cvx;
address public immutable cvxCrv;
address public immutable crvDepositWrapper;
address public immutable cvxCrvRewards;
address public immutable locker;
address public immutable owner;
address public immutable compounder;
struct ClaimRewardsAmounts {
uint256 depositCrvMaxAmount;
uint256 minAmountOut;
uint256 depositCvxMaxAmount;
uint256 depositCvxCrvMaxAmount;
}
struct Options {
bool claimCvxCrv;
bool claimLockedCvx;
bool lockCvxCrv;
bool lockCrvDeposit;
bool useAllWalletFunds;
bool useCompounder;
bool lockCvx;
}
constructor(
address _crv,
address _cvx,
address _cvxCrv,
address _crvDepositWrapper,
address _cvxCrvRewards,
address _locker,
address _compounder
) {
crv = _crv;
cvx = _cvx;
cvxCrv = _cvxCrv;
crvDepositWrapper = _crvDepositWrapper;
cvxCrvRewards = _cvxCrvRewards;
locker = _locker;
owner = msg.sender;
compounder = _compounder;
}
function getName() external pure returns (string memory) {
return "ClaimZap V3.0";
}
function setApprovals() external {
require(msg.sender == owner, "!auth");
_approveToken(crv, crvDepositWrapper);
_approveToken(cvxCrv, cvxCrvRewards);
_approveToken(cvxCrv, compounder);
_approveToken(cvx, locker);
}
function _approveToken(address _token, address _spender) internal {
IERC20(_token).safeApprove(address(_spender), 0);
IERC20(_token).safeApprove(address(_spender), type(uint256).max);
}
function claimRewards(
address[] calldata rewardContracts,
address[] calldata extraRewardContracts,
address[] calldata tokenRewardContracts,
address[] calldata tokenRewardTokens,
ClaimRewardsAmounts calldata amounts,
Options calldata options
) external {
require(tokenRewardContracts.length == tokenRewardTokens.length, "!parity");
uint256 crvBalance;
uint256 cvxBalance;
uint256 cvxCrvBalance;
if (!options.useAllWalletFunds && _callRelockRewards(options)) {
crvBalance = IERC20(crv).balanceOf(msg.sender);
cvxBalance = IERC20(cvx).balanceOf(msg.sender);
cvxCrvBalance = IERC20(cvxCrv).balanceOf(msg.sender);
}
for (uint256 i = 0; i < rewardContracts.length; i++) {
IRewardStaking(rewardContracts[i]).getReward(msg.sender, true);
}
for (uint256 i = 0; i < extraRewardContracts.length; i++) {
IRewardStaking(extraRewardContracts[i]).getReward(msg.sender);
}
for (uint256 i = 0; i < tokenRewardContracts.length; i++) {
IRewardStaking(tokenRewardContracts[i]).getReward(msg.sender, tokenRewardTokens[i]);
}
if (options.claimCvxCrv) {
IRewardStaking(cvxCrvRewards).getReward(msg.sender, true);
}
if (options.claimLockedCvx) {
IAuraLocker(locker).getReward(msg.sender);
}
if (_callRelockRewards(options)) {
_relockRewards(crvBalance, cvxBalance, cvxCrvBalance, amounts, options);
}
}
function _callRelockRewards(Options calldata options) internal view returns (bool) {
return (options.lockCvxCrv || options.lockCrvDeposit || options.useCompounder || options.lockCvx);
}
function _relockRewards(
uint256 removeCrvBalance,
uint256 removeCvxBalance,
uint256 removeCvxCrvBalance,
ClaimRewardsAmounts calldata amounts,
Options calldata options
) internal {
if (amounts.depositCrvMaxAmount > 0) {
(uint256 crvBalance, bool continued) = _checkBalanceAndPullToken(
crv,
removeCrvBalance,
amounts.depositCrvMaxAmount
);
if (continued) {ICrvDepositorWrapper(crvDepositWrapper).deposit(
crvBalance,
amounts.minAmountOut,
options.lockCrvDeposit,
address(0)
);}
}
if (options.lockCvxCrv) {
_checkBalanceAndPullToken(cvxCrv, removeCvxCrvBalance, amounts.depositCvxCrvMaxAmount);
}
uint cvxCrvBalanceToLock = IERC20(cvxCrv).balanceOf(address(this));
if(cvxCrvBalanceToLock > 0){
if(options.useCompounder) {
IRewardPool4626(compounder).deposit(cvxCrvBalanceToLock, msg.sender);
}
else{
IRewardStaking(cvxCrvRewards).stakeFor(msg.sender, cvxCrvBalanceToLock);
}
}
if (options.lockCvx) {
(uint256 cvxBalance, bool continued) = _checkBalanceAndPullToken(
cvx,
removeCvxBalance,
amounts.depositCvxMaxAmount
);
if(continued){IAuraLocker(locker).lock(msg.sender, cvxBalance);}
}
}
function _checkBalanceAndPullToken(
address _token,
uint256 _removeAmount,
uint256 _maxAmount
) internal returns (uint256 _balance, bool continued) {
_balance = IERC20(_token).balanceOf(msg.sender).sub(_removeAmount);
_balance = AuraMath.min(_balance, _maxAmount);
if (_balance > 0) {
IERC20(_token).safeTransferFrom(msg.sender, address(this), _balance);
continued = true;
}
}
}
文件 3 的 9:AuraMath.sol
pragma solidity 0.8.11;
library AuraMath {
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a - b;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a * b;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return (a / 2) + (b / 2) + (((a % 2) + (b % 2)) / 2);
}
function to224(uint256 a) internal pure returns (uint224 c) {
require(a <= type(uint224).max, "AuraMath: uint224 Overflow");
c = uint224(a);
}
function to128(uint256 a) internal pure returns (uint128 c) {
require(a <= type(uint128).max, "AuraMath: uint128 Overflow");
c = uint128(a);
}
function to112(uint256 a) internal pure returns (uint112 c) {
require(a <= type(uint112).max, "AuraMath: uint112 Overflow");
c = uint112(a);
}
function to96(uint256 a) internal pure returns (uint96 c) {
require(a <= type(uint96).max, "AuraMath: uint96 Overflow");
c = uint96(a);
}
function to32(uint256 a) internal pure returns (uint32 c) {
require(a <= type(uint32).max, "AuraMath: uint32 Overflow");
c = uint32(a);
}
}
library AuraMath32 {
function sub(uint32 a, uint32 b) internal pure returns (uint32 c) {
c = a - b;
}
}
library AuraMath112 {
function add(uint112 a, uint112 b) internal pure returns (uint112 c) {
c = a + b;
}
function sub(uint112 a, uint112 b) internal pure returns (uint112 c) {
c = a - b;
}
}
library AuraMath224 {
function add(uint224 a, uint224 b) internal pure returns (uint224 c) {
c = a + b;
}
}
文件 4 的 9:IAuraLocker.sol
pragma solidity 0.8.11;
interface IAuraLocker {
function lock(address _account, uint256 _amount) external;
function checkpointEpoch() external;
function epochCount() external view returns (uint256);
function balanceAtEpochOf(uint256 _epoch, address _user) external view returns (uint256 amount);
function totalSupplyAtEpoch(uint256 _epoch) external view returns (uint256 supply);
function queueNewRewards(address _rewardsToken, uint256 reward) external;
function getReward(address _account, bool _stake) external;
function getReward(address _account) external;
}
文件 5 的 9:ICrvDepositorWrapper.sol
pragma solidity 0.8.11;
interface ICrvDepositorWrapper {
function getMinOut(uint256, uint256) external view returns (uint256);
function deposit(
uint256,
uint256,
bool,
address _stakeAddress
) external;
}
文件 6 的 9: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);
}
文件 7 的 9:IRewardPool4626.sol
pragma solidity 0.8.11;
interface IRewardPool4626 {
function withdraw(
uint256 assets,
address receiver,
address owner
) external returns (uint256 shares);
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
function asset() external view returns (address);
function balanceOf(address account) external view returns (uint256);
function processIdleRewards() external;
}
文件 8 的 9:IRewardStaking.sol
pragma solidity 0.8.11;
interface IRewardStaking {
function getReward(address _account, bool _claimExtras) external;
function getReward(address _account) external;
function getReward(address _account, address _token) external;
function stakeFor(address, uint256) external;
function processIdleRewards() external;
}
文件 9 的 9:SafeERC20.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../../../utils/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");
}
}
}
{
"compilationTarget": {
"contracts/peripheral/AuraClaimZapV3.sol": "AuraClaimZapV3"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "none"
},
"optimizer": {
"enabled": true,
"runs": 800
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_crv","type":"address"},{"internalType":"address","name":"_cvx","type":"address"},{"internalType":"address","name":"_cvxCrv","type":"address"},{"internalType":"address","name":"_crvDepositWrapper","type":"address"},{"internalType":"address","name":"_cvxCrvRewards","type":"address"},{"internalType":"address","name":"_locker","type":"address"},{"internalType":"address","name":"_compounder","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address[]","name":"rewardContracts","type":"address[]"},{"internalType":"address[]","name":"extraRewardContracts","type":"address[]"},{"internalType":"address[]","name":"tokenRewardContracts","type":"address[]"},{"internalType":"address[]","name":"tokenRewardTokens","type":"address[]"},{"components":[{"internalType":"uint256","name":"depositCrvMaxAmount","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"uint256","name":"depositCvxMaxAmount","type":"uint256"},{"internalType":"uint256","name":"depositCvxCrvMaxAmount","type":"uint256"}],"internalType":"struct AuraClaimZapV3.ClaimRewardsAmounts","name":"amounts","type":"tuple"},{"components":[{"internalType":"bool","name":"claimCvxCrv","type":"bool"},{"internalType":"bool","name":"claimLockedCvx","type":"bool"},{"internalType":"bool","name":"lockCvxCrv","type":"bool"},{"internalType":"bool","name":"lockCrvDeposit","type":"bool"},{"internalType":"bool","name":"useAllWalletFunds","type":"bool"},{"internalType":"bool","name":"useCompounder","type":"bool"},{"internalType":"bool","name":"lockCvx","type":"bool"}],"internalType":"struct AuraClaimZapV3.Options","name":"options","type":"tuple"}],"name":"claimRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"compounder","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"crv","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"crvDepositWrapper","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cvx","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cvxCrv","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cvxCrvRewards","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getName","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"locker","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"setApprovals","outputs":[],"stateMutability":"nonpayable","type":"function"}]