Latest 25 from a total of 766 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Accure Interest | 44840656 | 13 hrs ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 44797474 | 37 hrs ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 44754260 | 2 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 44711078 | 3 days ago | IN | 0 ETH | 0.00000033 | ||||
| Accure Interest | 44667868 | 4 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 44581481 | 6 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 44538270 | 7 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 44495060 | 8 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 44451878 | 9 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 44408668 | 10 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 44365460 | 11 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 44279070 | 13 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 44235890 | 14 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 44192668 | 15 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 44149459 | 16 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 44106279 | 17 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 44063067 | 18 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 43976674 | 20 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 43933465 | 21 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 43890283 | 22 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 43847075 | 23 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 43803866 | 24 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 43760675 | 25 days ago | IN | 0 ETH | 0.00000032 | ||||
| Accure Interest | 43674267 | 27 days ago | IN | 0 ETH | 0.00000278 | ||||
| Accure Interest | 43631056 | 28 days ago | IN | 0 ETH | 0.00000032 |
Cross-Chain Transactions
Loading...
Loading
Contract Name:
WooLendingManager
Compiler Version
v0.8.14+commit.80d49f37
Optimization Enabled:
Yes with 20000 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity =0.8.14;
/*
░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
*
* MIT License
* ===========
*
* Copyright (c) 2020 WooTrade
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import "./WooSuperChargerVaultV2.sol";
import "../interfaces/IWETH.sol";
import "../interfaces/IWooAccessManager.sol";
import "../interfaces/IWooPPV2.sol";
import "../libraries/TransferHelper.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
contract WooLendingManager is Ownable, ReentrancyGuard {
event Borrow(address indexed user, uint256 assets);
event Repay(address indexed user, uint256 assets, uint256 perfFee);
event InterestRateUpdated(address indexed user, uint256 oldInterest, uint256 newInterest);
address public weth;
address public want;
address public accessManager;
address public wooPP;
WooSuperChargerVaultV2 public superChargerVault;
uint256 public borrowedPrincipal;
uint256 public borrowedInterest;
uint256 public perfRate = 1000; // 1 in 10000th. 1000 = 10%
address public treasury;
uint256 public interestRate; // 1 in 10000th. 1 = 0.01% (1 bp), 10 = 0.1% (10 bps)
uint256 public lastAccuredTs; // Timestamp of last accured interests
mapping(address => bool) public isBorrower;
address constant ETH_PLACEHOLDER_ADDR = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
constructor() {}
function init(
address _weth,
address _want,
address _accessManager,
address _wooPP,
address payable _superChargerVault
) external onlyOwner {
weth = _weth;
want = _want;
accessManager = _accessManager;
wooPP = _wooPP;
superChargerVault = WooSuperChargerVaultV2(_superChargerVault);
lastAccuredTs = block.timestamp;
treasury = 0x4094D7A17a387795838c7aba4687387B0d32BCf3;
}
modifier onlyAdmin() {
require(
owner() == msg.sender || IWooAccessManager(accessManager).isVaultAdmin(msg.sender),
"WooLendingManager: !ADMIN"
);
_;
}
modifier onlyBorrower() {
require(isBorrower[msg.sender] || msg.sender == wooPP, "WooLendingManager: !borrower");
_;
}
modifier onlySuperChargerVault() {
require(msg.sender == address(superChargerVault), "WooLendingManager: !superChargerVault");
_;
}
function setSuperChargerVault(address payable _wooSuperCharger) external onlyOwner {
superChargerVault = WooSuperChargerVaultV2(_wooSuperCharger);
}
function setWooPP(address _wooPP) external onlyOwner {
wooPP = _wooPP;
}
function setBorrower(address _borrower, bool _isBorrower) external onlyOwner {
isBorrower[_borrower] = _isBorrower;
}
function setPerfRate(uint256 _rate) external onlyAdmin {
require(_rate < 10000);
perfRate = _rate;
}
function debt() public view returns (uint256 assets) {
return borrowedPrincipal + borrowedInterest;
}
function debtAfterPerfFee() public view returns (uint256 assets) {
return debt();
}
function borrowState()
external
view
returns (
uint256 total,
uint256 principal,
uint256 interest,
uint256 borrowable
)
{
total = debt();
principal = borrowedPrincipal;
interest = borrowedInterest;
borrowable = superChargerVault.maxBorrowableAmount();
}
function accureInterest() public {
uint256 currentTs = block.timestamp;
// CAUTION: block.timestamp may be out of order
if (currentTs <= lastAccuredTs) {
return;
}
uint256 duration = currentTs - lastAccuredTs;
// interestRate is in 10000th.
// 31536000 = 365 * 24 * 3600 (1 year of seconds)
uint256 interest = (borrowedPrincipal * interestRate * duration) / 31536000 / 10000;
borrowedInterest = borrowedInterest + interest;
lastAccuredTs = currentTs;
}
function setInterestRate(uint256 _rate) external onlyAdmin {
require(_rate <= 50000, "RATE_INVALID"); // NOTE: rate < 500%
accureInterest();
uint256 oldInterest = interestRate;
interestRate = _rate;
emit InterestRateUpdated(msg.sender, oldInterest, _rate);
}
function setTreasury(address _treasury) external onlyAdmin {
require(_treasury != address(0), "WooLendingManager: !_treasury");
treasury = _treasury;
}
function maxBorrowableAmount() external view returns (uint256) {
return superChargerVault.maxBorrowableAmount();
}
/// @dev Borrow the fund from super charger and then deposit directly into WooPP.
/// @param amount the borrowing amount
function borrow(uint256 amount) external onlyBorrower {
require(amount > 0, "!AMOUNT");
accureInterest();
borrowedPrincipal = borrowedPrincipal + amount;
uint256 preBalance = IERC20(want).balanceOf(address(this));
superChargerVault.borrowFromLendingManager(amount, address(this));
uint256 afterBalance = IERC20(want).balanceOf(address(this));
require(afterBalance - preBalance == amount, "WooLendingManager: BORROW_AMOUNT_ERROR");
TransferHelper.safeApprove(want, wooPP, amount);
IWooPPV2(wooPP).deposit(want, amount);
emit Borrow(msg.sender, amount);
}
// NOTE: this is the view function;
// Remember to call the accureInterest to ensure the latest repayment state.
function weeklyRepayment() public view returns (uint256 repayAmount) {
(repayAmount, , , ) = weeklyRepaymentBreakdown();
}
function weeklyRepaymentBreakdown()
public
view
returns (
uint256 repayAmount,
uint256 principal,
uint256 interest,
uint256 perfFee
)
{
uint256 neededAmount = superChargerVault.weeklyNeededAmountForWithdraw();
if (neededAmount == 0) {
return (0, 0, 0, 0);
}
if (neededAmount <= borrowedInterest) {
interest = neededAmount;
principal = 0;
} else {
interest = borrowedInterest;
principal = neededAmount - borrowedInterest;
}
perfFee = (interest * perfRate) / 10000;
repayAmount = principal + interest + perfFee;
}
function repayWeekly() external onlyBorrower returns (uint256 repaidAmount) {
accureInterest();
uint256 _principal;
uint256 _interest;
(, _principal, _interest, ) = weeklyRepaymentBreakdown();
return _repay(_principal, _interest);
}
function repayAll() external onlyBorrower returns (uint256 repaidAmount) {
accureInterest();
return _repay(borrowedPrincipal, borrowedInterest);
}
// NOTE: repay the specified principal amount with all the borrowed interest
function repayPrincipal(uint256 _principal) external onlyBorrower returns (uint256 repaidAmount) {
accureInterest();
return _repay(_principal, borrowedInterest);
}
function _repay(uint256 _principal, uint256 _interest) private returns (uint256 repaidAmount) {
if (_principal == 0 && _interest == 0) {
emit Repay(msg.sender, 0, 0);
return 0;
}
uint256 _perfFee = (_interest * perfRate) / 10000;
uint256 _totalAmount = _principal + _interest + _perfFee;
TransferHelper.safeTransferFrom(want, msg.sender, address(this), _totalAmount);
borrowedInterest -= _interest;
borrowedPrincipal -= _principal;
TransferHelper.safeTransfer(want, treasury, _perfFee);
TransferHelper.safeApprove(want, address(superChargerVault), _principal + _interest);
superChargerVault.repayFromLendingManager(_principal + _interest);
emit Repay(msg.sender, _totalAmount, _perfFee);
return _totalAmount;
}
function inCaseTokenGotStuck(address stuckToken) external onlyOwner {
if (stuckToken == ETH_PLACEHOLDER_ADDR) {
TransferHelper.safeTransferETH(msg.sender, address(this).balance);
} else {
uint256 amount = IERC20(stuckToken).balanceOf(address(this));
TransferHelper.safeTransfer(stuckToken, msg.sender, amount);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(address from, address to, uint256 amount) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
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));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
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));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
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));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
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);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
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");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
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");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
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");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
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");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
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);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
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);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
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);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
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 {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastValue;
// Update the index for the moved value
set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.14;
/*
░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
*
* MIT License
* ===========
*
* Copyright (c) 2020 WooTrade
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import "../interfaces/IStrategy.sol";
import "../interfaces/IWETH.sol";
import "../interfaces/IWooAccessManager.sol";
import "../interfaces/IVaultV2.sol";
import "../interfaces/IMasterChefWoo.sol";
import "./WooWithdrawManagerV2.sol";
import "./WooLendingManager.sol";
import "../libraries/TransferHelper.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
contract WooSuperChargerVaultV2 is ERC20, Ownable, Pausable, ReentrancyGuard {
using EnumerableSet for EnumerableSet.AddressSet;
event Deposit(address indexed depositor, address indexed receiver, uint256 assets, uint256 shares);
event RequestWithdraw(address indexed owner, uint256 assets, uint256 shares);
event InstantWithdraw(address indexed owner, uint256 assets, uint256 shares, uint256 fees);
event WeeklySettleStarted(address indexed caller, uint256 totalRequestedShares, uint256 weeklyRepayAmount);
event WeeklySettleEnded(
address indexed caller,
uint256 totalBalance,
uint256 lendingBalance,
uint256 reserveBalance
);
event ReserveVaultMigrated(address indexed user, address indexed oldVault, address indexed newVault);
event SuperChargerVaultMigrated(
address indexed user,
address indexed oldVault,
address indexed newVault,
uint256 amount
);
event LendingManagerUpdated(address formerLendingManager, address newLendingManager);
event WithdrawManagerUpdated(address formerWithdrawManager, address newWithdrawManager);
event InstantWithdrawFeeRateUpdated(uint256 formerFeeRate, uint256 newFeeRate);
/* ----- State Variables ----- */
address constant ETH_PLACEHOLDER_ADDR = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
IVaultV2 public reserveVault;
address public migrationVault;
WooLendingManager public lendingManager;
WooWithdrawManagerV2 public withdrawManager;
address public immutable want;
address public immutable weth;
IWooAccessManager public immutable accessManager;
mapping(address => uint256) public costSharePrice;
mapping(address => uint256) public requestedWithdrawShares; // Requested withdrawn amount (in assets, NOT shares)
uint256 public requestedTotalShares;
EnumerableSet.AddressSet private requestUsers;
uint256 public instantWithdrawCap; // Max instant withdraw amount (in assets, per week)
uint256 public instantWithdrawnAmount; // Withdrawn amout already consumed (in assets, per week)
bool public isSettling;
address public treasury = 0x815D4517427Fc940A90A5653cdCEA1544c6283c9;
uint256 public instantWithdrawFeeRate = 30; // 1 in 10000th. default: 30 -> 0.3%
uint256 public maxWithdrawCount = 300;
address public masterChef;
uint256 public pid;
constructor(
address _weth,
address _want,
address _accessManager
)
ERC20(
string(abi.encodePacked("WOOFi Super Charger ", ERC20(_want).name())),
string(abi.encodePacked("we", ERC20(_want).symbol()))
)
{
require(_weth != address(0), "WooSuperChargerVault: !weth");
require(_want != address(0), "WooSuperChargerVault: !want");
require(_accessManager != address(0), "WooSuperChargerVault: !accessManager");
weth = _weth;
want = _want;
accessManager = IWooAccessManager(_accessManager);
}
function init(
address _reserveVault,
address _lendingManager,
address payable _withdrawManager
) external onlyOwner {
require(_reserveVault != address(0), "WooSuperChargerVault: !_reserveVault");
require(_lendingManager != address(0), "WooSuperChargerVault: !_lendingManager");
require(_withdrawManager != address(0), "WooSuperChargerVault: !_withdrawManager");
reserveVault = IVaultV2(_reserveVault);
require(reserveVault.want() == want);
lendingManager = WooLendingManager(_lendingManager);
withdrawManager = WooWithdrawManagerV2(_withdrawManager);
}
modifier onlyAdmin() {
require(owner() == msg.sender || accessManager.isVaultAdmin(msg.sender), "WooSuperChargerVault: !ADMIN");
_;
}
modifier onlyLendingManager() {
require(msg.sender == address(lendingManager), "WooSuperChargerVault: !lendingManager");
_;
}
/* ----- External Functions ----- */
function setMasterChef(address _masterChef, uint256 _pid) external onlyOwner {
require(_masterChef != address(0), "!_masterChef");
masterChef = _masterChef;
pid = _pid;
(IERC20 weToken, , , , ) = IMasterChefWoo(masterChef).poolInfo(pid);
require(address(weToken) == address(this), "!pid");
}
function stakedShares(address _user) public view returns (uint256 shares) {
if (masterChef == address(0)) {
shares = 0;
} else {
(shares, ) = IMasterChefWoo(masterChef).userInfo(pid, _user);
}
}
function deposit(uint256 amount) external payable whenNotPaused nonReentrant {
_deposit(amount, msg.sender);
}
function deposit(uint256 amount, address receiver) external payable whenNotPaused nonReentrant {
_deposit(amount, receiver);
}
function _deposit(uint256 amount, address receiver) private {
if (amount == 0) {
return;
}
lendingManager.accureInterest();
uint256 shares = _shares(amount, getPricePerFullShare());
require(shares > 0, "!shares");
uint256 sharesBefore = balanceOf(receiver) + stakedShares(receiver);
uint256 costBefore = costSharePrice[receiver];
uint256 costAfter = (sharesBefore * costBefore + amount * 1e18) / (sharesBefore + shares);
costSharePrice[receiver] = costAfter;
if (want == weth) {
require(amount == msg.value, "WooSuperChargerVault: msg.value_INSUFFICIENT");
reserveVault.deposit{value: msg.value}(amount);
} else {
TransferHelper.safeTransferFrom(want, msg.sender, address(this), amount);
TransferHelper.safeApprove(want, address(reserveVault), amount);
reserveVault.deposit(amount);
}
_mint(receiver, shares);
instantWithdrawCap = instantWithdrawCap + amount / 10;
emit Deposit(msg.sender, receiver, amount, shares);
}
function instantWithdraw(uint256 amount) external whenNotPaused nonReentrant {
_instantWithdrawShares(_sharesUpLatest(amount), msg.sender);
}
function instantWithdrawAll() external whenNotPaused nonReentrant {
_instantWithdrawShares(balanceOf(msg.sender), msg.sender);
}
function _instantWithdrawShares(uint256 shares, address owner) private {
require(shares > 0, "WooSuperChargerVault: !amount");
require(!isSettling, "WooSuperChargerVault: NOT_ALLOWED_IN_SETTLING");
if (instantWithdrawnAmount >= instantWithdrawCap) {
// NOTE: no more instant withdraw quota.
return;
}
lendingManager.accureInterest();
uint256 amount = _assets(shares);
require(amount <= instantWithdrawCap - instantWithdrawnAmount, "WooSuperChargerVault: OUT_OF_CAP");
if (msg.sender != owner) {
_spendAllowance(owner, msg.sender, shares);
}
_burn(owner, shares);
uint256 reserveShares = _sharesUp(amount, reserveVault.getPricePerFullShare());
reserveVault.withdraw(reserveShares);
uint256 fee = accessManager.isZeroFeeVault(msg.sender) ? 0 : (amount * instantWithdrawFeeRate) / 10000;
if (want == weth) {
TransferHelper.safeTransferETH(treasury, fee);
TransferHelper.safeTransferETH(owner, amount - fee);
} else {
TransferHelper.safeTransfer(want, treasury, fee);
TransferHelper.safeTransfer(want, owner, amount - fee);
}
instantWithdrawnAmount = instantWithdrawnAmount + amount;
emit InstantWithdraw(owner, amount, reserveShares, fee);
}
function migrateToNewVault() external whenNotPaused nonReentrant {
_migrateToNewVault(msg.sender);
}
function _migrateToNewVault(address owner) private {
require(owner != address(0), "WooSuperChargerVault: !owner");
require(migrationVault != address(0), "WooSuperChargerVault: !migrationVault");
WooSuperChargerVaultV2 newVault = WooSuperChargerVaultV2(payable(migrationVault));
require(newVault.want() == want, "WooSuperChargerVault: !WANT_newVault");
uint256 shares = balanceOf(owner);
if (shares == 0) {
return;
}
lendingManager.accureInterest();
uint256 amount = _assets(shares);
if (msg.sender != owner) {
_spendAllowance(owner, msg.sender, shares);
}
_burn(owner, shares);
uint256 reserveShares = _sharesUp(amount, reserveVault.getPricePerFullShare());
reserveVault.withdraw(reserveShares);
if (want == weth) {
newVault.deposit{value: amount}(amount, owner);
} else {
TransferHelper.safeApprove(want, address(newVault), amount);
newVault.deposit(amount, owner);
}
emit SuperChargerVaultMigrated(owner, address(this), address(newVault), amount);
}
function requestWithdraw(uint256 amount) external whenNotPaused nonReentrant {
_requestWithdrawShares(_sharesUpLatest(amount));
}
function requestWithdrawAll() external whenNotPaused nonReentrant {
_requestWithdrawShares(balanceOf(msg.sender));
}
function _requestWithdrawShares(uint256 shares) private {
require(shares > 0, "WooSuperChargerVault: !amount");
require(!isSettling, "WooSuperChargerVault: CANNOT_WITHDRAW_IN_SETTLING");
require(requestUsers.length() <= maxWithdrawCount, "WooSuperChargerVault: MAX_WITHDRAW_COUNT");
address owner = msg.sender;
lendingManager.accureInterest();
uint256 amount = _assets(shares);
TransferHelper.safeTransferFrom(address(this), owner, address(this), shares);
requestedWithdrawShares[owner] = requestedWithdrawShares[owner] + shares;
requestedTotalShares = requestedTotalShares + shares;
requestUsers.add(owner);
emit RequestWithdraw(owner, amount, shares);
}
function requestedTotalAmount() public view returns (uint256) {
return _assets(requestedTotalShares);
}
function totalRequestedUserNumber() external view returns (uint256 totalNumber) {
return requestUsers.length();
}
function requestedWithdrawAmount(address user) public view returns (uint256) {
return _assets(requestedWithdrawShares[user]);
}
function available() public view returns (uint256) {
return IERC20(want).balanceOf(address(this));
}
function reserveBalance() public view returns (uint256) {
return _assets(IERC20(address(reserveVault)).balanceOf(address(this)), reserveVault.getPricePerFullShare());
}
function lendingBalance() public view returns (uint256) {
return lendingManager.debtAfterPerfFee();
}
// Returns the total balance (assets), which is avaiable + reserve + lending.
function balance() public view returns (uint256) {
return available() + reserveBalance() + lendingBalance();
}
function getPricePerFullShare() public view returns (uint256) {
return totalSupply() == 0 ? 1e18 : (balance() * 1e18) / totalSupply();
}
// --- For WooLendingManager --- //
function maxBorrowableAmount() public view returns (uint256) {
uint256 resBal = reserveBalance();
uint256 instWithdrawBal = instantWithdrawCap - instantWithdrawnAmount;
return resBal > instWithdrawBal ? resBal - instWithdrawBal : 0;
}
function borrowFromLendingManager(uint256 amount, address fundAddr) external onlyLendingManager {
require(!isSettling, "IN SETTLING");
require(amount <= maxBorrowableAmount(), "INSUFF_AMOUNT_FOR_BORROW");
uint256 sharesToWithdraw = _sharesUp(amount, reserveVault.getPricePerFullShare());
reserveVault.withdraw(sharesToWithdraw);
if (want == weth) {
IWETH(weth).deposit{value: amount}();
}
TransferHelper.safeTransfer(want, fundAddr, amount);
}
function repayFromLendingManager(uint256 amount) external onlyLendingManager {
TransferHelper.safeTransferFrom(want, msg.sender, address(this), amount);
if (want == weth) {
IWETH(weth).withdraw(amount);
reserveVault.deposit{value: amount}(amount);
} else {
TransferHelper.safeApprove(want, address(reserveVault), amount);
reserveVault.deposit(amount);
}
}
// --- Admin operations --- //
function weeklyNeededAmountForWithdraw() public view returns (uint256) {
uint256 reserveBal = reserveBalance();
uint256 requestedAmount = requestedTotalAmount();
uint256 afterBal = balance() - requestedAmount;
return reserveBal >= requestedAmount + afterBal / 10 ? 0 : requestedAmount + afterBal / 10 - reserveBal;
}
function startWeeklySettle() external onlyAdmin {
require(!isSettling, "IN_SETTLING");
isSettling = true;
lendingManager.accureInterest();
emit WeeklySettleStarted(msg.sender, requestedTotalShares, weeklyNeededAmountForWithdraw());
}
function endWeeklySettle() public onlyAdmin {
require(isSettling, "!SETTLING");
require(weeklyNeededAmountForWithdraw() == 0, "WEEKLY_REPAY_NOT_CLEARED");
// NOTE: Do need accureInterest here, since it's already been updated in `startWeeklySettle`
uint256 sharePrice = getPricePerFullShare();
isSettling = false;
uint256 totalWithdrawAmount = requestedTotalAmount();
if (totalWithdrawAmount != 0) {
uint256 shares = _sharesUp(totalWithdrawAmount, reserveVault.getPricePerFullShare());
reserveVault.withdraw(shares);
if (want == weth) {
IWETH(weth).deposit{value: totalWithdrawAmount}();
}
require(available() >= totalWithdrawAmount);
uint256 length = requestUsers.length();
for (uint256 i = 0; i < length; i++) {
address user = requestUsers.at(0);
withdrawManager.addWithdrawAmount(user, (requestedWithdrawShares[user] * sharePrice) / 1e18);
requestedWithdrawShares[user] = 0;
requestUsers.remove(user);
}
_burn(address(this), requestedTotalShares);
requestedTotalShares = 0;
TransferHelper.safeTransfer(want, address(withdrawManager), totalWithdrawAmount);
}
instantWithdrawnAmount = 0;
lendingManager.accureInterest();
uint256 totalBalance = balance();
instantWithdrawCap = totalBalance / 10;
emit WeeklySettleEnded(msg.sender, totalBalance, lendingBalance(), reserveBalance());
}
function migrateReserveVault(address _vault) external onlyOwner {
require(_vault != address(0), "!_vault");
uint256 preBal = (want == weth) ? address(this).balance : available();
reserveVault.withdraw(IERC20(address(reserveVault)).balanceOf(address(this)));
uint256 afterBal = (want == weth) ? address(this).balance : available();
uint256 reserveAmount = afterBal - preBal;
address oldVault = address(reserveVault);
reserveVault = IVaultV2(_vault);
require(reserveVault.want() == want, "INVALID_WANT");
if (want == weth) {
reserveVault.deposit{value: reserveAmount}(reserveAmount);
} else {
TransferHelper.safeApprove(want, address(reserveVault), reserveAmount);
reserveVault.deposit(reserveAmount);
}
emit ReserveVaultMigrated(msg.sender, oldVault, _vault);
}
function inCaseTokenGotStuck(address stuckToken) external onlyOwner {
if (stuckToken == ETH_PLACEHOLDER_ADDR) {
TransferHelper.safeTransferETH(msg.sender, address(this).balance);
} else {
uint256 amount = IERC20(stuckToken).balanceOf(address(this));
TransferHelper.safeTransfer(stuckToken, msg.sender, amount);
}
}
function setLendingManager(address _lendingManager) external onlyOwner {
address formerManager = address(lendingManager);
lendingManager = WooLendingManager(_lendingManager);
emit LendingManagerUpdated(formerManager, _lendingManager);
}
function setWithdrawManager(address payable _withdrawManager) external onlyOwner {
address formerManager = address(withdrawManager);
withdrawManager = WooWithdrawManagerV2(_withdrawManager);
emit WithdrawManagerUpdated(formerManager, _withdrawManager);
}
function setTreasury(address _treasury) external onlyOwner {
treasury = _treasury;
}
function setMaxWithdrawCount(uint256 _maxWithdrawCount) external onlyOwner {
maxWithdrawCount = _maxWithdrawCount;
}
function setInstantWithdrawFeeRate(uint256 _feeRate) external onlyOwner {
uint256 formerFeeRate = instantWithdrawFeeRate;
instantWithdrawFeeRate = _feeRate;
emit InstantWithdrawFeeRateUpdated(formerFeeRate, _feeRate);
}
function setInstantWithdrawCap(uint256 _instantWithdrawCap) external onlyOwner {
instantWithdrawCap = _instantWithdrawCap;
}
function setMigrationVault(address _vault) external onlyOwner {
migrationVault = _vault;
WooSuperChargerVaultV2 newVault = WooSuperChargerVaultV2(payable(_vault));
require(newVault.want() == want, "WooSuperChargerVault: !WANT_vault");
}
function pause() public onlyAdmin {
_pause();
}
function unpause() external onlyAdmin {
_unpause();
}
receive() external payable {}
function _assets(uint256 shares) private view returns (uint256) {
return _assets(shares, getPricePerFullShare());
}
function _assets(uint256 shares, uint256 sharePrice) private pure returns (uint256) {
return (shares * sharePrice) / 1e18;
}
function _shares(uint256 assets, uint256 sharePrice) private pure returns (uint256) {
return (assets * 1e18) / sharePrice;
}
function _sharesUpLatest(uint256 assets) private returns (uint256) {
lendingManager.accureInterest();
return _sharesUp(assets, getPricePerFullShare());
}
function _sharesUp(uint256 assets, uint256 sharePrice) private pure returns (uint256) {
uint256 shares = (assets * 1e18) / sharePrice;
return _assets(shares, sharePrice) == assets ? shares : shares + 1;
}
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.14;
/*
░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
*
* MIT License
* ===========
*
* Copyright (c) 2020 WooTrade
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import "../interfaces/IWETH.sol";
import "../interfaces/IWooAccessManager.sol";
import "../libraries/TransferHelper.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
contract WooWithdrawManagerV2 is Ownable, ReentrancyGuard {
// addedAmount: added withdrawal amount for this user
// totalAmount: total withdrawal amount for this user
event WithdrawAdded(address indexed user, uint256 addedAmount, uint256 totalAmount);
event Withdraw(address indexed user, uint256 amount);
address public want;
address public weth;
address public accessManager;
address public superChargerVault;
mapping(address => uint256) public withdrawAmount;
address constant ETH_PLACEHOLDER_ADDR = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
constructor() {}
function init(
address _weth,
address _want,
address _accessManager,
address _superChargerVault
) external onlyOwner {
weth = _weth;
want = _want;
accessManager = _accessManager;
superChargerVault = _superChargerVault;
}
modifier onlyAdmin() {
require(
owner() == msg.sender || IWooAccessManager(accessManager).isVaultAdmin(msg.sender),
"WooWithdrawManager: !owner"
);
_;
}
modifier onlySuperChargerVault() {
require(superChargerVault == msg.sender, "WooWithdrawManager: !superChargerVault");
_;
}
function setSuperChargerVault(address _superChargerVault) external onlyAdmin {
superChargerVault = _superChargerVault;
}
function addWithdrawAmount(address user, uint256 amount) external onlySuperChargerVault {
// NOTE: in V2, granular token transfer is avoided to save the gas consumption;
// Do remember batch transfer the total amount of `want` tokens after calling this method.
// TransferHelper.safeTransferFrom(want, msg.sender, address(this), amount);
withdrawAmount[user] = withdrawAmount[user] + amount;
emit WithdrawAdded(user, amount, withdrawAmount[user]);
}
function withdraw() external nonReentrant {
uint256 amount = withdrawAmount[msg.sender];
if (amount == 0) {
return;
}
withdrawAmount[msg.sender] = 0;
if (want == weth) {
IWETH(weth).withdraw(amount);
TransferHelper.safeTransferETH(msg.sender, amount);
} else {
TransferHelper.safeTransfer(want, msg.sender, amount);
}
emit Withdraw(msg.sender, amount);
}
function inCaseTokenGotStuck(address stuckToken) external onlyOwner {
require(stuckToken != want);
if (stuckToken == ETH_PLACEHOLDER_ADDR) {
TransferHelper.safeTransferETH(msg.sender, address(this).balance);
} else {
uint256 amount = IERC20(stuckToken).balanceOf(address(this));
TransferHelper.safeTransfer(stuckToken, msg.sender, amount);
}
}
receive() external payable {}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.14;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IRewarder.sol";
interface IMasterChefWoo {
event PoolAdded(uint256 poolId, uint256 allocPoint, IERC20 weToken, IRewarder rewarder);
event PoolSet(uint256 poolId, uint256 allocPoint, IRewarder rewarder);
event PoolUpdated(uint256 poolId, uint256 lastRewardBlock, uint256 supply, uint256 accTokenPerShare);
event XWooPerBlockUpdated(uint256 xWooPerBlock);
event Deposit(address indexed user, uint256 indexed pid, uint256 amount);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);
event Harvest(address indexed user, uint256 indexed pid, uint256 amount);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);
struct UserInfo {
uint256 amount;
uint256 rewardDebt;
}
struct PoolInfo {
IERC20 weToken;
uint256 allocPoint;
uint256 lastRewardBlock;
uint256 accTokenPerShare;
IRewarder rewarder;
}
// System-level function
function setXWooPerBlock(uint256 _xWooPerBlock) external;
// Pool-related functions
function poolLength() external view returns (uint256);
function add(
uint256 allocPoint,
IERC20 weToken,
IRewarder rewarder
) external;
function set(
uint256 pid,
uint256 allocPoint,
IRewarder rewarder
) external;
function massUpdatePools() external;
function updatePool(uint256 pid) external;
// User-related functions
function pendingXWoo(uint256 pid, address user) external view returns (uint256, uint256);
function deposit(uint256 pid, uint256 amount) external;
function withdraw(uint256 pid, uint256 amount) external;
function harvest(uint256 pid) external;
function emergencyWithdraw(uint256 pid) external;
function userInfo(uint256 pid, address user) external view returns (uint256 amount, uint256 rewardDebt);
function poolInfo(uint256 pid)
external
view
returns (
IERC20 weToken,
uint256 allocPoint,
uint256 lastRewardBlock,
uint256 accTokenPerShare,
IRewarder rewarder
);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.14;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IRewarder {
event OnRewarded(address indexed user, uint256 amount);
event RewardRateUpdated(uint256 oldRate, uint256 newRate);
struct UserInfo {
uint256 amount;
uint256 rewardDebt;
uint256 unpaidRewards;
}
struct PoolInfo {
uint256 accTokenPerShare;
uint256 lastRewardBlock;
}
function onRewarded(address user, uint256 amount) external;
function pendingTokens(address user) external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.14;
/*
░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
*
* MIT License
* ===========
*
* Copyright (c) 2020 WooTrade
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
interface IStrategy {
function vault() external view returns (address);
function want() external view returns (address);
function beforeDeposit() external;
function beforeWithdraw() external;
function deposit() external;
function withdraw(uint256) external;
function balanceOf() external view returns (uint256);
function balanceOfWant() external view returns (uint256);
function balanceOfPool() external view returns (uint256);
function harvest() external;
function retireStrat() external;
function emergencyExit() external;
function paused() external view returns (bool);
function inCaseTokensGetStuck(address stuckToken) external;
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.14;
interface IVaultV2 {
function want() external view returns (address);
function weth() external view returns (address);
function deposit(uint256 amount) external payable;
function withdraw(uint256 shares) external;
function earn() external;
function available() external view returns (uint256);
function balance() external view returns (uint256);
function getPricePerFullShare() external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Wrapped ETH.
interface IWETH {
/// @dev Deposit ETH into WETH
function deposit() external payable;
/// @dev Transfer WETH to receiver
/// @param to address of WETH receiver
/// @param value amount of WETH to transfer
/// @return get true when succeed, else false
function transfer(address to, uint256 value) external returns (bool);
/// @dev Withdraw WETH to ETH
function withdraw(uint256) external;
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.14;
/*
░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
*
* MIT License
* ===========
*
* Copyright (c) 2020 WooTrade
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/// @title Reward manager interface for WooFi Swap.
/// @notice this is for swap rebate or potential incentive program
interface IWooAccessManager {
/* ----- Events ----- */
event FeeAdminUpdated(address indexed feeAdmin, bool flag);
event VaultAdminUpdated(address indexed vaultAdmin, bool flag);
event RebateAdminUpdated(address indexed rebateAdmin, bool flag);
event ZeroFeeVaultUpdated(address indexed vault, bool flag);
/* ----- External Functions ----- */
function isFeeAdmin(address feeAdmin) external returns (bool);
function isVaultAdmin(address vaultAdmin) external returns (bool);
function isRebateAdmin(address rebateAdmin) external returns (bool);
function isZeroFeeVault(address vault) external returns (bool);
/* ----- Admin Functions ----- */
/// @notice Sets feeAdmin
function setFeeAdmin(address feeAdmin, bool flag) external;
/// @notice Sets vaultAdmin
function setVaultAdmin(address vaultAdmin, bool flag) external;
/// @notice Sets rebateAdmin
function setRebateAdmin(address rebateAdmin, bool flag) external;
/// @notice Sets zeroFeeVault
function setZeroFeeVault(address vault, bool flag) external;
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.14;
/*
░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
*
* MIT License
* ===========
*
* Copyright (c) 2020 WooTrade
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/// @title Woo private pool for swap.
/// @notice Use this contract to directly interfact with woo's synthetic proactive
/// marketing making pool.
/// @author woo.network
interface IWooPPV2 {
/* ----- Events ----- */
event Deposit(address indexed token, address indexed sender, uint256 amount);
event Withdraw(address indexed token, address indexed receiver, uint256 amount);
event Migrate(address indexed token, address indexed receiver, uint256 amount);
event AdminUpdated(address indexed addr, bool flag);
event PauseRoleUpdated(address indexed addr, bool flag);
event FeeAddrUpdated(address indexed newFeeAddr);
event WooracleUpdated(address indexed newWooracle);
event WooSwap(
address indexed fromToken,
address indexed toToken,
uint256 fromAmount,
uint256 toAmount,
address from,
address indexed to,
address rebateTo,
uint256 swapVol,
uint256 swapFee
);
/* ----- External Functions ----- */
/// @notice The quote token address (immutable).
/// @return address of quote token
function quoteToken() external view returns (address);
/// @notice Gets the pool size of the specified token (swap liquidity).
/// @param token the token address
/// @return the pool size
function poolSize(address token) external view returns (uint256);
/// @notice Query the amount to swap `fromToken` to `toToken`, without checking the pool reserve balance.
/// @param fromToken the from token
/// @param toToken the to token
/// @param fromAmount the amount of `fromToken` to swap
/// @return toAmount the swapped amount of `toToken`
function tryQuery(
address fromToken,
address toToken,
uint256 fromAmount
) external view returns (uint256 toAmount);
/// @notice Query the amount to swap `fromToken` to `toToken`, with checking the pool reserve balance.
/// @dev tx reverts when 'toToken' balance is insufficient.
/// @param fromToken the from token
/// @param toToken the to token
/// @param fromAmount the amount of `fromToken` to swap
/// @return toAmount the swapped amount of `toToken`
function query(
address fromToken,
address toToken,
uint256 fromAmount
) external view returns (uint256 toAmount);
/// @notice Swap `fromToken` to `toToken`.
/// @param fromToken the from token
/// @param toToken the to token
/// @param fromAmount the amount of `fromToken` to swap
/// @param minToAmount the minimum amount of `toToken` to receive
/// @param to the destination address
/// @param rebateTo the rebate address (optional, can be address ZERO)
/// @return realToAmount the amount of toToken to receive
function swap(
address fromToken,
address toToken,
uint256 fromAmount,
uint256 minToAmount,
address to,
address rebateTo
) external returns (uint256 realToAmount);
/// @notice Deposit the specified token into the liquidity pool of WooPPV2.
/// @param token the token to deposit
/// @param amount the deposit amount
function deposit(address token, uint256 amount) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @title TransferHelper
/// @notice Contains helper methods for interacting with ERC20 and native tokens that do not consistently return true/false
/// @dev implementation from https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/TransferHelper.sol
library TransferHelper {
/// @notice Transfers tokens from the targeted address to the given destination
/// @notice Errors with 'STF' if transfer fails
/// @param token The contract address of the token to be transferred
/// @param from The originating address from which the tokens will be transferred
/// @param to The destination address of the transfer
/// @param value The amount to be transferred
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
(bool success, bytes memory data) =
token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), "STF");
}
/// @notice Transfers tokens from msg.sender to a recipient
/// @dev Errors with ST if transfer fails
/// @param token The contract address of the token which will be transferred
/// @param to The recipient of the transfer
/// @param value The value of the transfer
function safeTransfer(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), "ST");
}
/// @notice Approves the stipulated contract to spend the given allowance in the given token
/// @dev Errors with 'SA' if transfer fails
/// @param token The contract address of the token to be approved
/// @param to The target of the approval
/// @param value The amount of the given token the target will be allowed to spend
function safeApprove(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), "SA");
}
/// @notice Transfers ETH to the recipient address
/// @dev Fails with `STE`
/// @param to The destination of the transfer
/// @param value The value to be transferred
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, "STE");
}
}{
"optimizer": {
"enabled": true,
"runs": 20000
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"Borrow","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"oldInterest","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newInterest","type":"uint256"}],"name":"InterestRateUpdated","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":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"perfFee","type":"uint256"}],"name":"Repay","type":"event"},{"inputs":[],"name":"accessManager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accureInterest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"borrow","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"borrowState","outputs":[{"internalType":"uint256","name":"total","type":"uint256"},{"internalType":"uint256","name":"principal","type":"uint256"},{"internalType":"uint256","name":"interest","type":"uint256"},{"internalType":"uint256","name":"borrowable","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"borrowedInterest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"borrowedPrincipal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"debt","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"debtAfterPerfFee","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"stuckToken","type":"address"}],"name":"inCaseTokenGotStuck","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_weth","type":"address"},{"internalType":"address","name":"_want","type":"address"},{"internalType":"address","name":"_accessManager","type":"address"},{"internalType":"address","name":"_wooPP","type":"address"},{"internalType":"address payable","name":"_superChargerVault","type":"address"}],"name":"init","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"interestRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isBorrower","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastAccuredTs","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxBorrowableAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"perfRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"repayAll","outputs":[{"internalType":"uint256","name":"repaidAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_principal","type":"uint256"}],"name":"repayPrincipal","outputs":[{"internalType":"uint256","name":"repaidAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"repayWeekly","outputs":[{"internalType":"uint256","name":"repaidAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_borrower","type":"address"},{"internalType":"bool","name":"_isBorrower","type":"bool"}],"name":"setBorrower","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_rate","type":"uint256"}],"name":"setInterestRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_rate","type":"uint256"}],"name":"setPerfRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_wooSuperCharger","type":"address"}],"name":"setSuperChargerVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_treasury","type":"address"}],"name":"setTreasury","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_wooPP","type":"address"}],"name":"setWooPP","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"superChargerVault","outputs":[{"internalType":"contract WooSuperChargerVaultV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"treasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"want","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weeklyRepayment","outputs":[{"internalType":"uint256","name":"repayAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weeklyRepaymentBreakdown","outputs":[{"internalType":"uint256","name":"repayAmount","type":"uint256"},{"internalType":"uint256","name":"principal","type":"uint256"},{"internalType":"uint256","name":"interest","type":"uint256"},{"internalType":"uint256","name":"perfFee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"wooPP","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]Contract Creation Code
60806040526103e860095534801561001657600080fd5b5061002033610029565b60018055610079565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6121de806100886000396000f3fe608060405234801561001057600080fd5b50600436106102265760003560e01c8063a373ed4e1161012a578063e1a4e72a116100bd578063f0f442601161008c578063fa3ae6dc11610071578063fa3ae6dc146104b3578063fcc7c4ed146104bb578063fdcb6068146104c457600080fd5b8063f0f442601461048d578063f2fde38b146104a057600080fd5b8063e1a4e72a14610436578063e5e2abf514610449578063eaf6e48314610452578063f077cbab1461048557600080fd5b8063d183a7a2116100f9578063d183a7a2146103de578063d736ce7c14610406578063d83e6b3814610426578063dbe08b561461042e57600080fd5b8063a373ed4e146103a8578063bab8583a146103b0578063c1ae359a146103c3578063c5ebeaec146103cb57600080fd5b80634bb2dcea116101bd57806361d027b31161018c5780637c3a00fd116101715780637c3a00fd146103785780637e452aff146103815780638da5cb5b1461038a57600080fd5b806361d027b314610350578063715018a61461037057600080fd5b80634bb2dcea1461031957806352c49c44146103215780635bc9f65d1461032a5780635f84f3021461033d57600080fd5b80633560df8c116101f95780633560df8c146102c0578063359ef75b146102d35780633fc8cef3146102e65780634422bc5a1461030657600080fd5b80630dca59c11461022b5780631779aacf146102465780631f1fcd511461025b578063245b74be146102a0575b600080fd5b6102336104e4565b6040519081526020015b60405180910390f35b610259610254366004611f6c565b6104fb565b005b60035461027b9073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200161023d565b60065461027b9073ffffffffffffffffffffffffffffffffffffffff1681565b6102336102ce366004611f90565b61054a565b6102596102e1366004611fa9565b610604565b60025461027b9073ffffffffffffffffffffffffffffffffffffffff1681565b610259610314366004612028565b6106b4565b610233610712565b61023360085481565b610259610338366004611f6c565b6107a6565b61025961034b366004611f90565b6107f5565b600a5461027b9073ffffffffffffffffffffffffffffffffffffffff1681565b6102596109e8565b610233600b5481565b610233600c5481565b60005473ffffffffffffffffffffffffffffffffffffffff1661027b565b6102596109fc565b6102596103be366004611f90565b610a6f565b610233610bba565b6102596103d9366004611f90565b610c81565b6103e66110de565b60408051948552602085019390935291830152606082015260800161023d565b60055461027b9073ffffffffffffffffffffffffffffffffffffffff1681565b6102336111f8565b6103e6611202565b610259610444366004611f6c565b6112b5565b61023360095481565b610475610460366004611f6c565b600d6020526000908152604090205460ff1681565b604051901515815260200161023d565b6102336113a9565b61025961049b366004611f6c565b6113bc565b6102596104ae366004611f6c565b6115b8565b61023361166c565b61023360075481565b60045461027b9073ffffffffffffffffffffffffffffffffffffffff1681565b60006008546007546104f69190612090565b905090565b61050361171d565b600680547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b336000908152600d602052604081205460ff168061057f575060055473ffffffffffffffffffffffffffffffffffffffff1633145b6105ea576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f576f6f4c656e64696e674d616e616765723a2021626f72726f7765720000000060448201526064015b60405180910390fd5b6105f26109fc565b6105fe8260085461179e565b92915050565b61060c61171d565b600280547fffffffffffffffffffffffff000000000000000000000000000000000000000090811673ffffffffffffffffffffffffffffffffffffffff978816179091556003805482169587169590951790945560048054851693861693909317909255600580548416918516919091179055600680548316919093161790915542600c55600a8054734094d7a17a387795838c7aba4687387b0d32bcf39216919091179055565b6106bc61171d565b73ffffffffffffffffffffffffffffffffffffffff919091166000908152600d6020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b600654604080517f4bb2dcea000000000000000000000000000000000000000000000000000000008152905160009273ffffffffffffffffffffffffffffffffffffffff1691634bb2dcea9160048083019260209291908290030181865afa158015610782573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104f691906120a8565b6107ae61171d565b600580547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b3361081560005473ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff1614806108c75750600480546040517faf5b052b000000000000000000000000000000000000000000000000000000008152339281019290925273ffffffffffffffffffffffffffffffffffffffff169063af5b052b906024016020604051808303816000875af11580156108a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108c791906120c1565b61092d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f576f6f4c656e64696e674d616e616765723a202141444d494e0000000000000060448201526064016105e1565b61c350811115610999576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f524154455f494e56414c4944000000000000000000000000000000000000000060448201526064016105e1565b6109a16109fc565b600b805490829055604080518281526020810184905233917f3aebbb85b9698ba4e1588e9f25e8e3bb8d3c5fb5199f6b36b362e6775947b383910160405180910390a25050565b6109f061171d565b6109fa600061199a565b565b600c5442908111610a0a5750565b6000600c5482610a1a91906120de565b905060006127106301e1338083600b54600754610a3791906120f5565b610a4191906120f5565b610a4b9190612132565b610a559190612132565b905080600854610a659190612090565b6008555050600c55565b33610a8f60005473ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff161480610b415750600480546040517faf5b052b000000000000000000000000000000000000000000000000000000008152339281019290925273ffffffffffffffffffffffffffffffffffffffff169063af5b052b906024016020604051808303816000875af1158015610b1d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b4191906120c1565b610ba7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f576f6f4c656e64696e674d616e616765723a202141444d494e0000000000000060448201526064016105e1565b6127108110610bb557600080fd5b600955565b336000908152600d602052604081205460ff1680610bef575060055473ffffffffffffffffffffffffffffffffffffffff1633145b610c55576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f576f6f4c656e64696e674d616e616765723a2021626f72726f7765720000000060448201526064016105e1565b610c5d6109fc565b600080610c686110de565b509093509150610c7a9050828261179e565b9250505090565b336000908152600d602052604090205460ff1680610cb6575060055473ffffffffffffffffffffffffffffffffffffffff1633145b610d1c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f576f6f4c656e64696e674d616e616765723a2021626f72726f7765720000000060448201526064016105e1565b60008111610d86576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600760248201527f21414d4f554e540000000000000000000000000000000000000000000000000060448201526064016105e1565b610d8e6109fc565b80600754610d9c9190612090565b6007556003546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009173ffffffffffffffffffffffffffffffffffffffff16906370a0823190602401602060405180830381865afa158015610e0e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e3291906120a8565b6006546040517f2ea9239e0000000000000000000000000000000000000000000000000000000081526004810185905230602482015291925073ffffffffffffffffffffffffffffffffffffffff1690632ea9239e90604401600060405180830381600087803b158015610ea557600080fd5b505af1158015610eb9573d6000803e3d6000fd5b50506003546040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526000935073ffffffffffffffffffffffffffffffffffffffff90911691506370a0823190602401602060405180830381865afa158015610f2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f5291906120a8565b905082610f5f83836120de565b14610fec576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f576f6f4c656e64696e674d616e616765723a20424f52524f575f414d4f554e5460448201527f5f4552524f52000000000000000000000000000000000000000000000000000060648201526084016105e1565b6003546005546110169173ffffffffffffffffffffffffffffffffffffffff908116911685611a0f565b6005546003546040517f47e7ef2400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9182166004820152602481018690529116906347e7ef2490604401600060405180830381600087803b15801561108c57600080fd5b505af11580156110a0573d6000803e3d6000fd5b50506040518581523392507fcbc04eca7e9da35cb1393a6135a199ca52e450d5e9251cbd99f7847d33a36750915060200160405180910390a2505050565b6000806000806000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636aa9eda26040518163ffffffff1660e01b8152600401602060405180830381865afa158015611153573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061117791906120a8565b905080600003611195576000806000809450945094509450506111f2565b60085481116111aa57809250600093506111bc565b60085492506111b983826120de565b93505b612710600954846111cd91906120f5565b6111d79190612132565b9150816111e48486612090565b6111ee9190612090565b9450505b90919293565b60006104f66104e4565b6000806000806112106104e4565b935060075492506008549150600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16634bb2dcea6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611289573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112ad91906120a8565b905090919293565b6112bd61171d565b7fffffffffffffffffffffffff111111111111111111111111111111111111111273ffffffffffffffffffffffffffffffffffffffff821601611307576113043347611b7f565b50565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009073ffffffffffffffffffffffffffffffffffffffff8316906370a0823190602401602060405180830381865afa158015611374573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061139891906120a8565b90506113a5823383611c68565b5050565b60006113b36110de565b50919392505050565b336113dc60005473ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff16148061148e5750600480546040517faf5b052b000000000000000000000000000000000000000000000000000000008152339281019290925273ffffffffffffffffffffffffffffffffffffffff169063af5b052b906024016020604051808303816000875af115801561146a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061148e91906120c1565b6114f4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f576f6f4c656e64696e674d616e616765723a202141444d494e0000000000000060448201526064016105e1565b73ffffffffffffffffffffffffffffffffffffffff8116611571576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f576f6f4c656e64696e674d616e616765723a20215f747265617375727900000060448201526064016105e1565b600a80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b6115c061171d565b73ffffffffffffffffffffffffffffffffffffffff8116611663576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f646472657373000000000000000000000000000000000000000000000000000060648201526084016105e1565b6113048161199a565b336000908152600d602052604081205460ff16806116a1575060055473ffffffffffffffffffffffffffffffffffffffff1633145b611707576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f576f6f4c656e64696e674d616e616765723a2021626f72726f7765720000000060448201526064016105e1565b61170f6109fc565b6104f660075460085461179e565b60005473ffffffffffffffffffffffffffffffffffffffff1633146109fa576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016105e1565b6000821580156117ac575081155b156117f457604080516000808252602082015233917f77c6871227e5d2dec8dadd5354f78453203e22e669cd0ec4c19d9a8c5edb31d0910160405180910390a25060006105fe565b60006127106009548461180791906120f5565b6118119190612132565b90506000816118208587612090565b61182a9190612090565b6003549091506118529073ffffffffffffffffffffffffffffffffffffffff16333084611dd1565b836008600082825461186491906120de565b92505081905550846007600082825461187d91906120de565b9091555050600354600a546118ac9173ffffffffffffffffffffffffffffffffffffffff908116911684611c68565b6003546006546118df9173ffffffffffffffffffffffffffffffffffffffff90811691166118da8789612090565b611a0f565b60065473ffffffffffffffffffffffffffffffffffffffff1663b5589fad6119078688612090565b6040518263ffffffff1660e01b815260040161192591815260200190565b600060405180830381600087803b15801561193f57600080fd5b505af1158015611953573d6000803e3d6000fd5b505060408051848152602081018690523393507f77c6871227e5d2dec8dadd5354f78453203e22e669cd0ec4c19d9a8c5edb31d092500160405180910390a2949350505050565b6000805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b3000000000000000000000000000000000000000000000000000000001790529151600092839290871691611aa6919061216d565b6000604051808303816000865af19150503d8060008114611ae3576040519150601f19603f3d011682016040523d82523d6000602084013e611ae8565b606091505b5091509150818015611b12575080511580611b12575080806020019051810190611b1291906120c1565b611b78576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f534100000000000000000000000000000000000000000000000000000000000060448201526064016105e1565b5050505050565b6040805160008082526020820190925273ffffffffffffffffffffffffffffffffffffffff8416908390604051611bb6919061216d565b60006040518083038185875af1925050503d8060008114611bf3576040519150601f19603f3d011682016040523d82523d6000602084013e611bf8565b606091505b5050905080611c63576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600360248201527f535445000000000000000000000000000000000000000000000000000000000060448201526064016105e1565b505050565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001790529151600092839290871691611cff919061216d565b6000604051808303816000865af19150503d8060008114611d3c576040519150601f19603f3d011682016040523d82523d6000602084013e611d41565b606091505b5091509150818015611d6b575080511580611d6b575080806020019051810190611d6b91906120c1565b611b78576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f535400000000000000000000000000000000000000000000000000000000000060448201526064016105e1565b6040805173ffffffffffffffffffffffffffffffffffffffff85811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f23b872dd000000000000000000000000000000000000000000000000000000001790529151600092839290881691611e70919061216d565b6000604051808303816000865af19150503d8060008114611ead576040519150601f19603f3d011682016040523d82523d6000602084013e611eb2565b606091505b5091509150818015611edc575080511580611edc575080806020019051810190611edc91906120c1565b611f42576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600360248201527f535446000000000000000000000000000000000000000000000000000000000060448201526064016105e1565b505050505050565b73ffffffffffffffffffffffffffffffffffffffff8116811461130457600080fd5b600060208284031215611f7e57600080fd5b8135611f8981611f4a565b9392505050565b600060208284031215611fa257600080fd5b5035919050565b600080600080600060a08688031215611fc157600080fd5b8535611fcc81611f4a565b94506020860135611fdc81611f4a565b93506040860135611fec81611f4a565b92506060860135611ffc81611f4a565b9150608086013561200c81611f4a565b809150509295509295909350565b801515811461130457600080fd5b6000806040838503121561203b57600080fd5b823561204681611f4a565b915060208301356120568161201a565b809150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600082198211156120a3576120a3612061565b500190565b6000602082840312156120ba57600080fd5b5051919050565b6000602082840312156120d357600080fd5b8151611f898161201a565b6000828210156120f0576120f0612061565b500390565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561212d5761212d612061565b500290565b600082612168577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b6000825160005b8181101561218e5760208186018101518583015201612174565b8181111561219d576000828501525b50919091019291505056fea2646970667358221220ddb773c16f71ccd3deca0dd00947d12fb055db71440632f88d844fc79890d65a64736f6c634300080e0033
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106102265760003560e01c8063a373ed4e1161012a578063e1a4e72a116100bd578063f0f442601161008c578063fa3ae6dc11610071578063fa3ae6dc146104b3578063fcc7c4ed146104bb578063fdcb6068146104c457600080fd5b8063f0f442601461048d578063f2fde38b146104a057600080fd5b8063e1a4e72a14610436578063e5e2abf514610449578063eaf6e48314610452578063f077cbab1461048557600080fd5b8063d183a7a2116100f9578063d183a7a2146103de578063d736ce7c14610406578063d83e6b3814610426578063dbe08b561461042e57600080fd5b8063a373ed4e146103a8578063bab8583a146103b0578063c1ae359a146103c3578063c5ebeaec146103cb57600080fd5b80634bb2dcea116101bd57806361d027b31161018c5780637c3a00fd116101715780637c3a00fd146103785780637e452aff146103815780638da5cb5b1461038a57600080fd5b806361d027b314610350578063715018a61461037057600080fd5b80634bb2dcea1461031957806352c49c44146103215780635bc9f65d1461032a5780635f84f3021461033d57600080fd5b80633560df8c116101f95780633560df8c146102c0578063359ef75b146102d35780633fc8cef3146102e65780634422bc5a1461030657600080fd5b80630dca59c11461022b5780631779aacf146102465780631f1fcd511461025b578063245b74be146102a0575b600080fd5b6102336104e4565b6040519081526020015b60405180910390f35b610259610254366004611f6c565b6104fb565b005b60035461027b9073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200161023d565b60065461027b9073ffffffffffffffffffffffffffffffffffffffff1681565b6102336102ce366004611f90565b61054a565b6102596102e1366004611fa9565b610604565b60025461027b9073ffffffffffffffffffffffffffffffffffffffff1681565b610259610314366004612028565b6106b4565b610233610712565b61023360085481565b610259610338366004611f6c565b6107a6565b61025961034b366004611f90565b6107f5565b600a5461027b9073ffffffffffffffffffffffffffffffffffffffff1681565b6102596109e8565b610233600b5481565b610233600c5481565b60005473ffffffffffffffffffffffffffffffffffffffff1661027b565b6102596109fc565b6102596103be366004611f90565b610a6f565b610233610bba565b6102596103d9366004611f90565b610c81565b6103e66110de565b60408051948552602085019390935291830152606082015260800161023d565b60055461027b9073ffffffffffffffffffffffffffffffffffffffff1681565b6102336111f8565b6103e6611202565b610259610444366004611f6c565b6112b5565b61023360095481565b610475610460366004611f6c565b600d6020526000908152604090205460ff1681565b604051901515815260200161023d565b6102336113a9565b61025961049b366004611f6c565b6113bc565b6102596104ae366004611f6c565b6115b8565b61023361166c565b61023360075481565b60045461027b9073ffffffffffffffffffffffffffffffffffffffff1681565b60006008546007546104f69190612090565b905090565b61050361171d565b600680547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b336000908152600d602052604081205460ff168061057f575060055473ffffffffffffffffffffffffffffffffffffffff1633145b6105ea576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f576f6f4c656e64696e674d616e616765723a2021626f72726f7765720000000060448201526064015b60405180910390fd5b6105f26109fc565b6105fe8260085461179e565b92915050565b61060c61171d565b600280547fffffffffffffffffffffffff000000000000000000000000000000000000000090811673ffffffffffffffffffffffffffffffffffffffff978816179091556003805482169587169590951790945560048054851693861693909317909255600580548416918516919091179055600680548316919093161790915542600c55600a8054734094d7a17a387795838c7aba4687387b0d32bcf39216919091179055565b6106bc61171d565b73ffffffffffffffffffffffffffffffffffffffff919091166000908152600d6020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b600654604080517f4bb2dcea000000000000000000000000000000000000000000000000000000008152905160009273ffffffffffffffffffffffffffffffffffffffff1691634bb2dcea9160048083019260209291908290030181865afa158015610782573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104f691906120a8565b6107ae61171d565b600580547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b3361081560005473ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff1614806108c75750600480546040517faf5b052b000000000000000000000000000000000000000000000000000000008152339281019290925273ffffffffffffffffffffffffffffffffffffffff169063af5b052b906024016020604051808303816000875af11580156108a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108c791906120c1565b61092d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f576f6f4c656e64696e674d616e616765723a202141444d494e0000000000000060448201526064016105e1565b61c350811115610999576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f524154455f494e56414c4944000000000000000000000000000000000000000060448201526064016105e1565b6109a16109fc565b600b805490829055604080518281526020810184905233917f3aebbb85b9698ba4e1588e9f25e8e3bb8d3c5fb5199f6b36b362e6775947b383910160405180910390a25050565b6109f061171d565b6109fa600061199a565b565b600c5442908111610a0a5750565b6000600c5482610a1a91906120de565b905060006127106301e1338083600b54600754610a3791906120f5565b610a4191906120f5565b610a4b9190612132565b610a559190612132565b905080600854610a659190612090565b6008555050600c55565b33610a8f60005473ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff161480610b415750600480546040517faf5b052b000000000000000000000000000000000000000000000000000000008152339281019290925273ffffffffffffffffffffffffffffffffffffffff169063af5b052b906024016020604051808303816000875af1158015610b1d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b4191906120c1565b610ba7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f576f6f4c656e64696e674d616e616765723a202141444d494e0000000000000060448201526064016105e1565b6127108110610bb557600080fd5b600955565b336000908152600d602052604081205460ff1680610bef575060055473ffffffffffffffffffffffffffffffffffffffff1633145b610c55576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f576f6f4c656e64696e674d616e616765723a2021626f72726f7765720000000060448201526064016105e1565b610c5d6109fc565b600080610c686110de565b509093509150610c7a9050828261179e565b9250505090565b336000908152600d602052604090205460ff1680610cb6575060055473ffffffffffffffffffffffffffffffffffffffff1633145b610d1c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f576f6f4c656e64696e674d616e616765723a2021626f72726f7765720000000060448201526064016105e1565b60008111610d86576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600760248201527f21414d4f554e540000000000000000000000000000000000000000000000000060448201526064016105e1565b610d8e6109fc565b80600754610d9c9190612090565b6007556003546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009173ffffffffffffffffffffffffffffffffffffffff16906370a0823190602401602060405180830381865afa158015610e0e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e3291906120a8565b6006546040517f2ea9239e0000000000000000000000000000000000000000000000000000000081526004810185905230602482015291925073ffffffffffffffffffffffffffffffffffffffff1690632ea9239e90604401600060405180830381600087803b158015610ea557600080fd5b505af1158015610eb9573d6000803e3d6000fd5b50506003546040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526000935073ffffffffffffffffffffffffffffffffffffffff90911691506370a0823190602401602060405180830381865afa158015610f2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f5291906120a8565b905082610f5f83836120de565b14610fec576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f576f6f4c656e64696e674d616e616765723a20424f52524f575f414d4f554e5460448201527f5f4552524f52000000000000000000000000000000000000000000000000000060648201526084016105e1565b6003546005546110169173ffffffffffffffffffffffffffffffffffffffff908116911685611a0f565b6005546003546040517f47e7ef2400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9182166004820152602481018690529116906347e7ef2490604401600060405180830381600087803b15801561108c57600080fd5b505af11580156110a0573d6000803e3d6000fd5b50506040518581523392507fcbc04eca7e9da35cb1393a6135a199ca52e450d5e9251cbd99f7847d33a36750915060200160405180910390a2505050565b6000806000806000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636aa9eda26040518163ffffffff1660e01b8152600401602060405180830381865afa158015611153573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061117791906120a8565b905080600003611195576000806000809450945094509450506111f2565b60085481116111aa57809250600093506111bc565b60085492506111b983826120de565b93505b612710600954846111cd91906120f5565b6111d79190612132565b9150816111e48486612090565b6111ee9190612090565b9450505b90919293565b60006104f66104e4565b6000806000806112106104e4565b935060075492506008549150600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16634bb2dcea6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611289573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112ad91906120a8565b905090919293565b6112bd61171d565b7fffffffffffffffffffffffff111111111111111111111111111111111111111273ffffffffffffffffffffffffffffffffffffffff821601611307576113043347611b7f565b50565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009073ffffffffffffffffffffffffffffffffffffffff8316906370a0823190602401602060405180830381865afa158015611374573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061139891906120a8565b90506113a5823383611c68565b5050565b60006113b36110de565b50919392505050565b336113dc60005473ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff16148061148e5750600480546040517faf5b052b000000000000000000000000000000000000000000000000000000008152339281019290925273ffffffffffffffffffffffffffffffffffffffff169063af5b052b906024016020604051808303816000875af115801561146a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061148e91906120c1565b6114f4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f576f6f4c656e64696e674d616e616765723a202141444d494e0000000000000060448201526064016105e1565b73ffffffffffffffffffffffffffffffffffffffff8116611571576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f576f6f4c656e64696e674d616e616765723a20215f747265617375727900000060448201526064016105e1565b600a80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b6115c061171d565b73ffffffffffffffffffffffffffffffffffffffff8116611663576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f646472657373000000000000000000000000000000000000000000000000000060648201526084016105e1565b6113048161199a565b336000908152600d602052604081205460ff16806116a1575060055473ffffffffffffffffffffffffffffffffffffffff1633145b611707576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f576f6f4c656e64696e674d616e616765723a2021626f72726f7765720000000060448201526064016105e1565b61170f6109fc565b6104f660075460085461179e565b60005473ffffffffffffffffffffffffffffffffffffffff1633146109fa576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016105e1565b6000821580156117ac575081155b156117f457604080516000808252602082015233917f77c6871227e5d2dec8dadd5354f78453203e22e669cd0ec4c19d9a8c5edb31d0910160405180910390a25060006105fe565b60006127106009548461180791906120f5565b6118119190612132565b90506000816118208587612090565b61182a9190612090565b6003549091506118529073ffffffffffffffffffffffffffffffffffffffff16333084611dd1565b836008600082825461186491906120de565b92505081905550846007600082825461187d91906120de565b9091555050600354600a546118ac9173ffffffffffffffffffffffffffffffffffffffff908116911684611c68565b6003546006546118df9173ffffffffffffffffffffffffffffffffffffffff90811691166118da8789612090565b611a0f565b60065473ffffffffffffffffffffffffffffffffffffffff1663b5589fad6119078688612090565b6040518263ffffffff1660e01b815260040161192591815260200190565b600060405180830381600087803b15801561193f57600080fd5b505af1158015611953573d6000803e3d6000fd5b505060408051848152602081018690523393507f77c6871227e5d2dec8dadd5354f78453203e22e669cd0ec4c19d9a8c5edb31d092500160405180910390a2949350505050565b6000805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b3000000000000000000000000000000000000000000000000000000001790529151600092839290871691611aa6919061216d565b6000604051808303816000865af19150503d8060008114611ae3576040519150601f19603f3d011682016040523d82523d6000602084013e611ae8565b606091505b5091509150818015611b12575080511580611b12575080806020019051810190611b1291906120c1565b611b78576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f534100000000000000000000000000000000000000000000000000000000000060448201526064016105e1565b5050505050565b6040805160008082526020820190925273ffffffffffffffffffffffffffffffffffffffff8416908390604051611bb6919061216d565b60006040518083038185875af1925050503d8060008114611bf3576040519150601f19603f3d011682016040523d82523d6000602084013e611bf8565b606091505b5050905080611c63576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600360248201527f535445000000000000000000000000000000000000000000000000000000000060448201526064016105e1565b505050565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001790529151600092839290871691611cff919061216d565b6000604051808303816000865af19150503d8060008114611d3c576040519150601f19603f3d011682016040523d82523d6000602084013e611d41565b606091505b5091509150818015611d6b575080511580611d6b575080806020019051810190611d6b91906120c1565b611b78576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f535400000000000000000000000000000000000000000000000000000000000060448201526064016105e1565b6040805173ffffffffffffffffffffffffffffffffffffffff85811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f23b872dd000000000000000000000000000000000000000000000000000000001790529151600092839290881691611e70919061216d565b6000604051808303816000865af19150503d8060008114611ead576040519150601f19603f3d011682016040523d82523d6000602084013e611eb2565b606091505b5091509150818015611edc575080511580611edc575080806020019051810190611edc91906120c1565b611f42576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600360248201527f535446000000000000000000000000000000000000000000000000000000000060448201526064016105e1565b505050505050565b73ffffffffffffffffffffffffffffffffffffffff8116811461130457600080fd5b600060208284031215611f7e57600080fd5b8135611f8981611f4a565b9392505050565b600060208284031215611fa257600080fd5b5035919050565b600080600080600060a08688031215611fc157600080fd5b8535611fcc81611f4a565b94506020860135611fdc81611f4a565b93506040860135611fec81611f4a565b92506060860135611ffc81611f4a565b9150608086013561200c81611f4a565b809150509295509295909350565b801515811461130457600080fd5b6000806040838503121561203b57600080fd5b823561204681611f4a565b915060208301356120568161201a565b809150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600082198211156120a3576120a3612061565b500190565b6000602082840312156120ba57600080fd5b5051919050565b6000602082840312156120d357600080fd5b8151611f898161201a565b6000828210156120f0576120f0612061565b500390565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561212d5761212d612061565b500290565b600082612168577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b6000825160005b8181101561218e5760208186018101518583015201612174565b8181111561219d576000828501525b50919091019291505056fea2646970667358221220ddb773c16f71ccd3deca0dd00947d12fb055db71440632f88d844fc79890d65a64736f6c634300080e0033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.