Overview
CRO Balance
0 CRO
CRO Value
$0.00More Info
Private Name Tags
ContractCreator
Loading...
Loading
Contract Name:
PositionManager
Compiler Version
v0.8.17+commit.8df45f5f
Optimization Enabled:
Yes with 1 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; import "../access/Governable.sol"; import "./interfaces/ICircuitBreaker.sol"; import "./interfaces/IPositionManager.sol"; import "./interfaces/IRouter.sol"; import "./interfaces/IVault.sol"; import "./interfaces/IOrderBook.sol"; import "../peripherals/interfaces/ITimelock.sol"; import "../tokens/interfaces/IWETH.sol"; contract PositionManager is IPositionManager, ReentrancyGuardUpgradeable, Governable { using SafeERC20Upgradeable for IERC20Upgradeable; uint256 public constant BASIS_POINTS_DIVISOR = 10000; address public admin; address public feeAdmin; // deprecated, this is inherited from BasePositionManager before, but not used in this contract address public vault; address public shortsTracker; // deprecated address public router; // deprecated address public weth; uint256 public depositFee; // deprecated, this is inherited from BasePositionManager before, but not used in this contract uint256 public increasePositionBufferBps; address public referralStorage; // deprecated, this is inherited from BasePositionManager before, but not used in this contract mapping (address => uint256) public feeReserves; // deprecated, this is inherited from BasePositionManager before, but not used in this contract mapping (address => uint256) public override maxGlobalLongSizes; mapping (address => uint256) public override maxGlobalShortSizes; address public orderBook; bool public inLegacyMode; // deprecated bool public shouldValidateIncreaseOrder; mapping (address => bool) public isOrderKeeper; mapping (address => bool) public isPartner; // deprecated mapping (address => bool) public isLiquidator; ICircuitBreaker public circuitBreaker; event SetDepositFee(uint256 depositFee); event SetIncreasePositionBufferBps(uint256 increasePositionBufferBps); event SetReferralManager(address referralManager); event SetAdmin(address admin); event SetFeeAdmin(address feeAdmin); event WithdrawFees(address token, address receiver, uint256 amount); event SetMaxGlobalSizes( address[] tokens, uint256[] longSizes, uint256[] shortSizes ); event SetOrderKeeper(address indexed account, bool isActive); event SetLiquidator(address indexed account, bool isActive); event SetPartner(address account, bool isActive); event SetInLegacyMode(bool inLegacyMode); event SetShouldValidateIncreaseOrder(bool shouldValidateIncreaseOrder); modifier onlyAdminOrGov() { require(msg.sender == admin || msg.sender == gov, "PositionManager: forbidden"); _; } modifier onlyOrderKeeper() { require(isOrderKeeper[msg.sender], "PositionManager: forbidden"); _; } modifier onlyLiquidator() { require(isLiquidator[msg.sender], "PositionManager: forbidden"); _; } modifier onlyPartnersOrLegacyMode() { require(isPartner[msg.sender] || inLegacyMode, "PositionManager: forbidden"); _; } function initialize( address _vault, address _weth, address _orderBook ) public initializer { __ReentrancyGuard_init(); gov = msg.sender; vault = _vault; weth = _weth; increasePositionBufferBps = 100; admin = msg.sender; orderBook = _orderBook; shouldValidateIncreaseOrder = true; } receive() external payable { require(msg.sender == weth, "PositionManager: invalid sender"); } function setAdmin(address _admin) external onlyGov { require(_admin != address(0), "PositionManager: zero address"); admin = _admin; emit SetAdmin(_admin); } function setFeeAdmin(address _feeAdmin) external onlyGov { feeAdmin = _feeAdmin; emit SetFeeAdmin(_feeAdmin); } function setIncreasePositionBufferBps(uint256 _increasePositionBufferBps) external onlyGov { increasePositionBufferBps = _increasePositionBufferBps; emit SetIncreasePositionBufferBps(_increasePositionBufferBps); } function setReferralManager(address _referralManager) external onlyGov { referralStorage = _referralManager; emit SetReferralManager(_referralManager); } function setCircuitBreaker(ICircuitBreaker _circuitBreaker) external onlyGov { circuitBreaker = _circuitBreaker; } function setMaxGlobalSizes( address[] memory _tokens, uint256[] memory _longSizes, uint256[] memory _shortSizes ) external onlyAdminOrGov { for (uint256 i = 0; i < _tokens.length; i++) { address token = _tokens[i]; maxGlobalLongSizes[token] = _longSizes[i]; maxGlobalShortSizes[token] = _shortSizes[i]; } emit SetMaxGlobalSizes(_tokens, _longSizes, _shortSizes); } function _validateMaxGlobalSize(address _indexToken, bool _isLong, uint256 _sizeDelta) internal view { if (_sizeDelta == 0) { return; } if (_isLong) { uint256 maxGlobalLongSize = maxGlobalLongSizes[_indexToken]; if (maxGlobalLongSize > 0 && IVault(vault).guaranteedUsd(_indexToken) + _sizeDelta > maxGlobalLongSize) { revert("PositionManager: max global longs exceeded"); } } else { uint256 maxGlobalShortSize = maxGlobalShortSizes[_indexToken]; if (maxGlobalShortSize > 0 && IVault(vault).globalShortSizes(_indexToken) + _sizeDelta > maxGlobalShortSize) { revert("PositionManager: max global shorts exceeded"); } } } function setOrderKeeper(address _account, bool _isActive) external onlyGov { isOrderKeeper[_account] = _isActive; emit SetOrderKeeper(_account, _isActive); } function setLiquidator(address _account, bool _isActive) external onlyGov { isLiquidator[_account] = _isActive; emit SetLiquidator(_account, _isActive); } function setShouldValidateIncreaseOrder(bool _shouldValidateIncreaseOrder) external onlyGov { shouldValidateIncreaseOrder = _shouldValidateIncreaseOrder; emit SetShouldValidateIncreaseOrder(_shouldValidateIncreaseOrder); } function liquidatePosition( address _account, address _collateralToken, address _indexToken, bool _isLong, address _feeReceiver ) external nonReentrant onlyLiquidator { address _vault = vault; address timelock = IVault(_vault).gov(); ITimelock(timelock).enableLeverage(_vault); IVault(_vault).liquidatePosition(_account, _collateralToken, _indexToken, _isLong, _feeReceiver); ITimelock(timelock).disableLeverage(_vault); } function executeSwapOrder(address _account, uint256 _orderIndex, address payable _feeReceiver) external onlyOrderKeeper { IOrderBook(orderBook).executeSwapOrder(_account, _orderIndex, _feeReceiver); } function executeIncreaseOrder(address _account, uint256 _orderIndex, address payable _feeReceiver) external onlyOrderKeeper { _validateIncreaseOrder(_account, _orderIndex); address _vault = vault; address timelock = IVault(_vault).gov(); ( /*address purchaseToken*/, /*uint256 purchaseTokenAmount*/, /* address collateralToken*/, address indexToken, uint256 sizeDelta, bool isLong, /*uint256 triggerPrice*/, /*bool triggerAboveThreshold*/, /*uint256 executionFee*/ ) = IOrderBook(orderBook).getIncreaseOrder(_account, _orderIndex); circuitBreaker.validateCircuitBreaker(indexToken, sizeDelta, isLong); ITimelock(timelock).enableLeverage(_vault); IOrderBook(orderBook).executeIncreaseOrder(_account, _orderIndex, _feeReceiver); ITimelock(timelock).disableLeverage(_vault); } function executeDecreaseOrder(address _account, uint256 _orderIndex, address payable _feeReceiver) external onlyOrderKeeper { address _vault = vault; address timelock = IVault(_vault).gov(); ITimelock(timelock).enableLeverage(_vault); IOrderBook(orderBook).executeDecreaseOrder(_account, _orderIndex, _feeReceiver); ITimelock(timelock).disableLeverage(_vault); } function _validateIncreaseOrder(address _account, uint256 _orderIndex) internal view { ( address _purchaseToken, uint256 _purchaseTokenAmount, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong, , // triggerPrice , // triggerAboveThreshold // executionFee ) = IOrderBook(orderBook).getIncreaseOrder(_account, _orderIndex); _validateMaxGlobalSize(_indexToken, _isLong, _sizeDelta); if (!shouldValidateIncreaseOrder) { return; } // shorts are okay if (!_isLong) { return; } // if the position size is not increasing, this is a collateral deposit require(_sizeDelta > 0, "PositionManager: long deposit"); IVault _vault = IVault(vault); (uint256 size, uint256 collateral, , , , , , ) = _vault.getPosition(_account, _collateralToken, _indexToken, _isLong); // if there is no existing position, do not charge a fee if (size == 0) { return; } uint256 nextSize = size + _sizeDelta; uint256 collateralDelta = _vault.tokenToUsdMin(_purchaseToken, _purchaseTokenAmount); uint256 nextCollateral = collateral + collateralDelta; uint256 prevLeverage = size * BASIS_POINTS_DIVISOR / collateral; // allow for a maximum of a increasePositionBufferBps decrease since there might be some swap fees taken from the collateral uint256 nextLeverageWithBuffer = nextSize * (BASIS_POINTS_DIVISOR + increasePositionBufferBps) / nextCollateral; require(nextLeverageWithBuffer >= prevLeverage, "PositionManager: long leverage decrease"); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { function __AccessControl_init() internal onlyInitializing { } function __AccessControl_init_unchained() internal onlyInitializing { } struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view virtual override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `_msgSender()` is missing `role`. * Overriding this function changes the behavior of the {onlyRole} modifier. * * Format of the revert message is described in {_checkRole}. * * _Available since v4.6._ */ function _checkRole(bytes32 role) internal view virtual { _checkRole(role, _msgSender()); } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", StringsUpgradeable.toHexString(account), " is missing role ", StringsUpgradeable.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleGranted} event. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleRevoked} event. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. * * May emit a {RoleRevoked} event. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * May emit a {RoleGranted} event. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. * * May emit a {RoleGranted} event. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. * * May emit a {RoleRevoked} event. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } /** * @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; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.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] * ``` * 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 Internal function that returns the initialized version. Returns `_initialized` */ function _getInitializedVersion() internal view returns (uint8) { return _initialized; } /** * @dev Internal function that returns the initialized version. Returns `_initializing` */ function _isInitializing() internal view returns (bool) { return _initializing; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.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 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; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20PermitUpgradeable { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.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); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20Upgradeable.sol"; import "../extensions/draft-IERC20PermitUpgradeable.sol"; import "../../../utils/AddressUpgradeable.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20Upgradeable { using AddressUpgradeable for address; function safeTransfer( IERC20Upgradeable token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20Upgradeable token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20Upgradeable token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20Upgradeable token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20Upgradeable token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } function safePermit( IERC20PermitUpgradeable token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20Upgradeable token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.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 * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; 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; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } /** * @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; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library 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) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv( uint256 x, uint256 y, uint256 denominator, Rounding rounding ) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10**64) { value /= 10**64; result += 64; } if (value >= 10**32) { value /= 10**32; result += 32; } if (value >= 10**16) { value /= 10**16; result += 16; } if (value >= 10**8) { value /= 10**8; result += 8; } if (value >= 10**4) { value /= 10**4; result += 4; } if (value >= 10**2) { value /= 10**2; result += 2; } if (value >= 10**1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/MathUpgradeable.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 `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); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; pragma solidity ^0.8.0; abstract contract Governable is Initializable { address public gov; event UpdateGov(address gov); function __Governable_init() internal onlyInitializing { gov = msg.sender; } modifier onlyGov() { require(msg.sender == gov, "Governable: forbidden"); _; } function setGov(address _gov) external onlyGov { require(_gov != address(0), "Governable: zero address"); gov = _gov; emit UpdateGov(gov); } }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; interface ICircuitBreaker { function pauseStartTime(address _token) external returns (uint); function pauseEndTime(address _token) external returns (uint); function maxLongToShortRatio(address _token) external returns (uint); function maxShortToLongRatio(address _token) external returns (uint); function oiRatioCheckThreshold(address _token) external returns (uint); function validateCircuitBreaker(address _indexToken, uint _sizeDelta, bool _isLong) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IOrderBook { function minExecutionFee() external view returns (uint256); function getSwapOrder(address _account, uint256 _orderIndex) external view returns ( address path0, address path1, address path2, uint256 amountIn, uint256 minOut, uint256 triggerRatio, bool triggerAboveThreshold, bool shouldUnwrap, uint256 executionFee ); function getIncreaseOrder(address _account, uint256 _orderIndex) external view returns ( address purchaseToken, uint256 purchaseTokenAmount, address collateralToken, address indexToken, uint256 sizeDelta, bool isLong, uint256 triggerPrice, bool triggerAboveThreshold, uint256 executionFee ); function getDecreaseOrder(address _account, uint256 _orderIndex) external view returns ( address collateralToken, uint256 collateralDelta, address indexToken, uint256 sizeDelta, bool isLong, uint256 triggerPrice, bool triggerAboveThreshold, uint256 executionFee ); function createDecreaseOrderForAccount( address _account, address _indexToken, uint256 _sizeDelta, address _collateralToken, uint256 _collateralDelta, bool _isLong, uint256 _triggerPrice, bool _triggerAboveThreshold ) external payable; function executeSwapOrder(address, uint256, address payable) external; function executeDecreaseOrder(address, uint256, address payable) external; function executeIncreaseOrder(address, uint256, address payable) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IPositionManager { function maxGlobalLongSizes(address _token) external view returns (uint256); function maxGlobalShortSizes(address _token) external view returns (uint256); function executeIncreaseOrder(address, uint256, address payable) external; function executeDecreaseOrder(address, uint256, address payable) external; function executeSwapOrder(address, uint256, address payable) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IRouter { function addPlugin(address _plugin) external; function pluginTransfer(address _token, address _account, address _receiver, uint256 _amount) external; function pluginIncreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong) external; function pluginIncreasePositionV2(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong, address _brokerAddress, uint256 _brokerFeeBasisPoints) external; function pluginDecreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _collateralDelta, uint256 _sizeDelta, bool _isLong, address _receiver) external returns (uint256); function swap(address[] memory _path, uint256 _amountIn, uint256 _minOut, address _receiver) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IVaultUtils.sol"; import "../../referrals/interfaces/IReferralManager.sol"; interface IVault { struct IncreasePositionParams { address account; address collateralToken; address indexToken; uint256 sizeDelta; bool isLong; address brokerAddress; uint256 brokerFeeBasisPoints; } struct CollectFeeParams { address account; address collateralToken; address indexToken; bool isLong; uint256 sizeDelta; uint256 size; uint256 entryFundingRate; address brokerAddress; uint256 brokerFeeBasisPoints; } function isInitialized() external view returns (bool); function isSwapEnabled() external view returns (bool); function isLeverageEnabled() external view returns (bool); function setReferralManager(IReferralManager _referralManager) external; function setVaultUtils(IVaultUtils _vaultUtils) external; function setError(uint256 _errorCode, string calldata _error) external; function router() external view returns (address); function usdg() external view returns (address); function gov() external view returns (address); function feeAdmin() external view returns (address); function maxLeverage() external view returns (uint256); function minProfitTime() external view returns (uint256); function hasDynamicFees() external view returns (bool); function fundingInterval() external view returns (uint256); function totalTokenWeights() external view returns (uint256); function inManagerMode() external view returns (bool); function inPrivateLiquidationMode() external view returns (bool); function maxGasPrice() external view returns (uint256); function approvedRouters(address _account, address _router) external view returns (bool); function isLiquidator(address _account) external view returns (bool); function isManager(address _account) external view returns (bool); function minProfitBasisPoints(address _token) external view returns (uint256); function tokenBalances(address _token) external view returns (uint256); function lastFundingTimes(address _token) external view returns (uint256); function setMaxLeverage(uint256 _maxLeverage) external; function setInManagerMode(bool _inManagerMode) external; function setManager(address _manager, bool _isManager) external; function setIsSwapEnabled(bool _isSwapEnabled) external; function setIsLeverageEnabled(bool _isLeverageEnabled) external; function setMaxGasPrice(uint256 _maxGasPrice) external; function setUsdgAmount(address _token, uint256 _amount) external; function setBufferAmount(address _token, uint256 _amount) external; function setMaxGlobalShortSize(address _token, uint256 _amount) external; function setInPrivateLiquidationMode(bool _inPrivateLiquidationMode) external; function setLiquidator(address _liquidator, bool _isActive) external; function setFundingRate(uint256 _fundingInterval, uint256 _fundingRateFactor, uint256 _stableFundingRateFactor) external; function setFees( uint256 _taxBasisPoints, uint256 _stableTaxBasisPoints, uint256 _mintBurnFeeBasisPoints, uint256 _swapFeeBasisPoints, uint256 _stableSwapFeeBasisPoints, uint256 _marginFeeBasisPoints, uint256 _dynLiquidationFeeBasisPoints, uint256 _fixedLiquidationFeeUsd, uint256 _minProfitTime, bool _hasDynamicFees ) external; function setTokenConfig( address _token, uint256 _tokenDecimals, uint256 _redemptionBps, uint256 _minProfitBps, uint256 _maxUsdgAmount, bool _isStable, bool _isShortable ) external; function setPriceFeed(address _priceFeed) external; function setFeeAdmin(address _feeAdmin) external; function withdrawFees(address _token, address _receiver) external returns (uint256); function directPoolDeposit(address _token) external; function buyUSDG(address _token, address _receiver) external returns (uint256); function sellUSDG(address _token, address _receiver) external returns (uint256); function swap(address _tokenIn, address _tokenOut, address _receiver) external returns (uint256); function increasePosition(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong) external; function increasePositionV2(IncreasePositionParams calldata increasePositionParams) external; function decreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _collateralDelta, uint256 _sizeDelta, bool _isLong, address _receiver) external returns (uint256); function validateLiquidation(address _account, address _collateralToken, address _indexToken, bool _isLong, bool _raise) external view returns (uint256, uint256); function liquidatePosition(address _account, address _collateralToken, address _indexToken, bool _isLong, address _feeReceiver) external; function tokenToUsdMin(address _token, uint256 _tokenAmount) external view returns (uint256); function priceFeed() external view returns (address); function fundingRateFactor() external view returns (uint256); function stableFundingRateFactor() external view returns (uint256); function cumulativeFundingRates(address _token) external view returns (uint256); function getNextFundingRate(address _token) external view returns (uint256); function fixedLiquidationFeeUsd() external view returns (uint256); function dynLiquidationFeeBasisPoints() external view returns (uint256); function taxBasisPoints() external view returns (uint256); function stableTaxBasisPoints() external view returns (uint256); function mintBurnFeeBasisPoints() external view returns (uint256); function swapFeeBasisPoints() external view returns (uint256); function stableSwapFeeBasisPoints() external view returns (uint256); function marginFeeBasisPoints() external view returns (uint256); function whitelistedTokens(uint256 _index) external view returns (address); function isWhitelistedToken(address _token) external view returns (bool); function whitelistedTokenCount() external view returns (uint256); function stableTokens(address _token) external view returns (bool); function shortableTokens(address _token) external view returns (bool); function feeReserves(address _token) external view returns (uint256); function positions(bytes32 key) external view returns (uint256, uint256, uint256, uint256, uint256, int256, uint256, address, uint256); function globalShortSizes(address _token) external view returns (uint256); function globalShortAveragePrices(address _token) external view returns (uint256); function maxGlobalShortSizes(address _token) external view returns (uint256); function tokenDecimals(address _token) external view returns (uint256); function tokenWeights(address _token) external view returns (uint256); function guaranteedUsd(address _token) external view returns (uint256); function poolAmounts(address _token) external view returns (uint256); function bufferAmounts(address _token) external view returns (uint256); function reservedAmounts(address _token) external view returns (uint256); function usdgAmounts(address _token) external view returns (uint256); function maxUsdgAmounts(address _token) external view returns (uint256); function getMaxPrice(address _token) external view returns (uint256); function getMinPrice(address _token) external view returns (uint256); function getPositionKey(address _account, address _collateralToken, address _indexToken, bool _isLong) external pure returns (bytes32); function getDelta(address _indexToken, uint256 _size, uint256 _averagePrice, bool _isLong, uint256 _lastIncreasedTime) external view returns (bool, uint256); function getRedemptionAmount(address _token, uint256 _usdgAmount) external view returns (uint256); function errors(uint256 errCode) external view returns (string calldata); function getPosition(address _account, address _collateralToken, address _indexToken, bool _isLong) external view returns (uint256, uint256, uint256, uint256, uint256, uint256, bool, uint256); function transferOutTokens(address[] calldata _tokens, uint[] calldata _amounts, address _receiver) external; function usdToToken(address _token, uint256 _usdAmount, uint256 _price) external returns (uint256); function adjustForDecimals(uint256 _amount, address _tokenDiv, address _tokenMul) external view returns (uint256); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IVaultUtils { struct Position { uint256 size; uint256 collateral; uint256 averagePrice; uint256 entryFundingRate; uint256 reserveAmount; uint256 realisedPnl; uint256 lastIncreasedTime; address brokerAddress; uint256 brokerFeeBasisPoints; } function updateCumulativeFundingRate(address _collateralToken, address _indexToken) external returns (bool); function validateIncreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong) external view; function validateDecreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _collateralDelta, uint256 _sizeDelta, bool _isLong, address _receiver) external view; function validateLiquidation(address _account, address _collateralToken, address _indexToken, bool _isLong, bool _raise) external view returns (uint256, uint256); function validateLiquidationForBot(address _account, address _collateralToken, address _indexToken, bool _isLong, bool _raise) external view returns (uint256, uint256); function validateBufferAmount(address _token) external view; function getLiquidationFee(uint256 remainingCollateralUsd) external view returns (uint256); function getEntryFundingRate(address _collateralToken, address _indexToken, bool _isLong) external view returns (uint256); function getPositionFee(uint256 _sizeDelta) external view returns (uint256); function getBrokerFee(uint256 _sizeDelta, uint256 _brokerFeeBasisPoints) external view returns (uint256); function getPositionFeeForBot(uint256 _sizeDelta) external view returns (uint256); function getFundingFee(address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _size, uint256 _entryFundingRate) external view returns (uint256); function getBuyUsdgFeeBasisPoints(address _token, uint256 _usdgAmount) external view returns (uint256); function getSellUsdgFeeBasisPoints(address _token, uint256 _usdgAmount) external view returns (uint256); function getSwapFeeBasisPoints(address _tokenIn, address _tokenOut, uint256 _usdgAmount) external view returns (uint256); function getFeeBasisPoints(address _token, uint256 _usdgDelta, uint256 _feeBasisPoints, uint256 _taxBasisPoints, bool _increment) external view returns (uint256); function getDelta(address _indexToken, uint256 _size, uint256 _averagePrice, bool _isLong, uint256 _lastIncreasedTime) external view returns (bool, uint256); function getNextAveragePrice(address _indexToken, uint256 _size, uint256 _averagePrice, bool _isLong, uint256 _nextPrice, uint256 _sizeDelta, uint256 _lastIncreasedTime )external view returns (uint256); function getNextGlobalShortAveragePrice(address _indexToken, uint256 _nextPrice, uint256 _sizeDelta) external view returns (uint256); function getGlobalShortDelta(address _token) external view returns (bool, uint256); function getNextFundingRate(address _token) external view returns (uint256); function getRedemptionAmount(address _token, uint256 _usdgAmount) external view returns (uint256); function adjustForDecimals(uint256 _amount, address _tokenDiv, address _tokenMul) external view returns (uint256); function getPositionLeverage(address _account, address _collateralToken, address _indexToken, bool _isLong) external view returns (uint256); function getPositionBroker(address _account, address _collateralToken, address _indexToken, bool _isLong) external view returns (address, uint256); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface ITimelock { function setAdmin(address _admin) external; function enableLeverage(address _vault) external; function disableLeverage(address _vault) external; function setIsLeverageEnabled(address _vault, bool _isLeverageEnabled) external; function signalSetGov(address _target, address _gov) external; function marginFeeBasisPoints() external view returns (uint256); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; struct ReferralPositionFee { uint feeForPoolAmount; uint feeForPoolUsd; uint rebateAmount; uint rebateUsd; } struct ReferralInfo { bytes32 code; address affiliate; bool isActive; Tier tier; } struct Tier { uint256 id; uint256 rebate; uint256 discount; } interface IReferralManager { function codeOwners(bytes32 _code) external view returns (address); function getReferralInfoByTrader(address _trader) external view returns (ReferralInfo memory); function getReferralInfoByCode(bytes32 _code) external view returns (ReferralInfo memory); function getReferralInfoByAffiliate(address _affiliate) external view returns (ReferralInfo memory); function setTraderReferralCode(address _trader, bytes32 _code) external; function setTraderReferralCodeByUser(bytes32 _code) external; function setTier(uint256 _tierId, uint256 _rebate, uint256 _discount) external; function setAffiliateTier(address _referrer, uint256 _tierId) external; function getAffiliateReward(address _affiliate) external view returns (address[] memory, uint256[] memory); function claimAffiliateReward() external; function discountPositionFee( address _trader, address _token, uint256 _tokenPrice, uint256 _positionFeeUsd, uint256 _sizeDelta ) external returns (ReferralPositionFee memory fee); }
//SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IWETH is IERC20 { function deposit() external payable; function withdraw(uint) external; }
{ "optimizer": { "enabled": true, "runs": 1 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"admin","type":"address"}],"name":"SetAdmin","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"depositFee","type":"uint256"}],"name":"SetDepositFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"feeAdmin","type":"address"}],"name":"SetFeeAdmin","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"inLegacyMode","type":"bool"}],"name":"SetInLegacyMode","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"increasePositionBufferBps","type":"uint256"}],"name":"SetIncreasePositionBufferBps","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"isActive","type":"bool"}],"name":"SetLiquidator","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address[]","name":"tokens","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"longSizes","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"shortSizes","type":"uint256[]"}],"name":"SetMaxGlobalSizes","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"isActive","type":"bool"}],"name":"SetOrderKeeper","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"isActive","type":"bool"}],"name":"SetPartner","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"referralManager","type":"address"}],"name":"SetReferralManager","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"shouldValidateIncreaseOrder","type":"bool"}],"name":"SetShouldValidateIncreaseOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"gov","type":"address"}],"name":"UpdateGov","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawFees","type":"event"},{"inputs":[],"name":"BASIS_POINTS_DIVISOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"circuitBreaker","outputs":[{"internalType":"contract ICircuitBreaker","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"depositFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"},{"internalType":"uint256","name":"_orderIndex","type":"uint256"},{"internalType":"address payable","name":"_feeReceiver","type":"address"}],"name":"executeDecreaseOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"},{"internalType":"uint256","name":"_orderIndex","type":"uint256"},{"internalType":"address payable","name":"_feeReceiver","type":"address"}],"name":"executeIncreaseOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"},{"internalType":"uint256","name":"_orderIndex","type":"uint256"},{"internalType":"address payable","name":"_feeReceiver","type":"address"}],"name":"executeSwapOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"feeReserves","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gov","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"inLegacyMode","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"increasePositionBufferBps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_vault","type":"address"},{"internalType":"address","name":"_weth","type":"address"},{"internalType":"address","name":"_orderBook","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isLiquidator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isOrderKeeper","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isPartner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"},{"internalType":"address","name":"_collateralToken","type":"address"},{"internalType":"address","name":"_indexToken","type":"address"},{"internalType":"bool","name":"_isLong","type":"bool"},{"internalType":"address","name":"_feeReceiver","type":"address"}],"name":"liquidatePosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxGlobalLongSizes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxGlobalShortSizes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"orderBook","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"referralStorage","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"router","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_admin","type":"address"}],"name":"setAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ICircuitBreaker","name":"_circuitBreaker","type":"address"}],"name":"setCircuitBreaker","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeAdmin","type":"address"}],"name":"setFeeAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_gov","type":"address"}],"name":"setGov","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_increasePositionBufferBps","type":"uint256"}],"name":"setIncreasePositionBufferBps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"},{"internalType":"bool","name":"_isActive","type":"bool"}],"name":"setLiquidator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_tokens","type":"address[]"},{"internalType":"uint256[]","name":"_longSizes","type":"uint256[]"},{"internalType":"uint256[]","name":"_shortSizes","type":"uint256[]"}],"name":"setMaxGlobalSizes","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"},{"internalType":"bool","name":"_isActive","type":"bool"}],"name":"setOrderKeeper","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_referralManager","type":"address"}],"name":"setReferralManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_shouldValidateIncreaseOrder","type":"bool"}],"name":"setShouldValidateIncreaseOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"shortsTracker","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"shouldValidateIncreaseOrder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
608060405234801561001057600080fd5b5061228e806100206000396000f3fe6080604052600436106101a25760003560e01c80626cc35e1461020d57806307c7edc3146102435780631045c74e1461026357806311d9444a1461029e578063126082cf146102be57806312d43a51146102d457806316efd941146102f45780631b904359146103145780631ce9cb8f146103345780631e26153814610361578063233bfe3b1461038157806330a402c0146103a15780633833f5f5146103c15780633fc8cef3146104015780634453a374146104215780634584bd4b14610441578063529a356f14610462578063657bc5d01461049257806367a52793146104b25780636eb2d031146104c8578063704b6c02146104e8578063776af5ba1461050857806382beee89146105285780638c0f9aac146105485780639698d25a1461057857806398d1e03a146105a5578063c0c53b8b146105bb578063c5f3a4c4146105db578063cfad57a2146105fb578063d38ab5191461061b578063d4ca83f91461063b578063de2ea9481461065c578063ef12c67e1461067c578063f851a4401461069c578063f887ea40146106bc578063fbfa77cf146106dc57600080fd5b36610208576039546001600160a01b031633146102065760405162461bcd60e51b815260206004820152601f60248201527f506f736974696f6e4d616e616765723a20696e76616c69642073656e6465720060448201526064015b60405180910390fd5b005b600080fd5b34801561021957600080fd5b50603c5461022d906001600160a01b031681565b60405161023a9190611b72565b60405180910390f35b34801561024f57600080fd5b5061020661025e366004611b9e565b6106fc565b34801561026f57600080fd5b5061029061027e366004611be0565b603e6020526000908152604090205481565b60405190815260200161023a565b3480156102aa57600080fd5b506102066102b9366004611b9e565b610796565b3480156102ca57600080fd5b5061029061271081565b3480156102e057600080fd5b5060335461022d906001600160a01b031681565b34801561030057600080fd5b5060445461022d906001600160a01b031681565b34801561032057600080fd5b5061020661032f366004611c12565b610964565b34801561034057600080fd5b5061029061034f366004611be0565b603d6020526000908152604090205481565b34801561036d57600080fd5b5061020661037c366004611c2f565b6109e4565b34801561038d57600080fd5b5061020661039c366004611c68565b610a6e565b3480156103ad57600080fd5b5060355461022d906001600160a01b031681565b3480156103cd57600080fd5b506103f16103dc366004611be0565b60416020526000908152604090205460ff1681565b604051901515815260200161023a565b34801561040d57600080fd5b5060395461022d906001600160a01b031681565b34801561042d57600080fd5b5061020661043c366004611c2f565b610acd565b34801561044d57600080fd5b506040546103f190600160a81b900460ff1681565b34801561046e57600080fd5b506103f161047d366004611be0565b60436020526000908152604090205460ff1681565b34801561049e57600080fd5b5060375461022d906001600160a01b031681565b3480156104be57600080fd5b50610290603a5481565b3480156104d457600080fd5b506102066104e3366004611be0565b610b4f565b3480156104f457600080fd5b50610206610503366004611be0565b610bc4565b34801561051457600080fd5b5060405461022d906001600160a01b031681565b34801561053457600080fd5b50610206610543366004611be0565b610c8f565b34801561055457600080fd5b506103f1610563366004611be0565b60426020526000908152604090205460ff1681565b34801561058457600080fd5b50610290610593366004611be0565b603f6020526000908152604090205481565b3480156105b157600080fd5b50610290603b5481565b3480156105c757600080fd5b506102066105d6366004611c81565b610cdb565b3480156105e757600080fd5b506102066105f6366004611be0565b610e5a565b34801561060757600080fd5b50610206610616366004611be0565b610ecf565b34801561062757600080fd5b50610206610636366004611b9e565b610f96565b34801561064757600080fd5b506040546103f190600160a01b900460ff1681565b34801561066857600080fd5b50610206610677366004611cc1565b61126b565b34801561068857600080fd5b50610206610697366004611e06565b611461565b3480156106a857600080fd5b5060345461022d906001600160a01b031681565b3480156106c857600080fd5b5060385461022d906001600160a01b031681565b3480156106e857600080fd5b5060365461022d906001600160a01b031681565b3360009081526041602052604090205460ff1661072b5760405162461bcd60e51b81526004016101fd90611eeb565b6040805490516307c7edc360e01b81526001600160a01b03909116906307c7edc39061075f90869086908690600401611f1f565b600060405180830381600087803b15801561077957600080fd5b505af115801561078d573d6000803e3d6000fd5b50505050505050565b3360009081526041602052604090205460ff166107c55760405162461bcd60e51b81526004016101fd90611eeb565b603654604080516312d43a5160e01b815290516001600160a01b039092169160009183916312d43a51916004808201926020929091908290030181865afa158015610814573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108389190611f42565b6040516306d63c1d60e41b81529091506001600160a01b03821690636d63c1d090610867908590600401611b72565b600060405180830381600087803b15801561088157600080fd5b505af1158015610895573d6000803e3d6000fd5b50506040805490516308eca22560e11b81526001600160a01b0390911692506311d9444a91506108cd90889088908890600401611f1f565b600060405180830381600087803b1580156108e757600080fd5b505af11580156108fb573d6000803e3d6000fd5b505060405163d3c87bbb60e01b81526001600160a01b038416925063d3c87bbb915061092b908590600401611b72565b600060405180830381600087803b15801561094557600080fd5b505af1158015610959573d6000803e3d6000fd5b505050505050505050565b6033546001600160a01b0316331461098e5760405162461bcd60e51b81526004016101fd90611f5f565b60408054821515600160a81b0260ff60a81b19909116178155517fa956222e37fe025ff51e5440ac729a9bd417ff91e485e14dcffa2c0ba8894f40906109d990831515815260200190565b60405180910390a150565b6033546001600160a01b03163314610a0e5760405162461bcd60e51b81526004016101fd90611f5f565b6001600160a01b038216600081815260416020908152604091829020805460ff191685151590811790915591519182527f1d5bc0255b943d6a5b5279e8a55d74d620baccbceecb25e87a3558f14c4c118e91015b60405180910390a25050565b6033546001600160a01b03163314610a985760405162461bcd60e51b81526004016101fd90611f5f565b603b8190556040518181527f21167d0d4661af93817ebce920f18986eed3d75d5e1c03f2aed05efcbafbc452906020016109d9565b6033546001600160a01b03163314610af75760405162461bcd60e51b81526004016101fd90611f5f565b6001600160a01b038216600081815260436020908152604091829020805460ff191685151590811790915591519182527f8c0d56805c3b43d441481229dc64bee168253ffe4305f37ab7cfe63b1c4268c69101610a62565b6033546001600160a01b03163314610b795760405162461bcd60e51b81526004016101fd90611f5f565b603580546001600160a01b0319166001600160a01b0383161790556040517f26cb770c9a24026a0c99d6be6fa7fb963470f03731f629156bbdf1baecae5958906109d9908390611b72565b6033546001600160a01b03163314610bee5760405162461bcd60e51b81526004016101fd90611f5f565b6001600160a01b038116610c445760405162461bcd60e51b815260206004820152601d60248201527f506f736974696f6e4d616e616765723a207a65726f206164647265737300000060448201526064016101fd565b603480546001600160a01b0319166001600160a01b0383161790556040517f5a272403b402d892977df56625f4164ccaf70ca3863991c43ecfe76a6905b0a1906109d9908390611b72565b6033546001600160a01b03163314610cb95760405162461bcd60e51b81526004016101fd90611f5f565b604480546001600160a01b0319166001600160a01b0392909216919091179055565b600054610100900460ff1615808015610cfb5750600054600160ff909116105b80610d155750303b158015610d15575060005460ff166001145b610d785760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016101fd565b6000805460ff191660011790558015610d9b576000805461ff0019166101001790555b610da3611598565b60338054336001600160a01b031991821681179092556036805482166001600160a01b03888116919091179091556039805483168783161790556064603b5560348054909216909217905560408054600160a81b928516600161ff0160a01b0319909116179190911790558015610e54576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50505050565b6033546001600160a01b03163314610e845760405162461bcd60e51b81526004016101fd90611f5f565b603c80546001600160a01b0319166001600160a01b0383161790556040517f57202bce87a87010e83825477a341d777f701216d3e2a3b4642c72d9e8a93198906109d9908390611b72565b6033546001600160a01b03163314610ef95760405162461bcd60e51b81526004016101fd90611f5f565b6001600160a01b038116610f4a5760405162461bcd60e51b8152602060048201526018602482015277476f7665726e61626c653a207a65726f206164647265737360401b60448201526064016101fd565b603380546001600160a01b0319166001600160a01b0383169081179091556040517fe24c39186e9137521953beaa8446e71f55b8f12296984f9d4273ceb1af728d90916109d991611b72565b3360009081526041602052604090205460ff16610fc55760405162461bcd60e51b81526004016101fd90611eeb565b610fcf83836115c9565b603654604080516312d43a5160e01b815290516001600160a01b039092169160009183916312d43a51916004808201926020929091908290030181865afa15801561101e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110429190611f42565b60408054905163d3bab1d160e01b8152919250600091829182916001600160a01b039091169063d3bab1d19061107e908b908b90600401611f8e565b61012060405180830381865afa15801561109c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110c09190611fa7565b505060448054604051637ebea3e360e01b81526001600160a01b0380881660048301526024820187905285151593820193909352959b5093995091975050169350637ebea3e392506064019050600060405180830381600087803b15801561112757600080fd5b505af115801561113b573d6000803e3d6000fd5b50506040516306d63c1d60e41b81526001600160a01b0387169250636d63c1d0915061116b908890600401611b72565b600060405180830381600087803b15801561118557600080fd5b505af1158015611199573d6000803e3d6000fd5b505060408054905163d38ab51960e01b81526001600160a01b03909116925063d38ab51991506111d1908b908b908b90600401611f1f565b600060405180830381600087803b1580156111eb57600080fd5b505af11580156111ff573d6000803e3d6000fd5b505060405163d3c87bbb60e01b81526001600160a01b038716925063d3c87bbb915061122f908890600401611b72565b600060405180830381600087803b15801561124957600080fd5b505af115801561125d573d6000803e3d6000fd5b505050505050505050505050565b6112736118d0565b3360009081526043602052604090205460ff166112a25760405162461bcd60e51b81526004016101fd90611eeb565b603654604080516312d43a5160e01b815290516001600160a01b039092169160009183916312d43a51916004808201926020929091908290030181865afa1580156112f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113159190611f42565b6040516306d63c1d60e41b81529091506001600160a01b03821690636d63c1d090611344908590600401611b72565b600060405180830381600087803b15801561135e57600080fd5b505af1158015611372573d6000803e3d6000fd5b5050604051631bc5d52960e31b81526001600160a01b038a8116600483015289811660248301528881166044830152871515606483015286811660848301528516925063de2ea948915060a401600060405180830381600087803b1580156113d957600080fd5b505af11580156113ed573d6000803e3d6000fd5b505060405163d3c87bbb60e01b81526001600160a01b038416925063d3c87bbb915061141d908590600401611b72565b600060405180830381600087803b15801561143757600080fd5b505af115801561144b573d6000803e3d6000fd5b50505050505061145a60018055565b5050505050565b6034546001600160a01b031633148061148457506033546001600160a01b031633145b6114a05760405162461bcd60e51b81526004016101fd90611eeb565b60005b83518110156115575760008482815181106114c0576114c0612043565b602002602001015190508382815181106114dc576114dc612043565b6020026020010151603e6000836001600160a01b03166001600160a01b031681526020019081526020016000208190555082828151811061151f5761151f612043565b6020908102919091018101516001600160a01b039092166000908152603f90915260409020558061154f8161206f565b9150506114a3565b507fae32d569b058895b9620d6552b09aaffedc9a6f396be4d595a224ad09f8b213983838360405161158b939291906120c3565b60405180910390a1505050565b600054610100900460ff166115bf5760405162461bcd60e51b81526004016101fd90612138565b6115c761192f565b565b60408054905163d3bab1d160e01b8152600091829182918291829182916001600160a01b039091169063d3bab1d190611608908b908b90600401611f8e565b61012060405180830381865afa158015611626573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061164a9190611fa7565b505050955095509550955095509550611664838284611956565b604054600160a81b900460ff1661167f575050505050505050565b8061168e575050505050505050565b600082116116de5760405162461bcd60e51b815260206004820152601d60248201527f506f736974696f6e4d616e616765723a206c6f6e67206465706f73697400000060448201526064016101fd565b603654604051634a3f088d60e01b81526001600160a01b038a811660048301528681166024830152858116604483015283151560648301529091169060009081908390634a3f088d9060840161010060405180830381865afa158015611748573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061176c9190612183565b505050505050915091508160000361178b575050505050505050505050565b600061179786846121ed565b90506000846001600160a01b0316630a48d5a98c8c6040518363ffffffff1660e01b81526004016117c9929190611f8e565b602060405180830381865afa1580156117e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061180a9190612206565b9050600061181882856121ed565b90506000846118296127108861221f565b6118339190612236565b9050600082603b5461271061184891906121ed565b611852908761221f565b61185c9190612236565b9050818110156118be5760405162461bcd60e51b815260206004820152602760248201527f506f736974696f6e4d616e616765723a206c6f6e67206c6576657261676520646044820152666563726561736560c81b60648201526084016101fd565b50505050505050505050505050505050565b6002600154036119225760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016101fd565b6002600155565b60018055565b600054610100900460ff166119295760405162461bcd60e51b81526004016101fd90612138565b8060000361196357505050565b8115611a6d576001600160a01b0383166000908152603e60205260409020548015801590611a0d575060365460405163783a2b6760e11b8152829184916001600160a01b039091169063f07456ce906119c0908990600401611b72565b602060405180830381865afa1580156119dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a019190612206565b611a0b91906121ed565b115b15610e545760405162461bcd60e51b815260206004820152602a60248201527f506f736974696f6e4d616e616765723a206d617820676c6f62616c206c6f6e676044820152691cc8195e18d95959195960b21b60648201526084016101fd565b6001600160a01b0383166000908152603f60205260409020548015801590611b11575060365460405163114f1b5560e31b8152829184916001600160a01b0390911690638a78daa890611ac4908990600401611b72565b602060405180830381865afa158015611ae1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b059190612206565b611b0f91906121ed565b115b15610e545760405162461bcd60e51b815260206004820152602b60248201527f506f736974696f6e4d616e616765723a206d617820676c6f62616c2073686f7260448201526a1d1cc8195e18d95959195960aa1b60648201526084016101fd565b6001600160a01b0391909116815260200190565b6001600160a01b0381168114611b9b57600080fd5b50565b600080600060608486031215611bb357600080fd5b8335611bbe81611b86565b9250602084013591506040840135611bd581611b86565b809150509250925092565b600060208284031215611bf257600080fd5b8135611bfd81611b86565b9392505050565b8015158114611b9b57600080fd5b600060208284031215611c2457600080fd5b8135611bfd81611c04565b60008060408385031215611c4257600080fd5b8235611c4d81611b86565b91506020830135611c5d81611c04565b809150509250929050565b600060208284031215611c7a57600080fd5b5035919050565b600080600060608486031215611c9657600080fd5b8335611ca181611b86565b92506020840135611cb181611b86565b91506040840135611bd581611b86565b600080600080600060a08688031215611cd957600080fd5b8535611ce481611b86565b94506020860135611cf481611b86565b93506040860135611d0481611b86565b92506060860135611d1481611c04565b91506080860135611d2481611b86565b809150509295509295909350565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715611d7057611d70611d32565b604052919050565b60006001600160401b03821115611d9157611d91611d32565b5060051b60200190565b600082601f830112611dac57600080fd5b81356020611dc1611dbc83611d78565b611d48565b82815260059290921b84018101918181019086841115611de057600080fd5b8286015b84811015611dfb5780358352918301918301611de4565b509695505050505050565b600080600060608486031215611e1b57600080fd5b83356001600160401b0380821115611e3257600080fd5b818601915086601f830112611e4657600080fd5b81356020611e56611dbc83611d78565b82815260059290921b8401810191818101908a841115611e7557600080fd5b948201945b83861015611e9c578535611e8d81611b86565b82529482019490820190611e7a565b97505087013592505080821115611eb257600080fd5b611ebe87838801611d9b565b93506040860135915080821115611ed457600080fd5b50611ee186828701611d9b565b9150509250925092565b6020808252601a90820152792837b9b4ba34b7b726b0b730b3b2b91d103337b93134b23232b760311b604082015260600190565b6001600160a01b0393841681526020810192909252909116604082015260600190565b600060208284031215611f5457600080fd5b8151611bfd81611b86565b60208082526015908201527423b7bb32b93730b136329d103337b93134b23232b760591b604082015260600190565b6001600160a01b03929092168252602082015260400190565b60008060008060008060008060006101208a8c031215611fc657600080fd5b8951611fd181611b86565b60208b015160408c0151919a509850611fe981611b86565b60608b0151909750611ffa81611b86565b60808b015160a08c0151919750955061201281611c04565b60c08b015160e08c0151919550935061202a81611c04565b809250506101008a015190509295985092959850929598565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60006001820161208157612081612059565b5060010190565b600081518084526020808501945080840160005b838110156120b85781518752958201959082019060010161209c565b509495945050505050565b606080825284519082018190526000906020906080840190828801845b828110156121055781516001600160a01b0316845292840192908401906001016120e0565b505050838103828501526121198187612088565b915050828103604084015261212e8185612088565b9695505050505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b600080600080600080600080610100898b0312156121a057600080fd5b885197506020890151965060408901519550606089015194506080890151935060a0890151925060c08901516121d581611c04565b8092505060e089015190509295985092959890939650565b8082018082111561220057612200612059565b92915050565b60006020828403121561221857600080fd5b5051919050565b808202811582820484141761220057612200612059565b60008261225357634e487b7160e01b600052601260045260246000fd5b50049056fea2646970667358221220f5cda5e2ed8e56df850a140929737b2040a8966e0fc54200d5186ce1499d187064736f6c63430008110033
Deployed Bytecode
0x6080604052600436106101a25760003560e01c80626cc35e1461020d57806307c7edc3146102435780631045c74e1461026357806311d9444a1461029e578063126082cf146102be57806312d43a51146102d457806316efd941146102f45780631b904359146103145780631ce9cb8f146103345780631e26153814610361578063233bfe3b1461038157806330a402c0146103a15780633833f5f5146103c15780633fc8cef3146104015780634453a374146104215780634584bd4b14610441578063529a356f14610462578063657bc5d01461049257806367a52793146104b25780636eb2d031146104c8578063704b6c02146104e8578063776af5ba1461050857806382beee89146105285780638c0f9aac146105485780639698d25a1461057857806398d1e03a146105a5578063c0c53b8b146105bb578063c5f3a4c4146105db578063cfad57a2146105fb578063d38ab5191461061b578063d4ca83f91461063b578063de2ea9481461065c578063ef12c67e1461067c578063f851a4401461069c578063f887ea40146106bc578063fbfa77cf146106dc57600080fd5b36610208576039546001600160a01b031633146102065760405162461bcd60e51b815260206004820152601f60248201527f506f736974696f6e4d616e616765723a20696e76616c69642073656e6465720060448201526064015b60405180910390fd5b005b600080fd5b34801561021957600080fd5b50603c5461022d906001600160a01b031681565b60405161023a9190611b72565b60405180910390f35b34801561024f57600080fd5b5061020661025e366004611b9e565b6106fc565b34801561026f57600080fd5b5061029061027e366004611be0565b603e6020526000908152604090205481565b60405190815260200161023a565b3480156102aa57600080fd5b506102066102b9366004611b9e565b610796565b3480156102ca57600080fd5b5061029061271081565b3480156102e057600080fd5b5060335461022d906001600160a01b031681565b34801561030057600080fd5b5060445461022d906001600160a01b031681565b34801561032057600080fd5b5061020661032f366004611c12565b610964565b34801561034057600080fd5b5061029061034f366004611be0565b603d6020526000908152604090205481565b34801561036d57600080fd5b5061020661037c366004611c2f565b6109e4565b34801561038d57600080fd5b5061020661039c366004611c68565b610a6e565b3480156103ad57600080fd5b5060355461022d906001600160a01b031681565b3480156103cd57600080fd5b506103f16103dc366004611be0565b60416020526000908152604090205460ff1681565b604051901515815260200161023a565b34801561040d57600080fd5b5060395461022d906001600160a01b031681565b34801561042d57600080fd5b5061020661043c366004611c2f565b610acd565b34801561044d57600080fd5b506040546103f190600160a81b900460ff1681565b34801561046e57600080fd5b506103f161047d366004611be0565b60436020526000908152604090205460ff1681565b34801561049e57600080fd5b5060375461022d906001600160a01b031681565b3480156104be57600080fd5b50610290603a5481565b3480156104d457600080fd5b506102066104e3366004611be0565b610b4f565b3480156104f457600080fd5b50610206610503366004611be0565b610bc4565b34801561051457600080fd5b5060405461022d906001600160a01b031681565b34801561053457600080fd5b50610206610543366004611be0565b610c8f565b34801561055457600080fd5b506103f1610563366004611be0565b60426020526000908152604090205460ff1681565b34801561058457600080fd5b50610290610593366004611be0565b603f6020526000908152604090205481565b3480156105b157600080fd5b50610290603b5481565b3480156105c757600080fd5b506102066105d6366004611c81565b610cdb565b3480156105e757600080fd5b506102066105f6366004611be0565b610e5a565b34801561060757600080fd5b50610206610616366004611be0565b610ecf565b34801561062757600080fd5b50610206610636366004611b9e565b610f96565b34801561064757600080fd5b506040546103f190600160a01b900460ff1681565b34801561066857600080fd5b50610206610677366004611cc1565b61126b565b34801561068857600080fd5b50610206610697366004611e06565b611461565b3480156106a857600080fd5b5060345461022d906001600160a01b031681565b3480156106c857600080fd5b5060385461022d906001600160a01b031681565b3480156106e857600080fd5b5060365461022d906001600160a01b031681565b3360009081526041602052604090205460ff1661072b5760405162461bcd60e51b81526004016101fd90611eeb565b6040805490516307c7edc360e01b81526001600160a01b03909116906307c7edc39061075f90869086908690600401611f1f565b600060405180830381600087803b15801561077957600080fd5b505af115801561078d573d6000803e3d6000fd5b50505050505050565b3360009081526041602052604090205460ff166107c55760405162461bcd60e51b81526004016101fd90611eeb565b603654604080516312d43a5160e01b815290516001600160a01b039092169160009183916312d43a51916004808201926020929091908290030181865afa158015610814573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108389190611f42565b6040516306d63c1d60e41b81529091506001600160a01b03821690636d63c1d090610867908590600401611b72565b600060405180830381600087803b15801561088157600080fd5b505af1158015610895573d6000803e3d6000fd5b50506040805490516308eca22560e11b81526001600160a01b0390911692506311d9444a91506108cd90889088908890600401611f1f565b600060405180830381600087803b1580156108e757600080fd5b505af11580156108fb573d6000803e3d6000fd5b505060405163d3c87bbb60e01b81526001600160a01b038416925063d3c87bbb915061092b908590600401611b72565b600060405180830381600087803b15801561094557600080fd5b505af1158015610959573d6000803e3d6000fd5b505050505050505050565b6033546001600160a01b0316331461098e5760405162461bcd60e51b81526004016101fd90611f5f565b60408054821515600160a81b0260ff60a81b19909116178155517fa956222e37fe025ff51e5440ac729a9bd417ff91e485e14dcffa2c0ba8894f40906109d990831515815260200190565b60405180910390a150565b6033546001600160a01b03163314610a0e5760405162461bcd60e51b81526004016101fd90611f5f565b6001600160a01b038216600081815260416020908152604091829020805460ff191685151590811790915591519182527f1d5bc0255b943d6a5b5279e8a55d74d620baccbceecb25e87a3558f14c4c118e91015b60405180910390a25050565b6033546001600160a01b03163314610a985760405162461bcd60e51b81526004016101fd90611f5f565b603b8190556040518181527f21167d0d4661af93817ebce920f18986eed3d75d5e1c03f2aed05efcbafbc452906020016109d9565b6033546001600160a01b03163314610af75760405162461bcd60e51b81526004016101fd90611f5f565b6001600160a01b038216600081815260436020908152604091829020805460ff191685151590811790915591519182527f8c0d56805c3b43d441481229dc64bee168253ffe4305f37ab7cfe63b1c4268c69101610a62565b6033546001600160a01b03163314610b795760405162461bcd60e51b81526004016101fd90611f5f565b603580546001600160a01b0319166001600160a01b0383161790556040517f26cb770c9a24026a0c99d6be6fa7fb963470f03731f629156bbdf1baecae5958906109d9908390611b72565b6033546001600160a01b03163314610bee5760405162461bcd60e51b81526004016101fd90611f5f565b6001600160a01b038116610c445760405162461bcd60e51b815260206004820152601d60248201527f506f736974696f6e4d616e616765723a207a65726f206164647265737300000060448201526064016101fd565b603480546001600160a01b0319166001600160a01b0383161790556040517f5a272403b402d892977df56625f4164ccaf70ca3863991c43ecfe76a6905b0a1906109d9908390611b72565b6033546001600160a01b03163314610cb95760405162461bcd60e51b81526004016101fd90611f5f565b604480546001600160a01b0319166001600160a01b0392909216919091179055565b600054610100900460ff1615808015610cfb5750600054600160ff909116105b80610d155750303b158015610d15575060005460ff166001145b610d785760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016101fd565b6000805460ff191660011790558015610d9b576000805461ff0019166101001790555b610da3611598565b60338054336001600160a01b031991821681179092556036805482166001600160a01b03888116919091179091556039805483168783161790556064603b5560348054909216909217905560408054600160a81b928516600161ff0160a01b0319909116179190911790558015610e54576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50505050565b6033546001600160a01b03163314610e845760405162461bcd60e51b81526004016101fd90611f5f565b603c80546001600160a01b0319166001600160a01b0383161790556040517f57202bce87a87010e83825477a341d777f701216d3e2a3b4642c72d9e8a93198906109d9908390611b72565b6033546001600160a01b03163314610ef95760405162461bcd60e51b81526004016101fd90611f5f565b6001600160a01b038116610f4a5760405162461bcd60e51b8152602060048201526018602482015277476f7665726e61626c653a207a65726f206164647265737360401b60448201526064016101fd565b603380546001600160a01b0319166001600160a01b0383169081179091556040517fe24c39186e9137521953beaa8446e71f55b8f12296984f9d4273ceb1af728d90916109d991611b72565b3360009081526041602052604090205460ff16610fc55760405162461bcd60e51b81526004016101fd90611eeb565b610fcf83836115c9565b603654604080516312d43a5160e01b815290516001600160a01b039092169160009183916312d43a51916004808201926020929091908290030181865afa15801561101e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110429190611f42565b60408054905163d3bab1d160e01b8152919250600091829182916001600160a01b039091169063d3bab1d19061107e908b908b90600401611f8e565b61012060405180830381865afa15801561109c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110c09190611fa7565b505060448054604051637ebea3e360e01b81526001600160a01b0380881660048301526024820187905285151593820193909352959b5093995091975050169350637ebea3e392506064019050600060405180830381600087803b15801561112757600080fd5b505af115801561113b573d6000803e3d6000fd5b50506040516306d63c1d60e41b81526001600160a01b0387169250636d63c1d0915061116b908890600401611b72565b600060405180830381600087803b15801561118557600080fd5b505af1158015611199573d6000803e3d6000fd5b505060408054905163d38ab51960e01b81526001600160a01b03909116925063d38ab51991506111d1908b908b908b90600401611f1f565b600060405180830381600087803b1580156111eb57600080fd5b505af11580156111ff573d6000803e3d6000fd5b505060405163d3c87bbb60e01b81526001600160a01b038716925063d3c87bbb915061122f908890600401611b72565b600060405180830381600087803b15801561124957600080fd5b505af115801561125d573d6000803e3d6000fd5b505050505050505050505050565b6112736118d0565b3360009081526043602052604090205460ff166112a25760405162461bcd60e51b81526004016101fd90611eeb565b603654604080516312d43a5160e01b815290516001600160a01b039092169160009183916312d43a51916004808201926020929091908290030181865afa1580156112f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113159190611f42565b6040516306d63c1d60e41b81529091506001600160a01b03821690636d63c1d090611344908590600401611b72565b600060405180830381600087803b15801561135e57600080fd5b505af1158015611372573d6000803e3d6000fd5b5050604051631bc5d52960e31b81526001600160a01b038a8116600483015289811660248301528881166044830152871515606483015286811660848301528516925063de2ea948915060a401600060405180830381600087803b1580156113d957600080fd5b505af11580156113ed573d6000803e3d6000fd5b505060405163d3c87bbb60e01b81526001600160a01b038416925063d3c87bbb915061141d908590600401611b72565b600060405180830381600087803b15801561143757600080fd5b505af115801561144b573d6000803e3d6000fd5b50505050505061145a60018055565b5050505050565b6034546001600160a01b031633148061148457506033546001600160a01b031633145b6114a05760405162461bcd60e51b81526004016101fd90611eeb565b60005b83518110156115575760008482815181106114c0576114c0612043565b602002602001015190508382815181106114dc576114dc612043565b6020026020010151603e6000836001600160a01b03166001600160a01b031681526020019081526020016000208190555082828151811061151f5761151f612043565b6020908102919091018101516001600160a01b039092166000908152603f90915260409020558061154f8161206f565b9150506114a3565b507fae32d569b058895b9620d6552b09aaffedc9a6f396be4d595a224ad09f8b213983838360405161158b939291906120c3565b60405180910390a1505050565b600054610100900460ff166115bf5760405162461bcd60e51b81526004016101fd90612138565b6115c761192f565b565b60408054905163d3bab1d160e01b8152600091829182918291829182916001600160a01b039091169063d3bab1d190611608908b908b90600401611f8e565b61012060405180830381865afa158015611626573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061164a9190611fa7565b505050955095509550955095509550611664838284611956565b604054600160a81b900460ff1661167f575050505050505050565b8061168e575050505050505050565b600082116116de5760405162461bcd60e51b815260206004820152601d60248201527f506f736974696f6e4d616e616765723a206c6f6e67206465706f73697400000060448201526064016101fd565b603654604051634a3f088d60e01b81526001600160a01b038a811660048301528681166024830152858116604483015283151560648301529091169060009081908390634a3f088d9060840161010060405180830381865afa158015611748573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061176c9190612183565b505050505050915091508160000361178b575050505050505050505050565b600061179786846121ed565b90506000846001600160a01b0316630a48d5a98c8c6040518363ffffffff1660e01b81526004016117c9929190611f8e565b602060405180830381865afa1580156117e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061180a9190612206565b9050600061181882856121ed565b90506000846118296127108861221f565b6118339190612236565b9050600082603b5461271061184891906121ed565b611852908761221f565b61185c9190612236565b9050818110156118be5760405162461bcd60e51b815260206004820152602760248201527f506f736974696f6e4d616e616765723a206c6f6e67206c6576657261676520646044820152666563726561736560c81b60648201526084016101fd565b50505050505050505050505050505050565b6002600154036119225760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016101fd565b6002600155565b60018055565b600054610100900460ff166119295760405162461bcd60e51b81526004016101fd90612138565b8060000361196357505050565b8115611a6d576001600160a01b0383166000908152603e60205260409020548015801590611a0d575060365460405163783a2b6760e11b8152829184916001600160a01b039091169063f07456ce906119c0908990600401611b72565b602060405180830381865afa1580156119dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a019190612206565b611a0b91906121ed565b115b15610e545760405162461bcd60e51b815260206004820152602a60248201527f506f736974696f6e4d616e616765723a206d617820676c6f62616c206c6f6e676044820152691cc8195e18d95959195960b21b60648201526084016101fd565b6001600160a01b0383166000908152603f60205260409020548015801590611b11575060365460405163114f1b5560e31b8152829184916001600160a01b0390911690638a78daa890611ac4908990600401611b72565b602060405180830381865afa158015611ae1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b059190612206565b611b0f91906121ed565b115b15610e545760405162461bcd60e51b815260206004820152602b60248201527f506f736974696f6e4d616e616765723a206d617820676c6f62616c2073686f7260448201526a1d1cc8195e18d95959195960aa1b60648201526084016101fd565b6001600160a01b0391909116815260200190565b6001600160a01b0381168114611b9b57600080fd5b50565b600080600060608486031215611bb357600080fd5b8335611bbe81611b86565b9250602084013591506040840135611bd581611b86565b809150509250925092565b600060208284031215611bf257600080fd5b8135611bfd81611b86565b9392505050565b8015158114611b9b57600080fd5b600060208284031215611c2457600080fd5b8135611bfd81611c04565b60008060408385031215611c4257600080fd5b8235611c4d81611b86565b91506020830135611c5d81611c04565b809150509250929050565b600060208284031215611c7a57600080fd5b5035919050565b600080600060608486031215611c9657600080fd5b8335611ca181611b86565b92506020840135611cb181611b86565b91506040840135611bd581611b86565b600080600080600060a08688031215611cd957600080fd5b8535611ce481611b86565b94506020860135611cf481611b86565b93506040860135611d0481611b86565b92506060860135611d1481611c04565b91506080860135611d2481611b86565b809150509295509295909350565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715611d7057611d70611d32565b604052919050565b60006001600160401b03821115611d9157611d91611d32565b5060051b60200190565b600082601f830112611dac57600080fd5b81356020611dc1611dbc83611d78565b611d48565b82815260059290921b84018101918181019086841115611de057600080fd5b8286015b84811015611dfb5780358352918301918301611de4565b509695505050505050565b600080600060608486031215611e1b57600080fd5b83356001600160401b0380821115611e3257600080fd5b818601915086601f830112611e4657600080fd5b81356020611e56611dbc83611d78565b82815260059290921b8401810191818101908a841115611e7557600080fd5b948201945b83861015611e9c578535611e8d81611b86565b82529482019490820190611e7a565b97505087013592505080821115611eb257600080fd5b611ebe87838801611d9b565b93506040860135915080821115611ed457600080fd5b50611ee186828701611d9b565b9150509250925092565b6020808252601a90820152792837b9b4ba34b7b726b0b730b3b2b91d103337b93134b23232b760311b604082015260600190565b6001600160a01b0393841681526020810192909252909116604082015260600190565b600060208284031215611f5457600080fd5b8151611bfd81611b86565b60208082526015908201527423b7bb32b93730b136329d103337b93134b23232b760591b604082015260600190565b6001600160a01b03929092168252602082015260400190565b60008060008060008060008060006101208a8c031215611fc657600080fd5b8951611fd181611b86565b60208b015160408c0151919a509850611fe981611b86565b60608b0151909750611ffa81611b86565b60808b015160a08c0151919750955061201281611c04565b60c08b015160e08c0151919550935061202a81611c04565b809250506101008a015190509295985092959850929598565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60006001820161208157612081612059565b5060010190565b600081518084526020808501945080840160005b838110156120b85781518752958201959082019060010161209c565b509495945050505050565b606080825284519082018190526000906020906080840190828801845b828110156121055781516001600160a01b0316845292840192908401906001016120e0565b505050838103828501526121198187612088565b915050828103604084015261212e8185612088565b9695505050505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b600080600080600080600080610100898b0312156121a057600080fd5b885197506020890151965060408901519550606089015194506080890151935060a0890151925060c08901516121d581611c04565b8092505060e089015190509295985092959890939650565b8082018082111561220057612200612059565b92915050565b60006020828403121561221857600080fd5b5051919050565b808202811582820484141761220057612200612059565b60008261225357634e487b7160e01b600052601260045260246000fd5b50049056fea2646970667358221220f5cda5e2ed8e56df850a140929737b2040a8966e0fc54200d5186ce1499d187064736f6c63430008110033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 27 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.