Overview
ETH Balance
ETH Value
$0.00Latest 25 from a total of 8,906 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Distribute | 207064195 | 641 days ago | IN | 0 ETH | 0.00000351 | ||||
| Distribute | 207064188 | 641 days ago | IN | 0 ETH | 0.00000295 | ||||
| Distribute | 192335603 | 684 days ago | IN | 0 ETH | 0.00000274 | ||||
| Execute | 192322896 | 684 days ago | IN | 0 ETH | 0.00000589 | ||||
| Create Stv With ... | 192322314 | 684 days ago | IN | 0 ETH | 0.00000521 | ||||
| Distribute | 192321424 | 684 days ago | IN | 0 ETH | 0.00000348 | ||||
| Execute | 192321074 | 684 days ago | IN | 0 ETH | 0.00000741 | ||||
| Create Stv With ... | 192320576 | 684 days ago | IN | 0 ETH | 0.00000617 | ||||
| Execute | 192320367 | 684 days ago | IN | 0 ETH | 0.00000613 | ||||
| Create Stv With ... | 192320142 | 684 days ago | IN | 0 ETH | 0.00000487 | ||||
| Execute | 192319966 | 684 days ago | IN | 0 ETH | 0.00000548 | ||||
| Create Stv With ... | 192319518 | 684 days ago | IN | 0 ETH | 0.0000048 | ||||
| Execute | 192319351 | 684 days ago | IN | 0 ETH | 0.00000564 | ||||
| Create Stv With ... | 192318298 | 684 days ago | IN | 0 ETH | 0.00000522 | ||||
| Create Stv With ... | 192317960 | 684 days ago | IN | 0 ETH | 0.00000527 | ||||
| Execute | 192315246 | 684 days ago | IN | 0 ETH | 0.00000566 | ||||
| Cancel Stv | 192292363 | 684 days ago | IN | 0 ETH | 0.00000207 | ||||
| Create Stv With ... | 192284421 | 684 days ago | IN | 0 ETH | 0.00000564 | ||||
| Execute | 192272433 | 684 days ago | IN | 0 ETH | 0.00000623 | ||||
| Distribute | 192272091 | 684 days ago | IN | 0 ETH | 0.00000266 | ||||
| Create Stv With ... | 192271690 | 684 days ago | IN | 0 ETH | 0.00000597 | ||||
| Distribute | 192271609 | 684 days ago | IN | 0 ETH | 0.00000296 | ||||
| Execute | 192266338 | 684 days ago | IN | 0 ETH | 0.00000578 | ||||
| Create Stv With ... | 192265782 | 684 days ago | IN | 0 ETH | 0.00000609 | ||||
| Distribute | 192265311 | 684 days ago | IN | 0 ETH | 0.00000306 |
Latest 25 internal transactions (View All)
Cross-Chain Transactions
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import {IVault} from "src/interfaces/IVault.sol";
import {Errors} from "src/libraries/Errors.sol";
import {BytesCheck} from "src/libraries/BytesCheck.sol";
import {VaultEvents} from "src/storage/VaultEvents.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IAccount} from "src/q/interfaces/IAccount.sol";
import {IStvAccount} from "src/interfaces/IStvAccount.sol";
import {IQ} from "src/q/interfaces/IQ.sol";
import {Generate} from "src/Generate.sol";
import {Trade} from "src/Trade.sol";
import {IOperator} from "src/storage/interfaces/IOperator.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
/// @title Vault
/// @notice Contract to handle STFX logic
contract Vault is ReentrancyGuard, IVault, VaultEvents {
using SafeERC20 for IERC20;
/*//////////////////////////////////////////////////////////////
STATE VARIABLES
//////////////////////////////////////////////////////////////*/
/// @notice address of the operator
address public operator;
/// @notice max funcraising period for an stv
uint40 public maxFundraisingPeriod;
/// @notice nonce for users
mapping(address => uint256) public nonces;
/// @notice typehash for the current chain
bytes32 public constant EXECUTE_TYPEHASH = keccak256("executeData(bytes data,address user,uint256 nonce)");
bytes32 private constant _TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
bytes32 private immutable _hashedName = keccak256(bytes("vault"));
bytes32 private immutable _hashedVersion = keccak256(bytes("1"));
bytes32 private immutable _cachedDomainSeparator;
uint256 private immutable _cachedChainId;
address private immutable _cachedThis;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR/MODIFIERS
//////////////////////////////////////////////////////////////*/
constructor(address _operator, uint40 _maxFundraisingPeriod) {
operator = _operator;
maxFundraisingPeriod = _maxFundraisingPeriod;
_cachedDomainSeparator = _buildDomainSeparator();
_cachedChainId = block.chainid;
_cachedThis = address(this);
emit InitVault(_operator, _maxFundraisingPeriod, _cachedDomainSeparator, EXECUTE_TYPEHASH);
}
modifier onlyOwner() {
address owner = IOperator(operator).getAddress("OWNER");
if (msg.sender != owner) revert Errors.NotOwner();
_;
}
modifier onlyAdmin() {
address admin = IOperator(operator).getAddress("ADMIN");
if (msg.sender != admin) revert Errors.NotAdmin();
_;
}
/*//////////////////////////////////////////////////////////////
GETTERS/SETTERS
//////////////////////////////////////////////////////////////*/
function DOMAIN_SEPARATOR() public view returns (bytes32) {
if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
return _cachedDomainSeparator;
} else {
return _buildDomainSeparator();
}
}
function _buildDomainSeparator() private view returns (bytes32) {
return keccak256(abi.encode(_TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
}
/// @notice Get the address of Q contract
/// @return address q
function getQ() external view returns (address) {
address q = IOperator(operator).getAddress("Q");
return q;
}
/// @notice Get the stv info
/// @param stvId address of the stv
function getStvInfo(address stvId) public view returns (StvInfo memory) {
return IStvAccount(stvId).stvInfo();
}
/// @notice Get the stv's accounting details
/// @param stvId address of the stv
function getStvBalance(address stvId) public view returns (StvBalance memory) {
return IStvAccount(stvId).stvBalance();
}
/// @notice Get the investor's details in a particular stv
/// @param investor address of the investor
/// @param stvId address of the stv
function getInvestorInfo(address investor, address stvId) public view returns (InvestorInfo memory) {
return IStvAccount(stvId).investorInfo(investor);
}
/// @notice Get all the addresses invested in the stv
/// @param stvId address of the stv
function getInvestors(address stvId) public view returns (address[] memory) {
return IStvAccount(stvId).getInvestors();
}
/// @notice Set the max fundraising period which is used when creating an stv
/// @dev can only be called by the `owner`
/// @param _maxFundraisingPeriod the max fundraising period in seconds
function setMaxFundraisingPeriod(uint40 _maxFundraisingPeriod) external onlyOwner {
if (_maxFundraisingPeriod == 0) revert Errors.ZeroAmount();
maxFundraisingPeriod = _maxFundraisingPeriod;
emit MaxFundraisingPeriod(_maxFundraisingPeriod);
}
/*//////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice creates a new stv by deploying a clone of `StvAccount` contract
/// @dev the payload has to be signed by the `admin` before sending it as calldata
/// @param capacityOfStv capacity of the stv
/// @param metadataHash hash of the metadata
/// @return stvId address of the stv
function createStv(
uint96 capacityOfStv,
uint96 subscriptionFundLimit,
bytes32 metadataHash,
bytes calldata signature
) external returns (address stvId) {
if (subscriptionFundLimit > capacityOfStv) revert Errors.InputMismatch();
bytes memory data = abi.encode(capacityOfStv, metadataHash);
_verifyData(data, signature);
address op = operator;
address managerAccount = IOperator(op).getTraderAccount(msg.sender);
address q = IOperator(op).getAddress("Q");
if (managerAccount == address(0)) IQ(q).createAccount(msg.sender);
StvInfo memory stv = Generate.generate(capacityOfStv, msg.sender, op, maxFundraisingPeriod);
stvId = stv.stvId;
IStvAccount(stvId).createStv(stv);
emit CreateStv(metadataHash, stv.stvId, stv.manager, stv.endTime, stv.capacityOfStv);
if (subscriptionFundLimit > 0) {
_investSubscribers(stvId, op, subscriptionFundLimit);
}
}
/// @notice creates a new stv by deploying a clone of `StvAccount` contract
/// @dev the payload has to be signed by the `admin` before sending it as calldata
/// @param capacityOfStv capacity of the stv
/// @param metadataHash hash of the metadata
/// @param token address of the token the manager wants to use to deposit
/// @param amount amount of the token the manager wants to deposit into the stv
/// @param exchangeData data from `1inch` API
/// @param signature signature from the `admin`
/// @return stvId address of the stv
function createStvWithDeposit(
uint96 capacityOfStv,
uint96 subscriptionFundLimit,
bytes32 metadataHash,
address token,
uint96 amount,
bytes memory exchangeData,
bytes calldata signature
) external payable nonReentrant returns (address stvId) {
bytes memory validateData = abi.encode(capacityOfStv, metadataHash, exchangeData);
_verifyData(validateData, signature);
address op = operator;
address traderAccount;
{
traderAccount = IOperator(op).getTraderAccount(msg.sender);
address q = IOperator(op).getAddress("Q");
if (traderAccount == address(0)) traderAccount = IQ(q).createAccount(msg.sender);
}
{
StvInfo memory stv = Generate.generate(capacityOfStv, msg.sender, op, maxFundraisingPeriod);
stvId = stv.stvId;
IStvAccount(stvId).createStv(stv);
emit CreateStv(metadataHash, stvId, stv.manager, stv.endTime, stv.capacityOfStv);
}
{
uint96 totalDepositWithSubscription;
if (subscriptionFundLimit > 0) {
totalDepositWithSubscription = _investSubscribers(stvId, op, subscriptionFundLimit);
}
uint256 returnAmount = _swap(token, stvId, amount, exchangeData, traderAccount);
if (totalDepositWithSubscription + uint96(returnAmount) > capacityOfStv) {
revert Errors.TotalRaisedMoreThanCapacity();
}
IStvAccount(stvId).deposit(traderAccount, uint96(returnAmount), true);
emit Deposit(stvId, msg.sender, msg.sender, uint96(returnAmount));
}
}
/// @notice deposits into the stv's contract from the trader's account contract
/// @param stvId address of the stv
/// @param amount amount of `defaultStableCoin` to deposit from the trader's Account contract
function deposit(address stvId, uint96 amount) external nonReentrant {
address account = IOperator(operator).getTraderAccount(msg.sender);
StvInfo memory stv = getStvInfo(stvId);
StvBalance memory sBalance = getStvBalance(stvId);
InvestorInfo memory investorInfo = getInvestorInfo(account, stvId);
address defaultStableCoin = IOperator(operator).getAddress("DEFAULTSTABLECOIN");
uint256 accountBalance = IERC20(defaultStableCoin).balanceOf(account);
uint256 minDepositAmount = 10 ** IERC20(defaultStableCoin).decimals();
if (amount < minDepositAmount) revert Errors.BelowMinStvDepositAmount(); // 1 unit
if (account == address(0)) revert Errors.AccountNotExists();
if (accountBalance < amount) revert Errors.BalanceLessThanAmount();
if (stv.manager == address(0)) revert Errors.StvDoesNotExist();
if (uint40(block.timestamp) > stv.endTime) revert Errors.FundraisingPeriodEnded();
if (stv.status != StvStatus.NOT_OPENED) revert Errors.AlreadyOpened();
if (sBalance.totalRaised + amount > stv.capacityOfStv) {
revert Errors.TotalRaisedMoreThanCapacity();
}
if (investorInfo.depositAmount == 0) IStvAccount(stvId).deposit(account, amount, true);
else IStvAccount(stvId).deposit(account, amount, false);
bytes memory transferData = abi.encodeWithSignature("transfer(address,uint256)", stvId, amount);
IAccount(payable(account)).execute(defaultStableCoin, transferData, 0);
emit Deposit(stvId, msg.sender, msg.sender, amount);
}
/// @notice deposits into the stv's contract without an Account create
/// @notice creates an Account contract for `to`
/// @dev `to` can be `msg.sender` when its the investor
/// @dev `to` can be trader's address when its called in through a crosschain protocol
/// @param to address of the trader
/// @param stvId address of the stv
/// @param amount amount of the token the investor wants to deposit into the stv
/// @param token address of the token the investor wants to use to deposit
/// @param exchangeData data from `1inch` API
/// @param signature signature from the `admin`
function depositTo(
address to,
address stvId,
uint96 amount,
address token,
bytes memory exchangeData,
bytes calldata signature
) external payable nonReentrant {
_verifyData(exchangeData, signature);
address account = IOperator(operator).getTraderAccount(to);
address q = IOperator(operator).getAddress("Q");
if (account == address(0)) account = IQ(q).createAccount(to);
StvInfo memory stv = getStvInfo(stvId);
StvBalance memory sBalance = getStvBalance(stvId);
InvestorInfo memory investorInfo = getInvestorInfo(account, stvId);
if (token == address(0)) {
if (msg.value != amount) revert Errors.InputMismatch();
} else {
uint256 accountBalance = IERC20(token).balanceOf(msg.sender);
if (amount > accountBalance) revert Errors.BalanceLessThanAmount();
}
if (stv.manager == address(0)) revert Errors.StvDoesNotExist();
if (uint40(block.timestamp) > stv.endTime) revert Errors.FundraisingPeriodEnded();
if (stv.status != StvStatus.NOT_OPENED) revert Errors.AlreadyOpened();
amount = uint96(_swap(token, stvId, amount, exchangeData, account));
if (sBalance.totalRaised + amount > stv.capacityOfStv) {
revert Errors.TotalRaisedMoreThanCapacity();
}
if (investorInfo.depositAmount == 0) IStvAccount(stvId).deposit(account, amount, true);
else IStvAccount(stvId).deposit(account, amount, false);
emit Deposit(stvId, msg.sender, to, amount);
}
/// @notice changes the status of the stv to `LIQUIDATED`
/// @dev can only be called by the `admin`
/// @param stvId address of the stv
function liquidate(address stvId) external onlyAdmin {
IStvAccount(stvId).liquidate();
emit Liquidate(stvId, uint8(IVault.StvStatus.LIQUIDATED));
}
/// @notice execute the type of trade
/// @dev `totalReceived` will be 0 for perps and will be more than 0 for spot
/// @dev can only be called by the `admin`
/// @param command the command of the ddex protocol from `Commands` library
/// @param data encoded data of parameters depending on the ddex
/// @param isOpen bool to check if its an increase or decrease trade
/// @return tradeToken address of the token which is used for spot execution
/// @return totalReceived tokens received after trading a spot position
function execute(uint256 command, bytes calldata data, bool isOpen)
external
payable
onlyAdmin
returns (address tradeToken, uint96 totalReceived)
{
(address stvId, uint96 amount) = _getAmountAndStvId(data);
StvInfo memory stv = getStvInfo(stvId);
StvBalance memory sBalance = getStvBalance(stvId);
if (amount == 0) revert Errors.ZeroAmount();
if (sBalance.totalRaised < 1) revert Errors.ZeroTotalRaised();
if (stv.status != IVault.StvStatus.NOT_OPENED && stv.status != IVault.StvStatus.OPEN) {
revert Errors.StvStatusMismatch();
}
if (BytesCheck.checkFirstDigit0x1(uint8(command))) {
tradeToken = _getTradeToken(data);
if (!isOpen) {
if (
IStvAccount(stvId).totalTradeTokenUsedForClose(tradeToken) + amount
> IStvAccount(stvId).totalTradeTokenReceivedAfterOpen(tradeToken)
) {
revert Errors.MoreThanTotalRaised();
}
}
totalReceived = Trade.execute(command, data, isOpen, operator);
} else {
address perpTrade = IOperator(operator).getAddress("PERPTRADE");
bytes memory perpTradeData = abi.encodeWithSignature("execute(uint256,bytes,bool)", command, data, isOpen);
(bool success,) = perpTrade.call{value: msg.value}(perpTradeData);
if (!success) revert Errors.CallFailed(perpTradeData);
}
IStvAccount(stvId).execute(amount, tradeToken, totalReceived, isOpen);
emit Execute(stvId, amount, totalReceived, command, data, msg.value, isOpen);
}
/// @notice executes many trades in a single function
/// @dev `totalReceived` will be 0 for perps and will be more than 0 for spot
/// @dev can only be called by the `admin`
/// @param commands array of commands of the ddex protocol from `Commands` library
/// @param data array of encoded data of parameters depending on the ddex
/// @param msgValue msg.value for each command which has to be transfered when executing the position
/// @param isOpen array of bool to check if its an increase or decrease trade
function multiExecute(
uint256[] memory commands,
bytes[] calldata data,
uint256[] memory msgValue,
bool[] memory isOpen
) external payable onlyAdmin {
uint256 length = commands.length;
if (length != data.length) revert Errors.LengthMismatch();
if (length != msgValue.length) revert Errors.LengthMismatch();
uint256 i;
address tradeToken;
uint96 amountReceived;
for (; i < length;) {
uint256 command = commands[i];
bytes calldata tradeData = data[i];
uint256 value = msgValue[i];
bool openOrClose = isOpen[i];
(address stvId, uint96 amount) = _getAmountAndStvId(tradeData);
StvInfo memory stv = getStvInfo(stvId);
StvBalance memory sBalance = getStvBalance(stvId);
if (amount == 0) revert Errors.ZeroAmount();
if (sBalance.totalRaised < 1) revert Errors.ZeroTotalRaised();
if (stv.status != IVault.StvStatus.NOT_OPENED && stv.status != IVault.StvStatus.OPEN) {
revert Errors.StvStatusMismatch();
}
if (BytesCheck.checkFirstDigit0x1(uint8(command))) {
tradeToken = _getTradeToken(tradeData);
if (!openOrClose) {
if (
IStvAccount(stvId).totalTradeTokenUsedForClose(tradeToken) + amount
> IStvAccount(stvId).totalTradeTokenReceivedAfterOpen(tradeToken)
) {
revert Errors.MoreThanTotalRaised();
}
}
amountReceived = Trade.execute(command, tradeData, openOrClose, operator);
} else {
address perpTrade = IOperator(operator).getAddress("PERPTRADE");
bytes memory perpTradeData =
abi.encodeWithSignature("execute(uint256,bytes,bool)", command, tradeData, openOrClose);
(bool success,) = perpTrade.call{value: value}(perpTradeData);
if (!success) revert Errors.CallFailed(perpTradeData);
}
IStvAccount(stvId).execute(amount, tradeToken, amountReceived, openOrClose);
emit Execute(stvId, amount, amountReceived, command, tradeData, value, openOrClose);
unchecked {
++i;
}
}
}
/// @notice distributes the fees to the manager and protocol and the remaining in the stv's contract to the investors
/// @dev can only be called by the admin
/// @param stvId address of the stv
/// @param command command of the ddex protocol
/// @param totalDepositTokenUsed total deposit token used in defaultStableCoin decimals
/// @param managerFees manager fees in 1e18 decimals
/// @param protocolFees protocol fees in 1e18 decimals
/// @param tradeTokens addresss of the trade tokens to swap
/// @param exchangeData exchange data to swap, 0 - eth swap, 1 - tradeToken swap
function distribute(
address stvId,
uint256 command,
uint96 totalDepositTokenUsed,
uint96 managerFees,
uint96 protocolFees,
address[] calldata tradeTokens,
bytes[] calldata exchangeData
) external onlyAdmin {
// TODO solve stack too deep by making the input params as a struct ??
uint256 c = command; // to avoid stack too deep
{
StvInfo memory stv = getStvInfo(stvId);
if (stv.status != StvStatus.OPEN) revert Errors.StvNotOpen();
}
(uint96 totalRemainingAfterDistribute, uint96 mFee, uint96 pFee) = Trade.distribute(
stvId, c, totalDepositTokenUsed, managerFees, protocolFees, tradeTokens, exchangeData, operator
);
IStvAccount(stvId).distribute(totalRemainingAfterDistribute, mFee, pFee);
emit Distribute(stvId, totalRemainingAfterDistribute, mFee, pFee, c);
}
/// @notice same as `distribute`, but is only called if `distribute` runs out of gas
function distributeOut(address stvId, bool isCancel, uint256 indexFrom, uint256 indexTo) external onlyAdmin {
IStvAccount(stvId).distributeOut(isCancel, indexFrom, indexTo);
}
/// @notice cancels the stv and transfers the tokens back to the investors
/// @param stvId address of the stv
function cancelStv(address stvId) external {
StvInfo memory stv = getStvInfo(stvId);
StvBalance memory sBalance = getStvBalance(stvId);
address admin = IOperator(operator).getAddress("ADMIN");
if (stv.status != StvStatus.NOT_OPENED) revert Errors.AlreadyOpened();
if (msg.sender == admin) {
if (uint40(block.timestamp) <= stv.endTime) revert Errors.BelowMinEndTime();
if (sBalance.totalRaised == 0) {
IStvAccount(stvId).updateStatus(StvStatus.CANCELLED_WITH_ZERO_RAISE);
} else {
IStvAccount(stvId).updateStatus(StvStatus.CANCELLED_WITH_NO_FILL);
}
} else if (msg.sender == stv.manager) {
IStvAccount(stvId).updateStatus(StvStatus.CANCELLED_BY_MANAGER);
} else {
revert Errors.NoAccess();
}
IStvAccount(stvId).cancel();
emit Cancel(stvId, uint8(stv.status));
}
/// @notice claims rewards from eligible ddex protocols
/// @dev can only be called by the admin
/// @param data array of encoded data to claim rewards from each ddex
function claimStvTradingReward(uint256[] calldata commands, bytes[] calldata data) external onlyAdmin {
address perpTrade = IOperator(operator).getAddress("PERPTRADE");
uint256 i;
for (; i < data.length;) {
uint256 command = commands[i];
bytes memory rewardData = data[i];
bytes memory perpTradeData =
abi.encodeWithSignature("execute(uint256,bytes,bool)", command, rewardData, false);
(bool success,) = perpTrade.call(perpTradeData);
if (!success) revert Errors.CallFailed(perpTradeData);
(address stvId,) = _getAmountAndStvId(data[i]);
emit ClaimRewards(stvId, command, rewardData);
unchecked {
++i;
}
}
}
/*//////////////////////////////////////////////////////////////
INTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
function _investSubscribers(address stvId, address op, uint96 subscriptionFundLimit)
internal
returns (uint96 totalDepositWithSubscription)
{
address defaultStableCoin = IOperator(op).getAddress("DEFAULTSTABLECOIN");
address[] memory subscribers = IOperator(op).getAllSubscribers(msg.sender);
(bytes[] memory users, uint256 ratio) =
_getSubscriptionRatio(subscribers, subscriptionFundLimit, defaultStableCoin, op);
uint256 i;
for (; i < users.length;) {
(address traderAccount, uint96 amountToUse) = abi.decode(users[i], (address, uint96));
uint96 amountAfterRatio = uint96(uint256(amountToUse) * ratio / 1e18);
if (amountAfterRatio > 0) {
totalDepositWithSubscription += amountAfterRatio;
IStvAccount(stvId).deposit(traderAccount, amountAfterRatio, true);
bytes memory transferData = abi.encodeWithSignature("transfer(address,uint256)", stvId, amountAfterRatio);
IAccount(payable(traderAccount)).execute(defaultStableCoin, transferData, 0);
emit DepositWithSubscription(stvId, msg.sender, traderAccount, amountAfterRatio);
}
unchecked {
++i;
}
}
}
/// @notice pure function to get the first two params of the calldata
/// @dev the first 2 params will always be the address and the amount
function _getAmountAndStvId(bytes calldata data) internal pure returns (address stvId, uint96 amount) {
assembly {
stvId := calldataload(data.offset)
amount := calldataload(add(data.offset, 0x20))
}
}
/// @notice pure function to get the third param of the calldata which is the `tradeToken` for Spot execute
/// @dev the third param for spot execution will always be `tradeToken`
function _getTradeToken(bytes calldata data) internal pure returns (address tradeToken) {
assembly {
tradeToken := calldataload(add(data.offset, 0x40))
}
}
function _getSubscriptionRatio(address[] memory subscribers, uint96 capacity, address defaultStableCoin, address op)
internal
view
returns (bytes[] memory, uint256)
{
uint256 totalLiquidity;
uint256 i;
uint256 ratio;
bytes[] memory users = new bytes[](subscribers.length);
for (; i < subscribers.length;) {
address subscriber = subscribers[i];
uint96 maxLimit = IOperator(op).getSubscriptionAmount(msg.sender, subscriber);
uint96 traderAccountBalance = uint96(IERC20(defaultStableCoin).balanceOf(subscriber));
uint256 amountToUse = traderAccountBalance < maxLimit ? traderAccountBalance : maxLimit;
users[i] = abi.encode(subscriber, amountToUse);
totalLiquidity += amountToUse;
unchecked {
++i;
}
}
if (totalLiquidity > 0) {
uint256 capacityToSubscriptions = uint256(capacity) * 1e18 / uint256(totalLiquidity);
ratio = capacityToSubscriptions < 1e18 ? capacityToSubscriptions : 1e18;
}
return (users, ratio);
}
/// @notice internal function to swap the amount of token
/// @param token address of the token to be swapped
/// @param to address of the receipient
/// @param amount amount of tokens to be swapped
/// @param exchangeData calldata to swap
/// @param traderAccount address of the account contract
function _swap(address token, address to, uint96 amount, bytes memory exchangeData, address traderAccount)
internal
returns (uint256 returnAmount)
{
address defaultStableCoin = IOperator(operator).getAddress("DEFAULTSTABLECOIN");
if (token != defaultStableCoin) {
if (exchangeData.length == 0) revert Errors.ExchangeDataMismatch();
address exchangeRouter = IOperator(operator).getAddress("ONEINCHROUTER");
if (token != address(0)) {
IERC20(token).safeTransferFrom(msg.sender, to, amount);
bytes memory approveData = abi.encodeWithSelector(IERC20.approve.selector, exchangeRouter, amount);
IStvAccount(to).execute(token, approveData, 0);
}
uint256 balanceBefore = IERC20(defaultStableCoin).balanceOf(to);
IStvAccount(to).execute{value: msg.value}(exchangeRouter, exchangeData, msg.value);
uint256 balanceAfter = IERC20(defaultStableCoin).balanceOf(to);
if (balanceAfter <= balanceBefore) revert Errors.BalanceLessThanAmount();
returnAmount = balanceAfter - balanceBefore;
if (token != address(0) && (IERC20(token).allowance(to, exchangeRouter) != 0)) {
revert Errors.InputMismatch();
}
} else {
if (exchangeData.length != 0) revert Errors.ExchangeDataMismatch();
uint96 traderAccountBalance = uint96(IERC20(defaultStableCoin).balanceOf(traderAccount));
if (traderAccountBalance >= amount) {
bytes memory transferData = abi.encodeWithSignature("transfer(address,uint256)", to, amount);
IAccount(payable(traderAccount)).execute(defaultStableCoin, transferData, 0);
} else {
IERC20(defaultStableCoin).transferFrom(msg.sender, to, amount);
}
returnAmount = amount;
}
uint256 minDepositAmount = 10 ** IERC20(defaultStableCoin).decimals();
if (returnAmount < minDepositAmount) revert Errors.BelowMinStvDepositAmount(); // 1 unit
}
/// @notice internal function to verify if the calldata is signed by the `admin` or not
/// @dev the data has to be signed by the `admin`
function _verifyData(bytes memory data, bytes calldata signature) internal {
bytes32 structHash = keccak256(abi.encode(EXECUTE_TYPEHASH, keccak256(data), msg.sender, nonces[msg.sender]++));
bytes32 signedData = ECDSA.toTypedDataHash(DOMAIN_SEPARATOR(), structHash);
address signer = ECDSA.recover(signedData, signature);
address admin = IOperator(operator).getAddress("ADMIN");
if (signer != admin) revert Errors.NotAdmin();
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
interface IVault {
/// @notice Enum to describe the trading status of the vault
/// @dev NOT_OPENED - Not open
/// @dev OPEN - opened position
/// @dev CANCELLED_WITH_ZERO_RAISE - cancelled without any raise
/// @dev CANCELLED_WITH_NO_FILL - cancelled with raise but not opening a position
/// @dev CANCELLED_BY_MANAGER - cancelled by the manager after raising
/// @dev DISTRIBUTED - distributed fees
/// @dev LIQUIDATED - liquidated position
enum StvStatus {
NOT_OPENED,
OPEN,
CANCELLED_WITH_ZERO_RAISE,
CANCELLED_WITH_NO_FILL,
CANCELLED_BY_MANAGER,
DISTRIBUTED,
LIQUIDATED
}
struct StvInfo {
address stvId;
uint40 endTime;
StvStatus status;
address manager;
uint96 capacityOfStv;
}
struct StvBalance {
uint96 totalRaised;
uint96 totalRemainingAfterDistribute;
}
struct InvestorInfo {
uint96 depositAmount;
uint96 claimedAmount;
bool claimed;
}
function getQ() external view returns (address);
function maxFundraisingPeriod() external view returns (uint40);
function distributeOut(address stvId, bool isCancel, uint256 indexFrom, uint256 indexTo) external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
library Errors {
// Zero Errors
error ZeroAmount();
error ZeroAddress();
error ZeroTotalRaised();
error ZeroClaimableAmount();
// Modifier Errors
error NotOwner();
error NotAdmin();
error CallerNotVault();
error CallerNotTrade();
error CallerNotVaultOwner();
error CallerNotGenerate();
error NoAccess();
error NotPlugin();
// State Errors
error BelowMinFundraisingPeriod();
error AboveMaxFundraisingPeriod();
error BelowMinLeverage();
error AboveMaxLeverage();
error BelowMinEndTime();
error TradeTokenNotApplicable();
// STV errors
error StvDoesNotExist();
error AlreadyOpened();
error MoreThanTotalRaised();
error MoreThanTotalReceived();
error StvNotOpen();
error StvNotClose();
error ClaimNotApplicable();
error StvStatusMismatch();
// General Errors
error BalanceLessThanAmount();
error FundraisingPeriodEnded();
error TotalRaisedMoreThanCapacity();
error StillFundraising();
error CommandMisMatch();
error TradeCommandMisMatch();
error NotInitialised();
error Initialised();
error LengthMismatch();
error TransferFailed();
error DelegateCallFailed();
error CallFailed(bytes);
error AccountAlreadyExists();
error SwapFailed();
error ExchangeDataMismatch();
error AccountNotExists();
error InputMismatch();
error AboveMaxDistributeIndex();
error BelowMinStvDepositAmount();
// Protocol specific errors
error GmxFeesMisMatch();
error UpdateOrderRequestMisMatch();
error CancelOrderRequestMisMatch();
// Subscriptions
error NotASubscriber();
error AlreadySubscribed();
error MoreThanLimit();
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
library BytesCheck {
/// @notice check if the first digit of the hexadecimal value starts with `0x0`
function checkFirstDigit0x0(uint8 x) public pure returns (bool) {
uint8 y = uint8(x & 0xF0);
uint8 z = y >> 4;
return (z == 0x0);
}
/// @notice check if the first digit of the hexadecimal value starts with `0x1`
function checkFirstDigit0x1(uint8 x) public pure returns (bool) {
uint8 y = uint8(x & 0xF0);
uint8 z = y >> 4;
return (z == 0x1);
}
/// @notice check if the first digit of the hexadecimal value starts with `0x2`
function checkFirstDigit0x2(uint8 x) public pure returns (bool) {
uint8 y = uint8(x & 0xF0);
uint8 z = y >> 4;
return (z == 0x2);
}
/// @notice check if the first digit of the hexadecimal value starts with `0x3`
function checkFirstDigit0x3(uint8 x) public pure returns (bool) {
uint8 y = uint8(x & 0xF0);
uint8 z = y >> 4;
return (z == 0x3);
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
contract VaultEvents {
event InitVault(
address indexed operator,
uint40 maxFundraisingPeriod,
bytes32 indexed domainSeparator,
bytes32 indexed executeTypeHash
);
event CreateStv(
bytes32 indexed metadataHash,
address indexed stvId,
address indexed manager,
uint40 endTime,
uint96 capacityOfStv
);
event Deposit(address indexed stvId, address indexed caller, address indexed investor, uint96 amount);
event DepositWithSubscription(
address indexed stvId, address indexed caller, address indexed investor, uint96 amount
);
event Liquidate(address indexed stvId, uint8 status);
event Execute(
address indexed stvId,
uint96 amount,
uint96 totalReceived,
uint256 command,
bytes data,
uint256 msgValue,
bool isIncrease
);
event Distribute(
address indexed stvId, uint96 totalRemainingAfterDistribute, uint96 mFee, uint96 pFee, uint256 command
);
event Cancel(address indexed stvId, uint8 status);
event MaxFundraisingPeriod(uint40 maxFundraisingPeriod);
event ClaimRewards(address indexed stvId, uint256 command, bytes indexed rewardData);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
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));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
interface IAccount {
function execute(address adapter, bytes calldata data, uint256 ethToSend)
external
payable
returns (bytes memory returnData);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import {IVault} from "src/interfaces/IVault.sol";
interface IStvAccount {
function stvInfo() external view returns (IVault.StvInfo memory);
function stvBalance() external view returns (IVault.StvBalance memory);
function investorInfo(address investorAccount) external view returns (IVault.InvestorInfo memory);
function investors() external view returns (address[] memory);
function getInvestors() external view returns (address[] memory);
function totalTradeTokenReceivedAfterOpen(address token) external view returns (uint96);
function totalTradeTokenUsedForClose(address token) external view returns (uint96);
function execute(address adapter, bytes calldata data, uint256 ethToSend) external payable;
function createStv(IVault.StvInfo memory stv) external;
function deposit(address investorAccount, uint96 amount, bool isFirstDeposit) external;
function liquidate() external;
function execute(uint96 amount, address tradeToken, uint96 totalReceived, bool isOpen) external;
function distribute(uint96 totalRemainingAfterDistribute, uint96 mFee, uint96 pFee) external;
function distributeOut(bool isCancel, uint256 indexFrom, uint256 indexTo) external;
function updateStatus(IVault.StvStatus status) external;
function cancel() external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
interface IQ {
function owner() external view returns (address);
function admin() external view returns (address);
function perpTrade() external view returns (address);
function whitelistedPlugins(address) external view returns (bool);
function defaultStableCoin() external view returns (address);
function traderAccount(address) external view returns (address);
function createAccount(address) external returns (address);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import {Errors} from "src/libraries/Errors.sol";
import {IVault} from "src/interfaces/IVault.sol";
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
import {IOperator} from "src/storage/interfaces/IOperator.sol";
library Generate {
/// @notice deploys a new clone of `StvAccount`
/// @param capacityOfStv capacity of the stv
/// @param manager address of the manager
/// @param operator address of the operator
/// @param maxFundraisingPeriod max fundraising period for an stv
function generate(uint96 capacityOfStv, address manager, address operator, uint40 maxFundraisingPeriod)
external
returns (IVault.StvInfo memory stv)
{
address stvAccountImplementation = IOperator(operator).getAddress("STVACCOUNT");
address defaultStableCoin = IOperator(operator).getAddress("DEFAULTSTABLECOIN");
if (capacityOfStv < 1e6) revert Errors.InputMismatch();
stv.manager = manager;
stv.endTime = uint40(block.timestamp) + maxFundraisingPeriod;
stv.capacityOfStv = capacityOfStv;
bytes32 salt = keccak256(
abi.encodePacked(
manager, defaultStableCoin, capacityOfStv, maxFundraisingPeriod, block.timestamp, block.chainid
)
);
address contractAddress = Clones.cloneDeterministic(stvAccountImplementation, salt);
stv.stvId = contractAddress;
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import {Commands} from "src/libraries/Commands.sol";
import {Errors} from "src/libraries/Errors.sol";
import {IStvAccount} from "src/interfaces/IStvAccount.sol";
import {SpotTrade} from "src/SpotTrade/SpotTrade.sol";
import {IOperator} from "src/storage/interfaces/IOperator.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IPerpTrade} from "src/PerpTrade/interfaces/IPerpTrade.sol";
library Trade {
/*//////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice execute the type of trade
/// @param command the command of the ddex protocol from `Commands` library
/// @param data encoded data of parameters depending on the ddex
/// @param isOpen bool to check if the trade is an increase or a decrease trade
/// @param operator address of the operator
/// @return totalReceived after executing the trade
function execute(uint256 command, bytes calldata data, bool isOpen, address operator)
external
returns (uint96 totalReceived)
{
(address stvId, uint96 amount, address tradeToken) = _getParams(data);
address defaultStableCoin = IOperator(operator).getAddress("DEFAULTSTABLECOIN");
if (tradeToken == defaultStableCoin) revert Errors.InputMismatch();
address tokenIn = isOpen ? defaultStableCoin : tradeToken;
address tokenOut = isOpen ? tradeToken : defaultStableCoin;
if (command == Commands.UNI) {
(,,, bytes memory commands, bytes[] memory inputs, uint256 deadline) =
abi.decode(data, (address, uint96, address, bytes, bytes[], uint256));
bytes memory addresses = abi.encode(stvId, operator);
_transferTokens(stvId, amount, tokenIn, operator);
totalReceived = SpotTrade.uni(tokenIn, tokenOut, amount, commands, inputs, deadline, addresses);
} else if (command == Commands.SUSHI) {
(,,, uint256 amountOutMin) = abi.decode(data, (address, uint96, address, uint256));
if (amountOutMin < 1) revert Errors.ZeroAmount();
_transferTokens(stvId, amount, tokenIn, operator);
totalReceived = SpotTrade.sushi(tokenIn, tokenOut, amount, amountOutMin, stvId, operator);
} else if (command == Commands.ONE_INCH) {
(,,, bytes memory exchangeData) = abi.decode(data, (address, uint96, address, bytes));
_transferTokens(stvId, amount, tokenIn, operator);
totalReceived = SpotTrade.oneInch(tokenIn, tokenOut, stvId, exchangeData, operator);
} else {
revert Errors.CommandMisMatch();
}
}
/// @notice distribute the fees and the remaining tokens after the stv is closed
/// @param stvId address of the stv
/// @param command the command of the ddex protocol from `Commands` library
/// @param managerFees manager fees in 1e18 decimals
/// @param protocolFees protocol fees in 1e18 decimals
/// @param tradeTokens address of the trade tokens to swap
/// @param exchangeData exchange data to swap, 0 - eth swap, 1 - tradeToken swap
/// @param operator address of the operator
/// @return totalRemainingAfterDistribute amount of defaultStableCoin remaining after fees
/// @return mFee manager fees
/// @return pFee protocol fees
function distribute(
address stvId,
uint256 command,
uint96 totalDepositTokenUsed,
uint96 managerFees,
uint96 protocolFees,
address[] calldata tradeTokens,
bytes[] calldata exchangeData,
address operator
) external returns (uint96 totalRemainingAfterDistribute, uint96 mFee, uint96 pFee) {
address id = stvId; // to avoid stack too deep
address defaultStableCoin = IOperator(operator).getAddress("DEFAULTSTABLECOIN");
uint256 depositTokenBalance = IERC20(defaultStableCoin).balanceOf(id);
// TODO solve stack too deep by making the input params as a struct ??
{
uint256 c = command; // to avoid stack too deep
if (c == Commands.GMX) {
address[] memory tts = tradeTokens;
bytes[] memory tokenSwapExchangeData = exchangeData;
if (tts.length != tokenSwapExchangeData.length) revert Errors.LengthMismatch();
_swap(id, operator, tts, tokenSwapExchangeData);
} else if (c == Commands.KWENTA) {
// swap from sUSD to USDC is done in PerpTrade call (withdraw all margin + swap to USDC)
// exchangeData[0] should be "data" in PerpTrade._kwenta(bytes calldata data, bool isOpen) call
address perpTrade = IOperator(operator).getAddress("PERPTRADE");
IPerpTrade(perpTrade).execute(Commands.KWENTA, exchangeData[0], false);
}
uint256 depositTokenBalanceAfter = IERC20(defaultStableCoin).balanceOf(id);
if (depositTokenBalanceAfter > depositTokenBalance) depositTokenBalance = depositTokenBalanceAfter;
if (depositTokenBalance < 1) revert Errors.ZeroAmount();
}
(totalRemainingAfterDistribute, mFee, pFee) =
_distribute(totalDepositTokenUsed, uint96(depositTokenBalance), managerFees, protocolFees);
}
/*//////////////////////////////////////////////////////////////
INTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice get the first two params of the encoded data which is the address and the amount
function _getParams(bytes calldata data) internal pure returns (address stvId, uint96 amount, address tradeToken) {
assembly {
stvId := calldataload(data.offset)
amount := calldataload(add(data.offset, 0x20))
tradeToken := calldataload(add(data.offset, 0x40))
}
}
/// @notice transfer the tokens to the `Vault` contract before executing the trade
function _transferTokens(address stvId, uint96 amount, address tokenIn, address operator) internal {
address vault = IOperator(operator).getAddress("VAULT");
bytes memory tradeData = abi.encodeWithSignature("transfer(address,uint256)", vault, amount);
IStvAccount(stvId).execute(tokenIn, tradeData, 0);
}
/// @notice pure function to calculate the manager and the protocol fees
function _distribute(uint96 totalRaised, uint96 totalReceivedAfterClose, uint96 managerFees, uint96 protocolFees)
internal
pure
returns (uint96 totalRemainingAfterDistribute, uint96 mFee, uint96 pFee)
{
if (totalReceivedAfterClose > totalRaised) {
uint96 profits = totalReceivedAfterClose - totalRaised;
mFee = (profits * (managerFees / 1e18)) / 100;
pFee = (profits * (protocolFees / 1e18)) / 100;
totalRemainingAfterDistribute = totalReceivedAfterClose - mFee - pFee;
} else {
totalRemainingAfterDistribute = totalReceivedAfterClose;
}
}
/// @notice internal function to swap the tokens when `distribute` is called
function _swap(address account, address operator, address[] memory tokensIn, bytes[] memory exchangeData)
internal
{
if (tokensIn.length != exchangeData.length) revert Errors.LengthMismatch();
address exchangeRouter = IOperator(operator).getAddress("ONEINCHROUTER");
uint256 i;
for (; i < tokensIn.length;) {
if (tokensIn[i] != address(0)) {
address defaultStableCoin = IOperator(operator).getAddress("DEFAULTSTABLECOIN");
uint256 balanceBefore = IERC20(defaultStableCoin).balanceOf(account);
uint256 tokenInBalance = IERC20(tokensIn[i]).balanceOf(account);
bytes memory tokenApprovalData =
abi.encodeWithSignature("approve(address,uint256)", exchangeRouter, tokenInBalance);
IStvAccount(account).execute(tokensIn[i], tokenApprovalData, 0);
IStvAccount(account).execute(exchangeRouter, exchangeData[i], 0);
// (uint256 returnAmount,) = abi.decode(returnData, (uint256, uint256));
uint256 balanceAfter = IERC20(defaultStableCoin).balanceOf(account);
if (balanceAfter <= balanceBefore) revert Errors.BalanceLessThanAmount();
} else {
uint256 ethBalance = account.balance;
// TODO use i or 0
bytes memory ethSwapExchangeData = exchangeData[0];
if (ethBalance > 0) IStvAccount(account).execute(exchangeRouter, ethSwapExchangeData, ethBalance);
}
unchecked {
++i;
}
}
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
interface IOperator {
function getMaxDistributeIndex() external view returns (uint256);
function getAddress(string calldata adapter) external view returns (address);
function getAddresses(string[] calldata adapters) external view returns (address[] memory);
function getTraderAccount(address trader) external view returns (address);
function getPlugin(address plugin) external view returns (bool);
function getPlugins(address[] calldata plugins) external view returns (bool[] memory);
function setAddress(string calldata adapter, address addr) external;
function setAddresses(string[] calldata adapters, address[] calldata addresses) external;
function setPlugin(address plugin, bool isPlugin) external;
function setPlugins(address[] calldata plugins, bool[] calldata isPlugin) external;
function setTraderAccount(address trader, address account) external;
function getAllSubscribers(address manager) external view returns (address[] memory);
function getIsSubscriber(address manager, address subscriber) external view returns (bool);
function getSubscriptionAmount(address manager, address subscriber) external view returns (uint96);
function getTotalSubscribedAmountPerManager(address manager) external view returns (uint96);
function setSubscribe(address manager, address subscriber, uint96 maxLimit) external;
function setUnsubscribe(address manager, address subscriber) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../Strings.sol";
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV // Deprecated in v4.8
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://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 functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (proxy/Clones.sol)
pragma solidity ^0.8.0;
/**
* @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
* deploying minimal proxy contracts, also known as "clones".
*
* > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
* > a minimal bytecode implementation that delegates all calls to a known, fixed address.
*
* The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
* (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
* deterministic method.
*
* _Available since v3.4._
*/
library Clones {
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
*
* This function uses the create opcode, which should never revert.
*/
function clone(address implementation) internal returns (address instance) {
/// @solidity memory-safe-assembly
assembly {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
instance := create(0, 0x09, 0x37)
}
require(instance != address(0), "ERC1167: create failed");
}
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
*
* This function uses the create2 opcode and a `salt` to deterministically deploy
* the clone. Using the same `implementation` and `salt` multiple time will revert, since
* the clones cannot be deployed twice at the same address.
*/
function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
/// @solidity memory-safe-assembly
assembly {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
instance := create2(0, 0x09, 0x37, salt)
}
require(instance != address(0), "ERC1167: create2 failed");
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(add(ptr, 0x38), deployer)
mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)
mstore(add(ptr, 0x14), implementation)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73)
mstore(add(ptr, 0x58), salt)
mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37))
predicted := keccak256(add(ptr, 0x43), 0x55)
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(address implementation, bytes32 salt)
internal
view
returns (address predicted)
{
return predictDeterministicAddress(implementation, salt, address(this));
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
/// @title Commands similar to UniversalRouter
/// @notice Command Flags used to decode commands
/// @notice https://github.com/Uniswap/universal-router/blob/main/contracts/libraries/Commands.sol
library Commands {
// Masks to extract certain bits of commands
bytes1 internal constant FLAG_ALLOW_REVERT = 0x80;
bytes1 internal constant COMMAND_TYPE_MASK = 0x3f;
// Command Types. Maximum supported command at this moment is 0x3f.
// Command Types where value >= 0x00, for Perpetuals
uint256 constant GMX = 0x00;
uint256 constant PERP = 0x01;
uint256 constant CAP = 0x02;
uint256 constant KWENTA = 0x03;
// COMMAND_PLACEHOLDER = 0x04;
// Future perpetual protocols can be added below
// Command Types where value >= 0x10, for Spot
uint256 constant UNI = 0x10;
uint256 constant SUSHI = 0x11;
uint256 constant ONE_INCH = 0x12;
uint256 constant TRADER_JOE = 0x13;
uint256 constant PANCAKE = 0x14;
// COMMAND_PLACEHOLDER = 0x15;
// Future spot protocols can be added below
// Future financial services like options can be added with a value >= 0x20
// Command Types where value >= 0x30, for trade functions
uint256 constant CROSS_CHAIN = 0x30;
uint256 constant MODIFY_ORDER = 0x31;
uint256 constant CLAIM_REWARDS = 0x32;
// COMMAND_PLACEHOLDER = 0x3d;
// Future functions to interact with protocols can be added below
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import {Commands} from "src/libraries/Commands.sol";
import {Errors} from "src/libraries/Errors.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IUniversalRouter} from "src/protocols/uni/interfaces/IUniversalRouter.sol";
import {IPermit2} from "src/protocols/uni/interfaces/IPermit2.sol";
import {IUniswapV2Router02} from "src/protocols/sushi/interfaces/IUniswapV2Router02.sol";
import {Commands as UniCommands} from "test/libraries/Commands.sol";
import {BytesLib} from "test/libraries/BytesLib.sol";
import {IOperator} from "src/storage/interfaces/IOperator.sol";
library SpotTrade {
using BytesLib for bytes;
using SafeERC20 for IERC20;
function uni(
address tokenIn,
address tokenOut,
uint96 amountIn,
bytes calldata commands,
bytes[] calldata inputs,
uint256 deadline,
bytes memory addresses
) external returns (uint96) {
(address receiver, address operator) = abi.decode(addresses, (address, address));
address universalRouter = IOperator(operator).getAddress("UNIVERSALROUTER");
address permit2 = IOperator(operator).getAddress("PERMIT2");
_check(tokenIn, tokenOut, amountIn, commands, inputs, receiver);
IERC20(tokenIn).approve(address(permit2), amountIn);
IPermit2(permit2).approve(tokenIn, address(universalRouter), uint160(amountIn), type(uint48).max);
uint96 balanceBeforeSwap = uint96(IERC20(tokenOut).balanceOf(receiver));
if (deadline > 0) IUniversalRouter(universalRouter).execute(commands, inputs, deadline);
else IUniversalRouter(universalRouter).execute(commands, inputs);
uint96 balanceAfterSwap = uint96(IERC20(tokenOut).balanceOf(receiver));
return balanceAfterSwap - balanceBeforeSwap;
}
function _check(
address tokenIn,
address tokenOut,
uint96 amountIn,
bytes calldata commands,
bytes[] calldata inputs,
address receiver
) internal pure {
uint256 amount;
for (uint256 i = 0; i < commands.length;) {
bytes calldata input = inputs[i];
// the address of the receiver should be spot when opening and trade when closing
if (address(bytes20(input[12:32])) != receiver) revert Errors.InputMismatch();
// since the route can be through v2 and v3, adding the swap amount for each input should be equal to the total swap amount
amount += uint256(bytes32(input[32:64]));
if (commands[i] == bytes1(uint8(UniCommands.V2_SWAP_EXACT_IN))) {
address[] calldata path = input.toAddressArray(3);
// the first address of the path should be tokenIn
if (path[0] != tokenIn) revert Errors.InputMismatch();
// last address of the path should be the tokenOut
if (path[path.length - 1] != tokenOut) revert Errors.InputMismatch();
} else if (commands[i] == bytes1(uint8(UniCommands.V3_SWAP_EXACT_IN))) {
bytes calldata path = input.toBytes(3);
// the first address of the path should be tokenIn
if (address(bytes20(path[:20])) != tokenIn) revert Errors.InputMismatch();
// last address of the path should be the tokenOut
if (address(bytes20(path[path.length - 20:])) != tokenOut) revert Errors.InputMismatch();
} else {
// if its not v2 or v3, then revert
revert Errors.CommandMisMatch();
}
unchecked {
++i;
}
}
if (amount != uint256(amountIn)) revert Errors.InputMismatch();
}
function sushi(
address tokenIn,
address tokenOut,
uint96 amountIn,
uint256 amountOutMin,
address receiver,
address operator
) external returns (uint96) {
address router = IOperator(operator).getAddress("SUSHIROUTER");
IERC20(tokenIn).approve(router, amountIn);
address[] memory tokenPath;
address wrappedToken = IOperator(operator).getAddress("WRAPPEDTOKEN");
if (tokenIn == wrappedToken || tokenOut == wrappedToken) {
tokenPath = new address[](2);
tokenPath[0] = tokenIn;
tokenPath[1] = tokenOut;
} else {
tokenPath = new address[](3);
tokenPath[0] = tokenIn;
tokenPath[1] = wrappedToken;
tokenPath[2] = tokenOut;
}
uint256[] memory amounts = IUniswapV2Router02(router).swapExactTokensForTokens(
amountIn, amountOutMin, tokenPath, receiver, block.timestamp
);
uint256 length = amounts.length;
// return the last amount received
return uint96(amounts[length - 1]);
}
function oneInch(address tokenIn, address tokenOut, address receiver, bytes memory exchangeData, address operator)
external
returns (uint96)
{
if (exchangeData.length == 0) revert Errors.ExchangeDataMismatch();
address router = IOperator(operator).getAddress("ONEINCHROUTER");
address vault = IOperator(operator).getAddress("VAULT");
uint256 tokenInBalanceBefore = IERC20(tokenIn).balanceOf(vault);
uint256 tokenOutBalanceBefore = IERC20(tokenOut).balanceOf(receiver);
IERC20(tokenIn).safeApprove(router, type(uint256).max);
(bool success, bytes memory returnData) = router.call(exchangeData);
uint256 returnAmount;
if (success) {
IERC20(tokenIn).safeApprove(router, 0);
returnAmount = abi.decode(returnData, (uint256));
uint256 tokenInBalanceAfter = IERC20(tokenIn).balanceOf(vault);
uint256 tokenOutBalanceAfter = IERC20(tokenOut).balanceOf(receiver);
if (tokenInBalanceAfter >= tokenInBalanceBefore) revert Errors.BalanceLessThanAmount();
if (tokenOutBalanceAfter <= tokenOutBalanceBefore) revert Errors.BalanceLessThanAmount();
} else {
revert Errors.SwapFailed();
}
return uint96(returnAmount);
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
interface IPerpTrade {
function execute(uint256 command, bytes calldata data, bool isOpen) external payable;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.13;
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {IERC1155Receiver} from "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
/// @title LooksRare Rewards Collector
/// @notice Implements a permissionless call to fetch LooksRare rewards earned by Universal Router users
/// and transfers them to an external rewards distributor contract
interface IRewardsCollector {
/// @notice Fetches users' LooksRare rewards and sends them to the distributor contract
/// @param looksRareClaim The data required by LooksRare to claim reward tokens
function collectRewards(bytes calldata looksRareClaim) external;
}
interface IUniversalRouter is IRewardsCollector, IERC721Receiver, IERC1155Receiver {
/// @notice Thrown when a required command has failed
error ExecutionFailed(uint256 commandIndex, bytes message);
/// @notice Thrown when attempting to send ETH directly to the contract
error ETHNotAccepted();
/// @notice Thrown when executing commands with an expired deadline
error TransactionDeadlinePassed();
/// @notice Thrown when attempting to execute commands and an incorrect number of inputs are provided
error LengthMismatch();
/// @notice Executes encoded commands along with provided inputs. Reverts if deadline has expired.
/// @param commands A set of concatenated commands, each 1 byte in length
/// @param inputs An array of byte strings containing abi encoded inputs for each command
/// @param deadline The deadline by which the transaction must be executed
function execute(bytes calldata commands, bytes[] calldata inputs, uint256 deadline) external payable;
/// @notice Executes encoded commands along with provided inputs.
/// @param commands A set of concatenated commands, each 1 byte in length
/// @param inputs An array of byte strings containing abi encoded inputs for each command
function execute(bytes calldata commands, bytes[] calldata inputs) external payable;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
/// @title AllowanceTransfer
/// @notice Handles ERC20 token permissions through signature based allowance setting and ERC20 token transfers by checking allowed amounts
/// @dev Requires user's token approval on the Permit2 contract
interface IPermit2 {
/// @notice Thrown when an allowance on a token has expired.
/// @param deadline The timestamp at which the allowed amount is no longer valid
error AllowanceExpired(uint256 deadline);
/// @notice Thrown when an allowance on a token has been depleted.
/// @param amount The maximum amount allowed
error InsufficientAllowance(uint256 amount);
/// @notice Thrown when too many nonces are invalidated.
error ExcessiveInvalidation();
/// @notice Emits an event when the owner successfully invalidates an ordered nonce.
event NonceInvalidation(
address indexed owner, address indexed token, address indexed spender, uint48 newNonce, uint48 oldNonce
);
/// @notice Emits an event when the owner successfully sets permissions on a token for the spender.
event Approval(
address indexed owner, address indexed token, address indexed spender, uint160 amount, uint48 expiration
);
/// @notice Emits an event when the owner successfully sets permissions using a permit signature on a token for the spender.
event Permit(
address indexed owner,
address indexed token,
address indexed spender,
uint160 amount,
uint48 expiration,
uint48 nonce
);
/// @notice Emits an event when the owner sets the allowance back to 0 with the lockdown function.
event Lockdown(address indexed owner, address token, address spender);
/// @notice The permit data for a token
struct PermitDetails {
// ERC20 token address
address token;
// the maximum amount allowed to spend
uint160 amount;
// timestamp at which a spender's token allowances become invalid
uint48 expiration;
// an incrementing value indexed per owner,token,and spender for each signature
uint48 nonce;
}
/// @notice The permit message signed for a single token allownce
struct PermitSingle {
// the permit data for a single token alownce
PermitDetails details;
// address permissioned on the allowed tokens
address spender;
// deadline on the permit signature
uint256 sigDeadline;
}
/// @notice The permit message signed for multiple token allowances
struct PermitBatch {
// the permit data for multiple token allowances
PermitDetails[] details;
// address permissioned on the allowed tokens
address spender;
// deadline on the permit signature
uint256 sigDeadline;
}
/// @notice The saved permissions
/// @dev This info is saved per owner, per token, per spender and all signed over in the permit message
/// @dev Setting amount to type(uint160).max sets an unlimited approval
struct PackedAllowance {
// amount allowed
uint160 amount;
// permission expiry
uint48 expiration;
// an incrementing value indexed per owner,token,and spender for each signature
uint48 nonce;
}
/// @notice A token spender pair.
struct TokenSpenderPair {
// the token the spender is approved
address token;
// the spender address
address spender;
}
/// @notice Details for a token transfer.
struct AllowanceTransferDetails {
// the owner of the token
address from;
// the recipient of the token
address to;
// the amount of the token
uint160 amount;
// the token to be transferred
address token;
}
/// @notice A mapping from owner address to token address to spender address to PackedAllowance struct, which contains details and conditions of the approval.
/// @notice The mapping is indexed in the above order see: allowance[ownerAddress][tokenAddress][spenderAddress]
/// @dev The packed slot holds the allowed amount, expiration at which the allowed amount is no longer valid, and current nonce thats updated on any signature based approvals.
function allowance(address, address, address) external view returns (uint160, uint48, uint48);
/// @notice Approves the spender to use up to amount of the specified token up until the expiration
/// @param token The token to approve
/// @param spender The spender address to approve
/// @param amount The approved amount of the token
/// @param expiration The timestamp at which the approval is no longer valid
/// @dev The packed allowance also holds a nonce, which will stay unchanged in approve
/// @dev Setting amount to type(uint160).max sets an unlimited approval
function approve(address token, address spender, uint160 amount, uint48 expiration) external;
/// @notice Permit a spender to a given amount of the owners token via the owner's EIP-712 signature
/// @dev May fail if the owner's nonce was invalidated in-flight by invalidateNonce
/// @param owner The owner of the tokens being approved
/// @param permitSingle Data signed over by the owner specifying the terms of approval
/// @param signature The owner's signature over the permit data
function permit(address owner, PermitSingle memory permitSingle, bytes calldata signature) external;
/// @notice Permit a spender to the signed amounts of the owners tokens via the owner's EIP-712 signature
/// @dev May fail if the owner's nonce was invalidated in-flight by invalidateNonce
/// @param owner The owner of the tokens being approved
/// @param permitBatch Data signed over by the owner specifying the terms of approval
/// @param signature The owner's signature over the permit data
function permit(address owner, PermitBatch memory permitBatch, bytes calldata signature) external;
/// @notice Transfer approved tokens from one address to another
/// @param from The address to transfer from
/// @param to The address of the recipient
/// @param amount The amount of the token to transfer
/// @param token The token address to transfer
/// @dev Requires the from address to have approved at least the desired amount
/// of tokens to msg.sender.
function transferFrom(address from, address to, uint160 amount, address token) external;
/// @notice Transfer approved tokens in a batch
/// @param transferDetails Array of owners, recipients, amounts, and tokens for the transfers
/// @dev Requires the from addresses to have approved at least the desired amount
/// of tokens to msg.sender.
function transferFrom(AllowanceTransferDetails[] calldata transferDetails) external;
/// @notice Enables performing a "lockdown" of the sender's Permit2 identity
/// by batch revoking approvals
/// @param approvals Array of approvals to revoke.
function lockdown(TokenSpenderPair[] calldata approvals) external;
/// @notice Invalidate nonces for a given (token, spender) pair
/// @param token The token to invalidate nonces for
/// @param spender The spender to invalidate nonces for
/// @param newNonce The new nonce to set. Invalidates all nonces less than it.
/// @dev Can't invalidate more than 2**16 nonces per transaction.
function invalidateNonces(address token, address spender, uint48 newNonce) external;
}// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.6.2;
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB, uint256 liquidity);
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB);
function removeLiquidityETH(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountToken, uint256 amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountA, uint256 amountB);
function removeLiquidityETHWithPermit(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountToken, uint256 amountETH);
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactETHForTokens(uint256 amountOutMin, address[] calldata path, address to, uint256 deadline)
external
payable
returns (uint256[] memory amounts);
function swapTokensForExactETH(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactTokensForETH(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapETHForExactTokens(uint256 amountOut, address[] calldata path, address to, uint256 deadline)
external
payable
returns (uint256[] memory amounts);
function quote(uint256 amountA, uint256 reserveA, uint256 reserveB) external pure returns (uint256 amountB);
function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut)
external
pure
returns (uint256 amountOut);
function getAmountIn(uint256 amountOut, uint256 reserveIn, uint256 reserveOut)
external
pure
returns (uint256 amountIn);
function getAmountsOut(uint256 amountIn, address[] calldata path)
external
view
returns (uint256[] memory amounts);
function getAmountsIn(uint256 amountOut, address[] calldata path)
external
view
returns (uint256[] memory amounts);
}
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.15;
/// @title Commands
/// @notice Command Flags used to decode commands
library Commands {
// Masks to extract certain bits of commands
bytes1 internal constant FLAG_ALLOW_REVERT = 0x80;
bytes1 internal constant COMMAND_TYPE_MASK = 0x3f;
// Command Types. Maximum supported command at this moment is 0x3f.
// Command Types where value<0x08, executed in the first nested-if block
uint256 constant V3_SWAP_EXACT_IN = 0x00;
uint256 constant V3_SWAP_EXACT_OUT = 0x01;
uint256 constant PERMIT2_TRANSFER_FROM = 0x02;
uint256 constant PERMIT2_PERMIT_BATCH = 0x03;
uint256 constant SWEEP = 0x04;
uint256 constant TRANSFER = 0x05;
uint256 constant PAY_PORTION = 0x06;
// COMMAND_PLACEHOLDER = 0x07;
// Command Types where 0x08<=value<=0x0f, executed in the second nested-if block
uint256 constant V2_SWAP_EXACT_IN = 0x08;
uint256 constant V2_SWAP_EXACT_OUT = 0x09;
uint256 constant PERMIT2_PERMIT = 0x0a;
uint256 constant WRAP_ETH = 0x0b;
uint256 constant UNWRAP_WETH = 0x0c;
uint256 constant PERMIT2_TRANSFER_FROM_BATCH = 0x0d;
// COMMAND_PLACEHOLDER = 0x0e;
// COMMAND_PLACEHOLDER = 0x0f;
// Command Types where 0x10<=value<0x18, executed in the third nested-if block
uint256 constant SEAPORT = 0x10;
uint256 constant LOOKS_RARE_721 = 0x11;
uint256 constant NFTX = 0x12;
uint256 constant CRYPTOPUNKS = 0x13;
uint256 constant LOOKS_RARE_1155 = 0x14;
uint256 constant OWNER_CHECK_721 = 0x15;
uint256 constant OWNER_CHECK_1155 = 0x16;
uint256 constant SWEEP_ERC721 = 0x17;
// Command Types where 0x18<=value<=0x1f, executed in the final nested-if block
uint256 constant X2Y2_721 = 0x18;
uint256 constant SUDOSWAP = 0x19;
uint256 constant NFT20 = 0x1a;
uint256 constant X2Y2_1155 = 0x1b;
uint256 constant FOUNDATION = 0x1c;
uint256 constant SWEEP_ERC1155 = 0x1d;
// COMMAND_PLACEHOLDER = 0x1e
// COMMAND_PLACEHOLDER = 0x1f
// Command Types where 0x20<=value
uint256 constant EXECUTE_SUB_PLAN = 0x20;
uint256 constant SEAPORT_V2 = 0x21;
// COMMAND_PLACEHOLDER for 0x22 to 0x3f (all unused)
}// SPDX-License-Identifier: GPL-3.0-or-later
/// @title Library for Bytes Manipulation
/// Based on Gonçalo Sá's BytesLib - but updated and heavily editted
pragma solidity ^0.8.0;
library BytesLib {
/// @notice Returns the address starting at byte 0
/// @dev length and overflow checks must be carried out before calling
/// @param _bytes The input bytes string to slice
/// @return tempAddress The address starting at byte 0
function toAddress(bytes calldata _bytes) internal pure returns (address tempAddress) {
assembly {
tempAddress := shr(96, calldataload(_bytes.offset))
}
}
/// @notice Returns the pool details starting at byte 0
/// @dev length and overflow checks must be carried out before calling
/// @param _bytes The input bytes string to slice
/// @return token0 The address at byte 0
/// @return fee The uint24 starting at byte 20
/// @return token1 The address at byte 23
function toPool(bytes calldata _bytes) internal pure returns (address token0, uint24 fee, address token1) {
assembly {
token0 := shr(96, calldataload(_bytes.offset))
fee := shr(232, calldataload(add(_bytes.offset, 20)))
token1 := shr(96, calldataload(add(_bytes.offset, 23)))
}
}
/// @notice Decode the `_arg`-th element in `_bytes` as a dynamic array
/// @dev The decoding of `length` and `offset` is universal,
/// whereas the type declaration of `res` instructs the compiler how to read it.
/// @param _bytes The input bytes string to slice
/// @param _arg The index of the argument to extract
/// @return length Length of the array
/// @return offset Pointer to the data part of the array
function toLengthOffset(bytes calldata _bytes, uint256 _arg)
internal
pure
returns (uint256 length, uint256 offset)
{
assembly {
// The offset of the `_arg`-th element is `32 * arg`, which stores the offset of the length pointer.
let lengthPtr := add(_bytes.offset, calldataload(add(_bytes.offset, mul(0x20, _arg))))
length := calldataload(lengthPtr)
offset := add(lengthPtr, 0x20)
}
}
/// @notice Decode the `_arg`-th element in `_bytes` as `bytes`
/// @param _bytes The input bytes string to extract a bytes string from
/// @param _arg The index of the argument to extract
function toBytes(bytes calldata _bytes, uint256 _arg) internal pure returns (bytes calldata res) {
(uint256 length, uint256 offset) = toLengthOffset(_bytes, _arg);
assembly {
res.length := length
res.offset := offset
}
}
/// @notice Decode the `_arg`-th element in `_bytes` as `address[]`
/// @param _bytes The input bytes string to extract an address array from
/// @param _arg The index of the argument to extract
function toAddressArray(bytes calldata _bytes, uint256 _arg) internal pure returns (address[] calldata res) {
(uint256 length, uint256 offset) = toLengthOffset(_bytes, _arg);
assembly {
res.length := length
res.offset := offset
}
}
/// @notice Decode the `_arg`-th element in `_bytes` as `bytes[]`
/// @param _bytes The input bytes string to extract a bytes array from
/// @param _arg The index of the argument to extract
function toBytesArray(bytes calldata _bytes, uint256 _arg) internal pure returns (bytes[] calldata res) {
(uint256 length, uint256 offset) = toLengthOffset(_bytes, _arg);
assembly {
res.length := length
res.offset := offset
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev _Available since v3.1._
*/
interface IERC1155Receiver is IERC165 {
/**
* @dev Handles the receipt of a single ERC1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
* @dev Handles the receipt of a multiple ERC1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}{
"remappings": [
"forge-std/=lib/forge-std/src/",
"@synthetix/=src/interfaces/synthetix/",
"@openzeppelin/=lib/openzeppelin-contracts/",
"@openzeppelin-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"solmate/=lib/solmate/src/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "paris",
"libraries": {
"src/Generate.sol": {
"Generate": "0x20eaed9ec336f9c1da92cc7e1c8a69d04926d946"
},
"src/SpotTrade/SpotTrade.sol": {
"SpotTrade": "0x035bbb9fe14e740bc32c31eae216dcafd0fcd6f8"
},
"src/Trade.sol": {
"Trade": "0x12be7395d46a024f7b82e2c6d8485498bde88bf3"
},
"src/libraries/BytesCheck.sol": {
"BytesCheck": "0xd70458ce942f4a4b911b3203591c1920c9007057"
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_operator","type":"address"},{"internalType":"uint40","name":"_maxFundraisingPeriod","type":"uint40"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccountNotExists","type":"error"},{"inputs":[],"name":"AlreadyOpened","type":"error"},{"inputs":[],"name":"BalanceLessThanAmount","type":"error"},{"inputs":[],"name":"BelowMinEndTime","type":"error"},{"inputs":[],"name":"BelowMinStvDepositAmount","type":"error"},{"inputs":[{"internalType":"bytes","name":"","type":"bytes"}],"name":"CallFailed","type":"error"},{"inputs":[],"name":"ExchangeDataMismatch","type":"error"},{"inputs":[],"name":"FundraisingPeriodEnded","type":"error"},{"inputs":[],"name":"InputMismatch","type":"error"},{"inputs":[],"name":"LengthMismatch","type":"error"},{"inputs":[],"name":"MoreThanTotalRaised","type":"error"},{"inputs":[],"name":"NoAccess","type":"error"},{"inputs":[],"name":"NotAdmin","type":"error"},{"inputs":[],"name":"NotOwner","type":"error"},{"inputs":[],"name":"StvDoesNotExist","type":"error"},{"inputs":[],"name":"StvNotOpen","type":"error"},{"inputs":[],"name":"StvStatusMismatch","type":"error"},{"inputs":[],"name":"TotalRaisedMoreThanCapacity","type":"error"},{"inputs":[],"name":"ZeroAmount","type":"error"},{"inputs":[],"name":"ZeroTotalRaised","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"stvId","type":"address"},{"indexed":false,"internalType":"uint8","name":"status","type":"uint8"}],"name":"Cancel","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"stvId","type":"address"},{"indexed":false,"internalType":"uint256","name":"command","type":"uint256"},{"indexed":true,"internalType":"bytes","name":"rewardData","type":"bytes"}],"name":"ClaimRewards","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"metadataHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"stvId","type":"address"},{"indexed":true,"internalType":"address","name":"manager","type":"address"},{"indexed":false,"internalType":"uint40","name":"endTime","type":"uint40"},{"indexed":false,"internalType":"uint96","name":"capacityOfStv","type":"uint96"}],"name":"CreateStv","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"stvId","type":"address"},{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"investor","type":"address"},{"indexed":false,"internalType":"uint96","name":"amount","type":"uint96"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"stvId","type":"address"},{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"investor","type":"address"},{"indexed":false,"internalType":"uint96","name":"amount","type":"uint96"}],"name":"DepositWithSubscription","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"stvId","type":"address"},{"indexed":false,"internalType":"uint96","name":"totalRemainingAfterDistribute","type":"uint96"},{"indexed":false,"internalType":"uint96","name":"mFee","type":"uint96"},{"indexed":false,"internalType":"uint96","name":"pFee","type":"uint96"},{"indexed":false,"internalType":"uint256","name":"command","type":"uint256"}],"name":"Distribute","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"stvId","type":"address"},{"indexed":false,"internalType":"uint96","name":"amount","type":"uint96"},{"indexed":false,"internalType":"uint96","name":"totalReceived","type":"uint96"},{"indexed":false,"internalType":"uint256","name":"command","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"},{"indexed":false,"internalType":"uint256","name":"msgValue","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isIncrease","type":"bool"}],"name":"Execute","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"uint40","name":"maxFundraisingPeriod","type":"uint40"},{"indexed":true,"internalType":"bytes32","name":"domainSeparator","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"executeTypeHash","type":"bytes32"}],"name":"InitVault","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"stvId","type":"address"},{"indexed":false,"internalType":"uint8","name":"status","type":"uint8"}],"name":"Liquidate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint40","name":"maxFundraisingPeriod","type":"uint40"}],"name":"MaxFundraisingPeriod","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"EXECUTE_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"stvId","type":"address"}],"name":"cancelStv","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"commands","type":"uint256[]"},{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"claimStvTradingReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint96","name":"capacityOfStv","type":"uint96"},{"internalType":"uint96","name":"subscriptionFundLimit","type":"uint96"},{"internalType":"bytes32","name":"metadataHash","type":"bytes32"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"createStv","outputs":[{"internalType":"address","name":"stvId","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint96","name":"capacityOfStv","type":"uint96"},{"internalType":"uint96","name":"subscriptionFundLimit","type":"uint96"},{"internalType":"bytes32","name":"metadataHash","type":"bytes32"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint96","name":"amount","type":"uint96"},{"internalType":"bytes","name":"exchangeData","type":"bytes"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"createStvWithDeposit","outputs":[{"internalType":"address","name":"stvId","type":"address"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"stvId","type":"address"},{"internalType":"uint96","name":"amount","type":"uint96"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"stvId","type":"address"},{"internalType":"uint96","name":"amount","type":"uint96"},{"internalType":"address","name":"token","type":"address"},{"internalType":"bytes","name":"exchangeData","type":"bytes"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"depositTo","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"stvId","type":"address"},{"internalType":"uint256","name":"command","type":"uint256"},{"internalType":"uint96","name":"totalDepositTokenUsed","type":"uint96"},{"internalType":"uint96","name":"managerFees","type":"uint96"},{"internalType":"uint96","name":"protocolFees","type":"uint96"},{"internalType":"address[]","name":"tradeTokens","type":"address[]"},{"internalType":"bytes[]","name":"exchangeData","type":"bytes[]"}],"name":"distribute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"stvId","type":"address"},{"internalType":"bool","name":"isCancel","type":"bool"},{"internalType":"uint256","name":"indexFrom","type":"uint256"},{"internalType":"uint256","name":"indexTo","type":"uint256"}],"name":"distributeOut","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"command","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"bool","name":"isOpen","type":"bool"}],"name":"execute","outputs":[{"internalType":"address","name":"tradeToken","type":"address"},{"internalType":"uint96","name":"totalReceived","type":"uint96"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"investor","type":"address"},{"internalType":"address","name":"stvId","type":"address"}],"name":"getInvestorInfo","outputs":[{"components":[{"internalType":"uint96","name":"depositAmount","type":"uint96"},{"internalType":"uint96","name":"claimedAmount","type":"uint96"},{"internalType":"bool","name":"claimed","type":"bool"}],"internalType":"struct IVault.InvestorInfo","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"stvId","type":"address"}],"name":"getInvestors","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getQ","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"stvId","type":"address"}],"name":"getStvBalance","outputs":[{"components":[{"internalType":"uint96","name":"totalRaised","type":"uint96"},{"internalType":"uint96","name":"totalRemainingAfterDistribute","type":"uint96"}],"internalType":"struct IVault.StvBalance","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"stvId","type":"address"}],"name":"getStvInfo","outputs":[{"components":[{"internalType":"address","name":"stvId","type":"address"},{"internalType":"uint40","name":"endTime","type":"uint40"},{"internalType":"enum IVault.StvStatus","name":"status","type":"uint8"},{"internalType":"address","name":"manager","type":"address"},{"internalType":"uint96","name":"capacityOfStv","type":"uint96"}],"internalType":"struct IVault.StvInfo","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"stvId","type":"address"}],"name":"liquidate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"maxFundraisingPeriod","outputs":[{"internalType":"uint40","name":"","type":"uint40"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"commands","type":"uint256[]"},{"internalType":"bytes[]","name":"data","type":"bytes[]"},{"internalType":"uint256[]","name":"msgValue","type":"uint256[]"},{"internalType":"bool[]","name":"isOpen","type":"bool[]"}],"name":"multiExecute","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"operator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint40","name":"_maxFundraisingPeriod","type":"uint40"}],"name":"setMaxFundraisingPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
600561012052641d985d5b1d60da1b610140527f23c14fceac7676b670aa56866076586ea1ce15ddcf19208ec6346cf748dffbee6080526101a0604052600161016052603160f81b610180527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660a0523480156200007c57600080fd5b5060405162005a2038038062005a208339810160408190526200009f91620001b5565b6001600081905580546001600160a01b0384166001600160c81b031990911617600160a01b64ffffffffff8416021790556080805160a08051604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f602080830191909152818301959095526060810192909252469482019490945230818301528351808203909201825260c001909252815191012060c08190524660e052306101005260405164ffffffffff831681527f0e8122b9966a5ace153720b4cfa9a4339fe04cf7270694b3ad4068a61436900b91906001600160a01b038516907f562f8815308f4da77fac1f69d14177b023fda3f7ae6690f99abcc912f408846f9060200160405180910390a4505062000208565b60008060408385031215620001c957600080fd5b82516001600160a01b0381168114620001e157600080fd5b602084015190925064ffffffffff81168114620001fd57600080fd5b809150509250929050565b60805160a05160c05160e051610100516157d36200024d60003960006105d8015260006106020152600061062c015260006106a50152600061067d01526157d36000f3fe6080604052600436106101355760003560e01c8063814f543c116100ab578063dad8be5b1161006f578063dad8be5b146103e5578063e34c333314610405578063e8e4197a14610425578063e98285e91461043a578063ec259c891461044d578063fe75ede31461047a57600080fd5b8063814f543c146102f8578063865f694b14610319578063a74865b21461032c578063ac156ddb1461037e578063acd560b11461039e57600080fd5b8063570ca735116100fd578063570ca735146101ef5780635c9438801461020f57806360d2f33d1461024a578063757b4db01461027e5780637b91d36d146102ab5780637ecebe00146102cb57600080fd5b80632f8655681461013a5780633644e5151461015c57806337c9b7be146101845780633ae50b73146101af57806340b40940146101cf575b600080fd5b34801561014657600080fd5b5061015a61015536600461454e565b61049a565b005b34801561016857600080fd5b506101716105cb565b6040519081526020015b60405180910390f35b610197610192366004614684565b6106fb565b6040516001600160a01b03909116815260200161017b565b3480156101bb57600080fd5b5061015a6101ca366004614741565b610b3a565b3480156101db57600080fd5b5061015a6101ea3660046147be565b61107c565b3480156101fb57600080fd5b50600154610197906001600160a01b031681565b34801561021b57600080fd5b5060015461023490600160a01b900464ffffffffff1681565b60405164ffffffffff909116815260200161017b565b34801561025657600080fd5b506101717f0e8122b9966a5ace153720b4cfa9a4339fe04cf7270694b3ad4068a61436900b81565b34801561028a57600080fd5b5061029e61029936600461454e565b611384565b60405161017b9190614861565b3480156102b757600080fd5b5061015a6102c63660046148ce565b611417565b3480156102d757600080fd5b506101716102e636600461454e565b60026020526000908152604090205481565b61030b610306366004614914565b611522565b60405161017b929190614972565b61015a610327366004614a1d565b611ac4565b34801561033857600080fd5b5061034c610347366004614b2d565b612160565b6040805182516001600160601b039081168252602080850151909116908201529181015115159082015260600161017b565b34801561038a57600080fd5b5061015a61039936600461454e565b6121ea565b3480156103aa57600080fd5b506103be6103b936600461454e565b61249c565b6040805182516001600160601b03908116825260209384015116928101929092520161017b565b3480156103f157600080fd5b50610197610400366004614b5b565b612511565b34801561041157600080fd5b5061015a610420366004614be0565b612870565b34801561043157600080fd5b506101976129a3565b61015a610448366004614bfd565b612a17565b34801561045957600080fd5b5061046d61046836600461454e565b612eac565b60405161017b9190614cb1565b34801561048657600080fd5b5061015a610495366004614cfe565b612f14565b60015460405163bf40fac160e01b81526000916001600160a01b03169063bf40fac1906104c990600401614dc3565b602060405180830381865afa1580156104e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061050a9190614de2565b9050336001600160a01b0382161461053557604051637bfa4b9f60e01b815260040160405180910390fd5b816001600160a01b03166328a070256040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561057057600080fd5b505af1158015610584573d6000803e3d6000fd5b5050604051600681526001600160a01b03851692507ff00620e0b19d6d6f2ade4ed44f5ea58ad99158a95e6d8b8003b83a83ff09b721915060200160405180910390a25050565b6000306001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614801561062457507f000000000000000000000000000000000000000000000000000000000000000046145b1561064e57507f000000000000000000000000000000000000000000000000000000000000000090565b6106f6604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f0000000000000000000000000000000000000000000000000000000000000000918101919091527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b905090565b600061070561318e565b600089888660405160200161071c93929190614e4f565b60405160208183030381529060405290506107388185856131e7565b6001546040516360862d6960e01b81523360048201526001600160a01b039091169060009082906360862d6990602401602060405180830381865afa158015610785573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107a99190614de2565b90506000826001600160a01b031663bf40fac16040518163ffffffff1660e01b81526004016107d790614e80565b602060405180830381865afa1580156107f4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108189190614de2565b90506001600160a01b03821661089557604051639859387b60e01b81523360048201526001600160a01b03821690639859387b906024016020604051808303816000875af115801561086e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108929190614de2565b91505b5060007320eaed9ec336f9c1da92cc7e1c8a69d04926d946633e42e78d8e3386600160149054906101000a900464ffffffffff166040518563ffffffff1660e01b81526004016108e89493929190614e9b565b60a060405180830381865af4158015610905573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109299190614ed2565b80516040516367d28ec560e01b81529096509091506001600160a01b038616906367d28ec59061095d908490600401614861565b600060405180830381600087803b15801561097757600080fd5b505af115801561098b573d6000803e3d6000fd5b5050505080606001516001600160a01b0316856001600160a01b03168c7f1e19c550230ca6c5c32d1885c49330e81a79a3002c2ea87672384f8dfec9ff5d846020015185608001516040516109fc92919064ffffffffff9290921682526001600160601b0316602082015260400190565b60405180910390a45060006001600160601b038c1615610a2457610a2185848e6133b0565b90505b6000610a338b878c8c876136c8565b90506001600160601b038e16610a498284614f83565b6001600160601b03161115610a71576040516329db8ba960e01b815260040160405180910390fd5b604051638e50c08b60e01b81526001600160a01b03871690638e50c08b90610aa29086908590600190600401614faa565b600060405180830381600087803b158015610abc57600080fd5b505af1158015610ad0573d6000803e3d6000fd5b50506040516001600160601b03841681523392508291506001600160a01b038916907f4e27d0536502149219866575ceba882206512f58dea2412ddd6625a7c63d6c6c9060200160405180910390a45050505050610b2e6001600055565b98975050505050505050565b610b4261318e565b6001546040516360862d6960e01b81523360048201526000916001600160a01b0316906360862d6990602401602060405180830381865afa158015610b8b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610baf9190614de2565b90506000610bbc84611384565b90506000610bc98561249c565b90506000610bd78487612160565b60015460405163bf40fac160e01b81529192506000916001600160a01b039091169063bf40fac190610c0b90600401614fd6565b602060405180830381865afa158015610c28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c4c9190614de2565b6040516370a0823160e01b81526001600160a01b0387811660048301529192506000918316906370a0823190602401602060405180830381865afa158015610c98573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cbc9190615001565b90506000826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610cfe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d22919061501a565b610d2d90600a615121565b905080886001600160601b03161015610d5957604051639c55d34560e01b815260040160405180910390fd5b6001600160a01b038716610d805760405163587ec6ff60e11b815260040160405180910390fd5b876001600160601b0316821015610daa57604051631d00495b60e31b815260040160405180910390fd5b60608601516001600160a01b0316610dd55760405163e42ddc1d60e01b815260040160405180910390fd5b856020015164ffffffffff164264ffffffffff161115610e0857604051630fc3544960e41b815260040160405180910390fd5b600086604001516006811115610e2057610e20614829565b14610e3e57604051630ed2159360e11b815260040160405180910390fd5b85608001516001600160601b0316888660000151610e5c9190614f83565b6001600160601b03161115610e84576040516329db8ba960e01b815260040160405180910390fd5b83516001600160601b0316600003610efe57604051638e50c08b60e01b81526001600160a01b038a1690638e50c08b90610ec7908a908c90600190600401614faa565b600060405180830381600087803b158015610ee157600080fd5b505af1158015610ef5573d6000803e3d6000fd5b50505050610f62565b604051638e50c08b60e01b81526001600160a01b038a1690638e50c08b90610f2f908a908c90600090600401614faa565b600060405180830381600087803b158015610f4957600080fd5b505af1158015610f5d573d6000803e3d6000fd5b505050505b60008989604051602401610f77929190614972565b60408051601f198184030181529181526020820180516001600160e01b031663a9059cbb60e01b17905251631409412160e31b81529091506001600160a01b0389169063a04a090890610fd39087908590600090600401615130565b6000604051808303816000875af1158015610ff2573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261101a9190810190615164565b506040516001600160601b038a168152339081906001600160a01b038d16907f4e27d0536502149219866575ceba882206512f58dea2412ddd6625a7c63d6c6c9060200160405180910390a450505050505050506110786001600055565b5050565b60015460405163bf40fac160e01b81526000916001600160a01b03169063bf40fac1906110ab90600401614dc3565b602060405180830381865afa1580156110c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110ec9190614de2565b9050336001600160a01b0382161461111757604051637bfa4b9f60e01b815260040160405180910390fd5b60015460405163bf40fac160e01b81526000916001600160a01b03169063bf40fac190611146906004016151d1565b602060405180830381865afa158015611163573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111879190614de2565b905060005b8381101561137b5760008787838181106111a8576111a86151f4565b90506020020135905060008686848181106111c5576111c56151f4565b90506020028101906111d7919061520a565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052506040519495509361122393508692508591508490602401615250565b60408051601f198184030181529181526020820180516001600160e01b0316632053d50f60e21b179052519091506000906001600160a01b0387169061126a90849061527b565b6000604051808303816000865af19150503d80600081146112a7576040519150601f19603f3d011682016040523d82523d6000602084013e6112ac565b606091505b50509050806112d9578160405163a5fa8d2b60e01b81526004016112d09190615297565b60405180910390fd5b600061130f8a8a888181106112f0576112f06151f4565b9050602002810190611302919061520a565b5080359160209091013590565b50905083604051611320919061527b565b6040518091039020816001600160a01b03167f9645b00fbfff6323833c294cb14b155cf4bed69c59e6e90f8b37ef9572eda4f68760405161136391815260200190565b60405180910390a3856001019550505050505061118c565b50505050505050565b6040805160a081018252600080825260208201819052918101829052606081018290526080810191909152816001600160a01b031663a46bf4366040518163ffffffff1660e01b815260040160a060405180830381865afa1580156113ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114119190614ed2565b92915050565b60015460405163bf40fac160e01b81526000916001600160a01b03169063bf40fac19061144690600401614dc3565b602060405180830381865afa158015611463573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114879190614de2565b9050336001600160a01b038216146114b257604051637bfa4b9f60e01b815260040160405180910390fd5b604051631bb14aef60e21b8152841515600482015260248101849052604481018390526001600160a01b03861690636ec52bbc90606401600060405180830381600087803b15801561150357600080fd5b505af1158015611517573d6000803e3d6000fd5b505050505050505050565b60015460405163bf40fac160e01b8152600091829182916001600160a01b03169063bf40fac19061155590600401614dc3565b602060405180830381865afa158015611572573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115969190614de2565b9050336001600160a01b038216146115c157604051637bfa4b9f60e01b815260040160405180910390fd5b8535602087013560006115d383611384565b905060006115e08461249c565b9050826001600160601b031660000361160c57604051631f2a200560e01b815260040160405180910390fd5b600181600001516001600160601b0316101561163b57604051633df8562d60e01b815260040160405180910390fd5b60008260400151600681111561165357611653614829565b14158015611677575060018260400151600681111561167457611674614829565b14155b156116955760405163950b706f60e01b815260040160405180910390fd5b6040516304c60b5f60e11b815260ff8c16600482015273d70458ce942f4a4b911b3203591c1920c90070579063098c16be90602401602060405180830381865af41580156116e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061170b91906152aa565b156118c75760408a0135965087611835576040516001620f914d60e11b031981526001600160a01b03888116600483015285169063ffe0dd6690602401602060405180830381865afa158015611765573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061178991906152c7565b6040516352fbf01d60e01b81526001600160a01b0389811660048301526001600160601b0392909216918591908716906352fbf01d90602401602060405180830381865afa1580156117df573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061180391906152c7565b61180d9190614f83565b6001600160601b031611156118355760405163277f952d60e11b815260040160405180910390fd5b600154604051633b0e033d60e01b81527312be7395d46a024f7b82e2c6d8485498bde88bf391633b0e033d9161187f918f918f918f918f916001600160a01b03169060040161530d565b602060405180830381865af415801561189c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118c091906152c7565b9550611a05565b60015460405163bf40fac160e01b81526000916001600160a01b03169063bf40fac1906118f6906004016151d1565b602060405180830381865afa158015611913573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119379190614de2565b905060008c8c8c8c6040516024016119529493929190615349565b60408051601f198184030181529181526020820180516001600160e01b0316632053d50f60e21b179052519091506000906001600160a01b03841690349061199b90859061527b565b60006040518083038185875af1925050503d80600081146119d8576040519150601f19603f3d011682016040523d82523d6000602084013e6119dd565b606091505b5050905080611a01578160405163a5fa8d2b60e01b81526004016112d09190615297565b5050505b60405163dab81c6160e01b81526001600160a01b0385169063dab81c6190611a379086908b908b908e90600401615376565b600060405180830381600087803b158015611a5157600080fd5b505af1158015611a65573d6000803e3d6000fd5b50505050836001600160a01b03167f6a6307e4e0f9004c177d9be0a97e9d145952aebbfb7a2769cdfe10c3bd67847c84888e8e8e348f604051611aae97969594939291906153a9565b60405180910390a2505050505094509492505050565b60015460405163bf40fac160e01b81526000916001600160a01b03169063bf40fac190611af390600401614dc3565b602060405180830381865afa158015611b10573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b349190614de2565b9050336001600160a01b03821614611b5f57604051637bfa4b9f60e01b815260040160405180910390fd5b8551848114611b84576040516001621398b960e31b0319815260040160405180910390fd5b83518114611ba8576040516001621398b960e31b0319815260040160405180910390fd5b60008060005b838310156121545760008a8481518110611bca57611bca6151f4565b602002602001015190503660008b8b87818110611be957611be96151f4565b9050602002810190611bfb919061520a565b9150915060008a8781518110611c1357611c136151f4565b6020026020010151905060008a8881518110611c3157611c316151f4565b60200260200101519050600080611c4e8680359160209091013590565b915091506000611c5d83611384565b90506000611c6a8461249c565b9050826001600160601b0316600003611c9657604051631f2a200560e01b815260040160405180910390fd5b600181600001516001600160601b03161015611cc557604051633df8562d60e01b815260040160405180910390fd5b600082604001516006811115611cdd57611cdd614829565b14158015611d015750600182604001516006811115611cfe57611cfe614829565b14155b15611d1f5760405163950b706f60e01b815260040160405180910390fd5b6040516304c60b5f60e11b815260ff8a16600482015273d70458ce942f4a4b911b3203591c1920c90070579063098c16be90602401602060405180830381865af4158015611d71573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d9591906152aa565b15611f515760408801359a5084611ebf576040516001620f914d60e11b031981526001600160a01b038c8116600483015285169063ffe0dd6690602401602060405180830381865afa158015611def573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e1391906152c7565b6040516352fbf01d60e01b81526001600160a01b038d811660048301526001600160601b0392909216918591908716906352fbf01d90602401602060405180830381865afa158015611e69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e8d91906152c7565b611e979190614f83565b6001600160601b03161115611ebf5760405163277f952d60e11b815260040160405180910390fd5b600154604051633b0e033d60e01b81527312be7395d46a024f7b82e2c6d8485498bde88bf391633b0e033d91611f09918d918d918d918c916001600160a01b03169060040161530d565b602060405180830381865af4158015611f26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f4a91906152c7565b995061208f565b60015460405163bf40fac160e01b81526000916001600160a01b03169063bf40fac190611f80906004016151d1565b602060405180830381865afa158015611f9d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fc19190614de2565b905060008a8a8a89604051602401611fdc9493929190615349565b60408051601f198184030181529181526020820180516001600160e01b0316632053d50f60e21b179052519091506000906001600160a01b038416908a9061202590859061527b565b60006040518083038185875af1925050503d8060008114612062576040519150601f19603f3d011682016040523d82523d6000602084013e612067565b606091505b505090508061208b578160405163a5fa8d2b60e01b81526004016112d09190615297565b5050505b60405163dab81c6160e01b81526001600160a01b0385169063dab81c61906120c19086908f908f908b90600401615376565b600060405180830381600087803b1580156120db57600080fd5b505af11580156120ef573d6000803e3d6000fd5b50505050836001600160a01b03167f6a6307e4e0f9004c177d9be0a97e9d145952aebbfb7a2769cdfe10c3bd67847c848c8c8c8c8c8c60405161213897969594939291906153a9565b60405180910390a28b6001019b50505050505050505050611bae565b50505050505050505050565b604080516060810182526000808252602082018190528183015290516336f2eb2960e21b81526001600160a01b03848116600483015283169063dbcbaca490602401606060405180830381865afa1580156121bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121e391906153f7565b9392505050565b60006121f582611384565b905060006122028361249c565b60015460405163bf40fac160e01b81529192506000916001600160a01b039091169063bf40fac19061223690600401614dc3565b602060405180830381865afa158015612253573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122779190614de2565b905060008360400151600681111561229157612291614829565b146122af57604051630ed2159360e11b815260040160405180910390fd5b6001600160a01b038116330361239457826020015164ffffffffff164264ffffffffff16116122f157604051638a8e7bf960e01b815260040160405180910390fd5b81516001600160601b031660000361236757604051630b3af7f960e01b81526001600160a01b03851690630b3af7f99061233090600290600401615468565b600060405180830381600087803b15801561234a57600080fd5b505af115801561235e573d6000803e3d6000fd5b505050506123ed565b604051630b3af7f960e01b81526001600160a01b03851690630b3af7f99061233090600390600401615468565b60608301516001600160a01b031633036123d457604051630b3af7f960e01b81526001600160a01b03851690630b3af7f990612330906004908101615468565b60405163160d3af160e11b815260040160405180910390fd5b836001600160a01b031663ea8a1af06040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561242857600080fd5b505af115801561243c573d6000803e3d6000fd5b50505050836001600160a01b03167fcd8e02743d921fb9bca767936271b8b93911716c78c1d46c2c6ee6189309d30c8460400151600681111561248157612481614829565b60405160ff909116815260200160405180910390a250505050565b6040805180820190915260008082526020820152816001600160a01b03166323ccc2876040518163ffffffff1660e01b81526004016040805180830381865afa1580156124ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114119190615476565b6000856001600160601b0316856001600160601b031611156125455760405162a80fb560e51b815260040160405180910390fd5b604080516001600160601b0388166020820152808201869052815180820383018152606090910190915261257a8185856131e7565b6001546040516360862d6960e01b81523360048201526001600160a01b039091169060009082906360862d6990602401602060405180830381865afa1580156125c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125eb9190614de2565b90506000826001600160a01b031663bf40fac16040518163ffffffff1660e01b815260040161261990614e80565b602060405180830381865afa158015612636573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061265a9190614de2565b90506001600160a01b0382166126d657604051639859387b60e01b81523360048201526001600160a01b03821690639859387b906024016020604051808303816000875af11580156126b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126d49190614de2565b505b600154604051633e42e78d60e01b81526000917320eaed9ec336f9c1da92cc7e1c8a69d04926d94691633e42e78d91612726918f9133918a91600160a01b900464ffffffffff1690600401614e9b565b60a060405180830381865af4158015612743573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127679190614ed2565b80516040516367d28ec560e01b81529097509091506001600160a01b038716906367d28ec59061279b908490600401614861565b600060405180830381600087803b1580156127b557600080fd5b505af11580156127c9573d6000803e3d6000fd5b5050505080606001516001600160a01b031681600001516001600160a01b03168a7f1e19c550230ca6c5c32d1885c49330e81a79a3002c2ea87672384f8dfec9ff5d8460200151856080015160405161283e92919064ffffffffff9290921682526001600160601b0316602082015260400190565b60405180910390a46001600160601b038a16156128625761286086858c6133b0565b505b505050505095945050505050565b60015460405163bf40fac160e01b815260206004820152600560248201526427aba722a960d91b60448201526000916001600160a01b03169063bf40fac190606401602060405180830381865afa1580156128cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128f39190614de2565b9050336001600160a01b0382161461291e576040516330cd747160e01b815260040160405180910390fd5b8164ffffffffff1660000361294657604051631f2a200560e01b815260040160405180910390fd5b6001805464ffffffffff60a01b1916600160a01b64ffffffffff8516908102919091179091556040519081527feeecb329e59d8e925b3142c110f5fadf78bd09ad1c3ddf1fe54edcf44f291d349060200160405180910390a15050565b60015460405163bf40fac160e01b815260009182916001600160a01b039091169063bf40fac1906129d690600401614e80565b602060405180830381865afa1580156129f3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114119190614de2565b612a1f61318e565b612a2a8383836131e7565b6001546040516360862d6960e01b81526001600160a01b03898116600483015260009216906360862d6990602401602060405180830381865afa158015612a75573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a999190614de2565b60015460405163bf40fac160e01b81529192506000916001600160a01b039091169063bf40fac190612acd90600401614e80565b602060405180830381865afa158015612aea573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b0e9190614de2565b90506001600160a01b038216612b8d57604051639859387b60e01b81526001600160a01b038a81166004830152821690639859387b906024016020604051808303816000875af1158015612b66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b8a9190614de2565b91505b6000612b9889611384565b90506000612ba58a61249c565b90506000612bb3858c612160565b90506001600160a01b038916612bf057896001600160601b03163414612beb5760405162a80fb560e51b815260040160405180910390fd5b612c89565b6040516370a0823160e01b81523360048201526000906001600160a01b038b16906370a0823190602401602060405180830381865afa158015612c37573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c5b9190615001565b9050808b6001600160601b03161115612c8757604051631d00495b60e31b815260040160405180910390fd5b505b60608301516001600160a01b0316612cb45760405163e42ddc1d60e01b815260040160405180910390fd5b826020015164ffffffffff164264ffffffffff161115612ce757604051630fc3544960e41b815260040160405180910390fd5b600083604001516006811115612cff57612cff614829565b14612d1d57604051630ed2159360e11b815260040160405180910390fd5b612d2a898c8c8b896136c8565b995082608001516001600160601b03168a8360000151612d4a9190614f83565b6001600160601b03161115612d72576040516329db8ba960e01b815260040160405180910390fd5b80516001600160601b0316600003612dec57604051638e50c08b60e01b81526001600160a01b038c1690638e50c08b90612db59088908e90600190600401614faa565b600060405180830381600087803b158015612dcf57600080fd5b505af1158015612de3573d6000803e3d6000fd5b50505050612e50565b604051638e50c08b60e01b81526001600160a01b038c1690638e50c08b90612e1d9088908e90600090600401614faa565b600060405180830381600087803b158015612e3757600080fd5b505af1158015612e4b573d6000803e3d6000fd5b505050505b6040516001600160601b038b1681526001600160a01b03808e169133918e16907f4e27d0536502149219866575ceba882206512f58dea2412ddd6625a7c63d6c6c9060200160405180910390a4505050505061137b6001600055565b6060816001600160a01b031663b2f5a54c6040518163ffffffff1660e01b8152600401600060405180830381865afa158015612eec573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261141191908101906154d4565b60015460405163bf40fac160e01b81526000916001600160a01b03169063bf40fac190612f4390600401614dc3565b602060405180830381865afa158015612f60573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f849190614de2565b9050336001600160a01b03821614612faf57604051637bfa4b9f60e01b815260040160405180910390fd5b886000612fbb8c611384565b9050600181604001516006811115612fd557612fd5614829565b14612ff35760405163fd16aabb60e01b815260040160405180910390fd5b5060008060007312be7395d46a024f7b82e2c6d8485498bde88bf3639900a35a8f868f8f8f8f8f8f8f600160009054906101000a90046001600160a01b03166040518b63ffffffff1660e01b81526004016130579a999897969594939291906155f3565b606060405180830381865af4158015613074573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061309891906156a9565b604051630922a48560e01b81526001600160601b03808516600483015280841660248301528216604482015292955090935091506001600160a01b038f1690630922a48590606401600060405180830381600087803b1580156130fa57600080fd5b505af115801561310e573d6000803e3d6000fd5b505050508d6001600160a01b03167f5cd97a0c3ff270ca4d2af5c4999843547ed0b876a26e9f249170d363f1b59a638484848860405161317694939291906001600160601b039485168152928416602084015292166040820152606081019190915260800190565b60405180910390a25050505050505050505050505050565b6002600054036131e05760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016112d0565b6002600055565b825160208085019190912033600081815260029093526040832080547f0e8122b9966a5ace153720b4cfa9a4339fe04cf7270694b3ad4068a61436900b93929185613231836156f6565b909155506040805160208101959095528401929092526001600160a01b03166060830152608082015260a00160405160208183030381529060405280519060200120905060006132c36132826105cb565b8360405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b905060006133078286868080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250613d9a92505050565b60015460405163bf40fac160e01b81529192506000916001600160a01b039091169063bf40fac19061333b90600401614dc3565b602060405180830381865afa158015613358573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061337c9190614de2565b9050806001600160a01b0316826001600160a01b03161461137b57604051637bfa4b9f60e01b815260040160405180910390fd5b600080836001600160a01b031663bf40fac16040518163ffffffff1660e01b81526004016133dd90614fd6565b602060405180830381865afa1580156133fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061341e9190614de2565b604051634fb33bdd60e01b81523360048201529091506000906001600160a01b03861690634fb33bdd90602401600060405180830381865afa158015613468573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261349091908101906154d4565b90506000806134a18387868a613dbe565b9150915060005b82518110156136bc576000808483815181106134c6576134c66151f4565b60200260200101518060200190518101906134e1919061570f565b90925090506000670de0b6b3a7640000613504866001600160601b03851661573e565b61350e9190615755565b90506001600160601b038116156136ae57613529818a614f83565b604051638e50c08b60e01b81529099506001600160a01b038d1690638e50c08b9061355d9086908590600190600401614faa565b600060405180830381600087803b15801561357757600080fd5b505af115801561358b573d6000803e3d6000fd5b5050505060008c826040516024016135a4929190614972565b60408051601f198184030181529181526020820180516001600160e01b031663a9059cbb60e01b17905251631409412160e31b81529091506001600160a01b0385169063a04a090890613600908c908590600090600401615130565b6000604051808303816000875af115801561361f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526136479190810190615164565b50836001600160a01b0316336001600160a01b03168e6001600160a01b03167f6150be318f9a74709ffa8e4c220eee68a5939284c67ec84222af648b3c58de70856040516136a491906001600160601b0391909116815260200190565b60405180910390a4505b8360010193505050506134a8565b50505050509392505050565b60015460405163bf40fac160e01b815260009182916001600160a01b039091169063bf40fac1906136fb90600401614fd6565b602060405180830381865afa158015613718573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061373c9190614de2565b9050806001600160a01b0316876001600160a01b031614613b0457835160000361377957604051632e47553f60e21b815260040160405180910390fd5b60015460405163bf40fac160e01b815260206004820152600d60248201526c27a722a4a721a42927aaaa22a960991b60448201526000916001600160a01b03169063bf40fac190606401602060405180830381865afa1580156137e0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138049190614de2565b90506001600160a01b038816156138e9576138336001600160a01b03891633896001600160601b038a1661401f565b600063095ea7b360e01b8288604051602401613850929190614972565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051631409412160e31b81529091506001600160a01b0389169063a04a0908906138b5908c908590600090600401615130565b600060405180830381600087803b1580156138cf57600080fd5b505af11580156138e3573d6000803e3d6000fd5b50505050505b6040516370a0823160e01b81526001600160a01b038881166004830152600091908416906370a0823190602401602060405180830381865afa158015613933573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139579190615001565b9050876001600160a01b031663a04a0908348489346040518563ffffffff1660e01b815260040161398a93929190615130565b6000604051808303818588803b1580156139a357600080fd5b505af11580156139b7573d6000803e3d6000fd5b50506040516370a0823160e01b81526001600160a01b038c8116600483015260009450871692506370a082319150602401602060405180830381865afa158015613a05573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a299190615001565b9050818111613a4b57604051631d00495b60e31b815260040160405180910390fd5b613a558282615777565b94506001600160a01b038a1615801590613adf5750604051636eb1769f60e11b81526001600160a01b038a8116600483015284811660248301528b169063dd62ed3e90604401602060405180830381865afa158015613ab8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613adc9190615001565b15155b15613afc5760405162a80fb560e51b815260040160405180910390fd5b505050613cfd565b835115613b2457604051632e47553f60e21b815260040160405180910390fd5b6040516370a0823160e01b81526001600160a01b038481166004830152600091908316906370a0823190602401602060405180830381865afa158015613b6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b929190615001565b9050856001600160601b0316816001600160601b031610613c6c5760008787604051602401613bc2929190614972565b60408051601f198184030181529181526020820180516001600160e01b031663a9059cbb60e01b17905251631409412160e31b81529091506001600160a01b0386169063a04a090890613c1e9086908590600090600401615130565b6000604051808303816000875af1158015613c3d573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052613c659190810190615164565b5050613cef565b6040516323b872dd60e01b81523360048201526001600160a01b0388811660248301526001600160601b03881660448301528316906323b872dd906064016020604051808303816000875af1158015613cc9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ced91906152aa565b505b856001600160601b03169250505b6000816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613d3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d61919061501a565b613d6c90600a615121565b905080831015613d8f57604051639c55d34560e01b815260040160405180910390fd5b505095945050505050565b6000806000613da9858561407f565b91509150613db6816140c4565b509392505050565b6060600080600080600089516001600160401b03811115613de157613de1614580565b604051908082528060200260200182016040528015613e1457816020015b6060815260200190600190039081613dff5790505b5090505b8951831015613fbc5760008a8481518110613e3557613e356151f4565b6020908102919091010151604051632c78933160e01b81523360048201526001600160a01b0380831660248301529192506000918a1690632c78933190604401602060405180830381865afa158015613e92573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613eb691906152c7565b6040516370a0823160e01b81526001600160a01b0384811660048301529192506000918c16906370a0823190602401602060405180830381865afa158015613f02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f269190615001565b90506000826001600160601b0316826001600160601b031610613f495782613f4b565b815b604080516001600160a01b03871660208201526001600160601b03929092169082018190529150606001604051602081830303815290604052858881518110613f9657613f966151f4565b6020908102919091010152613fab818961578a565b975086600101965050505050613e18565b831561400f57600084613fe06001600160601b038c16670de0b6b3a764000061573e565b613fea9190615755565b9050670de0b6b3a7640000811061400957670de0b6b3a764000061400b565b805b9250505b9450925050505b94509492505050565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052614079908590614211565b50505050565b60008082516041036140b55760208301516040840151606085015160001a6140a9878285856142e8565b945094505050506140bd565b506000905060025b9250929050565b60008160048111156140d8576140d8614829565b036140e05750565b60018160048111156140f4576140f4614829565b036141415760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e6174757265000000000000000060448201526064016112d0565b600281600481111561415557614155614829565b036141a25760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e6774680060448201526064016112d0565b60038160048111156141b6576141b6614829565b0361420e5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b60648201526084016112d0565b50565b6000614266826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166143a99092919063ffffffff16565b8051909150156142e3578080602001905181019061428491906152aa565b6142e35760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016112d0565b505050565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a083111561431f5750600090506003614016565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015614373573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661439c57600060019250925050614016565b9660009650945050505050565b60606143b884846000856143c0565b949350505050565b6060824710156144215760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016112d0565b600080866001600160a01b0316858760405161443d919061527b565b60006040518083038185875af1925050503d806000811461447a576040519150601f19603f3d011682016040523d82523d6000602084013e61447f565b606091505b50915091506144908783838761449b565b979650505050505050565b6060831561450a578251600003614503576001600160a01b0385163b6145035760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016112d0565b50816143b8565b6143b8838381511561451f5781518083602001fd5b8060405162461bcd60e51b81526004016112d09190615297565b6001600160a01b038116811461420e57600080fd5b60006020828403121561456057600080fd5b81356121e381614539565b6001600160601b038116811461420e57600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156145be576145be614580565b604052919050565b60006001600160401b038211156145df576145df614580565b50601f01601f191660200190565b600082601f8301126145fe57600080fd5b813561461161460c826145c6565b614596565b81815284602083860101111561462657600080fd5b816020850160208301376000918101602001919091529392505050565b60008083601f84011261465557600080fd5b5081356001600160401b0381111561466c57600080fd5b6020830191508360208285010111156140bd57600080fd5b60008060008060008060008060e0898b0312156146a057600080fd5b88356146ab8161456b565b975060208901356146bb8161456b565b96506040890135955060608901356146d281614539565b945060808901356146e28161456b565b935060a08901356001600160401b03808211156146fe57600080fd5b61470a8c838d016145ed565b945060c08b013591508082111561472057600080fd5b5061472d8b828c01614643565b999c989b5096995094979396929594505050565b6000806040838503121561475457600080fd5b823561475f81614539565b9150602083013561476f8161456b565b809150509250929050565b60008083601f84011261478c57600080fd5b5081356001600160401b038111156147a357600080fd5b6020830191508360208260051b85010111156140bd57600080fd5b600080600080604085870312156147d457600080fd5b84356001600160401b03808211156147eb57600080fd5b6147f78883890161477a565b9096509450602087013591508082111561481057600080fd5b5061481d8782880161477a565b95989497509550505050565b634e487b7160e01b600052602160045260246000fd5b6007811061485d57634e487b7160e01b600052602160045260246000fd5b9052565b81516001600160a01b03908116825260208084015164ffffffffff169083015260408084015160a0840192916148999085018261483f565b50806060850151166060840152506001600160601b03608084015116608083015292915050565b801515811461420e57600080fd5b600080600080608085870312156148e457600080fd5b84356148ef81614539565b935060208501356148ff816148c0565b93969395505050506040820135916060013590565b6000806000806060858703121561492a57600080fd5b8435935060208501356001600160401b0381111561494757600080fd5b61495387828801614643565b9094509250506040850135614967816148c0565b939692955090935050565b6001600160a01b039290921682526001600160601b0316602082015260400190565b60006001600160401b038211156149ad576149ad614580565b5060051b60200190565b600082601f8301126149c857600080fd5b813560206149d861460c83614994565b82815260059290921b840181019181810190868411156149f757600080fd5b8286015b84811015614a1257803583529183019183016149fb565b509695505050505050565b600080600080600060808688031215614a3557600080fd5b85356001600160401b0380821115614a4c57600080fd5b614a5889838a016149b7565b9650602091508188013581811115614a6f57600080fd5b614a7b8a828b0161477a565b909750955050604088013581811115614a9357600080fd5b614a9f8a828b016149b7565b945050606088013581811115614ab457600080fd5b88019050601f81018913614ac757600080fd5b8035614ad561460c82614994565b81815260059190911b8201830190838101908b831115614af457600080fd5b928401925b82841015614b1b578335614b0c816148c0565b82529284019290840190614af9565b80955050505050509295509295909350565b60008060408385031215614b4057600080fd5b8235614b4b81614539565b9150602083013561476f81614539565b600080600080600060808688031215614b7357600080fd5b8535614b7e8161456b565b94506020860135614b8e8161456b565b93506040860135925060608601356001600160401b03811115614bb057600080fd5b614bbc88828901614643565b969995985093965092949392505050565b64ffffffffff8116811461420e57600080fd5b600060208284031215614bf257600080fd5b81356121e381614bcd565b600080600080600080600060c0888a031215614c1857600080fd5b8735614c2381614539565b96506020880135614c3381614539565b95506040880135614c438161456b565b94506060880135614c5381614539565b935060808801356001600160401b0380821115614c6f57600080fd5b614c7b8b838c016145ed565b945060a08a0135915080821115614c9157600080fd5b50614c9e8a828b01614643565b989b979a50959850939692959293505050565b6020808252825182820181905260009190848201906040850190845b81811015614cf25783516001600160a01b031683529284019291840191600101614ccd565b50909695505050505050565b600080600080600080600080600060e08a8c031215614d1c57600080fd5b8935614d2781614539565b985060208a0135975060408a0135614d3e8161456b565b965060608a0135614d4e8161456b565b955060808a0135614d5e8161456b565b945060a08a01356001600160401b0380821115614d7a57600080fd5b614d868d838e0161477a565b909650945060c08c0135915080821115614d9f57600080fd5b50614dac8c828d0161477a565b915080935050809150509295985092959850929598565b60208082526005908201526420a226a4a760d91b604082015260600190565b600060208284031215614df457600080fd5b81516121e381614539565b60005b83811015614e1a578181015183820152602001614e02565b50506000910152565b60008151808452614e3b816020860160208601614dff565b601f01601f19169290920160200192915050565b6001600160601b0384168152826020820152606060408201526000614e776060830184614e23565b95945050505050565b6020808252600190820152605160f81b604082015260600190565b6001600160601b039490941684526001600160a01b0392831660208501529116604083015264ffffffffff16606082015260800190565b600060a08284031215614ee457600080fd5b60405160a081018181106001600160401b0382111715614f0657614f06614580565b6040528251614f1481614539565b81526020830151614f2481614bcd565b6020820152604083015160078110614f3b57600080fd5b60408201526060830151614f4e81614539565b60608201526080830151614f618161456b565b60808201529392505050565b634e487b7160e01b600052601160045260246000fd5b6001600160601b03818116838216019080821115614fa357614fa3614f6d565b5092915050565b6001600160a01b039390931683526001600160601b039190911660208301521515604082015260600190565b6020808252601190820152702222a320aaa62a29aa20a12622a1a7a4a760791b604082015260600190565b60006020828403121561501357600080fd5b5051919050565b60006020828403121561502c57600080fd5b815160ff811681146121e357600080fd5b600181815b8085111561507857816000190482111561505e5761505e614f6d565b8085161561506b57918102915b93841c9390800290615042565b509250929050565b60008261508f57506001611411565b8161509c57506000611411565b81600181146150b257600281146150bc576150d8565b6001915050611411565b60ff8411156150cd576150cd614f6d565b50506001821b611411565b5060208310610133831016604e8410600b84101617156150fb575081810a611411565b615105838361503d565b806000190482111561511957615119614f6d565b029392505050565b60006121e360ff841683615080565b6001600160a01b038416815260606020820181905260009061515490830185614e23565b9050826040830152949350505050565b60006020828403121561517657600080fd5b81516001600160401b0381111561518c57600080fd5b8201601f8101841361519d57600080fd5b80516151ab61460c826145c6565b8181528560208385010111156151c057600080fd5b614e77826020830160208601614dff565b60208082526009908201526850455250545241444560b81b604082015260600190565b634e487b7160e01b600052603260045260246000fd5b6000808335601e1984360301811261522157600080fd5b8301803591506001600160401b0382111561523b57600080fd5b6020019150368190038213156140bd57600080fd5b8381526060602082015260006152696060830185614e23565b90508215156040830152949350505050565b6000825161528d818460208701614dff565b9190910192915050565b6020815260006121e36020830184614e23565b6000602082840312156152bc57600080fd5b81516121e3816148c0565b6000602082840312156152d957600080fd5b81516121e38161456b565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b8581526080602082015260006153276080830186886152e4565b9315156040830152506001600160a01b03919091166060909101529392505050565b8481526060602082015260006153636060830185876152e4565b9050821515604083015295945050505050565b6001600160601b0394851681526001600160a01b0393909316602084015292166040820152901515606082015260800190565b60006001600160601b03808a16835280891660208401525086604083015260c060608301526153dc60c0830186886152e4565b60808301949094525090151560a09091015295945050505050565b60006060828403121561540957600080fd5b604051606081018181106001600160401b038211171561542b5761542b614580565b60405282516154398161456b565b815260208301516154498161456b565b6020820152604083015161545c816148c0565b60408201529392505050565b60208101611411828461483f565b60006040828403121561548857600080fd5b604051604081018181106001600160401b03821117156154aa576154aa614580565b60405282516154b88161456b565b815260208301516154c88161456b565b60208201529392505050565b600060208083850312156154e757600080fd5b82516001600160401b038111156154fd57600080fd5b8301601f8101851361550e57600080fd5b805161551c61460c82614994565b81815260059190911b8201830190838101908783111561553b57600080fd5b928401925b8284101561449057835161555381614539565b82529284019290840190615540565b81835260006020808501808196508560051b810191508460005b878110156155e65782840389528135601e1988360301811261559d57600080fd5b870185810190356001600160401b038111156155b857600080fd5b8036038213156155c757600080fd5b6155d28682846152e4565b9a87019a955050509084019060010161557c565b5091979650505050505050565b6001600160a01b038b8116825260208083018c90526001600160601b038b811660408501528a811660608501528916608084015261010060a084018190528301879052600091610120840191899190845b8a81101561566b57833561565781614539565b831685529381019392810192600101615644565b5050505082810360c0840152615682818688615562565b91505061569a60e08301846001600160a01b03169052565b9b9a5050505050505050505050565b6000806000606084860312156156be57600080fd5b83516156c98161456b565b60208501519093506156da8161456b565b60408501519092506156eb8161456b565b809150509250925092565b60006001820161570857615708614f6d565b5060010190565b6000806040838503121561572257600080fd5b825161572d81614539565b602084015190925061476f8161456b565b808202811582820484141761141157611411614f6d565b60008261577257634e487b7160e01b600052601260045260246000fd5b500490565b8181038181111561141157611411614f6d565b8082018082111561141157611411614f6d56fea26469706673582212207459ecebbd433ab629026001bddb8b993518a054daf8313e9b539ff2659ca1dd64736f6c63430008130033000000000000000000000000e52625d111cdbafcc1bc1e97380eb0e22fea06990000000000000000000000000000000000000000000000000000000000093a80
Deployed Bytecode
0x6080604052600436106101355760003560e01c8063814f543c116100ab578063dad8be5b1161006f578063dad8be5b146103e5578063e34c333314610405578063e8e4197a14610425578063e98285e91461043a578063ec259c891461044d578063fe75ede31461047a57600080fd5b8063814f543c146102f8578063865f694b14610319578063a74865b21461032c578063ac156ddb1461037e578063acd560b11461039e57600080fd5b8063570ca735116100fd578063570ca735146101ef5780635c9438801461020f57806360d2f33d1461024a578063757b4db01461027e5780637b91d36d146102ab5780637ecebe00146102cb57600080fd5b80632f8655681461013a5780633644e5151461015c57806337c9b7be146101845780633ae50b73146101af57806340b40940146101cf575b600080fd5b34801561014657600080fd5b5061015a61015536600461454e565b61049a565b005b34801561016857600080fd5b506101716105cb565b6040519081526020015b60405180910390f35b610197610192366004614684565b6106fb565b6040516001600160a01b03909116815260200161017b565b3480156101bb57600080fd5b5061015a6101ca366004614741565b610b3a565b3480156101db57600080fd5b5061015a6101ea3660046147be565b61107c565b3480156101fb57600080fd5b50600154610197906001600160a01b031681565b34801561021b57600080fd5b5060015461023490600160a01b900464ffffffffff1681565b60405164ffffffffff909116815260200161017b565b34801561025657600080fd5b506101717f0e8122b9966a5ace153720b4cfa9a4339fe04cf7270694b3ad4068a61436900b81565b34801561028a57600080fd5b5061029e61029936600461454e565b611384565b60405161017b9190614861565b3480156102b757600080fd5b5061015a6102c63660046148ce565b611417565b3480156102d757600080fd5b506101716102e636600461454e565b60026020526000908152604090205481565b61030b610306366004614914565b611522565b60405161017b929190614972565b61015a610327366004614a1d565b611ac4565b34801561033857600080fd5b5061034c610347366004614b2d565b612160565b6040805182516001600160601b039081168252602080850151909116908201529181015115159082015260600161017b565b34801561038a57600080fd5b5061015a61039936600461454e565b6121ea565b3480156103aa57600080fd5b506103be6103b936600461454e565b61249c565b6040805182516001600160601b03908116825260209384015116928101929092520161017b565b3480156103f157600080fd5b50610197610400366004614b5b565b612511565b34801561041157600080fd5b5061015a610420366004614be0565b612870565b34801561043157600080fd5b506101976129a3565b61015a610448366004614bfd565b612a17565b34801561045957600080fd5b5061046d61046836600461454e565b612eac565b60405161017b9190614cb1565b34801561048657600080fd5b5061015a610495366004614cfe565b612f14565b60015460405163bf40fac160e01b81526000916001600160a01b03169063bf40fac1906104c990600401614dc3565b602060405180830381865afa1580156104e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061050a9190614de2565b9050336001600160a01b0382161461053557604051637bfa4b9f60e01b815260040160405180910390fd5b816001600160a01b03166328a070256040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561057057600080fd5b505af1158015610584573d6000803e3d6000fd5b5050604051600681526001600160a01b03851692507ff00620e0b19d6d6f2ade4ed44f5ea58ad99158a95e6d8b8003b83a83ff09b721915060200160405180910390a25050565b6000306001600160a01b037f00000000000000000000000056afa0771b6e1e0a33bf050f029ffe49c00f1bb91614801561062457507f000000000000000000000000000000000000000000000000000000000000a4b146145b1561064e57507f1ccd21e0a68e5a73ca9f5931e25c66c538414fda3237d42c0b8fff432e9b656a90565b6106f6604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f23c14fceac7676b670aa56866076586ea1ce15ddcf19208ec6346cf748dffbee918101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b905090565b600061070561318e565b600089888660405160200161071c93929190614e4f565b60405160208183030381529060405290506107388185856131e7565b6001546040516360862d6960e01b81523360048201526001600160a01b039091169060009082906360862d6990602401602060405180830381865afa158015610785573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107a99190614de2565b90506000826001600160a01b031663bf40fac16040518163ffffffff1660e01b81526004016107d790614e80565b602060405180830381865afa1580156107f4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108189190614de2565b90506001600160a01b03821661089557604051639859387b60e01b81523360048201526001600160a01b03821690639859387b906024016020604051808303816000875af115801561086e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108929190614de2565b91505b5060007320eaed9ec336f9c1da92cc7e1c8a69d04926d946633e42e78d8e3386600160149054906101000a900464ffffffffff166040518563ffffffff1660e01b81526004016108e89493929190614e9b565b60a060405180830381865af4158015610905573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109299190614ed2565b80516040516367d28ec560e01b81529096509091506001600160a01b038616906367d28ec59061095d908490600401614861565b600060405180830381600087803b15801561097757600080fd5b505af115801561098b573d6000803e3d6000fd5b5050505080606001516001600160a01b0316856001600160a01b03168c7f1e19c550230ca6c5c32d1885c49330e81a79a3002c2ea87672384f8dfec9ff5d846020015185608001516040516109fc92919064ffffffffff9290921682526001600160601b0316602082015260400190565b60405180910390a45060006001600160601b038c1615610a2457610a2185848e6133b0565b90505b6000610a338b878c8c876136c8565b90506001600160601b038e16610a498284614f83565b6001600160601b03161115610a71576040516329db8ba960e01b815260040160405180910390fd5b604051638e50c08b60e01b81526001600160a01b03871690638e50c08b90610aa29086908590600190600401614faa565b600060405180830381600087803b158015610abc57600080fd5b505af1158015610ad0573d6000803e3d6000fd5b50506040516001600160601b03841681523392508291506001600160a01b038916907f4e27d0536502149219866575ceba882206512f58dea2412ddd6625a7c63d6c6c9060200160405180910390a45050505050610b2e6001600055565b98975050505050505050565b610b4261318e565b6001546040516360862d6960e01b81523360048201526000916001600160a01b0316906360862d6990602401602060405180830381865afa158015610b8b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610baf9190614de2565b90506000610bbc84611384565b90506000610bc98561249c565b90506000610bd78487612160565b60015460405163bf40fac160e01b81529192506000916001600160a01b039091169063bf40fac190610c0b90600401614fd6565b602060405180830381865afa158015610c28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c4c9190614de2565b6040516370a0823160e01b81526001600160a01b0387811660048301529192506000918316906370a0823190602401602060405180830381865afa158015610c98573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cbc9190615001565b90506000826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610cfe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d22919061501a565b610d2d90600a615121565b905080886001600160601b03161015610d5957604051639c55d34560e01b815260040160405180910390fd5b6001600160a01b038716610d805760405163587ec6ff60e11b815260040160405180910390fd5b876001600160601b0316821015610daa57604051631d00495b60e31b815260040160405180910390fd5b60608601516001600160a01b0316610dd55760405163e42ddc1d60e01b815260040160405180910390fd5b856020015164ffffffffff164264ffffffffff161115610e0857604051630fc3544960e41b815260040160405180910390fd5b600086604001516006811115610e2057610e20614829565b14610e3e57604051630ed2159360e11b815260040160405180910390fd5b85608001516001600160601b0316888660000151610e5c9190614f83565b6001600160601b03161115610e84576040516329db8ba960e01b815260040160405180910390fd5b83516001600160601b0316600003610efe57604051638e50c08b60e01b81526001600160a01b038a1690638e50c08b90610ec7908a908c90600190600401614faa565b600060405180830381600087803b158015610ee157600080fd5b505af1158015610ef5573d6000803e3d6000fd5b50505050610f62565b604051638e50c08b60e01b81526001600160a01b038a1690638e50c08b90610f2f908a908c90600090600401614faa565b600060405180830381600087803b158015610f4957600080fd5b505af1158015610f5d573d6000803e3d6000fd5b505050505b60008989604051602401610f77929190614972565b60408051601f198184030181529181526020820180516001600160e01b031663a9059cbb60e01b17905251631409412160e31b81529091506001600160a01b0389169063a04a090890610fd39087908590600090600401615130565b6000604051808303816000875af1158015610ff2573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261101a9190810190615164565b506040516001600160601b038a168152339081906001600160a01b038d16907f4e27d0536502149219866575ceba882206512f58dea2412ddd6625a7c63d6c6c9060200160405180910390a450505050505050506110786001600055565b5050565b60015460405163bf40fac160e01b81526000916001600160a01b03169063bf40fac1906110ab90600401614dc3565b602060405180830381865afa1580156110c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110ec9190614de2565b9050336001600160a01b0382161461111757604051637bfa4b9f60e01b815260040160405180910390fd5b60015460405163bf40fac160e01b81526000916001600160a01b03169063bf40fac190611146906004016151d1565b602060405180830381865afa158015611163573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111879190614de2565b905060005b8381101561137b5760008787838181106111a8576111a86151f4565b90506020020135905060008686848181106111c5576111c56151f4565b90506020028101906111d7919061520a565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052506040519495509361122393508692508591508490602401615250565b60408051601f198184030181529181526020820180516001600160e01b0316632053d50f60e21b179052519091506000906001600160a01b0387169061126a90849061527b565b6000604051808303816000865af19150503d80600081146112a7576040519150601f19603f3d011682016040523d82523d6000602084013e6112ac565b606091505b50509050806112d9578160405163a5fa8d2b60e01b81526004016112d09190615297565b60405180910390fd5b600061130f8a8a888181106112f0576112f06151f4565b9050602002810190611302919061520a565b5080359160209091013590565b50905083604051611320919061527b565b6040518091039020816001600160a01b03167f9645b00fbfff6323833c294cb14b155cf4bed69c59e6e90f8b37ef9572eda4f68760405161136391815260200190565b60405180910390a3856001019550505050505061118c565b50505050505050565b6040805160a081018252600080825260208201819052918101829052606081018290526080810191909152816001600160a01b031663a46bf4366040518163ffffffff1660e01b815260040160a060405180830381865afa1580156113ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114119190614ed2565b92915050565b60015460405163bf40fac160e01b81526000916001600160a01b03169063bf40fac19061144690600401614dc3565b602060405180830381865afa158015611463573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114879190614de2565b9050336001600160a01b038216146114b257604051637bfa4b9f60e01b815260040160405180910390fd5b604051631bb14aef60e21b8152841515600482015260248101849052604481018390526001600160a01b03861690636ec52bbc90606401600060405180830381600087803b15801561150357600080fd5b505af1158015611517573d6000803e3d6000fd5b505050505050505050565b60015460405163bf40fac160e01b8152600091829182916001600160a01b03169063bf40fac19061155590600401614dc3565b602060405180830381865afa158015611572573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115969190614de2565b9050336001600160a01b038216146115c157604051637bfa4b9f60e01b815260040160405180910390fd5b8535602087013560006115d383611384565b905060006115e08461249c565b9050826001600160601b031660000361160c57604051631f2a200560e01b815260040160405180910390fd5b600181600001516001600160601b0316101561163b57604051633df8562d60e01b815260040160405180910390fd5b60008260400151600681111561165357611653614829565b14158015611677575060018260400151600681111561167457611674614829565b14155b156116955760405163950b706f60e01b815260040160405180910390fd5b6040516304c60b5f60e11b815260ff8c16600482015273d70458ce942f4a4b911b3203591c1920c90070579063098c16be90602401602060405180830381865af41580156116e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061170b91906152aa565b156118c75760408a0135965087611835576040516001620f914d60e11b031981526001600160a01b03888116600483015285169063ffe0dd6690602401602060405180830381865afa158015611765573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061178991906152c7565b6040516352fbf01d60e01b81526001600160a01b0389811660048301526001600160601b0392909216918591908716906352fbf01d90602401602060405180830381865afa1580156117df573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061180391906152c7565b61180d9190614f83565b6001600160601b031611156118355760405163277f952d60e11b815260040160405180910390fd5b600154604051633b0e033d60e01b81527312be7395d46a024f7b82e2c6d8485498bde88bf391633b0e033d9161187f918f918f918f918f916001600160a01b03169060040161530d565b602060405180830381865af415801561189c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118c091906152c7565b9550611a05565b60015460405163bf40fac160e01b81526000916001600160a01b03169063bf40fac1906118f6906004016151d1565b602060405180830381865afa158015611913573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119379190614de2565b905060008c8c8c8c6040516024016119529493929190615349565b60408051601f198184030181529181526020820180516001600160e01b0316632053d50f60e21b179052519091506000906001600160a01b03841690349061199b90859061527b565b60006040518083038185875af1925050503d80600081146119d8576040519150601f19603f3d011682016040523d82523d6000602084013e6119dd565b606091505b5050905080611a01578160405163a5fa8d2b60e01b81526004016112d09190615297565b5050505b60405163dab81c6160e01b81526001600160a01b0385169063dab81c6190611a379086908b908b908e90600401615376565b600060405180830381600087803b158015611a5157600080fd5b505af1158015611a65573d6000803e3d6000fd5b50505050836001600160a01b03167f6a6307e4e0f9004c177d9be0a97e9d145952aebbfb7a2769cdfe10c3bd67847c84888e8e8e348f604051611aae97969594939291906153a9565b60405180910390a2505050505094509492505050565b60015460405163bf40fac160e01b81526000916001600160a01b03169063bf40fac190611af390600401614dc3565b602060405180830381865afa158015611b10573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b349190614de2565b9050336001600160a01b03821614611b5f57604051637bfa4b9f60e01b815260040160405180910390fd5b8551848114611b84576040516001621398b960e31b0319815260040160405180910390fd5b83518114611ba8576040516001621398b960e31b0319815260040160405180910390fd5b60008060005b838310156121545760008a8481518110611bca57611bca6151f4565b602002602001015190503660008b8b87818110611be957611be96151f4565b9050602002810190611bfb919061520a565b9150915060008a8781518110611c1357611c136151f4565b6020026020010151905060008a8881518110611c3157611c316151f4565b60200260200101519050600080611c4e8680359160209091013590565b915091506000611c5d83611384565b90506000611c6a8461249c565b9050826001600160601b0316600003611c9657604051631f2a200560e01b815260040160405180910390fd5b600181600001516001600160601b03161015611cc557604051633df8562d60e01b815260040160405180910390fd5b600082604001516006811115611cdd57611cdd614829565b14158015611d015750600182604001516006811115611cfe57611cfe614829565b14155b15611d1f5760405163950b706f60e01b815260040160405180910390fd5b6040516304c60b5f60e11b815260ff8a16600482015273d70458ce942f4a4b911b3203591c1920c90070579063098c16be90602401602060405180830381865af4158015611d71573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d9591906152aa565b15611f515760408801359a5084611ebf576040516001620f914d60e11b031981526001600160a01b038c8116600483015285169063ffe0dd6690602401602060405180830381865afa158015611def573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e1391906152c7565b6040516352fbf01d60e01b81526001600160a01b038d811660048301526001600160601b0392909216918591908716906352fbf01d90602401602060405180830381865afa158015611e69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e8d91906152c7565b611e979190614f83565b6001600160601b03161115611ebf5760405163277f952d60e11b815260040160405180910390fd5b600154604051633b0e033d60e01b81527312be7395d46a024f7b82e2c6d8485498bde88bf391633b0e033d91611f09918d918d918d918c916001600160a01b03169060040161530d565b602060405180830381865af4158015611f26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f4a91906152c7565b995061208f565b60015460405163bf40fac160e01b81526000916001600160a01b03169063bf40fac190611f80906004016151d1565b602060405180830381865afa158015611f9d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fc19190614de2565b905060008a8a8a89604051602401611fdc9493929190615349565b60408051601f198184030181529181526020820180516001600160e01b0316632053d50f60e21b179052519091506000906001600160a01b038416908a9061202590859061527b565b60006040518083038185875af1925050503d8060008114612062576040519150601f19603f3d011682016040523d82523d6000602084013e612067565b606091505b505090508061208b578160405163a5fa8d2b60e01b81526004016112d09190615297565b5050505b60405163dab81c6160e01b81526001600160a01b0385169063dab81c61906120c19086908f908f908b90600401615376565b600060405180830381600087803b1580156120db57600080fd5b505af11580156120ef573d6000803e3d6000fd5b50505050836001600160a01b03167f6a6307e4e0f9004c177d9be0a97e9d145952aebbfb7a2769cdfe10c3bd67847c848c8c8c8c8c8c60405161213897969594939291906153a9565b60405180910390a28b6001019b50505050505050505050611bae565b50505050505050505050565b604080516060810182526000808252602082018190528183015290516336f2eb2960e21b81526001600160a01b03848116600483015283169063dbcbaca490602401606060405180830381865afa1580156121bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121e391906153f7565b9392505050565b60006121f582611384565b905060006122028361249c565b60015460405163bf40fac160e01b81529192506000916001600160a01b039091169063bf40fac19061223690600401614dc3565b602060405180830381865afa158015612253573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122779190614de2565b905060008360400151600681111561229157612291614829565b146122af57604051630ed2159360e11b815260040160405180910390fd5b6001600160a01b038116330361239457826020015164ffffffffff164264ffffffffff16116122f157604051638a8e7bf960e01b815260040160405180910390fd5b81516001600160601b031660000361236757604051630b3af7f960e01b81526001600160a01b03851690630b3af7f99061233090600290600401615468565b600060405180830381600087803b15801561234a57600080fd5b505af115801561235e573d6000803e3d6000fd5b505050506123ed565b604051630b3af7f960e01b81526001600160a01b03851690630b3af7f99061233090600390600401615468565b60608301516001600160a01b031633036123d457604051630b3af7f960e01b81526001600160a01b03851690630b3af7f990612330906004908101615468565b60405163160d3af160e11b815260040160405180910390fd5b836001600160a01b031663ea8a1af06040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561242857600080fd5b505af115801561243c573d6000803e3d6000fd5b50505050836001600160a01b03167fcd8e02743d921fb9bca767936271b8b93911716c78c1d46c2c6ee6189309d30c8460400151600681111561248157612481614829565b60405160ff909116815260200160405180910390a250505050565b6040805180820190915260008082526020820152816001600160a01b03166323ccc2876040518163ffffffff1660e01b81526004016040805180830381865afa1580156124ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114119190615476565b6000856001600160601b0316856001600160601b031611156125455760405162a80fb560e51b815260040160405180910390fd5b604080516001600160601b0388166020820152808201869052815180820383018152606090910190915261257a8185856131e7565b6001546040516360862d6960e01b81523360048201526001600160a01b039091169060009082906360862d6990602401602060405180830381865afa1580156125c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125eb9190614de2565b90506000826001600160a01b031663bf40fac16040518163ffffffff1660e01b815260040161261990614e80565b602060405180830381865afa158015612636573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061265a9190614de2565b90506001600160a01b0382166126d657604051639859387b60e01b81523360048201526001600160a01b03821690639859387b906024016020604051808303816000875af11580156126b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126d49190614de2565b505b600154604051633e42e78d60e01b81526000917320eaed9ec336f9c1da92cc7e1c8a69d04926d94691633e42e78d91612726918f9133918a91600160a01b900464ffffffffff1690600401614e9b565b60a060405180830381865af4158015612743573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127679190614ed2565b80516040516367d28ec560e01b81529097509091506001600160a01b038716906367d28ec59061279b908490600401614861565b600060405180830381600087803b1580156127b557600080fd5b505af11580156127c9573d6000803e3d6000fd5b5050505080606001516001600160a01b031681600001516001600160a01b03168a7f1e19c550230ca6c5c32d1885c49330e81a79a3002c2ea87672384f8dfec9ff5d8460200151856080015160405161283e92919064ffffffffff9290921682526001600160601b0316602082015260400190565b60405180910390a46001600160601b038a16156128625761286086858c6133b0565b505b505050505095945050505050565b60015460405163bf40fac160e01b815260206004820152600560248201526427aba722a960d91b60448201526000916001600160a01b03169063bf40fac190606401602060405180830381865afa1580156128cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128f39190614de2565b9050336001600160a01b0382161461291e576040516330cd747160e01b815260040160405180910390fd5b8164ffffffffff1660000361294657604051631f2a200560e01b815260040160405180910390fd5b6001805464ffffffffff60a01b1916600160a01b64ffffffffff8516908102919091179091556040519081527feeecb329e59d8e925b3142c110f5fadf78bd09ad1c3ddf1fe54edcf44f291d349060200160405180910390a15050565b60015460405163bf40fac160e01b815260009182916001600160a01b039091169063bf40fac1906129d690600401614e80565b602060405180830381865afa1580156129f3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114119190614de2565b612a1f61318e565b612a2a8383836131e7565b6001546040516360862d6960e01b81526001600160a01b03898116600483015260009216906360862d6990602401602060405180830381865afa158015612a75573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a999190614de2565b60015460405163bf40fac160e01b81529192506000916001600160a01b039091169063bf40fac190612acd90600401614e80565b602060405180830381865afa158015612aea573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b0e9190614de2565b90506001600160a01b038216612b8d57604051639859387b60e01b81526001600160a01b038a81166004830152821690639859387b906024016020604051808303816000875af1158015612b66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b8a9190614de2565b91505b6000612b9889611384565b90506000612ba58a61249c565b90506000612bb3858c612160565b90506001600160a01b038916612bf057896001600160601b03163414612beb5760405162a80fb560e51b815260040160405180910390fd5b612c89565b6040516370a0823160e01b81523360048201526000906001600160a01b038b16906370a0823190602401602060405180830381865afa158015612c37573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c5b9190615001565b9050808b6001600160601b03161115612c8757604051631d00495b60e31b815260040160405180910390fd5b505b60608301516001600160a01b0316612cb45760405163e42ddc1d60e01b815260040160405180910390fd5b826020015164ffffffffff164264ffffffffff161115612ce757604051630fc3544960e41b815260040160405180910390fd5b600083604001516006811115612cff57612cff614829565b14612d1d57604051630ed2159360e11b815260040160405180910390fd5b612d2a898c8c8b896136c8565b995082608001516001600160601b03168a8360000151612d4a9190614f83565b6001600160601b03161115612d72576040516329db8ba960e01b815260040160405180910390fd5b80516001600160601b0316600003612dec57604051638e50c08b60e01b81526001600160a01b038c1690638e50c08b90612db59088908e90600190600401614faa565b600060405180830381600087803b158015612dcf57600080fd5b505af1158015612de3573d6000803e3d6000fd5b50505050612e50565b604051638e50c08b60e01b81526001600160a01b038c1690638e50c08b90612e1d9088908e90600090600401614faa565b600060405180830381600087803b158015612e3757600080fd5b505af1158015612e4b573d6000803e3d6000fd5b505050505b6040516001600160601b038b1681526001600160a01b03808e169133918e16907f4e27d0536502149219866575ceba882206512f58dea2412ddd6625a7c63d6c6c9060200160405180910390a4505050505061137b6001600055565b6060816001600160a01b031663b2f5a54c6040518163ffffffff1660e01b8152600401600060405180830381865afa158015612eec573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261141191908101906154d4565b60015460405163bf40fac160e01b81526000916001600160a01b03169063bf40fac190612f4390600401614dc3565b602060405180830381865afa158015612f60573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f849190614de2565b9050336001600160a01b03821614612faf57604051637bfa4b9f60e01b815260040160405180910390fd5b886000612fbb8c611384565b9050600181604001516006811115612fd557612fd5614829565b14612ff35760405163fd16aabb60e01b815260040160405180910390fd5b5060008060007312be7395d46a024f7b82e2c6d8485498bde88bf3639900a35a8f868f8f8f8f8f8f8f600160009054906101000a90046001600160a01b03166040518b63ffffffff1660e01b81526004016130579a999897969594939291906155f3565b606060405180830381865af4158015613074573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061309891906156a9565b604051630922a48560e01b81526001600160601b03808516600483015280841660248301528216604482015292955090935091506001600160a01b038f1690630922a48590606401600060405180830381600087803b1580156130fa57600080fd5b505af115801561310e573d6000803e3d6000fd5b505050508d6001600160a01b03167f5cd97a0c3ff270ca4d2af5c4999843547ed0b876a26e9f249170d363f1b59a638484848860405161317694939291906001600160601b039485168152928416602084015292166040820152606081019190915260800190565b60405180910390a25050505050505050505050505050565b6002600054036131e05760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016112d0565b6002600055565b825160208085019190912033600081815260029093526040832080547f0e8122b9966a5ace153720b4cfa9a4339fe04cf7270694b3ad4068a61436900b93929185613231836156f6565b909155506040805160208101959095528401929092526001600160a01b03166060830152608082015260a00160405160208183030381529060405280519060200120905060006132c36132826105cb565b8360405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b905060006133078286868080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250613d9a92505050565b60015460405163bf40fac160e01b81529192506000916001600160a01b039091169063bf40fac19061333b90600401614dc3565b602060405180830381865afa158015613358573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061337c9190614de2565b9050806001600160a01b0316826001600160a01b03161461137b57604051637bfa4b9f60e01b815260040160405180910390fd5b600080836001600160a01b031663bf40fac16040518163ffffffff1660e01b81526004016133dd90614fd6565b602060405180830381865afa1580156133fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061341e9190614de2565b604051634fb33bdd60e01b81523360048201529091506000906001600160a01b03861690634fb33bdd90602401600060405180830381865afa158015613468573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261349091908101906154d4565b90506000806134a18387868a613dbe565b9150915060005b82518110156136bc576000808483815181106134c6576134c66151f4565b60200260200101518060200190518101906134e1919061570f565b90925090506000670de0b6b3a7640000613504866001600160601b03851661573e565b61350e9190615755565b90506001600160601b038116156136ae57613529818a614f83565b604051638e50c08b60e01b81529099506001600160a01b038d1690638e50c08b9061355d9086908590600190600401614faa565b600060405180830381600087803b15801561357757600080fd5b505af115801561358b573d6000803e3d6000fd5b5050505060008c826040516024016135a4929190614972565b60408051601f198184030181529181526020820180516001600160e01b031663a9059cbb60e01b17905251631409412160e31b81529091506001600160a01b0385169063a04a090890613600908c908590600090600401615130565b6000604051808303816000875af115801561361f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526136479190810190615164565b50836001600160a01b0316336001600160a01b03168e6001600160a01b03167f6150be318f9a74709ffa8e4c220eee68a5939284c67ec84222af648b3c58de70856040516136a491906001600160601b0391909116815260200190565b60405180910390a4505b8360010193505050506134a8565b50505050509392505050565b60015460405163bf40fac160e01b815260009182916001600160a01b039091169063bf40fac1906136fb90600401614fd6565b602060405180830381865afa158015613718573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061373c9190614de2565b9050806001600160a01b0316876001600160a01b031614613b0457835160000361377957604051632e47553f60e21b815260040160405180910390fd5b60015460405163bf40fac160e01b815260206004820152600d60248201526c27a722a4a721a42927aaaa22a960991b60448201526000916001600160a01b03169063bf40fac190606401602060405180830381865afa1580156137e0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138049190614de2565b90506001600160a01b038816156138e9576138336001600160a01b03891633896001600160601b038a1661401f565b600063095ea7b360e01b8288604051602401613850929190614972565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051631409412160e31b81529091506001600160a01b0389169063a04a0908906138b5908c908590600090600401615130565b600060405180830381600087803b1580156138cf57600080fd5b505af11580156138e3573d6000803e3d6000fd5b50505050505b6040516370a0823160e01b81526001600160a01b038881166004830152600091908416906370a0823190602401602060405180830381865afa158015613933573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139579190615001565b9050876001600160a01b031663a04a0908348489346040518563ffffffff1660e01b815260040161398a93929190615130565b6000604051808303818588803b1580156139a357600080fd5b505af11580156139b7573d6000803e3d6000fd5b50506040516370a0823160e01b81526001600160a01b038c8116600483015260009450871692506370a082319150602401602060405180830381865afa158015613a05573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a299190615001565b9050818111613a4b57604051631d00495b60e31b815260040160405180910390fd5b613a558282615777565b94506001600160a01b038a1615801590613adf5750604051636eb1769f60e11b81526001600160a01b038a8116600483015284811660248301528b169063dd62ed3e90604401602060405180830381865afa158015613ab8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613adc9190615001565b15155b15613afc5760405162a80fb560e51b815260040160405180910390fd5b505050613cfd565b835115613b2457604051632e47553f60e21b815260040160405180910390fd5b6040516370a0823160e01b81526001600160a01b038481166004830152600091908316906370a0823190602401602060405180830381865afa158015613b6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b929190615001565b9050856001600160601b0316816001600160601b031610613c6c5760008787604051602401613bc2929190614972565b60408051601f198184030181529181526020820180516001600160e01b031663a9059cbb60e01b17905251631409412160e31b81529091506001600160a01b0386169063a04a090890613c1e9086908590600090600401615130565b6000604051808303816000875af1158015613c3d573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052613c659190810190615164565b5050613cef565b6040516323b872dd60e01b81523360048201526001600160a01b0388811660248301526001600160601b03881660448301528316906323b872dd906064016020604051808303816000875af1158015613cc9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ced91906152aa565b505b856001600160601b03169250505b6000816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613d3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d61919061501a565b613d6c90600a615121565b905080831015613d8f57604051639c55d34560e01b815260040160405180910390fd5b505095945050505050565b6000806000613da9858561407f565b91509150613db6816140c4565b509392505050565b6060600080600080600089516001600160401b03811115613de157613de1614580565b604051908082528060200260200182016040528015613e1457816020015b6060815260200190600190039081613dff5790505b5090505b8951831015613fbc5760008a8481518110613e3557613e356151f4565b6020908102919091010151604051632c78933160e01b81523360048201526001600160a01b0380831660248301529192506000918a1690632c78933190604401602060405180830381865afa158015613e92573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613eb691906152c7565b6040516370a0823160e01b81526001600160a01b0384811660048301529192506000918c16906370a0823190602401602060405180830381865afa158015613f02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f269190615001565b90506000826001600160601b0316826001600160601b031610613f495782613f4b565b815b604080516001600160a01b03871660208201526001600160601b03929092169082018190529150606001604051602081830303815290604052858881518110613f9657613f966151f4565b6020908102919091010152613fab818961578a565b975086600101965050505050613e18565b831561400f57600084613fe06001600160601b038c16670de0b6b3a764000061573e565b613fea9190615755565b9050670de0b6b3a7640000811061400957670de0b6b3a764000061400b565b805b9250505b9450925050505b94509492505050565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052614079908590614211565b50505050565b60008082516041036140b55760208301516040840151606085015160001a6140a9878285856142e8565b945094505050506140bd565b506000905060025b9250929050565b60008160048111156140d8576140d8614829565b036140e05750565b60018160048111156140f4576140f4614829565b036141415760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e6174757265000000000000000060448201526064016112d0565b600281600481111561415557614155614829565b036141a25760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e6774680060448201526064016112d0565b60038160048111156141b6576141b6614829565b0361420e5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b60648201526084016112d0565b50565b6000614266826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166143a99092919063ffffffff16565b8051909150156142e3578080602001905181019061428491906152aa565b6142e35760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016112d0565b505050565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a083111561431f5750600090506003614016565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015614373573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661439c57600060019250925050614016565b9660009650945050505050565b60606143b884846000856143c0565b949350505050565b6060824710156144215760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016112d0565b600080866001600160a01b0316858760405161443d919061527b565b60006040518083038185875af1925050503d806000811461447a576040519150601f19603f3d011682016040523d82523d6000602084013e61447f565b606091505b50915091506144908783838761449b565b979650505050505050565b6060831561450a578251600003614503576001600160a01b0385163b6145035760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016112d0565b50816143b8565b6143b8838381511561451f5781518083602001fd5b8060405162461bcd60e51b81526004016112d09190615297565b6001600160a01b038116811461420e57600080fd5b60006020828403121561456057600080fd5b81356121e381614539565b6001600160601b038116811461420e57600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156145be576145be614580565b604052919050565b60006001600160401b038211156145df576145df614580565b50601f01601f191660200190565b600082601f8301126145fe57600080fd5b813561461161460c826145c6565b614596565b81815284602083860101111561462657600080fd5b816020850160208301376000918101602001919091529392505050565b60008083601f84011261465557600080fd5b5081356001600160401b0381111561466c57600080fd5b6020830191508360208285010111156140bd57600080fd5b60008060008060008060008060e0898b0312156146a057600080fd5b88356146ab8161456b565b975060208901356146bb8161456b565b96506040890135955060608901356146d281614539565b945060808901356146e28161456b565b935060a08901356001600160401b03808211156146fe57600080fd5b61470a8c838d016145ed565b945060c08b013591508082111561472057600080fd5b5061472d8b828c01614643565b999c989b5096995094979396929594505050565b6000806040838503121561475457600080fd5b823561475f81614539565b9150602083013561476f8161456b565b809150509250929050565b60008083601f84011261478c57600080fd5b5081356001600160401b038111156147a357600080fd5b6020830191508360208260051b85010111156140bd57600080fd5b600080600080604085870312156147d457600080fd5b84356001600160401b03808211156147eb57600080fd5b6147f78883890161477a565b9096509450602087013591508082111561481057600080fd5b5061481d8782880161477a565b95989497509550505050565b634e487b7160e01b600052602160045260246000fd5b6007811061485d57634e487b7160e01b600052602160045260246000fd5b9052565b81516001600160a01b03908116825260208084015164ffffffffff169083015260408084015160a0840192916148999085018261483f565b50806060850151166060840152506001600160601b03608084015116608083015292915050565b801515811461420e57600080fd5b600080600080608085870312156148e457600080fd5b84356148ef81614539565b935060208501356148ff816148c0565b93969395505050506040820135916060013590565b6000806000806060858703121561492a57600080fd5b8435935060208501356001600160401b0381111561494757600080fd5b61495387828801614643565b9094509250506040850135614967816148c0565b939692955090935050565b6001600160a01b039290921682526001600160601b0316602082015260400190565b60006001600160401b038211156149ad576149ad614580565b5060051b60200190565b600082601f8301126149c857600080fd5b813560206149d861460c83614994565b82815260059290921b840181019181810190868411156149f757600080fd5b8286015b84811015614a1257803583529183019183016149fb565b509695505050505050565b600080600080600060808688031215614a3557600080fd5b85356001600160401b0380821115614a4c57600080fd5b614a5889838a016149b7565b9650602091508188013581811115614a6f57600080fd5b614a7b8a828b0161477a565b909750955050604088013581811115614a9357600080fd5b614a9f8a828b016149b7565b945050606088013581811115614ab457600080fd5b88019050601f81018913614ac757600080fd5b8035614ad561460c82614994565b81815260059190911b8201830190838101908b831115614af457600080fd5b928401925b82841015614b1b578335614b0c816148c0565b82529284019290840190614af9565b80955050505050509295509295909350565b60008060408385031215614b4057600080fd5b8235614b4b81614539565b9150602083013561476f81614539565b600080600080600060808688031215614b7357600080fd5b8535614b7e8161456b565b94506020860135614b8e8161456b565b93506040860135925060608601356001600160401b03811115614bb057600080fd5b614bbc88828901614643565b969995985093965092949392505050565b64ffffffffff8116811461420e57600080fd5b600060208284031215614bf257600080fd5b81356121e381614bcd565b600080600080600080600060c0888a031215614c1857600080fd5b8735614c2381614539565b96506020880135614c3381614539565b95506040880135614c438161456b565b94506060880135614c5381614539565b935060808801356001600160401b0380821115614c6f57600080fd5b614c7b8b838c016145ed565b945060a08a0135915080821115614c9157600080fd5b50614c9e8a828b01614643565b989b979a50959850939692959293505050565b6020808252825182820181905260009190848201906040850190845b81811015614cf25783516001600160a01b031683529284019291840191600101614ccd565b50909695505050505050565b600080600080600080600080600060e08a8c031215614d1c57600080fd5b8935614d2781614539565b985060208a0135975060408a0135614d3e8161456b565b965060608a0135614d4e8161456b565b955060808a0135614d5e8161456b565b945060a08a01356001600160401b0380821115614d7a57600080fd5b614d868d838e0161477a565b909650945060c08c0135915080821115614d9f57600080fd5b50614dac8c828d0161477a565b915080935050809150509295985092959850929598565b60208082526005908201526420a226a4a760d91b604082015260600190565b600060208284031215614df457600080fd5b81516121e381614539565b60005b83811015614e1a578181015183820152602001614e02565b50506000910152565b60008151808452614e3b816020860160208601614dff565b601f01601f19169290920160200192915050565b6001600160601b0384168152826020820152606060408201526000614e776060830184614e23565b95945050505050565b6020808252600190820152605160f81b604082015260600190565b6001600160601b039490941684526001600160a01b0392831660208501529116604083015264ffffffffff16606082015260800190565b600060a08284031215614ee457600080fd5b60405160a081018181106001600160401b0382111715614f0657614f06614580565b6040528251614f1481614539565b81526020830151614f2481614bcd565b6020820152604083015160078110614f3b57600080fd5b60408201526060830151614f4e81614539565b60608201526080830151614f618161456b565b60808201529392505050565b634e487b7160e01b600052601160045260246000fd5b6001600160601b03818116838216019080821115614fa357614fa3614f6d565b5092915050565b6001600160a01b039390931683526001600160601b039190911660208301521515604082015260600190565b6020808252601190820152702222a320aaa62a29aa20a12622a1a7a4a760791b604082015260600190565b60006020828403121561501357600080fd5b5051919050565b60006020828403121561502c57600080fd5b815160ff811681146121e357600080fd5b600181815b8085111561507857816000190482111561505e5761505e614f6d565b8085161561506b57918102915b93841c9390800290615042565b509250929050565b60008261508f57506001611411565b8161509c57506000611411565b81600181146150b257600281146150bc576150d8565b6001915050611411565b60ff8411156150cd576150cd614f6d565b50506001821b611411565b5060208310610133831016604e8410600b84101617156150fb575081810a611411565b615105838361503d565b806000190482111561511957615119614f6d565b029392505050565b60006121e360ff841683615080565b6001600160a01b038416815260606020820181905260009061515490830185614e23565b9050826040830152949350505050565b60006020828403121561517657600080fd5b81516001600160401b0381111561518c57600080fd5b8201601f8101841361519d57600080fd5b80516151ab61460c826145c6565b8181528560208385010111156151c057600080fd5b614e77826020830160208601614dff565b60208082526009908201526850455250545241444560b81b604082015260600190565b634e487b7160e01b600052603260045260246000fd5b6000808335601e1984360301811261522157600080fd5b8301803591506001600160401b0382111561523b57600080fd5b6020019150368190038213156140bd57600080fd5b8381526060602082015260006152696060830185614e23565b90508215156040830152949350505050565b6000825161528d818460208701614dff565b9190910192915050565b6020815260006121e36020830184614e23565b6000602082840312156152bc57600080fd5b81516121e3816148c0565b6000602082840312156152d957600080fd5b81516121e38161456b565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b8581526080602082015260006153276080830186886152e4565b9315156040830152506001600160a01b03919091166060909101529392505050565b8481526060602082015260006153636060830185876152e4565b9050821515604083015295945050505050565b6001600160601b0394851681526001600160a01b0393909316602084015292166040820152901515606082015260800190565b60006001600160601b03808a16835280891660208401525086604083015260c060608301526153dc60c0830186886152e4565b60808301949094525090151560a09091015295945050505050565b60006060828403121561540957600080fd5b604051606081018181106001600160401b038211171561542b5761542b614580565b60405282516154398161456b565b815260208301516154498161456b565b6020820152604083015161545c816148c0565b60408201529392505050565b60208101611411828461483f565b60006040828403121561548857600080fd5b604051604081018181106001600160401b03821117156154aa576154aa614580565b60405282516154b88161456b565b815260208301516154c88161456b565b60208201529392505050565b600060208083850312156154e757600080fd5b82516001600160401b038111156154fd57600080fd5b8301601f8101851361550e57600080fd5b805161551c61460c82614994565b81815260059190911b8201830190838101908783111561553b57600080fd5b928401925b8284101561449057835161555381614539565b82529284019290840190615540565b81835260006020808501808196508560051b810191508460005b878110156155e65782840389528135601e1988360301811261559d57600080fd5b870185810190356001600160401b038111156155b857600080fd5b8036038213156155c757600080fd5b6155d28682846152e4565b9a87019a955050509084019060010161557c565b5091979650505050505050565b6001600160a01b038b8116825260208083018c90526001600160601b038b811660408501528a811660608501528916608084015261010060a084018190528301879052600091610120840191899190845b8a81101561566b57833561565781614539565b831685529381019392810192600101615644565b5050505082810360c0840152615682818688615562565b91505061569a60e08301846001600160a01b03169052565b9b9a5050505050505050505050565b6000806000606084860312156156be57600080fd5b83516156c98161456b565b60208501519093506156da8161456b565b60408501519092506156eb8161456b565b809150509250925092565b60006001820161570857615708614f6d565b5060010190565b6000806040838503121561572257600080fd5b825161572d81614539565b602084015190925061476f8161456b565b808202811582820484141761141157611411614f6d565b60008261577257634e487b7160e01b600052601260045260246000fd5b500490565b8181038181111561141157611411614f6d565b8082018082111561141157611411614f6d56fea26469706673582212207459ecebbd433ab629026001bddb8b993518a054daf8313e9b539ff2659ca1dd64736f6c63430008130033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000e52625d111cdbafcc1bc1e97380eb0e22fea06990000000000000000000000000000000000000000000000000000000000093a80
-----Decoded View---------------
Arg [0] : _operator (address): 0xE52625D111cDBaFCC1bC1E97380Eb0E22fea0699
Arg [1] : _maxFundraisingPeriod (uint40): 604800
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000e52625d111cdbafcc1bc1e97380eb0e22fea0699
Arg [1] : 0000000000000000000000000000000000000000000000000000000000093a80
Net Worth in USD
Net Worth in ETH
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
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.