编译器
0.8.17+commit.8df45f5f
文件 1 的 6:AaveLendingFactory.sol
pragma solidity 0.8.17;
pragma experimental ABIEncoderV2;
import "./libraries/CloneLibrary.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
contract AaveLendingFactory {
using CloneLibrary for address;
using SafeERC20 for IERC20;
event NewAaveLending(address aaveLending, address client);
event NewSponsor(address sponsor, address client);
event FactoryOwnerChanged(address newowner);
event NewYieldManager(address newYieldManager);
event NewRewardToken(address rewardToken);
event NewStakingToken(address stakingToken);
event NewStakingContract(address stakingContract);
event NewLendingViews(address lendingViews);
event FeesWithdrawn(uint amount, address withdrawer);
event NewAaveLendingImplementation(address newAaveLendingImplementation);
event RecoverOpen(bool recover);
address public factoryOwner;
address public aaveImplementation;
address public yieldManager;
address public rewardToken;
address public stakingToken;
address public stakingContract;
address public lendingViews;
bool public recoverOpen;
mapping(address => address) public stakingContractLookup;
constructor(
address _aaveImplementation,
address _yieldManager,
address _rewardToken,
address _stakingToken,
address _stakingContract,
address _lendingViews
)
{
require(_aaveImplementation != address(0), "No zero address for _aaveImplementation");
require(_yieldManager != address(0), "No zero address for _yieldManager");
factoryOwner = msg.sender;
aaveImplementation = _aaveImplementation;
yieldManager = _yieldManager;
rewardToken = _rewardToken;
stakingToken = _stakingToken;
stakingContract = _stakingContract;
lendingViews = _lendingViews;
emit FactoryOwnerChanged(factoryOwner);
emit NewAaveLendingImplementation(aaveImplementation);
emit NewYieldManager(yieldManager);
emit NewRewardToken(rewardToken);
emit NewStakingContract(stakingContract);
emit NewStakingToken(stakingToken);
emit NewLendingViews(lendingViews);
}
function aaveLendingMint(address sponsor)
external
returns(address aave)
{
aave = aaveImplementation.createClone();
emit NewAaveLending(aave, msg.sender);
stakingContractLookup[msg.sender] = aave;
IAaveLendingImplementation(aave).initialize(
msg.sender,
address(this)
);
if (sponsor != address(0) && sponsor != msg.sender && IYieldManager(yieldManager).getAffiliate(msg.sender) == address(0)) {
IYieldManager(yieldManager).setAffiliate(msg.sender, sponsor);
emit NewSponsor(sponsor, msg.sender);
}
}
function getYieldManager() external view returns (address) {
return yieldManager;
}
function getRewardToken() external view returns (address) {
return rewardToken;
}
function getStakingToken() external view returns (address) {
return stakingToken;
}
function getStakingContract() external view returns (address) {
return stakingContract;
}
function getLendingViews() external view returns (address) {
return lendingViews;
}
function getRecoverOpen() external view returns (bool) {
return recoverOpen;
}
function newAaveLendingImplementation(address aaveImplementation_) external {
require(msg.sender == factoryOwner, "Only factory owner");
require(aaveImplementation_ != address(0), "No zero address for aaveImplementation_");
aaveImplementation = aaveImplementation_;
emit NewAaveLendingImplementation(aaveImplementation);
}
function newYieldManager(address yieldManager_) external {
require(msg.sender == factoryOwner, "Only factory owner");
require(yieldManager_ != address(0), "No zero address for yieldManager_");
yieldManager = yieldManager_;
emit NewYieldManager(yieldManager);
}
function newRewardToken(address rewardToken_) external {
require(msg.sender == factoryOwner, "Only factory owner");
require(rewardToken_ != address(0), "No zero address for rewardToken_");
rewardToken = rewardToken_;
emit NewRewardToken(rewardToken);
}
function newStakingToken(address stakingToken_) external {
require(msg.sender == factoryOwner, "Only factory owner");
require(stakingToken_ != address(0), "No zero address for stakingToken_");
stakingToken = stakingToken_;
emit NewStakingToken(stakingToken);
}
function newStakingContract(address stakingContract_) external {
require(msg.sender == factoryOwner, "Only factory owner");
require(stakingContract_ != address(0), "No zero address for stakingContract_");
stakingContract = stakingContract_;
emit NewStakingContract(stakingContract);
}
function newLendingViews(address lendingViews_) external {
require(msg.sender == factoryOwner, "Only factory owner");
require(lendingViews_ != address(0), "No zero address for lendingViews_");
lendingViews = lendingViews_;
emit NewLendingViews(lendingViews);
}
function newRecoverOpen(bool recoverOpen_) external {
require(msg.sender == factoryOwner, "Only factory owner");
recoverOpen = recoverOpen_;
emit RecoverOpen(recoverOpen_);
}
function newFactoryOwner(address payable newOwner) external {
require(msg.sender == factoryOwner, "Only factory owner");
require(newOwner != address(0), "No zero address for newOwner");
factoryOwner = newOwner;
emit FactoryOwnerChanged(factoryOwner);
}
function getUserStakingContract(address staker) external view returns(address) {
return stakingContractLookup[staker];
}
function withdrawRewardFees(
address receiver,
uint amount
) external {
require(msg.sender == factoryOwner, "Only factory owner");
require(amount > 0, "Cannot withdraw 0");
require(
amount <= IERC20(rewardToken).balanceOf(address(this)),
"Cannot withdraw more than fees in the contract"
);
IERC20(rewardToken).safeTransfer(receiver, amount);
emit FeesWithdrawn(amount, receiver);
}
function executeTransaction(
address target,
uint256 value,
string memory signature,
bytes memory data
) public payable returns (bytes memory) {
require(
msg.sender == factoryOwner,
"executeTransaction: Call must come from owner"
);
bytes memory callData;
if (bytes(signature).length == 0) {
callData = data;
} else {
callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data);
}
(bool success, bytes memory returnData) = target.call{value: value}(callData);
require(
success,
"executeTransaction: Transaction execution reverted."
);
return returnData;
}
receive() external payable {}
}
interface IAaveLendingImplementation {
function initialize(
address owner_,
address factoryAddress_
) external;
}
interface IYieldManager {
function setAffiliate(address client, address sponsor) external;
function getAffiliate(address client) external view returns (address);
}
文件 2 的 6:Address.sol
pragma solidity ^0.8.1;
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 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 functionCallWithValue(target, data, 0, "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");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, 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) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, 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) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
文件 3 的 6:CloneLibrary.sol
pragma solidity >=0.8.6;
library CloneLibrary {
function createClone(address target) internal returns (address result) {
bytes memory cloneBuffer = new bytes(72);
assembly {
let clone := add(cloneBuffer, 32)
mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(clone, 0x14), shl(96, target))
mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
result := create(0, clone, 0x37)
}
}
function isClone(address target, address query) internal view returns (bool result) {
assembly {
let clone := mload(0x40)
mstore(clone, 0x363d3d373d3d3d363d7300000000000000000000000000000000000000000000)
mstore(add(clone, 0xa), shl(96, target))
mstore(add(clone, 0x1e), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
let other := add(clone, 0x40)
extcodecopy(query, other, 0, 0x2d)
result := and(
eq(mload(clone), mload(other)),
eq(mload(add(clone, 0xd)), mload(add(other, 0xd)))
)
}
}
}
文件 4 的 6:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, 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 from,
address to,
uint256 amount
) external returns (bool);
}
文件 5 的 6:SafeERC20.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.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 safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
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");
}
}
}
文件 6 的 6:draft-IERC20Permit.sol
pragma solidity ^0.8.0;
interface IERC20Permit {
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
function nonces(address owner) external view returns (uint256);
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
{
"compilationTarget": {
"contracts/AaveLendingFactory.sol": "AaveLendingFactory"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_aaveImplementation","type":"address"},{"internalType":"address","name":"_yieldManager","type":"address"},{"internalType":"address","name":"_rewardToken","type":"address"},{"internalType":"address","name":"_stakingToken","type":"address"},{"internalType":"address","name":"_stakingContract","type":"address"},{"internalType":"address","name":"_lendingViews","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newowner","type":"address"}],"name":"FactoryOwnerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"withdrawer","type":"address"}],"name":"FeesWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"aaveLending","type":"address"},{"indexed":false,"internalType":"address","name":"client","type":"address"}],"name":"NewAaveLending","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newAaveLendingImplementation","type":"address"}],"name":"NewAaveLendingImplementation","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"lendingViews","type":"address"}],"name":"NewLendingViews","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"rewardToken","type":"address"}],"name":"NewRewardToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sponsor","type":"address"},{"indexed":false,"internalType":"address","name":"client","type":"address"}],"name":"NewSponsor","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"stakingContract","type":"address"}],"name":"NewStakingContract","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"stakingToken","type":"address"}],"name":"NewStakingToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newYieldManager","type":"address"}],"name":"NewYieldManager","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"recover","type":"bool"}],"name":"RecoverOpen","type":"event"},{"inputs":[],"name":"aaveImplementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"sponsor","type":"address"}],"name":"aaveLendingMint","outputs":[{"internalType":"address","name":"aave","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"string","name":"signature","type":"string"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"executeTransaction","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"factoryOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLendingViews","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRecoverOpen","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRewardToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getStakingContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getStakingToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"staker","type":"address"}],"name":"getUserStakingContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getYieldManager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lendingViews","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"aaveImplementation_","type":"address"}],"name":"newAaveLendingImplementation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"newOwner","type":"address"}],"name":"newFactoryOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"lendingViews_","type":"address"}],"name":"newLendingViews","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"recoverOpen_","type":"bool"}],"name":"newRecoverOpen","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardToken_","type":"address"}],"name":"newRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"stakingContract_","type":"address"}],"name":"newStakingContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"stakingToken_","type":"address"}],"name":"newStakingToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"yieldManager_","type":"address"}],"name":"newYieldManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"recoverOpen","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stakingContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"stakingContractLookup","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stakingToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawRewardFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"yieldManager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]