编译器
0.8.17+commit.8df45f5f
文件 1 的 6:AccessControlled.sol
pragma solidity ^0.8.17;
import "../interfaces/IAuthority.sol";
abstract contract AccessControlled {
event AuthorityUpdated(IAuthority authority);
IAuthority public authority;
constructor(IAuthority _authority) {
require(address(_authority) != address(0), "Authority cannot be zero address");
authority = _authority;
emit AuthorityUpdated(_authority);
}
modifier onlyGovernor {
_onlyGovernor();
_;
}
modifier onlyGuardian {
_onlyGuardian();
_;
}
modifier onlyPolicy {
_onlyPolicy();
_;
}
modifier onlyVault {
_onlyVault();
_;
}
modifier onlyGlobalRole(bytes32 _role){
_onlyRole(_role);
_;
}
function initializeAuthority(IAuthority _newAuthority) internal {
require(authority == IAuthority(address(0)), "AUTHORITY_INITIALIZED");
authority = _newAuthority;
emit AuthorityUpdated(_newAuthority);
}
function setAuthority(IAuthority _newAuthority) external {
_onlyGovernor();
authority = _newAuthority;
emit AuthorityUpdated(_newAuthority);
}
function _onlyGovernor() internal view {
require(msg.sender == authority.governor(), "UNAUTHORIZED");
}
function _onlyGuardian() internal view {
require(msg.sender == authority.guardian(), "UNAUTHORIZED");
}
function _onlyPolicy() internal view {
require(msg.sender == authority.policy(), "UNAUTHORIZED");
}
function _onlyVault() internal view {
require(msg.sender == authority.vault(), "UNAUTHORIZED");
}
function _onlyRole(bytes32 _role) internal view {
require(authority.roles(msg.sender) == _role, "UNAUTHORIZED");
}
}
文件 2 的 6:IAuthority.sol
pragma solidity >=0.8.9;
interface IAuthority {
event GovernorPushed(address indexed from, address indexed to, bool _effectiveImmediately);
event GuardianPushed(address indexed from, address indexed to, bool _effectiveImmediately);
event PolicyPushed(address indexed from, address indexed to, bool _effectiveImmediately);
event VaultPushed(address indexed from, address indexed to, bool _effectiveImmediately);
event RolePushed(address indexed account, bytes32 _role);
event GovernorPulled(address indexed from, address indexed to);
event GuardianPulled(address indexed from, address indexed to);
event PolicyPulled(address indexed from, address indexed to);
event VaultPulled(address indexed from, address indexed to);
function governor() external view returns (address);
function guardian() external view returns (address);
function policy() external view returns (address);
function vault() external view returns (address);
function roles(address _addr) external view returns (bytes32);
}
文件 3 的 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);
}
文件 4 的 6:IERC20Metadata.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 5 的 6:IKonduxERC20.sol
pragma solidity ^0.8.17;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
interface IKonduxERC20 is IERC20 {
function excludedFromFees(address) external view returns (bool);
function tradingOpen() external view returns (bool);
function taxSwapMin() external view returns (uint256);
function taxSwapMax() external view returns (uint256);
function _isLiqPool(address) external view returns (bool);
function taxRateBuy() external view returns (uint8);
function taxRateSell() external view returns (uint8);
function antiBotEnabled() external view returns (bool);
function excludedFromAntiBot(address) external view returns (bool);
function _lastSwapBlock(address) external view returns (uint256);
function taxWallet() external view returns (address);
event TokensAirdropped(uint256 totalWallets, uint256 totalTokens);
event TokensBurned(address indexed burnedByWallet, uint256 tokenAmount);
event TaxWalletChanged(address newTaxWallet);
event TaxRateChanged(uint8 newBuyTax, uint8 newSellTax);
function initLP() external;
function enableTrading() external;
function burnTokens(uint256 amount) external;
function enableAntiBot(bool isEnabled) external;
function excludeFromAntiBot(address wallet, bool isExcluded) external;
function excludeFromFees(address wallet, bool isExcluded) external;
function adjustTaxRate(uint8 newBuyTax, uint8 newSellTax) external;
function setTaxWallet(address newTaxWallet) external;
function taxSwapSettings(uint32 minValue, uint32 minDivider, uint32 maxValue, uint32 maxDivider) external;
function totalSupply() external view returns (uint256);
function decimals() external view returns (uint8);
function symbol() external view returns (string memory);
function name() external view returns (string memory);
function getOwner() external view returns (address);
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);
}
文件 6 的 6:Treasury.sol
pragma solidity ^0.8.17;
import "./interfaces/IKonduxERC20.sol";
import "./types/AccessControlled.sol";
contract Treasury is AccessControlled {
event Deposit(address indexed token, uint256 amount);
event DepositEther(uint256 amount);
event EtherDeposit(uint256 amount);
event Withdrawal(address indexed token, uint256 amount);
event EtherWithdrawal(address to, uint256 amount);
enum STATUS {
RESERVEDEPOSITOR,
RESERVESPENDER,
RESERVETOKEN
}
string internal notAccepted = "Treasury: not accepted";
string internal notApproved = "Treasury: not approved";
string internal invalidToken = "Treasury: invalid token";
mapping(STATUS => mapping(address => bool)) public permissions;
mapping(address => bool) public isTokenApproved;
address[] public approvedTokensList;
uint256 public approvedTokensCount;
address public stakingContract;
constructor(address _authority) AccessControlled(IAuthority(_authority)) {
approvedTokensCount = 0;
}
function deposit(
uint256 _amount,
address _token
) external {
if (permissions[STATUS.RESERVETOKEN][_token]) {
require(permissions[STATUS.RESERVEDEPOSITOR][msg.sender], notApproved);
} else {
revert(invalidToken);
}
IKonduxERC20(_token).transferFrom(tx.origin, address(this), _amount);
uint256 allowance = IKonduxERC20(_token).allowance(stakingContract, _token);
IKonduxERC20(_token).approve(stakingContract, allowance + _amount);
emit Deposit(_token, _amount);
}
function depositEther () external payable {
require(permissions[STATUS.RESERVEDEPOSITOR][msg.sender], notApproved);
emit DepositEther(msg.value);
}
function withdraw(uint256 _amount, address _token) external {
require(permissions[STATUS.RESERVETOKEN][_token], notAccepted);
require(permissions[STATUS.RESERVESPENDER][msg.sender], notApproved);
IKonduxERC20(_token).transfer(msg.sender, _amount);
emit Withdrawal(_token, _amount);
}
receive() external payable {
emit EtherDeposit(msg.value);
}
fallback() external payable {
emit EtherDeposit(msg.value);
}
function withdrawEther(uint _amount) external {
require(permissions[STATUS.RESERVESPENDER][msg.sender], notApproved);
require(payable(msg.sender).send(_amount));
emit EtherWithdrawal(msg.sender, _amount);
}
function setPermission(
STATUS _status,
address _address,
bool _permission
) public onlyGovernor {
require(_address != address(0), "Treasury Permission: zero address");
permissions[_status][_address] = _permission;
if (_status == STATUS.RESERVETOKEN) {
isTokenApproved[_address] = _permission;
if (_permission) {
approvedTokensList.push(_address);
approvedTokensCount++;
}
}
}
function setStakingContract(address _stakingContract) public onlyGovernor {
require(_stakingContract != address(0), "Treasury SetStakingContract: zero address");
require(_stakingContract != stakingContract, "Treasury SetStakingContract: same address");
stakingContract = _stakingContract;
}
function erc20ApprovalSetup(address _token, uint256 _amount) public onlyGovernor {
IKonduxERC20(_token).approve(stakingContract, _amount);
}
function getApprovedTokensList() public view returns (address[] memory) {
return approvedTokensList;
}
function getApprovedTokensCount() public view returns (uint256) {
return approvedTokensCount;
}
function getApprovedToken(uint256 _index) public view returns (address) {
return approvedTokensList[_index];
}
function getApprovedTokenAllowance(address _token) public view returns (uint256) {
return IKonduxERC20(_token).allowance(stakingContract, _token);
}
function getApprovedTokenBalance(address _token) public view returns (uint256) {
return IKonduxERC20(_token).balanceOf(address(this));
}
function getEtherBalance() public view returns (uint256) {
return address(this).balance;
}
function getStakingContract() public view returns (address) {
return stakingContract;
}
function getStakingContractAllowance(address _token) public view returns (uint256) {
return IKonduxERC20(_token).allowance(address(this), stakingContract);
}
function getStakingContractBalance(address _token) public view returns (uint256) {
return IKonduxERC20(_token).balanceOf(stakingContract);
}
function getStakingContractEtherBalance() public view returns (uint256) {
return stakingContract.balance;
}
}
{
"compilationTarget": {
"contracts/Treasury.sol": "Treasury"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "none",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 800
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_authority","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IAuthority","name":"authority","type":"address"}],"name":"AuthorityUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"DepositEther","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"EtherDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"EtherWithdrawal","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdrawal","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"approvedTokensCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"approvedTokensList","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"authority","outputs":[{"internalType":"contract IAuthority","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_token","type":"address"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositEther","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"erc20ApprovalSetup","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"getApprovedToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"getApprovedTokenAllowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"getApprovedTokenBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getApprovedTokensCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getApprovedTokensList","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getEtherBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getStakingContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"getStakingContractAllowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"getStakingContractBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getStakingContractEtherBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isTokenApproved","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum Treasury.STATUS","name":"","type":"uint8"},{"internalType":"address","name":"","type":"address"}],"name":"permissions","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IAuthority","name":"_newAuthority","type":"address"}],"name":"setAuthority","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum Treasury.STATUS","name":"_status","type":"uint8"},{"internalType":"address","name":"_address","type":"address"},{"internalType":"bool","name":"_permission","type":"bool"}],"name":"setPermission","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_stakingContract","type":"address"}],"name":"setStakingContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stakingContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_token","type":"address"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawEther","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]