Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- ShortsTracker
- Optimization enabled
- true
- Compiler version
- v0.6.12+commit.27d51765
- Optimization runs
- 16
- Verified at
- 2023-07-04T13:08:56.972596Z
Constructor Arguments
0000000000000000000000005d2276c0860f4c6f731f30befa6e06162bc1a7ce
Arg [0] (address) : 0x5d2276c0860f4c6f731f30befa6e06162bc1a7ce
contracts/core/ShortsTracker.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; import "../libraries/math/SafeMath.sol"; import "../access/Governable.sol"; import "./interfaces/IShortsTracker.sol"; import "./interfaces/IVault.sol"; contract ShortsTracker is Governable, IShortsTracker { using SafeMath for uint256; event GlobalShortDataUpdated(address indexed token, uint256 globalShortSize, uint256 globalShortAveragePrice); uint256 public constant MAX_INT256 = uint256(type(int256).max); IVault public vault; mapping (address => bool) public isHandler; mapping (bytes32 => bytes32) public data; mapping (address => uint256) override public globalShortAveragePrices; bool override public isGlobalShortDataReady; modifier onlyHandler() { require(isHandler[msg.sender], "ShortsTracker: forbidden"); _; } constructor(address _vault) public { vault = IVault(_vault); } function setHandler(address _handler, bool _isActive) external onlyGov { require(_handler != address(0), "ShortsTracker: invalid _handler"); isHandler[_handler] = _isActive; } function _setGlobalShortAveragePrice(address _token, uint256 _averagePrice) internal { globalShortAveragePrices[_token] = _averagePrice; } function setIsGlobalShortDataReady(bool value) override external onlyGov { isGlobalShortDataReady = value; } function updateGlobalShortData( address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _sizeDelta, uint256 _markPrice, bool _isIncrease ) override external onlyHandler { if (_isLong || _sizeDelta == 0) { return; } if (!isGlobalShortDataReady) { return; } (uint256 globalShortSize, uint256 globalShortAveragePrice) = getNextGlobalShortData( _account, _collateralToken, _indexToken, _markPrice, _sizeDelta, _isIncrease ); _setGlobalShortAveragePrice(_indexToken, globalShortAveragePrice); emit GlobalShortDataUpdated(_indexToken, globalShortSize, globalShortAveragePrice); } function getGlobalShortDelta(address _token) public view returns (bool, uint256) { uint256 size = vault.globalShortSizes(_token); uint256 averagePrice = globalShortAveragePrices[_token]; if (size == 0) { return (false, 0); } uint256 nextPrice = IVault(vault).getMaxPrice(_token); uint256 priceDelta = averagePrice > nextPrice ? averagePrice.sub(nextPrice) : nextPrice.sub(averagePrice); uint256 delta = size.mul(priceDelta).div(averagePrice); bool hasProfit = averagePrice > nextPrice; return (hasProfit, delta); } function setInitData(address[] calldata _tokens, uint256[] calldata _averagePrices) override external onlyGov { require(!isGlobalShortDataReady, "ShortsTracker: already migrated"); for (uint256 i = 0; i < _tokens.length; i++) { globalShortAveragePrices[_tokens[i]] = _averagePrices[i]; } isGlobalShortDataReady = true; } function getNextGlobalShortData( address _account, address _collateralToken, address _indexToken, uint256 _nextPrice, uint256 _sizeDelta, bool _isIncrease ) override public view returns (uint256, uint256) { int256 realisedPnl = getRealisedPnl(_account,_collateralToken, _indexToken, _sizeDelta, _isIncrease); uint256 averagePrice = globalShortAveragePrices[_indexToken]; uint256 priceDelta = averagePrice > _nextPrice ? averagePrice.sub(_nextPrice) : _nextPrice.sub(averagePrice); uint256 nextSize; uint256 delta; // avoid stack to deep { uint256 size = vault.globalShortSizes(_indexToken); nextSize = _isIncrease ? size.add(_sizeDelta) : size.sub(_sizeDelta); if (nextSize == 0) { return (0, 0); } if (averagePrice == 0) { return (nextSize, _nextPrice); } delta = size.mul(priceDelta).div(averagePrice); } uint256 nextAveragePrice = _getNextGlobalAveragePrice( averagePrice, _nextPrice, nextSize, delta, realisedPnl ); return (nextSize, nextAveragePrice); } function getRealisedPnl( address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isIncrease ) public view returns (int256) { if (_isIncrease) { return 0; } IVault _vault = vault; (uint256 size, /*uint256 collateral*/, uint256 averagePrice, , , , , uint256 lastIncreasedTime) = _vault.getPosition(_account, _collateralToken, _indexToken, false); (bool hasProfit, uint256 delta) = _vault.getDelta(_indexToken, size, averagePrice, false, lastIncreasedTime); // get the proportional change in pnl uint256 adjustedDelta = _sizeDelta.mul(delta).div(size); require(adjustedDelta < MAX_INT256, "ShortsTracker: overflow"); return hasProfit ? int256(adjustedDelta) : -int256(adjustedDelta); } function _getNextGlobalAveragePrice( uint256 _averagePrice, uint256 _nextPrice, uint256 _nextSize, uint256 _delta, int256 _realisedPnl ) public pure returns (uint256) { (bool hasProfit, uint256 nextDelta) = _getNextDelta(_delta, _averagePrice, _nextPrice, _realisedPnl); uint256 nextAveragePrice = _nextPrice .mul(_nextSize) .div(hasProfit ? _nextSize.sub(nextDelta) : _nextSize.add(nextDelta)); return nextAveragePrice; } function _getNextDelta( uint256 _delta, uint256 _averagePrice, uint256 _nextPrice, int256 _realisedPnl ) internal pure returns (bool, uint256) { // global delta 10000, realised pnl 1000 => new pnl 9000 // global delta 10000, realised pnl -1000 => new pnl 11000 // global delta -10000, realised pnl 1000 => new pnl -11000 // global delta -10000, realised pnl -1000 => new pnl -9000 // global delta 10000, realised pnl 11000 => new pnl -1000 (flips sign) // global delta -10000, realised pnl -11000 => new pnl 1000 (flips sign) bool hasProfit = _averagePrice > _nextPrice; if (hasProfit) { // global shorts pnl is positive if (_realisedPnl > 0) { if (uint256(_realisedPnl) > _delta) { _delta = uint256(_realisedPnl).sub(_delta); hasProfit = false; } else { _delta = _delta.sub(uint256(_realisedPnl)); } } else { _delta = _delta.add(uint256(-_realisedPnl)); } return (hasProfit, _delta); } if (_realisedPnl > 0) { _delta = _delta.add(uint256(_realisedPnl)); } else { if (uint256(-_realisedPnl) > _delta) { _delta = uint256(-_realisedPnl).sub(_delta); hasProfit = true; } else { _delta = _delta.sub(uint256(-_realisedPnl)); } } return (hasProfit, _delta); } }
contracts/access/Governable.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.6.12; contract Governable { address public gov; constructor() public { gov = msg.sender; } modifier onlyGov() { require(msg.sender == gov, "Governable: forbidden"); _; } function setGov(address _gov) external onlyGov { gov = _gov; } }
contracts/core/interfaces/IShortsTracker.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; interface IShortsTracker { function isGlobalShortDataReady() external view returns (bool); function globalShortAveragePrices(address _token) external view returns (uint256); function getNextGlobalShortData( address _account, address _collateralToken, address _indexToken, uint256 _nextPrice, uint256 _sizeDelta, bool _isIncrease ) external view returns (uint256, uint256); function updateGlobalShortData( address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _sizeDelta, uint256 _markPrice, bool _isIncrease ) external; function setIsGlobalShortDataReady(bool value) external; function setInitData(address[] calldata _tokens, uint256[] calldata _averagePrices) external; }
contracts/core/interfaces/IVault.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; import "./IVaultUtils.sol"; interface IVault { function isInitialized() external view returns (bool); function isSwapEnabled() external view returns (bool); function isLeverageEnabled() external view returns (bool); function setVaultUtils(IVaultUtils _vaultUtils) external; function setError(uint256 _errorCode, string calldata _error) external; function router() external view returns (address); function usdk() external view returns (address); function gov() external view returns (address); function whitelistedTokenCount() external view returns (uint256); function maxLeverage() external view returns (uint256); function minProfitTime() external view returns (uint256); function hasDynamicFees() external view returns (bool); function fundingInterval() external view returns (uint256); function totalTokenWeights() external view returns (uint256); function getTargetUsdkAmount(address _token) external view returns (uint256); function inManagerMode() external view returns (bool); function inPrivateLiquidationMode() external view returns (bool); function maxGasPrice() external view returns (uint256); function approvedRouters(address _account, address _router) external view returns (bool); function isLiquidator(address _account) external view returns (bool); function isManager(address _account) external view returns (bool); function minProfitBasisPoints(address _token) external view returns (uint256); function tokenBalances(address _token) external view returns (uint256); function lastFundingTimes(address _token) external view returns (uint256); function setMaxLeverage(uint256 _maxLeverage) external; function setInManagerMode(bool _inManagerMode) external; function setManager(address _manager, bool _isManager) external; function setIsSwapEnabled(bool _isSwapEnabled) external; function setIsLeverageEnabled(bool _isLeverageEnabled) external; function setMaxGasPrice(uint256 _maxGasPrice) external; function setUsdkAmount(address _token, uint256 _amount) external; function setBufferAmount(address _token, uint256 _amount) external; function setMaxGlobalShortSize(address _token, uint256 _amount) external; function setInPrivateLiquidationMode(bool _inPrivateLiquidationMode) external; function setLiquidator(address _liquidator, bool _isActive) external; function setFundingRate(uint256 _fundingInterval, uint256 _fundingRateFactor, uint256 _stableFundingRateFactor) external; function setFees( uint256 _taxBasisPoints, uint256 _stableTaxBasisPoints, uint256 _mintBurnFeeBasisPoints, uint256 _swapFeeBasisPoints, uint256 _stableSwapFeeBasisPoints, uint256 _marginFeeBasisPoints, uint256 _liquidationFeeUsd, uint256 _minProfitTime, bool _hasDynamicFees ) external; function setTokenConfig( address _token, uint256 _tokenDecimals, uint256 _redemptionBps, uint256 _minProfitBps, uint256 _maxUsdkAmount, bool _isStable, bool _isShortable ) external; function setPriceFeed(address _priceFeed) external; function withdrawFees(address _token, address _receiver) external returns (uint256); function directPoolDeposit(address _token) external; function buyUSDK(address _token, address _receiver) external returns (uint256); function sellUSDK(address _token, address _receiver) external returns (uint256); function swap(address _tokenIn, address _tokenOut, address _receiver) external returns (uint256); function increasePosition(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong) external; function decreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _collateralDelta, uint256 _sizeDelta, bool _isLong, address _receiver) external returns (uint256); function validateLiquidation(address _account, address _collateralToken, address _indexToken, bool _isLong, bool _raise) external view returns (uint256, uint256); function liquidatePosition(address _account, address _collateralToken, address _indexToken, bool _isLong, address _feeReceiver) external; function tokenToUsdMin(address _token, uint256 _tokenAmount) external view returns (uint256); function priceFeed() external view returns (address); function fundingRateFactor() external view returns (uint256); function stableFundingRateFactor() external view returns (uint256); function cumulativeFundingRates(address _token) external view returns (uint256); function getNextFundingRate(address _token) external view returns (uint256); function getFeeBasisPoints(address _token, uint256 _usdkDelta, uint256 _feeBasisPoints, uint256 _taxBasisPoints, bool _increment) external view returns (uint256); function liquidationFeeUsd() external view returns (uint256); function taxBasisPoints() external view returns (uint256); function stableTaxBasisPoints() external view returns (uint256); function mintBurnFeeBasisPoints() external view returns (uint256); function swapFeeBasisPoints() external view returns (uint256); function stableSwapFeeBasisPoints() external view returns (uint256); function marginFeeBasisPoints() external view returns (uint256); function allWhitelistedTokensLength() external view returns (uint256); function allWhitelistedTokens(uint256) external view returns (address); function whitelistedTokens(address _token) external view returns (bool); function stableTokens(address _token) external view returns (bool); function shortableTokens(address _token) external view returns (bool); function feeReserves(address _token) external view returns (uint256); function globalShortSizes(address _token) external view returns (uint256); function globalShortAveragePrices(address _token) external view returns (uint256); function maxGlobalShortSizes(address _token) external view returns (uint256); function tokenDecimals(address _token) external view returns (uint256); function tokenWeights(address _token) external view returns (uint256); function guaranteedUsd(address _token) external view returns (uint256); function poolAmounts(address _token) external view returns (uint256); function bufferAmounts(address _token) external view returns (uint256); function reservedAmounts(address _token) external view returns (uint256); function usdkAmounts(address _token) external view returns (uint256); function maxUsdkAmounts(address _token) external view returns (uint256); function getRedemptionAmount(address _token, uint256 _usdkAmount) external view returns (uint256); function getMaxPrice(address _token) external view returns (uint256); function getMinPrice(address _token) external view returns (uint256); function getDelta(address _indexToken, uint256 _size, uint256 _averagePrice, bool _isLong, uint256 _lastIncreasedTime) external view returns (bool, uint256); function getPosition(address _account, address _collateralToken, address _indexToken, bool _isLong) external view returns (uint256, uint256, uint256, uint256, uint256, uint256, bool, uint256); }
contracts/core/interfaces/IVaultUtils.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; interface IVaultUtils { function updateCumulativeFundingRate(address _collateralToken, address _indexToken) external returns (bool); function validateIncreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong) external view; function validateDecreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _collateralDelta, uint256 _sizeDelta, bool _isLong, address _receiver) external view; function validateLiquidation(address _account, address _collateralToken, address _indexToken, bool _isLong, bool _raise) external view returns (uint256, uint256); function getEntryFundingRate(address _collateralToken, address _indexToken, bool _isLong) external view returns (uint256); function getPositionFee(address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _sizeDelta) external view returns (uint256); function getFundingFee(address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _size, uint256 _entryFundingRate) external view returns (uint256); function getBuyUsdkFeeBasisPoints(address _token, uint256 _usdkAmount) external view returns (uint256); function getSellUsdkFeeBasisPoints(address _token, uint256 _usdkAmount) external view returns (uint256); function getSwapFeeBasisPoints(address _tokenIn, address _tokenOut, uint256 _usdkAmount) external view returns (uint256); function getFeeBasisPoints(address _token, uint256 _usdkDelta, uint256 _feeBasisPoints, uint256 _taxBasisPoints, bool _increment) external view returns (uint256); }
contracts/libraries/math/SafeMath.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
contracts/access/Governable.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.6.12; contract Governable { address public gov; constructor() public { gov = msg.sender; } modifier onlyGov() { require(msg.sender == gov, "Governable: forbidden"); _; } function setGov(address _gov) external onlyGov { gov = _gov; } }
contracts/core/interfaces/IShortsTracker.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; interface IShortsTracker { function isGlobalShortDataReady() external view returns (bool); function globalShortAveragePrices(address _token) external view returns (uint256); function getNextGlobalShortData( address _account, address _collateralToken, address _indexToken, uint256 _nextPrice, uint256 _sizeDelta, bool _isIncrease ) external view returns (uint256, uint256); function updateGlobalShortData( address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _sizeDelta, uint256 _markPrice, bool _isIncrease ) external; function setIsGlobalShortDataReady(bool value) external; function setInitData(address[] calldata _tokens, uint256[] calldata _averagePrices) external; }
contracts/core/interfaces/IVault.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; import "./IVaultUtils.sol"; interface IVault { function isInitialized() external view returns (bool); function isSwapEnabled() external view returns (bool); function isLeverageEnabled() external view returns (bool); function setVaultUtils(IVaultUtils _vaultUtils) external; function setError(uint256 _errorCode, string calldata _error) external; function router() external view returns (address); function usdk() external view returns (address); function gov() external view returns (address); function whitelistedTokenCount() external view returns (uint256); function maxLeverage() external view returns (uint256); function minProfitTime() external view returns (uint256); function hasDynamicFees() external view returns (bool); function fundingInterval() external view returns (uint256); function totalTokenWeights() external view returns (uint256); function getTargetUsdkAmount(address _token) external view returns (uint256); function inManagerMode() external view returns (bool); function inPrivateLiquidationMode() external view returns (bool); function maxGasPrice() external view returns (uint256); function approvedRouters(address _account, address _router) external view returns (bool); function isLiquidator(address _account) external view returns (bool); function isManager(address _account) external view returns (bool); function minProfitBasisPoints(address _token) external view returns (uint256); function tokenBalances(address _token) external view returns (uint256); function lastFundingTimes(address _token) external view returns (uint256); function setMaxLeverage(uint256 _maxLeverage) external; function setInManagerMode(bool _inManagerMode) external; function setManager(address _manager, bool _isManager) external; function setIsSwapEnabled(bool _isSwapEnabled) external; function setIsLeverageEnabled(bool _isLeverageEnabled) external; function setMaxGasPrice(uint256 _maxGasPrice) external; function setUsdkAmount(address _token, uint256 _amount) external; function setBufferAmount(address _token, uint256 _amount) external; function setMaxGlobalShortSize(address _token, uint256 _amount) external; function setInPrivateLiquidationMode(bool _inPrivateLiquidationMode) external; function setLiquidator(address _liquidator, bool _isActive) external; function setFundingRate(uint256 _fundingInterval, uint256 _fundingRateFactor, uint256 _stableFundingRateFactor) external; function setFees( uint256 _taxBasisPoints, uint256 _stableTaxBasisPoints, uint256 _mintBurnFeeBasisPoints, uint256 _swapFeeBasisPoints, uint256 _stableSwapFeeBasisPoints, uint256 _marginFeeBasisPoints, uint256 _liquidationFeeUsd, uint256 _minProfitTime, bool _hasDynamicFees ) external; function setTokenConfig( address _token, uint256 _tokenDecimals, uint256 _redemptionBps, uint256 _minProfitBps, uint256 _maxUsdkAmount, bool _isStable, bool _isShortable ) external; function setPriceFeed(address _priceFeed) external; function withdrawFees(address _token, address _receiver) external returns (uint256); function directPoolDeposit(address _token) external; function buyUSDK(address _token, address _receiver) external returns (uint256); function sellUSDK(address _token, address _receiver) external returns (uint256); function swap(address _tokenIn, address _tokenOut, address _receiver) external returns (uint256); function increasePosition(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong) external; function decreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _collateralDelta, uint256 _sizeDelta, bool _isLong, address _receiver) external returns (uint256); function validateLiquidation(address _account, address _collateralToken, address _indexToken, bool _isLong, bool _raise) external view returns (uint256, uint256); function liquidatePosition(address _account, address _collateralToken, address _indexToken, bool _isLong, address _feeReceiver) external; function tokenToUsdMin(address _token, uint256 _tokenAmount) external view returns (uint256); function priceFeed() external view returns (address); function fundingRateFactor() external view returns (uint256); function stableFundingRateFactor() external view returns (uint256); function cumulativeFundingRates(address _token) external view returns (uint256); function getNextFundingRate(address _token) external view returns (uint256); function getFeeBasisPoints(address _token, uint256 _usdkDelta, uint256 _feeBasisPoints, uint256 _taxBasisPoints, bool _increment) external view returns (uint256); function liquidationFeeUsd() external view returns (uint256); function taxBasisPoints() external view returns (uint256); function stableTaxBasisPoints() external view returns (uint256); function mintBurnFeeBasisPoints() external view returns (uint256); function swapFeeBasisPoints() external view returns (uint256); function stableSwapFeeBasisPoints() external view returns (uint256); function marginFeeBasisPoints() external view returns (uint256); function allWhitelistedTokensLength() external view returns (uint256); function allWhitelistedTokens(uint256) external view returns (address); function whitelistedTokens(address _token) external view returns (bool); function stableTokens(address _token) external view returns (bool); function shortableTokens(address _token) external view returns (bool); function feeReserves(address _token) external view returns (uint256); function globalShortSizes(address _token) external view returns (uint256); function globalShortAveragePrices(address _token) external view returns (uint256); function maxGlobalShortSizes(address _token) external view returns (uint256); function tokenDecimals(address _token) external view returns (uint256); function tokenWeights(address _token) external view returns (uint256); function guaranteedUsd(address _token) external view returns (uint256); function poolAmounts(address _token) external view returns (uint256); function bufferAmounts(address _token) external view returns (uint256); function reservedAmounts(address _token) external view returns (uint256); function usdkAmounts(address _token) external view returns (uint256); function maxUsdkAmounts(address _token) external view returns (uint256); function getRedemptionAmount(address _token, uint256 _usdkAmount) external view returns (uint256); function getMaxPrice(address _token) external view returns (uint256); function getMinPrice(address _token) external view returns (uint256); function getDelta(address _indexToken, uint256 _size, uint256 _averagePrice, bool _isLong, uint256 _lastIncreasedTime) external view returns (bool, uint256); function getPosition(address _account, address _collateralToken, address _indexToken, bool _isLong) external view returns (uint256, uint256, uint256, uint256, uint256, uint256, bool, uint256); }
contracts/core/interfaces/IVaultUtils.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; interface IVaultUtils { function updateCumulativeFundingRate(address _collateralToken, address _indexToken) external returns (bool); function validateIncreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong) external view; function validateDecreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _collateralDelta, uint256 _sizeDelta, bool _isLong, address _receiver) external view; function validateLiquidation(address _account, address _collateralToken, address _indexToken, bool _isLong, bool _raise) external view returns (uint256, uint256); function getEntryFundingRate(address _collateralToken, address _indexToken, bool _isLong) external view returns (uint256); function getPositionFee(address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _sizeDelta) external view returns (uint256); function getFundingFee(address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _size, uint256 _entryFundingRate) external view returns (uint256); function getBuyUsdkFeeBasisPoints(address _token, uint256 _usdkAmount) external view returns (uint256); function getSellUsdkFeeBasisPoints(address _token, uint256 _usdkAmount) external view returns (uint256); function getSwapFeeBasisPoints(address _tokenIn, address _tokenOut, uint256 _usdkAmount) external view returns (uint256); function getFeeBasisPoints(address _token, uint256 _usdkDelta, uint256 _feeBasisPoints, uint256 _taxBasisPoints, bool _increment) external view returns (uint256); }
contracts/libraries/math/SafeMath.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
contracts/access/Governable.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.6.12; contract Governable { address public gov; constructor() public { gov = msg.sender; } modifier onlyGov() { require(msg.sender == gov, "Governable: forbidden"); _; } function setGov(address _gov) external onlyGov { gov = _gov; } }
contracts/core/interfaces/IShortsTracker.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; interface IShortsTracker { function isGlobalShortDataReady() external view returns (bool); function globalShortAveragePrices(address _token) external view returns (uint256); function getNextGlobalShortData( address _account, address _collateralToken, address _indexToken, uint256 _nextPrice, uint256 _sizeDelta, bool _isIncrease ) external view returns (uint256, uint256); function updateGlobalShortData( address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _sizeDelta, uint256 _markPrice, bool _isIncrease ) external; function setIsGlobalShortDataReady(bool value) external; function setInitData(address[] calldata _tokens, uint256[] calldata _averagePrices) external; }
contracts/core/interfaces/IVault.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; import "./IVaultUtils.sol"; interface IVault { function isInitialized() external view returns (bool); function isSwapEnabled() external view returns (bool); function isLeverageEnabled() external view returns (bool); function setVaultUtils(IVaultUtils _vaultUtils) external; function setError(uint256 _errorCode, string calldata _error) external; function router() external view returns (address); function usdk() external view returns (address); function gov() external view returns (address); function whitelistedTokenCount() external view returns (uint256); function maxLeverage() external view returns (uint256); function minProfitTime() external view returns (uint256); function hasDynamicFees() external view returns (bool); function fundingInterval() external view returns (uint256); function totalTokenWeights() external view returns (uint256); function getTargetUsdkAmount(address _token) external view returns (uint256); function inManagerMode() external view returns (bool); function inPrivateLiquidationMode() external view returns (bool); function maxGasPrice() external view returns (uint256); function approvedRouters(address _account, address _router) external view returns (bool); function isLiquidator(address _account) external view returns (bool); function isManager(address _account) external view returns (bool); function minProfitBasisPoints(address _token) external view returns (uint256); function tokenBalances(address _token) external view returns (uint256); function lastFundingTimes(address _token) external view returns (uint256); function setMaxLeverage(uint256 _maxLeverage) external; function setInManagerMode(bool _inManagerMode) external; function setManager(address _manager, bool _isManager) external; function setIsSwapEnabled(bool _isSwapEnabled) external; function setIsLeverageEnabled(bool _isLeverageEnabled) external; function setMaxGasPrice(uint256 _maxGasPrice) external; function setUsdkAmount(address _token, uint256 _amount) external; function setBufferAmount(address _token, uint256 _amount) external; function setMaxGlobalShortSize(address _token, uint256 _amount) external; function setInPrivateLiquidationMode(bool _inPrivateLiquidationMode) external; function setLiquidator(address _liquidator, bool _isActive) external; function setFundingRate(uint256 _fundingInterval, uint256 _fundingRateFactor, uint256 _stableFundingRateFactor) external; function setFees( uint256 _taxBasisPoints, uint256 _stableTaxBasisPoints, uint256 _mintBurnFeeBasisPoints, uint256 _swapFeeBasisPoints, uint256 _stableSwapFeeBasisPoints, uint256 _marginFeeBasisPoints, uint256 _liquidationFeeUsd, uint256 _minProfitTime, bool _hasDynamicFees ) external; function setTokenConfig( address _token, uint256 _tokenDecimals, uint256 _redemptionBps, uint256 _minProfitBps, uint256 _maxUsdkAmount, bool _isStable, bool _isShortable ) external; function setPriceFeed(address _priceFeed) external; function withdrawFees(address _token, address _receiver) external returns (uint256); function directPoolDeposit(address _token) external; function buyUSDK(address _token, address _receiver) external returns (uint256); function sellUSDK(address _token, address _receiver) external returns (uint256); function swap(address _tokenIn, address _tokenOut, address _receiver) external returns (uint256); function increasePosition(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong) external; function decreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _collateralDelta, uint256 _sizeDelta, bool _isLong, address _receiver) external returns (uint256); function validateLiquidation(address _account, address _collateralToken, address _indexToken, bool _isLong, bool _raise) external view returns (uint256, uint256); function liquidatePosition(address _account, address _collateralToken, address _indexToken, bool _isLong, address _feeReceiver) external; function tokenToUsdMin(address _token, uint256 _tokenAmount) external view returns (uint256); function priceFeed() external view returns (address); function fundingRateFactor() external view returns (uint256); function stableFundingRateFactor() external view returns (uint256); function cumulativeFundingRates(address _token) external view returns (uint256); function getNextFundingRate(address _token) external view returns (uint256); function getFeeBasisPoints(address _token, uint256 _usdkDelta, uint256 _feeBasisPoints, uint256 _taxBasisPoints, bool _increment) external view returns (uint256); function liquidationFeeUsd() external view returns (uint256); function taxBasisPoints() external view returns (uint256); function stableTaxBasisPoints() external view returns (uint256); function mintBurnFeeBasisPoints() external view returns (uint256); function swapFeeBasisPoints() external view returns (uint256); function stableSwapFeeBasisPoints() external view returns (uint256); function marginFeeBasisPoints() external view returns (uint256); function allWhitelistedTokensLength() external view returns (uint256); function allWhitelistedTokens(uint256) external view returns (address); function whitelistedTokens(address _token) external view returns (bool); function stableTokens(address _token) external view returns (bool); function shortableTokens(address _token) external view returns (bool); function feeReserves(address _token) external view returns (uint256); function globalShortSizes(address _token) external view returns (uint256); function globalShortAveragePrices(address _token) external view returns (uint256); function maxGlobalShortSizes(address _token) external view returns (uint256); function tokenDecimals(address _token) external view returns (uint256); function tokenWeights(address _token) external view returns (uint256); function guaranteedUsd(address _token) external view returns (uint256); function poolAmounts(address _token) external view returns (uint256); function bufferAmounts(address _token) external view returns (uint256); function reservedAmounts(address _token) external view returns (uint256); function usdkAmounts(address _token) external view returns (uint256); function maxUsdkAmounts(address _token) external view returns (uint256); function getRedemptionAmount(address _token, uint256 _usdkAmount) external view returns (uint256); function getMaxPrice(address _token) external view returns (uint256); function getMinPrice(address _token) external view returns (uint256); function getDelta(address _indexToken, uint256 _size, uint256 _averagePrice, bool _isLong, uint256 _lastIncreasedTime) external view returns (bool, uint256); function getPosition(address _account, address _collateralToken, address _indexToken, bool _isLong) external view returns (uint256, uint256, uint256, uint256, uint256, uint256, bool, uint256); }
contracts/core/interfaces/IVaultUtils.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; interface IVaultUtils { function updateCumulativeFundingRate(address _collateralToken, address _indexToken) external returns (bool); function validateIncreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong) external view; function validateDecreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _collateralDelta, uint256 _sizeDelta, bool _isLong, address _receiver) external view; function validateLiquidation(address _account, address _collateralToken, address _indexToken, bool _isLong, bool _raise) external view returns (uint256, uint256); function getEntryFundingRate(address _collateralToken, address _indexToken, bool _isLong) external view returns (uint256); function getPositionFee(address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _sizeDelta) external view returns (uint256); function getFundingFee(address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _size, uint256 _entryFundingRate) external view returns (uint256); function getBuyUsdkFeeBasisPoints(address _token, uint256 _usdkAmount) external view returns (uint256); function getSellUsdkFeeBasisPoints(address _token, uint256 _usdkAmount) external view returns (uint256); function getSwapFeeBasisPoints(address _tokenIn, address _tokenOut, uint256 _usdkAmount) external view returns (uint256); function getFeeBasisPoints(address _token, uint256 _usdkDelta, uint256 _feeBasisPoints, uint256 _taxBasisPoints, bool _increment) external view returns (uint256); }
contracts/libraries/math/SafeMath.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
contracts/access/Governable.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.6.12; contract Governable { address public gov; constructor() public { gov = msg.sender; } modifier onlyGov() { require(msg.sender == gov, "Governable: forbidden"); _; } function setGov(address _gov) external onlyGov { gov = _gov; } }
contracts/core/interfaces/IShortsTracker.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; interface IShortsTracker { function isGlobalShortDataReady() external view returns (bool); function globalShortAveragePrices(address _token) external view returns (uint256); function getNextGlobalShortData( address _account, address _collateralToken, address _indexToken, uint256 _nextPrice, uint256 _sizeDelta, bool _isIncrease ) external view returns (uint256, uint256); function updateGlobalShortData( address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _sizeDelta, uint256 _markPrice, bool _isIncrease ) external; function setIsGlobalShortDataReady(bool value) external; function setInitData(address[] calldata _tokens, uint256[] calldata _averagePrices) external; }
contracts/core/interfaces/IVault.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; import "./IVaultUtils.sol"; interface IVault { function isInitialized() external view returns (bool); function isSwapEnabled() external view returns (bool); function isLeverageEnabled() external view returns (bool); function setVaultUtils(IVaultUtils _vaultUtils) external; function setError(uint256 _errorCode, string calldata _error) external; function router() external view returns (address); function usdk() external view returns (address); function gov() external view returns (address); function whitelistedTokenCount() external view returns (uint256); function maxLeverage() external view returns (uint256); function minProfitTime() external view returns (uint256); function hasDynamicFees() external view returns (bool); function fundingInterval() external view returns (uint256); function totalTokenWeights() external view returns (uint256); function getTargetUsdkAmount(address _token) external view returns (uint256); function inManagerMode() external view returns (bool); function inPrivateLiquidationMode() external view returns (bool); function maxGasPrice() external view returns (uint256); function approvedRouters(address _account, address _router) external view returns (bool); function isLiquidator(address _account) external view returns (bool); function isManager(address _account) external view returns (bool); function minProfitBasisPoints(address _token) external view returns (uint256); function tokenBalances(address _token) external view returns (uint256); function lastFundingTimes(address _token) external view returns (uint256); function setMaxLeverage(uint256 _maxLeverage) external; function setInManagerMode(bool _inManagerMode) external; function setManager(address _manager, bool _isManager) external; function setIsSwapEnabled(bool _isSwapEnabled) external; function setIsLeverageEnabled(bool _isLeverageEnabled) external; function setMaxGasPrice(uint256 _maxGasPrice) external; function setUsdkAmount(address _token, uint256 _amount) external; function setBufferAmount(address _token, uint256 _amount) external; function setMaxGlobalShortSize(address _token, uint256 _amount) external; function setInPrivateLiquidationMode(bool _inPrivateLiquidationMode) external; function setLiquidator(address _liquidator, bool _isActive) external; function setFundingRate(uint256 _fundingInterval, uint256 _fundingRateFactor, uint256 _stableFundingRateFactor) external; function setFees( uint256 _taxBasisPoints, uint256 _stableTaxBasisPoints, uint256 _mintBurnFeeBasisPoints, uint256 _swapFeeBasisPoints, uint256 _stableSwapFeeBasisPoints, uint256 _marginFeeBasisPoints, uint256 _liquidationFeeUsd, uint256 _minProfitTime, bool _hasDynamicFees ) external; function setTokenConfig( address _token, uint256 _tokenDecimals, uint256 _redemptionBps, uint256 _minProfitBps, uint256 _maxUsdkAmount, bool _isStable, bool _isShortable ) external; function setPriceFeed(address _priceFeed) external; function withdrawFees(address _token, address _receiver) external returns (uint256); function directPoolDeposit(address _token) external; function buyUSDK(address _token, address _receiver) external returns (uint256); function sellUSDK(address _token, address _receiver) external returns (uint256); function swap(address _tokenIn, address _tokenOut, address _receiver) external returns (uint256); function increasePosition(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong) external; function decreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _collateralDelta, uint256 _sizeDelta, bool _isLong, address _receiver) external returns (uint256); function validateLiquidation(address _account, address _collateralToken, address _indexToken, bool _isLong, bool _raise) external view returns (uint256, uint256); function liquidatePosition(address _account, address _collateralToken, address _indexToken, bool _isLong, address _feeReceiver) external; function tokenToUsdMin(address _token, uint256 _tokenAmount) external view returns (uint256); function priceFeed() external view returns (address); function fundingRateFactor() external view returns (uint256); function stableFundingRateFactor() external view returns (uint256); function cumulativeFundingRates(address _token) external view returns (uint256); function getNextFundingRate(address _token) external view returns (uint256); function getFeeBasisPoints(address _token, uint256 _usdkDelta, uint256 _feeBasisPoints, uint256 _taxBasisPoints, bool _increment) external view returns (uint256); function liquidationFeeUsd() external view returns (uint256); function taxBasisPoints() external view returns (uint256); function stableTaxBasisPoints() external view returns (uint256); function mintBurnFeeBasisPoints() external view returns (uint256); function swapFeeBasisPoints() external view returns (uint256); function stableSwapFeeBasisPoints() external view returns (uint256); function marginFeeBasisPoints() external view returns (uint256); function allWhitelistedTokensLength() external view returns (uint256); function allWhitelistedTokens(uint256) external view returns (address); function whitelistedTokens(address _token) external view returns (bool); function stableTokens(address _token) external view returns (bool); function shortableTokens(address _token) external view returns (bool); function feeReserves(address _token) external view returns (uint256); function globalShortSizes(address _token) external view returns (uint256); function globalShortAveragePrices(address _token) external view returns (uint256); function maxGlobalShortSizes(address _token) external view returns (uint256); function tokenDecimals(address _token) external view returns (uint256); function tokenWeights(address _token) external view returns (uint256); function guaranteedUsd(address _token) external view returns (uint256); function poolAmounts(address _token) external view returns (uint256); function bufferAmounts(address _token) external view returns (uint256); function reservedAmounts(address _token) external view returns (uint256); function usdkAmounts(address _token) external view returns (uint256); function maxUsdkAmounts(address _token) external view returns (uint256); function getRedemptionAmount(address _token, uint256 _usdkAmount) external view returns (uint256); function getMaxPrice(address _token) external view returns (uint256); function getMinPrice(address _token) external view returns (uint256); function getDelta(address _indexToken, uint256 _size, uint256 _averagePrice, bool _isLong, uint256 _lastIncreasedTime) external view returns (bool, uint256); function getPosition(address _account, address _collateralToken, address _indexToken, bool _isLong) external view returns (uint256, uint256, uint256, uint256, uint256, uint256, bool, uint256); }
contracts/core/interfaces/IVaultUtils.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; interface IVaultUtils { function updateCumulativeFundingRate(address _collateralToken, address _indexToken) external returns (bool); function validateIncreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong) external view; function validateDecreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _collateralDelta, uint256 _sizeDelta, bool _isLong, address _receiver) external view; function validateLiquidation(address _account, address _collateralToken, address _indexToken, bool _isLong, bool _raise) external view returns (uint256, uint256); function getEntryFundingRate(address _collateralToken, address _indexToken, bool _isLong) external view returns (uint256); function getPositionFee(address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _sizeDelta) external view returns (uint256); function getFundingFee(address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _size, uint256 _entryFundingRate) external view returns (uint256); function getBuyUsdkFeeBasisPoints(address _token, uint256 _usdkAmount) external view returns (uint256); function getSellUsdkFeeBasisPoints(address _token, uint256 _usdkAmount) external view returns (uint256); function getSwapFeeBasisPoints(address _tokenIn, address _tokenOut, uint256 _usdkAmount) external view returns (uint256); function getFeeBasisPoints(address _token, uint256 _usdkDelta, uint256 _feeBasisPoints, uint256 _taxBasisPoints, bool _increment) external view returns (uint256); }
contracts/libraries/math/SafeMath.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
contracts/access/Governable.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.6.12; contract Governable { address public gov; constructor() public { gov = msg.sender; } modifier onlyGov() { require(msg.sender == gov, "Governable: forbidden"); _; } function setGov(address _gov) external onlyGov { gov = _gov; } }
contracts/core/interfaces/IShortsTracker.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; interface IShortsTracker { function isGlobalShortDataReady() external view returns (bool); function globalShortAveragePrices(address _token) external view returns (uint256); function getNextGlobalShortData( address _account, address _collateralToken, address _indexToken, uint256 _nextPrice, uint256 _sizeDelta, bool _isIncrease ) external view returns (uint256, uint256); function updateGlobalShortData( address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _sizeDelta, uint256 _markPrice, bool _isIncrease ) external; function setIsGlobalShortDataReady(bool value) external; function setInitData(address[] calldata _tokens, uint256[] calldata _averagePrices) external; }
contracts/core/interfaces/IVault.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; import "./IVaultUtils.sol"; interface IVault { function isInitialized() external view returns (bool); function isSwapEnabled() external view returns (bool); function isLeverageEnabled() external view returns (bool); function setVaultUtils(IVaultUtils _vaultUtils) external; function setError(uint256 _errorCode, string calldata _error) external; function router() external view returns (address); function usdk() external view returns (address); function gov() external view returns (address); function whitelistedTokenCount() external view returns (uint256); function maxLeverage() external view returns (uint256); function minProfitTime() external view returns (uint256); function hasDynamicFees() external view returns (bool); function fundingInterval() external view returns (uint256); function totalTokenWeights() external view returns (uint256); function getTargetUsdkAmount(address _token) external view returns (uint256); function inManagerMode() external view returns (bool); function inPrivateLiquidationMode() external view returns (bool); function maxGasPrice() external view returns (uint256); function approvedRouters(address _account, address _router) external view returns (bool); function isLiquidator(address _account) external view returns (bool); function isManager(address _account) external view returns (bool); function minProfitBasisPoints(address _token) external view returns (uint256); function tokenBalances(address _token) external view returns (uint256); function lastFundingTimes(address _token) external view returns (uint256); function setMaxLeverage(uint256 _maxLeverage) external; function setInManagerMode(bool _inManagerMode) external; function setManager(address _manager, bool _isManager) external; function setIsSwapEnabled(bool _isSwapEnabled) external; function setIsLeverageEnabled(bool _isLeverageEnabled) external; function setMaxGasPrice(uint256 _maxGasPrice) external; function setUsdkAmount(address _token, uint256 _amount) external; function setBufferAmount(address _token, uint256 _amount) external; function setMaxGlobalShortSize(address _token, uint256 _amount) external; function setInPrivateLiquidationMode(bool _inPrivateLiquidationMode) external; function setLiquidator(address _liquidator, bool _isActive) external; function setFundingRate(uint256 _fundingInterval, uint256 _fundingRateFactor, uint256 _stableFundingRateFactor) external; function setFees( uint256 _taxBasisPoints, uint256 _stableTaxBasisPoints, uint256 _mintBurnFeeBasisPoints, uint256 _swapFeeBasisPoints, uint256 _stableSwapFeeBasisPoints, uint256 _marginFeeBasisPoints, uint256 _liquidationFeeUsd, uint256 _minProfitTime, bool _hasDynamicFees ) external; function setTokenConfig( address _token, uint256 _tokenDecimals, uint256 _redemptionBps, uint256 _minProfitBps, uint256 _maxUsdkAmount, bool _isStable, bool _isShortable ) external; function setPriceFeed(address _priceFeed) external; function withdrawFees(address _token, address _receiver) external returns (uint256); function directPoolDeposit(address _token) external; function buyUSDK(address _token, address _receiver) external returns (uint256); function sellUSDK(address _token, address _receiver) external returns (uint256); function swap(address _tokenIn, address _tokenOut, address _receiver) external returns (uint256); function increasePosition(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong) external; function decreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _collateralDelta, uint256 _sizeDelta, bool _isLong, address _receiver) external returns (uint256); function validateLiquidation(address _account, address _collateralToken, address _indexToken, bool _isLong, bool _raise) external view returns (uint256, uint256); function liquidatePosition(address _account, address _collateralToken, address _indexToken, bool _isLong, address _feeReceiver) external; function tokenToUsdMin(address _token, uint256 _tokenAmount) external view returns (uint256); function priceFeed() external view returns (address); function fundingRateFactor() external view returns (uint256); function stableFundingRateFactor() external view returns (uint256); function cumulativeFundingRates(address _token) external view returns (uint256); function getNextFundingRate(address _token) external view returns (uint256); function getFeeBasisPoints(address _token, uint256 _usdkDelta, uint256 _feeBasisPoints, uint256 _taxBasisPoints, bool _increment) external view returns (uint256); function liquidationFeeUsd() external view returns (uint256); function taxBasisPoints() external view returns (uint256); function stableTaxBasisPoints() external view returns (uint256); function mintBurnFeeBasisPoints() external view returns (uint256); function swapFeeBasisPoints() external view returns (uint256); function stableSwapFeeBasisPoints() external view returns (uint256); function marginFeeBasisPoints() external view returns (uint256); function allWhitelistedTokensLength() external view returns (uint256); function allWhitelistedTokens(uint256) external view returns (address); function whitelistedTokens(address _token) external view returns (bool); function stableTokens(address _token) external view returns (bool); function shortableTokens(address _token) external view returns (bool); function feeReserves(address _token) external view returns (uint256); function globalShortSizes(address _token) external view returns (uint256); function globalShortAveragePrices(address _token) external view returns (uint256); function maxGlobalShortSizes(address _token) external view returns (uint256); function tokenDecimals(address _token) external view returns (uint256); function tokenWeights(address _token) external view returns (uint256); function guaranteedUsd(address _token) external view returns (uint256); function poolAmounts(address _token) external view returns (uint256); function bufferAmounts(address _token) external view returns (uint256); function reservedAmounts(address _token) external view returns (uint256); function usdkAmounts(address _token) external view returns (uint256); function maxUsdkAmounts(address _token) external view returns (uint256); function getRedemptionAmount(address _token, uint256 _usdkAmount) external view returns (uint256); function getMaxPrice(address _token) external view returns (uint256); function getMinPrice(address _token) external view returns (uint256); function getDelta(address _indexToken, uint256 _size, uint256 _averagePrice, bool _isLong, uint256 _lastIncreasedTime) external view returns (bool, uint256); function getPosition(address _account, address _collateralToken, address _indexToken, bool _isLong) external view returns (uint256, uint256, uint256, uint256, uint256, uint256, bool, uint256); }
contracts/core/interfaces/IVaultUtils.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; interface IVaultUtils { function updateCumulativeFundingRate(address _collateralToken, address _indexToken) external returns (bool); function validateIncreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong) external view; function validateDecreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _collateralDelta, uint256 _sizeDelta, bool _isLong, address _receiver) external view; function validateLiquidation(address _account, address _collateralToken, address _indexToken, bool _isLong, bool _raise) external view returns (uint256, uint256); function getEntryFundingRate(address _collateralToken, address _indexToken, bool _isLong) external view returns (uint256); function getPositionFee(address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _sizeDelta) external view returns (uint256); function getFundingFee(address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _size, uint256 _entryFundingRate) external view returns (uint256); function getBuyUsdkFeeBasisPoints(address _token, uint256 _usdkAmount) external view returns (uint256); function getSellUsdkFeeBasisPoints(address _token, uint256 _usdkAmount) external view returns (uint256); function getSwapFeeBasisPoints(address _tokenIn, address _tokenOut, uint256 _usdkAmount) external view returns (uint256); function getFeeBasisPoints(address _token, uint256 _usdkDelta, uint256 _feeBasisPoints, uint256 _taxBasisPoints, bool _increment) external view returns (uint256); }
contracts/libraries/math/SafeMath.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
contracts/access/Governable.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.6.12; contract Governable { address public gov; constructor() public { gov = msg.sender; } modifier onlyGov() { require(msg.sender == gov, "Governable: forbidden"); _; } function setGov(address _gov) external onlyGov { gov = _gov; } }
contracts/core/interfaces/IShortsTracker.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; interface IShortsTracker { function isGlobalShortDataReady() external view returns (bool); function globalShortAveragePrices(address _token) external view returns (uint256); function getNextGlobalShortData( address _account, address _collateralToken, address _indexToken, uint256 _nextPrice, uint256 _sizeDelta, bool _isIncrease ) external view returns (uint256, uint256); function updateGlobalShortData( address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _sizeDelta, uint256 _markPrice, bool _isIncrease ) external; function setIsGlobalShortDataReady(bool value) external; function setInitData(address[] calldata _tokens, uint256[] calldata _averagePrices) external; }
contracts/core/interfaces/IVault.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; import "./IVaultUtils.sol"; interface IVault { function isInitialized() external view returns (bool); function isSwapEnabled() external view returns (bool); function isLeverageEnabled() external view returns (bool); function setVaultUtils(IVaultUtils _vaultUtils) external; function setError(uint256 _errorCode, string calldata _error) external; function router() external view returns (address); function usdk() external view returns (address); function gov() external view returns (address); function whitelistedTokenCount() external view returns (uint256); function maxLeverage() external view returns (uint256); function minProfitTime() external view returns (uint256); function hasDynamicFees() external view returns (bool); function fundingInterval() external view returns (uint256); function totalTokenWeights() external view returns (uint256); function getTargetUsdkAmount(address _token) external view returns (uint256); function inManagerMode() external view returns (bool); function inPrivateLiquidationMode() external view returns (bool); function maxGasPrice() external view returns (uint256); function approvedRouters(address _account, address _router) external view returns (bool); function isLiquidator(address _account) external view returns (bool); function isManager(address _account) external view returns (bool); function minProfitBasisPoints(address _token) external view returns (uint256); function tokenBalances(address _token) external view returns (uint256); function lastFundingTimes(address _token) external view returns (uint256); function setMaxLeverage(uint256 _maxLeverage) external; function setInManagerMode(bool _inManagerMode) external; function setManager(address _manager, bool _isManager) external; function setIsSwapEnabled(bool _isSwapEnabled) external; function setIsLeverageEnabled(bool _isLeverageEnabled) external; function setMaxGasPrice(uint256 _maxGasPrice) external; function setUsdkAmount(address _token, uint256 _amount) external; function setBufferAmount(address _token, uint256 _amount) external; function setMaxGlobalShortSize(address _token, uint256 _amount) external; function setInPrivateLiquidationMode(bool _inPrivateLiquidationMode) external; function setLiquidator(address _liquidator, bool _isActive) external; function setFundingRate(uint256 _fundingInterval, uint256 _fundingRateFactor, uint256 _stableFundingRateFactor) external; function setFees( uint256 _taxBasisPoints, uint256 _stableTaxBasisPoints, uint256 _mintBurnFeeBasisPoints, uint256 _swapFeeBasisPoints, uint256 _stableSwapFeeBasisPoints, uint256 _marginFeeBasisPoints, uint256 _liquidationFeeUsd, uint256 _minProfitTime, bool _hasDynamicFees ) external; function setTokenConfig( address _token, uint256 _tokenDecimals, uint256 _redemptionBps, uint256 _minProfitBps, uint256 _maxUsdkAmount, bool _isStable, bool _isShortable ) external; function setPriceFeed(address _priceFeed) external; function withdrawFees(address _token, address _receiver) external returns (uint256); function directPoolDeposit(address _token) external; function buyUSDK(address _token, address _receiver) external returns (uint256); function sellUSDK(address _token, address _receiver) external returns (uint256); function swap(address _tokenIn, address _tokenOut, address _receiver) external returns (uint256); function increasePosition(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong) external; function decreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _collateralDelta, uint256 _sizeDelta, bool _isLong, address _receiver) external returns (uint256); function validateLiquidation(address _account, address _collateralToken, address _indexToken, bool _isLong, bool _raise) external view returns (uint256, uint256); function liquidatePosition(address _account, address _collateralToken, address _indexToken, bool _isLong, address _feeReceiver) external; function tokenToUsdMin(address _token, uint256 _tokenAmount) external view returns (uint256); function priceFeed() external view returns (address); function fundingRateFactor() external view returns (uint256); function stableFundingRateFactor() external view returns (uint256); function cumulativeFundingRates(address _token) external view returns (uint256); function getNextFundingRate(address _token) external view returns (uint256); function getFeeBasisPoints(address _token, uint256 _usdkDelta, uint256 _feeBasisPoints, uint256 _taxBasisPoints, bool _increment) external view returns (uint256); function liquidationFeeUsd() external view returns (uint256); function taxBasisPoints() external view returns (uint256); function stableTaxBasisPoints() external view returns (uint256); function mintBurnFeeBasisPoints() external view returns (uint256); function swapFeeBasisPoints() external view returns (uint256); function stableSwapFeeBasisPoints() external view returns (uint256); function marginFeeBasisPoints() external view returns (uint256); function allWhitelistedTokensLength() external view returns (uint256); function allWhitelistedTokens(uint256) external view returns (address); function whitelistedTokens(address _token) external view returns (bool); function stableTokens(address _token) external view returns (bool); function shortableTokens(address _token) external view returns (bool); function feeReserves(address _token) external view returns (uint256); function globalShortSizes(address _token) external view returns (uint256); function globalShortAveragePrices(address _token) external view returns (uint256); function maxGlobalShortSizes(address _token) external view returns (uint256); function tokenDecimals(address _token) external view returns (uint256); function tokenWeights(address _token) external view returns (uint256); function guaranteedUsd(address _token) external view returns (uint256); function poolAmounts(address _token) external view returns (uint256); function bufferAmounts(address _token) external view returns (uint256); function reservedAmounts(address _token) external view returns (uint256); function usdkAmounts(address _token) external view returns (uint256); function maxUsdkAmounts(address _token) external view returns (uint256); function getRedemptionAmount(address _token, uint256 _usdkAmount) external view returns (uint256); function getMaxPrice(address _token) external view returns (uint256); function getMinPrice(address _token) external view returns (uint256); function getDelta(address _indexToken, uint256 _size, uint256 _averagePrice, bool _isLong, uint256 _lastIncreasedTime) external view returns (bool, uint256); function getPosition(address _account, address _collateralToken, address _indexToken, bool _isLong) external view returns (uint256, uint256, uint256, uint256, uint256, uint256, bool, uint256); }
contracts/core/interfaces/IVaultUtils.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; interface IVaultUtils { function updateCumulativeFundingRate(address _collateralToken, address _indexToken) external returns (bool); function validateIncreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _sizeDelta, bool _isLong) external view; function validateDecreasePosition(address _account, address _collateralToken, address _indexToken, uint256 _collateralDelta, uint256 _sizeDelta, bool _isLong, address _receiver) external view; function validateLiquidation(address _account, address _collateralToken, address _indexToken, bool _isLong, bool _raise) external view returns (uint256, uint256); function getEntryFundingRate(address _collateralToken, address _indexToken, bool _isLong) external view returns (uint256); function getPositionFee(address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _sizeDelta) external view returns (uint256); function getFundingFee(address _account, address _collateralToken, address _indexToken, bool _isLong, uint256 _size, uint256 _entryFundingRate) external view returns (uint256); function getBuyUsdkFeeBasisPoints(address _token, uint256 _usdkAmount) external view returns (uint256); function getSellUsdkFeeBasisPoints(address _token, uint256 _usdkAmount) external view returns (uint256); function getSwapFeeBasisPoints(address _tokenIn, address _tokenOut, uint256 _usdkAmount) external view returns (uint256); function getFeeBasisPoints(address _token, uint256 _usdkDelta, uint256 _feeBasisPoints, uint256 _taxBasisPoints, bool _increment) external view returns (uint256); }
contracts/libraries/math/SafeMath.sol
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @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) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @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 sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @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) { // 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 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts 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) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts 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 mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_vault","internalType":"address"}]},{"type":"event","name":"GlobalShortDataUpdated","inputs":[{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"uint256","name":"globalShortSize","internalType":"uint256","indexed":false},{"type":"uint256","name":"globalShortAveragePrice","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"MAX_INT256","inputs":[]},{"type":"function","stateMutability":"pure","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"_getNextGlobalAveragePrice","inputs":[{"type":"uint256","name":"_averagePrice","internalType":"uint256"},{"type":"uint256","name":"_nextPrice","internalType":"uint256"},{"type":"uint256","name":"_nextSize","internalType":"uint256"},{"type":"uint256","name":"_delta","internalType":"uint256"},{"type":"int256","name":"_realisedPnl","internalType":"int256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"data","inputs":[{"type":"bytes32","name":"","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"},{"type":"uint256","name":"","internalType":"uint256"}],"name":"getGlobalShortDelta","inputs":[{"type":"address","name":"_token","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"}],"name":"getNextGlobalShortData","inputs":[{"type":"address","name":"_account","internalType":"address"},{"type":"address","name":"_collateralToken","internalType":"address"},{"type":"address","name":"_indexToken","internalType":"address"},{"type":"uint256","name":"_nextPrice","internalType":"uint256"},{"type":"uint256","name":"_sizeDelta","internalType":"uint256"},{"type":"bool","name":"_isIncrease","internalType":"bool"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"int256","name":"","internalType":"int256"}],"name":"getRealisedPnl","inputs":[{"type":"address","name":"_account","internalType":"address"},{"type":"address","name":"_collateralToken","internalType":"address"},{"type":"address","name":"_indexToken","internalType":"address"},{"type":"uint256","name":"_sizeDelta","internalType":"uint256"},{"type":"bool","name":"_isIncrease","internalType":"bool"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"globalShortAveragePrices","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"gov","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isGlobalShortDataReady","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isHandler","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setGov","inputs":[{"type":"address","name":"_gov","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setHandler","inputs":[{"type":"address","name":"_handler","internalType":"address"},{"type":"bool","name":"_isActive","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setInitData","inputs":[{"type":"address[]","name":"_tokens","internalType":"address[]"},{"type":"uint256[]","name":"_averagePrices","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setIsGlobalShortDataReady","inputs":[{"type":"bool","name":"value","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateGlobalShortData","inputs":[{"type":"address","name":"_account","internalType":"address"},{"type":"address","name":"_collateralToken","internalType":"address"},{"type":"address","name":"_indexToken","internalType":"address"},{"type":"bool","name":"_isLong","internalType":"bool"},{"type":"uint256","name":"_sizeDelta","internalType":"uint256"},{"type":"uint256","name":"_markPrice","internalType":"uint256"},{"type":"bool","name":"_isIncrease","internalType":"bool"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IVault"}],"name":"vault","inputs":[]}]
Contract Creation Code
0x608060405234801561001057600080fd5b506040516111483803806111488339818101604052602081101561003357600080fd5b5051600080546001600160a01b03199081163317909155600180546001600160a01b03909316929091169190911790556110d6806100726000396000f3fe608060405234801561001057600080fd5b50600436106100d05760003560e01c80630147fb0c146100d5578063122e7b071461010457806312d43a511461010c5780633d30cabf1461013057806346ea87af146101515780635886b7111461018b57806362749803146101c05780639a11178f146101e65780639cb7de4b146101ee5780639cdeb5931461021c578063a83b75fd1461027f578063b364accb146102c3578063bbd9718714610304578063cfad57a2146103c2578063f3238cec146103e8578063fbfa77cf1461043a575b600080fd5b6100f2600480360360208110156100eb57600080fd5b5035610442565b60408051918252519081900360200190f35b6100f2610454565b61011461045f565b604080516001600160a01b039092168252519081900360200190f35b61014f6004803603602081101561014657600080fd5b5035151561046e565b005b6101776004803603602081101561016757600080fd5b50356001600160a01b03166104ce565b604080519115158252519081900360200190f35b6100f2600480360360a08110156101a157600080fd5b50803590602081013590604081013590606081013590608001356104e3565b6100f2600480360360208110156101d657600080fd5b50356001600160a01b031661053a565b61017761054c565b61014f6004803603604081101561020457600080fd5b506001600160a01b0381351690602001351515610555565b610266600480360360c081101561023257600080fd5b506001600160a01b03813581169160208101358216916040820135169060608101359060808101359060a001351515610628565b6040805192835260208301919091528051918290030190f35b6100f2600480360360a081101561029557600080fd5b506001600160a01b03813581169160208101358216916040820135169060608101359060800135151561077c565b6102e9600480360360208110156102d957600080fd5b50356001600160a01b031661095c565b60408051921515835260208301919091528051918290030190f35b61014f6004803603604081101561031a57600080fd5b810190602081018135600160201b81111561033457600080fd5b82018360208201111561034657600080fd5b803590602001918460208302840111600160201b8311171561036757600080fd5b919390929091602081019035600160201b81111561038457600080fd5b82018360208201111561039657600080fd5b803590602001918460208302840111600160201b831117156103b757600080fd5b509092509050610acf565b61014f600480360360208110156103d857600080fd5b50356001600160a01b0316610be1565b61014f600480360360e08110156103fe57600080fd5b506001600160a01b038135811691602081013582169160408201351690606081013515159060808101359060a08101359060c001351515610c50565b610114610d40565b60036020526000908152604090205481565b6001600160ff1b0381565b6000546001600160a01b031681565b6000546001600160a01b031633146104bb576040805162461bcd60e51b81526020600482015260156024820152600080516020611060833981519152604482015290519081900360640190fd5b6005805460ff1916911515919091179055565b60026020526000908152604090205460ff1681565b60008060006104f485898987610d4f565b91509150600061052b836105115761050c8884610e0c565b61051b565b61051b8884610e6d565b6105258a8a610eaf565b90610f08565b93505050505b95945050505050565b60046020526000908152604090205481565b60055460ff1681565b6000546001600160a01b031633146105a2576040805162461bcd60e51b81526020600482015260156024820152600080516020611060833981519152604482015290519081900360640190fd5b6001600160a01b0382166105fd576040805162461bcd60e51b815260206004820152601f60248201527f53686f727473547261636b65723a20696e76616c6964205f68616e646c657200604482015290519081900360640190fd5b6001600160a01b03919091166000908152600260205260409020805460ff1916911515919091179055565b600080600061063a898989888861077c565b6001600160a01b03881660009081526004602052604081205491925087821161066c576106678883610e6d565b610676565b6106768289610e6d565b6001546040805163114f1b5560e31b81526001600160a01b038d811660048301529151939450600093849384931691638a78daa8916024808301926020929190829003018186803b1580156106ca57600080fd5b505afa1580156106de573d6000803e3d6000fd5b505050506040513d60208110156106f457600080fd5b505190508861070c57610707818b610e6d565b610716565b610716818b610e0c565b92508261072f5760008097509750505050505050610771565b8461074557828b97509750505050505050610771565b610753856105258387610eaf565b9150506000610765858c85858a6104e3565b92975091955050505050505b965096945050505050565b6000811561078c57506000610531565b60015460408051634a3f088d60e01b81526001600160a01b038981166004830152888116602483015287811660448301526000606483018190529251931692829182918591634a3f088d91608480830192610100929190829003018186803b1580156107f757600080fd5b505afa15801561080b573d6000803e3d6000fd5b505050506040513d61010081101561082257600080fd5b50805160408083015160e0909301518151635c07eaab60e01b81526001600160a01b038d811660048301526024820185905260448201869052600060648301819052608483018490528451959950959750919550849391891692635c07eaab9260a480840193829003018186803b15801561089c57600080fd5b505afa1580156108b0573d6000803e3d6000fd5b505050506040513d60408110156108c657600080fd5b508051602090910151909250905060006108e4866105258c85610eaf565b90506001600160ff1b03811061093b576040805162461bcd60e51b815260206004820152601760248201527653686f727473547261636b65723a206f766572666c6f7760481b604482015290519081900360640190fd5b82610949578060000361094b565b805b9d9c50505050505050505050505050565b6001546040805163114f1b5560e31b81526001600160a01b038481166004830152915160009384938493911691638a78daa891602480820192602092909190829003018186803b1580156109af57600080fd5b505afa1580156109c3573d6000803e3d6000fd5b505050506040513d60208110156109d957600080fd5b50516001600160a01b03851660009081526004602052604090205490915081610a0a57600080935093505050610aca565b60015460408051637092736960e11b81526001600160a01b0388811660048301529151600093929092169163e124e6d291602480820192602092909190829003018186803b158015610a5b57600080fd5b505afa158015610a6f573d6000803e3d6000fd5b505050506040513d6020811015610a8557600080fd5b505190506000818311610aa157610a9c8284610e6d565b610aab565b610aab8383610e6d565b90506000610abd846105258785610eaf565b9290931195509093505050505b915091565b6000546001600160a01b03163314610b1c576040805162461bcd60e51b81526020600482015260156024820152600080516020611060833981519152604482015290519081900360640190fd5b60055460ff1615610b74576040805162461bcd60e51b815260206004820152601f60248201527f53686f727473547261636b65723a20616c7265616479206d6967726174656400604482015290519081900360640190fd5b60005b83811015610bcd57828282818110610b8b57fe5b9050602002013560046000878785818110610ba257fe5b602090810292909201356001600160a01b031683525081019190915260400160002055600101610b77565b50506005805460ff19166001179055505050565b6000546001600160a01b03163314610c2e576040805162461bcd60e51b81526020600482015260156024820152600080516020611060833981519152604482015290519081900360640190fd5b600080546001600160a01b0319166001600160a01b0392909216919091179055565b3360009081526002602052604090205460ff16610caf576040805162461bcd60e51b815260206004820152601860248201527729b437b93a39aa3930b1b5b2b91d103337b93134b23232b760411b604482015290519081900360640190fd5b8380610cb9575082155b15610cc357610d37565b60055460ff16610cd257610d37565b600080610ce3898989878988610628565b91509150610cf18782610f47565b604080518381526020810183905281516001600160a01b038a16927fd6137be44db128ffcf1ea1821dbe8f889f67f949be7656c2d8acba2a4a891a02928290030190a250505b50505050505050565b6001546001600160a01b031681565b6000808385118015610dae576000841315610d935786841115610d8157610d768488610e6d565b965060009050610d8e565b610d8b8785610e6d565b96505b610da4565b610da1876000869003610e0c565b96505b9150859050610e03565b6000841315610dc857610dc18785610e0c565b9650610dfd565b86846000031115610dec57610de1600085900388610e6d565b965060019050610dfd565b610dfa876000869003610e6d565b96505b91508590505b94509492505050565b600082820183811015610e64576040805162461bcd60e51b815260206004820152601b60248201527a536166654d6174683a206164646974696f6e206f766572666c6f7760281b604482015290519081900360640190fd5b90505b92915050565b6000610e6483836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250610f63565b600082610ebe57506000610e67565b82820282848281610ecb57fe5b0414610e645760405162461bcd60e51b81526004018080602001828103825260218152602001806110806021913960400191505060405180910390fd5b6000610e6483836040518060400160405280601a815260200179536166654d6174683a206469766973696f6e206279207a65726f60301b815250610ffa565b6001600160a01b03909116600090815260046020526040902055565b60008184841115610ff25760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610fb7578181015183820152602001610f9f565b50505050905090810190601f168015610fe45780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b600081836110495760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610fb7578181015183820152602001610f9f565b50600083858161105557fe5b049594505050505056fe476f7665726e61626c653a20666f7262696464656e0000000000000000000000536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77a2646970667358221220d1560695fa8f801b8c5cfebfbbba9146abc00b0c788a4b92a8ba24f61f6968b164736f6c634300060c00330000000000000000000000005d2276c0860f4c6f731f30befa6e06162bc1a7ce
Deployed ByteCode
0x608060405234801561001057600080fd5b50600436106100d05760003560e01c80630147fb0c146100d5578063122e7b071461010457806312d43a511461010c5780633d30cabf1461013057806346ea87af146101515780635886b7111461018b57806362749803146101c05780639a11178f146101e65780639cb7de4b146101ee5780639cdeb5931461021c578063a83b75fd1461027f578063b364accb146102c3578063bbd9718714610304578063cfad57a2146103c2578063f3238cec146103e8578063fbfa77cf1461043a575b600080fd5b6100f2600480360360208110156100eb57600080fd5b5035610442565b60408051918252519081900360200190f35b6100f2610454565b61011461045f565b604080516001600160a01b039092168252519081900360200190f35b61014f6004803603602081101561014657600080fd5b5035151561046e565b005b6101776004803603602081101561016757600080fd5b50356001600160a01b03166104ce565b604080519115158252519081900360200190f35b6100f2600480360360a08110156101a157600080fd5b50803590602081013590604081013590606081013590608001356104e3565b6100f2600480360360208110156101d657600080fd5b50356001600160a01b031661053a565b61017761054c565b61014f6004803603604081101561020457600080fd5b506001600160a01b0381351690602001351515610555565b610266600480360360c081101561023257600080fd5b506001600160a01b03813581169160208101358216916040820135169060608101359060808101359060a001351515610628565b6040805192835260208301919091528051918290030190f35b6100f2600480360360a081101561029557600080fd5b506001600160a01b03813581169160208101358216916040820135169060608101359060800135151561077c565b6102e9600480360360208110156102d957600080fd5b50356001600160a01b031661095c565b60408051921515835260208301919091528051918290030190f35b61014f6004803603604081101561031a57600080fd5b810190602081018135600160201b81111561033457600080fd5b82018360208201111561034657600080fd5b803590602001918460208302840111600160201b8311171561036757600080fd5b919390929091602081019035600160201b81111561038457600080fd5b82018360208201111561039657600080fd5b803590602001918460208302840111600160201b831117156103b757600080fd5b509092509050610acf565b61014f600480360360208110156103d857600080fd5b50356001600160a01b0316610be1565b61014f600480360360e08110156103fe57600080fd5b506001600160a01b038135811691602081013582169160408201351690606081013515159060808101359060a08101359060c001351515610c50565b610114610d40565b60036020526000908152604090205481565b6001600160ff1b0381565b6000546001600160a01b031681565b6000546001600160a01b031633146104bb576040805162461bcd60e51b81526020600482015260156024820152600080516020611060833981519152604482015290519081900360640190fd5b6005805460ff1916911515919091179055565b60026020526000908152604090205460ff1681565b60008060006104f485898987610d4f565b91509150600061052b836105115761050c8884610e0c565b61051b565b61051b8884610e6d565b6105258a8a610eaf565b90610f08565b93505050505b95945050505050565b60046020526000908152604090205481565b60055460ff1681565b6000546001600160a01b031633146105a2576040805162461bcd60e51b81526020600482015260156024820152600080516020611060833981519152604482015290519081900360640190fd5b6001600160a01b0382166105fd576040805162461bcd60e51b815260206004820152601f60248201527f53686f727473547261636b65723a20696e76616c6964205f68616e646c657200604482015290519081900360640190fd5b6001600160a01b03919091166000908152600260205260409020805460ff1916911515919091179055565b600080600061063a898989888861077c565b6001600160a01b03881660009081526004602052604081205491925087821161066c576106678883610e6d565b610676565b6106768289610e6d565b6001546040805163114f1b5560e31b81526001600160a01b038d811660048301529151939450600093849384931691638a78daa8916024808301926020929190829003018186803b1580156106ca57600080fd5b505afa1580156106de573d6000803e3d6000fd5b505050506040513d60208110156106f457600080fd5b505190508861070c57610707818b610e6d565b610716565b610716818b610e0c565b92508261072f5760008097509750505050505050610771565b8461074557828b97509750505050505050610771565b610753856105258387610eaf565b9150506000610765858c85858a6104e3565b92975091955050505050505b965096945050505050565b6000811561078c57506000610531565b60015460408051634a3f088d60e01b81526001600160a01b038981166004830152888116602483015287811660448301526000606483018190529251931692829182918591634a3f088d91608480830192610100929190829003018186803b1580156107f757600080fd5b505afa15801561080b573d6000803e3d6000fd5b505050506040513d61010081101561082257600080fd5b50805160408083015160e0909301518151635c07eaab60e01b81526001600160a01b038d811660048301526024820185905260448201869052600060648301819052608483018490528451959950959750919550849391891692635c07eaab9260a480840193829003018186803b15801561089c57600080fd5b505afa1580156108b0573d6000803e3d6000fd5b505050506040513d60408110156108c657600080fd5b508051602090910151909250905060006108e4866105258c85610eaf565b90506001600160ff1b03811061093b576040805162461bcd60e51b815260206004820152601760248201527653686f727473547261636b65723a206f766572666c6f7760481b604482015290519081900360640190fd5b82610949578060000361094b565b805b9d9c50505050505050505050505050565b6001546040805163114f1b5560e31b81526001600160a01b038481166004830152915160009384938493911691638a78daa891602480820192602092909190829003018186803b1580156109af57600080fd5b505afa1580156109c3573d6000803e3d6000fd5b505050506040513d60208110156109d957600080fd5b50516001600160a01b03851660009081526004602052604090205490915081610a0a57600080935093505050610aca565b60015460408051637092736960e11b81526001600160a01b0388811660048301529151600093929092169163e124e6d291602480820192602092909190829003018186803b158015610a5b57600080fd5b505afa158015610a6f573d6000803e3d6000fd5b505050506040513d6020811015610a8557600080fd5b505190506000818311610aa157610a9c8284610e6d565b610aab565b610aab8383610e6d565b90506000610abd846105258785610eaf565b9290931195509093505050505b915091565b6000546001600160a01b03163314610b1c576040805162461bcd60e51b81526020600482015260156024820152600080516020611060833981519152604482015290519081900360640190fd5b60055460ff1615610b74576040805162461bcd60e51b815260206004820152601f60248201527f53686f727473547261636b65723a20616c7265616479206d6967726174656400604482015290519081900360640190fd5b60005b83811015610bcd57828282818110610b8b57fe5b9050602002013560046000878785818110610ba257fe5b602090810292909201356001600160a01b031683525081019190915260400160002055600101610b77565b50506005805460ff19166001179055505050565b6000546001600160a01b03163314610c2e576040805162461bcd60e51b81526020600482015260156024820152600080516020611060833981519152604482015290519081900360640190fd5b600080546001600160a01b0319166001600160a01b0392909216919091179055565b3360009081526002602052604090205460ff16610caf576040805162461bcd60e51b815260206004820152601860248201527729b437b93a39aa3930b1b5b2b91d103337b93134b23232b760411b604482015290519081900360640190fd5b8380610cb9575082155b15610cc357610d37565b60055460ff16610cd257610d37565b600080610ce3898989878988610628565b91509150610cf18782610f47565b604080518381526020810183905281516001600160a01b038a16927fd6137be44db128ffcf1ea1821dbe8f889f67f949be7656c2d8acba2a4a891a02928290030190a250505b50505050505050565b6001546001600160a01b031681565b6000808385118015610dae576000841315610d935786841115610d8157610d768488610e6d565b965060009050610d8e565b610d8b8785610e6d565b96505b610da4565b610da1876000869003610e0c565b96505b9150859050610e03565b6000841315610dc857610dc18785610e0c565b9650610dfd565b86846000031115610dec57610de1600085900388610e6d565b965060019050610dfd565b610dfa876000869003610e6d565b96505b91508590505b94509492505050565b600082820183811015610e64576040805162461bcd60e51b815260206004820152601b60248201527a536166654d6174683a206164646974696f6e206f766572666c6f7760281b604482015290519081900360640190fd5b90505b92915050565b6000610e6483836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250610f63565b600082610ebe57506000610e67565b82820282848281610ecb57fe5b0414610e645760405162461bcd60e51b81526004018080602001828103825260218152602001806110806021913960400191505060405180910390fd5b6000610e6483836040518060400160405280601a815260200179536166654d6174683a206469766973696f6e206279207a65726f60301b815250610ffa565b6001600160a01b03909116600090815260046020526040902055565b60008184841115610ff25760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610fb7578181015183820152602001610f9f565b50505050905090810190601f168015610fe45780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b600081836110495760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610fb7578181015183820152602001610f9f565b50600083858161105557fe5b049594505050505056fe476f7665726e61626c653a20666f7262696464656e0000000000000000000000536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77a2646970667358221220d1560695fa8f801b8c5cfebfbbba9146abc00b0c788a4b92a8ba24f61f6968b164736f6c634300060c0033