Polygon Sponsored slots available. Book your slot here!
Overview
POL Balance
0 POL
POL Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 5 from a total of 5 transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
TradingExtension
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 1000000 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.19; import "@openzeppelin/contracts/access/Ownable.sol"; import "./interfaces/IPairsContract.sol"; import "./utils/TradingLibrary.sol"; import "./interfaces/IPosition.sol"; import "./interfaces/ITradingExtension.sol"; contract TradingExtension is ITradingExtension, Ownable { uint256 constant private DIVISION_CONSTANT = 1e10; // 100% address public immutable trading; bool public paused; uint256 public validSignatureTimer; mapping(address => bool) private isNode; mapping(address => uint) public minPositionSize; mapping(address => bool) public allowedMargin; IPairsContract private immutable pairsContract; IPosition private immutable position; event SetAllowedMargin(address _token, bool _isAllowed); event SetNode(address _node, bool _isNode); event SetValidSignatureTimer(uint256 _time); modifier onlyProtocol { require(msg.sender == trading, "!protocol"); _; } constructor( address _trading, address _pairsContract, address _position ) { if ( _trading == address(0) || _pairsContract == address(0) || _position == address(0) ) revert BadConstructor(); trading = _trading; pairsContract = IPairsContract(_pairsContract); position = IPosition(_position); } /** * @notice returns the minimum position size per collateral asset * @param _asset address of the asset */ function minPos( address _asset ) external view returns(uint) { return minPositionSize[_asset]; } /** * @notice limitClose helper * @dev only callable by trading contract * @param _id id of the position NFT * @param _tp true if takeprofit, else stoploss * @param _priceData price data object came from the price oracle * @return _limitPrice price of sl or tp returned from positions contract * @return _tigAsset address of the position collateral asset */ function _limitClose( uint256 _id, bool _tp, PriceData calldata _priceData ) external view returns(uint256 _limitPrice, address _tigAsset) { IPosition.Trade memory _trade = position.trades(_id); _tigAsset = _trade.tigAsset; (uint256 _price,) = getVerifiedPrice(_trade.asset, _priceData, 0); if (_trade.orderType != 0) revert IsLimit(); if (_tp) { if (_trade.tpPrice == 0) revert LimitNotSet(); if (_trade.direction) { if (_trade.tpPrice > _price) revert LimitNotMet(); } else { if (_trade.tpPrice < _price) revert LimitNotMet(); } _limitPrice = _trade.tpPrice; } else { if (_trade.slPrice == 0) revert LimitNotSet(); if (_trade.direction) { if (_trade.slPrice < _price) revert LimitNotMet(); } else { if (_trade.slPrice > _price) revert LimitNotMet(); } _limitPrice = _trade.slPrice; } } /** * @notice verifies the signed price and returns it * @param _asset id of position asset * @param _priceData price data object came from the price oracle * @param _withSpreadIsLong 0, 1, or 2 - to specify if we need the price returned to be after spread * @return _price price after verification and with spread if _withSpreadIsLong is 1 or 2 * @return _spread spread after verification */ function getVerifiedPrice( uint256 _asset, PriceData calldata _priceData, uint8 _withSpreadIsLong ) public view returns(uint256 _price, uint256 _spread) { TradingLibrary.verifyPrice( validSignatureTimer, _asset, _priceData, isNode ); _price = _priceData.price; _spread = _priceData.spread; if(_withSpreadIsLong == 1) _price += _price * _spread / DIVISION_CONSTANT; else if(_withSpreadIsLong == 2) _price -= _price * _spread / DIVISION_CONSTANT; } /** * @dev validates the inputs of trades * @param _assetId asset id * @param _minLeverage minimum leverage * @param _maxLeverage maximum leverage * @param _tigAsset margin asset * @param _margin margin * @param _leverage leverage * @param _orderType market, limit, stop order types */ function validateTrade(uint256 _assetId, uint256 _minLeverage, uint256 _maxLeverage, address _tigAsset, uint256 _margin, uint256 _leverage, uint256 _orderType) external view { if (!allowedMargin[_tigAsset]) revert("Token not whitelisted."); if (paused) revert("Trading paused."); if (!pairsContract.allowedAsset(_assetId)) revert("Market is closed."); if (_leverage < _minLeverage || _leverage > _maxLeverage) revert("Leverage not within range."); if (_margin*_leverage/1e18 < minPositionSize[_tigAsset]) revert("Position size too small."); if (_orderType > 2) revert("Invalid order type."); } /** * @dev Sets the time for which a signature is valid * @param _time time in seconds */ function setValidSignatureTimer( uint256 _time ) external onlyOwner { validSignatureTimer = _time; } /** * @dev whitelists a node * @param _node node address * @param _isNode if address is set as a node */ function setNode(address _node, bool _isNode) external onlyOwner { isNode[_node] = _isNode; } /** * @dev Allows a tigAsset to be used * @param _tigAsset tigAsset * @param _isAllowed if token is allowed to be used as margin */ function setAllowedMargin( address _tigAsset, bool _isAllowed ) external onlyOwner { allowedMargin[_tigAsset] = _isAllowed; } /** * @dev changes the minimum position size * @param _tigAsset tigAsset * @param _min minimum position size 18 decimals */ function setMinPositionSize( address _tigAsset, uint256 _min ) external onlyOwner { minPositionSize[_tigAsset] = _min; } /** * @dev Pauses or unpauses opening new positions * @param _paused If opening new positions is paused */ function setPaused(bool _paused) external onlyOwner { paused = _paused; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// 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.8.0) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.0; import "../Strings.sol"; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS, InvalidSignatureV // Deprecated in v4.8 } function _throwError(RecoverError error) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert("ECDSA: invalid signature"); } else if (error == RecoverError.InvalidSignatureLength) { revert("ECDSA: invalid signature length"); } else if (error == RecoverError.InvalidSignatureS) { revert("ECDSA: invalid signature 's' value"); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature` or error string. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. /// @solidity memory-safe-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else { return (address(0), RecoverError.InvalidSignatureLength); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] * * _Available since v4.3._ */ function tryRecover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address, RecoverError) { bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); uint8 v = uint8((uint256(vs) >> 255) + 27); return tryRecover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. * * _Available since v4.2._ */ function recover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, r, vs); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. * * _Available since v4.3._ */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address, RecoverError) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature); } return (signer, RecoverError.NoError); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, v, r, s); _throwError(error); return recovered; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { // 32 is the length in bytes of hash, // enforced by the type signature above return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); } /** * @dev Returns an Ethereum Signed Message, created from `s`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s)); } /** * @dev Returns an Ethereum Signed Typed Data, created from a * `domainSeparator` and a `structHash`. This produces hash corresponding * to the one signed with the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] * JSON-RPC method as part of EIP-712. * * See {recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv( uint256 x, uint256 y, uint256 denominator, Rounding rounding ) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10**64) { value /= 10**64; result += 64; } if (value >= 10**32) { value /= 10**32; result += 32; } if (value >= 10**16) { value /= 10**16; result += 16; } if (value >= 10**8) { value /= 10**8; result += 8; } if (value >= 10**4) { value /= 10**4; result += 4; } if (value >= 10**2) { value /= 10**2; result += 2; } if (value >= 10**1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/Math.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IPairsContract { struct Asset { string name; address chainlinkFeed; uint256 minLeverage; uint256 maxLeverage; uint256 feeMultiplier; uint256 baseFundingRate; } struct OpenInterest { uint256 longOi; uint256 shortOi; uint256 maxOi; } function allowedAsset(uint) external view returns (bool); function idToAsset(uint256 _asset) external view returns (Asset memory); function idToOi(uint256 _asset, address _tigAsset) external view returns (OpenInterest memory); function setAssetBaseFundingRate(uint256 _asset, uint256 _baseFundingRate) external; function modifyLongOi(uint256 _asset, address _tigAsset, bool _onOpen, uint256 _amount) external; function modifyShortOi(uint256 _asset, address _tigAsset, bool _onOpen, uint256 _amount) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IPosition { struct Trade { uint256 margin; uint256 leverage; uint256 asset; bool direction; uint256 price; uint256 tpPrice; uint256 slPrice; uint256 orderType; address trader; uint256 id; address tigAsset; int accInterest; } struct MintTrade { address account; uint256 margin; uint256 leverage; uint256 asset; bool direction; uint256 price; uint256 tp; uint256 sl; uint256 orderType; address tigAsset; } function trades(uint256) external view returns (Trade memory); function executeLimitOrder(uint256 _id, uint256 _price, uint256 _newMargin) external; function modifyMargin(uint256 _id, uint256 _newMargin, uint256 _newLeverage) external; function addToPosition(uint256 _id, uint256 _newMargin, uint256 _newPrice) external; function reducePosition(uint256 _id, uint256 _newMargin) external; function assetOpenPositions(uint256 _asset) external view returns (uint256[] calldata); function assetOpenPositionsIndexes(uint256 _asset, uint256 _id) external view returns (uint256); function limitOrders(uint256 _asset) external view returns (uint256[] memory); function limitOrderIndexes(uint256 _asset, uint256 _id) external view returns (uint256); function assetOpenPositionsLength(uint256 _asset) external view returns (uint256); function limitOrdersLength(uint256 _asset) external view returns (uint256); function ownerOf(uint256 _id) external view returns (address); function mint(MintTrade memory _mintTrade) external; function burn(uint256 _id) external; function modifyTp(uint256 _id, uint256 _tpPrice) external; function modifySl(uint256 _id, uint256 _slPrice) external; function getCount() external view returns (uint); function updateFunding(uint256 _asset, address _tigAsset, uint256 _longOi, uint256 _shortOi, uint256 _baseFundingRate, uint256 _vaultFundingPercent) external; function setAccInterest(uint256 _id) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/TradingLibrary.sol"; interface ITrading { struct TradeInfo { uint256 margin; address marginAsset; address stableVault; uint256 leverage; uint256 asset; bool direction; uint256 tpPrice; uint256 slPrice; address referrer; } struct ERC20PermitData { uint256 deadline; uint256 amount; uint8 v; bytes32 r; bytes32 s; bool usePermit; } struct Fees { uint256 daoFees; uint256 burnFees; uint256 refDiscount; uint256 botFees; } struct Delay { uint256 delay; // Block timestamp where delay ends bool actionType; // True for open, False for close } error LimitNotSet(); error OnlyEOA(); error NotLiquidatable(); error TradingPaused(); error OldPriceData(); error OrderNotFound(); error TooEarlyToCancel(); error BadDeposit(); error BadWithdraw(); error BadStopLoss(); error IsLimit(); error ValueNotEqualToMargin(); error BadLeverage(); error NotMargin(); error NotAllowedInVault(); error NotVault(); error NotOwner(); error NotAllowedPair(); error WaitDelay(); error NotProxy(); error BelowMinPositionSize(); error BadClosePercent(); error NoPrice(); error LiqThreshold(); error CloseToMaxPnL(); error BadSetter(); error BadConstructor(); error NotLimit(); error LimitNotMet(); error NotEnoughGas(); function marketOpen( TradeInfo calldata _tradeInfo, ERC20PermitData calldata _permitData, address _trader, PriceData calldata _priceData ) external; function marketClose( uint256 _id, uint256 _percent, address _stableVault, address _outputToken, address _trader, PriceData calldata _priceData ) external; function addMargin( uint256 _id, address _stableVault, address _marginAsset, uint256 _addMargin, ERC20PermitData calldata _permitData, address _trader, PriceData calldata _priceData ) external; function removeMargin( uint256 _id, address _stableVault, address _outputToken, uint256 _removeMargin, address _trader, PriceData calldata _priceData ) external; function addToPosition( uint256 _id, address _stableVault, address _marginAsset, uint256 _addMargin, ERC20PermitData calldata _permitData, address _trader, PriceData calldata _priceData ) external; function createLimitOrder( TradeInfo calldata _tradeInfo, uint256 _orderType, // 1 limit, 2 momentum uint256 _price, ERC20PermitData calldata _permitData, address _trader ) external; function cancelLimitOrder( uint256 _id, address _trader ) external; function updateTpSl( bool _type, // true is TP uint256 _id, uint256 _limitPrice, address _trader, PriceData calldata _priceData ) external; function executeLimitOrder( uint256 _id, PriceData calldata _priceData ) external; function liquidatePosition( uint256 _id, PriceData calldata _priceData ) external; function limitClose( uint256 _id, bool _tp, PriceData calldata _priceData ) external; function proxyApprovals(address _account) external view returns(address); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/TradingLibrary.sol"; import "./IPairsContract.sol"; interface ITradingExtension { error LimitNotMet(); error LimitNotSet(); error IsLimit(); error GasTooHigh(); error BadConstructor(); function getVerifiedPrice( uint256 _asset, PriceData calldata _priceData, uint8 _withSpreadIsLong ) external returns(uint256 _price, uint256 _spread); function validateTrade(uint256 _assetId, uint256 _minLeverage, uint256 _maxLeverage, address _tigAsset, uint256 _margin, uint256 _leverage, uint256 _orderType) external view; function minPos(address) external view returns(uint); function paused() external view returns(bool); function _limitClose( uint256 _id, bool _tp, PriceData calldata _priceData ) external returns(uint256 _limitPrice, address _tigAsset); }
//SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import "../interfaces/IPosition.sol"; import "../interfaces/ITrading.sol"; struct PriceData { address provider; bool isClosed; uint256 asset; uint256 price; uint256 spread; uint256 timestamp; bytes signature; } library TradingLibrary { using ECDSA for bytes32; uint256 constant DIVISION_CONSTANT = 1e10; /** * @notice returns position profit or loss * @param _direction true if long * @param _currentPrice current price * @param _price opening price * @param _leverage position leverage * @param _margin collateral amount * @param accInterest funding fees * @return _positionSize position size * @return _payout payout trader should get */ function pnl(bool _direction, uint256 _currentPrice, uint256 _price, uint256 _margin, uint256 _leverage, int256 accInterest) external pure returns (uint256 _positionSize, int256 _payout) { uint256 _initPositionSize = _margin * _leverage / 1e18; if (_direction && _currentPrice >= _price) { _payout = int256(_margin) + int256(_initPositionSize * (1e18 * _currentPrice / _price - 1e18)/1e18) + accInterest; } else if (_direction && _currentPrice < _price) { _payout = int256(_margin) - int256(_initPositionSize * (1e18 - 1e18 * _currentPrice / _price)/1e18) + accInterest; } else if (!_direction && _currentPrice <= _price) { _payout = int256(_margin) + int256(_initPositionSize * (1e18 - 1e18 * _currentPrice / _price)/1e18) + accInterest; } else { _payout = int256(_margin) - int256(_initPositionSize * (1e18 * _currentPrice / _price - 1e18)/1e18) + accInterest; } _positionSize = _direction ? _initPositionSize * _currentPrice / _price : _initPositionSize * _price / _currentPrice; } /** * @notice returns position liquidation price * @param _direction true if long * @param _tradePrice opening price * @param _leverage position leverage * @param _margin collateral amount * @param _accInterest funding fees * @param _liqPercent liquidation percent * @return _liqPrice liquidation price */ function liqPrice(bool _direction, uint256 _tradePrice, uint256 _leverage, uint256 _margin, int256 _accInterest, uint256 _liqPercent) public pure returns (uint256 _liqPrice) { if (_direction) { _liqPrice = uint256(int256(_tradePrice) - int256(_tradePrice) * (int256(_margin) * int256(_liqPercent) / int256(DIVISION_CONSTANT) + _accInterest) * 1e18 / int256(_margin) / int256(_leverage)); } else { _liqPrice = uint256(int256(_tradePrice) + int256(_tradePrice) * (int256(_margin) * int256(_liqPercent) / int256(DIVISION_CONSTANT) + _accInterest) * 1e18 / int256(_margin) / int256(_leverage)); } } /** * @notice uses liqPrice() and returns position liquidation price * @param _positions positions contract address * @param _id position id * @param _liqPercent liquidation percent */ function getLiqPrice(address _positions, uint256 _id, uint256 _liqPercent) external view returns (uint256) { IPosition.Trade memory _trade = IPosition(_positions).trades(_id); return liqPrice(_trade.direction, _trade.price, _trade.leverage, _trade.margin, _trade.accInterest, _liqPercent); } /** * @notice verifies that price is signed by a whitelisted node * @param _validSignatureTimer seconds allowed before price is old * @param _asset position asset * @param _priceData PriceData object * @param _isNode mapping of allowed nodes */ function verifyPrice( uint256 _validSignatureTimer, uint256 _asset, PriceData calldata _priceData, mapping(address => bool) storage _isNode ) external view { require(block.timestamp <= _priceData.timestamp + _validSignatureTimer, "Price has expired."); require(block.timestamp >= _priceData.timestamp, "FutSig"); require(!_priceData.isClosed, "Market is closed."); require(_asset == _priceData.asset, "!Asset"); require(_priceData.price != 0, "NoPrice"); address _provider = ( keccak256(abi.encode( _priceData.provider, _priceData.isClosed, _priceData.asset, _priceData.price, _priceData.spread, _priceData.timestamp )) ).toEthSignedMessageHash().recover(_priceData.signature); require(_provider == _priceData.provider, "BadSig"); require(_isNode[_provider], "!Node"); } }
{ "optimizer": { "enabled": true, "runs": 1000000 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": { "contracts/utils/TradingLibrary.sol": { "TradingLibrary": "0xaf58aef6ece14f8f7ddcb3109638a19b7098ce70" } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_trading","type":"address"},{"internalType":"address","name":"_pairsContract","type":"address"},{"internalType":"address","name":"_position","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"BadConstructor","type":"error"},{"inputs":[],"name":"GasTooHigh","type":"error"},{"inputs":[],"name":"IsLimit","type":"error"},{"inputs":[],"name":"LimitNotMet","type":"error"},{"inputs":[],"name":"LimitNotSet","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"bool","name":"_isAllowed","type":"bool"}],"name":"SetAllowedMargin","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_node","type":"address"},{"indexed":false,"internalType":"bool","name":"_isNode","type":"bool"}],"name":"SetNode","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_time","type":"uint256"}],"name":"SetValidSignatureTimer","type":"event"},{"inputs":[{"internalType":"uint256","name":"_id","type":"uint256"},{"internalType":"bool","name":"_tp","type":"bool"},{"components":[{"internalType":"address","name":"provider","type":"address"},{"internalType":"bool","name":"isClosed","type":"bool"},{"internalType":"uint256","name":"asset","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"uint256","name":"spread","type":"uint256"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct PriceData","name":"_priceData","type":"tuple"}],"name":"_limitClose","outputs":[{"internalType":"uint256","name":"_limitPrice","type":"uint256"},{"internalType":"address","name":"_tigAsset","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"allowedMargin","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_asset","type":"uint256"},{"components":[{"internalType":"address","name":"provider","type":"address"},{"internalType":"bool","name":"isClosed","type":"bool"},{"internalType":"uint256","name":"asset","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"uint256","name":"spread","type":"uint256"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct PriceData","name":"_priceData","type":"tuple"},{"internalType":"uint8","name":"_withSpreadIsLong","type":"uint8"}],"name":"getVerifiedPrice","outputs":[{"internalType":"uint256","name":"_price","type":"uint256"},{"internalType":"uint256","name":"_spread","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"}],"name":"minPos","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"minPositionSize","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_tigAsset","type":"address"},{"internalType":"bool","name":"_isAllowed","type":"bool"}],"name":"setAllowedMargin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_tigAsset","type":"address"},{"internalType":"uint256","name":"_min","type":"uint256"}],"name":"setMinPositionSize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_node","type":"address"},{"internalType":"bool","name":"_isNode","type":"bool"}],"name":"setNode","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_paused","type":"bool"}],"name":"setPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_time","type":"uint256"}],"name":"setValidSignatureTimer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"trading","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"validSignatureTimer","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_assetId","type":"uint256"},{"internalType":"uint256","name":"_minLeverage","type":"uint256"},{"internalType":"uint256","name":"_maxLeverage","type":"uint256"},{"internalType":"address","name":"_tigAsset","type":"address"},{"internalType":"uint256","name":"_margin","type":"uint256"},{"internalType":"uint256","name":"_leverage","type":"uint256"},{"internalType":"uint256","name":"_orderType","type":"uint256"}],"name":"validateTrade","outputs":[],"stateMutability":"view","type":"function"}]
Contract Creation Code
60e06040523480156200001157600080fd5b50604051620014e7380380620014e783398101604081905262000034916200011a565b6200003f33620000ad565b6001600160a01b03831615806200005d57506001600160a01b038216155b806200007057506001600160a01b038116155b156200008f57604051636617fe2f60e01b815260040160405180910390fd5b6001600160a01b0392831660805290821660a0521660c05262000164565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b80516001600160a01b03811681146200011557600080fd5b919050565b6000806000606084860312156200013057600080fd5b6200013b84620000fd565b92506200014b60208501620000fd565b91506200015b60408501620000fd565b90509250925092565b60805160a05160c05161135362000194600039600061051c01526000610a48015260006102fc01526113536000f3fe608060405234801561001057600080fd5b506004361061011b5760003560e01c8063715018a6116100b25780638da5cb5b11610081578063ec44acf211610066578063ec44acf2146102f7578063f2fde38b1461031e578063f61a56bd1461033157600080fd5b80638da5cb5b146102af578063bf5d598d146102ee57600080fd5b8063715018a61461024b578063797b371e1461025357806380a1c4f514610266578063879bafb11461027957600080fd5b80632b355e01116100ee5780632b355e01146101a357806341addb7b146101d65780635c975abb146101e957806361234f1d1461020e57600080fd5b806306c921831461012057806316c38b3c1461014d5780631b6cc2971461016257806325f2f47914610190575b600080fd5b61013361012e366004610dcf565b610344565b604080519283526020830191909152015b60405180910390f35b61016061015b366004610e3e565b610434565b005b610182610170366004610e84565b60036020526000908152604090205481565b604051908152602001610144565b61016061019e366004610ea1565b610486565b6101c66101b1366004610e84565b60046020526000908152604090205460ff1681565b6040519015158152602001610144565b6101606101e4366004610ecd565b6104b7565b6000546101c69074010000000000000000000000000000000000000000900460ff1681565b61022161021c366004610f06565b610515565b6040805192835273ffffffffffffffffffffffffffffffffffffffff909116602083015201610144565b6101606107ca565b610160610261366004610f5f565b6107de565b610160610274366004610ecd565b6107eb565b610182610287366004610e84565b73ffffffffffffffffffffffffffffffffffffffff1660009081526003602052604090205490565b60005473ffffffffffffffffffffffffffffffffffffffff165b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610144565b61018260015481565b6102c97f000000000000000000000000000000000000000000000000000000000000000081565b61016061032c366004610e84565b610849565b61016061033f366004610f78565b610905565b60008073af58aef6ece14f8f7ddcb3109638a19b7098ce70635cf3eb44600154878760026040518563ffffffff1660e01b81526004016103879493929190611088565b60006040518083038186803b15801561039f57600080fd5b505af41580156103b3573d6000803e3d6000fd5b505050606085013592505050608083013560ff83166001036103fa576402540be4006103df8284611167565b6103e99190611184565b6103f390836111bf565b915061042c565b8260ff1660020361042c576402540be4006104158284611167565b61041f9190611184565b61042990836111d2565b91505b935093915050565b61043c610cc1565b6000805491151574010000000000000000000000000000000000000000027fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff909216919091179055565b61048e610cc1565b73ffffffffffffffffffffffffffffffffffffffff909116600090815260036020526040902055565b6104bf610cc1565b73ffffffffffffffffffffffffffffffffffffffff91909116600090815260026020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b60008060007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16631e6c598e876040518263ffffffff1660e01b815260040161057591815260200190565b61018060405180830381865afa158015610593573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105b79190611251565b9050806101400151915060006105d38260400151866000610344565b5090508160e00151600014610614576040517f6a77641400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b85156106ef578160a00151600003610658576040517f1200806d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8160600151156106a557808260a0015111156106a0576040517f74f7ce3600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6106e3565b808260a0015110156106e3576040517f74f7ce3600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8160a0015193506107c0565b8160c0015160000361072d576040517f1200806d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81606001511561077a57808260c001511015610775576040517f74f7ce3600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6107b8565b808260c0015111156107b8576040517f74f7ce3600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8160c0015193505b5050935093915050565b6107d2610cc1565b6107dc6000610d42565b565b6107e6610cc1565b600155565b6107f3610cc1565b73ffffffffffffffffffffffffffffffffffffffff91909116600090815260046020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b610851610cc1565b73ffffffffffffffffffffffffffffffffffffffff81166108f9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f646472657373000000000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b61090281610d42565b50565b73ffffffffffffffffffffffffffffffffffffffff841660009081526004602052604090205460ff16610994576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f546f6b656e206e6f742077686974656c69737465642e0000000000000000000060448201526064016108f0565b60005474010000000000000000000000000000000000000000900460ff1615610a19576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f54726164696e67207061757365642e000000000000000000000000000000000060448201526064016108f0565b6040517fd8a5f72f000000000000000000000000000000000000000000000000000000008152600481018890527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff169063d8a5f72f90602401602060405180830381865afa158015610aa4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ac89190611300565b610b2e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f4d61726b657420697320636c6f7365642e00000000000000000000000000000060448201526064016108f0565b85821080610b3b57508482115b15610ba2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f4c65766572616765206e6f742077697468696e2072616e67652e00000000000060448201526064016108f0565b73ffffffffffffffffffffffffffffffffffffffff8416600090815260036020526040902054670de0b6b3a7640000610bdb8486611167565b610be59190611184565b1015610c4d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f506f736974696f6e2073697a6520746f6f20736d616c6c2e000000000000000060448201526064016108f0565b6002811115610cb8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f496e76616c6964206f7264657220747970652e0000000000000000000000000060448201526064016108f0565b50505050505050565b60005473ffffffffffffffffffffffffffffffffffffffff1633146107dc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016108f0565b6000805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600060e08284031215610dc957600080fd5b50919050565b600080600060608486031215610de457600080fd5b83359250602084013567ffffffffffffffff811115610e0257600080fd5b610e0e86828701610db7565b925050604084013560ff81168114610e2557600080fd5b809150509250925092565b801515811461090257600080fd5b600060208284031215610e5057600080fd5b8135610e5b81610e30565b9392505050565b73ffffffffffffffffffffffffffffffffffffffff8116811461090257600080fd5b600060208284031215610e9657600080fd5b8135610e5b81610e62565b60008060408385031215610eb457600080fd5b8235610ebf81610e62565b946020939093013593505050565b60008060408385031215610ee057600080fd5b8235610eeb81610e62565b91506020830135610efb81610e30565b809150509250929050565b600080600060608486031215610f1b57600080fd5b833592506020840135610f2d81610e30565b9150604084013567ffffffffffffffff811115610f4957600080fd5b610f5586828701610db7565b9150509250925092565b600060208284031215610f7157600080fd5b5035919050565b600080600080600080600060e0888a031215610f9357600080fd5b8735965060208801359550604088013594506060880135610fb381610e62565b9699959850939660808101359560a0820135955060c0909101359350915050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261100957600080fd5b830160208101925035905067ffffffffffffffff81111561102957600080fd5b80360382131561103857600080fd5b9250929050565b8183528181602085013750600060208284010152600060207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b84815283602082015260806040820152600083356110a581610e62565b73ffffffffffffffffffffffffffffffffffffffff16608083015260208401356110ce81610e30565b80151560a084015250604084013560c0830152606084013560e0830152608084013561010083015260a084013561012083015261110e60c0850185610fd4565b60e06101408501526111256101608501828461103f565b9250505082606083015295945050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b808202811582820484141761117e5761117e611138565b92915050565b6000826111ba577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b8082018082111561117e5761117e611138565b8181038181111561117e5761117e611138565b604051610180810167ffffffffffffffff81118282101715611230577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60405290565b805161124181610e30565b919050565b805161124181610e62565b6000610180828403121561126457600080fd5b61126c6111e5565b82518152602083015160208201526040830151604082015261129060608401611236565b60608201526080830151608082015260a083015160a082015260c083015160c082015260e083015160e08201526101006112cb818501611246565b9082015261012083810151908201526101406112e8818501611246565b90820152610160928301519281019290925250919050565b60006020828403121561131257600080fd5b8151610e5b81610e3056fea2646970667358221220b2182f01482ca9746a9487e3c4c93b7fde3879f38a7dd59c8bdca7400899f17764736f6c63430008130033000000000000000000000000a35eabb4be62ed07e88c2af73234fe7dd48a73d4000000000000000000000000dee683a3a201597dc5d3059e8d4694001ce37832000000000000000000000000b60f2011d30b5b901d55a701c58f63ab34b4c23f
Deployed Bytecode
0x608060405234801561001057600080fd5b506004361061011b5760003560e01c8063715018a6116100b25780638da5cb5b11610081578063ec44acf211610066578063ec44acf2146102f7578063f2fde38b1461031e578063f61a56bd1461033157600080fd5b80638da5cb5b146102af578063bf5d598d146102ee57600080fd5b8063715018a61461024b578063797b371e1461025357806380a1c4f514610266578063879bafb11461027957600080fd5b80632b355e01116100ee5780632b355e01146101a357806341addb7b146101d65780635c975abb146101e957806361234f1d1461020e57600080fd5b806306c921831461012057806316c38b3c1461014d5780631b6cc2971461016257806325f2f47914610190575b600080fd5b61013361012e366004610dcf565b610344565b604080519283526020830191909152015b60405180910390f35b61016061015b366004610e3e565b610434565b005b610182610170366004610e84565b60036020526000908152604090205481565b604051908152602001610144565b61016061019e366004610ea1565b610486565b6101c66101b1366004610e84565b60046020526000908152604090205460ff1681565b6040519015158152602001610144565b6101606101e4366004610ecd565b6104b7565b6000546101c69074010000000000000000000000000000000000000000900460ff1681565b61022161021c366004610f06565b610515565b6040805192835273ffffffffffffffffffffffffffffffffffffffff909116602083015201610144565b6101606107ca565b610160610261366004610f5f565b6107de565b610160610274366004610ecd565b6107eb565b610182610287366004610e84565b73ffffffffffffffffffffffffffffffffffffffff1660009081526003602052604090205490565b60005473ffffffffffffffffffffffffffffffffffffffff165b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610144565b61018260015481565b6102c97f000000000000000000000000a35eabb4be62ed07e88c2af73234fe7dd48a73d481565b61016061032c366004610e84565b610849565b61016061033f366004610f78565b610905565b60008073af58aef6ece14f8f7ddcb3109638a19b7098ce70635cf3eb44600154878760026040518563ffffffff1660e01b81526004016103879493929190611088565b60006040518083038186803b15801561039f57600080fd5b505af41580156103b3573d6000803e3d6000fd5b505050606085013592505050608083013560ff83166001036103fa576402540be4006103df8284611167565b6103e99190611184565b6103f390836111bf565b915061042c565b8260ff1660020361042c576402540be4006104158284611167565b61041f9190611184565b61042990836111d2565b91505b935093915050565b61043c610cc1565b6000805491151574010000000000000000000000000000000000000000027fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff909216919091179055565b61048e610cc1565b73ffffffffffffffffffffffffffffffffffffffff909116600090815260036020526040902055565b6104bf610cc1565b73ffffffffffffffffffffffffffffffffffffffff91909116600090815260026020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b60008060007f000000000000000000000000b60f2011d30b5b901d55a701c58f63ab34b4c23f73ffffffffffffffffffffffffffffffffffffffff16631e6c598e876040518263ffffffff1660e01b815260040161057591815260200190565b61018060405180830381865afa158015610593573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105b79190611251565b9050806101400151915060006105d38260400151866000610344565b5090508160e00151600014610614576040517f6a77641400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b85156106ef578160a00151600003610658576040517f1200806d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8160600151156106a557808260a0015111156106a0576040517f74f7ce3600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6106e3565b808260a0015110156106e3576040517f74f7ce3600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8160a0015193506107c0565b8160c0015160000361072d576040517f1200806d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81606001511561077a57808260c001511015610775576040517f74f7ce3600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6107b8565b808260c0015111156107b8576040517f74f7ce3600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8160c0015193505b5050935093915050565b6107d2610cc1565b6107dc6000610d42565b565b6107e6610cc1565b600155565b6107f3610cc1565b73ffffffffffffffffffffffffffffffffffffffff91909116600090815260046020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b610851610cc1565b73ffffffffffffffffffffffffffffffffffffffff81166108f9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f646472657373000000000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b61090281610d42565b50565b73ffffffffffffffffffffffffffffffffffffffff841660009081526004602052604090205460ff16610994576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f546f6b656e206e6f742077686974656c69737465642e0000000000000000000060448201526064016108f0565b60005474010000000000000000000000000000000000000000900460ff1615610a19576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f54726164696e67207061757365642e000000000000000000000000000000000060448201526064016108f0565b6040517fd8a5f72f000000000000000000000000000000000000000000000000000000008152600481018890527f000000000000000000000000dee683a3a201597dc5d3059e8d4694001ce3783273ffffffffffffffffffffffffffffffffffffffff169063d8a5f72f90602401602060405180830381865afa158015610aa4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ac89190611300565b610b2e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f4d61726b657420697320636c6f7365642e00000000000000000000000000000060448201526064016108f0565b85821080610b3b57508482115b15610ba2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f4c65766572616765206e6f742077697468696e2072616e67652e00000000000060448201526064016108f0565b73ffffffffffffffffffffffffffffffffffffffff8416600090815260036020526040902054670de0b6b3a7640000610bdb8486611167565b610be59190611184565b1015610c4d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f506f736974696f6e2073697a6520746f6f20736d616c6c2e000000000000000060448201526064016108f0565b6002811115610cb8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f496e76616c6964206f7264657220747970652e0000000000000000000000000060448201526064016108f0565b50505050505050565b60005473ffffffffffffffffffffffffffffffffffffffff1633146107dc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016108f0565b6000805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600060e08284031215610dc957600080fd5b50919050565b600080600060608486031215610de457600080fd5b83359250602084013567ffffffffffffffff811115610e0257600080fd5b610e0e86828701610db7565b925050604084013560ff81168114610e2557600080fd5b809150509250925092565b801515811461090257600080fd5b600060208284031215610e5057600080fd5b8135610e5b81610e30565b9392505050565b73ffffffffffffffffffffffffffffffffffffffff8116811461090257600080fd5b600060208284031215610e9657600080fd5b8135610e5b81610e62565b60008060408385031215610eb457600080fd5b8235610ebf81610e62565b946020939093013593505050565b60008060408385031215610ee057600080fd5b8235610eeb81610e62565b91506020830135610efb81610e30565b809150509250929050565b600080600060608486031215610f1b57600080fd5b833592506020840135610f2d81610e30565b9150604084013567ffffffffffffffff811115610f4957600080fd5b610f5586828701610db7565b9150509250925092565b600060208284031215610f7157600080fd5b5035919050565b600080600080600080600060e0888a031215610f9357600080fd5b8735965060208801359550604088013594506060880135610fb381610e62565b9699959850939660808101359560a0820135955060c0909101359350915050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261100957600080fd5b830160208101925035905067ffffffffffffffff81111561102957600080fd5b80360382131561103857600080fd5b9250929050565b8183528181602085013750600060208284010152600060207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b84815283602082015260806040820152600083356110a581610e62565b73ffffffffffffffffffffffffffffffffffffffff16608083015260208401356110ce81610e30565b80151560a084015250604084013560c0830152606084013560e0830152608084013561010083015260a084013561012083015261110e60c0850185610fd4565b60e06101408501526111256101608501828461103f565b9250505082606083015295945050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b808202811582820484141761117e5761117e611138565b92915050565b6000826111ba577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b8082018082111561117e5761117e611138565b8181038181111561117e5761117e611138565b604051610180810167ffffffffffffffff81118282101715611230577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60405290565b805161124181610e30565b919050565b805161124181610e62565b6000610180828403121561126457600080fd5b61126c6111e5565b82518152602083015160208201526040830151604082015261129060608401611236565b60608201526080830151608082015260a083015160a082015260c083015160c082015260e083015160e08201526101006112cb818501611246565b9082015261012083810151908201526101406112e8818501611246565b90820152610160928301519281019290925250919050565b60006020828403121561131257600080fd5b8151610e5b81610e3056fea2646970667358221220b2182f01482ca9746a9487e3c4c93b7fde3879f38a7dd59c8bdca7400899f17764736f6c63430008130033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000a35eabb4be62ed07e88c2af73234fe7dd48a73d4000000000000000000000000dee683a3a201597dc5d3059e8d4694001ce37832000000000000000000000000b60f2011d30b5b901d55a701c58f63ab34b4c23f
-----Decoded View---------------
Arg [0] : _trading (address): 0xA35eabB4be62Ed07E88c2aF73234fe7dD48a73D4
Arg [1] : _pairsContract (address): 0xdEe683A3A201597DC5d3059E8d4694001cE37832
Arg [2] : _position (address): 0xb60F2011d30b5b901d55a701C58f63aB34b4C23f
-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 000000000000000000000000a35eabb4be62ed07e88c2af73234fe7dd48a73d4
Arg [1] : 000000000000000000000000dee683a3a201597dc5d3059e8d4694001ce37832
Arg [2] : 000000000000000000000000b60f2011d30b5b901d55a701c58f63ab34b4c23f
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.