文件 1 的 7: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 的 7:BalancerFeeDistributor.sol
pragma solidity 0.8.7;
interface BalancerFeeDistributor {
function claimToken(address user, address token) external returns (uint256);
function claimTokens(address user, address[] calldata tokens) external returns (uint256[] memory);
}
文件 3 的 7:BalancerLocker.sol
pragma solidity 0.8.7;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./interfaces/VeToken.sol";
import "./interfaces/GaugeController.sol";
import "./interfaces/BalancerFeeDistributor.sol";
contract BalancerLocker {
using SafeERC20 for IERC20;
address public governance;
address public depositor;
address public accumulator;
address public constant BALANCER_POOL_TOKEN = address(0x5c6Ee304399DBdB9C8Ef030aB642B10820DB8F56);
address public constant veBAL = address(0xC128a9954e6c874eA3d62ce62B468bA073093F25);
address public feeDistributor = address(0x26743984e3357eFC59f2fd6C1aFDC310335a61c9);
address public gaugeController = address(0xC128468b7Ce63eA702C1f104D55A2566b13D3ABD);
event LockCreated(address indexed user, uint256 value, uint256 duration);
event TokenClaimed(address indexed user, address token, uint256 value);
event TokensClaimed(address indexed user, address[] tokens, uint256[] value);
event VotedOnGaugeWeight(address indexed _gauge, uint256 _weight);
event Released(address indexed user, uint256 value);
event GovernanceChanged(address indexed newGovernance);
event BalancerDepositorChanged(address indexed newDepositor);
event AccumulatorChanged(address indexed newAccumulator);
event FeeDistributorChanged(address indexed newFeeDistributor);
event GaugeControllerChanged(address indexed newGaugeController);
constructor(address _accumulator) {
governance = msg.sender;
accumulator = _accumulator;
IERC20(BALANCER_POOL_TOKEN).approve(veBAL, type(uint256).max);
}
modifier onlyGovernance() {
require(msg.sender == governance, "!gov");
_;
}
modifier onlyGovernanceOrAcc() {
require(msg.sender == governance || msg.sender == accumulator, "!(gov||acc)");
_;
}
modifier onlyGovernanceOrDepositor() {
require(msg.sender == governance || msg.sender == depositor, "!(gov||Depositor)");
_;
}
function createLock(uint256 _value, uint256 _unlockTime) external onlyGovernance {
VeToken(veBAL).create_lock(_value, _unlockTime);
emit LockCreated(msg.sender, _value, _unlockTime);
}
function increaseAmount(uint256 _value) external onlyGovernanceOrDepositor {
VeToken(veBAL).increase_amount(_value);
}
function increaseUnlockTime(uint256 _unlockTime) external onlyGovernanceOrDepositor {
VeToken(veBAL).increase_unlock_time(_unlockTime);
}
function claimRewards(address _token, address _recipient) external onlyGovernanceOrAcc {
uint256 claimed = BalancerFeeDistributor(feeDistributor).claimToken(address(this), _token);
emit TokenClaimed(_recipient, _token, claimed);
IERC20(_token).safeTransfer(_recipient, claimed);
}
function claimAllRewards(address[] calldata _tokens, address _recipient) external onlyGovernanceOrAcc {
uint256[] memory claimed = BalancerFeeDistributor(feeDistributor).claimTokens(address(this), _tokens);
uint length = _tokens.length;
for(uint i; i < length; ++i){
IERC20(_tokens[i]).safeTransfer(_recipient, claimed[i]);
}
emit TokensClaimed(_recipient, _tokens, claimed);
}
function release(address _recipient) external onlyGovernance {
VeToken(veBAL).withdraw();
uint256 balance = IERC20(BALANCER_POOL_TOKEN).balanceOf(address(this));
IERC20(BALANCER_POOL_TOKEN).safeTransfer(_recipient, balance);
emit Released(_recipient, balance);
}
function voteGaugeWeight(address _gauge, uint256 _weight) external onlyGovernance {
GaugeController(gaugeController).vote_for_gauge_weights(_gauge, _weight);
emit VotedOnGaugeWeight(_gauge, _weight);
}
function setGovernance(address _governance) external onlyGovernance {
governance = _governance;
emit GovernanceChanged(_governance);
}
function setDepositor(address _depositor) external onlyGovernance {
depositor = _depositor;
emit BalancerDepositorChanged(_depositor);
}
function setFeeDistributor(address _newFD) external onlyGovernance {
feeDistributor = _newFD;
emit FeeDistributorChanged(_newFD);
}
function setGaugeController(address _gaugeController) external onlyGovernance {
gaugeController = _gaugeController;
emit GaugeControllerChanged(_gaugeController);
}
function setAccumulator(address _accumulator) external onlyGovernance {
accumulator = _accumulator;
emit AccumulatorChanged(_accumulator);
}
function execute(
address to,
uint256 value,
bytes calldata data
) external onlyGovernance returns (bool, bytes memory) {
(bool success, bytes memory result) = to.call{ value: value }(data);
return (success, result);
}
}
文件 4 的 7:GaugeController.sol
pragma solidity 0.8.7;
interface GaugeController {
function vote_for_gauge_weights(address, uint256) external;
function vote(
uint256,
bool,
bool
) external;
}
文件 5 的 7: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);
}
文件 6 的 7: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");
}
}
}
文件 7 的 7:VeToken.sol
pragma solidity 0.8.7;
interface VeToken {
struct LockedBalance {
int128 amount;
uint256 end;
}
function create_lock(uint256 _value, uint256 _unlock_time) external;
function increase_amount(uint256 _value) external;
function increase_unlock_time(uint256 _unlock_time) external;
function withdraw() external;
}
{
"compilationTarget": {
"contracts/BalancerLocker.sol": "BalancerLocker"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_accumulator","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newAccumulator","type":"address"}],"name":"AccumulatorChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newDepositor","type":"address"}],"name":"BalancerDepositorChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newFeeDistributor","type":"address"}],"name":"FeeDistributorChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newGaugeController","type":"address"}],"name":"GaugeControllerChanged","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":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"duration","type":"uint256"}],"name":"LockCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Released","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"TokenClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"address[]","name":"tokens","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"value","type":"uint256[]"}],"name":"TokensClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_gauge","type":"address"},{"indexed":false,"internalType":"uint256","name":"_weight","type":"uint256"}],"name":"VotedOnGaugeWeight","type":"event"},{"inputs":[],"name":"BALANCER_POOL_TOKEN","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accumulator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"_tokens","type":"address[]"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"claimAllRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"claimRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"},{"internalType":"uint256","name":"_unlockTime","type":"uint256"}],"name":"createLock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"execute","outputs":[{"internalType":"bool","name":"","type":"bool"},{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeDistributor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gaugeController","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"governance","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"increaseAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_unlockTime","type":"uint256"}],"name":"increaseUnlockTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"}],"name":"release","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_accumulator","type":"address"}],"name":"setAccumulator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_depositor","type":"address"}],"name":"setDepositor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newFD","type":"address"}],"name":"setFeeDistributor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_gaugeController","type":"address"}],"name":"setGaugeController","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_governance","type":"address"}],"name":"setGovernance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"veBAL","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_gauge","type":"address"},{"internalType":"uint256","name":"_weight","type":"uint256"}],"name":"voteGaugeWeight","outputs":[],"stateMutability":"nonpayable","type":"function"}]