Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- PassTokenStaking
- Optimization enabled
- true
- Compiler version
- v0.8.19+commit.7dd6d404
- Optimization runs
- 200
- EVM Version
- default
- Verified at
- 2023-11-24T02:16:35.068021Z
contracts/PassTokenStaking.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.0;
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import {ECDSAUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol";
import {SafeMathUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
import {AddressUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";
import {BlockContext} from "./base/BlockContext.sol";
import {Multicall} from "./base/Multicall.sol";
import {PassTokenProxy} from "./PassTokenProxy.sol";
import {IPassToken} from "./interfaces/IPassToken.sol";
import {IPassTokenFactory} from "./interfaces/IPassTokenFactory.sol";
import {IPassTokenStaking} from "./interfaces/IPassTokenStaking.sol";
import {PassTokenStakingStorage} from "./storage/PassTokenStakingStorage.sol";
import {IQuoter} from "./interfaces/IQuoter.sol";
import {ISwapRouter} from "./interfaces/ISwapRouter.sol";
import {IUniswapV3Pool} from "./interfaces/IUniswapV3Pool.sol";
import {NumberMath} from "./libraries/NumberMath.sol";
import {StakingTokenTypes} from "./libraries/StakingTokenTypes.sol";
import {INonfungiblePositionManager} from "./interfaces/INonfungiblePositionManager.sol";
import {TransferHelper} from "./libraries/TransferHelper.sol";
contract PassTokenStaking is
IPassTokenStaking,
BlockContext,
Multicall,
OwnableUpgradeable,
ReentrancyGuardUpgradeable,
PassTokenStakingStorage
{
//
using AddressUpgradeable for address;
using NumberMath for uint256;
using SafeMathUpgradeable for uint256;
//
modifier onlyToken(address token) {
require(
IPassTokenFactory(_passTokenFactory).getTokenTwitter(token) != 0,
"PTS_TZA"
);
_;
}
modifier onlyCreator(address token) {
require(IPassToken(token).getCreator() == _msgSender(), "PTS_NC");
_;
}
function initialize(
address passTokenFactory,
address swapRouter,
address quoter,
address btc
) external initializer {
//
__Ownable_init();
__ReentrancyGuard_init();
//
_passTokenFactory = passTokenFactory;
_swapRouter = swapRouter;
_quoter = quoter;
_btc = btc;
//
TransferHelper.safeApprove(btc, swapRouter, type(uint256).max);
//
}
function getPassTokenFactory() public view returns (address) {
return _passTokenFactory;
}
function getTokenCreator(address token) public view returns (address) {
return IPassToken(token).getCreator();
}
// view function
function stakingBalanceOf(
address token,
address user
) public view returns (uint256) {
return _tokenStakingBalances[token][user];
}
function freeStakingBalanceOf(
address token,
address user
) public view returns (uint256) {
uint256 balance = IERC20Upgradeable(token).balanceOf(user);
return balance.sub(_tokenStakingBalances[token][user]);
}
function exactOutputForBtc2Token(
address token,
uint24 ratio,
uint256 amountOut
) external onlyToken(token) returns (uint256) {
//
require(amountOut > 0 && ratio > 0, "PTS_IP");
//
uint256 interest = amountOut.mulRatio(ratio);
//
address poolV3Addr = IPassToken(token).getPoolV3();
uint24 fee = IUniswapV3Pool(poolV3Addr).fee();
//
(uint256 amountIn, , , ) = IQuoter(_quoter).quoteExactOutputSingle(
IQuoter.QuoteExactOutputSingleParams({
tokenIn: token,
tokenOut: _btc,
amount: interest,
fee: fee,
sqrtPriceLimitX96: 0
})
);
//
return amountIn;
}
// external function
function tokenStakingOpen(
address token,
uint24 ratio,
uint256 duration,
bool locked,
uint256 amount
) external onlyToken(token) onlyCreator(token) {
address creator = _msgSender();
//
uint256 stakingId = NumberMath.getStakingId(ratio, duration, locked);
//
StakingTokenTypes.Staking storage tokenStakings = _tokenStakings[token][
stakingId
];
//
amount = amount.roundMilliether();
require(amount > 0, "PTS_IA");
//
tokenStakings.status = StakingTokenTypes.Status.Running;
//
uint256 interest = amount.mulRatio(ratio);
uint256 free = tokenStakings.free.add(interest);
tokenStakings.free = free;
//
TransferHelper.safeTransferFrom(
token,
creator,
address(this),
interest
);
//
emit TokenStakingUpdated(
token,
StakingTokenTypes.Status.Running,
ratio,
duration,
locked,
free,
tokenStakings.total
);
}
function tokenStakingClose(
address token,
uint24 ratio,
uint256 duration,
bool locked
) external onlyToken(token) onlyCreator(token) {
address creator = _msgSender();
//
uint256 stakingId = NumberMath.getStakingId(ratio, duration, locked);
//
StakingTokenTypes.Staking storage tokenStakings = _tokenStakings[token][
stakingId
];
//
require(
tokenStakings.status == StakingTokenTypes.Status.Running,
"PTS_IS"
);
tokenStakings.status = StakingTokenTypes.Status.Stopped;
//
uint256 free = tokenStakings.free;
tokenStakings.free = 0;
//
TransferHelper.safeTransfer(token, creator, free);
//
emit TokenStakingUpdated(
token,
StakingTokenTypes.Status.Stopped,
ratio,
duration,
locked,
0,
tokenStakings.total
);
}
function tokenStakingOrderCreate(
address token,
bytes32 orderId,
uint24 ratio,
uint256 duration,
bool locked,
uint256 amount
) external onlyToken(token) {
//
address trader = _msgSender();
//
uint256 stakingId = NumberMath.getStakingId(ratio, duration, locked);
//
StakingTokenTypes.Staking storage tokenStakings = _tokenStakings[token][
stakingId
];
StakingTokenTypes.Order storage order = _tokenStakingOrders[token][
orderId
];
//
StakingTokenTypes.Status stakingStatus = tokenStakings.status;
//
require(stakingStatus == StakingTokenTypes.Status.Running, "PTS_IS");
//
amount = amount.roundMilliether();
require(amount > 0, "PTS_IA");
require(freeStakingBalanceOf(token, trader) >= amount, "PTS_IB");
//
require(order.status == StakingTokenTypes.OrderStatus.None, "PTS_BOS");
//
order.ratio = ratio;
order.duration = duration;
order.locked = locked;
order.trader = trader;
order.status = StakingTokenTypes.OrderStatus.Created;
order.amount = amount;
order.createdAt = _blockTimestamp();
//
uint256 intertest = amount.mulRatio(ratio);
//
uint256 free = tokenStakings.free;
require(free >= intertest, "PTS_IF");
free = free.sub(intertest);
tokenStakings.free = free;
//
uint256 total = tokenStakings.total.add(amount);
tokenStakings.total = total;
//
_tokenStakingTotal[token] = _tokenStakingTotal[token].add(amount);
_tokenStakingBalances[token][trader] = _tokenStakingBalances[token][
trader
].add(amount);
//
emit TokenStakingUpdated(
token,
stakingStatus,
ratio,
duration,
locked,
free,
total
);
//
emit TokenStakingOrderCreated(
token,
orderId,
ratio,
duration,
locked,
trader,
amount,
_blockTimestamp()
);
}
function tokenStakingOrderClose(
address token,
bytes32 orderId
) external onlyToken(token) {
//
address caller = _msgSender();
//
StakingTokenTypes.Order storage order = _tokenStakingOrders[token][
orderId
];
address trader = order.trader;
//
require(
order.status == StakingTokenTypes.OrderStatus.Created,
"PTS_BOS"
);
//
uint24 ratio = order.ratio;
uint256 duration = order.duration;
bool locked = order.locked;
uint256 amount = order.amount;
uint256 createdAt = order.createdAt;
//
uint256 stakingId = NumberMath.getStakingId(ratio, duration, locked);
//
StakingTokenTypes.Staking storage stakings = _tokenStakings[token][
stakingId
];
// decrease total
uint256 total = stakings.total.sub(amount);
stakings.total = total;
// release staking balance
_tokenStakingTotal[token] = _tokenStakingTotal[token].sub(amount);
_tokenStakingBalances[token][trader] = _tokenStakingBalances[token][
trader
].sub(amount);
//
StakingTokenTypes.OrderStatus orderStatus;
uint256 interest = amount.mulRatio(ratio);
StakingTokenTypes.Status termStatus = stakings.status;
uint256 free = stakings.free;
// check invalid lock duration
if (createdAt.add(duration) <= _blockTimestamp()) {
// update status done
orderStatus = StakingTokenTypes.OrderStatus.Done;
order.status = orderStatus;
// transfer interest
TransferHelper.safeTransfer(token, trader, interest);
//
} else {
require(order.trader == caller, "PTS_IC"); // invalid trader
require(!locked, "PTS_LO"); // locked order
// update status cancelled
orderStatus = StakingTokenTypes.OrderStatus.Cancelled;
order.status = orderStatus;
//
if (termStatus == StakingTokenTypes.Status.Running) {
// release free
free = free.add(interest);
stakings.free = free;
//
} else if (termStatus == StakingTokenTypes.Status.Stopped) {
// return free
address creator = getTokenCreator(token);
TransferHelper.safeTransfer(token, creator, interest);
//
} else {
revert("PTS_BS");
}
}
//
emit TokenStakingUpdated(
token,
termStatus,
ratio,
duration,
locked,
free,
total
);
//
emit TokenStakingOrderClosed(
token,
orderId,
ratio,
duration,
locked,
trader,
amount,
interest,
orderStatus,
_blockTimestamp()
);
}
function swapBtc2Token(
uint256 amountBtcMax,
address token,
uint256 amountOutMin
) external onlyToken(token) {
address trader = _msgSender();
if (amountOutMin > 0) {
//
address tokenBtc = _btc;
//
address poolV3Addr = IPassToken(token).getPoolV3();
uint24 fee = IUniswapV3Pool(poolV3Addr).fee();
//
(uint256 amountIn, , , ) = IQuoter(_quoter).quoteExactOutputSingle(
IQuoter.QuoteExactOutputSingleParams({
tokenIn: tokenBtc,
tokenOut: token,
amount: amountOutMin,
fee: fee,
sqrtPriceLimitX96: 0
})
);
//
require(amountIn <= amountBtcMax, "PTS_IAB");
//
TransferHelper.safeTransferFrom(
tokenBtc,
trader,
address(this),
amountIn
);
//
uint256 amountOunt = ISwapRouter(_swapRouter).exactInputSingle(
ISwapRouter.ExactInputSingleParams({
tokenIn: tokenBtc,
tokenOut: token,
fee: fee,
recipient: trader,
deadline: type(uint256).max,
amountIn: amountIn,
amountOutMinimum: 0,
sqrtPriceLimitX96: 0
})
);
//
require(amountOunt >= amountOutMin, "PTS_IAT");
//
}
}
}
contracts/libraries/StakingTokenTypes.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
library StakingTokenTypes {
//
enum Status {
None,
Running,
Stopped
}
struct Staking {
Status status;
uint256 free;
uint256 total;
}
enum OrderStatus {
None,
Created,
Done,
Cancelled
}
struct Order {
OrderStatus status;
uint24 ratio;
uint256 duration;
address trader;
uint256 createdAt;
uint256 amount;
bool locked;
}
}
contracts/base/Multicall.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >0.8.0;
/// @title Multicall
/// @notice Enables calling multiple methods in a single call to the contract
abstract contract Multicall {
function multicall(
bytes[] calldata data
) public payable returns (bytes[] memory results) {
results = new bytes[](data.length);
for (uint256 i = 0; i < data.length; i++) {
(bool success, bytes memory result) = address(this).delegatecall(
data[i]
);
if (!success) {
// Next 5 lines from https://ethereum.stackexchange.com/a/83577
if (result.length < 68) revert();
assembly {
result := add(result, 0x04)
}
revert(abi.decode(result, (string)));
}
results[i] = result;
}
}
}
@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal onlyInitializing {
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}
@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuardUpgradeable is Initializable {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20Upgradeable {
/**
* @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);
}
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/MathUpgradeable.sol";
import "./math/SignedMathUpgradeable.sol";
/**
* @dev String operations.
*/
library StringsUpgradeable {
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 = MathUpgradeable.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 `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMathUpgradeable.abs(value))));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, MathUpgradeable.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);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}
@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../StringsUpgradeable.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 ECDSAUpgradeable {
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 message) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32")
mstore(0x1c, hash)
message := keccak256(0x00, 0x3c)
}
}
/**
* @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", StringsUpgradeable.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 data) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, "\x19\x01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
data := keccak256(ptr, 0x42)
}
}
/**
* @dev Returns an Ethereum Signed Data with intended validator, created from a
* `validator` and `data` according to the version 0 of EIP-191.
*
* See {recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x00", validator, data));
}
}
@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library MathUpgradeable {
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) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 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 256, 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 << 3) < value ? 1 : 0);
}
}
}
@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol)
pragma solidity ^0.8.0;
// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.
/**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/
library SafeMathUpgradeable {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
@openzeppelin/contracts-upgradeable/utils/math/SignedMathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMathUpgradeable {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}
@openzeppelin/contracts/proxy/Proxy.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (proxy/Proxy.sol)
pragma solidity ^0.8.0;
/**
* @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
* instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
* be specified by overriding the virtual {_implementation} function.
*
* Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
* different contract through the {_delegate} function.
*
* The success and return data of the delegated call will be returned back to the caller of the proxy.
*/
abstract contract Proxy {
/**
* @dev Delegates the current call to `implementation`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _delegate(address implementation) internal virtual {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @dev This is a virtual function that should be overridden so it returns the address to which the fallback function
* and {_fallback} should delegate.
*/
function _implementation() internal view virtual returns (address);
/**
* @dev Delegates the current call to the address returned by `_implementation()`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _fallback() internal virtual {
_beforeFallback();
_delegate(_implementation());
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
* function in the contract matches the call data.
*/
fallback() external payable virtual {
_fallback();
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
* is empty.
*/
receive() external payable virtual {
_fallback();
}
/**
* @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
* call, or as part of the Solidity `fallback` or `receive` functions.
*
* If overridden should call `super._beforeFallback()`.
*/
function _beforeFallback() internal virtual {}
}
contracts/PassTokenProxy.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import {Proxy} from "@openzeppelin/contracts/proxy/Proxy.sol";
import {IPassTokenFactoryImpl} from "./interfaces/IPassTokenFactoryImpl.sol";
/**
* @title AlphaKeysTokenProxy
* @author 0xkongamoto
*/
contract PassTokenProxy is Proxy {
//
IPassTokenFactoryImpl public immutable factory;
// ======== Constructor =========
constructor() {
factory = IPassTokenFactoryImpl(msg.sender);
}
/**
* @dev This is a virtual function that should be overridden so it returns the address to which the fallback function
* and {_fallback} should delegate.
*/
function _implementation()
internal
view
virtual
override
returns (address impl)
{
return factory.getPassTokenImplementation();
}
}
contracts/base/BlockContext.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.0;
abstract contract BlockContext {
function _blockTimestamp() internal view virtual returns (uint256) {
// Reply from Arbitrum
// block.timestamp returns timestamp at the time at which the sequencer receives the tx.
// It may not actually correspond to a particular L1 block
return block.timestamp;
}
function _blockNumber() internal view virtual returns (uint256) {
return block.number;
}
}
contracts/interfaces/INonfungiblePositionManager.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;
/// @title Non-fungible token for positions
/// @notice Wraps Uniswap V3 positions in a non-fungible token interface which allows for them to be transferred
/// and authorized.
interface INonfungiblePositionManager {
function WTC() external view returns (address);
function factory() external view returns (address);
struct MintParams {
address token0;
address token1;
uint24 fee;
int24 tickLower;
int24 tickUpper;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
address recipient;
uint256 deadline;
}
function mint(
MintParams calldata params
)
external
payable
returns (
uint256 tokenId,
uint128 liquidity,
uint256 amount0,
uint256 amount1
);
function createAndInitializePoolIfNecessary(
address token0,
address token1,
uint24 fee,
uint160 sqrtPriceX96
) external payable returns (address pool);
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
struct DecreaseLiquidityParams {
uint256 tokenId;
uint128 liquidity;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
function positions(
uint256 tokenId
)
external
view
returns (
uint96 nonce,
address operator,
address token0,
address token1,
uint24 fee,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
);
struct IncreaseLiquidityParams {
uint256 tokenId;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
function increaseLiquidity(
IncreaseLiquidityParams calldata params
)
external
payable
returns (uint128 liquidity, uint256 amount0, uint256 amount1);
function decreaseLiquidity(
DecreaseLiquidityParams calldata params
) external payable returns (uint256 amount0, uint256 amount1);
struct CollectParams {
uint256 tokenId;
address recipient;
uint128 amount0Max;
uint128 amount1Max;
}
function collect(
CollectParams calldata params
) external payable returns (uint256 amount0, uint256 amount1);
function unwrapWTC(
uint256 amountMinimum,
address recipient
) external payable;
function sweepToken(
address token,
uint256 amountMinimum,
address recipient
) external payable;
function refundTC() external payable;
function burn(uint256 tokenId) external payable;
}
contracts/interfaces/IPassToken.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.0;
interface IPassToken {
//
event FeeEarned(address creator, uint256 amountToken, uint256 amountBTC);
event LockedTs(
address user,
uint256 amount,
uint256 duationTs,
uint256 expiredTs
);
event FundDeposited(
address trader,
uint256 amountBTC,
uint256 balanceBTCUser,
uint256 balanceBTC
);
event FundClaimed(
address trader,
uint256 balanceBTCUser,
uint256 balanceToken,
uint256 balanceClaimedBTC,
uint256 balanceClaimedToken
);
event FundEnded(uint256 balanceBTC, uint256 balanceToken);
//
function initialize(
address factory,
string calldata name,
string calldata symbol,
uint256 twitterId
) external;
function getCreator() external view returns (address);
function getPoolV3() external view returns (address);
}
contracts/interfaces/IPassTokenFactory.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.0;
import {IPassTokenFactoryImpl} from "./IPassTokenFactoryImpl.sol";
interface IPassTokenFactory is IPassTokenFactoryImpl {
//
event PassTokenCreated(uint256 twitterId, address token);
//
function getTwitterToken(uint256 twitterId) external view returns (address);
function getTokenTwitter(address token) external view returns (uint256);
function getAlphaKeysFactory() external view returns (address);
function getNonfungiblePositionManager() external view returns (address);
function getSwapRouter() external view returns (address);
function getUniswapV3Factory() external view returns (address);
function getPassTokenStaking() external view returns (address);
}
contracts/interfaces/IPassTokenFactoryImpl.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.0;
interface IPassTokenFactoryImpl {
function getPassTokenImplementation()
external
view
returns (address);
}
contracts/interfaces/IPassTokenStaking.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.0;
import {StakingTokenTypes} from "../libraries/StakingTokenTypes.sol";
interface IPassTokenStaking {
//
event TokenStakingUpdated(
address token,
StakingTokenTypes.Status status,
uint24 ratio,
uint256 duration,
bool locked,
uint256 free,
uint256 total
);
event TokenStakingOrderCreated(
address token,
bytes32 orderId,
uint24 ratio,
uint256 duration,
bool locked,
address trader,
uint256 amount,
uint256 createdAt
);
event TokenStakingOrderClosed(
address token,
bytes32 orderId,
uint24 ratio,
uint256 duration,
bool locked,
address trader,
uint256 amount,
uint256 interest,
StakingTokenTypes.OrderStatus status,
uint256 closedAt
);
//
function stakingBalanceOf(
address token,
address user
) external view returns (uint256);
}
contracts/interfaces/IQuoter.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;
interface IQuoter {
struct QuoteExactOutputSingleParams {
address tokenIn;
address tokenOut;
uint256 amount;
uint24 fee;
uint160 sqrtPriceLimitX96;
}
function quoteExactOutputSingle(
QuoteExactOutputSingleParams memory params
)
external
returns (
uint256 amountIn,
uint160 sqrtPriceX96After,
uint32 initializedTicksCrossed,
uint256 gasEstimate
);
}
contracts/interfaces/ISwapRouter.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;
/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
function exactInputSingle(
ExactInputSingleParams calldata params
) external payable returns (uint256 amountOut);
struct ExactInputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
}
function exactInput(
ExactInputParams memory params
) external payable returns (uint256 amountOut);
function unwrapWTC(
uint256 amountMinimum,
address recipient
) external payable;
function sweepToken(
address token,
uint256 amountMinimum,
address recipient
) external payable;
function refundTC() external payable;
}
contracts/interfaces/IUniswapV3Pool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;
interface IUniswapV3Pool {
function slot0()
external
view
returns (
uint160 sqrtPriceX96,
int24 tick,
uint16 observationIndex,
uint16 observationCardinality,
uint16 observationCardinalityNext,
uint8 feeProtocol,
bool unlocked
);
function fee() external view returns (uint24);
function token0() external view returns (address);
function liquidity() external view returns (uint128);
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
}
contracts/libraries/NumberMath.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
import {SafeMathUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import {MathUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol";
library NumberMath {
// CONST
uint256 internal constant RATIO = 1e6;
using SafeMathUpgradeable for uint256;
uint256 internal constant ONE_ETHER = 1 ether;
uint256 internal constant PRICE_UNIT = 0.000001 ether;
uint256 internal constant NUMBER_UNIT_PER_ONE_ETHER =
ONE_ETHER / PRICE_UNIT;
uint256 internal constant PRICE_BTC_PER_TC = 0.000416666666666667 ether; // 1 BTC = 2400 TC
uint256 internal constant PRICE_TC_PER_BTC = 2400 ether; // 1 BTC = 2400 TC
uint256 internal constant PRICE_KEYS_DENOMINATOR = 264000;
uint256 internal constant TS_30_DAYS = 30 days;
uint256 internal constant TS_180_DAYS = 180 days;
uint24 internal constant SWAP_PLATFORM_FEE_RATIO = 10000;
uint24 internal constant SWAP_CREATOR_FEE_RATIO = 40000;
//
uint24 internal constant DEFAULT_POOL_V3_FEE = 10000; // 1%
uint256 internal constant DEFAULT_PASS_TOKEN_SUPPLY = 21_000_000 ether; // 21M
uint256 internal constant DEFAULT_PASS_TOKEN_FUND_DURATION = 24 hours;
//
function mulRatio(
uint256 value,
uint24 ratio
) internal pure returns (uint256) {
return value.mul(ratio).div(RATIO);
}
function divRatio(
uint256 value,
uint24 ratio
) internal pure returns (uint256) {
return value.mul(RATIO).div(ratio);
}
function mulEther(uint256 value) internal pure returns (uint256) {
return value.mul(1 ether);
}
function divEther(uint256 value) internal pure returns (uint256) {
return value.div(1 ether);
}
function mulPrice(
uint256 value,
uint256 rate
) internal pure returns (uint256) {
return value.mul(rate).div(1 ether);
}
function roundMilliether(uint256 value) internal pure returns (uint256) {
return value.div(0.001 ether).mul(0.001 ether);
}
function roundEther(uint256 value) internal pure returns (uint256) {
return value.div(1 ether).mul(1 ether);
}
function getPriceV2(
uint256 supply,
uint256 amount
) internal pure returns (uint256) {
// invalid params
require(supply >= NUMBER_UNIT_PER_ONE_ETHER && amount >= 1, "NM_IP");
//
uint256 sum1 = ((supply - NUMBER_UNIT_PER_ONE_ETHER) *
supply *
(2 *
(supply - NUMBER_UNIT_PER_ONE_ETHER) +
NUMBER_UNIT_PER_ONE_ETHER)) / 6;
uint256 sum2 = ((supply - NUMBER_UNIT_PER_ONE_ETHER + amount) *
(supply + amount) *
(2 *
(supply - NUMBER_UNIT_PER_ONE_ETHER + amount) +
NUMBER_UNIT_PER_ONE_ETHER)) / 6;
uint256 summation = sum2 - sum1;
return
(summation * ONE_ETHER) /
PRICE_KEYS_DENOMINATOR /
(NUMBER_UNIT_PER_ONE_ETHER *
NUMBER_UNIT_PER_ONE_ETHER *
NUMBER_UNIT_PER_ONE_ETHER);
}
function getBuyPriceV2(
uint256 supply,
uint256 amountX18
) internal pure returns (uint256) {
return
getPriceV2(supply.div(PRICE_UNIT), amountX18.div(PRICE_UNIT)).add(
1
);
}
function getSellPriceV2(
uint256 supply,
uint256 amountX18
) internal pure returns (uint256) {
return
getPriceV2(
supply.div(PRICE_UNIT).sub(amountX18.div(PRICE_UNIT)),
amountX18.div(PRICE_UNIT)
);
}
function getBuyPriceV2AfterFee(
uint24 protocolFeeRatio,
uint24 playerFeeRatio,
uint256 supply,
uint256 amountX18
) internal pure returns (uint256) {
//
uint256 price = getBuyPriceV2(supply, amountX18);
uint256 protocolFee = mulRatio(price, protocolFeeRatio);
uint256 playerFee = mulRatio(price, playerFeeRatio);
return price.add(protocolFee).add(playerFee);
}
function getSellPriceV2AfterFee(
uint24 protocolFeeRatio,
uint24 playerFeeRatio,
uint256 supply,
uint256 amountX18
) internal pure returns (uint256) {
//
uint256 price = getSellPriceV2(supply, amountX18);
uint256 protocolFee = mulRatio(price, protocolFeeRatio);
uint256 playerFee = mulRatio(price, playerFeeRatio);
return price.sub(protocolFee).sub(playerFee);
}
function getBuyAmountMaxWithCash(
uint24 protocolFeeRatio,
uint24 playerFeeRatio,
address token,
uint256 buyPriceAfterFeeMax
) internal view returns (uint256) {
uint256 supply = IERC20Upgradeable(token).totalSupply();
uint256 amount = 0;
for (uint i = 0; i < 6; i++) {
uint256 delta = (ONE_ETHER / (10 ** i));
while (true) {
if (
getBuyPriceV2AfterFee(
protocolFeeRatio,
playerFeeRatio,
supply,
amount.add(delta)
) > buyPriceAfterFeeMax
) {
break;
}
amount = amount.add(delta);
}
}
return amount;
}
function getPaymentMaxFor(
address token,
address account,
address spender
) internal view returns (uint256) {
return
MathUpgradeable.min(
IERC20Upgradeable(token).balanceOf(account),
IERC20Upgradeable(token).allowance(account, spender)
);
}
function getBuyAmountMaxWithConditions(
address token,
uint24 protocolFeeRatio,
uint24 playerFeeRatio,
uint256 amountMax,
uint256 buyPriceAfterFeeMax,
uint256 amountBTC
) internal view returns (uint256) {
uint256 supply = IERC20Upgradeable(token).totalSupply();
uint256 amount = 0;
for (uint i = 0; i <= 6; i++) {
uint256 delta = (ONE_ETHER / (10 ** i));
while (true) {
if (
getBuyPriceV2AfterFee(
protocolFeeRatio,
playerFeeRatio,
supply.add(amount.add(delta)),
0.1 ether
).mul(10) >
buyPriceAfterFeeMax ||
amount.add(delta) > amountMax ||
getBuyPriceV2AfterFee(
protocolFeeRatio,
playerFeeRatio,
supply,
amount.add(delta)
) >
amountBTC
) {
break;
}
amount = amount.add(delta);
}
}
return amount;
}
function getSellAmountMaxWithConditions(
address token,
uint24 protocolFeeRatio,
uint24 playerFeeRatio,
uint256 amountMax,
uint256 sellPriceAfterFeeMax,
uint256 amountBTC
) internal view returns (uint256) {
uint256 supply = IERC20Upgradeable(token).totalSupply();
uint256 amount = 0;
for (uint i = 0; i <= 6; i++) {
uint256 delta = (ONE_ETHER / (10 ** i));
while (true) {
if (
getSellPriceV2AfterFee(
protocolFeeRatio,
playerFeeRatio,
supply.add(amount.add(delta)),
0.1 ether
).mul(10) >
sellPriceAfterFeeMax ||
amount.add(delta) > amountMax ||
getSellPriceV2AfterFee(
protocolFeeRatio,
playerFeeRatio,
supply,
amount.add(delta)
) >
amountBTC
) {
break;
}
amount = amount.add(delta);
}
}
if (amountBTC > 0) {
amount = amount.add(PRICE_UNIT);
}
return amount;
}
function getStakingId(
uint24 ratio,
uint256 duration,
bool locked
) internal pure returns (uint256) {
require(
ratio == (ratio / 100) * 100 && ratio >= 0 && ratio <= 15000000,
"NM_IR"
);
require(duration < ONE_ETHER, "NM_ID");
return
(uint256(locked ? 1 : 0).mul(ONE_ETHER).mul(ONE_ETHER)).add(
uint256(ratio).mul(ONE_ETHER).add(duration)
);
}
}
contracts/libraries/TransferHelper.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.0;
// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeApprove: approve failed'
);
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeTransfer: transfer failed'
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::transferFrom: transferFrom failed'
);
}
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, 'TransferHelper::safeTransferETH: ETH transfer failed');
}
}
contracts/storage/PassTokenStakingStorage.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.0;
import {StakingTokenTypes} from "../libraries/StakingTokenTypes.sol";
abstract contract PassTokenStakingStorage {
//
address internal _passTokenFactory;
address internal _swapRouter;
address internal _quoter;
address internal _btc;
// token -> data
mapping(address => mapping(uint256 => StakingTokenTypes.Staking)) _tokenStakings;
mapping(address => uint256) internal _tokenStakingTotal;
mapping(address => mapping(address => uint256)) _tokenStakingBalances;
mapping(address => mapping(bytes32 => StakingTokenTypes.Order)) _tokenStakingOrders;
//
}
Compiler Settings
{"viaIR":true,"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers"]}},"optimizer":{"runs":200,"enabled":true},"libraries":{}}
Contract ABI
[{"type":"event","name":"Initialized","inputs":[{"type":"uint8","name":"version","internalType":"uint8","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"TokenStakingOrderClosed","inputs":[{"type":"address","name":"token","internalType":"address","indexed":false},{"type":"bytes32","name":"orderId","internalType":"bytes32","indexed":false},{"type":"uint24","name":"ratio","internalType":"uint24","indexed":false},{"type":"uint256","name":"duration","internalType":"uint256","indexed":false},{"type":"bool","name":"locked","internalType":"bool","indexed":false},{"type":"address","name":"trader","internalType":"address","indexed":false},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"uint256","name":"interest","internalType":"uint256","indexed":false},{"type":"uint8","name":"status","internalType":"enum StakingTokenTypes.OrderStatus","indexed":false},{"type":"uint256","name":"closedAt","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"TokenStakingOrderCreated","inputs":[{"type":"address","name":"token","internalType":"address","indexed":false},{"type":"bytes32","name":"orderId","internalType":"bytes32","indexed":false},{"type":"uint24","name":"ratio","internalType":"uint24","indexed":false},{"type":"uint256","name":"duration","internalType":"uint256","indexed":false},{"type":"bool","name":"locked","internalType":"bool","indexed":false},{"type":"address","name":"trader","internalType":"address","indexed":false},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"uint256","name":"createdAt","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"TokenStakingUpdated","inputs":[{"type":"address","name":"token","internalType":"address","indexed":false},{"type":"uint8","name":"status","internalType":"enum StakingTokenTypes.Status","indexed":false},{"type":"uint24","name":"ratio","internalType":"uint24","indexed":false},{"type":"uint256","name":"duration","internalType":"uint256","indexed":false},{"type":"bool","name":"locked","internalType":"bool","indexed":false},{"type":"uint256","name":"free","internalType":"uint256","indexed":false},{"type":"uint256","name":"total","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"exactOutputForBtc2Token","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint24","name":"ratio","internalType":"uint24"},{"type":"uint256","name":"amountOut","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"freeStakingBalanceOf","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"address","name":"user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"getPassTokenFactory","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"getTokenCreator","inputs":[{"type":"address","name":"token","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[{"type":"address","name":"passTokenFactory","internalType":"address"},{"type":"address","name":"swapRouter","internalType":"address"},{"type":"address","name":"quoter","internalType":"address"},{"type":"address","name":"btc","internalType":"address"}]},{"type":"function","stateMutability":"payable","outputs":[{"type":"bytes[]","name":"results","internalType":"bytes[]"}],"name":"multicall","inputs":[{"type":"bytes[]","name":"data","internalType":"bytes[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"stakingBalanceOf","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"address","name":"user","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"swapBtc2Token","inputs":[{"type":"uint256","name":"amountBtcMax","internalType":"uint256"},{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"amountOutMin","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"tokenStakingClose","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint24","name":"ratio","internalType":"uint24"},{"type":"uint256","name":"duration","internalType":"uint256"},{"type":"bool","name":"locked","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"tokenStakingOpen","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint24","name":"ratio","internalType":"uint24"},{"type":"uint256","name":"duration","internalType":"uint256"},{"type":"bool","name":"locked","internalType":"bool"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"tokenStakingOrderClose","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"bytes32","name":"orderId","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"tokenStakingOrderCreate","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"bytes32","name":"orderId","internalType":"bytes32"},{"type":"uint24","name":"ratio","internalType":"uint24"},{"type":"uint256","name":"duration","internalType":"uint256"},{"type":"bool","name":"locked","internalType":"bool"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]}]
Contract Creation Code
0x60808060405234610016576123bf908161001c8239f35b600080fdfe6080604052600436101561001257600080fd5b60003560e01c8063138af50014610107578063231033a11461010257806323992bbc146100fd578063715018a6146100f85780637a09bd3a146100f35780638da5cb5b146100ee5780639b86cc92146100e9578063ac9650d8146100e4578063c78418b9146100df578063c955cb2d146100da578063ca6ad381146100d5578063cd32e92a146100d0578063eb7396a4146100cb578063f2fde38b146100c65763f8c8765e146100c157600080fd5b61085a565b6107c9565b610739565b610718565b610685565b610611565b6105d8565b6104cd565b610395565b61036c565b610327565b61029e565b610227565b61015d565b34610130576000366003190112610130576097546040516001600160a01b039091168152602090f35b600080fd5b6001600160a01b0381160361013057565b62ffffff81160361013057565b8015150361013057565b346101305760c03660031901126101305760043561017a81610135565b60443561018681610146565b60843561019281610153565b6097546040516343503b1360e01b81526001600160a01b03858116600483015290949160209186916024918391165afa938415610222576101f2946101e1916000916101f4575b501515610de2565b60a4359260643591602435906114e0565b005b610215915060203d811161021b575b61020d8183610c79565b810190610d18565b386101d9565b503d610203565b610cb0565b346101305760603660031901126101305760243561024481610135565b6097546040516343503b1360e01b81526001600160a01b03838116600483015290929160209184916024918391165afa918215610222576101f292610292916000916101f457501515610de2565b60443590600435611bec565b34610130576000806003193601126102fc576102b861096c565b603380546001600160a01b0319811690915581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b80fd5b60409060031901126101305760043561031781610135565b9060243561032481610135565b90565b3461013057602061036361033a366102ff565b6001600160a01b039182166000908152609d855260408082209290931681526020919091522090565b54604051908152f35b34610130576000366003190112610130576033546040516001600160a01b039091168152602090f35b34610130576080366003190112610130576004356103b281610135565b602435906103bf82610146565b606435906103cc82610153565b6097546040516343503b1360e01b81526001600160a01b03838116600483015290949160209186916024918391165afa938415610222576101f29461041a916000916101f457501515610de2565b60443591611301565b60005b8381106104365750506000910152565b8181015183820152602001610426565b9060209161045f81518092818552858086019101610423565b601f01601f1916010190565b602080820190808352835180925260408301928160408460051b8301019501936000915b84831061049f5750505050505090565b90919293949584806104bd600193603f198682030187528a51610446565b980193019301919493929061048f565b6020366003190112610130576004803567ffffffffffffffff918282116101305736602383011215610130578181013592831161013057602490818301928236918660051b0101116101305761052284611ea2565b9360005b81811061053f576040518061053b888261046b565b0390f35b60008061054d838589611f11565b6040939161055f855180938193611f58565b0390305af49061056d611f82565b9182901561059c57505090610597916105868289612022565b526105918188612022565b50611eec565b610526565b86838792604482511061013057826105d493856105bf9401518301019101611fb2565b925162461bcd60e51b81529283928301612011565b0390fd5b346101305760203660031901126101305760206105ff6004356105fa81610135565b610cbc565b6040516001600160a01b039091168152f35b346101305760403660031901126101305760043561062e81610135565b6097546040516343503b1360e01b81526001600160a01b03838116600483015290929160209184916024918391165afa918215610222576101f29261067c916000916101f457501515610de2565b6024359061184f565b34610130576060366003190112610130576004356106a281610135565b6024356106ae81610146565b6097546040516343503b1360e01b81526001600160a01b03848116600483015290939160209185916024918391165afa918215610222576106ff6107089361053b956000916101f457501515610de2565b60443591610f11565b6040519081529081906020820190565b3461013057602061073161072b366102ff565b90610d27565b604051908152f35b346101305760a03660031901126101305760043561075681610135565b60243561076281610146565b60643561076e81610153565b6097546040516343503b1360e01b81526001600160a01b03858116600483015290949160209186916024918391165afa938415610222576101f2946107bc916000916101f457501515610de2565b6084359260443591611107565b34610130576020366003190112610130576004356107e681610135565b6107ee61096c565b6001600160a01b03811615610806576101f2906109c4565b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b346101305760803660031901126101305760043561087781610135565b6108e060243561088681610135565b60443561089281610135565b6064359161089f83610135565b600054946108c460ff8760081c16158097819861095e575b811561093e575b50610a0d565b856108d7600160ff196000541617600055565b61092557610a70565b6108e657005b6108f661ff001960005416600055565b604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602090a1005b61093961010061ff00196000541617600055565b610a70565b303b15915081610950575b50386108be565b6001915060ff161438610949565b600160ff82161091506108b7565b6033546001600160a01b0316330361098057565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b603380546001600160a01b039283166001600160a01b0319821681179092559091167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b15610a1457565b60405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608490fd5b90600093918493610a9060ff865460081c16610a8b81610be2565b610be2565b610a99336109c4565b610aad60ff865460081c16610a8b81610be2565b600160655560018060a01b038091816bffffffffffffffffffffffff60a01b941684609754161760975581851684609854161760985516826099541617609955831690609a541617609a5582604051610b4081610b32602082019563095ea7b360e01b875260248301919091604081019260018060a01b031681526020600019910152565b03601f198101835282610c79565b51925af1610b4c611f82565b81610bb3575b5015610b5a57565b60405162461bcd60e51b815260206004820152602b60248201527f5472616e7366657248656c7065723a3a73616665417070726f76653a2061707060448201526a1c9bdd994819985a5b195960aa1b6064820152608490fd5b8051801592508215610bc8575b505038610b52565b610bdb9250602080918301019101612186565b3880610bc0565b15610be957565b60405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608490fd5b634e487b7160e01b600052604160045260246000fd5b60a0810190811067ffffffffffffffff821117610c7457604052565b610c42565b90601f8019910116810190811067ffffffffffffffff821117610c7457604052565b90816020910312610130575161032481610135565b6040513d6000823e3d90fd5b60405162ee2cb160e41b815290602090829060049082906001600160a01b03165afa90811561022257600091610cf0575090565b610324915060203d8111610d11575b610d098183610c79565b810190610c9b565b503d610cff565b90816020910312610130575190565b6040516370a0823160e01b81526001600160a01b0383811660048301529190911691602082602481865afa91821561022257600092610d9d575b50610d8b9192600052609d60205260406000209060018060a01b0316600052602052604060002090565b548103908111610d985790565b610dbf565b610d8b9250610db99060203d811161021b5761020d8183610c79565b91610d61565b634e487b7160e01b600052601160045260246000fd5b91908203918211610d9857565b15610de957565b60405162461bcd60e51b81526020600482015260076024820152665054535f545a4160c81b6044820152606490fd5b15610e1f57565b60405162461bcd60e51b815260206004820152600660248201526505054535f49560d41b6044820152606490fd5b90816020910312610130575161032481610146565b60405190610e6f82610c58565b565b60405190610100820182811067ffffffffffffffff821117610c7457604052565b9190826080910312610130578151916020810151610eaf81610135565b91604082015163ffffffff811681036101305760609092015190565b919091608060a08201938160018060a01b03918281511685528260208201511660208601526040810151604086015262ffffff6060820151166060860152015116910152565b91610f389062ffffff620f424093821515806110c7575b610f3190610e18565b169061206f565b60405163041eb2d560e21b81526001600160a01b0393929091049060209081816004818888165afa80156102225782916000916110aa575b5060046040518097819363ddca3f4360e01b8352165afa9283156102225761101660809461103794600097889261107b575b5060995461100590610fca90610fbe906001600160a01b031681565b6001600160a01b031690565b609a549096906001600160a01b031690610ff4610fe5610e62565b6001600160a01b039098168852565b6001600160a01b0390911690860152565b604084015262ffffff166060830152565b8484820152604051948580948193635e90b82560e11b835260048301610ecb565b03925af19081156102225760009161104d575090565b61106e915060803d8111611074575b6110668183610c79565b810190610e92565b50505090565b503d61105c565b61109c919250853d87116110a3575b6110948183610c79565b810190610e4d565b9038610fa2565b503d61108a565b6110c19150823d8411610d1157610d098183610c79565b38610f70565b508082161515610f28565b156110d957565b60405162461bcd60e51b81526020600482015260066024820152655054535f4e4360d01b6044820152606490fd5b60405162ee2cb160e41b81529193909290916001600160a01b038085169190602082600481865afa9081156102225761114b9260009261122f575b501633146110d2565b6111568383876120b6565b90600052609b602052604060002090600052602052620f42406111ab61118966038d7ea4c6800060406000209804612036565b61119481151561124f565b875460ff1916600117885562ffffff87169061206f565b046001860192835491808301809311610d985760008051602061236a833981519152976111e26002928561122a985530338a61227e565b015492604051968796879262ffffff60c095929897969360e086019960018060a01b031686526001602087015216604085015260608401521515608083015260a08201520152565b0390a1565b61124891925060203d8111610d1157610d098183610c79565b9038611142565b1561125657565b60405162461bcd60e51b81526020600482015260066024820152655054535f494160d01b6044820152606490fd5b634e487b7160e01b600052602160045260246000fd5b600311156112a457565b611284565b6001600160a01b03909116815260e0810197969592949093909160038110156112a45760c09562ffffff91602087015216604085015260608401521515608083015260a08201520152565b91908201809211610d9857565b60405162ee2cb160e41b815293919290916001600160a01b039190828416602087600481845afa9687156102225760008051602061236a8339815191529761122a956113579260009261122f57501633146110d2565b6113628284886120b6565b90600052609b60205260406000209060005260205260026040600020611397600160ff8354166113918161129a565b14611401565b805460ff191660021781556113b660018201600081549155338861219b565b01549160405195869586919262ffffff60c094979695929760e085019860018060a01b0316855260026020860152166040840152606083015215156080820152600060a08201520152565b1561140857565b60405162461bcd60e51b81526020600482015260066024820152655054535f495360d01b6044820152606490fd5b1561143d57565b60405162461bcd60e51b8152602060048201526006602482015265282a29afa4a160d11b6044820152606490fd5b600411156112a457565b1561147c57565b60405162461bcd60e51b81526020600482015260076024820152665054535f424f5360c81b6044820152606490fd5b156114b257565b60405162461bcd60e51b8152602060048201526006602482015265282a29afa4a360d11b6044820152606490fd5b947fc8962d842d234374a20d25f073e372bee97f667d7b30f6a9dc4f78d891a3c8059561122a93949560008051602061236a8339815191528661154f611527848b846120b6565b6001600160a01b0386166000908152609b602052604090205b90600052602052604060002090565b9461172b611573886115408860018060a01b0316600052609e602052604060002090565b966115a666038d7ea4c6800061158a835460ff1690565b946115948661129a565b6115a060018714611401565b04612036565b976115b289151561124f565b6115c7896115c0338b610d27565b1015611436565b6115e46115d5825460ff1690565b6115de8161146b565b15611475565b805463ffffff001916600886901b63ffffff00161781558c600182015561161a87600583019060ff801983541691151516179055565b6002810180546001600160a01b03191633179055805460ff191660011781558860048201556003429101556002620f424061165a62ffffff87168b61206f565b049161167760018201938454611672828210156114ab565b610dd5565b80935501906116878983546112f4565b8092556116b0896116aa8a60018060a01b0316600052609c602052604060002090565b546112f4565b6001600160a01b0389166000908152609c6020908152604080832093909355609d9052206116f8908a906116aa9033905b9060018060a01b0316600052602052604060002090565b6001600160a01b0389166000908152609d6020526040902061171b9033906116e1565b55868d6040519687968b886112a9565b0390a1604080516001600160a01b039093168352602083019490945262ffffff90951692810192909252606082019490945291151560808301523360a083015260c08201929092524260e0820152908190610100820190565b1561178b57565b60405162461bcd60e51b81526020600482015260066024820152655054535f494360d01b6044820152606490fd5b156117c057565b60405162461bcd60e51b81526020600482015260066024820152655054535f4c4f60d01b6044820152606490fd5b9694919a999897959262ffffff9094919461014089019c60018060a01b038097168a5260208a01521660408801526060870152151560808601521660a084015260c083015260e082015260048210156112a457610120916101008201520152565b90611870816115408460018060a01b0316600052609e602052604060002090565b6002810180549093919291906001600160a01b03169062ffffff84546118a4600160ff831661189e8161146b565b14611475565b60081c16936001810154956118bd600583015460ff1690565b936004830154906003840154986118f56118d888838c6120b6565b6001600160a01b0388166000908152609b60205260409020611540565b60028101611904858254610dd5565b80915561192d856119278a60018060a01b0316600052609c602052604060002090565b54610dd5565b6001600160a01b0389166000908152609c6020908152604080832093909355609d9052206119629086906119279087906116e1565b6001600160a01b0389166000908152609d602052604090206119859086906116e1565b55620f42406119948c8761206f565b049560016119a3845460ff1690565b9301906119b28583549f6112f4565b4210611a38575050918091888c8b9560029a6119d590600260ff19825416179055565b6119e08a898561219b565b7f451835efb5bb4f36d1a05ee99d316f9e2f8e9b8374b299f1b571e3718be460749f61122a9d60008051602061236a83398151915296611a27945b604051978897886112a9565b0390a1604051998a9942988b6117ee565b54909c989997989697959694959490611a5b906001600160a01b03163314611784565b611a6585156117b9565b611a78600399600360ff19825416179055565b611a818361129a565b60018303611ae0579189611a2760008051602061236a833981519152937f451835efb5bb4f36d1a05ee99d316f9e2f8e9b8374b299f1b571e3718be460749f8f988861122a9f9e9d9c9b9a611ad88e849c9b6112f4565b809455611a1b565b9098979695949392919b50611af48c61129a565b60028c03611b52577f451835efb5bb4f36d1a05ee99d316f9e2f8e9b8374b299f1b571e3718be460749b88611a2761122a9b60008051602061236a833981519152948f878991611b4d8e611b4789610cbc565b8961219b565b611a1b565b60405162461bcd60e51b81526020600482015260066024820152655054535f425360d01b6044820152606490fd5b15611b8757565b60405162461bcd60e51b8152602060048201526007602482015266282a29afa4a0a160c91b6044820152606490fd5b15611bbd57565b60405162461bcd60e51b8152602060048201526007602482015266141514d7d2505560ca1b6044820152606490fd5b91909181611bf957505050565b609a546001600160a01b03166040805163041eb2d560e21b815260209591926001600160a01b03929187816004818787165afa8015610222578891600091611e6d575b50600486518096819363ddca3f4360e01b8352165afa92831561022257600093611e4d575b50600092936080611cd5611c82610fbe610fbe60995460018060a01b031690565b611c8a610e62565b6001600160a01b03861681526001600160a01b038716818d01528085018b905262ffffff8916606082015287848201528451978880948193635e90b82560e11b835260048301610ecb565b03925af1958615610222576000968996611de7968992611e24575b50611d018293611d4e931115611b80565b611d0d8330338861227e565b609854611d4390611d2890610fbe906001600160a01b031681565b96611d34610fe5610e71565b6001600160a01b0316868a0152565b62ffffff1684840152565b33606084015286196080840190815260a0840191825260c0840188815260e08501898152935163414bf38960e01b815285516001600160a01b039081166004830152602087015181166024830152604087015162ffffff1660448301526060909601518616606482015291516084830152915160a4820152905160c4820152905190911660e48201529384928391908290610104820190565b03925af190811561022257610e6f93600092611e07575b50501015611bb6565b611e1d9250803d1061021b5761020d8183610c79565b3880611dfe565b611d4e9250611e43611d019160803d8111611074576110668183610c79565b5050509250611cf0565b60009350611e6790883d8a116110a3576110948183610c79565b92611c61565b611e849150823d8411610d1157610d098183610c79565b38611c3c565b67ffffffffffffffff8111610c745760051b60200190565b90611eac82611e8a565b611eb96040519182610c79565b8281528092611eca601f1991611e8a565b019060005b828110611edb57505050565b806060602080938501015201611ecf565b6000198114610d985760010190565b634e487b7160e01b600052603260045260246000fd5b9190811015611f535760051b81013590601e198136030182121561013057019081359167ffffffffffffffff8311610130576020018236038113610130579190565b611efb565b908092918237016000815290565b67ffffffffffffffff8111610c7457601f01601f191660200190565b3d15611fad573d90611f9382611f66565b91611fa16040519384610c79565b82523d6000602084013e565b606090565b6020818303126101305780519067ffffffffffffffff8211610130570181601f82011215610130578051611fe581611f66565b92611ff36040519485610c79565b81845260208284010111610130576103249160208085019101610423565b906020610324928181520190610446565b8051821015611f535760209160051b010190565b9066038d7ea4c6800091828102928184041490151715610d9857565b90670de0b6b3a764000091828102928184041490151715610d9857565b81810292918115918404141715610d9857565b1561208957565b60405162461bcd60e51b8152602060048201526005602482015264139357d25160da1b6044820152606490fd5b909162ffffff809216916064818185041602908116908103610d985782148061217e575b80612171575b15612144578261212d91612100670de0b6b3a76400006103249610612082565b60009015612133575061212861212261211d60ff60015b16612052565b612052565b93612052565b6112f4565b906112f4565b61212261211d60ff61212893612117565b60405162461bcd60e51b81526020600482015260056024820152642726afa4a960d91b6044820152606490fd5b5062e4e1c08211156120e0565b5060016120da565b90816020910312610130575161032481610153565b60405163a9059cbb60e01b602082019081526001600160a01b039093166024820152604481019390935260009283929083906121da8160648101610b32565b51925af16121e6611f82565b8161224f575b50156121f457565b60405162461bcd60e51b815260206004820152602d60248201527f5472616e7366657248656c7065723a3a736166655472616e736665723a20747260448201526c185b9cd9995c8819985a5b1959609a1b6064820152608490fd5b8051801592508215612264575b5050386121ec565b6122779250602080918301019101612186565b388061225c565b9091600080949381946040519160208301946323b872dd60e01b865260018060a01b0380921660248501521660448301526064820152606481526122c181610c58565b51925af16122cd611f82565b8161233a575b50156122db57565b60405162461bcd60e51b815260206004820152603160248201527f5472616e7366657248656c7065723a3a7472616e7366657246726f6d3a207472604482015270185b9cd9995c919c9bdb4819985a5b1959607a1b6064820152608490fd5b805180159250821561234f575b5050386122d3565b6123629250602080918301019101612186565b388061234756fe2d3e35c57c146665d6f44dca10ec8c5302d4f7b8665aced480d377637ad5798ea264697066735822122018dd1de8ccaac675d8d6ed45bb7318a2c9a1e977536978167a004e13fd679a1264736f6c63430008130033
Deployed ByteCode
0x6080604052600436101561001257600080fd5b60003560e01c8063138af50014610107578063231033a11461010257806323992bbc146100fd578063715018a6146100f85780637a09bd3a146100f35780638da5cb5b146100ee5780639b86cc92146100e9578063ac9650d8146100e4578063c78418b9146100df578063c955cb2d146100da578063ca6ad381146100d5578063cd32e92a146100d0578063eb7396a4146100cb578063f2fde38b146100c65763f8c8765e146100c157600080fd5b61085a565b6107c9565b610739565b610718565b610685565b610611565b6105d8565b6104cd565b610395565b61036c565b610327565b61029e565b610227565b61015d565b34610130576000366003190112610130576097546040516001600160a01b039091168152602090f35b600080fd5b6001600160a01b0381160361013057565b62ffffff81160361013057565b8015150361013057565b346101305760c03660031901126101305760043561017a81610135565b60443561018681610146565b60843561019281610153565b6097546040516343503b1360e01b81526001600160a01b03858116600483015290949160209186916024918391165afa938415610222576101f2946101e1916000916101f4575b501515610de2565b60a4359260643591602435906114e0565b005b610215915060203d811161021b575b61020d8183610c79565b810190610d18565b386101d9565b503d610203565b610cb0565b346101305760603660031901126101305760243561024481610135565b6097546040516343503b1360e01b81526001600160a01b03838116600483015290929160209184916024918391165afa918215610222576101f292610292916000916101f457501515610de2565b60443590600435611bec565b34610130576000806003193601126102fc576102b861096c565b603380546001600160a01b0319811690915581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b80fd5b60409060031901126101305760043561031781610135565b9060243561032481610135565b90565b3461013057602061036361033a366102ff565b6001600160a01b039182166000908152609d855260408082209290931681526020919091522090565b54604051908152f35b34610130576000366003190112610130576033546040516001600160a01b039091168152602090f35b34610130576080366003190112610130576004356103b281610135565b602435906103bf82610146565b606435906103cc82610153565b6097546040516343503b1360e01b81526001600160a01b03838116600483015290949160209186916024918391165afa938415610222576101f29461041a916000916101f457501515610de2565b60443591611301565b60005b8381106104365750506000910152565b8181015183820152602001610426565b9060209161045f81518092818552858086019101610423565b601f01601f1916010190565b602080820190808352835180925260408301928160408460051b8301019501936000915b84831061049f5750505050505090565b90919293949584806104bd600193603f198682030187528a51610446565b980193019301919493929061048f565b6020366003190112610130576004803567ffffffffffffffff918282116101305736602383011215610130578181013592831161013057602490818301928236918660051b0101116101305761052284611ea2565b9360005b81811061053f576040518061053b888261046b565b0390f35b60008061054d838589611f11565b6040939161055f855180938193611f58565b0390305af49061056d611f82565b9182901561059c57505090610597916105868289612022565b526105918188612022565b50611eec565b610526565b86838792604482511061013057826105d493856105bf9401518301019101611fb2565b925162461bcd60e51b81529283928301612011565b0390fd5b346101305760203660031901126101305760206105ff6004356105fa81610135565b610cbc565b6040516001600160a01b039091168152f35b346101305760403660031901126101305760043561062e81610135565b6097546040516343503b1360e01b81526001600160a01b03838116600483015290929160209184916024918391165afa918215610222576101f29261067c916000916101f457501515610de2565b6024359061184f565b34610130576060366003190112610130576004356106a281610135565b6024356106ae81610146565b6097546040516343503b1360e01b81526001600160a01b03848116600483015290939160209185916024918391165afa918215610222576106ff6107089361053b956000916101f457501515610de2565b60443591610f11565b6040519081529081906020820190565b3461013057602061073161072b366102ff565b90610d27565b604051908152f35b346101305760a03660031901126101305760043561075681610135565b60243561076281610146565b60643561076e81610153565b6097546040516343503b1360e01b81526001600160a01b03858116600483015290949160209186916024918391165afa938415610222576101f2946107bc916000916101f457501515610de2565b6084359260443591611107565b34610130576020366003190112610130576004356107e681610135565b6107ee61096c565b6001600160a01b03811615610806576101f2906109c4565b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b346101305760803660031901126101305760043561087781610135565b6108e060243561088681610135565b60443561089281610135565b6064359161089f83610135565b600054946108c460ff8760081c16158097819861095e575b811561093e575b50610a0d565b856108d7600160ff196000541617600055565b61092557610a70565b6108e657005b6108f661ff001960005416600055565b604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602090a1005b61093961010061ff00196000541617600055565b610a70565b303b15915081610950575b50386108be565b6001915060ff161438610949565b600160ff82161091506108b7565b6033546001600160a01b0316330361098057565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b603380546001600160a01b039283166001600160a01b0319821681179092559091167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b15610a1457565b60405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608490fd5b90600093918493610a9060ff865460081c16610a8b81610be2565b610be2565b610a99336109c4565b610aad60ff865460081c16610a8b81610be2565b600160655560018060a01b038091816bffffffffffffffffffffffff60a01b941684609754161760975581851684609854161760985516826099541617609955831690609a541617609a5582604051610b4081610b32602082019563095ea7b360e01b875260248301919091604081019260018060a01b031681526020600019910152565b03601f198101835282610c79565b51925af1610b4c611f82565b81610bb3575b5015610b5a57565b60405162461bcd60e51b815260206004820152602b60248201527f5472616e7366657248656c7065723a3a73616665417070726f76653a2061707060448201526a1c9bdd994819985a5b195960aa1b6064820152608490fd5b8051801592508215610bc8575b505038610b52565b610bdb9250602080918301019101612186565b3880610bc0565b15610be957565b60405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608490fd5b634e487b7160e01b600052604160045260246000fd5b60a0810190811067ffffffffffffffff821117610c7457604052565b610c42565b90601f8019910116810190811067ffffffffffffffff821117610c7457604052565b90816020910312610130575161032481610135565b6040513d6000823e3d90fd5b60405162ee2cb160e41b815290602090829060049082906001600160a01b03165afa90811561022257600091610cf0575090565b610324915060203d8111610d11575b610d098183610c79565b810190610c9b565b503d610cff565b90816020910312610130575190565b6040516370a0823160e01b81526001600160a01b0383811660048301529190911691602082602481865afa91821561022257600092610d9d575b50610d8b9192600052609d60205260406000209060018060a01b0316600052602052604060002090565b548103908111610d985790565b610dbf565b610d8b9250610db99060203d811161021b5761020d8183610c79565b91610d61565b634e487b7160e01b600052601160045260246000fd5b91908203918211610d9857565b15610de957565b60405162461bcd60e51b81526020600482015260076024820152665054535f545a4160c81b6044820152606490fd5b15610e1f57565b60405162461bcd60e51b815260206004820152600660248201526505054535f49560d41b6044820152606490fd5b90816020910312610130575161032481610146565b60405190610e6f82610c58565b565b60405190610100820182811067ffffffffffffffff821117610c7457604052565b9190826080910312610130578151916020810151610eaf81610135565b91604082015163ffffffff811681036101305760609092015190565b919091608060a08201938160018060a01b03918281511685528260208201511660208601526040810151604086015262ffffff6060820151166060860152015116910152565b91610f389062ffffff620f424093821515806110c7575b610f3190610e18565b169061206f565b60405163041eb2d560e21b81526001600160a01b0393929091049060209081816004818888165afa80156102225782916000916110aa575b5060046040518097819363ddca3f4360e01b8352165afa9283156102225761101660809461103794600097889261107b575b5060995461100590610fca90610fbe906001600160a01b031681565b6001600160a01b031690565b609a549096906001600160a01b031690610ff4610fe5610e62565b6001600160a01b039098168852565b6001600160a01b0390911690860152565b604084015262ffffff166060830152565b8484820152604051948580948193635e90b82560e11b835260048301610ecb565b03925af19081156102225760009161104d575090565b61106e915060803d8111611074575b6110668183610c79565b810190610e92565b50505090565b503d61105c565b61109c919250853d87116110a3575b6110948183610c79565b810190610e4d565b9038610fa2565b503d61108a565b6110c19150823d8411610d1157610d098183610c79565b38610f70565b508082161515610f28565b156110d957565b60405162461bcd60e51b81526020600482015260066024820152655054535f4e4360d01b6044820152606490fd5b60405162ee2cb160e41b81529193909290916001600160a01b038085169190602082600481865afa9081156102225761114b9260009261122f575b501633146110d2565b6111568383876120b6565b90600052609b602052604060002090600052602052620f42406111ab61118966038d7ea4c6800060406000209804612036565b61119481151561124f565b875460ff1916600117885562ffffff87169061206f565b046001860192835491808301809311610d985760008051602061236a833981519152976111e26002928561122a985530338a61227e565b015492604051968796879262ffffff60c095929897969360e086019960018060a01b031686526001602087015216604085015260608401521515608083015260a08201520152565b0390a1565b61124891925060203d8111610d1157610d098183610c79565b9038611142565b1561125657565b60405162461bcd60e51b81526020600482015260066024820152655054535f494160d01b6044820152606490fd5b634e487b7160e01b600052602160045260246000fd5b600311156112a457565b611284565b6001600160a01b03909116815260e0810197969592949093909160038110156112a45760c09562ffffff91602087015216604085015260608401521515608083015260a08201520152565b91908201809211610d9857565b60405162ee2cb160e41b815293919290916001600160a01b039190828416602087600481845afa9687156102225760008051602061236a8339815191529761122a956113579260009261122f57501633146110d2565b6113628284886120b6565b90600052609b60205260406000209060005260205260026040600020611397600160ff8354166113918161129a565b14611401565b805460ff191660021781556113b660018201600081549155338861219b565b01549160405195869586919262ffffff60c094979695929760e085019860018060a01b0316855260026020860152166040840152606083015215156080820152600060a08201520152565b1561140857565b60405162461bcd60e51b81526020600482015260066024820152655054535f495360d01b6044820152606490fd5b1561143d57565b60405162461bcd60e51b8152602060048201526006602482015265282a29afa4a160d11b6044820152606490fd5b600411156112a457565b1561147c57565b60405162461bcd60e51b81526020600482015260076024820152665054535f424f5360c81b6044820152606490fd5b156114b257565b60405162461bcd60e51b8152602060048201526006602482015265282a29afa4a360d11b6044820152606490fd5b947fc8962d842d234374a20d25f073e372bee97f667d7b30f6a9dc4f78d891a3c8059561122a93949560008051602061236a8339815191528661154f611527848b846120b6565b6001600160a01b0386166000908152609b602052604090205b90600052602052604060002090565b9461172b611573886115408860018060a01b0316600052609e602052604060002090565b966115a666038d7ea4c6800061158a835460ff1690565b946115948661129a565b6115a060018714611401565b04612036565b976115b289151561124f565b6115c7896115c0338b610d27565b1015611436565b6115e46115d5825460ff1690565b6115de8161146b565b15611475565b805463ffffff001916600886901b63ffffff00161781558c600182015561161a87600583019060ff801983541691151516179055565b6002810180546001600160a01b03191633179055805460ff191660011781558860048201556003429101556002620f424061165a62ffffff87168b61206f565b049161167760018201938454611672828210156114ab565b610dd5565b80935501906116878983546112f4565b8092556116b0896116aa8a60018060a01b0316600052609c602052604060002090565b546112f4565b6001600160a01b0389166000908152609c6020908152604080832093909355609d9052206116f8908a906116aa9033905b9060018060a01b0316600052602052604060002090565b6001600160a01b0389166000908152609d6020526040902061171b9033906116e1565b55868d6040519687968b886112a9565b0390a1604080516001600160a01b039093168352602083019490945262ffffff90951692810192909252606082019490945291151560808301523360a083015260c08201929092524260e0820152908190610100820190565b1561178b57565b60405162461bcd60e51b81526020600482015260066024820152655054535f494360d01b6044820152606490fd5b156117c057565b60405162461bcd60e51b81526020600482015260066024820152655054535f4c4f60d01b6044820152606490fd5b9694919a999897959262ffffff9094919461014089019c60018060a01b038097168a5260208a01521660408801526060870152151560808601521660a084015260c083015260e082015260048210156112a457610120916101008201520152565b90611870816115408460018060a01b0316600052609e602052604060002090565b6002810180549093919291906001600160a01b03169062ffffff84546118a4600160ff831661189e8161146b565b14611475565b60081c16936001810154956118bd600583015460ff1690565b936004830154906003840154986118f56118d888838c6120b6565b6001600160a01b0388166000908152609b60205260409020611540565b60028101611904858254610dd5565b80915561192d856119278a60018060a01b0316600052609c602052604060002090565b54610dd5565b6001600160a01b0389166000908152609c6020908152604080832093909355609d9052206119629086906119279087906116e1565b6001600160a01b0389166000908152609d602052604090206119859086906116e1565b55620f42406119948c8761206f565b049560016119a3845460ff1690565b9301906119b28583549f6112f4565b4210611a38575050918091888c8b9560029a6119d590600260ff19825416179055565b6119e08a898561219b565b7f451835efb5bb4f36d1a05ee99d316f9e2f8e9b8374b299f1b571e3718be460749f61122a9d60008051602061236a83398151915296611a27945b604051978897886112a9565b0390a1604051998a9942988b6117ee565b54909c989997989697959694959490611a5b906001600160a01b03163314611784565b611a6585156117b9565b611a78600399600360ff19825416179055565b611a818361129a565b60018303611ae0579189611a2760008051602061236a833981519152937f451835efb5bb4f36d1a05ee99d316f9e2f8e9b8374b299f1b571e3718be460749f8f988861122a9f9e9d9c9b9a611ad88e849c9b6112f4565b809455611a1b565b9098979695949392919b50611af48c61129a565b60028c03611b52577f451835efb5bb4f36d1a05ee99d316f9e2f8e9b8374b299f1b571e3718be460749b88611a2761122a9b60008051602061236a833981519152948f878991611b4d8e611b4789610cbc565b8961219b565b611a1b565b60405162461bcd60e51b81526020600482015260066024820152655054535f425360d01b6044820152606490fd5b15611b8757565b60405162461bcd60e51b8152602060048201526007602482015266282a29afa4a0a160c91b6044820152606490fd5b15611bbd57565b60405162461bcd60e51b8152602060048201526007602482015266141514d7d2505560ca1b6044820152606490fd5b91909181611bf957505050565b609a546001600160a01b03166040805163041eb2d560e21b815260209591926001600160a01b03929187816004818787165afa8015610222578891600091611e6d575b50600486518096819363ddca3f4360e01b8352165afa92831561022257600093611e4d575b50600092936080611cd5611c82610fbe610fbe60995460018060a01b031690565b611c8a610e62565b6001600160a01b03861681526001600160a01b038716818d01528085018b905262ffffff8916606082015287848201528451978880948193635e90b82560e11b835260048301610ecb565b03925af1958615610222576000968996611de7968992611e24575b50611d018293611d4e931115611b80565b611d0d8330338861227e565b609854611d4390611d2890610fbe906001600160a01b031681565b96611d34610fe5610e71565b6001600160a01b0316868a0152565b62ffffff1684840152565b33606084015286196080840190815260a0840191825260c0840188815260e08501898152935163414bf38960e01b815285516001600160a01b039081166004830152602087015181166024830152604087015162ffffff1660448301526060909601518616606482015291516084830152915160a4820152905160c4820152905190911660e48201529384928391908290610104820190565b03925af190811561022257610e6f93600092611e07575b50501015611bb6565b611e1d9250803d1061021b5761020d8183610c79565b3880611dfe565b611d4e9250611e43611d019160803d8111611074576110668183610c79565b5050509250611cf0565b60009350611e6790883d8a116110a3576110948183610c79565b92611c61565b611e849150823d8411610d1157610d098183610c79565b38611c3c565b67ffffffffffffffff8111610c745760051b60200190565b90611eac82611e8a565b611eb96040519182610c79565b8281528092611eca601f1991611e8a565b019060005b828110611edb57505050565b806060602080938501015201611ecf565b6000198114610d985760010190565b634e487b7160e01b600052603260045260246000fd5b9190811015611f535760051b81013590601e198136030182121561013057019081359167ffffffffffffffff8311610130576020018236038113610130579190565b611efb565b908092918237016000815290565b67ffffffffffffffff8111610c7457601f01601f191660200190565b3d15611fad573d90611f9382611f66565b91611fa16040519384610c79565b82523d6000602084013e565b606090565b6020818303126101305780519067ffffffffffffffff8211610130570181601f82011215610130578051611fe581611f66565b92611ff36040519485610c79565b81845260208284010111610130576103249160208085019101610423565b906020610324928181520190610446565b8051821015611f535760209160051b010190565b9066038d7ea4c6800091828102928184041490151715610d9857565b90670de0b6b3a764000091828102928184041490151715610d9857565b81810292918115918404141715610d9857565b1561208957565b60405162461bcd60e51b8152602060048201526005602482015264139357d25160da1b6044820152606490fd5b909162ffffff809216916064818185041602908116908103610d985782148061217e575b80612171575b15612144578261212d91612100670de0b6b3a76400006103249610612082565b60009015612133575061212861212261211d60ff60015b16612052565b612052565b93612052565b6112f4565b906112f4565b61212261211d60ff61212893612117565b60405162461bcd60e51b81526020600482015260056024820152642726afa4a960d91b6044820152606490fd5b5062e4e1c08211156120e0565b5060016120da565b90816020910312610130575161032481610153565b60405163a9059cbb60e01b602082019081526001600160a01b039093166024820152604481019390935260009283929083906121da8160648101610b32565b51925af16121e6611f82565b8161224f575b50156121f457565b60405162461bcd60e51b815260206004820152602d60248201527f5472616e7366657248656c7065723a3a736166655472616e736665723a20747260448201526c185b9cd9995c8819985a5b1959609a1b6064820152608490fd5b8051801592508215612264575b5050386121ec565b6122779250602080918301019101612186565b388061225c565b9091600080949381946040519160208301946323b872dd60e01b865260018060a01b0380921660248501521660448301526064820152606481526122c181610c58565b51925af16122cd611f82565b8161233a575b50156122db57565b60405162461bcd60e51b815260206004820152603160248201527f5472616e7366657248656c7065723a3a7472616e7366657246726f6d3a207472604482015270185b9cd9995c919c9bdb4819985a5b1959607a1b6064820152608490fd5b805180159250821561234f575b5050386122d3565b6123629250602080918301019101612186565b388061234756fe2d3e35c57c146665d6f44dca10ec8c5302d4f7b8665aced480d377637ad5798ea264697066735822122018dd1de8ccaac675d8d6ed45bb7318a2c9a1e977536978167a004e13fd679a1264736f6c63430008130033