编译器
0.8.19+commit.7dd6d404
文件 1 的 11: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);
}
}
}
文件 2 的 11:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 3 的 11:IConfig.sol
pragma solidity ^0.8.19;
interface IConfig {
function dexInterfacerAddress() external view returns (address);
function karrotsAddress() external view returns (address);
function karrotChefAddress() external view returns (address);
function karrotStolenPoolAddress() external view returns (address);
function karrotFullProtecAddress() external view returns (address);
function karrotsPoolAddress() external view returns (address);
function rabbitAddress() external view returns (address);
function randomizerAddress() external view returns (address);
function uniswapRouterAddress() external view returns (address);
function uniswapFactoryAddress() external view returns (address);
function treasuryAddress() external view returns (address);
function treasuryBAddress() external view returns (address);
function teamSplitterAddress() external view returns (address);
function presaleDistributorAddress() external view returns (address);
function airdropDistributorAddress() external view returns (address);
function attackRewardCalculatorAddress() external view returns (address);
}
文件 4 的 11: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 的 11: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);
}
文件 6 的 11:IKarrotChef.sol
pragma solidity ^0.8.19;
interface IKarrotChef {
function deposit(uint256 _pid, uint256 _amount) external;
function withdraw(uint256 _pid, uint256 _amount) external;
function claim(uint256 _pid) external;
function attack() external;
function getUserStakedAmount(address _user) external view returns (uint256);
function getTotalStakedAmount() external view returns (uint256);
function setAllocationPoint(uint256 _pid, uint128 _allocPoint, bool _withUpdatePools) external;
function setLockDuration(uint256 _pid, uint256 _lockDuration) external;
function updateRewardPerBlock(uint88 _rewardPerBlock) external;
function setDebaseMultiplier(uint48 _debaseMultiplier) external;
function openKarrotChefDeposits() external;
function setDepositIsPaused(bool _isPaused) external;
function setThresholdFullProtecKarrotBalance(uint256 _thresholdFullProtecKarrotBalance) external;
function setClaimTaxRate(uint16 _maxTaxRate) external;
function setFullProtecLiquidityProportion(uint16 _fullProtecLiquidityProportion) external;
function getFullToChefRatio(address _user) external view returns (uint256);
}
文件 7 的 11:IKarrotsToken.sol
pragma solidity 0.8.19;
interface IKarrotsToken {
function approve(address spender, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function addDexAddress(address _dexAddress) external;
function removeDexAddress(address _dexAddress) external;
function mint(address to, uint256 amount) external;
function burn(uint256 amount) external;
function burnFrom(address account, uint256 amount) external;
function rebase(uint256 epoch, uint256 indexDelta, bool positive) external returns (uint256);
function balanceOf(address account) external view returns (uint256);
function totalSupply() external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
function transferUnderlying(address to, uint256 value) external returns (bool);
function fragmentToKarrots(uint256 value) external view returns (uint256);
function karrotsToFragment(uint256 karrots) external view returns (uint256);
function balanceOfUnderlying(address who) external view returns (uint256);
function setSellTaxRate(uint16 _sellTaxRate) external;
function setBuyTaxRate(uint16 _buyTaxRate) external;
function setMaxScaleFactorDecreasePercentagePerDebase(uint256 _maxScaleFactorDecreasePercentagePerDebase) external;
function setTaxSwapAmountThreshold(uint256 _taxSwapAmountThreshold) external;
function setDivertTaxToStolenPoolRate(uint256 _divertRate) external;
}
文件 8 的 11:KarrotFullProtec.sol
pragma solidity ^0.8.19;
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./interfaces/IKarrotsToken.sol";
import "./interfaces/IKarrotChef.sol";
import "./interfaces/IConfig.sol";
contract KarrotFullProtec is Ownable, ReentrancyGuard {
using SafeERC20 for IERC20;
IConfig public config;
struct UserInfo {
uint256 amount;
uint256 lockEndedTimestamp;
}
uint32 public fullProtecLockDuration = 4 days;
uint224 public thresholdFullProtecKarrotBalance = 1000000000 * 1e18;
uint256 public totalStaked;
address public outputAddress;
bool public depositsEnabled;
mapping(address => UserInfo) public userInfo;
event Deposit(address indexed user, uint256 amount);
event Withdraw(address indexed user, uint256 amount);
event SetLockDuration(uint256 fullProtecLockDuration);
event SetDepositsEnabled(bool enabled);
event TaxRatioUpdate(address indexed user, uint256 indexed newUserTaxRatio);
event FullProtecOpened(uint256 timestamp);
error ForwardFailed();
error CallerIsNotConfig();
error DepositsDisabled();
error InvalidAmount();
error StillLocked();
error NoOutputAddressSet();
error InvalidAllowance();
constructor(address _configManager) {
config = IConfig(_configManager);
}
modifier onlyConfig() {
if (msg.sender != address(config)) {
revert CallerIsNotConfig();
}
_;
}
function deposit(uint256 _amount) external nonReentrant {
if(!depositsEnabled){
revert DepositsDisabled();
}
if(_amount == 0){
revert InvalidAmount();
}
if(IKarrotsToken(config.karrotsAddress()).allowance(msg.sender, address(this)) < _amount){
revert InvalidAllowance();
}
UserInfo storage user = userInfo[msg.sender];
user.lockEndedTimestamp = block.timestamp + fullProtecLockDuration;
totalStaked += _amount;
user.amount += _amount;
IERC20(config.karrotsAddress()).safeTransferFrom(address(msg.sender), address(this), _amount);
IKarrotsToken(config.karrotsAddress()).burn(_amount);
emit Deposit(msg.sender, _amount);
emit TaxRatioUpdate(msg.sender, IKarrotChef(config.karrotChefAddress()).getFullToChefRatio(msg.sender));
}
function withdraw(uint256 _amount) external nonReentrant {
if(_amount == 0){
revert InvalidAmount();
}
UserInfo storage user = userInfo[msg.sender];
if(user.lockEndedTimestamp > block.timestamp){
revert StillLocked();
}
if(user.amount < _amount){
revert InvalidAmount();
}
user.lockEndedTimestamp = block.timestamp + fullProtecLockDuration;
user.amount -= _amount;
totalStaked -= _amount;
IKarrotsToken(config.karrotsAddress()).mint(address(msg.sender), _amount);
emit Withdraw(msg.sender, _amount);
emit TaxRatioUpdate(msg.sender, IKarrotChef(config.karrotChefAddress()).getFullToChefRatio(msg.sender));
}
function getUserStakedAmount(address _user) external view returns (uint256) {
return userInfo[_user].amount;
}
function getTotalStakedAmount() external view returns (uint256) {
return totalStaked;
}
function getIsUserAboveThresholdToAvoidClaimTax(address _user) external view returns (bool) {
return userInfo[_user].amount >= thresholdFullProtecKarrotBalance;
}
function setOutputAddress(address _outputAddress) external onlyOwner {
outputAddress = _outputAddress;
}
function openFullProtecDeposits() external onlyConfig {
depositsEnabled = true;
emit FullProtecOpened(block.timestamp);
}
function setFullProtecLockDuration(uint32 _lockDuration) external onlyConfig{
fullProtecLockDuration = _lockDuration;
}
function setThresholdFullProtecKarrotBalance(uint224 _threshold) external onlyConfig {
thresholdFullProtecKarrotBalance = _threshold;
}
function setConfigManager(address _configManager) external onlyOwner {
config = IConfig(_configManager);
}
function withdrawERC20FromContract(address _to, address _token) external onlyOwner {
bool os = IERC20(_token).transfer(_to, IERC20(_token).balanceOf(address(this)));
if (!os) {
revert ForwardFailed();
}
}
function withdrawEthFromContract() external onlyOwner {
if(outputAddress == address(0)){
revert NoOutputAddressSet();
}
(bool os, ) = payable(outputAddress).call{value: address(this).balance}("");
if (!os) {
revert ForwardFailed();
}
}
}
文件 9 的 11:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 10 的 11:ReentrancyGuard.sol
pragma solidity ^0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
}
function _nonReentrantAfter() private {
_status = _NOT_ENTERED;
}
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
文件 11 的 11:SafeERC20.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/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 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
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");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
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");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}
{
"compilationTarget": {
"src/KarrotFullProtec.sol": "KarrotFullProtec"
},
"evmVersion": "london",
"libraries": {
"lib/foundry-devops/src/DevOpsTools.sol:DevOpsTools": "0x3fd2b64a587cc58117db334fbd51c58d256adac5"
},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"details": {
"constantOptimizer": true,
"cse": true,
"deduplicate": true,
"inliner": true,
"jumpdestRemover": true,
"orderLiterals": true,
"peephole": true,
"yul": true,
"yulDetails": {
"optimizerSteps": "dhfoDgvulfnTUtnIf:fDnTOc",
"stackAllocation": true
}
},
"runs": 200
},
"remappings": [
":@chainlink/contracts/=lib/chainlink/contracts/",
":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
":ds-test/=lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":foundry-devops/=lib/foundry-devops/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":openzeppelin/=lib/openzeppelin-contracts/contracts/"
]
}
[{"inputs":[{"internalType":"address","name":"_configManager","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"CallerIsNotConfig","type":"error"},{"inputs":[],"name":"DepositsDisabled","type":"error"},{"inputs":[],"name":"ForwardFailed","type":"error"},{"inputs":[],"name":"InvalidAllowance","type":"error"},{"inputs":[],"name":"InvalidAmount","type":"error"},{"inputs":[],"name":"NoOutputAddressSet","type":"error"},{"inputs":[],"name":"StillLocked","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"FullProtecOpened","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"enabled","type":"bool"}],"name":"SetDepositsEnabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"fullProtecLockDuration","type":"uint256"}],"name":"SetLockDuration","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"newUserTaxRatio","type":"uint256"}],"name":"TaxRatioUpdate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"config","outputs":[{"internalType":"contract IConfig","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositsEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fullProtecLockDuration","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"getIsUserAboveThresholdToAvoidClaimTax","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalStakedAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"getUserStakedAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"openFullProtecDeposits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"outputAddress","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":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_configManager","type":"address"}],"name":"setConfigManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_lockDuration","type":"uint32"}],"name":"setFullProtecLockDuration","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_outputAddress","type":"address"}],"name":"setOutputAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint224","name":"_threshold","type":"uint224"}],"name":"setThresholdFullProtecKarrotBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"thresholdFullProtecKarrotBalance","outputs":[{"internalType":"uint224","name":"","type":"uint224"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalStaked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userInfo","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"lockEndedTimestamp","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"address","name":"_token","type":"address"}],"name":"withdrawERC20FromContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawEthFromContract","outputs":[],"stateMutability":"nonpayable","type":"function"}]