Source Code
Latest 25 from a total of 746,289 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Set Prices And E... | 266446922 | 460 days ago | IN | 1 wei | 0.00001272 | ||||
| Set Prices And E... | 266446705 | 460 days ago | IN | 1 wei | 0.00000664 | ||||
| Set Prices And E... | 266446691 | 460 days ago | IN | 1 wei | 0.00001198 | ||||
| Set Prices And E... | 266446661 | 460 days ago | IN | 1 wei | 0.00001124 | ||||
| Set Prices And E... | 266375299 | 460 days ago | IN | 1 wei | 0.00001062 | ||||
| Set Prices And E... | 266375293 | 460 days ago | IN | 1 wei | 0.00001069 | ||||
| Set Prices And E... | 266375143 | 460 days ago | IN | 1 wei | 0.00001069 | ||||
| Set Prices And E... | 266375137 | 460 days ago | IN | 1 wei | 0.00001056 | ||||
| Set Prices And E... | 266374955 | 460 days ago | IN | 1 wei | 0.00001061 | ||||
| Set Prices And E... | 266374949 | 460 days ago | IN | 1 wei | 0.00001073 | ||||
| Set Prices And E... | 266374786 | 460 days ago | IN | 1 wei | 0.00001063 | ||||
| Set Prices And E... | 266374780 | 460 days ago | IN | 1 wei | 0.00001049 | ||||
| Set Prices And E... | 266374622 | 460 days ago | IN | 1 wei | 0.00001058 | ||||
| Set Prices And E... | 266374616 | 460 days ago | IN | 1 wei | 0.00001068 | ||||
| Set Prices And E... | 266374410 | 460 days ago | IN | 1 wei | 0.00001067 | ||||
| Set Prices And E... | 266374404 | 460 days ago | IN | 1 wei | 0.00001051 | ||||
| Set Prices And E... | 266374358 | 460 days ago | IN | 1 wei | 0.00001034 | ||||
| Set Prices And E... | 266374352 | 460 days ago | IN | 1 wei | 0.00001027 | ||||
| Set Prices And E... | 266374186 | 460 days ago | IN | 1 wei | 0.00001055 | ||||
| Set Prices And E... | 266374180 | 460 days ago | IN | 1 wei | 0.00001067 | ||||
| Set Prices And E... | 266374174 | 460 days ago | IN | 1 wei | 0.00001078 | ||||
| Set Prices And E... | 266374168 | 460 days ago | IN | 1 wei | 0.00001069 | ||||
| Set Prices And E... | 266374018 | 460 days ago | IN | 1 wei | 0.00001063 | ||||
| Set Prices And E... | 266374012 | 460 days ago | IN | 1 wei | 0.0000105 | ||||
| Set Prices And E... | 266373942 | 460 days ago | IN | 1 wei | 0.00001033 |
Latest 25 internal transactions (View All)
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 266446922 | 460 days ago | 1 wei | ||||
| 266446705 | 460 days ago | 1 wei | ||||
| 266446691 | 460 days ago | 1 wei | ||||
| 266446661 | 460 days ago | 1 wei | ||||
| 266375299 | 460 days ago | 1 wei | ||||
| 266375293 | 460 days ago | 1 wei | ||||
| 266375143 | 460 days ago | 1 wei | ||||
| 266375137 | 460 days ago | 1 wei | ||||
| 266374955 | 460 days ago | 1 wei | ||||
| 266374949 | 460 days ago | 1 wei | ||||
| 266374786 | 460 days ago | 1 wei | ||||
| 266374780 | 460 days ago | 1 wei | ||||
| 266374622 | 460 days ago | 1 wei | ||||
| 266374616 | 460 days ago | 1 wei | ||||
| 266374410 | 460 days ago | 1 wei | ||||
| 266374404 | 460 days ago | 1 wei | ||||
| 266374358 | 460 days ago | 1 wei | ||||
| 266374352 | 460 days ago | 1 wei | ||||
| 266374186 | 460 days ago | 1 wei | ||||
| 266374180 | 460 days ago | 1 wei | ||||
| 266374174 | 460 days ago | 1 wei | ||||
| 266374168 | 460 days ago | 1 wei | ||||
| 266374018 | 460 days ago | 1 wei | ||||
| 266374012 | 460 days ago | 1 wei | ||||
| 266373942 | 460 days ago | 1 wei |
Cross-Chain Transactions
Loading...
Loading
Contract Name:
Executor
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "../interfaces/IExecutor.sol";
import "../interfaces/IAddressesProvider.sol";
import "../interfaces/IRoleManager.sol";
import "../interfaces/IIndexPriceFeed.sol";
import "../interfaces/IPythOraclePriceFeed.sol";
import "../interfaces/IExecutionLogic.sol";
import "../libraries/Roleable.sol";
import "../interfaces/ILiquidationLogic.sol";
import "./Backtracker.sol";
import "../interfaces/IPositionManager.sol";
contract Executor is IExecutor, Roleable, ReentrancyGuard, Pausable {
IPositionManager public positionManager;
constructor(
IAddressesProvider addressProvider
) Roleable(addressProvider) {
}
modifier onlyPositionKeeper() {
require(IRoleManager(ADDRESS_PROVIDER.roleManager()).isKeeper(msg.sender), "opk");
_;
}
function setPaused() external onlyPoolAdmin {
_pause();
}
function setUnPaused() external onlyPoolAdmin {
_unpause();
}
function updatePositionManager(address _positionManager) external onlyPoolAdmin {
address oldAddress = address(positionManager);
positionManager = IPositionManager(_positionManager);
emit UpdatePositionManager(msg.sender, oldAddress, _positionManager);
}
function setPricesAndExecuteOrders(
address[] memory tokens,
uint256[] memory prices,
bytes[] memory updateData,
uint64[] memory publishTimes,
IExecutionLogic.ExecuteOrder[] memory orders
) external payable override whenNotPaused nonReentrant onlyPositionKeeper {
require(tokens.length == prices.length && tokens.length >= 0, "ip");
_setPrices(tokens, prices, updateData, publishTimes);
for (uint256 i = 0; i < orders.length; i++) {
IExecutionLogic.ExecuteOrder memory order = orders[i];
if (order.isIncrease) {
IExecutionLogic(ADDRESS_PROVIDER.executionLogic()).executeIncreaseOrders(
msg.sender,
_fillOrders(order),
order.tradeType
);
} else {
IExecutionLogic(ADDRESS_PROVIDER.executionLogic()).executeDecreaseOrders(
msg.sender,
_fillOrders(order),
order.tradeType
);
}
}
}
function setPricesAndExecuteIncreaseMarketOrders(
address[] memory tokens,
uint256[] memory prices,
bytes[] memory updateData,
uint64[] memory publishTimes,
IExecutionLogic.ExecuteOrder[] memory increaseOrders
) external payable override whenNotPaused nonReentrant onlyPositionKeeper {
require(tokens.length == prices.length && tokens.length >= 0, "ip");
_setPrices(tokens, prices, updateData, publishTimes);
IExecutionLogic(ADDRESS_PROVIDER.executionLogic()).executeIncreaseOrders(
msg.sender,
increaseOrders,
TradingTypes.TradeType.MARKET
);
}
function setPricesAndExecuteDecreaseMarketOrders(
address[] memory tokens,
uint256[] memory prices,
bytes[] memory updateData,
uint64[] memory publishTimes,
IExecutionLogic.ExecuteOrder[] memory decreaseOrders
) external payable override whenNotPaused nonReentrant onlyPositionKeeper {
require(tokens.length == prices.length && tokens.length >= 0, "ip");
_setPrices(tokens, prices, updateData, publishTimes);
IExecutionLogic(ADDRESS_PROVIDER.executionLogic()).executeDecreaseOrders(
msg.sender,
decreaseOrders,
TradingTypes.TradeType.MARKET
);
}
function setPricesAndExecuteIncreaseLimitOrders(
address[] memory tokens,
uint256[] memory prices,
bytes[] memory updateData,
uint64[] memory publishTimes,
IExecutionLogic.ExecuteOrder[] memory increaseOrders
) external payable override whenNotPaused nonReentrant onlyPositionKeeper {
require(tokens.length == prices.length && tokens.length >= 0, "ip");
_setPrices(tokens, prices, updateData, publishTimes);
IExecutionLogic(ADDRESS_PROVIDER.executionLogic()).executeIncreaseOrders(
msg.sender,
increaseOrders,
TradingTypes.TradeType.LIMIT
);
}
function setPricesAndExecuteDecreaseLimitOrders(
address[] memory tokens,
uint256[] memory prices,
bytes[] memory updateData,
uint64[] memory publishTimes,
IExecutionLogic.ExecuteOrder[] memory decreaseOrders
) external payable override whenNotPaused nonReentrant onlyPositionKeeper {
require(tokens.length == prices.length && tokens.length >= 0, "ip");
_setPrices(tokens, prices, updateData, publishTimes);
IExecutionLogic(ADDRESS_PROVIDER.executionLogic()).executeDecreaseOrders(
msg.sender,
decreaseOrders,
TradingTypes.TradeType.LIMIT
);
}
function setPricesAndExecuteADLOrders(
address[] memory tokens,
uint256[] memory prices,
bytes[] memory updateData,
uint64[] memory publishTimes,
uint256 pairIndex,
IExecution.ExecutePosition[] memory executePositions,
IExecutionLogic.ExecuteOrder[] memory executeOrders
) external payable override whenNotPaused nonReentrant onlyPositionKeeper {
require(tokens.length == prices.length && tokens.length >= 0, "ip");
_setPrices(tokens, prices, updateData, publishTimes);
IExecutionLogic(ADDRESS_PROVIDER.executionLogic()).executeADLAndDecreaseOrders(
msg.sender,
pairIndex,
executePositions,
executeOrders
);
}
function setPricesAndLiquidatePositions(
address[] memory _tokens,
uint256[] memory _prices,
LiquidatePosition[] memory liquidatePositions
) external payable override whenNotPaused nonReentrant onlyPositionKeeper {
require(_tokens.length == _prices.length && _tokens.length >= 0, "ip");
IIndexPriceFeed(ADDRESS_PROVIDER.indexPriceOracle()).updatePrice(_tokens, _prices);
for (uint256 i = 0; i < liquidatePositions.length; i++) {
LiquidatePosition memory execute = liquidatePositions[i];
IBacktracker(ADDRESS_PROVIDER.backtracker()).enterBacktracking(execute.backtrackRound);
address[] memory tokens = new address[](1);
tokens[0] = execute.token;
bytes[] memory updatesData = new bytes[](1);
updatesData[0] = execute.updateData;
IPythOraclePriceFeed(ADDRESS_PROVIDER.priceOracle()).updateHistoricalPrice{value: execute.updateFee}(
tokens,
updatesData,
execute.backtrackRound
);
try ILiquidationLogic(ADDRESS_PROVIDER.liquidationLogic()).liquidationPosition(
msg.sender,
execute.positionKey,
execute.tier,
execute.referralsRatio,
execute.referralUserRatio,
execute.referralOwner
) {} catch Error(string memory reason) {
emit ExecutePositionError(execute.positionKey, reason);
}
IPythOraclePriceFeed(ADDRESS_PROVIDER.priceOracle()).removeHistoricalPrice(
execute.backtrackRound,
tokens
);
IBacktracker(ADDRESS_PROVIDER.backtracker()).quitBacktracking();
}
}
function _setPrices(
address[] memory _tokens,
uint256[] memory _prices,
bytes[] memory updateData,
uint64[] memory publishTimes
) internal {
IIndexPriceFeed(ADDRESS_PROVIDER.indexPriceOracle()).updatePrice(_tokens, _prices);
IPythOraclePriceFeed(ADDRESS_PROVIDER.priceOracle()).updatePrice{value: msg.value}(
_tokens,
updateData,
publishTimes
);
}
// function _setPricesHistorical(
// address[] memory _tokens,
// uint256[] memory _prices,
// bytes[] memory updateData,
// uint64 backtrackRound
// ) internal {
//
// IIndexPriceFeed(ADDRESS_PROVIDER.indexPriceOracle()).updatePrice(_tokens, _prices);
//
// IPythOraclePriceFeed(ADDRESS_PROVIDER.priceOracle()).updateHistoricalPrice{value: msg.value}(
// _tokens,
// updateData,
// backtrackRound
// );
// }
function needADL(
uint256 pairIndex,
bool isLong,
uint256 executionSize,
uint256 executionPrice
) external view returns (bool need, uint256 needADLAmount) {
return positionManager.needADL(pairIndex, isLong, executionSize, executionPrice);
}
function cleanInvalidPositionOrders(
bytes32[] calldata positionKeys
) external override whenNotPaused nonReentrant onlyPositionKeeper {
ILiquidationLogic(ADDRESS_PROVIDER.liquidationLogic()).cleanInvalidPositionOrders(positionKeys);
}
function _fillOrders(
IExecutionLogic.ExecuteOrder memory order
) private pure returns (IExecutionLogic.ExecuteOrder[] memory increaseOrders) {
increaseOrders = new IExecutionLogic.ExecuteOrder[](1);
increaseOrders[0] = order;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol)
pragma solidity ^0.8.0;
// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.
/**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
import "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;
import "../interfaces/IBacktracker.sol";
import "../interfaces/IAddressesProvider.sol";
import "../interfaces/IRoleManager.sol";
contract Backtracker is IBacktracker {
IAddressesProvider public immutable ADDRESS_PROVIDER;
bool public override backtracking;
uint64 public override backtrackRound;
address public executor;
constructor(IAddressesProvider addressProvider) {
ADDRESS_PROVIDER = addressProvider;
backtracking = false;
}
modifier whenNotBacktracking() {
_requireNotBacktracking();
_;
}
modifier whenBacktracking() {
_requireBacktracking();
_;
}
modifier onlyPoolAdmin() {
require(IRoleManager(ADDRESS_PROVIDER.roleManager()).isPoolAdmin(msg.sender), "only poolAdmin");
_;
}
modifier onlyExecutor() {
require(msg.sender == executor, "only executor");
_;
}
function updateExecutorAddress(address newAddress) external onlyPoolAdmin {
address oldAddress = executor;
executor = newAddress;
emit UpdatedExecutorAddress(msg.sender, oldAddress, newAddress);
}
function enterBacktracking(uint64 _backtrackRound) external whenNotBacktracking onlyExecutor {
backtracking = true;
backtrackRound = _backtrackRound;
emit Backtracking(msg.sender, _backtrackRound);
}
function quitBacktracking() external whenBacktracking onlyExecutor {
backtracking = false;
emit UnBacktracking(msg.sender);
}
function _requireNotBacktracking() internal view {
require(!backtracking, "Backtracker: backtracking");
}
function _requireBacktracking() internal view {
require(backtracking, "Backtracker: not backtracking");
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "../libraries/PrecisionUtils.sol";
import "../interfaces/IPool.sol";
library TokenHelper {
using PrecisionUtils for uint256;
using SafeMath for uint256;
function convertIndexAmountToStable(
IPool.Pair memory pair,
int256 indexTokenAmount
) internal view returns (int256 amount) {
if (indexTokenAmount == 0) return 0;
uint8 stableTokenDec = IERC20Metadata(pair.stableToken).decimals();
return convertTokenAmountTo(pair.indexToken, indexTokenAmount, stableTokenDec);
}
function convertIndexAmountToStableWithPrice(
IPool.Pair memory pair,
int256 indexTokenAmount,
uint256 price
) internal view returns (int256 amount) {
if (indexTokenAmount == 0) return 0;
uint8 stableTokenDec = IERC20Metadata(pair.stableToken).decimals();
return convertTokenAmountWithPrice(pair.indexToken, indexTokenAmount, stableTokenDec, price);
}
function convertTokenAmountWithPrice(
address token,
int256 tokenAmount,
uint8 targetDecimals,
uint256 price
) internal view returns (int256 amount) {
if (tokenAmount == 0) return 0;
uint256 tokenDec = uint256(IERC20Metadata(token).decimals());
uint256 tokenWad = 10 ** (PrecisionUtils.maxTokenDecimals() - tokenDec);
uint256 targetTokenWad = 10 ** (PrecisionUtils.maxTokenDecimals() - targetDecimals);
amount = (tokenAmount * int256(tokenWad)) * int256(price) / int256(targetTokenWad) / int256(PrecisionUtils.PRICE_PRECISION);
}
function convertStableAmountToIndex(
IPool.Pair memory pair,
int256 stableTokenAmount
) internal view returns (int256 amount) {
if (stableTokenAmount == 0) return 0;
uint8 indexTokenDec = IERC20Metadata(pair.indexToken).decimals();
return convertTokenAmountTo(pair.stableToken, stableTokenAmount, indexTokenDec);
}
function convertTokenAmountTo(
address token,
int256 tokenAmount,
uint8 targetDecimals
) internal view returns (int256 amount) {
if (tokenAmount == 0) return 0;
uint256 tokenDec = uint256(IERC20Metadata(token).decimals());
uint256 tokenWad = 10 ** (PrecisionUtils.maxTokenDecimals() - tokenDec);
uint256 targetTokenWad = 10 ** (PrecisionUtils.maxTokenDecimals() - targetDecimals);
amount = (tokenAmount * int256(tokenWad)) / int256(targetTokenWad);
}
}// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;
interface IAddressesProvider {
event AddressSet(bytes32 indexed id, address indexed oldAddress, address indexed newAddress);
function WETH() external view returns (address);
function timelock() external view returns (address);
function priceOracle() external view returns (address);
function indexPriceOracle() external view returns (address);
function fundingRate() external view returns (address);
function executionLogic() external view returns (address);
function liquidationLogic() external view returns (address);
function roleManager() external view returns (address);
function backtracker() external view returns (address);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
interface IBacktracker {
event Backtracking(address account, uint64 round);
event UnBacktracking(address account);
event UpdatedExecutorAddress(address sender, address oldAddress, address newAddress);
function backtracking() external view returns (bool);
function backtrackRound() external view returns (uint64);
function enterBacktracking(uint64 _backtrackRound) external;
function quitBacktracking() external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import '../libraries/TradingTypes.sol';
import '../libraries/Position.sol';
interface IExecution {
event ExecuteIncreaseOrder(
address account,
uint256 orderId,
uint256 pairIndex,
TradingTypes.TradeType tradeType,
bool isLong,
int256 collateral,
uint256 orderSize,
uint256 orderPrice,
uint256 executionSize,
uint256 executionPrice,
uint256 executedSize,
uint256 tradingFee,
int256 fundingFee,
TradingTypes.InnerPaymentType paymentType,
uint256 networkFeeAmount
);
event ExecuteDecreaseOrder(
address account,
uint256 orderId,
uint256 pairIndex,
TradingTypes.TradeType tradeType,
bool isLong,
int256 collateral,
uint256 orderSize,
uint256 orderPrice,
uint256 executionSize,
uint256 executionPrice,
uint256 executedSize,
bool needADL,
int256 pnl,
uint256 tradingFee,
int256 fundingFee,
TradingTypes.InnerPaymentType paymentType,
uint256 networkFeeAmount
);
event ExecuteAdlOrder(
uint256[] adlOrderIds,
bytes32[] adlPositionKeys,
uint256[] orders
);
event ExecuteOrderError(uint256 orderId, string errorMessage);
event ExecutePositionError(bytes32 positionKey, string errorMessage);
event InvalidOrder(address sender, uint256 orderId, string message);
event ZeroPosition(address sender, address account, uint256 pairIndex, bool isLong, string message);
struct ExecutePosition {
bytes32 positionKey;
uint256 sizeAmount;
uint8 tier;
uint256 referralsRatio;
uint256 referralUserRatio;
address referralOwner;
}
struct LiquidatePosition {
address token;
bytes updateData;
uint256 updateFee;
uint64 backtrackRound;
bytes32 positionKey;
uint256 sizeAmount;
uint8 tier;
uint256 referralsRatio;
uint256 referralUserRatio;
address referralOwner;
}
struct PositionOrder {
address account;
uint256 pairIndex;
bool isLong;
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "../libraries/TradingTypes.sol";
import "../libraries/Position.sol";
import "./IExecution.sol";
interface IExecutionLogic is IExecution {
event UpdateMaxTimeDelay(uint256 oldDelay, uint256 newDelay);
event UpdateExecutorAddress(address sender, address oldAddress, address newAddress);
struct ExecuteOrder {
uint256 orderId;
TradingTypes.TradeType tradeType;
bool isIncrease;
uint8 tier;
uint256 referralsRatio;
uint256 referralUserRatio;
address referralOwner;
}
struct ExecutePositionInfo {
Position.Info position;
uint256 executionSize;
uint8 tier;
uint256 referralsRatio;
uint256 referralUserRatio;
address referralOwner;
}
function maxTimeDelay() external view returns (uint256);
function updateExecutor(address _executor) external;
function updateMaxTimeDelay(uint256 newMaxTimeDelay) external;
function executeIncreaseOrders(
address keeper,
ExecuteOrder[] memory orders,
TradingTypes.TradeType tradeType
) external;
function executeIncreaseOrder(
address keeper,
uint256 _orderId,
TradingTypes.TradeType _tradeType,
uint8 tier,
uint256 referralsRatio,
uint256 referralUserRatio,
address referralOwner
) external;
function executeDecreaseOrders(
address keeper,
ExecuteOrder[] memory orders,
TradingTypes.TradeType tradeType
) external;
function executeDecreaseOrder(
address keeper,
uint256 _orderId,
TradingTypes.TradeType _tradeType,
uint8 tier,
uint256 referralsRatio,
uint256 referralUserRatio,
address referralOwner,
bool isSystem,
uint256 executionSize,
bool onlyOnce
) external;
function executeADLAndDecreaseOrders(
address keeper,
uint256 pairIndex,
ExecutePosition[] memory executePositions,
IExecutionLogic.ExecuteOrder[] memory executeOrders
) external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import '../libraries/TradingTypes.sol';
import "./IExecutionLogic.sol";
interface IExecutor is IExecution {
event UpdatePositionManager(address sender, address oldAddress, address newAddress);
function setPricesAndExecuteOrders(
address[] memory tokens,
uint256[] memory prices,
bytes[] memory updateData,
uint64[] memory publishTimes,
IExecutionLogic.ExecuteOrder[] memory orders
) external payable;
function setPricesAndExecuteIncreaseMarketOrders(
address[] memory tokens,
uint256[] memory prices,
bytes[] memory updateData,
uint64[] memory publishTimes,
IExecutionLogic.ExecuteOrder[] memory increaseOrders
) external payable;
function setPricesAndExecuteDecreaseMarketOrders(
address[] memory tokens,
uint256[] memory prices,
bytes[] memory updateData,
uint64[] memory publishTimes,
IExecutionLogic.ExecuteOrder[] memory decreaseOrders
) external payable;
function setPricesAndExecuteIncreaseLimitOrders(
address[] memory tokens,
uint256[] memory prices,
bytes[] memory updateData,
uint64[] memory publishTimes,
IExecutionLogic.ExecuteOrder[] memory increaseOrders
) external payable;
function setPricesAndExecuteDecreaseLimitOrders(
address[] memory tokens,
uint256[] memory prices,
bytes[] memory updateData,
uint64[] memory publishTimes,
IExecutionLogic.ExecuteOrder[] memory decreaseOrders
) external payable;
function setPricesAndExecuteADLOrders(
address[] memory tokens,
uint256[] memory prices,
bytes[] memory updateData,
uint64[] memory publishTimes,
uint256 pairIndex,
IExecution.ExecutePosition[] memory executePositions,
IExecutionLogic.ExecuteOrder[] memory executeOrders
) external payable;
function setPricesAndLiquidatePositions(
address[] memory _tokens,
uint256[] memory _prices,
LiquidatePosition[] memory liquidatePositions
) external payable;
function needADL(
uint256 pairIndex,
bool isLong,
uint256 executionSize,
uint256 executionPrice
) external view returns (bool need, uint256 needADLAmount);
function cleanInvalidPositionOrders(
bytes32[] calldata positionKeys
) external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "./IPool.sol";
import "../libraries/TradingTypes.sol";
interface IFeeCollector {
event UpdatedTradingFeeTier(
address sender,
uint8 tier,
uint256 oldTakerFee,
uint256 oldMakerFee,
uint256 newTakerFee,
uint256 newMakerFee
);
event UpdateMaxReferralsRatio(uint256 oldRatio, uint256 newRatio);
event UpdatedStakingPoolAddress(address sender, address oldAddress, address newAddress);
event UpdatedPositionManagerAddress(address sender, address oldAddress, address newAddress);
event UpdateExecutionLogicAddress(address sender, address oldAddress, address newAddress);
event DistributeTradingFee(
address account,
uint256 pairIndex,
uint256 sizeDelta,
uint256 tradingFee,
uint256 vipDiscountAmount,
uint256 vipFeeRate,
uint256 referralsAmount,
uint256 referralUserAmount,
address referralOwner,
uint256 lpAmount,
uint256 keeperAmount,
uint256 stakingAmount,
uint256 distributorAmount
);
event ClaimedStakingTradingFee(address account, address claimToken, uint256 amount);
event ClaimedDistributorTradingFee(address account, address claimToken, uint256 amount);
event ClaimedReferralsTradingFee(address account, address claimToken, uint256 amount);
event ClaimedUserTradingFee(address account, address claimToken, uint256 amount);
event ClaimedKeeperNetworkFee(address account, address claimToken, uint256 amount);
struct TradingFeeTier {
uint256 makerFee;
uint256 takerFee;
}
function maxReferralsRatio() external view returns (uint256 maxReferenceRatio);
function stakingTradingFee() external view returns (uint256);
function treasuryFee() external view returns (uint256);
function userTradingFee(address _account) external view returns (uint256);
function referralFee(address _referralOwner) external view returns (uint256);
function getTradingFeeTier(uint256 pairIndex, uint8 tier) external view returns (TradingFeeTier memory);
function getRegularTradingFeeTier(uint256 pairIndex) external view returns (TradingFeeTier memory);
function getKeeperNetworkFee(
address account,
TradingTypes.InnerPaymentType paymentType
) external view returns (uint256);
function updateMaxReferralsRatio(uint256 newRatio) external;
function claimStakingTradingFee() external returns (uint256);
function claimTreasuryFee() external returns (uint256);
function claimReferralFee() external returns (uint256);
function claimUserTradingFee() external returns (uint256);
function claimKeeperNetworkFee(
TradingTypes.InnerPaymentType paymentType
) external returns (uint256);
function distributeTradingFee(
IPool.Pair memory pair,
address account,
address keeper,
uint256 sizeDelta,
uint256 tradingFee,
uint256 vipFeeRate,
uint256 referralsRatio,
uint256 referralUserRatio,
address referralOwner
) external returns (uint256 lpAmount, uint256 vipDiscountAmount);
function distributeNetworkFee(
address keeper,
TradingTypes.InnerPaymentType paymentType,
uint256 networkFeeAmount
) external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "./IPriceFeed.sol";
interface IIndexPriceFeed is IPriceFeed {
event UpdateExecutorAddress(address sender, address oldAddress, address newAddress);
event PriceUpdate(address asset, uint256 price, address sender);
function updatePrice(address[] calldata tokens, uint256[] memory prices) external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "./IExecution.sol";
interface ILiquidationLogic is IExecution {
event ExecuteLiquidation(
bytes32 positionKey,
address account,
uint256 pairIndex,
bool isLong,
uint256 collateral,
uint256 sizeAmount,
uint256 price,
uint256 orderId
);
event UpdateExecutorAddress(address sender, address oldAddress, address newAddress);
function updateExecutor(address _executor) external;
function liquidationPosition(
address keeper,
bytes32 positionKey,
uint8 tier,
uint256 referralsRatio,
uint256 referralUserRatio,
address referralOwner
) external;
function cleanInvalidPositionOrders(
bytes32[] calldata positionKeys
) external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import {IPriceFeed} from "./IPriceFeed.sol";
interface IOraclePriceFeed is IPriceFeed {
function updateHistoricalPrice(
address[] calldata tokens,
bytes[] calldata updateData,
uint64 backtrackRound
) external payable;
function removeHistoricalPrice(
uint64 backtrackRound,
address[] calldata tokens
) external;
function getHistoricalPrice(
uint64 backtrackRound,
address token
) external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
interface IPool {
// Events
event PairAdded(
address indexed indexToken,
address indexed stableToken,
address lpToken,
uint256 index
);
event UpdateTotalAmount(
uint256 indexed pairIndex,
int256 indexAmount,
int256 stableAmount,
uint256 indexTotalAmount,
uint256 stableTotalAmount
);
event UpdateReserveAmount(
uint256 indexed pairIndex,
int256 indexAmount,
int256 stableAmount,
uint256 indexReservedAmount,
uint256 stableReservedAmount
);
event UpdateLPProfit(
uint256 indexed pairIndex,
address token,
int256 profit,
uint256 totalAmount
);
event UpdateAveragePrice(uint256 indexed pairIndex, uint256 averagePrice);
event UpdateSpotSwap(address sender, address oldAddress, address newAddress);
event UpdatePoolView(address sender, address oldAddress, address newAddress);
event UpdateRouter(address sender, address oldAddress, address newAddress);
event UpdateRiskReserve(address sender, address oldAddress, address newAddress);
event UpdateFeeCollector(address sender, address oldAddress, address newAddress);
event UpdatePositionManager(address sender, address oldAddress, address newAddress);
event UpdateOrderManager(address sender, address oldAddress, address newAddress);
event AddStableToken(address sender, address token);
event RemoveStableToken(address sender, address token);
event AddLiquidity(
address indexed recipient,
uint256 indexed pairIndex,
uint256 indexAmount,
uint256 stableAmount,
uint256 lpAmount,
uint256 indexFeeAmount,
uint256 stableFeeAmount,
address slipToken,
uint256 slipFeeAmount,
uint256 lpPrice
);
event RemoveLiquidity(
address indexed recipient,
uint256 indexed pairIndex,
uint256 indexAmount,
uint256 stableAmount,
uint256 lpAmount,
uint256 feeAmount,
uint256 lpPrice
);
event ClaimedFee(address sender, address token, uint256 amount);
struct Vault {
uint256 indexTotalAmount; // total amount of tokens
uint256 indexReservedAmount; // amount of tokens reserved for open positions
uint256 stableTotalAmount;
uint256 stableReservedAmount;
uint256 averagePrice;
}
struct Pair {
uint256 pairIndex;
address indexToken;
address stableToken;
address pairToken;
bool enable;
uint256 kOfSwap; //Initial k value of liquidity
uint256 expectIndexTokenP; // for 100%
uint256 maxUnbalancedP;
uint256 unbalancedDiscountRate;
uint256 addLpFeeP; // Add liquidity fee
uint256 removeLpFeeP; // remove liquidity fee
}
struct TradingConfig {
uint256 minLeverage;
uint256 maxLeverage;
uint256 minTradeAmount;
uint256 maxTradeAmount;
uint256 maxPositionAmount;
uint256 maintainMarginRate; // Maintain the margin rate of for 100%
uint256 priceSlipP; // Price slip point
uint256 maxPriceDeviationP; // Maximum offset of index price
}
struct TradingFeeConfig {
uint256 lpFeeDistributeP;
uint256 stakingFeeDistributeP;
uint256 keeperFeeDistributeP;
uint256 treasuryFeeDistributeP;
uint256 reservedFeeDistributeP;
uint256 ecoFundFeeDistributeP;
}
function pairsIndex() external view returns (uint256);
function getPairIndex(address indexToken, address stableToken) external view returns (uint256);
function getPair(uint256) external view returns (Pair memory);
function getTradingConfig(uint256 _pairIndex) external view returns (TradingConfig memory);
function getTradingFeeConfig(uint256) external view returns (TradingFeeConfig memory);
function getVault(uint256 _pairIndex) external view returns (Vault memory vault);
function transferTokenTo(address token, address to, uint256 amount) external;
function transferEthTo(address to, uint256 amount) external;
function transferTokenOrSwap(
uint256 pairIndex,
address token,
address to,
uint256 amount
) external;
function increaseReserveAmount(
uint256 _pairToken,
uint256 _indexAmount,
uint256 _stableAmount
) external;
function decreaseReserveAmount(
uint256 _pairToken,
uint256 _indexAmount,
uint256 _stableAmount
) external;
function updateAveragePrice(uint256 _pairIndex, uint256 _averagePrice) external;
function setLPStableProfit(uint256 _pairIndex, int256 _profit) external;
function addLiquidity(
address recipient,
uint256 _pairIndex,
uint256 _indexAmount,
uint256 _stableAmount,
bytes calldata data
) external returns (uint256 mintAmount, address slipToken, uint256 slipAmount);
function removeLiquidity(
address payable _receiver,
uint256 _pairIndex,
uint256 _amount,
bool useETH,
bytes calldata data
)
external
returns (uint256 receivedIndexAmount, uint256 receivedStableAmount, uint256 feeAmount);
function claimFee(address token, uint256 amount) external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;
import '../libraries/Position.sol';
import "./IFeeCollector.sol";
enum PositionStatus {
Balance,
NetLong,
NetShort
}
interface IPositionManager {
event UpdateFundingInterval(uint256 oldInterval, uint256 newInterval);
event UpdatePosition(
address account,
bytes32 positionKey,
uint256 pairIndex,
uint256 orderId,
bool isLong,
uint256 beforCollateral,
uint256 afterCollateral,
uint256 price,
uint256 beforPositionAmount,
uint256 afterPositionAmount,
uint256 averagePrice,
int256 fundFeeTracker,
int256 pnl
);
event UpdatedExecutionLogic(address sender, address oldAddress, address newAddress);
event UpdatedLiquidationLogic(address sender, address oldAddress, address newAddress);
event UpdateRouterAddress(address sender, address oldAddress, address newAddress);
event UpdateFundingRate(uint256 pairIndex, uint price, int256 fundingRate, uint256 lastFundingTime);
event TakeFundingFeeAddTraderFee(
address account,
uint256 pairIndex,
uint256 orderId,
uint256 sizeDelta,
uint256 tradingFee,
int256 fundingFee,
uint256 lpTradingFee,
uint256 vipDiscountAmount
);
event AdjustCollateral(
address account,
uint256 pairIndex,
bool isLong,
bytes32 positionKey,
uint256 collateralBefore,
uint256 collateralAfter
);
function getExposedPositions(uint256 pairIndex) external view returns (int256);
function longTracker(uint256 pairIndex) external view returns (uint256);
function shortTracker(uint256 pairIndex) external view returns (uint256);
function getTradingFee(
uint256 _pairIndex,
bool _isLong,
uint256 _sizeAmount,
uint256 price
) external view returns (uint256 tradingFee);
function getFundingFee(
address _account,
uint256 _pairIndex,
bool _isLong
) external view returns (int256 fundingFee);
function getCurrentFundingRate(uint256 _pairIndex) external view returns (int256);
function getNextFundingRate(uint256 _pairIndex, uint256 price) external view returns (int256);
function getNextFundingRateUpdateTime(uint256 _pairIndex) external view returns (uint256);
function needADL(
uint256 pairIndex,
bool isLong,
uint256 executionSize,
uint256 executionPrice
) external view returns (bool needADL, uint256 needADLAmount);
function needLiquidation(
bytes32 positionKey,
uint256 price
) external view returns (bool);
function getPosition(
address _account,
uint256 _pairIndex,
bool _isLong
) external view returns (Position.Info memory);
function getPositionByKey(bytes32 key) external view returns (Position.Info memory);
function getPositionKey(address _account, uint256 _pairIndex, bool _isLong) external pure returns (bytes32);
function increasePosition(
uint256 _pairIndex,
uint256 orderId,
address _account,
address _keeper,
uint256 _sizeAmount,
bool _isLong,
int256 _collateral,
IFeeCollector.TradingFeeTier memory tradingFeeTier,
uint256 referralsRatio,
uint256 referralUserRatio,
address referralOwner,
uint256 _price
) external returns (uint256 tradingFee, int256 fundingFee);
function decreasePosition(
uint256 _pairIndex,
uint256 orderId,
address _account,
address _keeper,
uint256 _sizeAmount,
bool _isLong,
int256 _collateral,
IFeeCollector.TradingFeeTier memory tradingFeeTier,
uint256 referralsRatio,
uint256 referralUserRatio,
address referralOwner,
uint256 _price,
bool useRiskReserve
) external returns (uint256 tradingFee, int256 fundingFee, int256 pnl);
function adjustCollateral(uint256 pairIndex, address account, bool isLong, int256 collateral) external;
function updateFundingRate(uint256 _pairIndex) external;
function lpProfit(uint pairIndex, address token, uint256 price) external view returns (int256 profit);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
interface IPriceFeed {
event PriceAgeUpdated(uint256 oldAge, uint256 newAge);
function getPrice(address token) external view returns (uint256);
function getPriceSafely(address token) external view returns (uint256);
function decimals() external pure returns (uint256);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "./IOraclePriceFeed.sol";
interface IPythOraclePriceFeed is IOraclePriceFeed {
event TokenPriceIdUpdated(
address token,
bytes32 priceId
);
event PythAddressUpdated(address oldAddress, address newAddress);
event UpdatedExecutorAddress(address sender, address oldAddress, address newAddress);
event UnneededPricePublishWarn();
function updatePrice(
address[] calldata tokens,
bytes[] calldata updateData,
uint64[] calldata publishTimes
) external payable;
}// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;
interface IRoleManager {
function setRoleAdmin(bytes32 role, bytes32 adminRole) external;
function isAdmin(address) external view returns (bool);
function isPoolAdmin(address poolAdmin) external view returns (bool);
function isOperator(address operator) external view returns (bool);
function isTreasurer(address treasurer) external view returns (bool);
function isKeeper(address) external view returns (bool);
function isBlackList(address account) external view returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import '@openzeppelin/contracts/utils/math/Math.sol';
import '@openzeppelin/contracts/utils/Strings.sol';
library Int256Utils {
using Strings for uint256;
function abs(int256 a) internal pure returns (uint256) {
return a >= 0 ? uint256(a) : uint256(-a);
}
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
function safeConvertToInt256(uint256 value) internal pure returns (int256) {
require(value <= uint256(type(int256).max), "Value too large to fit in int256.");
return int256(value);
}
function toString(int256 amount) internal pure returns (string memory) {
return string.concat(amount >= 0 ? '' : '-', abs(amount).toString());
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import '@openzeppelin/contracts/utils/math/Math.sol';
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import '../libraries/PrecisionUtils.sol';
import '../libraries/Int256Utils.sol';
import '../libraries/TradingTypes.sol';
import '../libraries/PositionKey.sol';
import "../interfaces/IPool.sol";
import "../helpers/TokenHelper.sol";
library Position {
using Int256Utils for int256;
using Math for uint256;
using PrecisionUtils for uint256;
struct Info {
address account;
uint256 pairIndex;
bool isLong;
uint256 collateral;
uint256 positionAmount;
uint256 averagePrice;
int256 fundingFeeTracker;
}
function get(
mapping(bytes32 => Info) storage self,
address _account,
uint256 _pairIndex,
bool _isLong
) internal view returns (Position.Info storage position) {
position = self[PositionKey.getPositionKey(_account, _pairIndex, _isLong)];
}
function getPositionByKey(
mapping(bytes32 => Info) storage self,
bytes32 key
) internal view returns (Position.Info storage position) {
position = self[key];
}
function init(Info storage self, uint256 pairIndex, address account, bool isLong, uint256 oraclePrice) internal {
self.pairIndex = pairIndex;
self.account = account;
self.isLong = isLong;
self.averagePrice = oraclePrice;
}
function getUnrealizedPnl(
Info memory self,
IPool.Pair memory pair,
uint256 _sizeAmount,
uint256 price
) internal view returns (int256 pnl) {
if (price == self.averagePrice || self.averagePrice == 0 || _sizeAmount == 0) {
return 0;
}
if (self.isLong) {
if (price > self.averagePrice) {
pnl = TokenHelper.convertIndexAmountToStableWithPrice(
pair,
int256(_sizeAmount),
price - self.averagePrice
);
} else {
pnl = TokenHelper.convertIndexAmountToStableWithPrice(
pair,
-int256(_sizeAmount),
self.averagePrice - price
);
}
} else {
if (self.averagePrice > price) {
pnl = TokenHelper.convertIndexAmountToStableWithPrice(
pair,
int256(_sizeAmount),
self.averagePrice - price
);
} else {
pnl = TokenHelper.convertIndexAmountToStableWithPrice(
pair,
-int256(_sizeAmount),
price - self.averagePrice
);
}
}
return pnl;
}
function validLeverage(
Info memory self,
IPool.Pair memory pair,
uint256 price,
int256 _collateral,
uint256 _sizeAmount,
bool _increase,
uint256 maxLeverage,
uint256 maxPositionAmount,
bool simpleVerify,
int256 fundingFee
) internal view returns (uint256, uint256) {
// only increase collateral
if (_sizeAmount == 0 && _collateral >= 0) {
return (self.positionAmount, self.collateral);
}
uint256 afterPosition;
if (_increase) {
afterPosition = self.positionAmount + _sizeAmount;
} else {
afterPosition = self.positionAmount >= _sizeAmount ? self.positionAmount - _sizeAmount : 0;
}
if (_increase && afterPosition > maxPositionAmount) {
revert("exceeds max position");
}
int256 availableCollateral = int256(self.collateral) + fundingFee;
// pnl
if (!simpleVerify) {
int256 pnl = getUnrealizedPnl(self, pair, self.positionAmount, price);
if (!_increase && _sizeAmount > 0 && _sizeAmount < self.positionAmount) {
if (pnl >= 0) {
availableCollateral += getUnrealizedPnl(self, pair, self.positionAmount - _sizeAmount, price);
} else {
// availableCollateral += getUnrealizedPnl(self, pair, _sizeAmount, price);
availableCollateral += pnl;
}
} else {
availableCollateral += pnl;
}
}
// adjust collateral
if (_collateral != 0) {
availableCollateral += _collateral;
}
require(simpleVerify || availableCollateral >= 0, 'collateral not enough');
if (!simpleVerify && ((_increase && _sizeAmount > 0) || _collateral < 0)) {
uint256 collateralDec = uint256(IERC20Metadata(pair.stableToken).decimals());
uint256 tokenDec = uint256(IERC20Metadata(pair.indexToken).decimals());
uint256 tokenWad = 10 ** (PrecisionUtils.maxTokenDecimals() - tokenDec);
uint256 collateralWad = 10 ** (PrecisionUtils.maxTokenDecimals() - collateralDec);
uint256 afterPositionD = afterPosition * tokenWad;
uint256 availableD = (availableCollateral.abs() * maxLeverage * collateralWad).divPrice(price);
require(afterPositionD <= availableD, 'exceeds max leverage');
}
return (afterPosition, availableCollateral.abs());
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
library PositionKey {
function getPositionKey(address account, uint256 pairIndex, bool isLong) internal pure returns (bytes32) {
require(pairIndex < 2 ** (96 - 32), "ptl");
return bytes32(
uint256(uint160(account)) << 96 | pairIndex << 32 | (isLong ? 1 : 0)
);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import '@openzeppelin/contracts/utils/math/Math.sol';
library PrecisionUtils {
uint256 public constant PERCENTAGE = 1e8;
uint256 public constant PRICE_PRECISION = 1e30;
uint256 public constant MAX_TOKEN_DECIMALS = 18;
function mulPrice(uint256 amount, uint256 price) internal pure returns (uint256) {
return Math.mulDiv(amount, price, PRICE_PRECISION);
}
function divPrice(uint256 delta, uint256 price) internal pure returns (uint256) {
return Math.mulDiv(delta, PRICE_PRECISION, price);
}
function calculatePrice(uint256 delta, uint256 amount) internal pure returns (uint256) {
return Math.mulDiv(delta, PRICE_PRECISION, amount);
}
function mulPercentage(uint256 amount, uint256 _percentage) internal pure returns (uint256) {
return Math.mulDiv(amount, _percentage, PERCENTAGE);
}
function divPercentage(uint256 amount, uint256 _percentage) internal pure returns (uint256) {
return Math.mulDiv(amount, PERCENTAGE, _percentage);
}
function calculatePercentage(uint256 amount0, uint256 amount1) internal pure returns (uint256) {
return Math.mulDiv(amount0, PERCENTAGE, amount1);
}
function percentage() internal pure returns (uint256) {
return PERCENTAGE;
}
function fundingRatePrecision() internal pure returns (uint256) {
return PERCENTAGE;
}
function pricePrecision() internal pure returns (uint256) {
return PRICE_PRECISION;
}
function maxTokenDecimals() internal pure returns (uint256) {
return MAX_TOKEN_DECIMALS;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../interfaces/IAddressesProvider.sol";
import "../interfaces/IRoleManager.sol";
abstract contract Roleable {
IAddressesProvider public immutable ADDRESS_PROVIDER;
constructor(IAddressesProvider _addressProvider) {
ADDRESS_PROVIDER = _addressProvider;
}
modifier onlyAdmin() {
require(IRoleManager(ADDRESS_PROVIDER.roleManager()).isAdmin(msg.sender), "onlyAdmin");
_;
}
modifier onlyPoolAdmin() {
require(
IRoleManager(ADDRESS_PROVIDER.roleManager()).isPoolAdmin(msg.sender),
"onlyPoolAdmin"
);
_;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
library TradingTypes {
enum TradeType {
MARKET,
LIMIT,
TP,
SL
}
enum NetworkFeePaymentType {
ETH,
COLLATERAL
}
struct CreateOrderRequest {
address account;
uint256 pairIndex; // pair index
TradeType tradeType; // 0: MARKET, 1: LIMIT 2: TP 3: SL
int256 collateral; // 1e18 collateral amount,negative number is withdrawal
uint256 openPrice; // 1e30, price
bool isLong; // long or short
int256 sizeAmount; // size
uint256 maxSlippage;
InnerPaymentType paymentType;
uint256 networkFeeAmount;
bytes data;
}
struct OrderWithTpSl {
uint256 tpPrice; // 1e30, tp price
uint128 tp; // tp size
uint256 slPrice; // 1e30, sl price
uint128 sl; // sl size
}
struct IncreasePositionRequest {
address account;
uint256 pairIndex; // pair index
TradeType tradeType; // 0: MARKET, 1: LIMIT 2: TP 3: SL
int256 collateral; // 1e18 collateral amount,negative number is withdrawal
uint256 openPrice; // 1e30, price
bool isLong; // long or short
uint256 sizeAmount; // size
uint256 maxSlippage;
NetworkFeePaymentType paymentType;
uint256 networkFeeAmount;
}
struct IncreasePositionWithTpSlRequest {
address account;
uint256 pairIndex; // pair index
TradeType tradeType; // 0: MARKET, 1: LIMIT 2: TP 3: SL
int256 collateral; // 1e18 collateral amount,negative number is withdrawal
uint256 openPrice; // 1e30, price
bool isLong; // long or short
uint128 sizeAmount; // size
uint256 tpPrice; // 1e30, tp price
uint128 tp; // tp size
uint256 slPrice; // 1e30, sl price
uint128 sl; // sl size
uint256 maxSlippage;
NetworkFeePaymentType paymentType; // 1: eth 2: collateral
uint256 networkFeeAmount;
uint256 tpNetworkFeeAmount;
uint256 slNetworkFeeAmount;
}
struct DecreasePositionRequest {
address account;
uint256 pairIndex;
TradeType tradeType;
int256 collateral; // 1e18 collateral amount,negative number is withdrawal
uint256 triggerPrice; // 1e30, price
uint256 sizeAmount; // size
bool isLong;
uint256 maxSlippage;
NetworkFeePaymentType paymentType;
uint256 networkFeeAmount;
}
struct CreateTpSlRequest {
address account;
uint256 pairIndex; // pair index
bool isLong;
uint256 tpPrice; // Stop profit price 1e30
uint128 tp; // The number of profit stops
uint256 slPrice; // Stop price 1e30
uint128 sl; // Stop loss quantity
NetworkFeePaymentType paymentType;
uint256 tpNetworkFeeAmount;
uint256 slNetworkFeeAmount;
}
struct IncreasePositionOrder {
uint256 orderId;
address account;
uint256 pairIndex; // pair index
TradeType tradeType; // 0: MARKET, 1: LIMIT
int256 collateral; // 1e18 Margin amount
uint256 openPrice; // 1e30 Market acceptable price/Limit opening price
bool isLong; // Long/short
uint256 sizeAmount; // Number of positions
uint256 executedSize;
uint256 maxSlippage;
uint256 blockTime;
}
struct DecreasePositionOrder {
uint256 orderId;
address account;
uint256 pairIndex;
TradeType tradeType;
int256 collateral; // 1e18 Margin amount
uint256 triggerPrice; // Limit trigger price
uint256 sizeAmount; // Number of customs documents
uint256 executedSize;
uint256 maxSlippage;
bool isLong;
bool abovePrice; // Above or below the trigger price
// market:long: true, short: false
// limit:long: false, short: true
// tp:long: false, short: true
// sl:long: true, short: false
uint256 blockTime;
bool needADL;
}
struct OrderNetworkFee {
InnerPaymentType paymentType;
uint256 networkFeeAmount;
}
enum InnerPaymentType {
NONE,
ETH,
COLLATERAL
}
function convertPaymentType(
NetworkFeePaymentType paymentType
) internal pure returns (InnerPaymentType) {
if (paymentType == NetworkFeePaymentType.ETH) {
return InnerPaymentType.ETH;
} else if (paymentType == NetworkFeePaymentType.COLLATERAL) {
return InnerPaymentType.COLLATERAL;
} else {
revert("Invalid payment type");
}
}
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"viaIR": true,
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"metadata": {
"useLiteralContent": true
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"contract IAddressesProvider","name":"addressProvider","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256[]","name":"adlOrderIds","type":"uint256[]"},{"indexed":false,"internalType":"bytes32[]","name":"adlPositionKeys","type":"bytes32[]"},{"indexed":false,"internalType":"uint256[]","name":"orders","type":"uint256[]"}],"name":"ExecuteAdlOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"pairIndex","type":"uint256"},{"indexed":false,"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"indexed":false,"internalType":"bool","name":"isLong","type":"bool"},{"indexed":false,"internalType":"int256","name":"collateral","type":"int256"},{"indexed":false,"internalType":"uint256","name":"orderSize","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"orderPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"executionSize","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"executionPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"executedSize","type":"uint256"},{"indexed":false,"internalType":"bool","name":"needADL","type":"bool"},{"indexed":false,"internalType":"int256","name":"pnl","type":"int256"},{"indexed":false,"internalType":"uint256","name":"tradingFee","type":"uint256"},{"indexed":false,"internalType":"int256","name":"fundingFee","type":"int256"},{"indexed":false,"internalType":"enum TradingTypes.InnerPaymentType","name":"paymentType","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"networkFeeAmount","type":"uint256"}],"name":"ExecuteDecreaseOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"pairIndex","type":"uint256"},{"indexed":false,"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"indexed":false,"internalType":"bool","name":"isLong","type":"bool"},{"indexed":false,"internalType":"int256","name":"collateral","type":"int256"},{"indexed":false,"internalType":"uint256","name":"orderSize","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"orderPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"executionSize","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"executionPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"executedSize","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tradingFee","type":"uint256"},{"indexed":false,"internalType":"int256","name":"fundingFee","type":"int256"},{"indexed":false,"internalType":"enum TradingTypes.InnerPaymentType","name":"paymentType","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"networkFeeAmount","type":"uint256"}],"name":"ExecuteIncreaseOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"},{"indexed":false,"internalType":"string","name":"errorMessage","type":"string"}],"name":"ExecuteOrderError","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"positionKey","type":"bytes32"},{"indexed":false,"internalType":"string","name":"errorMessage","type":"string"}],"name":"ExecutePositionError","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"},{"indexed":false,"internalType":"string","name":"message","type":"string"}],"name":"InvalidOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"oldAddress","type":"address"},{"indexed":false,"internalType":"address","name":"newAddress","type":"address"}],"name":"UpdatePositionManager","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"pairIndex","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isLong","type":"bool"},{"indexed":false,"internalType":"string","name":"message","type":"string"}],"name":"ZeroPosition","type":"event"},{"inputs":[],"name":"ADDRESS_PROVIDER","outputs":[{"internalType":"contract IAddressesProvider","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32[]","name":"positionKeys","type":"bytes32[]"}],"name":"cleanInvalidPositionOrders","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"pairIndex","type":"uint256"},{"internalType":"bool","name":"isLong","type":"bool"},{"internalType":"uint256","name":"executionSize","type":"uint256"},{"internalType":"uint256","name":"executionPrice","type":"uint256"}],"name":"needADL","outputs":[{"internalType":"bool","name":"need","type":"bool"},{"internalType":"uint256","name":"needADLAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"positionManager","outputs":[{"internalType":"contract IPositionManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"setPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"prices","type":"uint256[]"},{"internalType":"bytes[]","name":"updateData","type":"bytes[]"},{"internalType":"uint64[]","name":"publishTimes","type":"uint64[]"},{"internalType":"uint256","name":"pairIndex","type":"uint256"},{"components":[{"internalType":"bytes32","name":"positionKey","type":"bytes32"},{"internalType":"uint256","name":"sizeAmount","type":"uint256"},{"internalType":"uint8","name":"tier","type":"uint8"},{"internalType":"uint256","name":"referralsRatio","type":"uint256"},{"internalType":"uint256","name":"referralUserRatio","type":"uint256"},{"internalType":"address","name":"referralOwner","type":"address"}],"internalType":"struct IExecution.ExecutePosition[]","name":"executePositions","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"bool","name":"isIncrease","type":"bool"},{"internalType":"uint8","name":"tier","type":"uint8"},{"internalType":"uint256","name":"referralsRatio","type":"uint256"},{"internalType":"uint256","name":"referralUserRatio","type":"uint256"},{"internalType":"address","name":"referralOwner","type":"address"}],"internalType":"struct IExecutionLogic.ExecuteOrder[]","name":"executeOrders","type":"tuple[]"}],"name":"setPricesAndExecuteADLOrders","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"prices","type":"uint256[]"},{"internalType":"bytes[]","name":"updateData","type":"bytes[]"},{"internalType":"uint64[]","name":"publishTimes","type":"uint64[]"},{"components":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"bool","name":"isIncrease","type":"bool"},{"internalType":"uint8","name":"tier","type":"uint8"},{"internalType":"uint256","name":"referralsRatio","type":"uint256"},{"internalType":"uint256","name":"referralUserRatio","type":"uint256"},{"internalType":"address","name":"referralOwner","type":"address"}],"internalType":"struct IExecutionLogic.ExecuteOrder[]","name":"decreaseOrders","type":"tuple[]"}],"name":"setPricesAndExecuteDecreaseLimitOrders","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"prices","type":"uint256[]"},{"internalType":"bytes[]","name":"updateData","type":"bytes[]"},{"internalType":"uint64[]","name":"publishTimes","type":"uint64[]"},{"components":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"bool","name":"isIncrease","type":"bool"},{"internalType":"uint8","name":"tier","type":"uint8"},{"internalType":"uint256","name":"referralsRatio","type":"uint256"},{"internalType":"uint256","name":"referralUserRatio","type":"uint256"},{"internalType":"address","name":"referralOwner","type":"address"}],"internalType":"struct IExecutionLogic.ExecuteOrder[]","name":"decreaseOrders","type":"tuple[]"}],"name":"setPricesAndExecuteDecreaseMarketOrders","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"prices","type":"uint256[]"},{"internalType":"bytes[]","name":"updateData","type":"bytes[]"},{"internalType":"uint64[]","name":"publishTimes","type":"uint64[]"},{"components":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"bool","name":"isIncrease","type":"bool"},{"internalType":"uint8","name":"tier","type":"uint8"},{"internalType":"uint256","name":"referralsRatio","type":"uint256"},{"internalType":"uint256","name":"referralUserRatio","type":"uint256"},{"internalType":"address","name":"referralOwner","type":"address"}],"internalType":"struct IExecutionLogic.ExecuteOrder[]","name":"increaseOrders","type":"tuple[]"}],"name":"setPricesAndExecuteIncreaseLimitOrders","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"prices","type":"uint256[]"},{"internalType":"bytes[]","name":"updateData","type":"bytes[]"},{"internalType":"uint64[]","name":"publishTimes","type":"uint64[]"},{"components":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"bool","name":"isIncrease","type":"bool"},{"internalType":"uint8","name":"tier","type":"uint8"},{"internalType":"uint256","name":"referralsRatio","type":"uint256"},{"internalType":"uint256","name":"referralUserRatio","type":"uint256"},{"internalType":"address","name":"referralOwner","type":"address"}],"internalType":"struct IExecutionLogic.ExecuteOrder[]","name":"increaseOrders","type":"tuple[]"}],"name":"setPricesAndExecuteIncreaseMarketOrders","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"prices","type":"uint256[]"},{"internalType":"bytes[]","name":"updateData","type":"bytes[]"},{"internalType":"uint64[]","name":"publishTimes","type":"uint64[]"},{"components":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"enum TradingTypes.TradeType","name":"tradeType","type":"uint8"},{"internalType":"bool","name":"isIncrease","type":"bool"},{"internalType":"uint8","name":"tier","type":"uint8"},{"internalType":"uint256","name":"referralsRatio","type":"uint256"},{"internalType":"uint256","name":"referralUserRatio","type":"uint256"},{"internalType":"address","name":"referralOwner","type":"address"}],"internalType":"struct IExecutionLogic.ExecuteOrder[]","name":"orders","type":"tuple[]"}],"name":"setPricesAndExecuteOrders","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_tokens","type":"address[]"},{"internalType":"uint256[]","name":"_prices","type":"uint256[]"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"bytes","name":"updateData","type":"bytes"},{"internalType":"uint256","name":"updateFee","type":"uint256"},{"internalType":"uint64","name":"backtrackRound","type":"uint64"},{"internalType":"bytes32","name":"positionKey","type":"bytes32"},{"internalType":"uint256","name":"sizeAmount","type":"uint256"},{"internalType":"uint8","name":"tier","type":"uint8"},{"internalType":"uint256","name":"referralsRatio","type":"uint256"},{"internalType":"uint256","name":"referralUserRatio","type":"uint256"},{"internalType":"address","name":"referralOwner","type":"address"}],"internalType":"struct IExecution.LiquidatePosition[]","name":"liquidatePositions","type":"tuple[]"}],"name":"setPricesAndLiquidatePositions","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"setUnPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_positionManager","type":"address"}],"name":"updatePositionManager","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
60a0346100fd57601f612bd138819003918201601f19168301916001600160401b03831184841017610102578084926020946040528339810103126100fd57516001600160a01b03811681036100fd57608052600160005560ff1960015416600155604051612ab89081610119823960805181818160fd015281816103c90152818161046b0152818161051601528181610611015281816106e9015281816107d70152818161089001528181610d1801528181610ee20152818161109801528181611260015281816113e70152818161178e0152818161182401528181611a7301528181611bc001528181611dd101528181611e3c01526128350152f35b600080fd5b634e487b7160e01b600052604160045260246000fdfe6080604052600436101561001257600080fd5b6000803560e01c806316d0c6fe14611e005780631848effa14611dbb5780632a267a7c14611cf5578063349fdb0914611b9057806337a66d8514611a435780633ef7293c1461167d5780635c975abb1461165a5780635f0c9781146113b25780636881d8cb14611222578063791b98bc146111f5578063a8a9a7cc1461105c578063b6cc273a14610ea6578063dee05e3f14610ca3578063f949a3ae146102e95763fdd99e2d146100c257600080fd5b806100cc36612352565b93916100d9939193612443565b6100e1612626565b60405162435da560e01b81526001600160a01b039460209491927f00000000000000000000000000000000000000000000000000000000000000008716928685600481875afa9485156102c157889588918c916102cc575b506024604051809881936335d2155560e11b8352336004840152165afa80156102c15787958b91610274575b5095610191939291610178600498612487565b80518251148061026c575b61018c906124b9565b612810565b60405163c4aa304160e01b815292839182905afa918215610261578592610234575b505016803b156102305760405163bb02ec9b60e01b81523360048201526060602482015291839183918290849082906101f0906064830190612569565b6000604483015203925af180156102255761020e575b506001905580f35b61021790611fc3565b610222578038610206565b80fd5b6040513d84823e3d90fd5b5050fd5b6102539250803d1061025a575b61024b818361200c565b8101906123db565b38806101b3565b503d610241565b6040513d87823e3d90fd5b506001610183565b86819594939792503d83116102ba575b61028e818361200c565b810103126102b65760049587956101786102aa610191966123fa565b92985050919293610165565b8980fd5b503d610284565b6040513d8c823e3d90fd5b6102e39150823d841161025a5761024b818361200c565b38610139565b506060366003190112610222576004356001600160401b03811161092357610315903690600401612058565b906024356001600160401b038111610923576103359036906004016120be565b6001600160401b0360443511610923573660236044350112156109235760443560040135926103638461202d565b93610371604051958661200c565b808552602085013660248360051b60443501011161096957602460443501905b60248360051b60443501018210610b75575050506103ad612443565b6103b5612626565b60405162435da560e01b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610ab0576024916020918691610b58575b506040516335d2155560e11b815233600482015292839182906001600160a01b03165afa8015610ab0578490610b1d575b6104429150612487565b805182511480610b15575b610456906124b9565b604051635434a1df60e01b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610ab0578491610af6575b506001600160a01b031690813b15610a59579183916104d99383604051809681958294631a2b825160e21b8452600484016126b9565b03925af1801561022557908291610ae2575b505b8251811015610ada576105008184612532565b51604051632b47bb3d60e21b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610ab0578491610abb575b5060018060a01b03166001600160401b03606083015116813b15610969578491602483926040519485938492634c77e2e560e01b845260048401525af18015610ab057908491610a9c575b5050604051906105a882611ff1565b600182526020368184013780516001600160a01b03166105c78361250f565b526040516105d481611ff1565b60018152845b60208110610a8b575060208201516105f18261250f565b526105fb8161250f565b50604051632630c12f60e01b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610a80578691610a61575b50604083015160608401516001600160401b031692906001600160a01b0383163b15610a5d57916106af918893604051809681958294633c8d30db60e11b84526060600485015261069d606485018d61267c565b84810360031901602486015290612746565b604483019190915203926001600160a01b03165af1801561026157908591610a45575b505060405163477a86ef60e01b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610261578591610a26575b50608082015160c083015160e0840151610100850151610120860151919460ff90931693926001600160a01b03908116921690823b156102b657928980959360c4938296604051998a97889663063007c560e31b8852336004890152602488015260448701526064860152608485015260a48401525af19182610a12575b5050610a0d5760018460033d116109fd575b6308c379a01461099a575b610927575b604051632630c12f60e01b8152906020826004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa91821561026157859261096d575b50606001516001600160401b03166001600160a01b0382163b156109695791849161085e938360405180968195829463cfb1d08760e01b8452600484015260406024840152604483019061267c565b03926001600160a01b03165af1801561092757908391610955575b5050604051632b47bb3d60e21b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610927578391610936575b506001600160a01b0316803b156109325782809160046040518094819363042ec5cb60e11b83525af180156109275790839161090f575b505061090a906124ea565b6104ed565b61091890611fc3565b6109235781386108ff565b5080fd5b6040513d85823e3d90fd5b8280fd5b61094f915060203d60201161025a5761024b818361200c565b386108c8565b61095e90611fc3565b610923578138610879565b8480fd5b6001600160401b0391925061099260609160203d60201161025a5761024b818361200c565b92915061080f565b6109a26127a2565b806109ae575b506107bc565b90507fedd32c7c9778f5c32416a3b51524d565f0b6bd3bbe26fd7c951dbe3d65cd427f859160808401516109f46040519283928352604060208401526040830190612706565b0390a1386109a8565b50600485803e845160e01c6107b1565b6107c1565b610a1b90611fc3565b61096957843861079f565b610a3f915060203d60201161025a5761024b818361200c565b38610721565b610a4e90611fc3565b610a595783386106d2565b8380fd5b8780fd5b610a7a915060203d60201161025a5761024b818361200c565b38610649565b6040513d88823e3d90fd5b8060606020809385010152016105da565b610aa590611fc3565b610932578238610599565b6040513d86823e3d90fd5b610ad4915060203d60201161025a5761024b818361200c565b3861054e565b506001815580f35b610aeb90611fc3565b6102225780386104eb565b610b0f915060203d60201161025a5761024b818361200c565b386104a3565b50600161044d565b506020813d602011610b50575b81610b376020938361200c565b81010312610a5957610b4b610442916123fa565b610438565b3d9150610b2a565b610b6f9150823d841161025a5761024b818361200c565b38610407565b81356001600160401b038111610c9f576101409081602319826044350136030112610a5d576040519182818101106001600160401b038285011117610c89578201604052610bc96024826044350101612044565b82526001600160401b03604482813501013511610a5d57602492602092610c766101448594610c07368960448481350101358460443501010161211c565b84870152604435810160648101356040860152610c26906084016121f2565b6060850152604435810160a4810135608086015260c481013560a0860152610c509060e40161226c565b60c08501526044350161010481013560e085015261012481013561010085015201612044565b6101208201528152019201919050610391565b634e487b7160e01b600052604160045260246000fd5b8680fd5b50346102225780602080600319360112610ea3576001600160401b03600435818111610e9e5736602382011215610e9e578060040135918211610e9e578160051b91366024848401011161096957610cf9612443565b610d01612626565b60405162435da560e01b81526001600160a01b03907f00000000000000000000000000000000000000000000000000000000000000008216908681600481855afa908115610e7657839188918a91610e81575b506024604051809481936335d2155560e11b8352336004840152165afa8015610e765787918991610e38575b5091610d8d600493612487565b60405163477a86ef60e01b815292839182905afa908115610e2d578791610e10575b501690813b15610e0c5760405163dee05e3f60e01b81526004810195909552602485018190526001600160fb1b031061096957838560448286839760248398018484013781010301925af180156102255761020e57506001905580f35b8580fd5b610e279150863d881161025a5761024b818361200c565b38610daf565b6040513d89823e3d90fd5b82819392503d8311610e6f575b610e4f818361200c565b81010312610a5d57600491610d8d610e6789936123fa565b919350610d80565b503d610e45565b6040513d8a823e3d90fd5b610e989150823d841161025a5761024b818361200c565b38610d54565b505050fd5b50fd5b5080610eb136612352565b9391610ebe939193612443565b610ec6612626565b60405162435da560e01b81526001600160a01b039460209491927f00000000000000000000000000000000000000000000000000000000000000008716928685600481875afa9485156102c157889588918c9161103f575b506024604051809881936335d2155560e11b8352336004840152165afa80156102c15787958b91610ff6575b5095610f5d939291610178600498612487565b60405163c4aa304160e01b815292839182905afa918215610261578592610fd9575b505016803b156102305760405163bb02ec9b60e01b8152336004820152606060248201529183918391829084908290610fbc906064830190612569565b6001604483015203925af180156102255761020e57506001905580f35b610fef9250803d1061025a5761024b818361200c565b3880610f7f565b86819594939792503d8311611038575b611010818361200c565b810103126102b657600495879561017861102c610f5d966123fa565b92985050919293610f4a565b503d611006565b6110569150823d841161025a5761024b818361200c565b38610f1e565b508061106736612352565b9391611074939193612443565b61107c612626565b60405162435da560e01b81526001600160a01b039460209491927f00000000000000000000000000000000000000000000000000000000000000008716928685600481875afa9485156102c157889588918c916111d8575b506024604051809881936335d2155560e11b8352336004840152165afa80156102c15787958b9161118f575b5095611113939291610178600498612487565b60405163c4aa304160e01b815292839182905afa918215610261578592611172575b505016803b1561023057604051632dc0e2db60e11b81523360048201526060602482015291839183918290849082906101f0906064830190612569565b6111889250803d1061025a5761024b818361200c565b3880611135565b86819594939792503d83116111d1575b6111a9818361200c565b810103126102b65760049587956101786111c5611113966123fa565b92985050919293611100565b503d61119f565b6111ef9150823d841161025a5761024b818361200c565b386110d4565b503461022257806003193601126102225760015460405160089190911c6001600160a01b03168152602090f35b503461022257602080600319360112610923576001600160a01b039060043590828216908183036113ad5760405162435da560e01b815281816004817f000000000000000000000000000000000000000000000000000000000000000089165afa908115610a8057859183918891611390575b50602460405180948193637be53ca160e01b8352336004840152165afa908115610a8057869161132b575b50907f888f67ba778372c27e79bbfc2b6a7933c7f94ac44ea6110df376637c513641e4946112f16060959493612407565b60015493610100600160a81b039060081b16610100600160a81b03198516176001556040519333855260081c16908301526040820152a180f35b93929180915084813d8311611389575b611345818361200c565b81010312610e0c577f888f67ba778372c27e79bbfc2b6a7933c7f94ac44ea6110df376637c513641e4946112f161137d6060966123fa565b929394955050946112c0565b503d61133b565b6113a79150823d841161025a5761024b818361200c565b38611295565b600080fd5b506113bc36612352565b93916113c9939193612443565b6113d1612626565b60405162435da560e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081169590946020949293909285856004818b5afa9384156102c15787958b9561163b575b508660405180966335d2155560e11b82523360048301528160249b8c92165afa948515611630578b956115f0575b5061017861146595612487565b855b85518110156115e85761147a8187612532565b5160408101511561155f5760405163c4aa304160e01b815284816004818a5afa80156115545784918a91611537575b501690846114b682612a00565b9101516004811015611524579082918a933b15610a59576114f192849283604051809681958294632dc0e2db60e11b845233600485016125f4565b03925af1801561022557611510575b505061150b906124ea565b611467565b61151990611fc3565b610c9f578638611500565b634e487b7160e01b8a526021600452868afd5b61154e9150863d881161025a5761024b818361200c565b386114a9565b6040513d8b823e3d90fd5b60405163c4aa304160e01b815284816004818a5afa80156115545784918a916115cb575b5016908461159082612a00565b9101516004811015611524579082918a933b15610a59576114f19284928360405180968195829463bb02ec9b60e01b845233600485016125f4565b6115e29150863d881161025a5761024b818361200c565b38611583565b866001815580f35b94508685813d8311611629575b611607818361200c565b810103126116255761017861161e611465966123fa565b9550611458565b8a80fd5b503d6115fd565b6040513d8d823e3d90fd5b611653919550873d891161025a5761024b818361200c565b933861142a565b5034610222578060031936011261022257602060ff600154166040519015158152f35b5060e0366003190112610222576001600160401b0390600435828111610923576116ab903690600401612058565b602435838111610932576116c39036906004016120be565b92604435818111610a59576116dc903690600401612172565b606435828111610969576116f4903690600401612206565b9060a43595838711610e0c5736602388011215610e0c5786600401359361171a8561202d565b97611728604051998a61200c565b8589526020890190602460c0839802820101903682116102b657602401915b8183106119cf5750505060c435908111610c9f5761176990369060040161227a565b94611772612443565b61177a612626565b60405162435da560e01b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610e76576024916020918a916119b2575b506040516335d2155560e11b815233600482015292839182906001600160a01b03165afa908115610e76578891611969575b509061017861180f95949392612487565b60405163c4aa304160e01b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610ab057849161194a575b506001600160a01b031690813b15610a59576040519263174f3f3360e21b84526084840133600486015260843560248601526080968760448701525180915260a485019290865b8181106118f35786850360031901606488015287808881818a8183816118c98e8e612569565b03925af18015610225576118df57506001905580f35b6118e890611fc3565b610222578082610206565b8251805186526020818101518188015260408083015160ff1690880152606080830151908801528a8201518b88015260a0918201516001600160a01b03169187019190915260c090950194909201916001016118a3565b611963915060203d60201161025a5761024b818361200c565b3861185c565b90506020813d6020116119aa575b816119846020938361200c565b81010312610a5d579061017861199f61180f969594936123fa565b9192939495506117fe565b3d9150611977565b6119c99150823d841161025a5761024b818361200c565b386117cc565b60c0833603126102b6576040519060c082019082821086831117610c895760c092602092604052853581528286013583820152611a0e6040870161226c565b6040820152606080870135908201526080808701359082015260a0611a34818801612044565b90820152815201920191611747565b503461022257806003193601126102225760405162435da560e01b81526001600160a01b039060209081816004817f000000000000000000000000000000000000000000000000000000000000000087165afa8015610ab05782918591611b73575b50602460405180958193637be53ca160e01b8352336004840152165afa918215610927578392611b19575b50611afb7f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25892612407565b611b03612443565b600160ff1981541617600155604051338152a180f35b91508082813d8311611b6c575b611b30818361200c565b8101031261093257611afb611b657f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258936123fa565b9250611ad0565b503d611b26565b611b8a9150823d841161025a5761024b818361200c565b38611aa5565b503461022257806003193601126102225760405162435da560e01b81526020906001600160a01b039082816004817f000000000000000000000000000000000000000000000000000000000000000086165afa8015610ab05783918591611cd8575b50602460405180948193637be53ca160e01b8352336004840152165afa8015610927578390611ca2575b611c269150612407565b60015460ff811615611c665760ff19166001556040513381527f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa9190a180f35b60405162461bcd60e51b815260048101839052601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606490fd5b508181813d8311611cd1575b611cb8818361200c565b8101031261093257611ccc611c26916123fa565b611c1c565b503d611cae565b611cef9150823d841161025a5761024b818361200c565b38611bf2565b5034610222576080366003190112610222576024358015158091036113ad57604060018060a01b0360015460081c16916084825180948193630a899e9f60e21b835260043560048401526024830152604435604483015260643560648301525afa80156102255782918391611d77575b60408383825191151582526020820152f35b9150506040813d604011611db3575b81611d936040938361200c565b8101031261092357604091506020611daa826123fa565b91015138611d65565b3d9150611d86565b50346102225780600319360112610222576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b5080611e0b36612352565b9391611e18939193612443565b611e20612626565b60405162435da560e01b81526001600160a01b039460209491927f00000000000000000000000000000000000000000000000000000000000000008716928685600481875afa9485156102c157889588918c91611fa6575b506024604051809881936335d2155560e11b8352336004840152165afa80156102c15787958b91611f5d575b5095611eb7939291610178600498612487565b60405163c4aa304160e01b815292839182905afa918215610261578592611f40575b50501690813b15610230578291611f1491604051948580948193632dc0e2db60e11b8352336004840152606060248401526064830190612569565b6001604483015203925af1801561022557611f3157506001815580f35b611f3a90611fc3565b38610ada565b611f569250803d1061025a5761024b818361200c565b3880611ed9565b86819594939792503d8311611f9f575b611f77818361200c565b810103126102b6576004958795610178611f93611eb7966123fa565b92985050919293611ea4565b503d611f6d565b611fbd9150823d841161025a5761024b818361200c565b38611e78565b6001600160401b038111610c8957604052565b60e081019081106001600160401b03821117610c8957604052565b604081019081106001600160401b03821117610c8957604052565b90601f801991011681019081106001600160401b03821117610c8957604052565b6001600160401b038111610c895760051b60200190565b35906001600160a01b03821682036113ad57565b81601f820112156113ad5780359161206f8361202d565b9261207d604051948561200c565b808452602092838086019260051b8201019283116113ad578301905b8282106120a7575050505090565b8380916120b384612044565b815201910190612099565b81601f820112156113ad578035916120d58361202d565b926120e3604051948561200c565b808452602092838086019260051b8201019283116113ad578301905b82821061210d575050505090565b813581529083019083016120ff565b81601f820112156113ad578035906001600160401b038211610c895760405192612150601f8401601f19166020018561200c565b828452602083830101116113ad57816000926020809301838601378301015290565b9080601f830112156113ad5781359061218a8261202d565b92612198604051948561200c565b828452602092838086019160051b830101928084116113ad57848301915b8483106121c65750505050505090565b82356001600160401b0381116113ad5786916121e78484809489010161211c565b8152019201916121b6565b35906001600160401b03821682036113ad57565b81601f820112156113ad5780359161221d8361202d565b9261222b604051948561200c565b808452602092838086019260051b8201019283116113ad578301905b828210612255575050505090565b838091612261846121f2565b815201910190612247565b359060ff821682036113ad57565b81601f820112156113ad578035906122918261202d565b926040906122a18251958661200c565b838552602091828601918360e0809702860101948186116113ad578401925b8584106122d1575050505050505090565b86848303126113ad578251906122e682611fd6565b843582528585013560048110156113ad5786830152838501359081151582036113ad57828792868b950152606061231e81890161226c565b908201526080808801359082015260a0808801359082015260c0612343818901612044565b908201528152019301926122c0565b60a06003198201126113ad576004906001600160401b0382358181116113ad578261237e918501612058565b936024358281116113ad57836123959186016120be565b936044358381116113ad57846123ac918301612172565b936064358481116113ad57816123c3918401612206565b936084359081116113ad576123d8920161227a565b90565b908160209103126113ad57516001600160a01b03811681036113ad5790565b519081151582036113ad57565b1561240e57565b60405162461bcd60e51b815260206004820152600d60248201526c37b7363ca837b7b620b236b4b760991b6044820152606490fd5b60ff6001541661244f57565b60405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606490fd5b1561248e57565b60405162461bcd60e51b81526020600482015260036024820152626f706b60e81b6044820152606490fd5b156124c057565b60405162461bcd60e51b8152602060048201526002602482015261069760f41b6044820152606490fd5b60001981146124f95760010190565b634e487b7160e01b600052601160045260246000fd5b80511561251c5760200190565b634e487b7160e01b600052603260045260246000fd5b805182101561251c5760209160051b010190565b9060048210156125535752565b634e487b7160e01b600052602160045260246000fd5b90815180825260208080930193019160005b828110612589575050505090565b909192938260e06001928751805182526125a98482015185840190612546565b60408181015115159083015260608082015160ff16908301526080808201519083015260a0808201518184015260c0918201519086901b86900316908201520195019392910161257b565b93929061261c6126249360409260018060a01b03168752606060208801526060870190612569565b940190612546565b565b600260005414612637576002600055565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b90815180825260208080930193019160005b82811061269c575050505090565b83516001600160a01b03168552938101939281019260010161268e565b906126cc9060408352604083019061267c565b81810360209283015282518082529082019282019160005b8281106126f2575050505090565b8351855293810193928101926001016126e4565b919082519283825260005b848110612732575050826000602080949584010152601f8019910116010190565b602081830181015184830182015201612711565b908082519081815260208091019281808460051b8301019501936000915b8483106127745750505050505090565b9091929394958480612792600193601f198682030187528a51612706565b9801930193019194939290612764565b600060443d106123d857604051600319913d83016004833e81516001600160401b03918282113d6024840111176127ff57818401948551938411612807573d850101602084870101116127ff57506123d89291016020019061200c565b949350505050565b50949350505050565b60408051635434a1df60e01b81526000959294919360209392916001600160a01b03917f00000000000000000000000000000000000000000000000000000000000000008316918681600481865afa9081156129f6579084918b916129d9575b5016803b156102b65761289c918a918a838b51809681958294631a2b825160e21b8452600484016126b9565b03925af180156129cf576129b9575b5084600491875192838092632630c12f60e01b82525afa9081156129af578891612992575b501692833b15610c9f5791612906959287949261291987519889966318c68c5b60e21b885260606004890152606488019061267c565b6003199283888303016024890152612746565b90858203016044860152818084519283815201930191865b82811061296f5750505050828091039134905af19081156129665750612955575050565b61295f8291611fc3565b6102225750565b513d84823e3d90fd5b83516001600160401b031685528a97508996509381019392810192600101612931565b6129a99150853d871161025a5761024b818361200c565b386128d0565b86513d8a823e3d90fd5b600491986129c78792611fc3565b9891506128ab565b87513d8b823e3d90fd5b6129f09150883d8a1161025a5761024b818361200c565b38612870565b88513d8c823e3d90fd5b60408051612a0d81611ff1565b6001815260005b602080821015612a6457835160209291612a2d82611fd6565b600082526000818301526000868301526000606083015260006080830152600060a0830152600060c0830152828501015201612a14565b5050612a7f91509291928093612a798261250f565b5261250f565b5056fea2646970667358221220da68bee99af93cc265beddb33f9f7ed76aced294105390ce48cf1c882c9a3a3164736f6c63430008130033000000000000000000000000446dd43816a00d56849f549c032b4814008e183d
Deployed Bytecode
0x6080604052600436101561001257600080fd5b6000803560e01c806316d0c6fe14611e005780631848effa14611dbb5780632a267a7c14611cf5578063349fdb0914611b9057806337a66d8514611a435780633ef7293c1461167d5780635c975abb1461165a5780635f0c9781146113b25780636881d8cb14611222578063791b98bc146111f5578063a8a9a7cc1461105c578063b6cc273a14610ea6578063dee05e3f14610ca3578063f949a3ae146102e95763fdd99e2d146100c257600080fd5b806100cc36612352565b93916100d9939193612443565b6100e1612626565b60405162435da560e01b81526001600160a01b039460209491927f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d8716928685600481875afa9485156102c157889588918c916102cc575b506024604051809881936335d2155560e11b8352336004840152165afa80156102c15787958b91610274575b5095610191939291610178600498612487565b80518251148061026c575b61018c906124b9565b612810565b60405163c4aa304160e01b815292839182905afa918215610261578592610234575b505016803b156102305760405163bb02ec9b60e01b81523360048201526060602482015291839183918290849082906101f0906064830190612569565b6000604483015203925af180156102255761020e575b506001905580f35b61021790611fc3565b610222578038610206565b80fd5b6040513d84823e3d90fd5b5050fd5b6102539250803d1061025a575b61024b818361200c565b8101906123db565b38806101b3565b503d610241565b6040513d87823e3d90fd5b506001610183565b86819594939792503d83116102ba575b61028e818361200c565b810103126102b65760049587956101786102aa610191966123fa565b92985050919293610165565b8980fd5b503d610284565b6040513d8c823e3d90fd5b6102e39150823d841161025a5761024b818361200c565b38610139565b506060366003190112610222576004356001600160401b03811161092357610315903690600401612058565b906024356001600160401b038111610923576103359036906004016120be565b6001600160401b0360443511610923573660236044350112156109235760443560040135926103638461202d565b93610371604051958661200c565b808552602085013660248360051b60443501011161096957602460443501905b60248360051b60443501018210610b75575050506103ad612443565b6103b5612626565b60405162435da560e01b81526020816004817f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d6001600160a01b03165afa908115610ab0576024916020918691610b58575b506040516335d2155560e11b815233600482015292839182906001600160a01b03165afa8015610ab0578490610b1d575b6104429150612487565b805182511480610b15575b610456906124b9565b604051635434a1df60e01b81526020816004817f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d6001600160a01b03165afa908115610ab0578491610af6575b506001600160a01b031690813b15610a59579183916104d99383604051809681958294631a2b825160e21b8452600484016126b9565b03925af1801561022557908291610ae2575b505b8251811015610ada576105008184612532565b51604051632b47bb3d60e21b81526020816004817f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d6001600160a01b03165afa908115610ab0578491610abb575b5060018060a01b03166001600160401b03606083015116813b15610969578491602483926040519485938492634c77e2e560e01b845260048401525af18015610ab057908491610a9c575b5050604051906105a882611ff1565b600182526020368184013780516001600160a01b03166105c78361250f565b526040516105d481611ff1565b60018152845b60208110610a8b575060208201516105f18261250f565b526105fb8161250f565b50604051632630c12f60e01b81526020816004817f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d6001600160a01b03165afa908115610a80578691610a61575b50604083015160608401516001600160401b031692906001600160a01b0383163b15610a5d57916106af918893604051809681958294633c8d30db60e11b84526060600485015261069d606485018d61267c565b84810360031901602486015290612746565b604483019190915203926001600160a01b03165af1801561026157908591610a45575b505060405163477a86ef60e01b81526020816004817f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d6001600160a01b03165afa908115610261578591610a26575b50608082015160c083015160e0840151610100850151610120860151919460ff90931693926001600160a01b03908116921690823b156102b657928980959360c4938296604051998a97889663063007c560e31b8852336004890152602488015260448701526064860152608485015260a48401525af19182610a12575b5050610a0d5760018460033d116109fd575b6308c379a01461099a575b610927575b604051632630c12f60e01b8152906020826004817f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d6001600160a01b03165afa91821561026157859261096d575b50606001516001600160401b03166001600160a01b0382163b156109695791849161085e938360405180968195829463cfb1d08760e01b8452600484015260406024840152604483019061267c565b03926001600160a01b03165af1801561092757908391610955575b5050604051632b47bb3d60e21b81526020816004817f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d6001600160a01b03165afa908115610927578391610936575b506001600160a01b0316803b156109325782809160046040518094819363042ec5cb60e11b83525af180156109275790839161090f575b505061090a906124ea565b6104ed565b61091890611fc3565b6109235781386108ff565b5080fd5b6040513d85823e3d90fd5b8280fd5b61094f915060203d60201161025a5761024b818361200c565b386108c8565b61095e90611fc3565b610923578138610879565b8480fd5b6001600160401b0391925061099260609160203d60201161025a5761024b818361200c565b92915061080f565b6109a26127a2565b806109ae575b506107bc565b90507fedd32c7c9778f5c32416a3b51524d565f0b6bd3bbe26fd7c951dbe3d65cd427f859160808401516109f46040519283928352604060208401526040830190612706565b0390a1386109a8565b50600485803e845160e01c6107b1565b6107c1565b610a1b90611fc3565b61096957843861079f565b610a3f915060203d60201161025a5761024b818361200c565b38610721565b610a4e90611fc3565b610a595783386106d2565b8380fd5b8780fd5b610a7a915060203d60201161025a5761024b818361200c565b38610649565b6040513d88823e3d90fd5b8060606020809385010152016105da565b610aa590611fc3565b610932578238610599565b6040513d86823e3d90fd5b610ad4915060203d60201161025a5761024b818361200c565b3861054e565b506001815580f35b610aeb90611fc3565b6102225780386104eb565b610b0f915060203d60201161025a5761024b818361200c565b386104a3565b50600161044d565b506020813d602011610b50575b81610b376020938361200c565b81010312610a5957610b4b610442916123fa565b610438565b3d9150610b2a565b610b6f9150823d841161025a5761024b818361200c565b38610407565b81356001600160401b038111610c9f576101409081602319826044350136030112610a5d576040519182818101106001600160401b038285011117610c89578201604052610bc96024826044350101612044565b82526001600160401b03604482813501013511610a5d57602492602092610c766101448594610c07368960448481350101358460443501010161211c565b84870152604435810160648101356040860152610c26906084016121f2565b6060850152604435810160a4810135608086015260c481013560a0860152610c509060e40161226c565b60c08501526044350161010481013560e085015261012481013561010085015201612044565b6101208201528152019201919050610391565b634e487b7160e01b600052604160045260246000fd5b8680fd5b50346102225780602080600319360112610ea3576001600160401b03600435818111610e9e5736602382011215610e9e578060040135918211610e9e578160051b91366024848401011161096957610cf9612443565b610d01612626565b60405162435da560e01b81526001600160a01b03907f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d8216908681600481855afa908115610e7657839188918a91610e81575b506024604051809481936335d2155560e11b8352336004840152165afa8015610e765787918991610e38575b5091610d8d600493612487565b60405163477a86ef60e01b815292839182905afa908115610e2d578791610e10575b501690813b15610e0c5760405163dee05e3f60e01b81526004810195909552602485018190526001600160fb1b031061096957838560448286839760248398018484013781010301925af180156102255761020e57506001905580f35b8580fd5b610e279150863d881161025a5761024b818361200c565b38610daf565b6040513d89823e3d90fd5b82819392503d8311610e6f575b610e4f818361200c565b81010312610a5d57600491610d8d610e6789936123fa565b919350610d80565b503d610e45565b6040513d8a823e3d90fd5b610e989150823d841161025a5761024b818361200c565b38610d54565b505050fd5b50fd5b5080610eb136612352565b9391610ebe939193612443565b610ec6612626565b60405162435da560e01b81526001600160a01b039460209491927f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d8716928685600481875afa9485156102c157889588918c9161103f575b506024604051809881936335d2155560e11b8352336004840152165afa80156102c15787958b91610ff6575b5095610f5d939291610178600498612487565b60405163c4aa304160e01b815292839182905afa918215610261578592610fd9575b505016803b156102305760405163bb02ec9b60e01b8152336004820152606060248201529183918391829084908290610fbc906064830190612569565b6001604483015203925af180156102255761020e57506001905580f35b610fef9250803d1061025a5761024b818361200c565b3880610f7f565b86819594939792503d8311611038575b611010818361200c565b810103126102b657600495879561017861102c610f5d966123fa565b92985050919293610f4a565b503d611006565b6110569150823d841161025a5761024b818361200c565b38610f1e565b508061106736612352565b9391611074939193612443565b61107c612626565b60405162435da560e01b81526001600160a01b039460209491927f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d8716928685600481875afa9485156102c157889588918c916111d8575b506024604051809881936335d2155560e11b8352336004840152165afa80156102c15787958b9161118f575b5095611113939291610178600498612487565b60405163c4aa304160e01b815292839182905afa918215610261578592611172575b505016803b1561023057604051632dc0e2db60e11b81523360048201526060602482015291839183918290849082906101f0906064830190612569565b6111889250803d1061025a5761024b818361200c565b3880611135565b86819594939792503d83116111d1575b6111a9818361200c565b810103126102b65760049587956101786111c5611113966123fa565b92985050919293611100565b503d61119f565b6111ef9150823d841161025a5761024b818361200c565b386110d4565b503461022257806003193601126102225760015460405160089190911c6001600160a01b03168152602090f35b503461022257602080600319360112610923576001600160a01b039060043590828216908183036113ad5760405162435da560e01b815281816004817f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d89165afa908115610a8057859183918891611390575b50602460405180948193637be53ca160e01b8352336004840152165afa908115610a8057869161132b575b50907f888f67ba778372c27e79bbfc2b6a7933c7f94ac44ea6110df376637c513641e4946112f16060959493612407565b60015493610100600160a81b039060081b16610100600160a81b03198516176001556040519333855260081c16908301526040820152a180f35b93929180915084813d8311611389575b611345818361200c565b81010312610e0c577f888f67ba778372c27e79bbfc2b6a7933c7f94ac44ea6110df376637c513641e4946112f161137d6060966123fa565b929394955050946112c0565b503d61133b565b6113a79150823d841161025a5761024b818361200c565b38611295565b600080fd5b506113bc36612352565b93916113c9939193612443565b6113d1612626565b60405162435da560e01b81526001600160a01b037f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d81169590946020949293909285856004818b5afa9384156102c15787958b9561163b575b508660405180966335d2155560e11b82523360048301528160249b8c92165afa948515611630578b956115f0575b5061017861146595612487565b855b85518110156115e85761147a8187612532565b5160408101511561155f5760405163c4aa304160e01b815284816004818a5afa80156115545784918a91611537575b501690846114b682612a00565b9101516004811015611524579082918a933b15610a59576114f192849283604051809681958294632dc0e2db60e11b845233600485016125f4565b03925af1801561022557611510575b505061150b906124ea565b611467565b61151990611fc3565b610c9f578638611500565b634e487b7160e01b8a526021600452868afd5b61154e9150863d881161025a5761024b818361200c565b386114a9565b6040513d8b823e3d90fd5b60405163c4aa304160e01b815284816004818a5afa80156115545784918a916115cb575b5016908461159082612a00565b9101516004811015611524579082918a933b15610a59576114f19284928360405180968195829463bb02ec9b60e01b845233600485016125f4565b6115e29150863d881161025a5761024b818361200c565b38611583565b866001815580f35b94508685813d8311611629575b611607818361200c565b810103126116255761017861161e611465966123fa565b9550611458565b8a80fd5b503d6115fd565b6040513d8d823e3d90fd5b611653919550873d891161025a5761024b818361200c565b933861142a565b5034610222578060031936011261022257602060ff600154166040519015158152f35b5060e0366003190112610222576001600160401b0390600435828111610923576116ab903690600401612058565b602435838111610932576116c39036906004016120be565b92604435818111610a59576116dc903690600401612172565b606435828111610969576116f4903690600401612206565b9060a43595838711610e0c5736602388011215610e0c5786600401359361171a8561202d565b97611728604051998a61200c565b8589526020890190602460c0839802820101903682116102b657602401915b8183106119cf5750505060c435908111610c9f5761176990369060040161227a565b94611772612443565b61177a612626565b60405162435da560e01b81526020816004817f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d6001600160a01b03165afa908115610e76576024916020918a916119b2575b506040516335d2155560e11b815233600482015292839182906001600160a01b03165afa908115610e76578891611969575b509061017861180f95949392612487565b60405163c4aa304160e01b81526020816004817f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d6001600160a01b03165afa908115610ab057849161194a575b506001600160a01b031690813b15610a59576040519263174f3f3360e21b84526084840133600486015260843560248601526080968760448701525180915260a485019290865b8181106118f35786850360031901606488015287808881818a8183816118c98e8e612569565b03925af18015610225576118df57506001905580f35b6118e890611fc3565b610222578082610206565b8251805186526020818101518188015260408083015160ff1690880152606080830151908801528a8201518b88015260a0918201516001600160a01b03169187019190915260c090950194909201916001016118a3565b611963915060203d60201161025a5761024b818361200c565b3861185c565b90506020813d6020116119aa575b816119846020938361200c565b81010312610a5d579061017861199f61180f969594936123fa565b9192939495506117fe565b3d9150611977565b6119c99150823d841161025a5761024b818361200c565b386117cc565b60c0833603126102b6576040519060c082019082821086831117610c895760c092602092604052853581528286013583820152611a0e6040870161226c565b6040820152606080870135908201526080808701359082015260a0611a34818801612044565b90820152815201920191611747565b503461022257806003193601126102225760405162435da560e01b81526001600160a01b039060209081816004817f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d87165afa8015610ab05782918591611b73575b50602460405180958193637be53ca160e01b8352336004840152165afa918215610927578392611b19575b50611afb7f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25892612407565b611b03612443565b600160ff1981541617600155604051338152a180f35b91508082813d8311611b6c575b611b30818361200c565b8101031261093257611afb611b657f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258936123fa565b9250611ad0565b503d611b26565b611b8a9150823d841161025a5761024b818361200c565b38611aa5565b503461022257806003193601126102225760405162435da560e01b81526020906001600160a01b039082816004817f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d86165afa8015610ab05783918591611cd8575b50602460405180948193637be53ca160e01b8352336004840152165afa8015610927578390611ca2575b611c269150612407565b60015460ff811615611c665760ff19166001556040513381527f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa9190a180f35b60405162461bcd60e51b815260048101839052601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606490fd5b508181813d8311611cd1575b611cb8818361200c565b8101031261093257611ccc611c26916123fa565b611c1c565b503d611cae565b611cef9150823d841161025a5761024b818361200c565b38611bf2565b5034610222576080366003190112610222576024358015158091036113ad57604060018060a01b0360015460081c16916084825180948193630a899e9f60e21b835260043560048401526024830152604435604483015260643560648301525afa80156102255782918391611d77575b60408383825191151582526020820152f35b9150506040813d604011611db3575b81611d936040938361200c565b8101031261092357604091506020611daa826123fa565b91015138611d65565b3d9150611d86565b50346102225780600319360112610222576040517f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d6001600160a01b03168152602090f35b5080611e0b36612352565b9391611e18939193612443565b611e20612626565b60405162435da560e01b81526001600160a01b039460209491927f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d8716928685600481875afa9485156102c157889588918c91611fa6575b506024604051809881936335d2155560e11b8352336004840152165afa80156102c15787958b91611f5d575b5095611eb7939291610178600498612487565b60405163c4aa304160e01b815292839182905afa918215610261578592611f40575b50501690813b15610230578291611f1491604051948580948193632dc0e2db60e11b8352336004840152606060248401526064830190612569565b6001604483015203925af1801561022557611f3157506001815580f35b611f3a90611fc3565b38610ada565b611f569250803d1061025a5761024b818361200c565b3880611ed9565b86819594939792503d8311611f9f575b611f77818361200c565b810103126102b6576004958795610178611f93611eb7966123fa565b92985050919293611ea4565b503d611f6d565b611fbd9150823d841161025a5761024b818361200c565b38611e78565b6001600160401b038111610c8957604052565b60e081019081106001600160401b03821117610c8957604052565b604081019081106001600160401b03821117610c8957604052565b90601f801991011681019081106001600160401b03821117610c8957604052565b6001600160401b038111610c895760051b60200190565b35906001600160a01b03821682036113ad57565b81601f820112156113ad5780359161206f8361202d565b9261207d604051948561200c565b808452602092838086019260051b8201019283116113ad578301905b8282106120a7575050505090565b8380916120b384612044565b815201910190612099565b81601f820112156113ad578035916120d58361202d565b926120e3604051948561200c565b808452602092838086019260051b8201019283116113ad578301905b82821061210d575050505090565b813581529083019083016120ff565b81601f820112156113ad578035906001600160401b038211610c895760405192612150601f8401601f19166020018561200c565b828452602083830101116113ad57816000926020809301838601378301015290565b9080601f830112156113ad5781359061218a8261202d565b92612198604051948561200c565b828452602092838086019160051b830101928084116113ad57848301915b8483106121c65750505050505090565b82356001600160401b0381116113ad5786916121e78484809489010161211c565b8152019201916121b6565b35906001600160401b03821682036113ad57565b81601f820112156113ad5780359161221d8361202d565b9261222b604051948561200c565b808452602092838086019260051b8201019283116113ad578301905b828210612255575050505090565b838091612261846121f2565b815201910190612247565b359060ff821682036113ad57565b81601f820112156113ad578035906122918261202d565b926040906122a18251958661200c565b838552602091828601918360e0809702860101948186116113ad578401925b8584106122d1575050505050505090565b86848303126113ad578251906122e682611fd6565b843582528585013560048110156113ad5786830152838501359081151582036113ad57828792868b950152606061231e81890161226c565b908201526080808801359082015260a0808801359082015260c0612343818901612044565b908201528152019301926122c0565b60a06003198201126113ad576004906001600160401b0382358181116113ad578261237e918501612058565b936024358281116113ad57836123959186016120be565b936044358381116113ad57846123ac918301612172565b936064358481116113ad57816123c3918401612206565b936084359081116113ad576123d8920161227a565b90565b908160209103126113ad57516001600160a01b03811681036113ad5790565b519081151582036113ad57565b1561240e57565b60405162461bcd60e51b815260206004820152600d60248201526c37b7363ca837b7b620b236b4b760991b6044820152606490fd5b60ff6001541661244f57565b60405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606490fd5b1561248e57565b60405162461bcd60e51b81526020600482015260036024820152626f706b60e81b6044820152606490fd5b156124c057565b60405162461bcd60e51b8152602060048201526002602482015261069760f41b6044820152606490fd5b60001981146124f95760010190565b634e487b7160e01b600052601160045260246000fd5b80511561251c5760200190565b634e487b7160e01b600052603260045260246000fd5b805182101561251c5760209160051b010190565b9060048210156125535752565b634e487b7160e01b600052602160045260246000fd5b90815180825260208080930193019160005b828110612589575050505090565b909192938260e06001928751805182526125a98482015185840190612546565b60408181015115159083015260608082015160ff16908301526080808201519083015260a0808201518184015260c0918201519086901b86900316908201520195019392910161257b565b93929061261c6126249360409260018060a01b03168752606060208801526060870190612569565b940190612546565b565b600260005414612637576002600055565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b90815180825260208080930193019160005b82811061269c575050505090565b83516001600160a01b03168552938101939281019260010161268e565b906126cc9060408352604083019061267c565b81810360209283015282518082529082019282019160005b8281106126f2575050505090565b8351855293810193928101926001016126e4565b919082519283825260005b848110612732575050826000602080949584010152601f8019910116010190565b602081830181015184830182015201612711565b908082519081815260208091019281808460051b8301019501936000915b8483106127745750505050505090565b9091929394958480612792600193601f198682030187528a51612706565b9801930193019194939290612764565b600060443d106123d857604051600319913d83016004833e81516001600160401b03918282113d6024840111176127ff57818401948551938411612807573d850101602084870101116127ff57506123d89291016020019061200c565b949350505050565b50949350505050565b60408051635434a1df60e01b81526000959294919360209392916001600160a01b03917f000000000000000000000000446dd43816a00d56849f549c032b4814008e183d8316918681600481865afa9081156129f6579084918b916129d9575b5016803b156102b65761289c918a918a838b51809681958294631a2b825160e21b8452600484016126b9565b03925af180156129cf576129b9575b5084600491875192838092632630c12f60e01b82525afa9081156129af578891612992575b501692833b15610c9f5791612906959287949261291987519889966318c68c5b60e21b885260606004890152606488019061267c565b6003199283888303016024890152612746565b90858203016044860152818084519283815201930191865b82811061296f5750505050828091039134905af19081156129665750612955575050565b61295f8291611fc3565b6102225750565b513d84823e3d90fd5b83516001600160401b031685528a97508996509381019392810192600101612931565b6129a99150853d871161025a5761024b818361200c565b386128d0565b86513d8a823e3d90fd5b600491986129c78792611fc3565b9891506128ab565b87513d8b823e3d90fd5b6129f09150883d8a1161025a5761024b818361200c565b38612870565b88513d8c823e3d90fd5b60408051612a0d81611ff1565b6001815260005b602080821015612a6457835160209291612a2d82611fd6565b600082526000818301526000868301526000606083015260006080830152600060a0830152600060c0830152828501015201612a14565b5050612a7f91509291928093612a798261250f565b5261250f565b5056fea2646970667358221220da68bee99af93cc265beddb33f9f7ed76aced294105390ce48cf1c882c9a3a3164736f6c63430008130033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000446dd43816a00d56849f549c032b4814008e183d
-----Decoded View---------------
Arg [0] : addressProvider (address): 0x446DD43816A00d56849F549c032b4814008e183d
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000446dd43816a00d56849f549c032b4814008e183d
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ 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.