Feature Tip: Add private address tag to any address under My Name Tag !
Source Code
Overview
ETH Balance
0 ETH
Eth Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
RibbonThetaVaultWithSwap
Compiler Version
v0.8.4+commit.c7e474f2
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity =0.8.4;
import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {
SafeERC20
} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ISwap} from "../../interfaces/ISwap.sol";
import {
IOtoken
} from "../../interfaces/GammaInterface.sol";
import {
RibbonThetaVaultStorage
} from "../../storage/RibbonThetaVaultStorage.sol";
import {Vault} from "../../libraries/Vault.sol";
import {
VaultLifecycleWithSwap
} from "../../libraries/VaultLifecycleWithSwap.sol";
import {ShareMath} from "../../libraries/ShareMath.sol";
import {RibbonVault} from "./base/RibbonVault.sol";
/**
* UPGRADEABILITY: Since we use the upgradeable proxy pattern, we must observe
* the inheritance chain closely.
* Any changes/appends in storage variable needs to happen in RibbonThetaVaultStorage.
* RibbonThetaVault should not inherit from any other contract aside from RibbonVault, RibbonThetaVaultStorage
*/
contract RibbonThetaVaultWithSwap is RibbonVault, RibbonThetaVaultStorage {
using SafeERC20 for IERC20;
using SafeMath for uint256;
using ShareMath for Vault.DepositReceipt;
/************************************************
* IMMUTABLES & CONSTANTS
***********************************************/
// USDC
address public constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
/// @notice Deprecated: 15 minute timelock between commitAndClose and rollToNexOption.
uint256 public constant DELAY = 0;
/// @notice oTokenFactory is the factory contract used to spawn otokens. Used to lookup otokens.
address public immutable OTOKEN_FACTORY;
/************************************************
* EVENTS
***********************************************/
event OpenShort(
address indexed options,
uint256 depositAmount,
address indexed manager
);
event CloseShort(
address indexed options,
uint256 withdrawAmount,
address indexed manager
);
event NewOptionStrikeSelected(uint256 strikePrice, uint256 delta);
event InstantWithdraw(
address indexed account,
uint256 amount,
uint256 round
);
event NewOffer(
uint256 swapId,
address seller,
address oToken,
address biddingToken,
uint256 minPrice,
uint256 minBidSize,
uint256 totalSize
);
/************************************************
* STRUCTS
***********************************************/
/**
* @notice Initialization parameters for the vault.
* @param _owner is the owner of the vault with critical permissions
* @param _feeRecipient is the address to recieve vault performance and management fees
* @param _managementFee is the management fee pct.
* @param _performanceFee is the perfomance fee pct.
* @param _tokenName is the name of the token
* @param _tokenSymbol is the symbol of the token
* @param _optionsPremiumPricer is the address of the contract with the
black-scholes premium calculation logic
* @param _strikeSelection is the address of the contract with strike selection logic
* @param _period is the period between each option sales
*/
struct InitParams {
address _owner;
address _keeper;
address _feeRecipient;
uint256 _period;
uint256 _managementFee;
uint256 _performanceFee;
string _tokenName;
string _tokenSymbol;
address _optionsPremiumPricer;
address _strikeSelection;
}
/************************************************
* CONSTRUCTOR & INITIALIZATION
***********************************************/
/**
* @notice Initializes the contract with immutable variables
* @param _oTokenFactory is the contract address for minting new opyn option types (strikes, asset, expiry)
* @param _gammaController is the contract address for opyn actions
* @param _marginPool is the contract address for providing collateral to opyn
* @param _swapContract is the contract address that facilitates bids settlement
* @param _amplol is the contract address for AMPLOLs
*/
constructor(
address _oTokenFactory,
address _gammaController,
address _marginPool,
address _swapContract,
address _amplol
) RibbonVault(_gammaController, _marginPool, _swapContract, _amplol) {
require(_oTokenFactory != address(0), "!_oTokenFactory");
OTOKEN_FACTORY = _oTokenFactory;
}
/**
* @notice Initializes the OptionVault contract with storage variables.
* @param _initParams is the struct with vault initialization parameters
* @param _vaultParams is the struct with vault general data
*/
function initialize(
InitParams calldata _initParams,
Vault.VaultParams calldata _vaultParams
) external initializer {
baseInitialize(
_initParams._owner,
_initParams._keeper,
_initParams._feeRecipient,
_initParams._period,
_initParams._managementFee,
_initParams._performanceFee,
_initParams._tokenName,
_initParams._tokenSymbol,
_vaultParams
);
require(
_initParams._optionsPremiumPricer != address(0),
"!_optionsPremiumPricer"
);
require(
_initParams._strikeSelection != address(0),
"!_strikeSelection"
);
optionsPremiumPricer = _initParams._optionsPremiumPricer;
strikeSelection = _initParams._strikeSelection;
}
/************************************************
* SETTERS
***********************************************/
/**
* @notice Sets the new strike selection contract
* @param newStrikeSelection is the address of the new strike selection contract
*/
function setStrikeSelection(address newStrikeSelection) external onlyOwner {
require(newStrikeSelection != address(0), "!newStrikeSelection");
strikeSelection = newStrikeSelection;
}
/**
* @notice Sets the new options premium pricer contract
* @param newOptionsPremiumPricer is the address of the new strike selection contract
*/
function setOptionsPremiumPricer(address newOptionsPremiumPricer)
external
onlyOwner
{
require(
newOptionsPremiumPricer != address(0),
"!newOptionsPremiumPricer"
);
optionsPremiumPricer = newOptionsPremiumPricer;
}
/**
* @notice Optionality to set strike price manually
* Should be called after closeRound if we are setting current week's strike
* @param strikePrice is the strike price of the new oTokens (decimals = 8)
*/
function setStrikePrice(uint128 strikePrice) external onlyOwner {
require(strikePrice > 0, "!strikePrice");
overriddenStrikePrice = strikePrice;
lastStrikeOverrideRound = vaultState.round;
}
/**
* @notice Sets oToken Premium
* @param minPrice is the new oToken Premium in the units of 10**18
*/
function setMinPrice(uint256 minPrice) external onlyKeeper {
require(minPrice > 0, "!minPrice");
currentOtokenPremium = minPrice;
}
/************************************************
* VAULT OPERATIONS
***********************************************/
/**
* @notice Withdraws the assets on the vault using the outstanding `DepositReceipt.amount`
* @param amount is the amount to withdraw
*/
function withdrawInstantly(uint256 amount) external nonReentrant {
Vault.DepositReceipt storage depositReceipt =
depositReceipts[msg.sender];
uint256 currentRound = vaultState.round;
require(amount > 0, "!amount");
require(depositReceipt.round == currentRound, "Invalid round");
uint256 receiptAmount = depositReceipt.amount;
require(receiptAmount >= amount, "Exceed amount");
// Subtraction underflow checks already ensure it is smaller than uint104
depositReceipt.amount = uint104(receiptAmount.sub(amount));
vaultState.totalPending = uint128(
uint256(vaultState.totalPending).sub(amount)
);
emit InstantWithdraw(msg.sender, amount, currentRound);
AMPLOL.burn(msg.sender, amount);
transferAsset(msg.sender, amount);
}
/**
* @notice Initiates a withdrawal that can be processed once the round completes
* @param numShares is the number of shares to withdraw
*/
function initiateWithdraw(uint256 numShares) external nonReentrant {
_initiateWithdraw(numShares);
currentQueuedWithdrawShares = currentQueuedWithdrawShares.add(
numShares
);
}
/**
* @notice Completes a scheduled withdrawal from a past round. Uses finalized pps for the round
*/
function completeWithdraw() external nonReentrant {
uint256 withdrawAmount = _completeWithdraw();
lastQueuedWithdrawAmount = uint128(
uint256(lastQueuedWithdrawAmount).sub(withdrawAmount)
);
}
/**
* @notice Closes the existing short and calculate the shares to mint, new price per share &
amount of funds to re-allocate as collateral for the new round
* Since we are incrementing the round here, the options are sold in the beginning of a round
* instead of at the end of the round. For example, at round 1, we don't sell any options. We
* start selling options at the beginning of round 2.
*/
function closeRound() external nonReentrant {
address oldOption = optionState.currentOption;
require(
oldOption != address(0) || vaultState.round == 1,
"Round closed"
);
_closeShort(oldOption);
uint256 currQueuedWithdrawShares = currentQueuedWithdrawShares;
(uint256 lockedBalance, uint256 queuedWithdrawAmount) =
_closeRound(
uint256(lastQueuedWithdrawAmount),
currQueuedWithdrawShares
);
lastQueuedWithdrawAmount = queuedWithdrawAmount;
uint256 newQueuedWithdrawShares =
uint256(vaultState.queuedWithdrawShares).add(
currQueuedWithdrawShares
);
ShareMath.assertUint128(newQueuedWithdrawShares);
vaultState.queuedWithdrawShares = uint128(newQueuedWithdrawShares);
currentQueuedWithdrawShares = 0;
ShareMath.assertUint104(lockedBalance);
vaultState.lockedAmount = uint104(lockedBalance);
uint256 nextOptionReady = block.timestamp.add(DELAY);
require(
nextOptionReady <= type(uint32).max,
"Overflow nextOptionReady"
);
optionState.nextOptionReadyAt = uint32(nextOptionReady);
for (uint256 i = 0; i < settledBids.length; i++) {
delete settledBids[i];
}
}
/**
* @notice Closes the existing short position for the vault.
*/
function _closeShort(address oldOption) private {
uint256 lockedAmount = vaultState.lockedAmount;
if (oldOption != address(0)) {
vaultState.lastLockedAmount = uint104(lockedAmount);
}
vaultState.lockedAmount = 0;
optionState.currentOption = address(0);
if (oldOption != address(0)) {
uint256 withdrawAmount =
VaultLifecycleWithSwap.settleShort(GAMMA_CONTROLLER);
emit CloseShort(oldOption, withdrawAmount, msg.sender);
}
}
/**
* @notice Sets the next option the vault will be shorting
*/
function commitNextOption() external onlyKeeper nonReentrant {
address currentOption = optionState.currentOption;
require(
currentOption == address(0) && vaultState.round != 1,
"Round not closed"
);
VaultLifecycleWithSwap.CommitParams memory commitParams =
VaultLifecycleWithSwap.CommitParams({
OTOKEN_FACTORY: OTOKEN_FACTORY,
USDC: USDC,
collateralAsset: vaultParams.asset,
currentOption: currentOption,
delay: DELAY,
lastStrikeOverrideRound: lastStrikeOverrideRound,
overriddenStrikePrice: overriddenStrikePrice,
strikeSelection: strikeSelection,
optionsPremiumPricer: optionsPremiumPricer,
period: period
});
(address otokenAddress, uint256 strikePrice, uint256 delta) =
VaultLifecycleWithSwap.commitNextOption(
commitParams,
vaultParams,
vaultState
);
emit NewOptionStrikeSelected(strikePrice, delta);
optionState.nextOption = otokenAddress;
}
/**
* @notice Rolls the vault's funds into a new short position and create a new offer.
*/
function rollToNextOption() external onlyKeeper nonReentrant {
address newOption = optionState.nextOption;
require(newOption != address(0), "!nextOption");
optionState.currentOption = newOption;
optionState.nextOption = address(0);
uint256 lockedBalance = vaultState.lockedAmount;
emit OpenShort(newOption, lockedBalance, msg.sender);
VaultLifecycleWithSwap.createShort(
GAMMA_CONTROLLER,
MARGIN_POOL,
newOption,
lockedBalance
);
_createOffer();
}
function _createOffer() private {
address currentOtoken = optionState.currentOption;
uint256 currOtokenPremium = currentOtokenPremium;
optionAuctionID = VaultLifecycleWithSwap.createOffer(
currentOtoken,
currOtokenPremium,
SWAP_CONTRACT,
vaultParams
);
}
/**
* @notice Settle current offer
*/
function settleOffer(ISwap.Bid[] calldata bids)
external
onlyKeeper
nonReentrant
{
for (uint256 i = 0; i < bids.length; i++) {
settledBids.push(bids[i]);
}
ISwap(SWAP_CONTRACT).settleOffer(optionAuctionID, bids);
}
/**
* @notice Burn the remaining oTokens left over and return premiums
*/
function burnRemainingOTokens() external onlyKeeper nonReentrant {
VaultLifecycleWithSwap.burnOtokens(
GAMMA_CONTROLLER,
optionState.currentOption
);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.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 OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal initializer {
__Context_init_unchained();
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal initializer {
_setOwner(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_setOwner(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");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
*/
bool private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Modifier to protect an initializer function from being invoked twice.
*/
modifier initializer() {
require(_initializing || !_initialized, "Initializable: contract is already initialized");
bool isTopLevelCall = !_initializing;
if (isTopLevelCall) {
_initializing = true;
_initialized = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @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 ReentrancyGuardUpgradeable is Initializable {
// 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;
function __ReentrancyGuard_init() internal initializer {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal initializer {
_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 make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC20Upgradeable.sol";
import "./extensions/IERC20MetadataUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import "../../proxy/utils/Initializable.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.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* 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 ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable {
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}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
function __ERC20_init(string memory name_, string memory symbol_) internal initializer {
__Context_init_unchained();
__ERC20_init_unchained(name_, symbol_);
}
function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer {
_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 value {ERC20} uses, unless this function is
* 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:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, 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}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), 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}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
unchecked {
_approve(sender, _msgSender(), currentAllowance - 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) {
_approve(_msgSender(), spender, _allowances[_msgSender()][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) {
uint256 currentAllowance = _allowances[_msgSender()][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(_msgSender(), spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `sender` to `recipient`.
*
* 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:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[sender] = senderBalance - amount;
}
_balances[recipient] += amount;
emit Transfer(sender, recipient, amount);
_afterTokenTransfer(sender, recipient, 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;
_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;
}
_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 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 {}
uint256[45] private __gap;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC20Upgradeable.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20MetadataUpgradeable is IERC20Upgradeable {
/**
* @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
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20Upgradeable {
/**
* @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 `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, 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 `sender` to `recipient` 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 sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @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);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @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 ContextUpgradeable is Initializable {
function __Context_init() internal initializer {
__Context_init_unchained();
}
function __Context_init_unchained() internal initializer {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
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
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @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 `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, 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 `sender` to `recipient` 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 sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @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);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC20.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;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @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));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
/**
* @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");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @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
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 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://diligence.consensys.net/posts/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.5.11/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 functionCall(target, data, "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");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(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) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(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) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason 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 {
// 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
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.
/**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
* now has built in overflow checking.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.4;
library GammaTypes {
// vault is a struct of 6 arrays that describe a position a user has, a user can have multiple vaults.
struct Vault {
// addresses of oTokens a user has shorted (i.e. written) against this vault
address[] shortOtokens;
// addresses of oTokens a user has bought and deposited in this vault
// user can be long oTokens without opening a vault (e.g. by buying on a DEX)
// generally, long oTokens will be 'deposited' in vaults to act as collateral
// in order to write oTokens against (i.e. in spreads)
address[] longOtokens;
// addresses of other ERC-20s a user has deposited as collateral in this vault
address[] collateralAssets;
// quantity of oTokens minted/written for each oToken address in shortOtokens
uint256[] shortAmounts;
// quantity of oTokens owned and held in the vault for each oToken address in longOtokens
uint256[] longAmounts;
// quantity of ERC-20 deposited as collateral in the vault for each ERC-20 address in collateralAssets
uint256[] collateralAmounts;
}
}
interface IOtoken {
function underlyingAsset() external view returns (address);
function strikeAsset() external view returns (address);
function collateralAsset() external view returns (address);
function strikePrice() external view returns (uint256);
function expiryTimestamp() external view returns (uint256);
function isPut() external view returns (bool);
function balanceOf(address) external view returns (uint256);
function totalSupply() external view returns (uint256);
function transfer(address, uint256) external;
}
interface IOtokenFactory {
function getOtoken(
address _underlyingAsset,
address _strikeAsset,
address _collateralAsset,
uint256 _strikePrice,
uint256 _expiry,
bool _isPut
) external view returns (address);
function createOtoken(
address _underlyingAsset,
address _strikeAsset,
address _collateralAsset,
uint256 _strikePrice,
uint256 _expiry,
bool _isPut
) external returns (address);
function getTargetOtokenAddress(
address _underlyingAsset,
address _strikeAsset,
address _collateralAsset,
uint256 _strikePrice,
uint256 _expiry,
bool _isPut
) external view returns (address);
event OtokenCreated(
address tokenAddress,
address creator,
address indexed underlying,
address indexed strike,
address indexed collateral,
uint256 strikePrice,
uint256 expiry,
bool isPut
);
}
interface IController {
// possible actions that can be performed
enum ActionType {
OpenVault,
MintShortOption,
BurnShortOption,
DepositLongOption,
WithdrawLongOption,
DepositCollateral,
WithdrawCollateral,
SettleVault,
Redeem,
Call,
Liquidate
}
struct ActionArgs {
// type of action that is being performed on the system
ActionType actionType;
// address of the account owner
address owner;
// address which we move assets from or to (depending on the action type)
address secondAddress;
// asset that is to be transfered
address asset;
// index of the vault that is to be modified (if any)
uint256 vaultId;
// amount of asset that is to be transfered
uint256 amount;
// each vault can hold multiple short / long / collateral assets
// but we are restricting the scope to only 1 of each in this version
// in future versions this would be the index of the short / long / collateral asset that needs to be modified
uint256 index;
// any other data that needs to be passed in for arbitrary function calls
bytes data;
}
struct RedeemArgs {
// address to which we pay out the oToken proceeds
address receiver;
// oToken that is to be redeemed
address otoken;
// amount of oTokens that is to be redeemed
uint256 amount;
}
function getPayout(address _otoken, uint256 _amount)
external
view
returns (uint256);
function operate(ActionArgs[] calldata _actions) external;
function getAccountVaultCounter(address owner)
external
view
returns (uint256);
function oracle() external view returns (address);
function getVault(address _owner, uint256 _vaultId)
external
view
returns (GammaTypes.Vault memory);
function getProceed(address _owner, uint256 _vaultId)
external
view
returns (uint256);
function isSettlementAllowed(
address _underlying,
address _strike,
address _collateral,
uint256 _expiry
) external view returns (bool);
}
interface IOracle {
function setAssetPricer(address _asset, address _pricer) external;
function updateAssetPricer(address _asset, address _pricer) external;
function getPrice(address _asset) external view returns (uint256);
function getExpiryPrice(address _asset, uint256 _expiryTimestamp)
external
view
returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.4;
// Amplol interface
interface IAmplol {
function mint(address,uint256) external;
function burn(address,uint256) external;
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.4;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IERC20Detailed is IERC20 {
function decimals() external view returns (uint8);
function symbol() external view returns (string calldata);
function name() external view returns (string calldata);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IOptionsPurchaseQueue {
/**
* @dev Contains purchase request info
* @param optionsAmount Amount of options to purchase
* @param premiums Total premiums the buyer is spending to purchase the options (optionsAmount * ceilingPrice)
* We need to track the premiums here since the ceilingPrice could change between the time the purchase was
* requested and when the options are sold
* @param buyer The buyer requesting this purchase
*/
struct Purchase {
uint128 optionsAmount; // Slot 0
uint128 premiums;
address buyer; // Slot 1
}
function purchases(address, uint256)
external
view
returns (
uint128,
uint128,
address
);
function totalOptionsAmount(address) external view returns (uint256);
function vaultAllocatedOptions(address) external view returns (uint256);
function whitelistedBuyer(address) external view returns (bool);
function minPurchaseAmount(address) external view returns (uint256);
function ceilingPrice(address) external view returns (uint256);
function getPurchases(address vault)
external
view
returns (Purchase[] memory);
function getPremiums(address vault, uint256 optionsAmount)
external
view
returns (uint256);
function getOptionsAllocation(address vault, uint256 allocatedOptions)
external
view
returns (uint256);
function requestPurchase(address vault, uint256 optionsAmount)
external
returns (uint256);
function allocateOptions(uint256 allocatedOptions)
external
returns (uint256);
function sellToBuyers(uint256 settlementPrice) external returns (uint256);
function cancelAllPurchases(address vault) external;
function addWhitelist(address buyer) external;
function removeWhitelist(address buyer) external;
function setCeilingPrice(address vault, uint256 price) external;
function setMinPurchaseAmount(address vault, uint256 amount) external;
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.4;
import {Vault} from "../libraries/Vault.sol";
interface IRibbonVault {
function deposit(uint256 amount) external;
function depositETH() external payable;
function cap() external view returns (uint256);
function depositFor(uint256 amount, address creditor) external;
function vaultParams() external view returns (Vault.VaultParams memory);
}
interface IStrikeSelection {
function getStrikePrice(uint256 expiryTimestamp, bool isPut)
external
view
returns (uint256, uint256);
function delta() external view returns (uint256);
}
interface IOptionsPremiumPricer {
function getPremium(
uint256 strikePrice,
uint256 timeToExpiry,
bool isPut
) external view returns (uint256);
function getPremiumInStables(
uint256 strikePrice,
uint256 timeToExpiry,
bool isPut
) external view returns (uint256);
function getOptionDelta(
uint256 spotPrice,
uint256 strikePrice,
uint256 volatility,
uint256 expiryTimestamp
) external view returns (uint256 delta);
function getUnderlyingPrice() external view returns (uint256);
function priceOracle() external view returns (address);
function volatilityOracle() external view returns (address);
function optionId() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.4;
interface ISwap {
struct Offer {
// 32 byte slot 1, partial fill
// Seller wallet address
address seller;
// 32 byte slot 2
// Addess of oToken
address oToken;
// Price per oToken denominated in biddingToken
uint96 minPrice;
// 32 byte slot 3
// ERC20 Token to bid for oToken
address biddingToken;
// Minimum oToken amount acceptable for a single bid
uint96 minBidSize;
// 32 byte slot 4
// Total available oToken amount
uint128 totalSize;
// Remaining available oToken amount
// This figure is updated after each successfull swap
uint128 availableSize;
// 32 byte slot 5
// Amount of biddingToken received
// This figure is updated after each successfull swap
uint256 totalSales;
}
struct Bid {
// ID assigned to offers
uint256 swapId;
// Number only used once for each wallet
uint256 nonce;
// Signer wallet address
address signerWallet;
// Buyer address
address buyer;
// Amount of biddingToken offered by signer
uint256 sellAmount;
// Amount of oToken requested by signer
uint256 buyAmount;
// Referrer wallet address
address referrer;
// Signature recovery id
uint8 v;
// r portion of the ECSDA signature
bytes32 r;
// s portion of the ECSDA signature
bytes32 s;
}
struct OfferDetails {
// Seller wallet address
address seller;
// Addess of oToken
address oToken;
// Price per oToken denominated in biddingToken
uint256 minPrice;
// ERC20 Token to bid for oToken
address biddingToken;
// Minimum oToken amount acceptable for a single bid
uint256 minBidSize;
}
event Swap(
uint256 indexed swapId,
uint256 nonce,
address indexed buyer,
uint256 signerAmount,
uint256 sellerAmount,
address referrer,
uint256 feeAmount
);
event NewOffer(
uint256 swapId,
address seller,
address oToken,
address biddingToken,
uint256 minPrice,
uint256 minBidSize,
uint256 totalSize
);
event SetFee(address referrer, uint256 fee);
event SetPriceFeed(address asset, address aggregator);
event SettleOffer(uint256 swapId);
event Cancel(uint256 indexed nonce, address indexed signerWallet);
event Authorize(address indexed signer, address indexed signerWallet);
event Revoke(address indexed signer, address indexed signerWallet);
function createOffer(
address oToken,
address biddingToken,
uint96 minPrice,
uint96 minBidSize,
uint128 totalSize
) external returns (uint256 swapId);
function settleOffer(uint256 swapId, Bid[] calldata bids) external;
function cancelNonce(uint256[] calldata nonces) external;
function check(Bid calldata bid)
external
view
returns (uint256, bytes32[] memory);
function averagePriceForOffer(uint256 swapId)
external
view
returns (uint256);
function authorize(address sender) external;
function revoke() external;
function nonceUsed(address, uint256) external view returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.4;
import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import {Vault} from "./Vault.sol";
library ShareMath {
using SafeMath for uint256;
uint256 internal constant PLACEHOLDER_UINT = 1;
function assetToShares(
uint256 assetAmount,
uint256 assetPerShare,
uint256 decimals
) internal pure returns (uint256) {
// If this throws, it means that vault's roundPricePerShare[currentRound] has not been set yet
// which should never happen.
// Has to be larger than 1 because `1` is used in `initRoundPricePerShares` to prevent cold writes.
require(assetPerShare > PLACEHOLDER_UINT, "Invalid assetPerShare");
return assetAmount.mul(10**decimals).div(assetPerShare);
}
function sharesToAsset(
uint256 shares,
uint256 assetPerShare,
uint256 decimals
) internal pure returns (uint256) {
// If this throws, it means that vault's roundPricePerShare[currentRound] has not been set yet
// which should never happen.
// Has to be larger than 1 because `1` is used in `initRoundPricePerShares` to prevent cold writes.
require(assetPerShare > PLACEHOLDER_UINT, "Invalid assetPerShare");
return shares.mul(assetPerShare).div(10**decimals);
}
/**
* @notice Returns the shares unredeemed by the user given their DepositReceipt
* @param depositReceipt is the user's deposit receipt
* @param currentRound is the `round` stored on the vault
* @param assetPerShare is the price in asset per share
* @param decimals is the number of decimals the asset/shares use
* @return unredeemedShares is the user's virtual balance of shares that are owed
*/
function getSharesFromReceipt(
Vault.DepositReceipt memory depositReceipt,
uint256 currentRound,
uint256 assetPerShare,
uint256 decimals
) internal pure returns (uint256 unredeemedShares) {
if (depositReceipt.round > 0 && depositReceipt.round < currentRound) {
uint256 sharesFromRound =
assetToShares(depositReceipt.amount, assetPerShare, decimals);
return
uint256(depositReceipt.unredeemedShares).add(sharesFromRound);
}
return depositReceipt.unredeemedShares;
}
function pricePerShare(
uint256 totalSupply,
uint256 totalBalance,
uint256 pendingAmount,
uint256 decimals
) internal pure returns (uint256) {
uint256 singleShare = 10**decimals;
return
totalSupply > 0
? singleShare.mul(totalBalance.sub(pendingAmount)).div(
totalSupply
)
: singleShare;
}
/************************************************
* HELPERS
***********************************************/
function assertUint104(uint256 num) internal pure {
require(num <= type(uint104).max, "Overflow uint104");
}
function assertUint128(uint256 num) internal pure {
require(num <= type(uint128).max, "Overflow uint128");
}
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.4;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {
SafeERC20
} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
/**
* This library supports ERC20s that have quirks in their behavior.
* One such ERC20 is USDT, which requires allowance to be 0 before calling approve.
* We plan to update this library with ERC20s that display such idiosyncratic behavior.
*/
library SupportsNonCompliantERC20 {
address private constant USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
function safeApproveNonCompliant(
IERC20 token,
address spender,
uint256 amount
) internal {
if (address(token) == USDT) {
SafeERC20.safeApprove(token, spender, 0);
}
SafeERC20.safeApprove(token, spender, amount);
}
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.4;
library Vault {
/************************************************
* IMMUTABLES & CONSTANTS
***********************************************/
// Fees are 6-decimal places. For example: 20 * 10**6 = 20%
uint256 internal constant FEE_MULTIPLIER = 10**6;
// Premium discount has 1-decimal place. For example: 80 * 10**1 = 80%. Which represents a 20% discount.
uint256 internal constant PREMIUM_DISCOUNT_MULTIPLIER = 10;
// Otokens have 8 decimal places.
uint256 internal constant OTOKEN_DECIMALS = 8;
// Percentage of funds allocated to options is 2 decimal places. 10 * 10**2 = 10%
uint256 internal constant OPTION_ALLOCATION_MULTIPLIER = 10**2;
// Placeholder uint value to prevent cold writes
uint256 internal constant PLACEHOLDER_UINT = 1;
struct VaultParams {
// Option type the vault is selling
bool isPut;
// Token decimals for vault shares
uint8 decimals;
// Asset used in Theta / Delta Vault
address asset;
// Underlying asset of the options sold by vault
address underlying;
// Minimum supply of the vault shares issued, for ETH it's 10**10
uint56 minimumSupply;
// Vault cap
uint104 cap;
}
struct OptionState {
// Option that the vault is shorting / longing in the next cycle
address nextOption;
// Option that the vault is currently shorting / longing
address currentOption;
// The timestamp when the `nextOption` can be used by the vault
uint32 nextOptionReadyAt;
}
struct VaultState {
// 32 byte slot 1
// Current round number. `round` represents the number of `period`s elapsed.
uint16 round;
// Amount that is currently locked for selling options
uint104 lockedAmount;
// Amount that was locked for selling options in the previous round
// used for calculating performance fee deduction
uint104 lastLockedAmount;
// 32 byte slot 2
// Stores the total tally of how much of `asset` there is
// to be used to mint rTHETA tokens
uint128 totalPending;
// Total amount of queued withdrawal shares from previous rounds (doesn't include the current round)
uint128 queuedWithdrawShares;
}
struct DepositReceipt {
// Maximum of 65535 rounds. Assuming 1 round is 7 days, maximum is 1256 years.
uint16 round;
// Deposit amount, max 20,282,409,603,651 or 20 trillion ETH deposit
uint104 amount;
// Unredeemed shares balance
uint128 unredeemedShares;
}
struct Withdrawal {
// Maximum of 65535 rounds. Assuming 1 round is 7 days, maximum is 1256 years.
uint16 round;
// Number of shares withdrawn
uint128 shares;
}
struct AuctionSellOrder {
// Amount of `asset` token offered in auction
uint96 sellAmount;
// Amount of oToken requested in auction
uint96 buyAmount;
// User Id of delta vault in latest gnosis auction
uint64 userId;
}
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.4;
import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {
SafeERC20
} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Vault} from "./Vault.sol";
import {ShareMath} from "./ShareMath.sol";
import {IStrikeSelection} from "../interfaces/IRibbon.sol";
import {
IOtokenFactory,
IOtoken,
IController,
GammaTypes
} from "../interfaces/GammaInterface.sol";
import {IERC20Detailed} from "../interfaces/IERC20Detailed.sol";
import {ISwap} from "../interfaces/ISwap.sol";
import {IOptionsPurchaseQueue} from "../interfaces/IOptionsPurchaseQueue.sol";
import {SupportsNonCompliantERC20} from "./SupportsNonCompliantERC20.sol";
import {IOptionsPremiumPricer} from "../interfaces/IRibbon.sol";
library VaultLifecycleWithSwap {
using SafeMath for uint256;
using SupportsNonCompliantERC20 for IERC20;
using SafeERC20 for IERC20;
struct CommitParams {
address OTOKEN_FACTORY;
address USDC;
address collateralAsset;
address currentOption;
uint256 delay;
uint16 lastStrikeOverrideRound;
uint256 overriddenStrikePrice;
address strikeSelection;
address optionsPremiumPricer;
uint256 period;
}
/**
* @notice Sets the next option the vault will be shorting, and calculates its premium for the auction
* @param commitParams is the struct with details on previous option and strike selection details
* @param vaultParams is the struct with vault general data
* @param vaultState is the struct with vault accounting state
* @return otokenAddress is the address of the new option
* @return strikePrice is the strike price of the new option
* @return delta is the delta of the new option
*/
function commitNextOption(
CommitParams calldata commitParams,
Vault.VaultParams storage vaultParams,
Vault.VaultState storage vaultState
)
external
returns (
address otokenAddress,
uint256 strikePrice,
uint256 delta
)
{
uint256 expiry = getNextExpiry(commitParams.period);
IStrikeSelection selection =
IStrikeSelection(commitParams.strikeSelection);
bool isPut = vaultParams.isPut;
address underlying = vaultParams.underlying;
(strikePrice, delta) = commitParams.lastStrikeOverrideRound ==
vaultState.round
? (commitParams.overriddenStrikePrice, selection.delta())
: selection.getStrikePrice(expiry, isPut);
require(strikePrice != 0, "!strikePrice");
// retrieve address if option already exists, or deploy it
otokenAddress = getOrDeployOtoken(
commitParams,
vaultParams,
underlying,
strikePrice,
expiry,
isPut
);
return (otokenAddress, strikePrice, delta);
}
/**
* @notice Verify the otoken has the correct parameters to prevent vulnerability to opyn contract changes
* @param otokenAddress is the address of the otoken
* @param vaultParams is the struct with vault general data
* @param collateralAsset is the address of the collateral asset
* @param USDC is the address of usdc
* @param delay is the delay between commitAndClose and rollToNextOption
*/
function verifyOtoken(
address otokenAddress,
Vault.VaultParams storage vaultParams,
address collateralAsset,
address USDC,
uint256 delay
) private view {
require(otokenAddress != address(0), "!otokenAddress");
IOtoken otoken = IOtoken(otokenAddress);
require(otoken.isPut() == vaultParams.isPut, "Type mismatch");
require(
otoken.underlyingAsset() == vaultParams.underlying,
"Wrong underlyingAsset"
);
require(
otoken.collateralAsset() == collateralAsset,
"Wrong collateralAsset"
);
// we just assume all options use USDC as the strike
require(otoken.strikeAsset() == USDC, "strikeAsset != USDC");
uint256 readyAt = block.timestamp.add(delay);
require(otoken.expiryTimestamp() >= readyAt, "Expiry before delay");
}
/**
* @param decimals is the decimals of the asset
* @param totalBalance is the vault's total asset balance
* @param currentShareSupply is the supply of the shares invoked with totalSupply()
* @param lastQueuedWithdrawAmount is the amount queued for withdrawals from last round
* @param performanceFee is the perf fee percent to charge on premiums
* @param managementFee is the management fee percent to charge on the AUM
*/
struct CloseParams {
uint256 decimals;
uint256 totalBalance;
uint256 currentShareSupply;
uint256 lastQueuedWithdrawAmount;
uint256 performanceFee;
uint256 managementFee;
uint256 currentQueuedWithdrawShares;
}
/**
* @notice Calculate the shares to mint, new price per share, and
amount of funds to re-allocate as collateral for the new round
* @param vaultState is the storage variable vaultState passed from RibbonVault
* @param params is the rollover parameters passed to compute the next state
* @return newLockedAmount is the amount of funds to allocate for the new round
* @return queuedWithdrawAmount is the amount of funds set aside for withdrawal
* @return newPricePerShare is the price per share of the new round
* @return mintShares is the amount of shares to mint from deposits
* @return performanceFeeInAsset is the performance fee charged by vault
* @return totalVaultFee is the total amount of fee charged by vault
*/
function closeRound(
Vault.VaultState storage vaultState,
CloseParams calldata params
)
external
view
returns (
uint256 newLockedAmount,
uint256 queuedWithdrawAmount,
uint256 newPricePerShare,
uint256 mintShares,
uint256 performanceFeeInAsset,
uint256 totalVaultFee
)
{
uint256 currentBalance = params.totalBalance;
uint256 pendingAmount = vaultState.totalPending;
// Total amount of queued withdrawal shares from previous rounds (doesn't include the current round)
uint256 lastQueuedWithdrawShares = vaultState.queuedWithdrawShares;
// Deduct older queued withdraws so we don't charge fees on them
uint256 balanceForVaultFees =
currentBalance.sub(params.lastQueuedWithdrawAmount);
{
(performanceFeeInAsset, , totalVaultFee) = getVaultFees(
balanceForVaultFees,
vaultState.lastLockedAmount,
vaultState.totalPending,
params.performanceFee,
params.managementFee
);
}
// Take into account the fee
// so we can calculate the newPricePerShare
currentBalance = currentBalance.sub(totalVaultFee);
{
newPricePerShare = ShareMath.pricePerShare(
params.currentShareSupply.sub(lastQueuedWithdrawShares),
currentBalance.sub(params.lastQueuedWithdrawAmount),
pendingAmount,
params.decimals
);
queuedWithdrawAmount = params.lastQueuedWithdrawAmount.add(
ShareMath.sharesToAsset(
params.currentQueuedWithdrawShares,
newPricePerShare,
params.decimals
)
);
// After closing the short, if the options expire in-the-money
// vault pricePerShare would go down because vault's asset balance decreased.
// This ensures that the newly-minted shares do not take on the loss.
mintShares = ShareMath.assetToShares(
pendingAmount,
newPricePerShare,
params.decimals
);
}
return (
currentBalance.sub(queuedWithdrawAmount), // new locked balance subtracts the queued withdrawals
queuedWithdrawAmount,
newPricePerShare,
mintShares,
performanceFeeInAsset,
totalVaultFee
);
}
/**
* @notice Creates the actual Opyn short position by depositing collateral and minting otokens
* @param gammaController is the address of the opyn controller contract
* @param marginPool is the address of the opyn margin contract which holds the collateral
* @param oTokenAddress is the address of the otoken to mint
* @param depositAmount is the amount of collateral to deposit
* @return the otoken mint amount
*/
function createShort(
address gammaController,
address marginPool,
address oTokenAddress,
uint256 depositAmount
) external returns (uint256) {
IController controller = IController(gammaController);
uint256 newVaultID =
(controller.getAccountVaultCounter(address(this))).add(1);
// An otoken's collateralAsset is the vault's `asset`
// So in the context of performing Opyn short operations we call them collateralAsset
IOtoken oToken = IOtoken(oTokenAddress);
address collateralAsset = oToken.collateralAsset();
uint256 collateralDecimals =
uint256(IERC20Detailed(collateralAsset).decimals());
uint256 mintAmount;
if (oToken.isPut()) {
// For minting puts, there will be instances where the full depositAmount will not be used for minting.
// This is because of an issue with precision.
//
// For ETH put options, we are calculating the mintAmount (10**8 decimals) using
// the depositAmount (10**18 decimals), which will result in truncation of decimals when scaling down.
// As a result, there will be tiny amounts of dust left behind in the Opyn vault when minting put otokens.
//
// For simplicity's sake, we do not refund the dust back to the address(this) on minting otokens.
// We retain the dust in the vault so the calling contract can withdraw the
// actual locked amount + dust at settlement.
//
// To test this behavior, we can console.log
// MarginCalculatorInterface(0x7A48d10f372b3D7c60f6c9770B91398e4ccfd3C7).getExcessCollateral(vault)
// to see how much dust (or excess collateral) is left behind.
mintAmount = depositAmount
.mul(10**Vault.OTOKEN_DECIMALS)
.mul(10**18) // we use 10**18 to give extra precision
.div(oToken.strikePrice().mul(10**(10 + collateralDecimals)));
} else {
mintAmount = depositAmount;
if (collateralDecimals > 8) {
uint256 scaleBy = 10**(collateralDecimals.sub(8)); // oTokens have 8 decimals
if (mintAmount > scaleBy) {
mintAmount = depositAmount.div(scaleBy); // scale down from 10**18 to 10**8
}
}
}
// double approve to fix non-compliant ERC20s
IERC20 collateralToken = IERC20(collateralAsset);
collateralToken.safeApproveNonCompliant(marginPool, depositAmount);
IController.ActionArgs[] memory actions =
new IController.ActionArgs[](3);
actions[0] = IController.ActionArgs(
IController.ActionType.OpenVault,
address(this), // owner
address(this), // receiver
address(0), // asset, otoken
newVaultID, // vaultId
0, // amount
0, //index
"" //data
);
actions[1] = IController.ActionArgs(
IController.ActionType.DepositCollateral,
address(this), // owner
address(this), // address to transfer from
collateralAsset, // deposited asset
newVaultID, // vaultId
depositAmount, // amount
0, //index
"" //data
);
actions[2] = IController.ActionArgs(
IController.ActionType.MintShortOption,
address(this), // owner
address(this), // address to transfer to
oTokenAddress, // option address
newVaultID, // vaultId
mintAmount, // amount
0, //index
"" //data
);
controller.operate(actions);
return mintAmount;
}
/**
* @notice Close the existing short otoken position. Currently this implementation is simple.
* It closes the most recent vault opened by the contract. This assumes that the contract will
* only have a single vault open at any given time. Since calling `_closeShort` deletes vaults by
calling SettleVault action, this assumption should hold.
* @param gammaController is the address of the opyn controller contract
* @return amount of collateral redeemed from the vault
*/
function settleShort(address gammaController) external returns (uint256) {
IController controller = IController(gammaController);
// gets the currently active vault ID
uint256 vaultID = controller.getAccountVaultCounter(address(this));
GammaTypes.Vault memory vault =
controller.getVault(address(this), vaultID);
require(vault.shortOtokens.length > 0, "No short");
// An otoken's collateralAsset is the vault's `asset`
// So in the context of performing Opyn short operations we call them collateralAsset
IERC20 collateralToken = IERC20(vault.collateralAssets[0]);
// The short position has been previously closed, or all the otokens have been burned.
// So we return early.
if (address(collateralToken) == address(0)) {
return 0;
}
// This is equivalent to doing IERC20(vault.asset).balanceOf(address(this))
uint256 startCollateralBalance =
collateralToken.balanceOf(address(this));
// If it is after expiry, we need to settle the short position using the normal way
// Delete the vault and withdraw all remaining collateral from the vault
IController.ActionArgs[] memory actions =
new IController.ActionArgs[](1);
actions[0] = IController.ActionArgs(
IController.ActionType.SettleVault,
address(this), // owner
address(this), // address to transfer to
address(0), // not used
vaultID, // vaultId
0, // not used
0, // not used
"" // not used
);
controller.operate(actions);
uint256 endCollateralBalance = collateralToken.balanceOf(address(this));
return endCollateralBalance.sub(startCollateralBalance);
}
/**
* @notice Exercises the ITM option using existing long otoken position. Currently this implementation is simple.
* It calls the `Redeem` action to claim the payout.
* @param gammaController is the address of the opyn controller contract
* @param oldOption is the address of the old option
* @param asset is the address of the vault's asset
* @return amount of asset received by exercising the option
*/
function settleLong(
address gammaController,
address oldOption,
address asset
) external returns (uint256) {
IController controller = IController(gammaController);
uint256 oldOptionBalance = IERC20(oldOption).balanceOf(address(this));
if (controller.getPayout(oldOption, oldOptionBalance) == 0) {
return 0;
}
uint256 startAssetBalance = IERC20(asset).balanceOf(address(this));
// If it is after expiry, we need to redeem the profits
IController.ActionArgs[] memory actions =
new IController.ActionArgs[](1);
actions[0] = IController.ActionArgs(
IController.ActionType.Redeem,
address(0), // not used
address(this), // address to send profits to
oldOption, // address of otoken
0, // not used
oldOptionBalance, // otoken balance
0, // not used
"" // not used
);
controller.operate(actions);
uint256 endAssetBalance = IERC20(asset).balanceOf(address(this));
return endAssetBalance.sub(startAssetBalance);
}
/**
* @notice Burn the remaining oTokens left over from auction. Currently this implementation is simple.
* It burns oTokens from the most recent vault opened by the contract. This assumes that the contract will
* only have a single vault open at any given time.
* @param gammaController is the address of the opyn controller contract
* @param currentOption is the address of the current option
* @return amount of collateral redeemed by burning otokens
*/
function burnOtokens(address gammaController, address currentOption)
external
returns (uint256)
{
uint256 numOTokensToBurn =
IERC20(currentOption).balanceOf(address(this));
require(numOTokensToBurn > 0, "No oTokens to burn");
IController controller = IController(gammaController);
// gets the currently active vault ID
uint256 vaultID = controller.getAccountVaultCounter(address(this));
GammaTypes.Vault memory vault =
controller.getVault(address(this), vaultID);
require(vault.shortOtokens.length > 0, "No short");
IERC20 collateralToken = IERC20(vault.collateralAssets[0]);
uint256 startCollateralBalance =
collateralToken.balanceOf(address(this));
// Burning `amount` of oTokens from the ribbon vault,
// then withdrawing the corresponding collateral amount from the vault
IController.ActionArgs[] memory actions =
new IController.ActionArgs[](2);
actions[0] = IController.ActionArgs(
IController.ActionType.BurnShortOption,
address(this), // owner
address(this), // address to transfer from
address(vault.shortOtokens[0]), // otoken address
vaultID, // vaultId
numOTokensToBurn, // amount
0, //index
"" //data
);
actions[1] = IController.ActionArgs(
IController.ActionType.WithdrawCollateral,
address(this), // owner
address(this), // address to transfer to
address(collateralToken), // withdrawn asset
vaultID, // vaultId
vault.collateralAmounts[0].mul(numOTokensToBurn).div(
vault.shortAmounts[0]
), // amount
0, //index
"" //data
);
controller.operate(actions);
uint256 endCollateralBalance = collateralToken.balanceOf(address(this));
return endCollateralBalance.sub(startCollateralBalance);
}
/**
* @notice Calculates the performance and management fee for this week's round
* @param currentBalance is the balance of funds held on the vault after closing short
* @param lastLockedAmount is the amount of funds locked from the previous round
* @param pendingAmount is the pending deposit amount
* @param performanceFeePercent is the performance fee pct.
* @param managementFeePercent is the management fee pct.
* @return performanceFeeInAsset is the performance fee
* @return managementFeeInAsset is the management fee
* @return vaultFee is the total fees
*/
function getVaultFees(
uint256 currentBalance,
uint256 lastLockedAmount,
uint256 pendingAmount,
uint256 performanceFeePercent,
uint256 managementFeePercent
)
internal
pure
returns (
uint256 performanceFeeInAsset,
uint256 managementFeeInAsset,
uint256 vaultFee
)
{
// At the first round, currentBalance=0, pendingAmount>0
// so we just do not charge anything on the first round
uint256 lockedBalanceSansPending =
currentBalance > pendingAmount
? currentBalance.sub(pendingAmount)
: 0;
uint256 _performanceFeeInAsset;
uint256 _managementFeeInAsset;
uint256 _vaultFee;
// Take performance fee and management fee ONLY if difference between
// last week and this week's vault deposits, taking into account pending
// deposits and withdrawals, is positive. If it is negative, last week's
// option expired ITM past breakeven, and the vault took a loss so we
// do not collect performance fee for last week
if (lockedBalanceSansPending > lastLockedAmount) {
_performanceFeeInAsset = performanceFeePercent > 0
? lockedBalanceSansPending
.sub(lastLockedAmount)
.mul(performanceFeePercent)
.div(100 * Vault.FEE_MULTIPLIER)
: 0;
_managementFeeInAsset = managementFeePercent > 0
? lockedBalanceSansPending.mul(managementFeePercent).div(
100 * Vault.FEE_MULTIPLIER
)
: 0;
_vaultFee = _performanceFeeInAsset.add(_managementFeeInAsset);
}
return (_performanceFeeInAsset, _managementFeeInAsset, _vaultFee);
}
/**
* @notice Either retrieves the option token if it already exists, or deploy it
* @param commitParams is the struct with details on previous option and strike selection details
* @param vaultParams is the struct with vault general data
* @param underlying is the address of the underlying asset of the option
* @param strikePrice is the strike price of the option
* @param expiry is the expiry timestamp of the option
* @param isPut is whether the option is a put
* @return the address of the option
*/
function getOrDeployOtoken(
CommitParams calldata commitParams,
Vault.VaultParams storage vaultParams,
address underlying,
uint256 strikePrice,
uint256 expiry,
bool isPut
) internal returns (address) {
IOtokenFactory factory = IOtokenFactory(commitParams.OTOKEN_FACTORY);
address otokenFromFactory =
factory.getOtoken(
underlying,
commitParams.USDC,
commitParams.collateralAsset,
strikePrice,
expiry,
isPut
);
if (otokenFromFactory != address(0)) {
return otokenFromFactory;
}
address otoken =
factory.createOtoken(
underlying,
commitParams.USDC,
commitParams.collateralAsset,
strikePrice,
expiry,
isPut
);
verifyOtoken(
otoken,
vaultParams,
commitParams.collateralAsset,
commitParams.USDC,
commitParams.delay
);
return otoken;
}
/**
* @notice Creates an offer in the Swap Contract
* @param currentOtoken is the current otoken address
* @param currOtokenPremium is premium for each otoken
* @param swapContract the address of the swap contract
* @param vaultParams is the struct with vault general data
* @return optionAuctionID auction id of the newly created offer
*/
function createOffer(
address currentOtoken,
uint256 currOtokenPremium,
address swapContract,
Vault.VaultParams storage vaultParams
) external returns (uint256 optionAuctionID) {
require(
currOtokenPremium <= type(uint96).max,
"currentOtokenPremium > type(uint96) max value!"
);
require(currOtokenPremium > 0, "!currentOtokenPremium");
uint256 oTokenBalance = IERC20(currentOtoken).balanceOf(address(this));
require(
oTokenBalance <= type(uint128).max,
"oTokenBalance > type(uint128) max value!"
);
// Use safeIncrease instead of safeApproval because safeApproval is only used for initial
// approval and cannot be called again. Using safeIncrease allow us to call _createOffer
// even when we are approving the same oTokens we have used before. This might happen if
// we accidentally burn the oTokens before settlement.
uint256 allowance =
IERC20(currentOtoken).allowance(address(this), swapContract);
if (allowance < oTokenBalance) {
IERC20(currentOtoken).safeIncreaseAllowance(
swapContract,
oTokenBalance.sub(allowance)
);
}
uint256 decimals = vaultParams.decimals;
// If total size is larger than 1, set minimum bid as 1
// Otherwise, set minimum bid to one tenth the total size
uint256 minBidSize =
oTokenBalance > 10**decimals ? 10**decimals : oTokenBalance.div(10);
require(
minBidSize <= type(uint96).max,
"minBidSize > type(uint96) max value!"
);
currOtokenPremium = decimals > 18
? currOtokenPremium.mul(10**(decimals.sub(18)))
: currOtokenPremium.div(10**(uint256(18).sub(decimals)));
optionAuctionID = ISwap(swapContract).createOffer(
currentOtoken,
vaultParams.asset,
uint96(currOtokenPremium),
uint96(minBidSize),
uint128(oTokenBalance)
);
}
/**
* @notice Allocates the vault's minted options to the OptionsPurchaseQueue contract
* @dev Skipped if the optionsPurchaseQueue doesn't exist
* @param optionsPurchaseQueue is the OptionsPurchaseQueue contract
* @param option is the minted option
* @param optionsAmount is the amount of options minted
* @param optionAllocation is the maximum % of options to allocate towards the purchase queue (will only allocate
* up to the amount that is on the queue)
* @return allocatedOptions is the amount of options that ended up getting allocated to the OptionsPurchaseQueue
*/
function allocateOptions(
address optionsPurchaseQueue,
address option,
uint256 optionsAmount,
uint256 optionAllocation
) external returns (uint256 allocatedOptions) {
// Skip if optionsPurchaseQueue is address(0)
if (optionsPurchaseQueue != address(0)) {
allocatedOptions = optionsAmount.mul(optionAllocation).div(
100 * Vault.OPTION_ALLOCATION_MULTIPLIER
);
allocatedOptions = IOptionsPurchaseQueue(optionsPurchaseQueue)
.getOptionsAllocation(address(this), allocatedOptions);
if (allocatedOptions != 0) {
IERC20(option).approve(optionsPurchaseQueue, allocatedOptions);
IOptionsPurchaseQueue(optionsPurchaseQueue).allocateOptions(
allocatedOptions
);
}
}
return allocatedOptions;
}
/**
* @notice Sell the allocated options to the purchase queue post auction settlement
* @dev Reverts if the auction hasn't settled yet
* @param optionsPurchaseQueue is the OptionsPurchaseQueue contract
* @param swapContract The address of the swap settlement contract
* @return totalPremiums Total premiums earnt by the vault
*/
function sellOptionsToQueue(
address optionsPurchaseQueue,
address swapContract,
uint256 optionAuctionID
) external returns (uint256) {
uint256 settlementPrice =
getAuctionSettlementPrice(swapContract, optionAuctionID);
require(settlementPrice != 0, "!settlementPrice");
return
IOptionsPurchaseQueue(optionsPurchaseQueue).sellToBuyers(
settlementPrice
);
}
/**
* @notice Gets the settlement price of a settled auction
* @param swapContract The address of the swap settlement contract
* @param optionAuctionID is the offer ID
* @return settlementPrice Auction settlement price
*/
function getAuctionSettlementPrice(
address swapContract,
uint256 optionAuctionID
) public view returns (uint256) {
return ISwap(swapContract).averagePriceForOffer(optionAuctionID);
}
/**
* @notice Verify the constructor params satisfy requirements
* @param owner is the owner of the vault with critical permissions
* @param feeRecipient is the address to recieve vault performance and management fees
* @param performanceFee is the perfomance fee pct.
* @param tokenName is the name of the token
* @param tokenSymbol is the symbol of the token
* @param _vaultParams is the struct with vault general data
*/
function verifyInitializerParams(
address owner,
address keeper,
address feeRecipient,
uint256 period,
uint256 performanceFee,
uint256 managementFee,
string calldata tokenName,
string calldata tokenSymbol,
Vault.VaultParams calldata _vaultParams
) external pure {
require(owner != address(0), "!owner");
require(keeper != address(0), "!keeper");
require(feeRecipient != address(0), "!feeRecipient");
require(period > 0, "!_period");
require(
performanceFee < 100 * Vault.FEE_MULTIPLIER,
"performanceFee >= 100%"
);
require(
managementFee < 100 * Vault.FEE_MULTIPLIER,
"managementFee >= 100%"
);
require(bytes(tokenName).length > 0, "!tokenName");
require(bytes(tokenSymbol).length > 0, "!tokenSymbol");
require(_vaultParams.asset != address(0), "!asset");
require(_vaultParams.underlying != address(0), "!underlying");
require(_vaultParams.minimumSupply > 0, "!minimumSupply");
require(_vaultParams.cap > 0, "!cap");
require(
_vaultParams.cap > _vaultParams.minimumSupply,
"cap has to be higher than minimumSupply"
);
}
/**
* @notice Gets the next options expiry timestamp for the specified period
* @param period is no. of days in between option sales. Available periods are:
* 7(1w), 14(2w), 30(1m), 90(3m), 180(6m)
*/
function getNextExpiry(uint256 period)
internal
view
returns (uint256 nextExpiry)
{
nextExpiry = block.timestamp + period * 1 days;
nextExpiry = nextExpiry - (nextExpiry % (24 hours)) + (8 hours);
}
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.4;
import {ISwap} from "../interfaces/ISwap.sol";
abstract contract RibbonThetaVaultStorageV1 {
// Logic contract used to price options
address public optionsPremiumPricer;
// Logic contract used to select strike prices
address public strikeSelection;
// Current oToken premium
uint256 public currentOtokenPremium;
// Last round id at which the strike was manually overridden
uint16 public lastStrikeOverrideRound;
// Price last overridden strike set to
uint256 public overriddenStrikePrice;
// Auction id of current option
uint256 public optionAuctionID;
// Amount locked for scheduled withdrawals last week;
uint256 public lastQueuedWithdrawAmount;
// OptionsPurchaseQueue contract for selling options
address public optionsPurchaseQueue;
// Queued withdraw shares for the current round
uint256 public currentQueuedWithdrawShares;
}
abstract contract RibbonThetaVaultStorageV2 {
// Settled bids from previous round
ISwap.Bid[] internal settledBids;
}
// We are following Compound's method of upgrading new contract implementations
// When we need to add new storage variables, we create a new version of RibbonThetaVaultStorage
// e.g. RibbonThetaVaultStorage<versionNumber>, so finally it would look like
// contract RibbonThetaVaultStorage is RibbonThetaVaultStorageV1, RibbonThetaVaultStorageV2
abstract contract RibbonThetaVaultStorage is RibbonThetaVaultStorageV1, RibbonThetaVaultStorageV2 {
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.4;
import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {
SafeERC20
} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {
ReentrancyGuardUpgradeable
} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import {
OwnableUpgradeable
} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {
ERC20Upgradeable
} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {
IERC20Permit
} from "@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol";
import {Vault} from "../../../libraries/Vault.sol";
import {
VaultLifecycleWithSwap
} from "../../../libraries/VaultLifecycleWithSwap.sol";
import {ShareMath} from "../../../libraries/ShareMath.sol";
import {IAmplol} from "../../../interfaces/IAmplol.sol";
contract RibbonVault is
ReentrancyGuardUpgradeable,
OwnableUpgradeable,
ERC20Upgradeable
{
using SafeERC20 for IERC20;
using SafeMath for uint256;
using ShareMath for Vault.DepositReceipt;
/************************************************
* NON UPGRADEABLE STORAGE
***********************************************/
/// @notice Stores the user's pending deposit for the round
mapping(address => Vault.DepositReceipt) public depositReceipts;
/// @notice On every round's close, the pricePerShare value of an rTHETA token is stored
/// This is used to determine the number of shares to be returned
/// to a user with their DepositReceipt.depositAmount
mapping(uint256 => uint256) public roundPricePerShare;
/// @notice Stores pending user withdrawals
mapping(address => Vault.Withdrawal) public withdrawals;
/// @notice Vault's parameters like cap, decimals
Vault.VaultParams public vaultParams;
/// @notice Vault's lifecycle state like round and locked amounts
Vault.VaultState public vaultState;
/// @notice Vault's state of the options sold and the timelocked option
Vault.OptionState public optionState;
/// @notice Fee recipient for the performance and management fees
address public feeRecipient;
/// @notice role in charge of weekly vault operations such as rollToNextOption and burnRemainingOTokens
// no access to critical vault changes
address public keeper;
/// @notice Performance fee charged on premiums earned in rollToNextOption. Only charged when there is no loss.
uint256 public performanceFee;
/// @notice Management fee charged on entire AUM in rollToNextOption. Only charged when there is no loss.
uint256 public managementFee;
/// @notice Period between each options sale.
/// Available options 7 (weekly), 14 (biweekly), 30 (monthly), 90 (quarterly), 180 (biannually)
uint256 public period;
// Gap is left to avoid storage collisions. Though RibbonVault is not upgradeable, we add this as a safety measure.
uint256[30] private ____gap;
// *IMPORTANT* NO NEW STORAGE VARIABLES SHOULD BE ADDED HERE
// This is to prevent storage collisions. All storage variables should be appended to RibbonThetaVaultStorage
// or RibbonDeltaVaultStorage instead. Read this documentation to learn more:
// https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#modifying-your-contracts
/************************************************
* IMMUTABLES & CONSTANTS
***********************************************/
// Number of weeks per year = 52.142857 weeks * FEE_MULTIPLIER = 52142857
// Dividing by weeks per year requires doing num.mul(FEE_MULTIPLIER).div(WEEKS_PER_YEAR)
uint256 private constant WEEKS_PER_YEAR = 52142857;
// GAMMA_CONTROLLER is the top-level contract in Gamma protocol
// which allows users to perform multiple actions on their vaults
// and positions https://github.com/opynfinance/GammaProtocol/blob/master/contracts/core/Controller.sol
address public immutable GAMMA_CONTROLLER;
// MARGIN_POOL is Gamma protocol's collateral pool.
// Needed to approve collateral.safeTransferFrom for minting otokens.
// https://github.com/opynfinance/GammaProtocol/blob/master/contracts/core/MarginPool.sol
address public immutable MARGIN_POOL;
// SWAP_CONTRACT is a contract for settling bids via signed messages
// https://github.com/ribbon-finance/ribbon-v2/blob/master/contracts/utils/Swap.sol
address public immutable SWAP_CONTRACT;
/// @notice amplol is the amplol address.
IAmplol public immutable AMPLOL;
/************************************************
* EVENTS
***********************************************/
event Deposit(address indexed account, uint256 amount, uint256 round);
event InitiateWithdraw(
address indexed account,
uint256 shares,
uint256 round
);
event Redeem(address indexed account, uint256 share, uint256 round);
event ManagementFeeSet(uint256 managementFee, uint256 newManagementFee);
event PerformanceFeeSet(uint256 performanceFee, uint256 newPerformanceFee);
event CapSet(uint256 oldCap, uint256 newCap);
event Withdraw(address indexed account, uint256 amount, uint256 shares);
event CollectVaultFees(
uint256 performanceFee,
uint256 vaultFee,
uint256 round,
address indexed feeRecipient
);
/************************************************
* CONSTRUCTOR & INITIALIZATION
***********************************************/
/**
* @notice Initializes the contract with immutable variables
* @param _gammaController is the contract address for opyn actions
* @param _marginPool is the contract address for providing collateral to opyn
* @param _swapContract is the contract address that facilitates bids settlement
* @param _amplol is the contract address for AMPLOLs
*/
constructor(
address _gammaController,
address _marginPool,
address _swapContract,
address _amplol
) {
require(_swapContract != address(0), "!_swapContract");
require(_gammaController != address(0), "!_gammaController");
require(_marginPool != address(0), "!_marginPool");
require(_amplol != address(0), "!_amplol");
GAMMA_CONTROLLER = _gammaController;
MARGIN_POOL = _marginPool;
SWAP_CONTRACT = _swapContract;
AMPLOL = IAmplol(_amplol);
}
/**
* @notice Initializes the OptionVault contract with storage variables.
*/
function baseInitialize(
address _owner,
address _keeper,
address _feeRecipient,
uint256 _period,
uint256 _managementFee,
uint256 _performanceFee,
string memory _tokenName,
string memory _tokenSymbol,
Vault.VaultParams calldata _vaultParams
) internal initializer {
VaultLifecycleWithSwap.verifyInitializerParams(
_owner,
_keeper,
_feeRecipient,
_period,
_performanceFee,
_managementFee,
_tokenName,
_tokenSymbol,
_vaultParams
);
__ReentrancyGuard_init();
__ERC20_init(_tokenName, _tokenSymbol);
__Ownable_init();
transferOwnership(_owner);
keeper = _keeper;
feeRecipient = _feeRecipient;
period = _period;
performanceFee = _performanceFee;
managementFee = _perRoundManagementFee(_managementFee);
vaultParams = _vaultParams;
uint256 assetBalance =
IERC20(vaultParams.asset).balanceOf(address(this));
ShareMath.assertUint104(assetBalance);
vaultState.lastLockedAmount = uint104(assetBalance);
vaultState.round = 1;
}
/**
* @dev Throws if called by any account other than the keeper.
*/
modifier onlyKeeper() {
require(msg.sender == keeper, "!keeper");
_;
}
/************************************************
* SETTERS
***********************************************/
/**
* @notice Sets the new keeper
* @param newKeeper is the address of the new keeper
*/
function setNewKeeper(address newKeeper) external onlyOwner {
require(newKeeper != address(0), "!newKeeper");
keeper = newKeeper;
}
/**
* @notice Sets the new fee recipient
* @param newFeeRecipient is the address of the new fee recipient
*/
function setFeeRecipient(address newFeeRecipient) external onlyOwner {
require(newFeeRecipient != address(0), "!newFeeRecipient");
require(newFeeRecipient != feeRecipient, "Must be new feeRecipient");
feeRecipient = newFeeRecipient;
}
/**
* @notice Sets the management fee for the vault
* @param newManagementFee is the management fee (6 decimals). ex: 2 * 10 ** 6 = 2%
*/
function setManagementFee(uint256 newManagementFee) external onlyOwner {
require(
newManagementFee < 100 * Vault.FEE_MULTIPLIER,
"Invalid management fee"
);
managementFee = _perRoundManagementFee(newManagementFee);
emit ManagementFeeSet(managementFee, newManagementFee);
}
/**
* @notice Sets the performance fee for the vault
* @param newPerformanceFee is the performance fee (6 decimals). ex: 20 * 10 ** 6 = 20%
*/
function setPerformanceFee(uint256 newPerformanceFee) external onlyOwner {
require(
newPerformanceFee < 100 * Vault.FEE_MULTIPLIER,
"Invalid performance fee"
);
emit PerformanceFeeSet(performanceFee, newPerformanceFee);
performanceFee = newPerformanceFee;
}
/**
* @notice Sets a new cap for deposits
* @param newCap is the new cap for deposits
*/
function setCap(uint256 newCap) external onlyOwner {
require(newCap > 0, "!newCap");
ShareMath.assertUint104(newCap);
emit CapSet(vaultParams.cap, newCap);
vaultParams.cap = uint104(newCap);
}
/************************************************
* DEPOSIT & WITHDRAWALS
***********************************************/
/**
* @notice Deposits the `asset` from msg.sender without an approve
* `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments
* @param amount is the amount of `asset` to deposit
* @param deadline must be a timestamp in the future
* @param v is a valid signature
* @param r is a valid signature
* @param s is a valid signature
*/
function depositWithPermit(
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external nonReentrant {
require(amount > 0, "!amount");
// Sign for transfer approval
IERC20Permit(vaultParams.asset).permit(
msg.sender,
address(this),
amount,
deadline,
v,
r,
s
);
_depositFor(amount, msg.sender);
// An approve() by the msg.sender is required beforehand
IERC20(vaultParams.asset).safeTransferFrom(
msg.sender,
address(this),
amount
);
AMPLOL.mint(msg.sender, amount);
}
/**
* @notice Deposits the `asset` from msg.sender.
* @param amount is the amount of `asset` to deposit
*/
function deposit(uint256 amount) external nonReentrant {
require(amount > 0, "!amount");
_depositFor(amount, msg.sender);
// An approve() by the msg.sender is required beforehand
IERC20(vaultParams.asset).safeTransferFrom(
msg.sender,
address(this),
amount
);
AMPLOL.mint(msg.sender, amount);
}
/**
* @notice Deposits the `asset` from msg.sender added to `creditor`'s deposit.
* @notice Used for vault -> vault deposits on the user's behalf
* @param amount is the amount of `asset` to deposit
* @param creditor is the address that can claim/withdraw deposited amount
*/
function depositFor(uint256 amount, address creditor)
external
nonReentrant
{
require(amount > 0, "!amount");
require(creditor != address(0));
_depositFor(amount, creditor);
// An approve() by the msg.sender is required beforehand
IERC20(vaultParams.asset).safeTransferFrom(
msg.sender,
address(this),
amount
);
AMPLOL.mint(creditor, amount);
}
/**
* @notice Internal function to set the management fee for the vault
* @param _managementFee is the management fee (6 decimals). ex: 2 * 10 ** 6 = 2%
* @return perRoundManagementFee is the management divided by the number of rounds per year
*/
function _perRoundManagementFee(uint256 _managementFee)
internal
view
returns (uint256)
{
uint256 _period = period;
uint256 feeDivider =
_period % 30 == 0
? (Vault.FEE_MULTIPLIER * 12 * 30)/ _period
: (WEEKS_PER_YEAR * 7) / _period;
// We are dividing annualized management fee by num weeks in a year
return _managementFee.mul(Vault.FEE_MULTIPLIER).div(feeDivider);
}
/**
* @notice Mints the vault shares to the creditor
* @param amount is the amount of `asset` deposited
* @param creditor is the address to receieve the deposit
*/
function _depositFor(uint256 amount, address creditor) private {
uint256 currentRound = vaultState.round;
uint256 totalWithDepositedAmount = totalBalance().add(amount);
require(totalWithDepositedAmount <= vaultParams.cap, "Exceed cap");
require(
totalWithDepositedAmount >= vaultParams.minimumSupply,
"Insufficient balance"
);
emit Deposit(creditor, amount, currentRound);
Vault.DepositReceipt memory depositReceipt = depositReceipts[creditor];
// If we have an unprocessed pending deposit from the previous rounds, we have to process it.
uint256 unredeemedShares =
depositReceipt.getSharesFromReceipt(
currentRound,
roundPricePerShare[depositReceipt.round],
vaultParams.decimals
);
uint256 depositAmount = amount;
// If we have a pending deposit in the current round, we add on to the pending deposit
if (currentRound == depositReceipt.round) {
uint256 newAmount = uint256(depositReceipt.amount).add(amount);
depositAmount = newAmount;
}
ShareMath.assertUint104(depositAmount);
depositReceipts[creditor] = Vault.DepositReceipt({
round: uint16(currentRound),
amount: uint104(depositAmount),
unredeemedShares: uint128(unredeemedShares)
});
uint256 newTotalPending = uint256(vaultState.totalPending).add(amount);
ShareMath.assertUint128(newTotalPending);
vaultState.totalPending = uint128(newTotalPending);
}
/**
* @notice Initiates a withdrawal that can be processed once the round completes
* @param numShares is the number of shares to withdraw
*/
function _initiateWithdraw(uint256 numShares) internal {
require(numShares > 0, "!numShares");
// We do a max redeem before initiating a withdrawal
// But we check if they must first have unredeemed shares
if (
depositReceipts[msg.sender].amount > 0 ||
depositReceipts[msg.sender].unredeemedShares > 0
) {
_redeem(0, true);
}
// This caches the `round` variable used in shareBalances
uint256 currentRound = vaultState.round;
Vault.Withdrawal storage withdrawal = withdrawals[msg.sender];
bool withdrawalIsSameRound = withdrawal.round == currentRound;
emit InitiateWithdraw(msg.sender, numShares, currentRound);
uint256 existingShares = uint256(withdrawal.shares);
uint256 withdrawalShares;
if (withdrawalIsSameRound) {
withdrawalShares = existingShares.add(numShares);
} else {
require(existingShares == 0, "Existing withdraw");
withdrawalShares = numShares;
withdrawals[msg.sender].round = uint16(currentRound);
}
ShareMath.assertUint128(withdrawalShares);
withdrawals[msg.sender].shares = uint128(withdrawalShares);
_transfer(msg.sender, address(this), numShares);
}
/**
* @notice Completes a scheduled withdrawal from a past round. Uses finalized pps for the round
* @return withdrawAmount the current withdrawal amount
*/
function _completeWithdraw() internal returns (uint256) {
Vault.Withdrawal storage withdrawal = withdrawals[msg.sender];
uint256 withdrawalShares = withdrawal.shares;
uint256 withdrawalRound = withdrawal.round;
// This checks if there is a withdrawal
require(withdrawalShares > 0, "Not initiated");
require(withdrawalRound < vaultState.round, "Round not closed");
// We leave the round number as non-zero to save on gas for subsequent writes
withdrawals[msg.sender].shares = 0;
vaultState.queuedWithdrawShares = uint128(
uint256(vaultState.queuedWithdrawShares).sub(withdrawalShares)
);
uint256 withdrawAmount =
ShareMath.sharesToAsset(
withdrawalShares,
roundPricePerShare[withdrawalRound],
vaultParams.decimals
);
emit Withdraw(msg.sender, withdrawAmount, withdrawalShares);
_burn(address(this), withdrawalShares);
require(withdrawAmount > 0, "!withdrawAmount");
AMPLOL.burn(msg.sender, withdrawAmount);
transferAsset(msg.sender, withdrawAmount);
return withdrawAmount;
}
/**
* @notice Redeems shares that are owed to the account
* @param numShares is the number of shares to redeem
*/
function redeem(uint256 numShares) external nonReentrant {
require(numShares > 0, "!numShares");
_redeem(numShares, false);
}
/**
* @notice Redeems the entire unredeemedShares balance that is owed to the account
*/
function maxRedeem() external nonReentrant {
_redeem(0, true);
}
/**
* @notice Redeems shares that are owed to the account
* @param numShares is the number of shares to redeem, could be 0 when isMax=true
* @param isMax is flag for when callers do a max redemption
*/
function _redeem(uint256 numShares, bool isMax) internal {
Vault.DepositReceipt memory depositReceipt =
depositReceipts[msg.sender];
// This handles the null case when depositReceipt.round = 0
// Because we start with round = 1 at `initialize`
uint256 currentRound = vaultState.round;
uint256 unredeemedShares =
depositReceipt.getSharesFromReceipt(
currentRound,
roundPricePerShare[depositReceipt.round],
vaultParams.decimals
);
numShares = isMax ? unredeemedShares : numShares;
if (numShares == 0) {
return;
}
require(numShares <= unredeemedShares, "Exceeds available");
// If we have a depositReceipt on the same round, BUT we have some unredeemed shares
// we debit from the unredeemedShares, but leave the amount field intact
// If the round has past, with no new deposits, we just zero it out for new deposits.
if (depositReceipt.round < currentRound) {
depositReceipts[msg.sender].amount = 0;
}
ShareMath.assertUint128(numShares);
depositReceipts[msg.sender].unredeemedShares = uint128(
unredeemedShares.sub(numShares)
);
emit Redeem(msg.sender, numShares, depositReceipt.round);
_transfer(address(this), msg.sender, numShares);
}
/************************************************
* VAULT OPERATIONS
***********************************************/
/**
* @notice Helper function that helps to save gas for writing values into the roundPricePerShare map.
* Writing `1` into the map makes subsequent writes warm, reducing the gas from 20k to 5k.
* Having 1 initialized beforehand will not be an issue as long as we round down share calculations to 0.
* @param numRounds is the number of rounds to initialize in the map
*/
function initRounds(uint256 numRounds) external nonReentrant {
require(numRounds > 0, "!numRounds");
uint256 _round = vaultState.round;
for (uint256 i = 0; i < numRounds; i++) {
uint256 index = _round + i;
require(roundPricePerShare[index] == 0, "Initialized"); // AVOID OVERWRITING ACTUAL VALUES
roundPricePerShare[index] = ShareMath.PLACEHOLDER_UINT;
}
}
/**
* @notice Helper function that performs most administrative tasks
* such as minting new shares, getting vault fees, etc.
* @param lastQueuedWithdrawAmount is old queued withdraw amount
* @param currentQueuedWithdrawShares is the queued withdraw shares for the current round
* @return lockedBalance is the new balance used to calculate next option purchase size or collateral size
* @return queuedWithdrawAmount is the new queued withdraw amount for this round
*/
function _closeRound(
uint256 lastQueuedWithdrawAmount,
uint256 currentQueuedWithdrawShares
) internal returns (uint256 lockedBalance, uint256 queuedWithdrawAmount) {
address recipient = feeRecipient;
uint256 mintShares;
uint256 performanceFeeInAsset;
uint256 totalVaultFee;
{
uint256 newPricePerShare;
(
lockedBalance,
queuedWithdrawAmount,
newPricePerShare,
mintShares,
performanceFeeInAsset,
totalVaultFee
) = VaultLifecycleWithSwap.closeRound(
vaultState,
VaultLifecycleWithSwap.CloseParams(
vaultParams.decimals,
IERC20(vaultParams.asset).balanceOf(address(this)),
totalSupply(),
lastQueuedWithdrawAmount,
performanceFee,
managementFee,
currentQueuedWithdrawShares
)
);
// Finalize the pricePerShare at the end of the round
uint256 currentRound = vaultState.round;
roundPricePerShare[currentRound] = newPricePerShare;
emit CollectVaultFees(
performanceFeeInAsset,
totalVaultFee,
currentRound,
recipient
);
vaultState.totalPending = 0;
vaultState.round = uint16(currentRound + 1);
}
_mint(address(this), mintShares);
if (totalVaultFee > 0) {
transferAsset(payable(recipient), totalVaultFee);
}
return (lockedBalance, queuedWithdrawAmount);
}
/**
* @notice Helper function to make either an ETH transfer or ERC20 transfer
* @param recipient is the receiving address
* @param amount is the transfer amount
*/
function transferAsset(address recipient, uint256 amount) internal {
address asset = vaultParams.asset;
IERC20(asset).safeTransfer(recipient, amount);
}
/************************************************
* GETTERS
***********************************************/
/**
* @notice Returns the asset balance held on the vault for the account
* @param account is the address to lookup balance for
* @return the amount of `asset` custodied by the vault for the user
*/
function accountVaultBalance(address account)
external
view
returns (uint256)
{
uint256 _decimals = vaultParams.decimals;
uint256 assetPerShare =
ShareMath.pricePerShare(
totalSupply(),
totalBalance(),
vaultState.totalPending,
_decimals
);
return
ShareMath.sharesToAsset(shares(account), assetPerShare, _decimals);
}
/**
* @notice Getter for returning the account's share balance including unredeemed shares
* @param account is the account to lookup share balance for
* @return the share balance
*/
function shares(address account) public view returns (uint256) {
(uint256 heldByAccount, uint256 heldByVault) = shareBalances(account);
return heldByAccount.add(heldByVault);
}
/**
* @notice Getter for returning the account's share balance split between account and vault holdings
* @param account is the account to lookup share balance for
* @return heldByAccount is the shares held by account
* @return heldByVault is the shares held on the vault (unredeemedShares)
*/
function shareBalances(address account)
public
view
returns (uint256 heldByAccount, uint256 heldByVault)
{
Vault.DepositReceipt memory depositReceipt = depositReceipts[account];
if (depositReceipt.round < ShareMath.PLACEHOLDER_UINT) {
return (balanceOf(account), 0);
}
uint256 unredeemedShares =
depositReceipt.getSharesFromReceipt(
vaultState.round,
roundPricePerShare[depositReceipt.round],
vaultParams.decimals
);
return (balanceOf(account), unredeemedShares);
}
/**
* @notice The price of a unit of share denominated in the `asset`
*/
function pricePerShare() external view returns (uint256) {
return
ShareMath.pricePerShare(
totalSupply(),
totalBalance(),
vaultState.totalPending,
vaultParams.decimals
);
}
/**
* @notice Returns the vault's total balance, including the amounts locked into a short position
* @return total balance of the vault, including the amounts locked in third party protocols
*/
function totalBalance() public view returns (uint256) {
// After calling closeRound, current option is set to none
// We also commit the lockedAmount but do not deposit into Opyn
// which results in double counting of asset balance and lockedAmount
return
optionState.currentOption != address(0)
? uint256(vaultState.lockedAmount).add(
IERC20(vaultParams.asset).balanceOf(address(this))
)
: IERC20(vaultParams.asset).balanceOf(address(this));
}
/**
* @notice Returns the token decimals
*/
function decimals() public view override returns (uint8) {
return vaultParams.decimals;
}
function cap() external view returns (uint256) {
return vaultParams.cap;
}
function nextOptionReadyAt() external view returns (uint256) {
return optionState.nextOptionReadyAt;
}
function currentOption() external view returns (address) {
return optionState.currentOption;
}
function nextOption() external view returns (address) {
return optionState.nextOption;
}
function totalPending() external view returns (uint256) {
return vaultState.totalPending;
}
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"metadata": {
"useLiteralContent": true
},
"libraries": {
"contracts/libraries/VaultLifecycleWithSwap.sol": {
"VaultLifecycleWithSwap": "0x4f1fafbfe3a3a3f66e17ba674c5c79eb0cdc19ba"
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_oTokenFactory","type":"address"},{"internalType":"address","name":"_gammaController","type":"address"},{"internalType":"address","name":"_marginPool","type":"address"},{"internalType":"address","name":"_swapContract","type":"address"},{"internalType":"address","name":"_amplol","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldCap","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newCap","type":"uint256"}],"name":"CapSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"options","type":"address"},{"indexed":false,"internalType":"uint256","name":"withdrawAmount","type":"uint256"},{"indexed":true,"internalType":"address","name":"manager","type":"address"}],"name":"CloseShort","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"performanceFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"vaultFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"round","type":"uint256"},{"indexed":true,"internalType":"address","name":"feeRecipient","type":"address"}],"name":"CollectVaultFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"round","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"round","type":"uint256"}],"name":"InitiateWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"round","type":"uint256"}],"name":"InstantWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"managementFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newManagementFee","type":"uint256"}],"name":"ManagementFeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"swapId","type":"uint256"},{"indexed":false,"internalType":"address","name":"seller","type":"address"},{"indexed":false,"internalType":"address","name":"oToken","type":"address"},{"indexed":false,"internalType":"address","name":"biddingToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"minPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"minBidSize","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalSize","type":"uint256"}],"name":"NewOffer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"strikePrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"delta","type":"uint256"}],"name":"NewOptionStrikeSelected","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"options","type":"address"},{"indexed":false,"internalType":"uint256","name":"depositAmount","type":"uint256"},{"indexed":true,"internalType":"address","name":"manager","type":"address"}],"name":"OpenShort","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"performanceFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newPerformanceFee","type":"uint256"}],"name":"PerformanceFeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"share","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"round","type":"uint256"}],"name":"Redeem","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"AMPLOL","outputs":[{"internalType":"contract IAmplol","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DELAY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"GAMMA_CONTROLLER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MARGIN_POOL","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OTOKEN_FACTORY","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SWAP_CONTRACT","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"USDC","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"accountVaultBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"burnRemainingOTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"closeRound","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"commitNextOption","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"completeWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"currentOption","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentOtokenPremium","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentQueuedWithdrawShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"creditor","type":"address"}],"name":"depositFor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"depositReceipts","outputs":[{"internalType":"uint16","name":"round","type":"uint16"},{"internalType":"uint104","name":"amount","type":"uint104"},{"internalType":"uint128","name":"unredeemedShares","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"depositWithPermit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"numRounds","type":"uint256"}],"name":"initRounds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_keeper","type":"address"},{"internalType":"address","name":"_feeRecipient","type":"address"},{"internalType":"uint256","name":"_period","type":"uint256"},{"internalType":"uint256","name":"_managementFee","type":"uint256"},{"internalType":"uint256","name":"_performanceFee","type":"uint256"},{"internalType":"string","name":"_tokenName","type":"string"},{"internalType":"string","name":"_tokenSymbol","type":"string"},{"internalType":"address","name":"_optionsPremiumPricer","type":"address"},{"internalType":"address","name":"_strikeSelection","type":"address"}],"internalType":"struct RibbonThetaVaultWithSwap.InitParams","name":"_initParams","type":"tuple"},{"components":[{"internalType":"bool","name":"isPut","type":"bool"},{"internalType":"uint8","name":"decimals","type":"uint8"},{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"underlying","type":"address"},{"internalType":"uint56","name":"minimumSupply","type":"uint56"},{"internalType":"uint104","name":"cap","type":"uint104"}],"internalType":"struct Vault.VaultParams","name":"_vaultParams","type":"tuple"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"numShares","type":"uint256"}],"name":"initiateWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"keeper","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastQueuedWithdrawAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastStrikeOverrideRound","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"managementFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxRedeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextOption","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextOptionReadyAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"optionAuctionID","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"optionState","outputs":[{"internalType":"address","name":"nextOption","type":"address"},{"internalType":"address","name":"currentOption","type":"address"},{"internalType":"uint32","name":"nextOptionReadyAt","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"optionsPremiumPricer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"optionsPurchaseQueue","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"overriddenStrikePrice","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":"performanceFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"period","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pricePerShare","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"numShares","type":"uint256"}],"name":"redeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rollToNextOption","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"roundPricePerShare","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"newCap","type":"uint256"}],"name":"setCap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newFeeRecipient","type":"address"}],"name":"setFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newManagementFee","type":"uint256"}],"name":"setManagementFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"minPrice","type":"uint256"}],"name":"setMinPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newKeeper","type":"address"}],"name":"setNewKeeper","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOptionsPremiumPricer","type":"address"}],"name":"setOptionsPremiumPricer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newPerformanceFee","type":"uint256"}],"name":"setPerformanceFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"strikePrice","type":"uint128"}],"name":"setStrikePrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newStrikeSelection","type":"address"}],"name":"setStrikeSelection","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"swapId","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"address","name":"signerWallet","type":"address"},{"internalType":"address","name":"buyer","type":"address"},{"internalType":"uint256","name":"sellAmount","type":"uint256"},{"internalType":"uint256","name":"buyAmount","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct ISwap.Bid[]","name":"bids","type":"tuple[]"}],"name":"settleOffer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"shareBalances","outputs":[{"internalType":"uint256","name":"heldByAccount","type":"uint256"},{"internalType":"uint256","name":"heldByVault","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"shares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"strikeSelection","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalPending","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"vaultParams","outputs":[{"internalType":"bool","name":"isPut","type":"bool"},{"internalType":"uint8","name":"decimals","type":"uint8"},{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"underlying","type":"address"},{"internalType":"uint56","name":"minimumSupply","type":"uint56"},{"internalType":"uint104","name":"cap","type":"uint104"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vaultState","outputs":[{"internalType":"uint16","name":"round","type":"uint16"},{"internalType":"uint104","name":"lockedAmount","type":"uint104"},{"internalType":"uint104","name":"lastLockedAmount","type":"uint104"},{"internalType":"uint128","name":"totalPending","type":"uint128"},{"internalType":"uint128","name":"queuedWithdrawShares","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawInstantly","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"withdrawals","outputs":[{"internalType":"uint16","name":"round","type":"uint16"},{"internalType":"uint128","name":"shares","type":"uint128"}],"stateMutability":"view","type":"function"}]Contract Creation Code
6101206040523480156200001257600080fd5b506040516200581f3803806200581f833981016040819052620000359162000208565b838383836001600160a01b038216620000865760405162461bcd60e51b815260206004820152600e60248201526d0857dcddd85c10dbdb9d1c9858dd60921b60448201526064015b60405180910390fd5b6001600160a01b038416620000d25760405162461bcd60e51b815260206004820152601160248201527010afb3b0b6b6b0a1b7b73a3937b63632b960791b60448201526064016200007d565b6001600160a01b038316620001195760405162461bcd60e51b815260206004820152600c60248201526b0857db585c99da5b941bdbdb60a21b60448201526064016200007d565b6001600160a01b0381166200015c5760405162461bcd60e51b81526020600482015260086024820152670857d85b5c1b1bdb60c21b60448201526064016200007d565b6001600160601b0319606094851b811660805292841b831660a05290831b821660c05290911b1660e0526001600160a01b038516620001d05760405162461bcd60e51b815260206004820152600f60248201526e215f6f546f6b656e466163746f727960881b60448201526064016200007d565b5050505060601b6001600160601b0319166101005262000277565b80516001600160a01b03811681146200020357600080fd5b919050565b600080600080600060a0868803121562000220578081fd5b6200022b86620001eb565b94506200023b60208701620001eb565b93506200024b60408701620001eb565b92506200025b60608701620001eb565b91506200026b60808701620001eb565b90509295509295909350565b60805160601c60a05160601c60c05160601c60e05160601c6101005160601c6155006200031f60003960008181610adb01526128cd015260008181610b3b015281816111760152818161132c015281816117c801528181611f6c0152613fa0015260008181610a85015281816114aa01526138750152600081816106fa01526121210152600081816104bb015281816119a6015281816120f901526139ad01526155006000f3fe608060405234801561001057600080fd5b50600436106104495760003560e01c80638778878211610241578063ce7c2ac21161013b578063e73c63d5116100c3578063f756fa2111610087578063f756fa2114610bc5578063f87c7d9314610bcd578063f957a06714610bd5578063fba7dc6114610be8578063fe56e23214610bfb57600080fd5b8063e73c63d514610b65578063e74b981b14610b6e578063ef78d4fd14610b81578063f2fde38b14610b8a578063f656ba5114610b9d57600080fd5b8063db006a751161010a578063db006a7514610ac3578063db43e86214610ad6578063dd62ed3e14610afd578063de667d3114610b36578063e278fe6f14610b5d57600080fd5b8063ce7c2ac214610a6d578063cf3afa5114610a80578063d164cc1514610aa7578063d5f2638214610aba57600080fd5b8063a285c9e8116101c9578063aced16611161018d578063aced166114610a24578063ad7a672f14610a37578063afa6626414610a3f578063b6b55f2514610a52578063b9f8092b14610a6557600080fd5b8063a285c9e8146109cf578063a2db9d83146109e4578063a457c2d7146109f5578063a6f7f5d614610a08578063a9059cbb14610a1157600080fd5b806395d89b411161021057806395d89b41146108b757806399530b06146108bf5780639be43daa146108c75780639fcc2d75146108da578063a083ff171461097957600080fd5b8063877887821461087157806389a302711461087a5780638b10cc7c146108955780638da5cb5b146108a657600080fd5b80634603c0aa11610352578063650cce8a116102da57806370a082311161029e57806370a08231146107b6578063715018a6146107df5780637a9262a2146107e75780637e108d521461083e57806387153eb11461085157600080fd5b8063650cce8a146106f55780636719b2ee1461071c57806369b41170146107935780636f31ab341461079b57806370897b23146107a357600080fd5b80634b2431d9116103215780634b2431d9146106b5578063503c70aa146106be57806355489bb2146106c75780635ea8cd12146106da578063600a2cfb146106ed57600080fd5b80634603c0aa14610669578063469048401461067c57806347786d371461068f5780634a970be7146106a257600080fd5b8063313ce567116103d55780633cb7bf19116103a45780633cb7bf19146106085780633ec143d31461061b5780633f23bb731461063c5780633f90916a1461064f578063432833a61461066057600080fd5b8063313ce567146105b4578063355274ea146105d157806336efd16f146105e257806339509351146105f557600080fd5b80631a92f6c21161041c5780631a92f6c2146104b657806323b872dd146104f55780632728f333146105085780632775d01c1461058e57806330630da4146105a157600080fd5b806305e941ec1461044e57806306fdde0314610463578063095ea7b31461048157806318160ddd146104a4575b600080fd5b61046161045c366004614aa3565b610c0e565b005b61046b610e76565b6040516104789190614d55565b60405180910390f35b61049461048f3660046149b5565b610f08565b6040519015158152602001610478565b6099545b604051908152602001610478565b6104dd7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610478565b610494610503366004614975565b610f1f565b60cf5460d0546105499161ffff8116916001600160681b03620100008304811692600160781b900416906001600160801b0380821691600160801b90041685565b6040805161ffff90961686526001600160681b03948516602087015293909216928401929092526001600160801b03918216606084015216608082015260a001610478565b61046161059c366004614b26565b610fcb565b6104616105af366004614921565b6111ee565b60cc54610100900460ff1660405160ff9091168152602001610478565b60ce546001600160681b03166104a8565b6104616105f0366004614b56565b611286565b6104946106033660046149b5565b611391565b610461610616366004614a16565b6113cd565b60f9546106299061ffff1681565b60405161ffff9091168152602001610478565b6104a861064a366004614921565b6114e2565b60d0546001600160801b03166104a8565b6104a860fb5481565b610461610677366004614921565b611535565b60d3546104dd906001600160a01b031681565b61046161069d366004614b26565b6115d7565b6104616106b0366004614bc3565b6116b2565b6104a860fe5481565b6104a860fc5481565b6104616106d5366004614aff565b611837565b6104616106e8366004614b26565b6118cf565b61046161193a565b6104dd7f000000000000000000000000000000000000000000000000000000000000000081565b61076261072a366004614921565b60c96020526000908152604090205461ffff8116906201000081046001600160681b031690600160781b90046001600160801b031683565b6040805161ffff90941684526001600160681b0390921660208401526001600160801b031690820152606001610478565b6104a8600081565b610461611a4a565b6104616107b1366004614b26565b611a87565b6104a86107c4366004614921565b6001600160a01b031660009081526097602052604090205490565b610461611b4e565b61081c6107f5366004614921565b60cb6020526000908152604090205461ffff8116906201000090046001600160801b031682565b6040805161ffff90931683526001600160801b03909116602083015201610478565b61046161084c366004614b26565b611b84565b6104a861085f366004614b26565b60ca6020526000908152604090205481565b6104a860d55481565b6104dd73a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b60d2546001600160a01b03166104dd565b6065546001600160a01b03166104dd565b61046b611bcc565b6104a8611bdb565b6104616108d5366004614b26565b611c15565b60cc5460cd5460ce546109299260ff808216936101008304909116926001600160a01b036201000090930483169282169166ffffffffffffff600160a01b90910416906001600160681b031686565b60408051961515875260ff90951660208701526001600160a01b03938416948601949094529116606084015266ffffffffffffff1660808301526001600160681b031660a082015260c001610478565b60d15460d2546109a3916001600160a01b039081169190811690600160a01b900463ffffffff1683565b604080516001600160a01b03948516815293909216602084015263ffffffff1690820152606001610478565b60d254600160a01b900463ffffffff166104a8565b60d1546001600160a01b03166104dd565b610494610a033660046149b5565b611d0f565b6104a860d65481565b610494610a1f3660046149b5565b611da8565b60d4546104dd906001600160a01b031681565b6104a8611db5565b60f6546104dd906001600160a01b031681565b610461610a60366004614b26565b611ee3565b610461611fd7565b6104a8610a7b366004614921565b6121d5565b6104dd7f000000000000000000000000000000000000000000000000000000000000000081565b610461610ab5366004614921565b6121f2565b6104a860f85481565b610461610ad1366004614b26565b612281565b6104dd7f000000000000000000000000000000000000000000000000000000000000000081565b6104a8610b0b36600461493d565b6001600160a01b03918216600090815260986020908152604080832093909416825291909152205490565b6104dd7f000000000000000000000000000000000000000000000000000000000000000081565b6104616122ee565b6104a860fa5481565b610461610b7c366004614921565b612540565b6104a860d75481565b610461610b98366004614921565b612633565b610bb0610bab366004614921565b6126ce565b60408051928352602083019190915201610478565b6104616127b1565b610461612806565b60f7546104dd906001600160a01b031681565b60fd546104dd906001600160a01b031681565b610461610c09366004614b26565b612a5a565b600054610100900460ff1680610c27575060005460ff16155b610c4c5760405162461bcd60e51b8152600401610c4390614d89565b60405180910390fd5b600054610100900460ff16158015610c6e576000805461ffff19166101011790555b610d38610c7e6020850185614921565b610c8e6040860160208701614921565b610c9e6060870160408801614921565b6060870135608088013560a0890135610cba60c08b018b61501f565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250610cfc9250505060e08c018c61501f565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152508d9250612b23915050565b6000610d4c61012085016101008601614921565b6001600160a01b03161415610d9c5760405162461bcd60e51b815260206004820152601660248201527510afb7b83a34b7b739a83932b6b4bab6a83934b1b2b960511b6044820152606401610c43565b6000610db061014085016101208601614921565b6001600160a01b03161415610dfb5760405162461bcd60e51b815260206004820152601160248201527010afb9ba3934b5b2a9b2b632b1ba34b7b760791b6044820152606401610c43565b610e0d61012084016101008501614921565b60f680546001600160a01b0319166001600160a01b0392909216919091179055610e3f61014084016101208501614921565b60f780546001600160a01b0319166001600160a01b03929092169190911790558015610e71576000805461ff00191690555b505050565b6060609a8054610e85906151dd565b80601f0160208091040260200160405190810160405280929190818152602001828054610eb1906151dd565b8015610efe5780601f10610ed357610100808354040283529160200191610efe565b820191906000526020600020905b815481529060010190602001808311610ee157829003601f168201915b5050505050905090565b6000610f15338484612d5e565b5060015b92915050565b6000610f2c848484612e83565b6001600160a01b038416600090815260986020908152604080832033845290915290205482811015610fb15760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b6064820152608401610c43565b610fbe8533858403612d5e565b60019150505b9392505050565b60026001541415610fee5760405162461bcd60e51b8152600401610c4390614e2d565b600260015533600090815260c96020526040902060cf5461ffff16826110265760405162461bcd60e51b8152600401610c4390614e0c565b815461ffff16811461106a5760405162461bcd60e51b815260206004820152600d60248201526c125b9d985b1a59081c9bdd5b99609a1b6044820152606401610c43565b81546201000090046001600160681b0316838110156110bb5760405162461bcd60e51b815260206004820152600d60248201526c115e18d9595908185b5bdd5b9d609a1b6044820152606401610c43565b6110c58185613053565b83546001600160681b0391909116620100000262010000600160781b031990911617835560d0546110ff906001600160801b031685613053565b60d080546001600160801b0319166001600160801b0392909216919091179055604080518581526020810184905233917fab2daf3c146ca6416cbccd2a86ed2ba995e171ef6319df14a38aef01403a9c96910160405180910390a2604051632770a7eb60e21b8152336004820152602481018590527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690639dc29fac90604401600060405180830381600087803b1580156111c257600080fd5b505af11580156111d6573d6000803e3d6000fd5b505050506111e4338561305f565b5050600180555050565b6065546001600160a01b031633146112185760405162461bcd60e51b8152600401610c4390614dd7565b6001600160a01b0381166112645760405162461bcd60e51b815260206004820152601360248201527210b732bba9ba3934b5b2a9b2b632b1ba34b7b760691b6044820152606401610c43565b60f780546001600160a01b0319166001600160a01b0392909216919091179055565b600260015414156112a95760405162461bcd60e51b8152600401610c4390614e2d565b6002600155816112cb5760405162461bcd60e51b8152600401610c4390614e0c565b6001600160a01b0381166112de57600080fd5b6112e8828261307c565b60cc54611306906201000090046001600160a01b031633308561330e565b6040516340c10f1960e01b81526001600160a01b038281166004830152602482018490527f000000000000000000000000000000000000000000000000000000000000000016906340c10f19906044015b600060405180830381600087803b15801561137157600080fd5b505af1158015611385573d6000803e3d6000fd5b50506001805550505050565b3360008181526098602090815260408083206001600160a01b03871684529091528120549091610f159185906113c8908690615064565b612d5e565b60d4546001600160a01b031633146113f75760405162461bcd60e51b8152600401610c4390614d68565b6002600154141561141a5760405162461bcd60e51b8152600401610c4390614e2d565b600260015560005b818110156114905760ff83838381811061144c57634e487b7160e01b600052603260045260246000fd5b8354600181018555600094855260209094206101409091029290920192600902909101905061147b82826152c7565b5050808061148890615218565b915050611422565b5060fb5460405162067a7560e61b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163019e9d4091611357919086908690600401614f41565b60cc5460009060ff61010090910416816115186114fe60995490565b611506611db5565b60d0546001600160801b031685613379565b905061152d611526856121d5565b82846133bf565b949350505050565b6065546001600160a01b0316331461155f5760405162461bcd60e51b8152600401610c4390614dd7565b6001600160a01b0381166115b55760405162461bcd60e51b815260206004820152601860248201527f216e65774f7074696f6e735072656d69756d50726963657200000000000000006044820152606401610c43565b60f680546001600160a01b0319166001600160a01b0392909216919091179055565b6065546001600160a01b031633146116015760405162461bcd60e51b8152600401610c4390614dd7565b6000811161163b5760405162461bcd60e51b81526020600482015260076024820152660216e65774361760cc1b6044820152606401610c43565b61164481613421565b60ce54604080516001600160681b039092168252602082018390527f5f86edbb9d92228a9edc3f0ebc0f001bda1ea345ac7335e0eeef3504b31d1a1c910160405180910390a160ce80546cffffffffffffffffffffffffff19166001600160681b0392909216919091179055565b600260015414156116d55760405162461bcd60e51b8152600401610c4390614e2d565b6002600155846116f75760405162461bcd60e51b8152600401610c4390614e0c565b60cc5460405163d505accf60e01b8152336004820152306024820152604481018790526064810186905260ff8516608482015260a4810184905260c48101839052620100009091046001600160a01b03169063d505accf9060e401600060405180830381600087803b15801561176c57600080fd5b505af1158015611780573d6000803e3d6000fd5b5050505061178e853361307c565b60cc546117ac906201000090046001600160a01b031633308861330e565b6040516340c10f1960e01b8152336004820152602481018690527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906340c10f1990604401600060405180830381600087803b15801561181457600080fd5b505af1158015611828573d6000803e3d6000fd5b50506001805550505050505050565b6065546001600160a01b031633146118615760405162461bcd60e51b8152600401610c4390614dd7565b6000816001600160801b0316116118a95760405162461bcd60e51b815260206004820152600c60248201526b21737472696b65507269636560a01b6044820152606401610c43565b6001600160801b031660fa5560cf5460f9805461ffff191661ffff909216919091179055565b60d4546001600160a01b031633146118f95760405162461bcd60e51b8152600401610c4390614d68565b600081116119355760405162461bcd60e51b8152602060048201526009602482015268216d696e507269636560b81b6044820152606401610c43565b60f855565b60d4546001600160a01b031633146119645760405162461bcd60e51b8152600401610c4390614d68565b600260015414156119875760405162461bcd60e51b8152600401610c4390614e2d565b600260015560d2546040516358ffbb3d60e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811660048301529091166024820152734f1fafbfe3a3a3f66e17ba674c5c79eb0cdc19ba906358ffbb3d9060440160206040518083038186803b158015611a0b57600080fd5b505af4158015611a1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a439190614b3e565b5060018055565b60026001541415611a6d5760405162461bcd60e51b8152600401610c4390614e2d565b6002600181905550611a816000600161346b565b60018055565b6065546001600160a01b03163314611ab15760405162461bcd60e51b8152600401610c4390614dd7565b611abf620f4240606461517b565b8110611b0d5760405162461bcd60e51b815260206004820152601760248201527f496e76616c696420706572666f726d616e6365206665650000000000000000006044820152606401610c43565b60d55460408051918252602082018390527f24867dfb6fcb9970a07be21024956524abe7a1837faa903ff0e99aaa40cf893e910160405180910390a160d555565b6065546001600160a01b03163314611b785760405162461bcd60e51b8152600401610c4390614dd7565b611b82600061361a565b565b60026001541415611ba75760405162461bcd60e51b8152600401610c4390614e2d565b6002600155611bb58161366c565b60fe54611bc2908261383b565b60fe555060018055565b6060609b8054610e85906151dd565b6000611c10611be960995490565b611bf1611db5565b60d05460cc546001600160801b0390911690610100900460ff16613379565b905090565b60026001541415611c385760405162461bcd60e51b8152600401610c4390614e2d565b600260015580611c775760405162461bcd60e51b815260206004820152600a602482015269216e756d526f756e647360b01b6044820152606401610c43565b60cf5461ffff1660005b82811015611d06576000611c958284615064565b600081815260ca602052604090205490915015611ce25760405162461bcd60e51b815260206004820152600b60248201526a125b9a5d1a585b1a5e995960aa1b6044820152606401610c43565b600090815260ca602052604090206001905580611cfe81615218565b915050611c81565b50506001805550565b3360009081526098602090815260408083206001600160a01b038616845290915281205482811015611d915760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610c43565b611d9e3385858403612d5e565b5060019392505050565b6000610f15338484612e83565b60d2546000906001600160a01b0316611e485760cc546040516370a0823160e01b8152306004820152620100009091046001600160a01b0316906370a082319060240160206040518083038186803b158015611e1057600080fd5b505afa158015611e24573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c109190614b3e565b60cc546040516370a0823160e01b8152306004820152611c10916201000090046001600160a01b0316906370a082319060240160206040518083038186803b158015611e9357600080fd5b505afa158015611ea7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ecb9190614b3e565b60cf546201000090046001600160681b03169061383b565b60026001541415611f065760405162461bcd60e51b8152600401610c4390614e2d565b600260015580611f285760405162461bcd60e51b8152600401610c4390614e0c565b611f32813361307c565b60cc54611f50906201000090046001600160a01b031633308461330e565b6040516340c10f1960e01b8152336004820152602481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906340c10f1990604401600060405180830381600087803b158015611fb857600080fd5b505af1158015611fcc573d6000803e3d6000fd5b505060018055505050565b60d4546001600160a01b031633146120015760405162461bcd60e51b8152600401610c4390614d68565b600260015414156120245760405162461bcd60e51b8152600401610c4390614e2d565b600260015560d1546001600160a01b0316806120705760405162461bcd60e51b815260206004820152600b60248201526a10b732bc3a27b83a34b7b760a91b6044820152606401610c43565b60d280546001600160a01b03199081166001600160a01b03841690811790925560d18054909116905560cf54604051620100009091046001600160681b03168082529133917f045c558fdce4714c5816d53820d27420f4cd860892df203fe636384d8d19aa019060200160405180910390a3604051632904c23960e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811660048301527f0000000000000000000000000000000000000000000000000000000000000000811660248301528316604482015260648101829052734f1fafbfe3a3a3f66e17ba674c5c79eb0cdc19ba90632904c2399060840160206040518083038186803b15801561218c57600080fd5b505af41580156121a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121c49190614b3e565b506121cd613847565b505060018055565b60008060006121e3846126ce565b909250905061152d828261383b565b6065546001600160a01b0316331461221c5760405162461bcd60e51b8152600401610c4390614dd7565b6001600160a01b03811661225f5760405162461bcd60e51b815260206004820152600a60248201526910b732bba5b2b2b832b960b11b6044820152606401610c43565b60d480546001600160a01b0319166001600160a01b0392909216919091179055565b600260015414156122a45760405162461bcd60e51b8152600401610c4390614e2d565b6002600155806122e35760405162461bcd60e51b815260206004820152600a602482015269216e756d53686172657360b01b6044820152606401610c43565b611a4381600061346b565b600260015414156123115760405162461bcd60e51b8152600401610c4390614e2d565b600260015560d2546001600160a01b031680151580612336575060cf5461ffff166001145b6123715760405162461bcd60e51b815260206004820152600c60248201526b149bdd5b990818db1bdcd95960a21b6044820152606401610c43565b61237a81613919565b600060fe54905060008061239060fc5484613a8f565b60fc81905560d05491935091506000906123ba90600160801b90046001600160801b03168561383b565b90506123c581613d16565b60d080546001600160801b03808416600160801b029116179055600060fe556123ed83613421565b60cf805462010000600160781b031916620100006001600160681b03861602179055600061241b428261383b565b905063ffffffff8111156124715760405162461bcd60e51b815260206004820152601860248201527f4f766572666c6f77206e6578744f7074696f6e526561647900000000000000006044820152606401610c43565b60d2805463ffffffff60a01b1916600160a01b63ffffffff84160217905560005b60ff548110156125335760ff81815481106124bd57634e487b7160e01b600052603260045260246000fd5b600091825260208220600990910201818155600181018290556002810180546001600160a01b0319908116909155600382018054909116905560048101829055600581018290556006810180546001600160a81b031916905560078101829055600801558061252b81615218565b915050612492565b5050600180555050505050565b6065546001600160a01b0316331461256a5760405162461bcd60e51b8152600401610c4390614dd7565b6001600160a01b0381166125b35760405162461bcd60e51b815260206004820152601060248201526f085b995dd19959549958da5c1a595b9d60821b6044820152606401610c43565b60d3546001600160a01b03828116911614156126115760405162461bcd60e51b815260206004820152601860248201527f4d757374206265206e657720666565526563697069656e7400000000000000006044820152606401610c43565b60d380546001600160a01b0319166001600160a01b0392909216919091179055565b6065546001600160a01b0316331461265d5760405162461bcd60e51b8152600401610c4390614dd7565b6001600160a01b0381166126c25760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610c43565b6126cb8161361a565b50565b6001600160a01b038116600090815260c9602090815260408083208151606081018352905461ffff81168083526201000082046001600160681b031694830194909452600160781b90046001600160801b031691810191909152829160011115612750575050506001600160a01b031660009081526097602052604081205491565b60cf54815161ffff908116600090815260ca602052604081205460cc54919361278693869391169190610100900460ff16613d60565b90506127a7856001600160a01b031660009081526097602052604090205490565b9590945092505050565b600260015414156127d45760405162461bcd60e51b8152600401610c4390614e2d565b600260015560006127e3613dd1565b60fc549091506127f39082613053565b6001600160801b031660fc555060018055565b60d4546001600160a01b031633146128305760405162461bcd60e51b8152600401610c4390614d68565b600260015414156128535760405162461bcd60e51b8152600401610c4390614e2d565b600260015560d2546001600160a01b031680158015612879575060cf5461ffff16600114155b6128b85760405162461bcd60e51b815260206004820152601060248201526f149bdd5b99081b9bdd0818db1bdcd95960821b6044820152606401610c43565b60408051610140810182526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116825273a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48602083015260cc8054620100009004821683850152848216606084015260006080840181905260f95461ffff1660a085015260fa5460c085015260f754831660e085015260f65490921661010084015260d75461012084015292516377e3ce0d60e11b81529192909182918291734f1fafbfe3a3a3f66e17ba674c5c79eb0cdc19ba9163efc79c1a9161299f91889160cf90600401614e64565b60606040518083038186803b1580156129b757600080fd5b505af41580156129cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129ef91906149e0565b604080518381526020810183905293965091945092507fa217999b1c125c2a996f712c5f26a28addad7167bd8a67d5bd5b2a751148abb0910160405180910390a1505060d180546001600160a01b0319166001600160a01b0392909216919091179055505060018055565b6065546001600160a01b03163314612a845760405162461bcd60e51b8152600401610c4390614dd7565b612a92620f4240606461517b565b8110612ad95760405162461bcd60e51b8152602060048201526016602482015275496e76616c6964206d616e6167656d656e742066656560501b6044820152606401610c43565b612ae28161400e565b60d681905560408051918252602082018390527f4e874b007ab14f7e263baefd44951834c8266f4f224d1092e49e9c254354cc54910160405180910390a150565b600054610100900460ff1680612b3c575060005460ff16155b612b585760405162461bcd60e51b8152600401610c4390614d89565b600054610100900460ff16158015612b7a576000805461ffff19166101011790555b60405163f8b170c160e01b8152734f1fafbfe3a3a3f66e17ba674c5c79eb0cdc19ba9063f8b170c190612bc1908d908d908d908d908c908e908d908d908d90600401614c53565b60006040518083038186803b158015612bd957600080fd5b505af4158015612bed573d6000803e3d6000fd5b50505050612bf961407b565b612c0384846140ee565b612c0b61416d565b612c148a612633565b60d480546001600160a01b03808c166001600160a01b03199283161790925560d38054928b169290911691909117905560d787905560d5859055612c578661400e565b60d6558160cc612c67828261537a565b505060cc546040516370a0823160e01b81523060048201526000916201000090046001600160a01b0316906370a082319060240160206040518083038186803b158015612cb357600080fd5b505afa158015612cc7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ceb9190614b3e565b9050612cf681613421565b60cf805461ffff196001600160681b03909316600160781b02929092167fffffffff00000000000000000000000000ffffffffffffffffffffffffff00009092169190911760011790558015612d52576000805461ff00191690555b50505050505050505050565b6001600160a01b038316612dc05760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610c43565b6001600160a01b038216612e215760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610c43565b6001600160a01b0383811660008181526098602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6001600160a01b038316612ee75760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610c43565b6001600160a01b038216612f495760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610c43565b6001600160a01b03831660009081526097602052604090205481811015612fc15760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610c43565b6001600160a01b03808516600090815260976020526040808220858503905591851681529081208054849290612ff8908490615064565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161304491815260200190565b60405180910390a35b50505050565b6000610fc4828461519a565b60cc546201000090046001600160a01b0316610e718184846141d4565b60cf5461ffff16600061309784613091611db5565b9061383b565b60ce549091506001600160681b03168111156130e25760405162461bcd60e51b815260206004820152600a6024820152690457863656564206361760b41b6044820152606401610c43565b60cd54600160a01b900466ffffffffffffff1681101561313b5760405162461bcd60e51b8152602060048201526014602482015273496e73756666696369656e742062616c616e636560601b6044820152606401610c43565b60408051858152602081018490526001600160a01b038516917f90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a15910160405180910390a26001600160a01b038316600090815260c9602090815260408083208151606081018352905461ffff81168083526201000082046001600160681b031683860152600160781b9091046001600160801b031682840152845260ca90925282205460cc549192916131fa918491879190610100900460ff16613d60565b8251909150869061ffff1685141561322b576020830151600090613227906001600160681b03168961383b565b9150505b61323481613421565b6040805160608101825261ffff80881682526001600160681b0380851660208085019182526001600160801b038089168688019081526001600160a01b038e16600090815260c990935296822095518654935197518216600160781b02600160781b600160f81b03199890951662010000026effffffffffffffffffffffffffffff1990941695169490941791909117949094161790915560d0546132da91168961383b565b90506132e581613d16565b60d080546001600160801b0319166001600160801b039290921691909117905550505050505050565b6040516001600160a01b038085166024830152831660448201526064810182905261304d9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614204565b60008061338783600a6150d3565b90506000861161339757806133b5565b6133b5866133af6133a88888613053565b84906142d6565b906142e2565b9695505050505050565b6000600183116134095760405162461bcd60e51b8152602060048201526015602482015274496e76616c6964206173736574506572536861726560581b6044820152606401610c43565b61152d61341783600a6150d3565b6133af86866142d6565b6001600160681b038111156126cb5760405162461bcd60e51b815260206004820152601060248201526f13dd995c999b1bddc81d5a5b9d0c4c0d60821b6044820152606401610c43565b33600090815260c9602090815260408083208151606081018352905461ffff8082168084526201000083046001600160681b031684870152600160781b9092046001600160801b03168385015260cf5491865260ca9094529184205460cc54919492909316926134e69185918591610100900460ff16613d60565b9050836134f357846134f5565b805b945084613503575050505050565b808511156135475760405162461bcd60e51b81526020600482015260116024820152704578636565647320617661696c61626c6560781b6044820152606401610c43565b825161ffff168211156135745733600090815260c960205260409020805462010000600160781b03191690555b61357d85613d16565b6135878186613053565b33600081815260c960205260409081902080546001600160801b0394909416600160781b02600160781b600160f81b0319909416939093179092558451915190917fe5b754fb1abb7f01b499791d0b820ae3b6af3424ac1c59768edb53f4ec31a929916136009189825261ffff16602082015260400190565b60405180910390a2613613303387612e83565b5050505050565b606580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600081116136a95760405162461bcd60e51b815260206004820152600a602482015269216e756d53686172657360b01b6044820152606401610c43565b33600090815260c960205260409020546201000090046001600160681b03161515806136f3575033600090815260c96020526040902054600160781b90046001600160801b031615155b15613704576137046000600161346b565b60cf5433600081815260cb60209081526040918290208054835187815261ffff96871693810184905292959194911685149290917f0c53c82ad07e2d592d88ece3b066777dd60f1118e2a081b380efc4358f0d9e2a910160405180910390a281546201000090046001600160801b03166000821561378d57613786828761383b565b90506137f0565b81156137cf5760405162461bcd60e51b81526020600482015260116024820152704578697374696e6720776974686472617760781b6044820152606401610c43565b5033600090815260cb60205260409020805461ffff191661ffff8616179055845b6137f981613d16565b33600081815260cb60205260409020805462010000600160901b031916620100006001600160801b03851602179055613833903088612e83565b505050505050565b6000610fc48284615064565b60d25460f8546040516301c6654960e21b81526001600160a01b0392831660048201819052602482018390527f0000000000000000000000000000000000000000000000000000000000000000909316604482015260cc6064820152734f1fafbfe3a3a3f66e17ba674c5c79eb0cdc19ba9063071995249060840160206040518083038186803b1580156138da57600080fd5b505af41580156138ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139129190614b3e565b60fb555050565b60cf546201000090046001600160681b03166001600160a01b038216156139655760cf80546cffffffffffffffffffffffffff60781b1916600160781b6001600160681b038416021790555b60cf805462010000600160781b031916905560d280546001600160a01b03191690556001600160a01b03821615613a8b57604051636c6fe87f60e11b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000166004820152600090734f1fafbfe3a3a3f66e17ba674c5c79eb0cdc19ba9063d8dfd0fe9060240160206040518083038186803b158015613a0c57600080fd5b505af4158015613a20573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a449190614b3e565b9050336001600160a01b0316836001600160a01b03167f7e830f7c1771deb1bdb35c4a7e6051bbac32b376f7f4e4976b8618b0b11997f783604051612e7691815260200190565b5050565b60d3546040805160e08101825260cc54610100810460ff16825291516370a0823160e01b815230600482015260009384936001600160a01b03918216938593849384938493734f1fafbfe3a3a3f66e17ba674c5c79eb0cdc19ba9363d9b874389360cf93602084019262010000909104909116906370a082319060240160206040518083038186803b158015613b2457600080fd5b505afa158015613b38573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b5c9190614b3e565b8152602001613b6a60995490565b81526020018d815260200160d554815260200160d65481526020018c8152506040518363ffffffff1660e01b8152600401613bf792919060006101008201905083825282516020830152602083015160408301526040830151606083015260608301516080830152608083015160a083015260a083015160c083015260c083015160e08301529392505050565b60c06040518083038186803b158015613c0f57600080fd5b505af4158015613c23573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c479190614b7a565b60cf5461ffff16600081815260ca60209081526040918290208790558151858152908101849052908101829052969d50949b50919850965094509250906001600160a01b038716907f0a242f7ecaf711036ca770774ceffae28e60ef042ac113ddd187f2631db0c0069060600160405180910390a260d080546001600160801b0319169055613cd7816001615064565b60cf805461ffff191661ffff9290921691909117905550613cfa905030846142ee565b8015613d0a57613d0a848261305f565b505050505b9250929050565b6001600160801b038111156126cb5760405162461bcd60e51b815260206004820152601060248201526f09eeccae4ccd8deee40ead2dce86264760831b6044820152606401610c43565b835160009061ffff1615801590613d7b5750845161ffff1684115b15613dbd576000613d9a86602001516001600160681b031685856143cd565b6040870151909150613db5906001600160801b03168261383b565b91505061152d565b50505050604001516001600160801b031690565b33600090815260cb6020526040812080546001600160801b03620100008204169061ffff1681613e335760405162461bcd60e51b815260206004820152600d60248201526c139bdd081a5b9a5d1a585d1959609a1b6044820152606401610c43565b60cf5461ffff168110613e7b5760405162461bcd60e51b815260206004820152601060248201526f149bdd5b99081b9bdd0818db1bdcd95960821b6044820152606401610c43565b33600090815260cb60205260409020805462010000600160901b031916905560d054613eb790600160801b90046001600160801b031683613053565b60d080546001600160801b03928316600160801b029216919091179055600081815260ca602052604081205460cc54613efa91859160ff610100909104166133bf565b604080518281526020810186905291925033917ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b568910160405180910390a2613f423084614430565b60008111613f845760405162461bcd60e51b815260206004820152600f60248201526e085dda5d1a191c985dd05b5bdd5b9d608a1b6044820152606401610c43565b604051632770a7eb60e21b8152336004820152602481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690639dc29fac90604401600060405180830381600087803b158015613fec57600080fd5b505af1158015614000573d6000803e3d6000fd5b5050505061152d338261305f565b60d75460009081614020601e83615233565b15614044578161403563031ba309600761517b565b61403f919061507c565b614068565b81614053620f4240600c61517b565b61405e90601e61517b565b614068919061507c565b905061152d816133af86620f42406142d6565b600054610100900460ff1680614094575060005460ff16155b6140b05760405162461bcd60e51b8152600401610c4390614d89565b600054610100900460ff161580156140d2576000805461ffff19166101011790555b6140da61457e565b80156126cb576000805461ff001916905550565b600054610100900460ff1680614107575060005460ff16155b6141235760405162461bcd60e51b8152600401610c4390614d89565b600054610100900460ff16158015614145576000805461ffff19166101011790555b61414d6145ed565b6141578383614657565b8015610e71576000805461ff0019169055505050565b600054610100900460ff1680614186575060005460ff16155b6141a25760405162461bcd60e51b8152600401610c4390614d89565b600054610100900460ff161580156141c4576000805461ffff19166101011790555b6141cc6145ed565b6140da6146ec565b6040516001600160a01b038316602482015260448101829052610e7190849063a9059cbb60e01b90606401613342565b6000614259826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661474c9092919063ffffffff16565b805190915015610e7157808060200190518101906142779190614a87565b610e715760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610c43565b6000610fc4828461517b565b6000610fc4828461507c565b6001600160a01b0382166143445760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610c43565b80609960008282546143569190615064565b90915550506001600160a01b03821660009081526097602052604081208054839290614383908490615064565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b6000600183116144175760405162461bcd60e51b8152602060048201526015602482015274496e76616c6964206173736574506572536861726560581b6044820152606401610c43565b61152d836133af61442985600a6150d3565b87906142d6565b6001600160a01b0382166144905760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610c43565b6001600160a01b038216600090815260976020526040902054818110156145045760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610c43565b6001600160a01b038316600090815260976020526040812083830390556099805484929061453390849061519a565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b600054610100900460ff1680614597575060005460ff16155b6145b35760405162461bcd60e51b8152600401610c4390614d89565b600054610100900460ff161580156145d5576000805461ffff19166101011790555b6001805580156126cb576000805461ff001916905550565b600054610100900460ff1680614606575060005460ff16155b6146225760405162461bcd60e51b8152600401610c4390614d89565b600054610100900460ff161580156140da576000805461ffff191661010117905580156126cb576000805461ff001916905550565b600054610100900460ff1680614670575060005460ff16155b61468c5760405162461bcd60e51b8152600401610c4390614d89565b600054610100900460ff161580156146ae576000805461ffff19166101011790555b82516146c190609a906020860190614857565b5081516146d590609b906020850190614857565b508015610e71576000805461ff0019169055505050565b600054610100900460ff1680614705575060005460ff16155b6147215760405162461bcd60e51b8152600401610c4390614d89565b600054610100900460ff16158015614743576000805461ffff19166101011790555b6140da3361361a565b606061152d848460008585843b6147a55760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610c43565b600080866001600160a01b031685876040516147c19190614c37565b60006040518083038185875af1925050503d80600081146147fe576040519150601f19603f3d011682016040523d82523d6000602084013e614803565b606091505b509150915061481382828661481e565b979650505050505050565b6060831561482d575081610fc4565b82511561483d5782518084602001fd5b8160405162461bcd60e51b8152600401610c439190614d55565b828054614863906151dd565b90600052602060002090601f01602090048101928261488557600085556148cb565b82601f1061489e57805160ff19168380011785556148cb565b828001600101855582156148cb579182015b828111156148cb5782518255916020019190600101906148b0565b506148d79291506148db565b5090565b5b808211156148d757600081556001016148dc565b80356148fb8161546e565b919050565b80356148fb81615491565b80356148fb816154a6565b80356148fb816154bb565b600060208284031215614932578081fd5b8135610fc48161546e565b6000806040838503121561494f578081fd5b823561495a8161546e565b9150602083013561496a8161546e565b809150509250929050565b600080600060608486031215614989578081fd5b83356149948161546e565b925060208401356149a48161546e565b929592945050506040919091013590565b600080604083850312156149c7578182fd5b82356149d28161546e565b946020939093013593505050565b6000806000606084860312156149f4578283fd5b83516149ff8161546e565b602085015160409095015190969495509392505050565b60008060208385031215614a28578182fd5b823567ffffffffffffffff80821115614a3f578384fd5b818501915085601f830112614a52578384fd5b813581811115614a60578485fd5b86602061014083028501011115614a75578485fd5b60209290920196919550909350505050565b600060208284031215614a98578081fd5b8151610fc481615483565b60008082840360e0811215614ab6578283fd5b833567ffffffffffffffff811115614acc578384fd5b84016101408187031215614ade578384fd5b925060c0601f1982011215614af1578182fd5b506020830190509250929050565b600060208284031215614b10578081fd5b81356001600160801b0381168114610fc4578182fd5b600060208284031215614b37578081fd5b5035919050565b600060208284031215614b4f578081fd5b5051919050565b60008060408385031215614b68578182fd5b82359150602083013561496a8161546e565b60008060008060008060c08789031215614b92578384fd5b865195506020870151945060408701519350606087015192506080870151915060a087015190509295509295509295565b600080600080600060a08688031215614bda578283fd5b85359450602086013593506040860135614bf3816154bb565b94979396509394606081013594506080013592915050565b60008151808452614c238160208601602086016151b1565b601f01601f19169290920160200192915050565b60008251614c498184602087016151b1565b9190910192915050565b60006101c060018060a01b03808d168452808c166020850152808b1660408501528960608501528860808501528760a08501528160c0850152614c9882850188614c0b565b915083820360e0850152614cac8287614c0b565b925084359150614cbb82615483565b901515610100840152602084013590614cd3826154bb565b60ff821661012085015260408501359150614ced8261546e565b16610140830152614d00606084016148f0565b6001600160a01b0316610160830152614d1b6080840161490b565b66ffffffffffffff16610180830152614d3660a08401614900565b6001600160681b0381166101a0840152509a9950505050505050505050565b602081526000610fc46020830184614c0b565b60208082526007908201526610b5b2b2b832b960c91b604082015260600190565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526007908201526608585b5bdd5b9d60ca1b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b83516001600160a01b0316815261018081016020850151614e9060208401826001600160a01b03169052565b506040850151614eab60408401826001600160a01b03169052565b506060850151614ec660608401826001600160a01b03169052565b506080850151608083015260a0850151614ee660a084018261ffff169052565b5060c085015160c083015260e0850151614f0b60e08401826001600160a01b03169052565b50610100858101516001600160a01b03169083015261012094850151948201949094526101408101929092526101609091015290565b838152604060208083018290528282018490526000919060609081850187855b8881101561501057813583528382013584840152614f808683016148f0565b6001600160a01b031686840152614f988286016148f0565b6001600160a01b0316858401526080828101359084015260a0808301359084015260c0614fc68184016148f0565b6001600160a01b03169084015260e0614fe0838201614916565b60ff1690840152610100828101359084015261012080830135908401526101409283019290910190600101614f61565b50909998505050505050505050565b6000808335601e19843603018112615035578283fd5b83018035915067ffffffffffffffff82111561504f578283fd5b602001915036819003821315613d0f57600080fd5b6000821982111561507757615077615247565b500190565b60008261508b5761508b61525d565b500490565b600181815b808511156150cb5781600019048211156150b1576150b1615247565b808516156150be57918102915b93841c9390800290615095565b509250929050565b6000610fc483836000826150e957506001610f19565b816150f657506000610f19565b816001811461510c576002811461511657615132565b6001915050610f19565b60ff84111561512757615127615247565b50506001821b610f19565b5060208310610133831016604e8410600b8410161715615155575081810a610f19565b61515f8383615090565b806000190482111561517357615173615247565b029392505050565b600081600019048311821515161561519557615195615247565b500290565b6000828210156151ac576151ac615247565b500390565b60005b838110156151cc5781810151838201526020016151b4565b8381111561304d5750506000910152565b600181811c908216806151f157607f821691505b6020821081141561521257634e487b7160e01b600052602260045260246000fd5b50919050565b600060001982141561522c5761522c615247565b5060010190565b6000826152425761524261525d565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b60008135610f198161546e565b60008135610f1981615491565b60008135610f19816154a6565b60008135610f19816154bb565b80546001600160a01b0319166001600160a01b0392909216919091179055565b81358155602082013560018201556152ed6152e460408401615273565b600283016152a7565b6153056152fc60608401615273565b600383016152a7565b6080820135600482015560a082013560058201556006810161533261532c60c08501615273565b826152a7565b61535f61534160e0850161529a565b82805460ff60a01b191660a09290921b60ff60a01b16919091179055565b50610100820135600782015561012082013560088201555050565b813561538581615483565b815460ff19811691151560ff16918217835560208401356153a5816154bb565b61ff008160081b169050808361ffff1984161717845560408501356153c98161546e565b6001600160b01b0319929092169092179190911760109190911b62010000600160b01b03161781556001810161540461532c60608501615273565b61543d6154136080850161528d565b82805466ffffffffffffff60a01b191660a09290921b66ffffffffffffff60a01b16919091179055565b50613a8b61544d60a08401615280565b600283016001600160681b0382166001600160681b03198254161781555050565b6001600160a01b03811681146126cb57600080fd5b80151581146126cb57600080fd5b6001600160681b03811681146126cb57600080fd5b66ffffffffffffff811681146126cb57600080fd5b60ff811681146126cb57600080fdfea26469706673582212209cab88207b06af4cdfcfffaa35aec23aea6b5bc63cd2a6914b05c142b9ed986a64736f6c6343000804003300000000000000000000000038a75d013cf52d102403d58d902b1ced93b909e20000000000000000000000001e79ea64489b897c1a7f03fbcfc936ae7c55c4210000000000000000000000000d5d7e216480c6533ed3ed9c8877d15c7dd9b5820000000000000000000000004772ddc1f5a66f38e77c0f7ccdf60b637f1ebd21000000000000000000000000eadf1de23cece2109cb72517da1b7b710b7509e5
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106104495760003560e01c80638778878211610241578063ce7c2ac21161013b578063e73c63d5116100c3578063f756fa2111610087578063f756fa2114610bc5578063f87c7d9314610bcd578063f957a06714610bd5578063fba7dc6114610be8578063fe56e23214610bfb57600080fd5b8063e73c63d514610b65578063e74b981b14610b6e578063ef78d4fd14610b81578063f2fde38b14610b8a578063f656ba5114610b9d57600080fd5b8063db006a751161010a578063db006a7514610ac3578063db43e86214610ad6578063dd62ed3e14610afd578063de667d3114610b36578063e278fe6f14610b5d57600080fd5b8063ce7c2ac214610a6d578063cf3afa5114610a80578063d164cc1514610aa7578063d5f2638214610aba57600080fd5b8063a285c9e8116101c9578063aced16611161018d578063aced166114610a24578063ad7a672f14610a37578063afa6626414610a3f578063b6b55f2514610a52578063b9f8092b14610a6557600080fd5b8063a285c9e8146109cf578063a2db9d83146109e4578063a457c2d7146109f5578063a6f7f5d614610a08578063a9059cbb14610a1157600080fd5b806395d89b411161021057806395d89b41146108b757806399530b06146108bf5780639be43daa146108c75780639fcc2d75146108da578063a083ff171461097957600080fd5b8063877887821461087157806389a302711461087a5780638b10cc7c146108955780638da5cb5b146108a657600080fd5b80634603c0aa11610352578063650cce8a116102da57806370a082311161029e57806370a08231146107b6578063715018a6146107df5780637a9262a2146107e75780637e108d521461083e57806387153eb11461085157600080fd5b8063650cce8a146106f55780636719b2ee1461071c57806369b41170146107935780636f31ab341461079b57806370897b23146107a357600080fd5b80634b2431d9116103215780634b2431d9146106b5578063503c70aa146106be57806355489bb2146106c75780635ea8cd12146106da578063600a2cfb146106ed57600080fd5b80634603c0aa14610669578063469048401461067c57806347786d371461068f5780634a970be7146106a257600080fd5b8063313ce567116103d55780633cb7bf19116103a45780633cb7bf19146106085780633ec143d31461061b5780633f23bb731461063c5780633f90916a1461064f578063432833a61461066057600080fd5b8063313ce567146105b4578063355274ea146105d157806336efd16f146105e257806339509351146105f557600080fd5b80631a92f6c21161041c5780631a92f6c2146104b657806323b872dd146104f55780632728f333146105085780632775d01c1461058e57806330630da4146105a157600080fd5b806305e941ec1461044e57806306fdde0314610463578063095ea7b31461048157806318160ddd146104a4575b600080fd5b61046161045c366004614aa3565b610c0e565b005b61046b610e76565b6040516104789190614d55565b60405180910390f35b61049461048f3660046149b5565b610f08565b6040519015158152602001610478565b6099545b604051908152602001610478565b6104dd7f0000000000000000000000001e79ea64489b897c1a7f03fbcfc936ae7c55c42181565b6040516001600160a01b039091168152602001610478565b610494610503366004614975565b610f1f565b60cf5460d0546105499161ffff8116916001600160681b03620100008304811692600160781b900416906001600160801b0380821691600160801b90041685565b6040805161ffff90961686526001600160681b03948516602087015293909216928401929092526001600160801b03918216606084015216608082015260a001610478565b61046161059c366004614b26565b610fcb565b6104616105af366004614921565b6111ee565b60cc54610100900460ff1660405160ff9091168152602001610478565b60ce546001600160681b03166104a8565b6104616105f0366004614b56565b611286565b6104946106033660046149b5565b611391565b610461610616366004614a16565b6113cd565b60f9546106299061ffff1681565b60405161ffff9091168152602001610478565b6104a861064a366004614921565b6114e2565b60d0546001600160801b03166104a8565b6104a860fb5481565b610461610677366004614921565b611535565b60d3546104dd906001600160a01b031681565b61046161069d366004614b26565b6115d7565b6104616106b0366004614bc3565b6116b2565b6104a860fe5481565b6104a860fc5481565b6104616106d5366004614aff565b611837565b6104616106e8366004614b26565b6118cf565b61046161193a565b6104dd7f0000000000000000000000000d5d7e216480c6533ed3ed9c8877d15c7dd9b58281565b61076261072a366004614921565b60c96020526000908152604090205461ffff8116906201000081046001600160681b031690600160781b90046001600160801b031683565b6040805161ffff90941684526001600160681b0390921660208401526001600160801b031690820152606001610478565b6104a8600081565b610461611a4a565b6104616107b1366004614b26565b611a87565b6104a86107c4366004614921565b6001600160a01b031660009081526097602052604090205490565b610461611b4e565b61081c6107f5366004614921565b60cb6020526000908152604090205461ffff8116906201000090046001600160801b031682565b6040805161ffff90931683526001600160801b03909116602083015201610478565b61046161084c366004614b26565b611b84565b6104a861085f366004614b26565b60ca6020526000908152604090205481565b6104a860d55481565b6104dd73a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b60d2546001600160a01b03166104dd565b6065546001600160a01b03166104dd565b61046b611bcc565b6104a8611bdb565b6104616108d5366004614b26565b611c15565b60cc5460cd5460ce546109299260ff808216936101008304909116926001600160a01b036201000090930483169282169166ffffffffffffff600160a01b90910416906001600160681b031686565b60408051961515875260ff90951660208701526001600160a01b03938416948601949094529116606084015266ffffffffffffff1660808301526001600160681b031660a082015260c001610478565b60d15460d2546109a3916001600160a01b039081169190811690600160a01b900463ffffffff1683565b604080516001600160a01b03948516815293909216602084015263ffffffff1690820152606001610478565b60d254600160a01b900463ffffffff166104a8565b60d1546001600160a01b03166104dd565b610494610a033660046149b5565b611d0f565b6104a860d65481565b610494610a1f3660046149b5565b611da8565b60d4546104dd906001600160a01b031681565b6104a8611db5565b60f6546104dd906001600160a01b031681565b610461610a60366004614b26565b611ee3565b610461611fd7565b6104a8610a7b366004614921565b6121d5565b6104dd7f0000000000000000000000004772ddc1f5a66f38e77c0f7ccdf60b637f1ebd2181565b610461610ab5366004614921565b6121f2565b6104a860f85481565b610461610ad1366004614b26565b612281565b6104dd7f00000000000000000000000038a75d013cf52d102403d58d902b1ced93b909e281565b6104a8610b0b36600461493d565b6001600160a01b03918216600090815260986020908152604080832093909416825291909152205490565b6104dd7f000000000000000000000000eadf1de23cece2109cb72517da1b7b710b7509e581565b6104616122ee565b6104a860fa5481565b610461610b7c366004614921565b612540565b6104a860d75481565b610461610b98366004614921565b612633565b610bb0610bab366004614921565b6126ce565b60408051928352602083019190915201610478565b6104616127b1565b610461612806565b60f7546104dd906001600160a01b031681565b60fd546104dd906001600160a01b031681565b610461610c09366004614b26565b612a5a565b600054610100900460ff1680610c27575060005460ff16155b610c4c5760405162461bcd60e51b8152600401610c4390614d89565b60405180910390fd5b600054610100900460ff16158015610c6e576000805461ffff19166101011790555b610d38610c7e6020850185614921565b610c8e6040860160208701614921565b610c9e6060870160408801614921565b6060870135608088013560a0890135610cba60c08b018b61501f565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250610cfc9250505060e08c018c61501f565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152508d9250612b23915050565b6000610d4c61012085016101008601614921565b6001600160a01b03161415610d9c5760405162461bcd60e51b815260206004820152601660248201527510afb7b83a34b7b739a83932b6b4bab6a83934b1b2b960511b6044820152606401610c43565b6000610db061014085016101208601614921565b6001600160a01b03161415610dfb5760405162461bcd60e51b815260206004820152601160248201527010afb9ba3934b5b2a9b2b632b1ba34b7b760791b6044820152606401610c43565b610e0d61012084016101008501614921565b60f680546001600160a01b0319166001600160a01b0392909216919091179055610e3f61014084016101208501614921565b60f780546001600160a01b0319166001600160a01b03929092169190911790558015610e71576000805461ff00191690555b505050565b6060609a8054610e85906151dd565b80601f0160208091040260200160405190810160405280929190818152602001828054610eb1906151dd565b8015610efe5780601f10610ed357610100808354040283529160200191610efe565b820191906000526020600020905b815481529060010190602001808311610ee157829003601f168201915b5050505050905090565b6000610f15338484612d5e565b5060015b92915050565b6000610f2c848484612e83565b6001600160a01b038416600090815260986020908152604080832033845290915290205482811015610fb15760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b6064820152608401610c43565b610fbe8533858403612d5e565b60019150505b9392505050565b60026001541415610fee5760405162461bcd60e51b8152600401610c4390614e2d565b600260015533600090815260c96020526040902060cf5461ffff16826110265760405162461bcd60e51b8152600401610c4390614e0c565b815461ffff16811461106a5760405162461bcd60e51b815260206004820152600d60248201526c125b9d985b1a59081c9bdd5b99609a1b6044820152606401610c43565b81546201000090046001600160681b0316838110156110bb5760405162461bcd60e51b815260206004820152600d60248201526c115e18d9595908185b5bdd5b9d609a1b6044820152606401610c43565b6110c58185613053565b83546001600160681b0391909116620100000262010000600160781b031990911617835560d0546110ff906001600160801b031685613053565b60d080546001600160801b0319166001600160801b0392909216919091179055604080518581526020810184905233917fab2daf3c146ca6416cbccd2a86ed2ba995e171ef6319df14a38aef01403a9c96910160405180910390a2604051632770a7eb60e21b8152336004820152602481018590527f000000000000000000000000eadf1de23cece2109cb72517da1b7b710b7509e56001600160a01b031690639dc29fac90604401600060405180830381600087803b1580156111c257600080fd5b505af11580156111d6573d6000803e3d6000fd5b505050506111e4338561305f565b5050600180555050565b6065546001600160a01b031633146112185760405162461bcd60e51b8152600401610c4390614dd7565b6001600160a01b0381166112645760405162461bcd60e51b815260206004820152601360248201527210b732bba9ba3934b5b2a9b2b632b1ba34b7b760691b6044820152606401610c43565b60f780546001600160a01b0319166001600160a01b0392909216919091179055565b600260015414156112a95760405162461bcd60e51b8152600401610c4390614e2d565b6002600155816112cb5760405162461bcd60e51b8152600401610c4390614e0c565b6001600160a01b0381166112de57600080fd5b6112e8828261307c565b60cc54611306906201000090046001600160a01b031633308561330e565b6040516340c10f1960e01b81526001600160a01b038281166004830152602482018490527f000000000000000000000000eadf1de23cece2109cb72517da1b7b710b7509e516906340c10f19906044015b600060405180830381600087803b15801561137157600080fd5b505af1158015611385573d6000803e3d6000fd5b50506001805550505050565b3360008181526098602090815260408083206001600160a01b03871684529091528120549091610f159185906113c8908690615064565b612d5e565b60d4546001600160a01b031633146113f75760405162461bcd60e51b8152600401610c4390614d68565b6002600154141561141a5760405162461bcd60e51b8152600401610c4390614e2d565b600260015560005b818110156114905760ff83838381811061144c57634e487b7160e01b600052603260045260246000fd5b8354600181018555600094855260209094206101409091029290920192600902909101905061147b82826152c7565b5050808061148890615218565b915050611422565b5060fb5460405162067a7560e61b81526001600160a01b037f0000000000000000000000004772ddc1f5a66f38e77c0f7ccdf60b637f1ebd21169163019e9d4091611357919086908690600401614f41565b60cc5460009060ff61010090910416816115186114fe60995490565b611506611db5565b60d0546001600160801b031685613379565b905061152d611526856121d5565b82846133bf565b949350505050565b6065546001600160a01b0316331461155f5760405162461bcd60e51b8152600401610c4390614dd7565b6001600160a01b0381166115b55760405162461bcd60e51b815260206004820152601860248201527f216e65774f7074696f6e735072656d69756d50726963657200000000000000006044820152606401610c43565b60f680546001600160a01b0319166001600160a01b0392909216919091179055565b6065546001600160a01b031633146116015760405162461bcd60e51b8152600401610c4390614dd7565b6000811161163b5760405162461bcd60e51b81526020600482015260076024820152660216e65774361760cc1b6044820152606401610c43565b61164481613421565b60ce54604080516001600160681b039092168252602082018390527f5f86edbb9d92228a9edc3f0ebc0f001bda1ea345ac7335e0eeef3504b31d1a1c910160405180910390a160ce80546cffffffffffffffffffffffffff19166001600160681b0392909216919091179055565b600260015414156116d55760405162461bcd60e51b8152600401610c4390614e2d565b6002600155846116f75760405162461bcd60e51b8152600401610c4390614e0c565b60cc5460405163d505accf60e01b8152336004820152306024820152604481018790526064810186905260ff8516608482015260a4810184905260c48101839052620100009091046001600160a01b03169063d505accf9060e401600060405180830381600087803b15801561176c57600080fd5b505af1158015611780573d6000803e3d6000fd5b5050505061178e853361307c565b60cc546117ac906201000090046001600160a01b031633308861330e565b6040516340c10f1960e01b8152336004820152602481018690527f000000000000000000000000eadf1de23cece2109cb72517da1b7b710b7509e56001600160a01b0316906340c10f1990604401600060405180830381600087803b15801561181457600080fd5b505af1158015611828573d6000803e3d6000fd5b50506001805550505050505050565b6065546001600160a01b031633146118615760405162461bcd60e51b8152600401610c4390614dd7565b6000816001600160801b0316116118a95760405162461bcd60e51b815260206004820152600c60248201526b21737472696b65507269636560a01b6044820152606401610c43565b6001600160801b031660fa5560cf5460f9805461ffff191661ffff909216919091179055565b60d4546001600160a01b031633146118f95760405162461bcd60e51b8152600401610c4390614d68565b600081116119355760405162461bcd60e51b8152602060048201526009602482015268216d696e507269636560b81b6044820152606401610c43565b60f855565b60d4546001600160a01b031633146119645760405162461bcd60e51b8152600401610c4390614d68565b600260015414156119875760405162461bcd60e51b8152600401610c4390614e2d565b600260015560d2546040516358ffbb3d60e01b81526001600160a01b037f0000000000000000000000001e79ea64489b897c1a7f03fbcfc936ae7c55c421811660048301529091166024820152734f1fafbfe3a3a3f66e17ba674c5c79eb0cdc19ba906358ffbb3d9060440160206040518083038186803b158015611a0b57600080fd5b505af4158015611a1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a439190614b3e565b5060018055565b60026001541415611a6d5760405162461bcd60e51b8152600401610c4390614e2d565b6002600181905550611a816000600161346b565b60018055565b6065546001600160a01b03163314611ab15760405162461bcd60e51b8152600401610c4390614dd7565b611abf620f4240606461517b565b8110611b0d5760405162461bcd60e51b815260206004820152601760248201527f496e76616c696420706572666f726d616e6365206665650000000000000000006044820152606401610c43565b60d55460408051918252602082018390527f24867dfb6fcb9970a07be21024956524abe7a1837faa903ff0e99aaa40cf893e910160405180910390a160d555565b6065546001600160a01b03163314611b785760405162461bcd60e51b8152600401610c4390614dd7565b611b82600061361a565b565b60026001541415611ba75760405162461bcd60e51b8152600401610c4390614e2d565b6002600155611bb58161366c565b60fe54611bc2908261383b565b60fe555060018055565b6060609b8054610e85906151dd565b6000611c10611be960995490565b611bf1611db5565b60d05460cc546001600160801b0390911690610100900460ff16613379565b905090565b60026001541415611c385760405162461bcd60e51b8152600401610c4390614e2d565b600260015580611c775760405162461bcd60e51b815260206004820152600a602482015269216e756d526f756e647360b01b6044820152606401610c43565b60cf5461ffff1660005b82811015611d06576000611c958284615064565b600081815260ca602052604090205490915015611ce25760405162461bcd60e51b815260206004820152600b60248201526a125b9a5d1a585b1a5e995960aa1b6044820152606401610c43565b600090815260ca602052604090206001905580611cfe81615218565b915050611c81565b50506001805550565b3360009081526098602090815260408083206001600160a01b038616845290915281205482811015611d915760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610c43565b611d9e3385858403612d5e565b5060019392505050565b6000610f15338484612e83565b60d2546000906001600160a01b0316611e485760cc546040516370a0823160e01b8152306004820152620100009091046001600160a01b0316906370a082319060240160206040518083038186803b158015611e1057600080fd5b505afa158015611e24573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c109190614b3e565b60cc546040516370a0823160e01b8152306004820152611c10916201000090046001600160a01b0316906370a082319060240160206040518083038186803b158015611e9357600080fd5b505afa158015611ea7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ecb9190614b3e565b60cf546201000090046001600160681b03169061383b565b60026001541415611f065760405162461bcd60e51b8152600401610c4390614e2d565b600260015580611f285760405162461bcd60e51b8152600401610c4390614e0c565b611f32813361307c565b60cc54611f50906201000090046001600160a01b031633308461330e565b6040516340c10f1960e01b8152336004820152602481018290527f000000000000000000000000eadf1de23cece2109cb72517da1b7b710b7509e56001600160a01b0316906340c10f1990604401600060405180830381600087803b158015611fb857600080fd5b505af1158015611fcc573d6000803e3d6000fd5b505060018055505050565b60d4546001600160a01b031633146120015760405162461bcd60e51b8152600401610c4390614d68565b600260015414156120245760405162461bcd60e51b8152600401610c4390614e2d565b600260015560d1546001600160a01b0316806120705760405162461bcd60e51b815260206004820152600b60248201526a10b732bc3a27b83a34b7b760a91b6044820152606401610c43565b60d280546001600160a01b03199081166001600160a01b03841690811790925560d18054909116905560cf54604051620100009091046001600160681b03168082529133917f045c558fdce4714c5816d53820d27420f4cd860892df203fe636384d8d19aa019060200160405180910390a3604051632904c23960e01b81526001600160a01b037f0000000000000000000000001e79ea64489b897c1a7f03fbcfc936ae7c55c421811660048301527f0000000000000000000000000d5d7e216480c6533ed3ed9c8877d15c7dd9b582811660248301528316604482015260648101829052734f1fafbfe3a3a3f66e17ba674c5c79eb0cdc19ba90632904c2399060840160206040518083038186803b15801561218c57600080fd5b505af41580156121a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121c49190614b3e565b506121cd613847565b505060018055565b60008060006121e3846126ce565b909250905061152d828261383b565b6065546001600160a01b0316331461221c5760405162461bcd60e51b8152600401610c4390614dd7565b6001600160a01b03811661225f5760405162461bcd60e51b815260206004820152600a60248201526910b732bba5b2b2b832b960b11b6044820152606401610c43565b60d480546001600160a01b0319166001600160a01b0392909216919091179055565b600260015414156122a45760405162461bcd60e51b8152600401610c4390614e2d565b6002600155806122e35760405162461bcd60e51b815260206004820152600a602482015269216e756d53686172657360b01b6044820152606401610c43565b611a4381600061346b565b600260015414156123115760405162461bcd60e51b8152600401610c4390614e2d565b600260015560d2546001600160a01b031680151580612336575060cf5461ffff166001145b6123715760405162461bcd60e51b815260206004820152600c60248201526b149bdd5b990818db1bdcd95960a21b6044820152606401610c43565b61237a81613919565b600060fe54905060008061239060fc5484613a8f565b60fc81905560d05491935091506000906123ba90600160801b90046001600160801b03168561383b565b90506123c581613d16565b60d080546001600160801b03808416600160801b029116179055600060fe556123ed83613421565b60cf805462010000600160781b031916620100006001600160681b03861602179055600061241b428261383b565b905063ffffffff8111156124715760405162461bcd60e51b815260206004820152601860248201527f4f766572666c6f77206e6578744f7074696f6e526561647900000000000000006044820152606401610c43565b60d2805463ffffffff60a01b1916600160a01b63ffffffff84160217905560005b60ff548110156125335760ff81815481106124bd57634e487b7160e01b600052603260045260246000fd5b600091825260208220600990910201818155600181018290556002810180546001600160a01b0319908116909155600382018054909116905560048101829055600581018290556006810180546001600160a81b031916905560078101829055600801558061252b81615218565b915050612492565b5050600180555050505050565b6065546001600160a01b0316331461256a5760405162461bcd60e51b8152600401610c4390614dd7565b6001600160a01b0381166125b35760405162461bcd60e51b815260206004820152601060248201526f085b995dd19959549958da5c1a595b9d60821b6044820152606401610c43565b60d3546001600160a01b03828116911614156126115760405162461bcd60e51b815260206004820152601860248201527f4d757374206265206e657720666565526563697069656e7400000000000000006044820152606401610c43565b60d380546001600160a01b0319166001600160a01b0392909216919091179055565b6065546001600160a01b0316331461265d5760405162461bcd60e51b8152600401610c4390614dd7565b6001600160a01b0381166126c25760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610c43565b6126cb8161361a565b50565b6001600160a01b038116600090815260c9602090815260408083208151606081018352905461ffff81168083526201000082046001600160681b031694830194909452600160781b90046001600160801b031691810191909152829160011115612750575050506001600160a01b031660009081526097602052604081205491565b60cf54815161ffff908116600090815260ca602052604081205460cc54919361278693869391169190610100900460ff16613d60565b90506127a7856001600160a01b031660009081526097602052604090205490565b9590945092505050565b600260015414156127d45760405162461bcd60e51b8152600401610c4390614e2d565b600260015560006127e3613dd1565b60fc549091506127f39082613053565b6001600160801b031660fc555060018055565b60d4546001600160a01b031633146128305760405162461bcd60e51b8152600401610c4390614d68565b600260015414156128535760405162461bcd60e51b8152600401610c4390614e2d565b600260015560d2546001600160a01b031680158015612879575060cf5461ffff16600114155b6128b85760405162461bcd60e51b815260206004820152601060248201526f149bdd5b99081b9bdd0818db1bdcd95960821b6044820152606401610c43565b60408051610140810182526001600160a01b037f00000000000000000000000038a75d013cf52d102403d58d902b1ced93b909e28116825273a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48602083015260cc8054620100009004821683850152848216606084015260006080840181905260f95461ffff1660a085015260fa5460c085015260f754831660e085015260f65490921661010084015260d75461012084015292516377e3ce0d60e11b81529192909182918291734f1fafbfe3a3a3f66e17ba674c5c79eb0cdc19ba9163efc79c1a9161299f91889160cf90600401614e64565b60606040518083038186803b1580156129b757600080fd5b505af41580156129cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129ef91906149e0565b604080518381526020810183905293965091945092507fa217999b1c125c2a996f712c5f26a28addad7167bd8a67d5bd5b2a751148abb0910160405180910390a1505060d180546001600160a01b0319166001600160a01b0392909216919091179055505060018055565b6065546001600160a01b03163314612a845760405162461bcd60e51b8152600401610c4390614dd7565b612a92620f4240606461517b565b8110612ad95760405162461bcd60e51b8152602060048201526016602482015275496e76616c6964206d616e6167656d656e742066656560501b6044820152606401610c43565b612ae28161400e565b60d681905560408051918252602082018390527f4e874b007ab14f7e263baefd44951834c8266f4f224d1092e49e9c254354cc54910160405180910390a150565b600054610100900460ff1680612b3c575060005460ff16155b612b585760405162461bcd60e51b8152600401610c4390614d89565b600054610100900460ff16158015612b7a576000805461ffff19166101011790555b60405163f8b170c160e01b8152734f1fafbfe3a3a3f66e17ba674c5c79eb0cdc19ba9063f8b170c190612bc1908d908d908d908d908c908e908d908d908d90600401614c53565b60006040518083038186803b158015612bd957600080fd5b505af4158015612bed573d6000803e3d6000fd5b50505050612bf961407b565b612c0384846140ee565b612c0b61416d565b612c148a612633565b60d480546001600160a01b03808c166001600160a01b03199283161790925560d38054928b169290911691909117905560d787905560d5859055612c578661400e565b60d6558160cc612c67828261537a565b505060cc546040516370a0823160e01b81523060048201526000916201000090046001600160a01b0316906370a082319060240160206040518083038186803b158015612cb357600080fd5b505afa158015612cc7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ceb9190614b3e565b9050612cf681613421565b60cf805461ffff196001600160681b03909316600160781b02929092167fffffffff00000000000000000000000000ffffffffffffffffffffffffff00009092169190911760011790558015612d52576000805461ff00191690555b50505050505050505050565b6001600160a01b038316612dc05760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610c43565b6001600160a01b038216612e215760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610c43565b6001600160a01b0383811660008181526098602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6001600160a01b038316612ee75760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610c43565b6001600160a01b038216612f495760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610c43565b6001600160a01b03831660009081526097602052604090205481811015612fc15760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610c43565b6001600160a01b03808516600090815260976020526040808220858503905591851681529081208054849290612ff8908490615064565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161304491815260200190565b60405180910390a35b50505050565b6000610fc4828461519a565b60cc546201000090046001600160a01b0316610e718184846141d4565b60cf5461ffff16600061309784613091611db5565b9061383b565b60ce549091506001600160681b03168111156130e25760405162461bcd60e51b815260206004820152600a6024820152690457863656564206361760b41b6044820152606401610c43565b60cd54600160a01b900466ffffffffffffff1681101561313b5760405162461bcd60e51b8152602060048201526014602482015273496e73756666696369656e742062616c616e636560601b6044820152606401610c43565b60408051858152602081018490526001600160a01b038516917f90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a15910160405180910390a26001600160a01b038316600090815260c9602090815260408083208151606081018352905461ffff81168083526201000082046001600160681b031683860152600160781b9091046001600160801b031682840152845260ca90925282205460cc549192916131fa918491879190610100900460ff16613d60565b8251909150869061ffff1685141561322b576020830151600090613227906001600160681b03168961383b565b9150505b61323481613421565b6040805160608101825261ffff80881682526001600160681b0380851660208085019182526001600160801b038089168688019081526001600160a01b038e16600090815260c990935296822095518654935197518216600160781b02600160781b600160f81b03199890951662010000026effffffffffffffffffffffffffffff1990941695169490941791909117949094161790915560d0546132da91168961383b565b90506132e581613d16565b60d080546001600160801b0319166001600160801b039290921691909117905550505050505050565b6040516001600160a01b038085166024830152831660448201526064810182905261304d9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614204565b60008061338783600a6150d3565b90506000861161339757806133b5565b6133b5866133af6133a88888613053565b84906142d6565b906142e2565b9695505050505050565b6000600183116134095760405162461bcd60e51b8152602060048201526015602482015274496e76616c6964206173736574506572536861726560581b6044820152606401610c43565b61152d61341783600a6150d3565b6133af86866142d6565b6001600160681b038111156126cb5760405162461bcd60e51b815260206004820152601060248201526f13dd995c999b1bddc81d5a5b9d0c4c0d60821b6044820152606401610c43565b33600090815260c9602090815260408083208151606081018352905461ffff8082168084526201000083046001600160681b031684870152600160781b9092046001600160801b03168385015260cf5491865260ca9094529184205460cc54919492909316926134e69185918591610100900460ff16613d60565b9050836134f357846134f5565b805b945084613503575050505050565b808511156135475760405162461bcd60e51b81526020600482015260116024820152704578636565647320617661696c61626c6560781b6044820152606401610c43565b825161ffff168211156135745733600090815260c960205260409020805462010000600160781b03191690555b61357d85613d16565b6135878186613053565b33600081815260c960205260409081902080546001600160801b0394909416600160781b02600160781b600160f81b0319909416939093179092558451915190917fe5b754fb1abb7f01b499791d0b820ae3b6af3424ac1c59768edb53f4ec31a929916136009189825261ffff16602082015260400190565b60405180910390a2613613303387612e83565b5050505050565b606580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600081116136a95760405162461bcd60e51b815260206004820152600a602482015269216e756d53686172657360b01b6044820152606401610c43565b33600090815260c960205260409020546201000090046001600160681b03161515806136f3575033600090815260c96020526040902054600160781b90046001600160801b031615155b15613704576137046000600161346b565b60cf5433600081815260cb60209081526040918290208054835187815261ffff96871693810184905292959194911685149290917f0c53c82ad07e2d592d88ece3b066777dd60f1118e2a081b380efc4358f0d9e2a910160405180910390a281546201000090046001600160801b03166000821561378d57613786828761383b565b90506137f0565b81156137cf5760405162461bcd60e51b81526020600482015260116024820152704578697374696e6720776974686472617760781b6044820152606401610c43565b5033600090815260cb60205260409020805461ffff191661ffff8616179055845b6137f981613d16565b33600081815260cb60205260409020805462010000600160901b031916620100006001600160801b03851602179055613833903088612e83565b505050505050565b6000610fc48284615064565b60d25460f8546040516301c6654960e21b81526001600160a01b0392831660048201819052602482018390527f0000000000000000000000004772ddc1f5a66f38e77c0f7ccdf60b637f1ebd21909316604482015260cc6064820152734f1fafbfe3a3a3f66e17ba674c5c79eb0cdc19ba9063071995249060840160206040518083038186803b1580156138da57600080fd5b505af41580156138ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139129190614b3e565b60fb555050565b60cf546201000090046001600160681b03166001600160a01b038216156139655760cf80546cffffffffffffffffffffffffff60781b1916600160781b6001600160681b038416021790555b60cf805462010000600160781b031916905560d280546001600160a01b03191690556001600160a01b03821615613a8b57604051636c6fe87f60e11b81526001600160a01b037f0000000000000000000000001e79ea64489b897c1a7f03fbcfc936ae7c55c421166004820152600090734f1fafbfe3a3a3f66e17ba674c5c79eb0cdc19ba9063d8dfd0fe9060240160206040518083038186803b158015613a0c57600080fd5b505af4158015613a20573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a449190614b3e565b9050336001600160a01b0316836001600160a01b03167f7e830f7c1771deb1bdb35c4a7e6051bbac32b376f7f4e4976b8618b0b11997f783604051612e7691815260200190565b5050565b60d3546040805160e08101825260cc54610100810460ff16825291516370a0823160e01b815230600482015260009384936001600160a01b03918216938593849384938493734f1fafbfe3a3a3f66e17ba674c5c79eb0cdc19ba9363d9b874389360cf93602084019262010000909104909116906370a082319060240160206040518083038186803b158015613b2457600080fd5b505afa158015613b38573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b5c9190614b3e565b8152602001613b6a60995490565b81526020018d815260200160d554815260200160d65481526020018c8152506040518363ffffffff1660e01b8152600401613bf792919060006101008201905083825282516020830152602083015160408301526040830151606083015260608301516080830152608083015160a083015260a083015160c083015260c083015160e08301529392505050565b60c06040518083038186803b158015613c0f57600080fd5b505af4158015613c23573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c479190614b7a565b60cf5461ffff16600081815260ca60209081526040918290208790558151858152908101849052908101829052969d50949b50919850965094509250906001600160a01b038716907f0a242f7ecaf711036ca770774ceffae28e60ef042ac113ddd187f2631db0c0069060600160405180910390a260d080546001600160801b0319169055613cd7816001615064565b60cf805461ffff191661ffff9290921691909117905550613cfa905030846142ee565b8015613d0a57613d0a848261305f565b505050505b9250929050565b6001600160801b038111156126cb5760405162461bcd60e51b815260206004820152601060248201526f09eeccae4ccd8deee40ead2dce86264760831b6044820152606401610c43565b835160009061ffff1615801590613d7b5750845161ffff1684115b15613dbd576000613d9a86602001516001600160681b031685856143cd565b6040870151909150613db5906001600160801b03168261383b565b91505061152d565b50505050604001516001600160801b031690565b33600090815260cb6020526040812080546001600160801b03620100008204169061ffff1681613e335760405162461bcd60e51b815260206004820152600d60248201526c139bdd081a5b9a5d1a585d1959609a1b6044820152606401610c43565b60cf5461ffff168110613e7b5760405162461bcd60e51b815260206004820152601060248201526f149bdd5b99081b9bdd0818db1bdcd95960821b6044820152606401610c43565b33600090815260cb60205260409020805462010000600160901b031916905560d054613eb790600160801b90046001600160801b031683613053565b60d080546001600160801b03928316600160801b029216919091179055600081815260ca602052604081205460cc54613efa91859160ff610100909104166133bf565b604080518281526020810186905291925033917ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b568910160405180910390a2613f423084614430565b60008111613f845760405162461bcd60e51b815260206004820152600f60248201526e085dda5d1a191c985dd05b5bdd5b9d608a1b6044820152606401610c43565b604051632770a7eb60e21b8152336004820152602481018290527f000000000000000000000000eadf1de23cece2109cb72517da1b7b710b7509e56001600160a01b031690639dc29fac90604401600060405180830381600087803b158015613fec57600080fd5b505af1158015614000573d6000803e3d6000fd5b5050505061152d338261305f565b60d75460009081614020601e83615233565b15614044578161403563031ba309600761517b565b61403f919061507c565b614068565b81614053620f4240600c61517b565b61405e90601e61517b565b614068919061507c565b905061152d816133af86620f42406142d6565b600054610100900460ff1680614094575060005460ff16155b6140b05760405162461bcd60e51b8152600401610c4390614d89565b600054610100900460ff161580156140d2576000805461ffff19166101011790555b6140da61457e565b80156126cb576000805461ff001916905550565b600054610100900460ff1680614107575060005460ff16155b6141235760405162461bcd60e51b8152600401610c4390614d89565b600054610100900460ff16158015614145576000805461ffff19166101011790555b61414d6145ed565b6141578383614657565b8015610e71576000805461ff0019169055505050565b600054610100900460ff1680614186575060005460ff16155b6141a25760405162461bcd60e51b8152600401610c4390614d89565b600054610100900460ff161580156141c4576000805461ffff19166101011790555b6141cc6145ed565b6140da6146ec565b6040516001600160a01b038316602482015260448101829052610e7190849063a9059cbb60e01b90606401613342565b6000614259826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661474c9092919063ffffffff16565b805190915015610e7157808060200190518101906142779190614a87565b610e715760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610c43565b6000610fc4828461517b565b6000610fc4828461507c565b6001600160a01b0382166143445760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610c43565b80609960008282546143569190615064565b90915550506001600160a01b03821660009081526097602052604081208054839290614383908490615064565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b6000600183116144175760405162461bcd60e51b8152602060048201526015602482015274496e76616c6964206173736574506572536861726560581b6044820152606401610c43565b61152d836133af61442985600a6150d3565b87906142d6565b6001600160a01b0382166144905760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610c43565b6001600160a01b038216600090815260976020526040902054818110156145045760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610c43565b6001600160a01b038316600090815260976020526040812083830390556099805484929061453390849061519a565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b600054610100900460ff1680614597575060005460ff16155b6145b35760405162461bcd60e51b8152600401610c4390614d89565b600054610100900460ff161580156145d5576000805461ffff19166101011790555b6001805580156126cb576000805461ff001916905550565b600054610100900460ff1680614606575060005460ff16155b6146225760405162461bcd60e51b8152600401610c4390614d89565b600054610100900460ff161580156140da576000805461ffff191661010117905580156126cb576000805461ff001916905550565b600054610100900460ff1680614670575060005460ff16155b61468c5760405162461bcd60e51b8152600401610c4390614d89565b600054610100900460ff161580156146ae576000805461ffff19166101011790555b82516146c190609a906020860190614857565b5081516146d590609b906020850190614857565b508015610e71576000805461ff0019169055505050565b600054610100900460ff1680614705575060005460ff16155b6147215760405162461bcd60e51b8152600401610c4390614d89565b600054610100900460ff16158015614743576000805461ffff19166101011790555b6140da3361361a565b606061152d848460008585843b6147a55760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610c43565b600080866001600160a01b031685876040516147c19190614c37565b60006040518083038185875af1925050503d80600081146147fe576040519150601f19603f3d011682016040523d82523d6000602084013e614803565b606091505b509150915061481382828661481e565b979650505050505050565b6060831561482d575081610fc4565b82511561483d5782518084602001fd5b8160405162461bcd60e51b8152600401610c439190614d55565b828054614863906151dd565b90600052602060002090601f01602090048101928261488557600085556148cb565b82601f1061489e57805160ff19168380011785556148cb565b828001600101855582156148cb579182015b828111156148cb5782518255916020019190600101906148b0565b506148d79291506148db565b5090565b5b808211156148d757600081556001016148dc565b80356148fb8161546e565b919050565b80356148fb81615491565b80356148fb816154a6565b80356148fb816154bb565b600060208284031215614932578081fd5b8135610fc48161546e565b6000806040838503121561494f578081fd5b823561495a8161546e565b9150602083013561496a8161546e565b809150509250929050565b600080600060608486031215614989578081fd5b83356149948161546e565b925060208401356149a48161546e565b929592945050506040919091013590565b600080604083850312156149c7578182fd5b82356149d28161546e565b946020939093013593505050565b6000806000606084860312156149f4578283fd5b83516149ff8161546e565b602085015160409095015190969495509392505050565b60008060208385031215614a28578182fd5b823567ffffffffffffffff80821115614a3f578384fd5b818501915085601f830112614a52578384fd5b813581811115614a60578485fd5b86602061014083028501011115614a75578485fd5b60209290920196919550909350505050565b600060208284031215614a98578081fd5b8151610fc481615483565b60008082840360e0811215614ab6578283fd5b833567ffffffffffffffff811115614acc578384fd5b84016101408187031215614ade578384fd5b925060c0601f1982011215614af1578182fd5b506020830190509250929050565b600060208284031215614b10578081fd5b81356001600160801b0381168114610fc4578182fd5b600060208284031215614b37578081fd5b5035919050565b600060208284031215614b4f578081fd5b5051919050565b60008060408385031215614b68578182fd5b82359150602083013561496a8161546e565b60008060008060008060c08789031215614b92578384fd5b865195506020870151945060408701519350606087015192506080870151915060a087015190509295509295509295565b600080600080600060a08688031215614bda578283fd5b85359450602086013593506040860135614bf3816154bb565b94979396509394606081013594506080013592915050565b60008151808452614c238160208601602086016151b1565b601f01601f19169290920160200192915050565b60008251614c498184602087016151b1565b9190910192915050565b60006101c060018060a01b03808d168452808c166020850152808b1660408501528960608501528860808501528760a08501528160c0850152614c9882850188614c0b565b915083820360e0850152614cac8287614c0b565b925084359150614cbb82615483565b901515610100840152602084013590614cd3826154bb565b60ff821661012085015260408501359150614ced8261546e565b16610140830152614d00606084016148f0565b6001600160a01b0316610160830152614d1b6080840161490b565b66ffffffffffffff16610180830152614d3660a08401614900565b6001600160681b0381166101a0840152509a9950505050505050505050565b602081526000610fc46020830184614c0b565b60208082526007908201526610b5b2b2b832b960c91b604082015260600190565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526007908201526608585b5bdd5b9d60ca1b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b83516001600160a01b0316815261018081016020850151614e9060208401826001600160a01b03169052565b506040850151614eab60408401826001600160a01b03169052565b506060850151614ec660608401826001600160a01b03169052565b506080850151608083015260a0850151614ee660a084018261ffff169052565b5060c085015160c083015260e0850151614f0b60e08401826001600160a01b03169052565b50610100858101516001600160a01b03169083015261012094850151948201949094526101408101929092526101609091015290565b838152604060208083018290528282018490526000919060609081850187855b8881101561501057813583528382013584840152614f808683016148f0565b6001600160a01b031686840152614f988286016148f0565b6001600160a01b0316858401526080828101359084015260a0808301359084015260c0614fc68184016148f0565b6001600160a01b03169084015260e0614fe0838201614916565b60ff1690840152610100828101359084015261012080830135908401526101409283019290910190600101614f61565b50909998505050505050505050565b6000808335601e19843603018112615035578283fd5b83018035915067ffffffffffffffff82111561504f578283fd5b602001915036819003821315613d0f57600080fd5b6000821982111561507757615077615247565b500190565b60008261508b5761508b61525d565b500490565b600181815b808511156150cb5781600019048211156150b1576150b1615247565b808516156150be57918102915b93841c9390800290615095565b509250929050565b6000610fc483836000826150e957506001610f19565b816150f657506000610f19565b816001811461510c576002811461511657615132565b6001915050610f19565b60ff84111561512757615127615247565b50506001821b610f19565b5060208310610133831016604e8410600b8410161715615155575081810a610f19565b61515f8383615090565b806000190482111561517357615173615247565b029392505050565b600081600019048311821515161561519557615195615247565b500290565b6000828210156151ac576151ac615247565b500390565b60005b838110156151cc5781810151838201526020016151b4565b8381111561304d5750506000910152565b600181811c908216806151f157607f821691505b6020821081141561521257634e487b7160e01b600052602260045260246000fd5b50919050565b600060001982141561522c5761522c615247565b5060010190565b6000826152425761524261525d565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b60008135610f198161546e565b60008135610f1981615491565b60008135610f19816154a6565b60008135610f19816154bb565b80546001600160a01b0319166001600160a01b0392909216919091179055565b81358155602082013560018201556152ed6152e460408401615273565b600283016152a7565b6153056152fc60608401615273565b600383016152a7565b6080820135600482015560a082013560058201556006810161533261532c60c08501615273565b826152a7565b61535f61534160e0850161529a565b82805460ff60a01b191660a09290921b60ff60a01b16919091179055565b50610100820135600782015561012082013560088201555050565b813561538581615483565b815460ff19811691151560ff16918217835560208401356153a5816154bb565b61ff008160081b169050808361ffff1984161717845560408501356153c98161546e565b6001600160b01b0319929092169092179190911760109190911b62010000600160b01b03161781556001810161540461532c60608501615273565b61543d6154136080850161528d565b82805466ffffffffffffff60a01b191660a09290921b66ffffffffffffff60a01b16919091179055565b50613a8b61544d60a08401615280565b600283016001600160681b0382166001600160681b03198254161781555050565b6001600160a01b03811681146126cb57600080fd5b80151581146126cb57600080fd5b6001600160681b03811681146126cb57600080fd5b66ffffffffffffff811681146126cb57600080fd5b60ff811681146126cb57600080fdfea26469706673582212209cab88207b06af4cdfcfffaa35aec23aea6b5bc63cd2a6914b05c142b9ed986a64736f6c63430008040033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000038a75d013cf52d102403d58d902b1ced93b909e20000000000000000000000001e79ea64489b897c1a7f03fbcfc936ae7c55c4210000000000000000000000000d5d7e216480c6533ed3ed9c8877d15c7dd9b5820000000000000000000000004772ddc1f5a66f38e77c0f7ccdf60b637f1ebd21000000000000000000000000eadf1de23cece2109cb72517da1b7b710b7509e5
-----Decoded View---------------
Arg [0] : _oTokenFactory (address): 0x38A75D013cF52d102403d58d902B1CEd93b909e2
Arg [1] : _gammaController (address): 0x1E79EA64489B897C1a7f03fBcFC936AE7c55c421
Arg [2] : _marginPool (address): 0x0d5D7e216480c6533eD3eD9c8877d15c7dd9b582
Arg [3] : _swapContract (address): 0x4772DDc1f5a66f38e77c0f7ccdf60b637f1EBd21
Arg [4] : _amplol (address): 0xEadF1dE23Cece2109Cb72517da1b7b710b7509e5
-----Encoded View---------------
5 Constructor Arguments found :
Arg [0] : 00000000000000000000000038a75d013cf52d102403d58d902b1ced93b909e2
Arg [1] : 0000000000000000000000001e79ea64489b897c1a7f03fbcfc936ae7c55c421
Arg [2] : 0000000000000000000000000d5d7e216480c6533ed3ed9c8877d15c7dd9b582
Arg [3] : 0000000000000000000000004772ddc1f5a66f38e77c0f7ccdf60b637f1ebd21
Arg [4] : 000000000000000000000000eadf1de23cece2109cb72517da1b7b710b7509e5
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
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.