文件 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
) 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 的 8:Depositor.sol
pragma solidity 0.8.7;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "../interfaces/ITokenMinter.sol";
import "../interfaces/ILocker.sol";
import "../interfaces/ISdToken.sol";
import "../interfaces/ILiquidityGauge.sol";
contract Depositor {
using SafeERC20 for IERC20;
address public token;
uint256 private constant MAXTIME = 4 * 364 * 86400;
uint256 private constant WEEK = 7 * 86400;
uint256 public lockIncentive = 10;
uint256 public constant FEE_DENOMINATOR = 10000;
address public gauge;
address public governance;
address public immutable locker;
address public immutable minter;
uint256 public incentiveToken = 0;
uint256 public unlockTime;
bool public relock = true;
event Deposited(address indexed caller, address indexed user, uint256 amount, bool lock, bool stake);
event IncentiveReceived(address indexed caller, uint256 amount);
event TokenLocked(address indexed user, uint256 amount);
event GovernanceChanged(address indexed newGovernance);
event SdTokenOperatorChanged(address indexed newSdToken);
event FeesChanged(uint256 newFee);
constructor(
address _token,
address _locker,
address _minter
) {
governance = msg.sender;
token = _token;
locker = _locker;
minter = _minter;
}
function setGovernance(address _governance) external {
require(msg.sender == governance, "!auth");
governance = _governance;
emit GovernanceChanged(_governance);
}
function setSdTokenOperator(address _operator) external {
require(msg.sender == governance, "!auth");
ISdToken(minter).setOperator(_operator);
emit SdTokenOperatorChanged(_operator);
}
function setRelock(bool _relock) external {
require(msg.sender == governance, "!auth");
relock = _relock;
}
function setGauge(address _gauge) external {
require(msg.sender == governance, "!auth");
gauge = _gauge;
}
function setFees(uint256 _lockIncentive) external {
require(msg.sender == governance, "!auth");
if (_lockIncentive >= 0 && _lockIncentive <= 30) {
lockIncentive = _lockIncentive;
emit FeesChanged(_lockIncentive);
}
}
function _lockToken() internal {
uint256 tokenBalance = IERC20(token).balanceOf(address(this));
if (tokenBalance > 0) {
IERC20(token).safeTransfer(locker, tokenBalance);
emit TokenLocked(msg.sender, tokenBalance);
}
uint256 tokenBalanceStaker = IERC20(token).balanceOf(locker);
if (tokenBalanceStaker == 0) {
return;
}
ILocker(locker).increaseAmount(tokenBalanceStaker);
if (relock) {
uint256 unlockAt = block.timestamp + MAXTIME;
uint256 unlockInWeeks = (unlockAt / WEEK) * WEEK;
if (unlockInWeeks - unlockTime > 1) {
ILocker(locker).increaseUnlockTime(unlockAt);
unlockTime = unlockInWeeks;
}
}
}
function lockToken() external {
_lockToken();
if (incentiveToken > 0) {
ITokenMinter(minter).mint(msg.sender, incentiveToken);
emit IncentiveReceived(msg.sender, incentiveToken);
incentiveToken = 0;
}
}
function deposit(
uint256 _amount,
bool _lock,
bool _stake,
address _user
) public {
require(_amount > 0, "!>0");
require(_user != address(0), "!user");
if (_lock) {
IERC20(token).safeTransferFrom(msg.sender, locker, _amount);
_lockToken();
if (incentiveToken > 0) {
_amount = _amount + incentiveToken;
emit IncentiveReceived(msg.sender, incentiveToken);
incentiveToken = 0;
}
} else {
IERC20(token).safeTransferFrom(msg.sender, address(this), _amount);
uint256 callIncentive = (_amount * lockIncentive) / FEE_DENOMINATOR;
_amount = _amount - callIncentive;
incentiveToken = incentiveToken + callIncentive;
}
if (_stake && gauge != address(0)) {
ITokenMinter(minter).mint(address(this), _amount);
IERC20(minter).safeApprove(gauge, 0);
IERC20(minter).safeApprove(gauge, _amount);
ILiquidityGauge(gauge).deposit(_amount, _user);
} else {
ITokenMinter(minter).mint(_user, _amount);
}
emit Deposited(msg.sender, _user, _amount, _lock, _stake);
}
function depositAll(
bool _lock,
bool _stake,
address _user
) external {
uint256 tokenBal = IERC20(token).balanceOf(msg.sender);
deposit(tokenBal, _lock, _stake, _user);
}
}
文件 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:ILiquidityGauge.sol
pragma solidity 0.8.7;
interface ILiquidityGauge {
struct Reward {
address token;
address distributor;
uint256 period_finish;
uint256 rate;
uint256 last_update;
uint256 integral;
}
function deposit_reward_token(address _rewardToken, uint256 _amount) external;
function claim_rewards_for(address _user, address _recipient) external;
function deposit(uint256 _value, address _addr) external;
function reward_tokens(uint256 _i) external view returns(address);
function reward_data(address _tokenReward) external view returns(Reward memory);
}
文件 5 的 8:ILocker.sol
pragma solidity 0.8.7;
interface ILocker {
function createLock(uint256, uint256) external;
function increaseAmount(uint256) external;
function increaseUnlockTime(uint256) external;
function release() external;
function claimRewards(address,address) external;
function claimFXSRewards(address) external;
function execute(
address,
uint256,
bytes calldata
) external returns (bool, bytes memory);
function setGovernance(address) external;
function voteGaugeWeight(address, uint256) external;
function setAngleDepositor(address) external;
function setFxsDepositor(address) external;
}
文件 6 的 8:ISdToken.sol
pragma solidity 0.8.7;
interface ISdToken {
function setOperator(address _operator) external;
}
文件 7 的 8:ITokenMinter.sol
pragma solidity 0.8.7;
interface ITokenMinter {
function mint(address, uint256) external;
function burn(address, uint256) external;
}
文件 8 的 8: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/locking/Depositor.sol": "Depositor"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_locker","type":"address"},{"internalType":"address","name":"_minter","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"bool","name":"lock","type":"bool"},{"indexed":false,"internalType":"bool","name":"stake","type":"bool"}],"name":"Deposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"FeesChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newGovernance","type":"address"}],"name":"GovernanceChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"IncentiveReceived","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newSdToken","type":"address"}],"name":"SdTokenOperatorChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TokenLocked","type":"event"},{"inputs":[],"name":"FEE_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"bool","name":"_lock","type":"bool"},{"internalType":"bool","name":"_stake","type":"bool"},{"internalType":"address","name":"_user","type":"address"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_lock","type":"bool"},{"internalType":"bool","name":"_stake","type":"bool"},{"internalType":"address","name":"_user","type":"address"}],"name":"depositAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"gauge","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"governance","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"incentiveToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lockIncentive","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lockToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"locker","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"relock","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_lockIncentive","type":"uint256"}],"name":"setFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_gauge","type":"address"}],"name":"setGauge","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_governance","type":"address"}],"name":"setGovernance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_relock","type":"bool"}],"name":"setRelock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"}],"name":"setSdTokenOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unlockTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]