Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- FXSwapV2Router02
- Optimization enabled
- true
- Compiler version
- v0.6.6+commit.6c089d02
- Optimization runs
- 200
- Verified at
- 2022-07-19T07:07:35.423574Z
Constructor Arguments
000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd
Arg [0] (address) : 0xd55b6952be7d52f315246afd4cc64822d2b3d34d
Arg [1] (address) : 0x80b5a32e4f032b2a058b4f29ec95eefeeb87adcd
contracts/FXSwap-Periphery/FXSwapV2Router02.sol
pragma solidity =0.6.6; import '../FXSwap-Core/interfaces/IFXSwapV2Factory.sol'; import '../FXSwap-Lib/libraries/TransferHelper.sol'; import './interfaces/IFXSwapV2Router02.sol'; import './libraries/FXSwapV2Library.sol'; import './libraries/SafeMath.sol'; import './interfaces/IERC20.sol'; import './interfaces/IWFX.sol'; contract FXSwapV2Router02 is IFXSwapV2Router02 { using SafeMath for uint; address public immutable override factory; address public immutable override WFX; modifier ensure(uint deadline) { require(deadline >= block.timestamp, 'FXSwapV2Router: EXPIRED'); _; } constructor(address _factory, address _WFX) public { factory = _factory; WFX = _WFX; } receive() external payable { assert(msg.sender == WFX); // only accept FX via fallback from the WFX contract } // **** ADD LIQUIDITY **** function _addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin ) internal virtual returns (uint amountA, uint amountB) { // create the pair if it doesn't exist yet if (IFXSwapV2Factory(factory).getPair(tokenA, tokenB) == address(0)) { IFXSwapV2Factory(factory).createPair(tokenA, tokenB); } (uint reserveA, uint reserveB) = FXSwapV2Library.getReserves(factory, tokenA, tokenB); if (reserveA == 0 && reserveB == 0) { (amountA, amountB) = (amountADesired, amountBDesired); } else { uint amountBOptimal = FXSwapV2Library.quote(amountADesired, reserveA, reserveB); if (amountBOptimal <= amountBDesired) { require(amountBOptimal >= amountBMin, 'FXSwapV2Router: INSUFFICIENT_B_AMOUNT'); (amountA, amountB) = (amountADesired, amountBOptimal); } else { uint amountAOptimal = FXSwapV2Library.quote(amountBDesired, reserveB, reserveA); assert(amountAOptimal <= amountADesired); require(amountAOptimal >= amountAMin, 'FXSwapV2Router: INSUFFICIENT_A_AMOUNT'); (amountA, amountB) = (amountAOptimal, amountBDesired); } } } function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external virtual override ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) { (amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin); address pair = FXSwapV2Library.pairFor(factory, tokenA, tokenB); TransferHelper.safeTransferFrom(tokenA, msg.sender, pair, amountA); TransferHelper.safeTransferFrom(tokenB, msg.sender, pair, amountB); liquidity = IFXSwapV2Pair(pair).mint(to); } function addLiquidityFX( address token, uint amountTokenDesired, uint amountTokenMin, uint amountFXMin, address to, uint deadline ) external virtual override payable ensure(deadline) returns (uint amountToken, uint amountFX, uint liquidity) { (amountToken, amountFX) = _addLiquidity( token, WFX, amountTokenDesired, msg.value, amountTokenMin, amountFXMin ); address pair = FXSwapV2Library.pairFor(factory, token, WFX); TransferHelper.safeTransferFrom(token, msg.sender, pair, amountToken); IWFX(WFX).deposit{value: amountFX}(); assert(IWFX(WFX).transfer(pair, amountFX)); liquidity = IFXSwapV2Pair(pair).mint(to); // refund dust FX, if any if (msg.value > amountFX) TransferHelper.safeTransferFX(msg.sender, msg.value - amountFX); } // **** REMOVE LIQUIDITY **** function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) public virtual override ensure(deadline) returns (uint amountA, uint amountB) { address pair = FXSwapV2Library.pairFor(factory, tokenA, tokenB); IFXSwapV2Pair(pair).transferFrom(msg.sender, pair, liquidity); // send liquidity to pair (uint amount0, uint amount1) = IFXSwapV2Pair(pair).burn(to); (address token0,) = FXSwapV2Library.sortTokens(tokenA, tokenB); (amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0); require(amountA >= amountAMin, 'FXSwapV2Router: INSUFFICIENT_A_AMOUNT'); require(amountB >= amountBMin, 'FXSwapV2Router: INSUFFICIENT_B_AMOUNT'); } function removeLiquidityFX( address token, uint liquidity, uint amountTokenMin, uint amountFXMin, address to, uint deadline ) public virtual override ensure(deadline) returns (uint amountToken, uint amountFX) { (amountToken, amountFX) = removeLiquidity( token, WFX, liquidity, amountTokenMin, amountFXMin, address(this), deadline ); TransferHelper.safeTransfer(token, to, amountToken); IWFX(WFX).withdraw(address(this), amountFX); TransferHelper.safeTransferFX(to, amountFX); } function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external virtual override returns (uint amountA, uint amountB) { address pair = FXSwapV2Library.pairFor(factory, tokenA, tokenB); uint value = approveMax ? uint(-1) : liquidity; IFXSwapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s); (amountA, amountB) = removeLiquidity(tokenA, tokenB, liquidity, amountAMin, amountBMin, to, deadline); } function removeLiquidityFXWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountFXMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external virtual override returns (uint amountToken, uint amountFX) { address pair = FXSwapV2Library.pairFor(factory, token, WFX); uint value = approveMax ? uint(-1) : liquidity; IFXSwapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s); (amountToken, amountFX) = removeLiquidityFX(token, liquidity, amountTokenMin, amountFXMin, to, deadline); } // **** REMOVE LIQUIDITY (supporting fee-on-transfer tokens) **** function removeLiquidityFXSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountFXMin, address to, uint deadline ) public virtual override ensure(deadline) returns (uint amountFX) { (, amountFX) = removeLiquidity( token, WFX, liquidity, amountTokenMin, amountFXMin, address(this), deadline ); TransferHelper.safeTransfer(token, to, IERC20(token).balanceOf(address(this))); IWFX(WFX).withdraw(address(this), amountFX); TransferHelper.safeTransferFX(to, amountFX); } function removeLiquidityFXWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountFXMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external virtual override returns (uint amountFX) { address pair = FXSwapV2Library.pairFor(factory, token, WFX); uint value = approveMax ? uint(-1) : liquidity; IFXSwapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s); amountFX = removeLiquidityFXSupportingFeeOnTransferTokens( token, liquidity, amountTokenMin, amountFXMin, to, deadline ); } // **** SWAP **** // requires the initial amount to have already been sent to the first pair function _swap(uint[] memory amounts, address[] memory path, address _to) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = FXSwapV2Library.sortTokens(input, output); uint amountOut = amounts[i + 1]; (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0)); address to = i < path.length - 2 ? FXSwapV2Library.pairFor(factory, output, path[i + 2]) : _to; IFXSwapV2Pair(FXSwapV2Library.pairFor(factory, input, output)).swap( amount0Out, amount1Out, to, new bytes(0) ); } } function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external virtual override ensure(deadline) returns (uint[] memory amounts) { amounts = FXSwapV2Library.getAmountsOut(factory, amountIn, path); require(amounts[amounts.length - 1] >= amountOutMin, 'FXSwapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); TransferHelper.safeTransferFrom( path[0], msg.sender, FXSwapV2Library.pairFor(factory, path[0], path[1]), amounts[0] ); _swap(amounts, path, to); } function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external virtual override ensure(deadline) returns (uint[] memory amounts) { amounts = FXSwapV2Library.getAmountsIn(factory, amountOut, path); require(amounts[0] <= amountInMax, 'FXSwapV2Router: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( path[0], msg.sender, FXSwapV2Library.pairFor(factory, path[0], path[1]), amounts[0] ); _swap(amounts, path, to); } function swapExactFXForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external virtual override payable ensure(deadline) returns (uint[] memory amounts) { require(path[0] == WFX, 'FXSwapV2Router: INVALID_PATH'); amounts = FXSwapV2Library.getAmountsOut(factory, msg.value, path); require(amounts[amounts.length - 1] >= amountOutMin, 'FXSwapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); IWFX(WFX).deposit{value: amounts[0]}(); assert(IWFX(WFX).transfer(FXSwapV2Library.pairFor(factory, path[0], path[1]), amounts[0])); _swap(amounts, path, to); } function swapTokensForExactFX(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external virtual override ensure(deadline) returns (uint[] memory amounts) { require(path[path.length - 1] == WFX, 'FXSwapV2Router: INVALID_PATH'); amounts = FXSwapV2Library.getAmountsIn(factory, amountOut, path); require(amounts[0] <= amountInMax, 'FXSwapV2Router: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( path[0], msg.sender, FXSwapV2Library.pairFor(factory, path[0], path[1]), amounts[0] ); _swap(amounts, path, address(this)); IWFX(WFX).withdraw(address(this), amounts[amounts.length - 1]); TransferHelper.safeTransferFX(to, amounts[amounts.length - 1]); } function swapExactTokensForFX(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external virtual override ensure(deadline) returns (uint[] memory amounts) { require(path[path.length - 1] == WFX, 'FXSwapV2Router: INVALID_PATH'); amounts = FXSwapV2Library.getAmountsOut(factory, amountIn, path); require(amounts[amounts.length - 1] >= amountOutMin, 'FXSwapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); TransferHelper.safeTransferFrom( path[0], msg.sender, FXSwapV2Library.pairFor(factory, path[0], path[1]), amounts[0] ); _swap(amounts, path, address(this)); IWFX(WFX).withdraw(address(this), amounts[amounts.length - 1]); TransferHelper.safeTransferFX(to, amounts[amounts.length - 1]); } function swapFXForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external virtual override payable ensure(deadline) returns (uint[] memory amounts) { require(path[0] == WFX, 'FXSwapV2Router: INVALID_PATH'); amounts = FXSwapV2Library.getAmountsIn(factory, amountOut, path); require(amounts[0] <= msg.value, 'FXSwapV2Router: EXCESSIVE_INPUT_AMOUNT'); IWFX(WFX).deposit{value: amounts[0]}(); assert(IWFX(WFX).transfer(FXSwapV2Library.pairFor(factory, path[0], path[1]), amounts[0])); _swap(amounts, path, to); // refund dust FX, if any if (msg.value > amounts[0]) TransferHelper.safeTransferFX(msg.sender, msg.value - amounts[0]); } // **** SWAP (supporting fee-on-transfer tokens) **** // requires the initial amount to have already been sent to the first pair function _swapSupportingFeeOnTransferTokens(address[] memory path, address _to) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = FXSwapV2Library.sortTokens(input, output); IFXSwapV2Pair pair = IFXSwapV2Pair(FXSwapV2Library.pairFor(factory, input, output)); uint amountInput; uint amountOutput; { // scope to avoid stack too deep errors (uint reserve0, uint reserve1,) = pair.getReserves(); (uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0); amountInput = IERC20(input).balanceOf(address(pair)).sub(reserveInput); amountOutput = FXSwapV2Library.getAmountOut(amountInput, reserveInput, reserveOutput); } (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0)); address to = i < path.length - 2 ? FXSwapV2Library.pairFor(factory, output, path[i + 2]) : _to; pair.swap(amount0Out, amount1Out, to, new bytes(0)); } } function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external virtual override ensure(deadline) { TransferHelper.safeTransferFrom( path[0], msg.sender, FXSwapV2Library.pairFor(factory, path[0], path[1]), amountIn ); uint balanceBefore = IERC20(path[path.length - 1]).balanceOf(to); _swapSupportingFeeOnTransferTokens(path, to); require( IERC20(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin, 'FXSwapV2Router: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapExactFXForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external virtual override payable ensure(deadline) { require(path[0] == WFX, 'FXSwapV2Router: INVALID_PATH'); uint amountIn = msg.value; IWFX(WFX).deposit{value: amountIn}(); assert(IWFX(WFX).transfer(FXSwapV2Library.pairFor(factory, path[0], path[1]), amountIn)); uint balanceBefore = IERC20(path[path.length - 1]).balanceOf(to); _swapSupportingFeeOnTransferTokens(path, to); require( IERC20(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin, 'FXSwapV2Router: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapExactTokensForFXSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external virtual override ensure(deadline) { require(path[path.length - 1] == WFX, 'FXSwapV2Router: INVALID_PATH'); TransferHelper.safeTransferFrom( path[0], msg.sender, FXSwapV2Library.pairFor(factory, path[0], path[1]), amountIn ); _swapSupportingFeeOnTransferTokens(path, address(this)); uint amountOut = IERC20(WFX).balanceOf(address(this)); require(amountOut >= amountOutMin, 'FXSwapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); IWFX(WFX).withdraw(address(this), amountOut); TransferHelper.safeTransferFX(to, amountOut); } // **** LIBRARY FUNCTIONS **** function quote(uint amountA, uint reserveA, uint reserveB) public pure virtual override returns (uint amountB) { return FXSwapV2Library.quote(amountA, reserveA, reserveB); } function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) public pure virtual override returns (uint amountOut) { return FXSwapV2Library.getAmountOut(amountIn, reserveIn, reserveOut); } function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) public pure virtual override returns (uint amountIn) { return FXSwapV2Library.getAmountIn(amountOut, reserveIn, reserveOut); } function getAmountsOut(uint amountIn, address[] memory path) public view virtual override returns (uint[] memory amounts) { return FXSwapV2Library.getAmountsOut(factory, amountIn, path); } function getAmountsIn(uint amountOut, address[] memory path) public view virtual override returns (uint[] memory amounts) { return FXSwapV2Library.getAmountsIn(factory, amountOut, path); } }
contracts/FXSwap-Core/interfaces/IERC20.sol
pragma solidity >=0.5.0; interface IERC20 { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); function transfer(address to, uint value) external returns (bool); function transferFrom(address from, address to, uint value) external returns (bool); }
contracts/FXSwap-Core/interfaces/IFXSwapV2Callee.sol
pragma solidity >=0.5.0; interface IFXSwapV2Callee { function fxswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external; }
contracts/FXSwap-Core/interfaces/IFXSwapV2ERC20.sol
pragma solidity >=0.5.0; interface IFXSwapV2ERC20 { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); function transfer(address to, uint value) external returns (bool); function transferFrom(address from, address to, uint value) external returns (bool); function DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address owner) external view returns (uint); function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; }
contracts/FXSwap-Core/interfaces/IFXSwapV2Factory.sol
pragma solidity >=0.5.0; interface IFXSwapV2Factory { event PairCreated(address indexed token0, address indexed token1, address pair, uint); function feeTo() external view returns (address); function feeToSetter() external view returns (address); function getPair(address tokenA, address tokenB) external view returns (address pair); function allPairs(uint) external view returns (address pair); function allPairsLength() external view returns (uint); function createPair(address tokenA, address tokenB) external returns (address pair); function setFeeTo(address) external; function setFeeToSetter(address) external; }
contracts/FXSwap-Core/interfaces/IFXSwapV2Pair.sol
pragma solidity >=0.5.0; interface IFXSwapV2Pair { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); function transfer(address to, uint value) external returns (bool); function transferFrom(address from, address to, uint value) external returns (bool); function DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address owner) external view returns (uint); function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; event Mint(address indexed sender, uint amount0, uint amount1); event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); event Swap( address indexed sender, uint amount0In, uint amount1In, uint amount0Out, uint amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); function price0CumulativeLast() external view returns (uint); function price1CumulativeLast() external view returns (uint); function kLast() external view returns (uint); function mint(address to) external returns (uint liquidity); function burn(address to) external returns (uint amount0, uint amount1); function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; function skim(address to) external; function sync() external; function initialize(address, address) external; }
contracts/FXSwap-Lib/libraries/Babylonian.sol
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity >=0.4.0; // computes square roots using the babylonian method // https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method library Babylonian { // credit for this implementation goes to // https://github.com/abdk-consulting/abdk-libraries-solidity/blob/master/ABDKMath64x64.sol#L687 function sqrt(uint256 x) internal pure returns (uint256) { if (x == 0) return 0; // this block is equivalent to r = uint256(1) << (BitMath.mostSignificantBit(x) / 2); // however that code costs significantly more gas uint256 xx = x; uint256 r = 1; if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; } if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; } if (xx >= 0x100000000) { xx >>= 32; r <<= 16; } if (xx >= 0x10000) { xx >>= 16; r <<= 8; } if (xx >= 0x100) { xx >>= 8; r <<= 4; } if (xx >= 0x10) { xx >>= 4; r <<= 2; } if (xx >= 0x8) { r <<= 1; } r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; // Seven iterations should be enough uint256 r1 = x / r; return (r < r1 ? r : r1); } }
contracts/FXSwap-Lib/libraries/BitMath.sol
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity >=0.5.0; library BitMath { // returns the 0 indexed position of the most significant bit of the input x // s.t. x >= 2**msb and x < 2**(msb+1) function mostSignificantBit(uint256 x) internal pure returns (uint8 r) { require(x > 0, 'BitMath::mostSignificantBit: zero'); if (x >= 0x100000000000000000000000000000000) { x >>= 128; r += 128; } if (x >= 0x10000000000000000) { x >>= 64; r += 64; } if (x >= 0x100000000) { x >>= 32; r += 32; } if (x >= 0x10000) { x >>= 16; r += 16; } if (x >= 0x100) { x >>= 8; r += 8; } if (x >= 0x10) { x >>= 4; r += 4; } if (x >= 0x4) { x >>= 2; r += 2; } if (x >= 0x2) r += 1; } // returns the 0 indexed position of the least significant bit of the input x // s.t. (x & 2**lsb) != 0 and (x & (2**(lsb) - 1)) == 0) // i.e. the bit at the index is set and the mask of all lower bits is 0 function leastSignificantBit(uint256 x) internal pure returns (uint8 r) { require(x > 0, 'BitMath::leastSignificantBit: zero'); r = 255; if (x & uint128(-1) > 0) { r -= 128; } else { x >>= 128; } if (x & uint64(-1) > 0) { r -= 64; } else { x >>= 64; } if (x & uint32(-1) > 0) { r -= 32; } else { x >>= 32; } if (x & uint16(-1) > 0) { r -= 16; } else { x >>= 16; } if (x & uint8(-1) > 0) { r -= 8; } else { x >>= 8; } if (x & 0xf > 0) { r -= 4; } else { x >>= 4; } if (x & 0x3 > 0) { r -= 2; } else { x >>= 2; } if (x & 0x1 > 0) r -= 1; } }
contracts/FXSwap-Lib/libraries/FixedPoint.sol
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity >=0.4.0; import './FullMath.sol'; import './Babylonian.sol'; import './BitMath.sol'; // a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format)) library FixedPoint { // range: [0, 2**112 - 1] // resolution: 1 / 2**112 struct uq112x112 { uint224 _x; } // range: [0, 2**144 - 1] // resolution: 1 / 2**112 struct uq144x112 { uint256 _x; } uint8 public constant RESOLUTION = 112; uint256 public constant Q112 = 0x10000000000000000000000000000; // 2**112 uint256 private constant Q224 = 0x100000000000000000000000000000000000000000000000000000000; // 2**224 uint256 private constant LOWER_MASK = 0xffffffffffffffffffffffffffff; // decimal of UQ*x112 (lower 112 bits) // encode a uint112 as a UQ112x112 function encode(uint112 x) internal pure returns (uq112x112 memory) { return uq112x112(uint224(x) << RESOLUTION); } // encodes a uint144 as a UQ144x112 function encode144(uint144 x) internal pure returns (uq144x112 memory) { return uq144x112(uint256(x) << RESOLUTION); } // decode a UQ112x112 into a uint112 by truncating after the radix point function decode(uq112x112 memory self) internal pure returns (uint112) { return uint112(self._x >> RESOLUTION); } // decode a UQ144x112 into a uint144 by truncating after the radix point function decode144(uq144x112 memory self) internal pure returns (uint144) { return uint144(self._x >> RESOLUTION); } // multiply a UQ112x112 by a uint, returning a UQ144x112 // reverts on overflow function mul(uq112x112 memory self, uint256 y) internal pure returns (uq144x112 memory) { uint256 z = 0; require(y == 0 || (z = self._x * y) / y == self._x, 'FixedPoint::mul: overflow'); return uq144x112(z); } // multiply a UQ112x112 by an int and decode, returning an int // reverts on overflow function muli(uq112x112 memory self, int256 y) internal pure returns (int256) { uint256 z = FullMath.mulDiv(self._x, uint256(y < 0 ? -y : y), Q112); require(z < 2**255, 'FixedPoint::muli: overflow'); return y < 0 ? -int256(z) : int256(z); } // multiply a UQ112x112 by a UQ112x112, returning a UQ112x112 // lossy function muluq(uq112x112 memory self, uq112x112 memory other) internal pure returns (uq112x112 memory) { if (self._x == 0 || other._x == 0) { return uq112x112(0); } uint112 upper_self = uint112(self._x >> RESOLUTION); // * 2^0 uint112 lower_self = uint112(self._x & LOWER_MASK); // * 2^-112 uint112 upper_other = uint112(other._x >> RESOLUTION); // * 2^0 uint112 lower_other = uint112(other._x & LOWER_MASK); // * 2^-112 // partial products uint224 upper = uint224(upper_self) * upper_other; // * 2^0 uint224 lower = uint224(lower_self) * lower_other; // * 2^-224 uint224 uppers_lowero = uint224(upper_self) * lower_other; // * 2^-112 uint224 uppero_lowers = uint224(upper_other) * lower_self; // * 2^-112 // so the bit shift does not overflow require(upper <= uint112(-1), 'FixedPoint::muluq: upper overflow'); // this cannot exceed 256 bits, all values are 224 bits uint256 sum = uint256(upper << RESOLUTION) + uppers_lowero + uppero_lowers + (lower >> RESOLUTION); // so the cast does not overflow require(sum <= uint224(-1), 'FixedPoint::muluq: sum overflow'); return uq112x112(uint224(sum)); } // divide a UQ112x112 by a UQ112x112, returning a UQ112x112 function divuq(uq112x112 memory self, uq112x112 memory other) internal pure returns (uq112x112 memory) { require(other._x > 0, 'FixedPoint::divuq: division by zero'); if (self._x == other._x) { return uq112x112(uint224(Q112)); } if (self._x <= uint144(-1)) { uint256 value = (uint256(self._x) << RESOLUTION) / other._x; require(value <= uint224(-1), 'FixedPoint::divuq: overflow'); return uq112x112(uint224(value)); } uint256 result = FullMath.mulDiv(Q112, self._x, other._x); require(result <= uint224(-1), 'FixedPoint::divuq: overflow'); return uq112x112(uint224(result)); } // returns a UQ112x112 which represents the ratio of the numerator to the denominator // can be lossy function fraction(uint256 numerator, uint256 denominator) internal pure returns (uq112x112 memory) { require(denominator > 0, 'FixedPoint::fraction: division by zero'); if (numerator == 0) return FixedPoint.uq112x112(0); if (numerator <= uint144(-1)) { uint256 result = (numerator << RESOLUTION) / denominator; require(result <= uint224(-1), 'FixedPoint::fraction: overflow'); return uq112x112(uint224(result)); } else { uint256 result = FullMath.mulDiv(numerator, Q112, denominator); require(result <= uint224(-1), 'FixedPoint::fraction: overflow'); return uq112x112(uint224(result)); } } // take the reciprocal of a UQ112x112 // reverts on overflow // lossy function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) { require(self._x != 0, 'FixedPoint::reciprocal: reciprocal of zero'); require(self._x != 1, 'FixedPoint::reciprocal: overflow'); return uq112x112(uint224(Q224 / self._x)); } // square root of a UQ112x112 // lossy between 0/1 and 40 bits function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) { if (self._x <= uint144(-1)) { return uq112x112(uint224(Babylonian.sqrt(uint256(self._x) << 112))); } uint8 safeShiftBits = 255 - BitMath.mostSignificantBit(self._x); safeShiftBits -= safeShiftBits % 2; return uq112x112(uint224(Babylonian.sqrt(uint256(self._x) << safeShiftBits) << ((112 - safeShiftBits) / 2))); } }
contracts/FXSwap-Lib/libraries/FullMath.sol
// SPDX-License-Identifier: CC-BY-4.0 pragma solidity >=0.4.0; // taken from https://medium.com/coinmonks/math-in-solidity-part-3-percents-and-proportions-4db014e080b1 // license is CC-BY-4.0 library FullMath { function fullMul(uint256 x, uint256 y) internal pure returns (uint256 l, uint256 h) { uint256 mm = mulmod(x, y, uint256(-1)); l = x * y; h = mm - l; if (mm < l) h -= 1; } function fullDiv( uint256 l, uint256 h, uint256 d ) private pure returns (uint256) { uint256 pow2 = d & -d; d /= pow2; l /= pow2; l += h * ((-pow2) / pow2 + 1); uint256 r = 1; r *= 2 - d * r; r *= 2 - d * r; r *= 2 - d * r; r *= 2 - d * r; r *= 2 - d * r; r *= 2 - d * r; r *= 2 - d * r; r *= 2 - d * r; return l * r; } function mulDiv( uint256 x, uint256 y, uint256 d ) internal pure returns (uint256) { (uint256 l, uint256 h) = fullMul(x, y); uint256 mm = mulmod(x, y, d); if (mm > l) h -= 1; l -= mm; if (h == 0) return l / d; require(h < d, 'FullMath: FULLDIV_OVERFLOW'); return fullDiv(l, h, d); } }
contracts/FXSwap-Lib/libraries/TransferHelper.sol
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity >=0.6.0; // helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false library TransferHelper { function safeApprove( address token, address to, uint256 value ) internal { // bytes4(keccak256(bytes('approve(address,uint256)'))); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value)); require( success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper::safeApprove: approve failed' ); } function safeTransfer( address token, address to, uint256 value ) internal { // bytes4(keccak256(bytes('transfer(address,uint256)'))); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value)); require( success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper::safeTransfer: transfer failed' ); } function safeTransferFrom( address token, address from, address to, uint256 value ) internal { // bytes4(keccak256(bytes('transferFrom(address,address,uint256)'))); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value)); require( success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper::transferFrom: transferFrom failed' ); } function safeTransferFX(address to, uint256 value) internal { (bool success, ) = to.call{value: value}(new bytes(0)); require(success, 'TransferHelper::safeTransferFX: FX transfer failed'); } }
contracts/FXSwap-Periphery/FXSwapV2Migrator.sol
pragma solidity =0.6.6; import '../FXSwap-Lib/libraries/TransferHelper.sol'; import './interfaces/IFXSwapV2Migrator.sol'; import './interfaces/V1/IFXSwapV1Factory.sol'; import './interfaces/V1/IFXSwapV1Exchange.sol'; import './interfaces/IFXSwapV2Router01.sol'; import './interfaces/IERC20.sol'; contract FXSwapV2Migrator is IFXSwapV2Migrator { IFXSwapV1Factory immutable factoryV1; IFXSwapV2Router01 immutable router; constructor(address _factoryV1, address _router) public { factoryV1 = IFXSwapV1Factory(_factoryV1); router = IFXSwapV2Router01(_router); } // needs to accept FX from any v1 exchange and the router. ideally this could be enforced, as in the router, // but it's not possible because it requires a call to the v1 factory, which takes too much gas receive() external payable {} function migrate(address token, uint amountTokenMin, uint amountFXMin, address to, uint deadline) external override { IFXSwapV1Exchange exchangeV1 = IFXSwapV1Exchange(factoryV1.getExchange(token)); uint liquidityV1 = exchangeV1.balanceOf(msg.sender); require(exchangeV1.transferFrom(msg.sender, address(this), liquidityV1), 'TRANSFER_FROM_FAILED'); (uint amountFXV1, uint amountTokenV1) = exchangeV1.removeLiquidity(liquidityV1, 1, 1, uint(-1)); TransferHelper.safeApprove(token, address(router), amountTokenV1); (uint amountTokenV2, uint amountFXV2,) = router.addLiquidityFX{value: amountFXV1}( token, amountTokenV1, amountTokenMin, amountFXMin, to, deadline ); if (amountTokenV1 > amountTokenV2) { TransferHelper.safeApprove(token, address(router), 0); // be a good blockchain citizen, reset allowance to 0 TransferHelper.safeTransfer(token, msg.sender, amountTokenV1 - amountTokenV2); } else if (amountFXV1 > amountFXV2) { // addLiquidityFX guarantees that all of amountFXV1 or amountTokenV1 will be used, hence this else is safe TransferHelper.safeTransferFX(msg.sender, amountFXV1 - amountFXV2); } } }
contracts/FXSwap-Periphery/FXSwapV2Router01.sol
pragma solidity =0.6.6; import '../FXSwap-Core/interfaces/IFXSwapV2Factory.sol'; import '../FXSwap-Lib/libraries/TransferHelper.sol'; import './libraries/FXSwapV2Library.sol'; import './interfaces/IFXSwapV2Router01.sol'; import './interfaces/IERC20.sol'; import './interfaces/IWFX.sol'; contract FXSwapV2Router01 is IFXSwapV2Router01 { address public immutable override factory; address public immutable override WFX; modifier ensure(uint deadline) { require(deadline >= block.timestamp, 'FXSwapV2Router: EXPIRED'); _; } constructor(address _factory, address _WFX) public { factory = _factory; WFX = _WFX; } receive() external payable { assert(msg.sender == WFX); // only accept FX via fallback from the WFX contract } // **** ADD LIQUIDITY **** function _addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin ) private returns (uint amountA, uint amountB) { // create the pair if it doesn't exist yet if (IFXSwapV2Factory(factory).getPair(tokenA, tokenB) == address(0)) { IFXSwapV2Factory(factory).createPair(tokenA, tokenB); } (uint reserveA, uint reserveB) = FXSwapV2Library.getReserves(factory, tokenA, tokenB); if (reserveA == 0 && reserveB == 0) { (amountA, amountB) = (amountADesired, amountBDesired); } else { uint amountBOptimal = FXSwapV2Library.quote(amountADesired, reserveA, reserveB); if (amountBOptimal <= amountBDesired) { require(amountBOptimal >= amountBMin, 'FXSwapV2Router: INSUFFICIENT_B_AMOUNT'); (amountA, amountB) = (amountADesired, amountBOptimal); } else { uint amountAOptimal = FXSwapV2Library.quote(amountBDesired, reserveB, reserveA); assert(amountAOptimal <= amountADesired); require(amountAOptimal >= amountAMin, 'FXSwapV2Router: INSUFFICIENT_A_AMOUNT'); (amountA, amountB) = (amountAOptimal, amountBDesired); } } } function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external override ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) { (amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin); address pair = FXSwapV2Library.pairFor(factory, tokenA, tokenB); TransferHelper.safeTransferFrom(tokenA, msg.sender, pair, amountA); TransferHelper.safeTransferFrom(tokenB, msg.sender, pair, amountB); liquidity = IFXSwapV2Pair(pair).mint(to); } function addLiquidityFX( address token, uint amountTokenDesired, uint amountTokenMin, uint amountFXMin, address to, uint deadline ) external override payable ensure(deadline) returns (uint amountToken, uint amountFX, uint liquidity) { (amountToken, amountFX) = _addLiquidity( token, WFX, amountTokenDesired, msg.value, amountTokenMin, amountFXMin ); address pair = FXSwapV2Library.pairFor(factory, token, WFX); TransferHelper.safeTransferFrom(token, msg.sender, pair, amountToken); IWFX(WFX).deposit{value: amountFX}(); assert(IWFX(WFX).transfer(pair, amountFX)); liquidity = IFXSwapV2Pair(pair).mint(to); if (msg.value > amountFX) TransferHelper.safeTransferFX(msg.sender, msg.value - amountFX); // refund dust FX, if any } // **** REMOVE LIQUIDITY **** function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) public override ensure(deadline) returns (uint amountA, uint amountB) { address pair = FXSwapV2Library.pairFor(factory, tokenA, tokenB); IFXSwapV2Pair(pair).transferFrom(msg.sender, pair, liquidity); // send liquidity to pair (uint amount0, uint amount1) = IFXSwapV2Pair(pair).burn(to); (address token0,) = FXSwapV2Library.sortTokens(tokenA, tokenB); (amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0); require(amountA >= amountAMin, 'FXSwapV2Router: INSUFFICIENT_A_AMOUNT'); require(amountB >= amountBMin, 'FXSwapV2Router: INSUFFICIENT_B_AMOUNT'); } function removeLiquidityFX( address token, uint liquidity, uint amountTokenMin, uint amountFXMin, address to, uint deadline ) public override ensure(deadline) returns (uint amountToken, uint amountFX) { (amountToken, amountFX) = removeLiquidity( token, WFX, liquidity, amountTokenMin, amountFXMin, address(this), deadline ); TransferHelper.safeTransfer(token, to, amountToken); IWFX(WFX).withdraw(address(this), amountFX); TransferHelper.safeTransferFX(to, amountFX); } function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external override returns (uint amountA, uint amountB) { address pair = FXSwapV2Library.pairFor(factory, tokenA, tokenB); uint value = approveMax ? uint(-1) : liquidity; IFXSwapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s); (amountA, amountB) = removeLiquidity(tokenA, tokenB, liquidity, amountAMin, amountBMin, to, deadline); } function removeLiquidityFXWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountFXMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external override returns (uint amountToken, uint amountFX) { address pair = FXSwapV2Library.pairFor(factory, token, WFX); uint value = approveMax ? uint(-1) : liquidity; IFXSwapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s); (amountToken, amountFX) = removeLiquidityFX(token, liquidity, amountTokenMin, amountFXMin, to, deadline); } // **** SWAP **** // requires the initial amount to have already been sent to the first pair function _swap(uint[] memory amounts, address[] memory path, address _to) private { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = FXSwapV2Library.sortTokens(input, output); uint amountOut = amounts[i + 1]; (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0)); address to = i < path.length - 2 ? FXSwapV2Library.pairFor(factory, output, path[i + 2]) : _to; IFXSwapV2Pair(FXSwapV2Library.pairFor(factory, input, output)).swap(amount0Out, amount1Out, to, new bytes(0)); } } function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external override ensure(deadline) returns (uint[] memory amounts) { amounts = FXSwapV2Library.getAmountsOut(factory, amountIn, path); require(amounts[amounts.length - 1] >= amountOutMin, 'FXSwapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); TransferHelper.safeTransferFrom(path[0], msg.sender, FXSwapV2Library.pairFor(factory, path[0], path[1]), amounts[0]); _swap(amounts, path, to); } function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external override ensure(deadline) returns (uint[] memory amounts) { amounts = FXSwapV2Library.getAmountsIn(factory, amountOut, path); require(amounts[0] <= amountInMax, 'FXSwapV2Router: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom(path[0], msg.sender, FXSwapV2Library.pairFor(factory, path[0], path[1]), amounts[0]); _swap(amounts, path, to); } function swapExactFXForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external override payable ensure(deadline) returns (uint[] memory amounts) { require(path[0] == WFX, 'FXSwapV2Router: INVALID_PATH'); amounts = FXSwapV2Library.getAmountsOut(factory, msg.value, path); require(amounts[amounts.length - 1] >= amountOutMin, 'FXSwapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); IWFX(WFX).deposit{value: amounts[0]}(); assert(IWFX(WFX).transfer(FXSwapV2Library.pairFor(factory, path[0], path[1]), amounts[0])); _swap(amounts, path, to); } function swapTokensForExactFX(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external override ensure(deadline) returns (uint[] memory amounts) { require(path[path.length - 1] == WFX, 'FXSwapV2Router: INVALID_PATH'); amounts = FXSwapV2Library.getAmountsIn(factory, amountOut, path); require(amounts[0] <= amountInMax, 'FXSwapV2Router: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom(path[0], msg.sender, FXSwapV2Library.pairFor(factory, path[0], path[1]), amounts[0]); _swap(amounts, path, address(this)); IWFX(WFX).withdraw(address(this), amounts[amounts.length - 1]); TransferHelper.safeTransferFX(to, amounts[amounts.length - 1]); } function swapExactTokensForFX(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external override ensure(deadline) returns (uint[] memory amounts) { require(path[path.length - 1] == WFX, 'FXSwapV2Router: INVALID_PATH'); amounts = FXSwapV2Library.getAmountsOut(factory, amountIn, path); require(amounts[amounts.length - 1] >= amountOutMin, 'FXSwapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); TransferHelper.safeTransferFrom(path[0], msg.sender, FXSwapV2Library.pairFor(factory, path[0], path[1]), amounts[0]); _swap(amounts, path, address(this)); IWFX(WFX).withdraw(address(this), amounts[amounts.length - 1]); TransferHelper.safeTransferFX(to, amounts[amounts.length - 1]); } function swapFXForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external override payable ensure(deadline) returns (uint[] memory amounts) { require(path[0] == WFX, 'FXSwapV2Router: INVALID_PATH'); amounts = FXSwapV2Library.getAmountsIn(factory, amountOut, path); require(amounts[0] <= msg.value, 'FXSwapV2Router: EXCESSIVE_INPUT_AMOUNT'); IWFX(WFX).deposit{value: amounts[0]}(); assert(IWFX(WFX).transfer(FXSwapV2Library.pairFor(factory, path[0], path[1]), amounts[0])); _swap(amounts, path, to); if (msg.value > amounts[0]) TransferHelper.safeTransferFX(msg.sender, msg.value - amounts[0]); // refund dust FX, if any } function quote(uint amountA, uint reserveA, uint reserveB) public pure override returns (uint amountB) { return FXSwapV2Library.quote(amountA, reserveA, reserveB); } function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) public pure override returns (uint amountOut) { return FXSwapV2Library.getAmountOut(amountIn, reserveIn, reserveOut); } function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) public pure override returns (uint amountIn) { return FXSwapV2Library.getAmountOut(amountOut, reserveIn, reserveOut); } function getAmountsOut(uint amountIn, address[] memory path) public view override returns (uint[] memory amounts) { return FXSwapV2Library.getAmountsOut(factory, amountIn, path); } function getAmountsIn(uint amountOut, address[] memory path) public view override returns (uint[] memory amounts) { return FXSwapV2Library.getAmountsIn(factory, amountOut, path); } }
contracts/FXSwap-Periphery/examples/ExampleComputeLiquidityValue.sol
pragma solidity =0.6.6; import '../libraries/FXSwapV2LiquidityMathLibrary.sol'; contract ExampleComputeLiquidityValue { using SafeMath for uint256; address public immutable factory; constructor(address factory_) public { factory = factory_; } // see FXSwapV2LiquidityMathLibrary#getReservesAfterArbitrage function getReservesAfterArbitrage( address tokenA, address tokenB, uint256 truePriceTokenA, uint256 truePriceTokenB ) external view returns (uint256 reserveA, uint256 reserveB) { return FXSwapV2LiquidityMathLibrary.getReservesAfterArbitrage( factory, tokenA, tokenB, truePriceTokenA, truePriceTokenB ); } // see FXSwapV2LiquidityMathLibrary#getLiquidityValue function getLiquidityValue( address tokenA, address tokenB, uint256 liquidityAmount ) external view returns ( uint256 tokenAAmount, uint256 tokenBAmount ) { return FXSwapV2LiquidityMathLibrary.getLiquidityValue( factory, tokenA, tokenB, liquidityAmount ); } // see FXSwapV2LiquidityMathLibrary#getLiquidityValueAfterArbitrageToPrice function getLiquidityValueAfterArbitrageToPrice( address tokenA, address tokenB, uint256 truePriceTokenA, uint256 truePriceTokenB, uint256 liquidityAmount ) external view returns ( uint256 tokenAAmount, uint256 tokenBAmount ) { return FXSwapV2LiquidityMathLibrary.getLiquidityValueAfterArbitrageToPrice( factory, tokenA, tokenB, truePriceTokenA, truePriceTokenB, liquidityAmount ); } // test function to measure the gas cost of the above function function getGasCostOfGetLiquidityValueAfterArbitrageToPrice( address tokenA, address tokenB, uint256 truePriceTokenA, uint256 truePriceTokenB, uint256 liquidityAmount ) external view returns ( uint256 ) { uint gasBefore = gasleft(); FXSwapV2LiquidityMathLibrary.getLiquidityValueAfterArbitrageToPrice( factory, tokenA, tokenB, truePriceTokenA, truePriceTokenB, liquidityAmount ); uint gasAfter = gasleft(); return gasBefore - gasAfter; } }
contracts/FXSwap-Periphery/examples/ExampleFlashSwap.sol
pragma solidity =0.6.6; import '../../FXSwap-Core/interfaces/IFXSwapV2Callee.sol'; import '../libraries/FXSwapV2Library.sol'; import '../interfaces/V1/IFXSwapV1Factory.sol'; import '../interfaces/V1/IFXSwapV1Exchange.sol'; import '../interfaces/IFXSwapV2Router01.sol'; import '../interfaces/IERC20.sol'; import '../interfaces/IWFX.sol'; contract ExampleFlashSwap is IFXSwapV2Callee { IFXSwapV1Factory immutable factoryV1; address immutable factory; IWFX immutable WFX; constructor(address _factory, address _factoryV1, address router) public { factoryV1 = IFXSwapV1Factory(_factoryV1); factory = _factory; WFX = IWFX(IFXSwapV2Router01(router).WFX()); } // needs to accept FX from any V1 exchange and WFX. ideally this could be enforced, as in the router, // but it's not possible because it requires a call to the v1 factory, which takes too much gas receive() external payable {} // gets tokens/WFX via a V2 flash swap, swaps for the FX/tokens on V1, repays V2, and keeps the rest! function fxswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external override { address[] memory path = new address[](2); uint amountToken; uint amountFX; { // scope for token{0,1}, avoids stack too deep errors address token0 = IFXSwapV2Pair(msg.sender).token0(); address token1 = IFXSwapV2Pair(msg.sender).token1(); assert(msg.sender == FXSwapV2Library.pairFor(factory, token0, token1)); // ensure that msg.sender is actually a V2 pair assert(amount0 == 0 || amount1 == 0); // this strategy is unidirectional path[0] = amount0 == 0 ? token0 : token1; path[1] = amount0 == 0 ? token1 : token0; amountToken = token0 == address(WFX) ? amount1 : amount0; amountFX = token0 == address(WFX) ? amount0 : amount1; } assert(path[0] == address(WFX) || path[1] == address(WFX)); // this strategy only works with a V2 WFX pair IERC20 token = IERC20(path[0] == address(WFX) ? path[1] : path[0]); IFXSwapV1Exchange exchangeV1 = IFXSwapV1Exchange(factoryV1.getExchange(address(token))); // get V1 exchange if (amountToken > 0) { (uint minFX) = abi.decode(data, (uint)); // slippage parameter for V1, passed in by caller token.approve(address(exchangeV1), amountToken); uint amountReceived = exchangeV1.tokenToFXSwapInput(amountToken, minFX, uint(-1)); uint amountRequired = FXSwapV2Library.getAmountsIn(factory, amountToken, path)[0]; assert(amountReceived > amountRequired); // fail if we didn't get enough FX back to repay our flash loan WFX.deposit{value: amountRequired}(); assert(WFX.transfer(msg.sender, amountRequired)); // return WFX to V2 pair (bool success,) = sender.call{value: amountReceived - amountRequired}(new bytes(0)); // keep the rest! (FX) assert(success); } else { (uint minTokens) = abi.decode(data, (uint)); // slippage parameter for V1, passed in by caller WFX.withdraw(msg.sender, amountFX); uint amountReceived = exchangeV1.fxToTokenSwapInput{value: amountFX}(minTokens, uint(-1)); uint amountRequired = FXSwapV2Library.getAmountsIn(factory, amountFX, path)[0]; assert(amountReceived > amountRequired); // fail if we didn't get enough tokens back to repay our flash loan assert(token.transfer(msg.sender, amountRequired)); // return tokens to V2 pair assert(token.transfer(sender, amountReceived - amountRequired)); // keep the rest! (tokens) } } }
contracts/FXSwap-Periphery/examples/ExampleOracleSimple.sol
pragma solidity =0.6.6; import '../../FXSwap-Core/interfaces/IFXSwapV2Factory.sol'; import '../../FXSwap-Core/interfaces/IFXSwapV2Pair.sol'; import '../../FXSwap-Lib/libraries/FixedPoint.sol'; import '../libraries/FXSwapV2OracleLibrary.sol'; import '../libraries/FXSwapV2Library.sol'; // fixed window oracle that recomputes the average price for the entire period once every period // note that the price average is only guaranteed to be over at least 1 period, but may be over a longer period contract ExampleOracleSimple { using FixedPoint for *; uint public constant PERIOD = 24 hours; IFXSwapV2Pair immutable pair; address public immutable token0; address public immutable token1; uint public price0CumulativeLast; uint public price1CumulativeLast; uint32 public blockTimestampLast; FixedPoint.uq112x112 public price0Average; FixedPoint.uq112x112 public price1Average; constructor(address factory, address tokenA, address tokenB) public { IFXSwapV2Pair _pair = IFXSwapV2Pair(FXSwapV2Library.pairFor(factory, tokenA, tokenB)); pair = _pair; token0 = _pair.token0(); token1 = _pair.token1(); price0CumulativeLast = _pair.price0CumulativeLast(); // fetch the current accumulated price value (1 / 0) price1CumulativeLast = _pair.price1CumulativeLast(); // fetch the current accumulated price value (0 / 1) uint112 reserve0; uint112 reserve1; (reserve0, reserve1, blockTimestampLast) = _pair.getReserves(); require(reserve0 != 0 && reserve1 != 0, 'ExampleOracleSimple: NO_RESERVES'); // ensure that there's liquidity in the pair } function update() external { (uint price0Cumulative, uint price1Cumulative, uint32 blockTimestamp) = FXSwapV2OracleLibrary.currentCumulativePrices(address(pair)); uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired // ensure that at least one full period has passed since the last update require(timeElapsed >= PERIOD, 'ExampleOracleSimple: PERIOD_NOT_ELAPSED'); // overflow is desired, casting never truncates // cumulative price is in (uq112x112 price * seconds) units so we simply wrap it after division by time elapsed price0Average = FixedPoint.uq112x112(uint224((price0Cumulative - price0CumulativeLast) / timeElapsed)); price1Average = FixedPoint.uq112x112(uint224((price1Cumulative - price1CumulativeLast) / timeElapsed)); price0CumulativeLast = price0Cumulative; price1CumulativeLast = price1Cumulative; blockTimestampLast = blockTimestamp; } // note this will always return 0 before update has been called successfully for the first time. function consult(address token, uint amountIn) external view returns (uint amountOut) { if (token == token0) { amountOut = price0Average.mul(amountIn).decode144(); } else { require(token == token1, 'ExampleOracleSimple: INVALID_TOKEN'); amountOut = price1Average.mul(amountIn).decode144(); } } }
contracts/FXSwap-Periphery/examples/ExampleSlidingWindowOracle.sol
pragma solidity =0.6.6; import '../../FXSwap-Core/interfaces/IFXSwapV2Factory.sol'; import '../../FXSwap-Core/interfaces/IFXSwapV2Pair.sol'; import '../../FXSwap-Lib/libraries/FixedPoint.sol'; import '../libraries/SafeMath.sol'; import '../libraries/FXSwapV2Library.sol'; import '../libraries/FXSwapV2OracleLibrary.sol'; // sliding window oracle that uses observations collected over a window to provide moving price averages in the past // `windowSize` with a precision of `windowSize / granularity` // note this is a singleton oracle and only needs to be deployed once per desired parameters, which // differs from the simple oracle which must be deployed once per pair. contract ExampleSlidingWindowOracle { using FixedPoint for *; using SafeMath for uint; struct Observation { uint timestamp; uint price0Cumulative; uint price1Cumulative; } address public immutable factory; // the desired amount of time over which the moving average should be computed, e.g. 24 hours uint public immutable windowSize; // the number of observations stored for each pair, i.e. how many price observations are stored for the window. // as granularity increases from 1, more frequent updates are needed, but moving averages become more precise. // averages are computed over intervals with sizes in the range: // [windowSize - (windowSize / granularity) * 2, windowSize] // e.g. if the window size is 24 hours, and the granularity is 24, the oracle will return the average price for // the period: // [now - [22 hours, 24 hours], now] uint8 public immutable granularity; // this is redundant with granularity and windowSize, but stored for gas savings & informational purposes. uint public immutable periodSize; // mapping from pair address to a list of price observations of that pair mapping(address => Observation[]) public pairObservations; constructor(address factory_, uint windowSize_, uint8 granularity_) public { require(granularity_ > 1, 'SlidingWindowOracle: GRANULARITY'); require( (periodSize = windowSize_ / granularity_) * granularity_ == windowSize_, 'SlidingWindowOracle: WINDOW_NOT_EVENLY_DIVISIBLE' ); factory = factory_; windowSize = windowSize_; granularity = granularity_; } // returns the index of the observation corresponding to the given timestamp function observationIndexOf(uint timestamp) public view returns (uint8 index) { uint epochPeriod = timestamp / periodSize; return uint8(epochPeriod % granularity); } // returns the observation from the oldest epoch (at the beginning of the window) relative to the current time function getFirstObservationInWindow(address pair) private view returns (Observation storage firstObservation) { uint8 observationIndex = observationIndexOf(block.timestamp); // no overflow issue. if observationIndex + 1 overflows, result is still zero. uint8 firstObservationIndex = (observationIndex + 1) % granularity; firstObservation = pairObservations[pair][firstObservationIndex]; } // update the cumulative price for the observation at the current timestamp. each observation is updated at most // once per epoch period. function update(address tokenA, address tokenB) external { address pair = FXSwapV2Library.pairFor(factory, tokenA, tokenB); // populate the array with empty observations (first call only) for (uint i = pairObservations[pair].length; i < granularity; i++) { pairObservations[pair].push(); } // get the observation for the current period uint8 observationIndex = observationIndexOf(block.timestamp); Observation storage observation = pairObservations[pair][observationIndex]; // we only want to commit updates once per period (i.e. windowSize / granularity) uint timeElapsed = block.timestamp - observation.timestamp; if (timeElapsed > periodSize) { (uint price0Cumulative, uint price1Cumulative,) = FXSwapV2OracleLibrary.currentCumulativePrices(pair); observation.timestamp = block.timestamp; observation.price0Cumulative = price0Cumulative; observation.price1Cumulative = price1Cumulative; } } // given the cumulative prices of the start and end of a period, and the length of the period, compute the average // price in terms of how much amount out is received for the amount in function computeAmountOut( uint priceCumulativeStart, uint priceCumulativeEnd, uint timeElapsed, uint amountIn ) private pure returns (uint amountOut) { // overflow is desired. FixedPoint.uq112x112 memory priceAverage = FixedPoint.uq112x112( uint224((priceCumulativeEnd - priceCumulativeStart) / timeElapsed) ); amountOut = priceAverage.mul(amountIn).decode144(); } // returns the amount out corresponding to the amount in for a given token using the moving average over the time // range [now - [windowSize, windowSize - periodSize * 2], now] // update must have been called for the bucket corresponding to timestamp `now - windowSize` function consult(address tokenIn, uint amountIn, address tokenOut) external view returns (uint amountOut) { address pair = FXSwapV2Library.pairFor(factory, tokenIn, tokenOut); Observation storage firstObservation = getFirstObservationInWindow(pair); uint timeElapsed = block.timestamp - firstObservation.timestamp; require(timeElapsed <= windowSize, 'SlidingWindowOracle: MISSING_HISTORICAL_OBSERVATION'); // should never happen. require(timeElapsed >= windowSize - periodSize * 2, 'SlidingWindowOracle: UNEXPECTED_TIME_ELAPSED'); (uint price0Cumulative, uint price1Cumulative,) = FXSwapV2OracleLibrary.currentCumulativePrices(pair); (address token0,) = FXSwapV2Library.sortTokens(tokenIn, tokenOut); if (token0 == tokenIn) { return computeAmountOut(firstObservation.price0Cumulative, price0Cumulative, timeElapsed, amountIn); } else { return computeAmountOut(firstObservation.price1Cumulative, price1Cumulative, timeElapsed, amountIn); } } }
contracts/FXSwap-Periphery/examples/ExampleSwapToPrice.sol
pragma solidity =0.6.6; import '../../FXSwap-Core/interfaces/IFXSwapV2Pair.sol'; import '../../FXSwap-Lib/libraries/Babylonian.sol'; import '../../FXSwap-Lib/libraries/TransferHelper.sol'; import '../libraries/FXSwapV2LiquidityMathLibrary.sol'; import '../interfaces/IERC20.sol'; import '../interfaces/IFXSwapV2Router01.sol'; import '../libraries/SafeMath.sol'; import '../libraries/FXSwapV2Library.sol'; contract ExampleSwapToPrice { using SafeMath for uint256; IFXSwapV2Router01 public immutable router; address public immutable factory; constructor(address factory_, IFXSwapV2Router01 router_) public { factory = factory_; router = router_; } // swaps an amount of either token such that the trade is profit-maximizing, given an external true price // true price is expressed in the ratio of token A to token B // caller must approve this contract to spend whichever token is intended to be swapped function swapToPrice( address tokenA, address tokenB, uint256 truePriceTokenA, uint256 truePriceTokenB, uint256 maxSpendTokenA, uint256 maxSpendTokenB, address to, uint256 deadline ) public { // true price is expressed as a ratio, so both values must be non-zero require(truePriceTokenA != 0 && truePriceTokenB != 0, "ExampleSwapToPrice: ZERO_PRICE"); // caller can specify 0 for either if they wish to swap in only one direction, but not both require(maxSpendTokenA != 0 || maxSpendTokenB != 0, "ExampleSwapToPrice: ZERO_SPEND"); bool aToB; uint256 amountIn; { (uint256 reserveA, uint256 reserveB) = FXSwapV2Library.getReserves(factory, tokenA, tokenB); (aToB, amountIn) = FXSwapV2LiquidityMathLibrary.computeProfitMaximizingTrade( truePriceTokenA, truePriceTokenB, reserveA, reserveB ); } require(amountIn > 0, 'ExampleSwapToPrice: ZERO_AMOUNT_IN'); // spend up to the allowance of the token in uint256 maxSpend = aToB ? maxSpendTokenA : maxSpendTokenB; if (amountIn > maxSpend) { amountIn = maxSpend; } address tokenIn = aToB ? tokenA : tokenB; address tokenOut = aToB ? tokenB : tokenA; TransferHelper.safeTransferFrom(tokenIn, msg.sender, address(this), amountIn); TransferHelper.safeApprove(tokenIn, address(router), amountIn); address[] memory path = new address[](2); path[0] = tokenIn; path[1] = tokenOut; router.swapExactTokensForTokens( amountIn, 0, // amountOutMin: we can skip computing this number because the math is tested path, to, deadline ); } }
contracts/FXSwap-Periphery/interfaces/IERC20.sol
pragma solidity >=0.5.0; interface IERC20 { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); function transfer(address to, uint value) external returns (bool); function transferFrom(address from, address to, uint value) external returns (bool); }
contracts/FXSwap-Periphery/interfaces/IFXSwapV2Migrator.sol
pragma solidity >=0.5.0; interface IFXSwapV2Migrator { function migrate(address token, uint amountTokenMin, uint amountFXMin, address to, uint deadline) external; }
contracts/FXSwap-Periphery/interfaces/IFXSwapV2Router01.sol
pragma solidity >=0.6.2; interface IFXSwapV2Router01 { function factory() external pure returns (address); function WFX() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB, uint liquidity); function addLiquidityFX( address token, uint amountTokenDesired, uint amountTokenMin, uint amountFXMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountFX, uint liquidity); function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB); function removeLiquidityFX( address token, uint liquidity, uint amountTokenMin, uint amountFXMin, address to, uint deadline ) external returns (uint amountToken, uint amountFX); function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountA, uint amountB); function removeLiquidityFXWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountFXMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountToken, uint amountFX); function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapExactFXForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function swapTokensForExactFX(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapExactTokensForFX(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapFXForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); }
contracts/FXSwap-Periphery/interfaces/IFXSwapV2Router02.sol
pragma solidity >=0.6.2; import './IFXSwapV2Router01.sol'; interface IFXSwapV2Router02 is IFXSwapV2Router01 { function removeLiquidityFXSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountFXMin, address to, uint deadline ) external returns (uint amountFX); function removeLiquidityFXWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountFXMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountFX); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function swapExactFXForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external payable; function swapExactTokensForFXSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; }
contracts/FXSwap-Periphery/interfaces/IWFX.sol
pragma solidity >=0.5.0; interface IWFX { function deposit() external payable; function transfer(address to, uint value) external returns (bool); function withdraw(address payable to, uint256 value) external; }
contracts/FXSwap-Periphery/interfaces/V1/IFXSwapV1Exchange.sol
pragma solidity >=0.5.0; interface IFXSwapV1Exchange { function balanceOf(address owner) external view returns (uint); function transferFrom(address from, address to, uint value) external returns (bool); function removeLiquidity(uint, uint, uint, uint) external returns (uint, uint); function tokenToFXSwapInput(uint, uint, uint) external returns (uint); function fxToTokenSwapInput(uint, uint) external payable returns (uint); }
contracts/FXSwap-Periphery/interfaces/V1/IFXSwapV1Factory.sol
pragma solidity >=0.5.0; interface IFXSwapV1Factory { function getExchange(address) external view returns (address); }
contracts/FXSwap-Periphery/libraries/FXSwapV2Library.sol
pragma solidity >=0.5.0; import '../../FXSwap-Core/interfaces/IFXSwapV2Pair.sol'; import "./SafeMath.sol"; library FXSwapV2Library { using SafeMath for uint; // returns sorted token addresses, used to handle return values from pairs sorted in this order function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { require(tokenA != tokenB, 'FXSwapV2Library: IDENTICAL_ADDRESSES'); (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); require(token0 != address(0), 'FXSwapV2Library: ZERO_ADDRESS'); } // calculates the CREATE2 address for a pair without making any external calls function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) { (address token0, address token1) = sortTokens(tokenA, tokenB); pair = address(uint(keccak256(abi.encodePacked( hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), hex'89bbd161b7f9309df13e388d6b1f71f5ff07259b5149560e726a4df10971bceb' // init code hash )))); } // fetches and sorts the reserves for a pair function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) { (address token0,) = sortTokens(tokenA, tokenB); (uint reserve0, uint reserve1,) = IFXSwapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves(); (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); } // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) { require(amountA > 0, 'FXSwapV2Library: INSUFFICIENT_AMOUNT'); require(reserveA > 0 && reserveB > 0, 'FXSwapV2Library: INSUFFICIENT_LIQUIDITY'); amountB = amountA.mul(reserveB) / reserveA; } // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) { require(amountIn > 0, 'FXSwapV2Library: INSUFFICIENT_INPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'FXSwapV2Library: INSUFFICIENT_LIQUIDITY'); uint amountInWithFee = amountIn.mul(997); uint numerator = amountInWithFee.mul(reserveOut); uint denominator = reserveIn.mul(1000).add(amountInWithFee); amountOut = numerator / denominator; } // given an output amount of an asset and pair reserves, returns a required input amount of the other asset function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) { require(amountOut > 0, 'FXSwapV2Library: INSUFFICIENT_OUTPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'FXSwapV2Library: INSUFFICIENT_LIQUIDITY'); uint numerator = reserveIn.mul(amountOut).mul(1000); uint denominator = reserveOut.sub(amountOut).mul(997); amountIn = (numerator / denominator).add(1); } // performs chained getAmountOut calculations on any number of pairs function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'FXSwapV2Library: INVALID_PATH'); amounts = new uint[](path.length); amounts[0] = amountIn; for (uint i; i < path.length - 1; i++) { (uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]); amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut); } } // performs chained getAmountIn calculations on any number of pairs function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'FXSwapV2Library: INVALID_PATH'); amounts = new uint[](path.length); amounts[amounts.length - 1] = amountOut; for (uint i = path.length - 1; i > 0; i--) { (uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]); amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut); } } }
contracts/FXSwap-Periphery/libraries/FXSwapV2LiquidityMathLibrary.sol
pragma solidity >=0.5.0; import '../../FXSwap-Core/interfaces/IFXSwapV2Pair.sol'; import '../../FXSwap-Core/interfaces/IFXSwapV2Factory.sol'; import '../../FXSwap-Lib/libraries/Babylonian.sol'; import '../../FXSwap-Lib/libraries/FullMath.sol'; import './SafeMath.sol'; import './FXSwapV2Library.sol'; // library containing some math for dealing with the liquidity shares of a pair, e.g. computing their exact value // in terms of the underlying tokens library FXSwapV2LiquidityMathLibrary { using SafeMath for uint256; // computes the direction and magnitude of the profit-maximizing trade function computeProfitMaximizingTrade( uint256 truePriceTokenA, uint256 truePriceTokenB, uint256 reserveA, uint256 reserveB ) pure internal returns (bool aToB, uint256 amountIn) { aToB = FullMath.mulDiv(reserveA, truePriceTokenB, reserveB) < truePriceTokenA; uint256 invariant = reserveA.mul(reserveB); uint256 leftSide = Babylonian.sqrt( FullMath.mulDiv( invariant.mul(1000), aToB ? truePriceTokenA : truePriceTokenB, (aToB ? truePriceTokenB : truePriceTokenA).mul(997) ) ); uint256 rightSide = (aToB ? reserveA.mul(1000) : reserveB.mul(1000)) / 997; if (leftSide < rightSide) return (false, 0); // compute the amount that must be sent to move the price to the profit-maximizing price amountIn = leftSide.sub(rightSide); } // gets the reserves after an arbitrage moves the price to the profit-maximizing ratio given an externally observed true price function getReservesAfterArbitrage( address factory, address tokenA, address tokenB, uint256 truePriceTokenA, uint256 truePriceTokenB ) view internal returns (uint256 reserveA, uint256 reserveB) { // first get reserves before the swap (reserveA, reserveB) = FXSwapV2Library.getReserves(factory, tokenA, tokenB); require(reserveA > 0 && reserveB > 0, 'FXSwapV2ArbitrageLibrary: ZERO_PAIR_RESERVES'); // then compute how much to swap to arb to the true price (bool aToB, uint256 amountIn) = computeProfitMaximizingTrade(truePriceTokenA, truePriceTokenB, reserveA, reserveB); if (amountIn == 0) { return (reserveA, reserveB); } // now affect the trade to the reserves if (aToB) { uint amountOut = FXSwapV2Library.getAmountOut(amountIn, reserveA, reserveB); reserveA += amountIn; reserveB -= amountOut; } else { uint amountOut = FXSwapV2Library.getAmountOut(amountIn, reserveB, reserveA); reserveB += amountIn; reserveA -= amountOut; } } // computes liquidity value given all the parameters of the pair function computeLiquidityValue( uint256 reservesA, uint256 reservesB, uint256 totalSupply, uint256 liquidityAmount, bool feeOn, uint kLast ) internal pure returns (uint256 tokenAAmount, uint256 tokenBAmount) { if (feeOn && kLast > 0) { uint rootK = Babylonian.sqrt(reservesA.mul(reservesB)); uint rootKLast = Babylonian.sqrt(kLast); if (rootK > rootKLast) { uint numerator1 = totalSupply; uint numerator2 = rootK.sub(rootKLast); uint denominator = rootK.mul(5).add(rootKLast); uint feeLiquidity = FullMath.mulDiv(numerator1, numerator2, denominator); totalSupply = totalSupply.add(feeLiquidity); } } return (reservesA.mul(liquidityAmount) / totalSupply, reservesB.mul(liquidityAmount) / totalSupply); } // get all current parameters from the pair and compute value of a liquidity amount // **note this is subject to manipulation, e.g. sandwich attacks**. prefer passing a manipulation resistant price to // #getLiquidityValueAfterArbitrageToPrice function getLiquidityValue( address factory, address tokenA, address tokenB, uint256 liquidityAmount ) internal view returns (uint256 tokenAAmount, uint256 tokenBAmount) { (uint256 reservesA, uint256 reservesB) = FXSwapV2Library.getReserves(factory, tokenA, tokenB); IFXSwapV2Pair pair = IFXSwapV2Pair(FXSwapV2Library.pairFor(factory, tokenA, tokenB)); bool feeOn = IFXSwapV2Factory(factory).feeTo() != address(0); uint kLast = feeOn ? pair.kLast() : 0; uint totalSupply = pair.totalSupply(); return computeLiquidityValue(reservesA, reservesB, totalSupply, liquidityAmount, feeOn, kLast); } // given two tokens, tokenA and tokenB, and their "true price", i.e. the observed ratio of value of token A to token B, // and a liquidity amount, returns the value of the liquidity in terms of tokenA and tokenB function getLiquidityValueAfterArbitrageToPrice( address factory, address tokenA, address tokenB, uint256 truePriceTokenA, uint256 truePriceTokenB, uint256 liquidityAmount ) internal view returns ( uint256 tokenAAmount, uint256 tokenBAmount ) { bool feeOn = IFXSwapV2Factory(factory).feeTo() != address(0); IFXSwapV2Pair pair = IFXSwapV2Pair(FXSwapV2Library.pairFor(factory, tokenA, tokenB)); uint kLast = feeOn ? pair.kLast() : 0; uint totalSupply = pair.totalSupply(); // this also checks that totalSupply > 0 require(totalSupply >= liquidityAmount && liquidityAmount > 0, 'ComputeLiquidityValue: LIQUIDITY_AMOUNT'); (uint reservesA, uint reservesB) = getReservesAfterArbitrage(factory, tokenA, tokenB, truePriceTokenA, truePriceTokenB); return computeLiquidityValue(reservesA, reservesB, totalSupply, liquidityAmount, feeOn, kLast); } }
contracts/FXSwap-Periphery/libraries/FXSwapV2OracleLibrary.sol
pragma solidity >=0.5.0; import '../../FXSwap-Core/interfaces/IFXSwapV2Pair.sol'; import '../../FXSwap-Lib/libraries/FixedPoint.sol'; // library with helper methods for oracles that are concerned with computing average prices library FXSwapV2OracleLibrary { using FixedPoint for *; // helper function that returns the current block timestamp within the range of uint32, i.e. [0, 2**32 - 1] function currentBlockTimestamp() internal view returns (uint32) { return uint32(block.timestamp % 2 ** 32); } // produces the cumulative price using counterfactuals to save gas and avoid a call to sync. function currentCumulativePrices( address pair ) internal view returns (uint price0Cumulative, uint price1Cumulative, uint32 blockTimestamp) { blockTimestamp = currentBlockTimestamp(); price0Cumulative = IFXSwapV2Pair(pair).price0CumulativeLast(); price1Cumulative = IFXSwapV2Pair(pair).price1CumulativeLast(); // if time has elapsed since the last update on the pair, mock the accumulated price values (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = IFXSwapV2Pair(pair).getReserves(); if (blockTimestampLast != blockTimestamp) { // subtraction overflow is desired uint32 timeElapsed = blockTimestamp - blockTimestampLast; // addition overflow is desired // counterfactual price0Cumulative += uint(FixedPoint.fraction(reserve1, reserve0)._x) * timeElapsed; // counterfactual price1Cumulative += uint(FixedPoint.fraction(reserve0, reserve1)._x) * timeElapsed; } } }
contracts/FXSwap-Periphery/libraries/SafeMath.sol
pragma solidity =0.6.6; // a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math) library SafeMath { function add(uint x, uint y) internal pure returns (uint z) { require((z = x + y) >= x, 'ds-math-add-overflow'); } function sub(uint x, uint y) internal pure returns (uint z) { require((z = x - y) <= x, 'ds-math-sub-underflow'); } function mul(uint x, uint y) internal pure returns (uint z) { require(y == 0 || (z = x * y) / y == x, 'ds-math-mul-overflow'); } }
contracts/FXSwap-Periphery/test/DeflatingERC20.sol
pragma solidity =0.6.6; import '../libraries/SafeMath.sol'; contract DeflatingERC20 { using SafeMath for uint; string public constant name = 'Deflating Test Token'; string public constant symbol = 'DTT'; uint8 public constant decimals = 18; uint public totalSupply; mapping(address => uint) public balanceOf; mapping(address => mapping(address => uint)) public allowance; bytes32 public DOMAIN_SEPARATOR; // keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9; mapping(address => uint) public nonces; event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); constructor(uint _totalSupply) public { uint chainId; assembly { chainId := chainid() } DOMAIN_SEPARATOR = keccak256( abi.encode( keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'), keccak256(bytes(name)), keccak256(bytes('1')), chainId, address(this) ) ); _mint(msg.sender, _totalSupply); } function _mint(address to, uint value) internal { totalSupply = totalSupply.add(value); balanceOf[to] = balanceOf[to].add(value); emit Transfer(address(0), to, value); } function _burn(address from, uint value) internal { balanceOf[from] = balanceOf[from].sub(value); totalSupply = totalSupply.sub(value); emit Transfer(from, address(0), value); } function _approve(address owner, address spender, uint value) private { allowance[owner][spender] = value; emit Approval(owner, spender, value); } function _transfer(address from, address to, uint value) private { uint burnAmount = value / 100; _burn(from, burnAmount); uint transferAmount = value.sub(burnAmount); balanceOf[from] = balanceOf[from].sub(transferAmount); balanceOf[to] = balanceOf[to].add(transferAmount); emit Transfer(from, to, transferAmount); } function approve(address spender, uint value) external returns (bool) { _approve(msg.sender, spender, value); return true; } function transfer(address to, uint value) external returns (bool) { _transfer(msg.sender, to, value); return true; } function transferFrom(address from, address to, uint value) external returns (bool) { if (allowance[from][msg.sender] != uint(-1)) { allowance[from][msg.sender] = allowance[from][msg.sender].sub(value); } _transfer(from, to, value); return true; } function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external { require(deadline >= block.timestamp, 'EXPIRED'); bytes32 digest = keccak256( abi.encodePacked( '\x19\x01', DOMAIN_SEPARATOR, keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline)) ) ); address recoveredAddress = ecrecover(digest, v, r, s); require(recoveredAddress != address(0) && recoveredAddress == owner, 'INVALID_SIGNATURE'); _approve(owner, spender, value); } }
contracts/FXSwap-Periphery/test/ERC20.sol
pragma solidity =0.6.6; import '../libraries/SafeMath.sol'; contract ERC20 { using SafeMath for uint; string public constant name = 'Test Token'; string public constant symbol = 'TT'; uint8 public constant decimals = 18; uint public totalSupply; mapping(address => uint) public balanceOf; mapping(address => mapping(address => uint)) public allowance; bytes32 public DOMAIN_SEPARATOR; // keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9; mapping(address => uint) public nonces; event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); constructor(uint _totalSupply) public { uint chainId; assembly { chainId := chainid() } DOMAIN_SEPARATOR = keccak256( abi.encode( keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'), keccak256(bytes(name)), keccak256(bytes('1')), chainId, address(this) ) ); _mint(msg.sender, _totalSupply); } function _mint(address to, uint value) internal { totalSupply = totalSupply.add(value); balanceOf[to] = balanceOf[to].add(value); emit Transfer(address(0), to, value); } function _burn(address from, uint value) internal { balanceOf[from] = balanceOf[from].sub(value); totalSupply = totalSupply.sub(value); emit Transfer(from, address(0), value); } function _approve(address owner, address spender, uint value) private { allowance[owner][spender] = value; emit Approval(owner, spender, value); } function _transfer(address from, address to, uint value) private { balanceOf[from] = balanceOf[from].sub(value); balanceOf[to] = balanceOf[to].add(value); emit Transfer(from, to, value); } function approve(address spender, uint value) external returns (bool) { _approve(msg.sender, spender, value); return true; } function transfer(address to, uint value) external returns (bool) { _transfer(msg.sender, to, value); return true; } function transferFrom(address from, address to, uint value) external returns (bool) { if (allowance[from][msg.sender] != uint(-1)) { allowance[from][msg.sender] = allowance[from][msg.sender].sub(value); } _transfer(from, to, value); return true; } function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external { require(deadline >= block.timestamp, 'EXPIRED'); bytes32 digest = keccak256( abi.encodePacked( '\x19\x01', DOMAIN_SEPARATOR, keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline)) ) ); address recoveredAddress = ecrecover(digest, v, r, s); require(recoveredAddress != address(0) && recoveredAddress == owner, 'INVALID_SIGNATURE'); _approve(owner, spender, value); } }
contracts/FXSwap-Periphery/test/RouterEventEmitter.sol
pragma solidity =0.6.6; import '../interfaces/IFXSwapV2Router01.sol'; contract RouterEventEmitter { event Amounts(uint[] amounts); receive() external payable {} function swapExactTokensForTokens( address router, uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external { (bool success, bytes memory returnData) = router.delegatecall(abi.encodeWithSelector( IFXSwapV2Router01(router).swapExactTokensForTokens.selector, amountIn, amountOutMin, path, to, deadline )); assert(success); emit Amounts(abi.decode(returnData, (uint[]))); } function swapTokensForExactTokens( address router, uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external { (bool success, bytes memory returnData) = router.delegatecall(abi.encodeWithSelector( IFXSwapV2Router01(router).swapTokensForExactTokens.selector, amountOut, amountInMax, path, to, deadline )); assert(success); emit Amounts(abi.decode(returnData, (uint[]))); } function swapExactFXForTokens( address router, uint amountOutMin, address[] calldata path, address to, uint deadline ) external payable { (bool success, bytes memory returnData) = router.delegatecall(abi.encodeWithSelector( IFXSwapV2Router01(router).swapExactFXForTokens.selector, amountOutMin, path, to, deadline )); assert(success); emit Amounts(abi.decode(returnData, (uint[]))); } function swapTokensForExactFX( address router, uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external { (bool success, bytes memory returnData) = router.delegatecall(abi.encodeWithSelector( IFXSwapV2Router01(router).swapTokensForExactFX.selector, amountOut, amountInMax, path, to, deadline )); assert(success); emit Amounts(abi.decode(returnData, (uint[]))); } function swapExactTokensForFX( address router, uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external { (bool success, bytes memory returnData) = router.delegatecall(abi.encodeWithSelector( IFXSwapV2Router01(router).swapExactTokensForFX.selector, amountIn, amountOutMin, path, to, deadline )); assert(success); emit Amounts(abi.decode(returnData, (uint[]))); } function swapFXForExactTokens( address router, uint amountOut, address[] calldata path, address to, uint deadline ) external payable { (bool success, bytes memory returnData) = router.delegatecall(abi.encodeWithSelector( IFXSwapV2Router01(router).swapFXForExactTokens.selector, amountOut, path, to, deadline )); assert(success); emit Amounts(abi.decode(returnData, (uint[]))); } }
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_factory","internalType":"address"},{"type":"address","name":"_WFX","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"WFX","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"amountA","internalType":"uint256"},{"type":"uint256","name":"amountB","internalType":"uint256"},{"type":"uint256","name":"liquidity","internalType":"uint256"}],"name":"addLiquidity","inputs":[{"type":"address","name":"tokenA","internalType":"address"},{"type":"address","name":"tokenB","internalType":"address"},{"type":"uint256","name":"amountADesired","internalType":"uint256"},{"type":"uint256","name":"amountBDesired","internalType":"uint256"},{"type":"uint256","name":"amountAMin","internalType":"uint256"},{"type":"uint256","name":"amountBMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"payable","outputs":[{"type":"uint256","name":"amountToken","internalType":"uint256"},{"type":"uint256","name":"amountFX","internalType":"uint256"},{"type":"uint256","name":"liquidity","internalType":"uint256"}],"name":"addLiquidityFX","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"amountTokenDesired","internalType":"uint256"},{"type":"uint256","name":"amountTokenMin","internalType":"uint256"},{"type":"uint256","name":"amountFXMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"factory","inputs":[]},{"type":"function","stateMutability":"pure","outputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"}],"name":"getAmountIn","inputs":[{"type":"uint256","name":"amountOut","internalType":"uint256"},{"type":"uint256","name":"reserveIn","internalType":"uint256"},{"type":"uint256","name":"reserveOut","internalType":"uint256"}]},{"type":"function","stateMutability":"pure","outputs":[{"type":"uint256","name":"amountOut","internalType":"uint256"}],"name":"getAmountOut","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"uint256","name":"reserveIn","internalType":"uint256"},{"type":"uint256","name":"reserveOut","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"getAmountsIn","inputs":[{"type":"uint256","name":"amountOut","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"getAmountsOut","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"}]},{"type":"function","stateMutability":"pure","outputs":[{"type":"uint256","name":"amountB","internalType":"uint256"}],"name":"quote","inputs":[{"type":"uint256","name":"amountA","internalType":"uint256"},{"type":"uint256","name":"reserveA","internalType":"uint256"},{"type":"uint256","name":"reserveB","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"amountA","internalType":"uint256"},{"type":"uint256","name":"amountB","internalType":"uint256"}],"name":"removeLiquidity","inputs":[{"type":"address","name":"tokenA","internalType":"address"},{"type":"address","name":"tokenB","internalType":"address"},{"type":"uint256","name":"liquidity","internalType":"uint256"},{"type":"uint256","name":"amountAMin","internalType":"uint256"},{"type":"uint256","name":"amountBMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"amountToken","internalType":"uint256"},{"type":"uint256","name":"amountFX","internalType":"uint256"}],"name":"removeLiquidityFX","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"liquidity","internalType":"uint256"},{"type":"uint256","name":"amountTokenMin","internalType":"uint256"},{"type":"uint256","name":"amountFXMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"amountFX","internalType":"uint256"}],"name":"removeLiquidityFXSupportingFeeOnTransferTokens","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"liquidity","internalType":"uint256"},{"type":"uint256","name":"amountTokenMin","internalType":"uint256"},{"type":"uint256","name":"amountFXMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"amountToken","internalType":"uint256"},{"type":"uint256","name":"amountFX","internalType":"uint256"}],"name":"removeLiquidityFXWithPermit","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"liquidity","internalType":"uint256"},{"type":"uint256","name":"amountTokenMin","internalType":"uint256"},{"type":"uint256","name":"amountFXMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"},{"type":"bool","name":"approveMax","internalType":"bool"},{"type":"uint8","name":"v","internalType":"uint8"},{"type":"bytes32","name":"r","internalType":"bytes32"},{"type":"bytes32","name":"s","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"amountFX","internalType":"uint256"}],"name":"removeLiquidityFXWithPermitSupportingFeeOnTransferTokens","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"liquidity","internalType":"uint256"},{"type":"uint256","name":"amountTokenMin","internalType":"uint256"},{"type":"uint256","name":"amountFXMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"},{"type":"bool","name":"approveMax","internalType":"bool"},{"type":"uint8","name":"v","internalType":"uint8"},{"type":"bytes32","name":"r","internalType":"bytes32"},{"type":"bytes32","name":"s","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"amountA","internalType":"uint256"},{"type":"uint256","name":"amountB","internalType":"uint256"}],"name":"removeLiquidityWithPermit","inputs":[{"type":"address","name":"tokenA","internalType":"address"},{"type":"address","name":"tokenB","internalType":"address"},{"type":"uint256","name":"liquidity","internalType":"uint256"},{"type":"uint256","name":"amountAMin","internalType":"uint256"},{"type":"uint256","name":"amountBMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"},{"type":"bool","name":"approveMax","internalType":"bool"},{"type":"uint8","name":"v","internalType":"uint8"},{"type":"bytes32","name":"r","internalType":"bytes32"},{"type":"bytes32","name":"s","internalType":"bytes32"}]},{"type":"function","stateMutability":"payable","outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"swapExactFXForTokens","inputs":[{"type":"uint256","name":"amountOutMin","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"swapExactFXForTokensSupportingFeeOnTransferTokens","inputs":[{"type":"uint256","name":"amountOutMin","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"swapExactTokensForFX","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"uint256","name":"amountOutMin","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"swapExactTokensForFXSupportingFeeOnTransferTokens","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"uint256","name":"amountOutMin","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"swapExactTokensForTokens","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"uint256","name":"amountOutMin","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"swapExactTokensForTokensSupportingFeeOnTransferTokens","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"uint256","name":"amountOutMin","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"payable","outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"swapFXForExactTokens","inputs":[{"type":"uint256","name":"amountOut","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"swapTokensForExactFX","inputs":[{"type":"uint256","name":"amountOut","internalType":"uint256"},{"type":"uint256","name":"amountInMax","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"swapTokensForExactTokens","inputs":[{"type":"uint256","name":"amountOut","internalType":"uint256"},{"type":"uint256","name":"amountInMax","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"receive","stateMutability":"payable"}]
Contract Creation Code
0x60c060405234801561001057600080fd5b50604051620047c4380380620047c48339818101604052604081101561003557600080fd5b5080516020909101516001600160601b0319606092831b8116608052911b1660a05260805160601c60a05160601c61463f620001856000398061015f5280610cf85280610dcc5280610e6c52806110cc5280611212528061129a52806115f752806119a05280611a005280611b7d5280611be55280611c7a5280611cee5280611f7b5280612108528061221e528061236152806123e952806127f8528061284e528061288252806128f65280612aef5280612db85280612eb25280612f8d525080610e4a5280610f5b5280610f94528061115f52806112cc5280611454528061152b52806115d552806117455280611acd5280611d20528061200952806122b1528061241b52806125b3528061282c5280612a505280612a795280612b7d5280612c91528061372552806137685280613a705280613bef528061401f52806140cd528061414d525061463f6000f3fe60806040526004361061014f5760003560e01c80638effbdb5116100b6578063bea915131161006f578063bea91513146109db578063c45a015514610a3f578063d06ca61f14610a54578063d9af10f714610b09578063e8e3370014610b9f578063f4d6842014610c0157610188565b80638effbdb514610779578063a2f4aada146107aa578063a97f36221461082e578063aaf7b998146108c4578063ad615dec14610948578063baa2abde1461097e57610188565b806338ed17391161010857806338ed1739146104bb5780634bd278ed146105515780635c11d795146105c45780637638ea371461065a57806385f8c259146106ad5780638803dbee146106e357610188565b8063054d50d41461018d578063140b5cd6146101d55780631edb7ef6146102285780631f00ca74146102b45780632195995c146103b95780632d23e1321461043757610188565b3661018857336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161461018657fe5b005b600080fd5b34801561019957600080fd5b506101c3600480360360608110156101b057600080fd5b5080359060208101359060400135610c97565b60408051918252519081900360200190f35b3480156101e157600080fd5b506101c3600480360360c08110156101f857600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a00135610cac565b34801561023457600080fd5b5061029b600480360361014081101561024c57600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a08101359060c081013515159060ff60e08201351690610100810135906101200135610e40565b6040805192835260208301919091528051918290030190f35b3480156102c057600080fd5b50610369600480360360408110156102d757600080fd5b81359190810190604081016020820135600160201b8111156102f857600080fd5b82018360208201111561030a57600080fd5b803590602001918460208302840111600160201b8311171561032b57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550610f54945050505050565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156103a557818101518382015260200161038d565b505050509050019250505060405180910390f35b3480156103c557600080fd5b5061029b60048036036101608110156103dd57600080fd5b506001600160a01b038135811691602081013582169160408201359160608101359160808201359160a08101359091169060c08101359060e081013515159060ff6101008201351690610120810135906101400135610f8a565b6103696004803603608081101561044d57600080fd5b81359190810190604081016020820135600160201b81111561046e57600080fd5b82018360208201111561048057600080fd5b803590602001918460208302840111600160201b831117156104a157600080fd5b91935091506001600160a01b038135169060200135611084565b3480156104c757600080fd5b50610369600480360360a08110156104de57600080fd5b813591602081013591810190606081016040820135600160201b81111561050457600080fd5b82018360208201111561051657600080fd5b803590602001918460208302840111600160201b8311171561053757600080fd5b91935091506001600160a01b038135169060200135611409565b34801561055d57600080fd5b506101c3600480360361014081101561057557600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a08101359060c081013515159060ff60e082013516906101008101359061012001356115cd565b3480156105d057600080fd5b50610186600480360360a08110156105e757600080fd5b813591602081013591810190606081016040820135600160201b81111561060d57600080fd5b82018360208201111561061f57600080fd5b803590602001918460208302840111600160201b8311171561064057600080fd5b91935091506001600160a01b0381351690602001356116db565b34801561066657600080fd5b5061029b600480360360c081101561067d57600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a00135611953565b3480156106b957600080fd5b506101c3600480360360608110156106d057600080fd5b5080359060208101359060400135611a75565b3480156106ef57600080fd5b50610369600480360360a081101561070657600080fd5b813591602081013591810190606081016040820135600160201b81111561072c57600080fd5b82018360208201111561073e57600080fd5b803590602001918460208302840111600160201b8311171561075f57600080fd5b91935091506001600160a01b038135169060200135611a82565b34801561078557600080fd5b5061078e611b7b565b604080516001600160a01b039092168252519081900360200190f35b610186600480360360808110156107c057600080fd5b81359190810190604081016020820135600160201b8111156107e157600080fd5b8201836020820111156107f357600080fd5b803590602001918460208302840111600160201b8311171561081457600080fd5b91935091506001600160a01b038135169060200135611b9f565b34801561083a57600080fd5b50610369600480360360a081101561085157600080fd5b813591602081013591810190606081016040820135600160201b81111561087757600080fd5b82018360208201111561088957600080fd5b803590602001918460208302840111600160201b831117156108aa57600080fd5b91935091506001600160a01b038135169060200135611f2b565b610369600480360360808110156108da57600080fd5b81359190810190604081016020820135600160201b8111156108fb57600080fd5b82018360208201111561090d57600080fd5b803590602001918460208302840111600160201b8311171561092e57600080fd5b91935091506001600160a01b0381351690602001356121d6565b34801561095457600080fd5b506101c36004803603606081101561096b57600080fd5b5080359060208101359060400135612558565b34801561098a57600080fd5b5061029b600480360360e08110156109a157600080fd5b506001600160a01b038135811691602081013582169160408201359160608101359160808201359160a08101359091169060c00135612565565b610a21600480360360c08110156109f157600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a001356127a9565b60408051938452602084019290925282820152519081900360600190f35b348015610a4b57600080fd5b5061078e612a4e565b348015610a6057600080fd5b5061036960048036036040811015610a7757600080fd5b81359190810190604081016020820135600160201b811115610a9857600080fd5b820183602082011115610aaa57600080fd5b803590602001918460208302840111600160201b83111715610acb57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550612a72945050505050565b348015610b1557600080fd5b50610369600480360360a0811015610b2c57600080fd5b813591602081013591810190606081016040820135600160201b811115610b5257600080fd5b820183602082011115610b6457600080fd5b803590602001918460208302840111600160201b83111715610b8557600080fd5b91935091506001600160a01b038135169060200135612a9f565b348015610bab57600080fd5b50610a216004803603610100811015610bc357600080fd5b506001600160a01b038135811691602081013582169160408201359160608101359160808201359160a08101359160c0820135169060e00135612c2e565b348015610c0d57600080fd5b50610186600480360360a0811015610c2457600080fd5b813591602081013591810190606081016040820135600160201b811115610c4a57600080fd5b820183602082011115610c5c57600080fd5b803590602001918460208302840111600160201b83111715610c7d57600080fd5b91935091506001600160a01b038135169060200135612d6a565b6000610ca4848484612ff6565b949350505050565b60008142811015610cf2576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b610d21887f00000000000000000000000000000000000000000000000000000000000000008989893089612565565b604080516370a0823160e01b81523060048201529051919450610da592508a9187916001600160a01b038416916370a0823191602480820192602092909190829003018186803b158015610d7457600080fd5b505afa158015610d88573d6000803e3d6000fd5b505050506040513d6020811015610d9e57600080fd5b50516130e6565b6040805163f3fef3a360e01b81523060048201526024810184905290516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163f3fef3a391604480830192600092919082900301818387803b158015610e1357600080fd5b505af1158015610e27573d6000803e3d6000fd5b50505050610e35848361323a565b509695505050505050565b6000806000610e907f00000000000000000000000000000000000000000000000000000000000000008e7f0000000000000000000000000000000000000000000000000000000000000000613332565b9050600087610e9f578c610ea3565b6000195b6040805163d505accf60e01b815233600482015230602482015260448101839052606481018c905260ff8a16608482015260a4810189905260c4810188905290519192506001600160a01b0384169163d505accf9160e48082019260009290919082900301818387803b158015610f1957600080fd5b505af1158015610f2d573d6000803e3d6000fd5b50505050610f3f8e8e8e8e8e8e611953565b909f909e509c50505050505050505050505050565b6060610f817f000000000000000000000000000000000000000000000000000000000000000084846133f2565b90505b92915050565b6000806000610fba7f00000000000000000000000000000000000000000000000000000000000000008f8f613332565b9050600087610fc9578c610fcd565b6000195b6040805163d505accf60e01b815233600482015230602482015260448101839052606481018c905260ff8a16608482015260a4810189905260c4810188905290519192506001600160a01b0384169163d505accf9160e48082019260009290919082900301818387803b15801561104357600080fd5b505af1158015611057573d6000803e3d6000fd5b5050505061106a8f8f8f8f8f8f8f612565565b809450819550505050509b509b9950505050505050505050565b606081428110156110ca576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168686600081811061110157fe5b905060200201356001600160a01b03166001600160a01b03161461115a576040805162461bcd60e51b815260206004820152601c60248201526000805160206145ea833981519152604482015290519081900360640190fd5b6111b87f00000000000000000000000000000000000000000000000000000000000000003488888080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525061353f92505050565b915086826001845103815181106111cb57fe5b602002602001015110156112105760405162461bcd60e51b815260040180806020018281038252602a815260200180614407602a913960400191505060405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db08360008151811061124c57fe5b60200260200101516040518263ffffffff1660e01b81526004016000604051808303818588803b15801561127f57600080fd5b505af1158015611293573d6000803e3d6000fd5b50505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a9059cbb61132a7f0000000000000000000000000000000000000000000000000000000000000000898960008181106112f857fe5b905060200201356001600160a01b03168a8a600181811061131557fe5b905060200201356001600160a01b0316613332565b8460008151811061133757fe5b60200260200101516040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561138e57600080fd5b505af11580156113a2573d6000803e3d6000fd5b505050506040513d60208110156113b857600080fd5b50516113c057fe5b6113ff82878780806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250899250613676915050565b5095945050505050565b6060814281101561144f576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b6114ad7f00000000000000000000000000000000000000000000000000000000000000008988888080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525061353f92505050565b915086826001845103815181106114c057fe5b602002602001015110156115055760405162461bcd60e51b815260040180806020018281038252602a815260200180614407602a913960400191505060405180910390fd5b61158e8686600081811061151557fe5b905060200201356001600160a01b0316336115747f00000000000000000000000000000000000000000000000000000000000000008a8a600081811061155757fe5b905060200201356001600160a01b03168b8b600181811061131557fe5b8560008151811061158157fe5b60200260200101516138bc565b610e3582878780806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250899250613676915050565b60008061161b7f00000000000000000000000000000000000000000000000000000000000000008d7f0000000000000000000000000000000000000000000000000000000000000000613332565b905060008661162a578b61162e565b6000195b6040805163d505accf60e01b815233600482015230602482015260448101839052606481018b905260ff8916608482015260a4810188905260c4810187905290519192506001600160a01b0384169163d505accf9160e48082019260009290919082900301818387803b1580156116a457600080fd5b505af11580156116b8573d6000803e3d6000fd5b505050506116ca8d8d8d8d8d8d610cac565b9d9c50505050505050505050505050565b804281101561171f576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b6117778585600081811061172f57fe5b905060200201356001600160a01b0316336117717f0000000000000000000000000000000000000000000000000000000000000000898960008181106112f857fe5b8a6138bc565b60008585600019810181811061178957fe5b905060200201356001600160a01b03166001600160a01b03166370a08231856040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156117ee57600080fd5b505afa158015611802573d6000803e3d6000fd5b505050506040513d602081101561181857600080fd5b5051604080516020888102828101820190935288825292935061185a929091899189918291850190849080828437600092019190915250889250613a19915050565b8661190c828888600019810181811061186f57fe5b905060200201356001600160a01b03166001600160a01b03166370a08231886040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156118d457600080fd5b505afa1580156118e8573d6000803e3d6000fd5b505050506040513d60208110156118fe57600080fd5b50519063ffffffff613d2416565b10156119495760405162461bcd60e51b815260040180806020018281038252602a815260200180614407602a913960400191505060405180910390fd5b5050505050505050565b600080824281101561199a576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b6119c9897f00000000000000000000000000000000000000000000000000000000000000008a8a8a308a612565565b90935091506119d98986856130e6565b6040805163f3fef3a360e01b81523060048201526024810184905290516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163f3fef3a391604480830192600092919082900301818387803b158015611a4757600080fd5b505af1158015611a5b573d6000803e3d6000fd5b50505050611a69858361323a565b50965096945050505050565b6000610ca4848484613d74565b60608142811015611ac8576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b611b267f0000000000000000000000000000000000000000000000000000000000000000898888808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506133f292505050565b91508682600081518110611b3657fe5b602002602001015111156115055760405162461bcd60e51b81526004018080602001828103825260268152602001806144626026913960400191505060405180910390fd5b7f000000000000000000000000000000000000000000000000000000000000000081565b8042811015611be3576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031685856000818110611c1a57fe5b905060200201356001600160a01b03166001600160a01b031614611c73576040805162461bcd60e51b815260206004820152601c60248201526000805160206145ea833981519152604482015290519081900360640190fd5b60003490507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b158015611cd357600080fd5b505af1158015611ce7573d6000803e3d6000fd5b50505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a9059cbb611d4c7f0000000000000000000000000000000000000000000000000000000000000000898960008181106112f857fe5b836040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b158015611d9c57600080fd5b505af1158015611db0573d6000803e3d6000fd5b505050506040513d6020811015611dc657600080fd5b5051611dce57fe5b600086866000198101818110611de057fe5b905060200201356001600160a01b03166001600160a01b03166370a08231866040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b158015611e4557600080fd5b505afa158015611e59573d6000803e3d6000fd5b505050506040513d6020811015611e6f57600080fd5b50516040805160208981028281018201909352898252929350611eb19290918a918a918291850190849080828437600092019190915250899250613a19915050565b8761190c8289896000198101818110611ec657fe5b905060200201356001600160a01b03166001600160a01b03166370a08231896040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156118d457600080fd5b60608142811015611f71576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001686866000198101818110611fab57fe5b905060200201356001600160a01b03166001600160a01b031614612004576040805162461bcd60e51b815260206004820152601c60248201526000805160206145ea833981519152604482015290519081900360640190fd5b6120627f0000000000000000000000000000000000000000000000000000000000000000898888808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506133f292505050565b9150868260008151811061207257fe5b602002602001015111156120b75760405162461bcd60e51b81526004018080602001828103825260268152602001806144626026913960400191505060405180910390fd5b6120c78686600081811061151557fe5b61210682878780806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250309250613676915050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663f3fef3a3308460018651038151811061214657fe5b60200260200101516040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050600060405180830381600087803b15801561219d57600080fd5b505af11580156121b1573d6000803e3d6000fd5b50505050610e3584836001855103815181106121c957fe5b602002602001015161323a565b6060814281101561221c576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168686600081811061225357fe5b905060200201356001600160a01b03166001600160a01b0316146122ac576040805162461bcd60e51b815260206004820152601c60248201526000805160206145ea833981519152604482015290519081900360640190fd5b61230a7f0000000000000000000000000000000000000000000000000000000000000000888888808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506133f292505050565b9150348260008151811061231a57fe5b6020026020010151111561235f5760405162461bcd60e51b81526004018080602001828103825260268152602001806144626026913960400191505060405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db08360008151811061239b57fe5b60200260200101516040518263ffffffff1660e01b81526004016000604051808303818588803b1580156123ce57600080fd5b505af11580156123e2573d6000803e3d6000fd5b50505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a9059cbb6124477f0000000000000000000000000000000000000000000000000000000000000000898960008181106112f857fe5b8460008151811061245457fe5b60200260200101516040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b1580156124ab57600080fd5b505af11580156124bf573d6000803e3d6000fd5b505050506040513d60208110156124d557600080fd5b50516124dd57fe5b61251c82878780806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250899250613676915050565b8160008151811061252957fe5b60200260200101513411156113ff576113ff338360008151811061254957fe5b6020026020010151340361323a565b6000610ca4848484613e64565b60008082428110156125ac576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b60006125d97f00000000000000000000000000000000000000000000000000000000000000008c8c613332565b604080516323b872dd60e01b81523360048201526001600160a01b03831660248201819052604482018d9052915192935090916323b872dd916064808201926020929091908290030181600087803b15801561263457600080fd5b505af1158015612648573d6000803e3d6000fd5b505050506040513d602081101561265e57600080fd5b50506040805163226bf2d160e21b81526001600160a01b03888116600483015282516000938493928616926389afcb44926024808301939282900301818787803b1580156126ab57600080fd5b505af11580156126bf573d6000803e3d6000fd5b505050506040513d60408110156126d557600080fd5b508051602090910151909250905060006126ef8e8e613f10565b509050806001600160a01b03168e6001600160a01b031614612712578183612715565b82825b90975095508a8710156127595760405162461bcd60e51b81526004018080602001828103825260258152602001806145096025913960400191505060405180910390fd5b898610156127985760405162461bcd60e51b81526004018080602001828103825260258152602001806144886025913960400191505060405180910390fd5b505050505097509795505050505050565b600080600083428110156127f2576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b6128208a7f00000000000000000000000000000000000000000000000000000000000000008b348c8c613fee565b909450925060006128727f00000000000000000000000000000000000000000000000000000000000000008c7f0000000000000000000000000000000000000000000000000000000000000000613332565b90506128808b3383886138bc565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0856040518263ffffffff1660e01b81526004016000604051808303818588803b1580156128db57600080fd5b505af11580156128ef573d6000803e3d6000fd5b50505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a9059cbb82866040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561297457600080fd5b505af1158015612988573d6000803e3d6000fd5b505050506040513d602081101561299e57600080fd5b50516129a657fe5b806001600160a01b0316636a627842886040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b03168152602001915050602060405180830381600087803b1580156129fe57600080fd5b505af1158015612a12573d6000803e3d6000fd5b505050506040513d6020811015612a2857600080fd5b5051925034841015612a4057612a403385340361323a565b505096509650969350505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6060610f817f0000000000000000000000000000000000000000000000000000000000000000848461353f565b60608142811015612ae5576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001686866000198101818110612b1f57fe5b905060200201356001600160a01b03166001600160a01b031614612b78576040805162461bcd60e51b815260206004820152601c60248201526000805160206145ea833981519152604482015290519081900360640190fd5b612bd67f00000000000000000000000000000000000000000000000000000000000000008988888080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525061353f92505050565b91508682600184510381518110612be957fe5b602002602001015110156120b75760405162461bcd60e51b815260040180806020018281038252602a815260200180614407602a913960400191505060405180910390fd5b60008060008342811015612c77576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b612c858c8c8c8c8c8c613fee565b90945092506000612cb77f00000000000000000000000000000000000000000000000000000000000000008e8e613332565b9050612cc58d3383886138bc565b612cd18c3383876138bc565b806001600160a01b0316636a627842886040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b03168152602001915050602060405180830381600087803b158015612d2957600080fd5b505af1158015612d3d573d6000803e3d6000fd5b505050506040513d6020811015612d5357600080fd5b5051949d939c50939a509198505050505050505050565b8042811015612dae576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001685856000198101818110612de857fe5b905060200201356001600160a01b03166001600160a01b031614612e41576040805162461bcd60e51b815260206004820152601c60248201526000805160206145ea833981519152604482015290519081900360640190fd5b612e518585600081811061172f57fe5b612e8f858580806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250309250613a19915050565b604080516370a0823160e01b815230600482015290516000916001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016916370a0823191602480820192602092909190829003018186803b158015612ef957600080fd5b505afa158015612f0d573d6000803e3d6000fd5b505050506040513d6020811015612f2357600080fd5b5051905086811015612f665760405162461bcd60e51b815260040180806020018281038252602a815260200180614407602a913960400191505060405180910390fd5b6040805163f3fef3a360e01b81523060048201526024810183905290516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163f3fef3a391604480830192600092919082900301818387803b158015612fd457600080fd5b505af1158015612fe8573d6000803e3d6000fd5b50505050611949848261323a565b60008084116130365760405162461bcd60e51b815260040180806020018281038252602a8152602001806144ad602a913960400191505060405180910390fd5b6000831180156130465750600082115b6130815760405162461bcd60e51b815260040180806020018281038252602781526020018061452e6027913960400191505060405180910390fd5b6000613095856103e563ffffffff61426216565b905060006130a9828563ffffffff61426216565b905060006130cf836130c3886103e863ffffffff61426216565b9063ffffffff6142c516565b90508082816130da57fe5b04979650505050505050565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b178152925182516000946060949389169392918291908083835b602083106131635780518252601f199092019160209182019101613144565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146131c5576040519150601f19603f3d011682016040523d82523d6000602084013e6131ca565b606091505b50915091508180156131f85750805115806131f857508080602001905160208110156131f557600080fd5b50515b6132335760405162461bcd60e51b815260040180806020018281038252602d8152602001806145bd602d913960400191505060405180910390fd5b5050505050565b604080516000808252602082019092526001600160a01b0384169083906040518082805190602001908083835b602083106132865780518252601f199092019160209182019101613267565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146132e8576040519150601f19603f3d011682016040523d82523d6000602084013e6132ed565b606091505b505090508061332d5760405162461bcd60e51b81526004018080602001828103825260328152602001806144d76032913960400191505060405180910390fd5b505050565b60008060006133418585613f10565b604080516bffffffffffffffffffffffff19606094851b811660208084019190915293851b81166034830152825160288184030181526048830184528051908501206001600160f81b031960688401529a90941b9093166069840152607d8301989098527f89bbd161b7f9309df13e388d6b1f71f5ff07259b5149560e726a4df10971bceb609d808401919091528851808403909101815260bd909201909752805196019590952095945050505050565b606060028251101561344b576040805162461bcd60e51b815260206004820152601d60248201527f46585377617056324c6962726172793a20494e56414c49445f50415448000000604482015290519081900360640190fd5b815167ffffffffffffffff8111801561346357600080fd5b5060405190808252806020026020018201604052801561348d578160200160208202803683370190505b50905082816001835103815181106134a157fe5b60209081029190910101528151600019015b8015613537576000806134f0878660018603815181106134cf57fe5b60200260200101518786815181106134e357fe5b6020026020010151614314565b9150915061351284848151811061350357fe5b60200260200101518383613d74565b84600185038151811061352157fe5b60209081029190910101525050600019016134b3565b509392505050565b6060600282511015613598576040805162461bcd60e51b815260206004820152601d60248201527f46585377617056324c6962726172793a20494e56414c49445f50415448000000604482015290519081900360640190fd5b815167ffffffffffffffff811180156135b057600080fd5b506040519080825280602002602001820160405280156135da578160200160208202803683370190505b50905082816000815181106135eb57fe5b60200260200101818152505060005b6001835103811015613537576000806136308786858151811061361957fe5b60200260200101518786600101815181106134e357fe5b9150915061365284848151811061364357fe5b60200260200101518383612ff6565b84846001018151811061366157fe5b602090810291909101015250506001016135fa565b60005b60018351038110156138b65760008084838151811061369457fe5b60200260200101518584600101815181106136ab57fe5b60200260200101519150915060006136c38383613f10565b50905060008785600101815181106136d757fe5b60200260200101519050600080836001600160a01b0316866001600160a01b03161461370557826000613709565b6000835b91509150600060028a510388106137205788613761565b6137617f0000000000000000000000000000000000000000000000000000000000000000878c8b6002018151811061375457fe5b6020026020010151613332565b905061378e7f00000000000000000000000000000000000000000000000000000000000000008888613332565b6001600160a01b031663022c0d9f84848460006040519080825280601f01601f1916602001820160405280156137cb576020820181803683370190505b506040518563ffffffff1660e01b815260040180858152602001848152602001836001600160a01b03166001600160a01b0316815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561383c578181015183820152602001613824565b50505050905090810190601f1680156138695780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801561388b57600080fd5b505af115801561389f573d6000803e3d6000fd5b505060019099019850613679975050505050505050565b50505050565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b17815292518251600094606094938a169392918291908083835b602083106139415780518252601f199092019160209182019101613922565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146139a3576040519150601f19603f3d011682016040523d82523d6000602084013e6139a8565b606091505b50915091508180156139d65750805115806139d657508080602001905160208110156139d357600080fd5b50515b613a115760405162461bcd60e51b81526004018080602001828103825260318152602001806144316031913960400191505060405180910390fd5b505050505050565b60005b600183510381101561332d57600080848381518110613a3757fe5b6020026020010151858460010181518110613a4e57fe5b6020026020010151915091506000613a668383613f10565b5090506000613a967f00000000000000000000000000000000000000000000000000000000000000008585613332565b9050600080600080846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015613ad757600080fd5b505afa158015613aeb573d6000803e3d6000fd5b505050506040513d6060811015613b0157600080fd5b5080516020909101516001600160701b0391821693501690506000806001600160a01b038a811690891614613b37578284613b3a565b83835b91509150613b98828b6001600160a01b03166370a082318a6040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156118d457600080fd5b9550613ba5868383612ff6565b945050505050600080856001600160a01b0316886001600160a01b031614613bcf57826000613bd3565b6000835b91509150600060028c51038a10613bea578a613c1e565b613c1e7f0000000000000000000000000000000000000000000000000000000000000000898e8d6002018151811061375457fe5b604080516000808252602082019283905263022c0d9f60e01b835260248201878152604483018790526001600160a01b038086166064850152608060848501908152845160a48601819052969750908c169563022c0d9f958a958a958a9591949193919260c486019290918190849084905b83811015613ca8578181015183820152602001613c90565b50505050905090810190601f168015613cd55780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b158015613cf757600080fd5b505af1158015613d0b573d6000803e3d6000fd5b50506001909b019a50613a1c9950505050505050505050565b80820382811115610f84576040805162461bcd60e51b815260206004820152601560248201527464732d6d6174682d7375622d756e646572666c6f7760581b604482015290519081900360640190fd5b6000808411613db45760405162461bcd60e51b815260040180806020018281038252602b8152602001806143dc602b913960400191505060405180910390fd5b600083118015613dc45750600082115b613dff5760405162461bcd60e51b815260040180806020018281038252602781526020018061452e6027913960400191505060405180910390fd5b6000613e236103e8613e17868863ffffffff61426216565b9063ffffffff61426216565b90506000613e3d6103e5613e17868963ffffffff613d2416565b9050613e5a6001828481613e4d57fe5b049063ffffffff6142c516565b9695505050505050565b6000808411613ea45760405162461bcd60e51b81526004018080602001828103825260248152602001806145996024913960400191505060405180910390fd5b600083118015613eb45750600082115b613eef5760405162461bcd60e51b815260040180806020018281038252602781526020018061452e6027913960400191505060405180910390fd5b82613f00858463ffffffff61426216565b81613f0757fe5b04949350505050565b600080826001600160a01b0316846001600160a01b03161415613f645760405162461bcd60e51b81526004018080602001828103825260248152602001806145756024913960400191505060405180910390fd5b826001600160a01b0316846001600160a01b031610613f84578284613f87565b83835b90925090506001600160a01b038216613fe7576040805162461bcd60e51b815260206004820152601d60248201527f46585377617056324c6962726172793a205a45524f5f41444452455353000000604482015290519081900360640190fd5b9250929050565b6040805163e6a4390560e01b81526001600160a01b03888116600483015287811660248301529151600092839283927f00000000000000000000000000000000000000000000000000000000000000009092169163e6a4390591604480820192602092909190829003018186803b15801561406857600080fd5b505afa15801561407c573d6000803e3d6000fd5b505050506040513d602081101561409257600080fd5b50516001600160a01b0316141561414557604080516364e329cb60e11b81526001600160a01b038a81166004830152898116602483015291517f00000000000000000000000000000000000000000000000000000000000000009092169163c9c65396916044808201926020929091908290030181600087803b15801561411857600080fd5b505af115801561412c573d6000803e3d6000fd5b505050506040513d602081101561414257600080fd5b50505b6000806141737f00000000000000000000000000000000000000000000000000000000000000008b8b614314565b91509150816000148015614185575080155b1561419557879350869250614255565b60006141a2898484613e64565b90508781116141f557858110156141ea5760405162461bcd60e51b81526004018080602001828103825260258152602001806144886025913960400191505060405180910390fd5b889450925082614253565b6000614202898486613e64565b90508981111561420e57fe5b8781101561424d5760405162461bcd60e51b81526004018080602001828103825260258152602001806145096025913960400191505060405180910390fd5b94508793505b505b5050965096945050505050565b600081158061427d5750508082028282828161427a57fe5b04145b610f84576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6d756c2d6f766572666c6f7760601b604482015290519081900360640190fd5b80820182811015610f84576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6164642d6f766572666c6f7760601b604482015290519081900360640190fd5b60008060006143238585613f10565b509050600080614334888888613332565b6001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b15801561436c57600080fd5b505afa158015614380573d6000803e3d6000fd5b505050506040513d606081101561439657600080fd5b5080516020909101516001600160701b0391821693501690506001600160a01b03878116908416146143c95780826143cc565b81815b9099909850965050505050505056fe46585377617056324c6962726172793a20494e53554646494349454e545f4f55545055545f414d4f554e544658537761705632526f757465723a20494e53554646494349454e545f4f55545055545f414d4f554e545472616e7366657248656c7065723a3a7472616e7366657246726f6d3a207472616e7366657246726f6d206661696c65644658537761705632526f757465723a204558434553534956455f494e5055545f414d4f554e544658537761705632526f757465723a20494e53554646494349454e545f425f414d4f554e5446585377617056324c6962726172793a20494e53554646494349454e545f494e5055545f414d4f554e545472616e7366657248656c7065723a3a736166655472616e7366657246583a204658207472616e73666572206661696c65644658537761705632526f757465723a20494e53554646494349454e545f415f414d4f554e5446585377617056324c6962726172793a20494e53554646494349454e545f4c49515549444954594658537761705632526f757465723a204558504952454400000000000000000046585377617056324c6962726172793a204944454e544943414c5f41444452455353455346585377617056324c6962726172793a20494e53554646494349454e545f414d4f554e545472616e7366657248656c7065723a3a736166655472616e736665723a207472616e73666572206661696c65644658537761705632526f757465723a20494e56414c49445f5041544800000000a2646970667358221220998098d9101c4955f14434aa4692b1cc2d17013dc735c90e0944e1d65734fed364736f6c63430006060033000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd
Deployed ByteCode
0x60806040526004361061014f5760003560e01c80638effbdb5116100b6578063bea915131161006f578063bea91513146109db578063c45a015514610a3f578063d06ca61f14610a54578063d9af10f714610b09578063e8e3370014610b9f578063f4d6842014610c0157610188565b80638effbdb514610779578063a2f4aada146107aa578063a97f36221461082e578063aaf7b998146108c4578063ad615dec14610948578063baa2abde1461097e57610188565b806338ed17391161010857806338ed1739146104bb5780634bd278ed146105515780635c11d795146105c45780637638ea371461065a57806385f8c259146106ad5780638803dbee146106e357610188565b8063054d50d41461018d578063140b5cd6146101d55780631edb7ef6146102285780631f00ca74146102b45780632195995c146103b95780632d23e1321461043757610188565b3661018857336001600160a01b037f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd161461018657fe5b005b600080fd5b34801561019957600080fd5b506101c3600480360360608110156101b057600080fd5b5080359060208101359060400135610c97565b60408051918252519081900360200190f35b3480156101e157600080fd5b506101c3600480360360c08110156101f857600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a00135610cac565b34801561023457600080fd5b5061029b600480360361014081101561024c57600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a08101359060c081013515159060ff60e08201351690610100810135906101200135610e40565b6040805192835260208301919091528051918290030190f35b3480156102c057600080fd5b50610369600480360360408110156102d757600080fd5b81359190810190604081016020820135600160201b8111156102f857600080fd5b82018360208201111561030a57600080fd5b803590602001918460208302840111600160201b8311171561032b57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550610f54945050505050565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156103a557818101518382015260200161038d565b505050509050019250505060405180910390f35b3480156103c557600080fd5b5061029b60048036036101608110156103dd57600080fd5b506001600160a01b038135811691602081013582169160408201359160608101359160808201359160a08101359091169060c08101359060e081013515159060ff6101008201351690610120810135906101400135610f8a565b6103696004803603608081101561044d57600080fd5b81359190810190604081016020820135600160201b81111561046e57600080fd5b82018360208201111561048057600080fd5b803590602001918460208302840111600160201b831117156104a157600080fd5b91935091506001600160a01b038135169060200135611084565b3480156104c757600080fd5b50610369600480360360a08110156104de57600080fd5b813591602081013591810190606081016040820135600160201b81111561050457600080fd5b82018360208201111561051657600080fd5b803590602001918460208302840111600160201b8311171561053757600080fd5b91935091506001600160a01b038135169060200135611409565b34801561055d57600080fd5b506101c3600480360361014081101561057557600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a08101359060c081013515159060ff60e082013516906101008101359061012001356115cd565b3480156105d057600080fd5b50610186600480360360a08110156105e757600080fd5b813591602081013591810190606081016040820135600160201b81111561060d57600080fd5b82018360208201111561061f57600080fd5b803590602001918460208302840111600160201b8311171561064057600080fd5b91935091506001600160a01b0381351690602001356116db565b34801561066657600080fd5b5061029b600480360360c081101561067d57600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a00135611953565b3480156106b957600080fd5b506101c3600480360360608110156106d057600080fd5b5080359060208101359060400135611a75565b3480156106ef57600080fd5b50610369600480360360a081101561070657600080fd5b813591602081013591810190606081016040820135600160201b81111561072c57600080fd5b82018360208201111561073e57600080fd5b803590602001918460208302840111600160201b8311171561075f57600080fd5b91935091506001600160a01b038135169060200135611a82565b34801561078557600080fd5b5061078e611b7b565b604080516001600160a01b039092168252519081900360200190f35b610186600480360360808110156107c057600080fd5b81359190810190604081016020820135600160201b8111156107e157600080fd5b8201836020820111156107f357600080fd5b803590602001918460208302840111600160201b8311171561081457600080fd5b91935091506001600160a01b038135169060200135611b9f565b34801561083a57600080fd5b50610369600480360360a081101561085157600080fd5b813591602081013591810190606081016040820135600160201b81111561087757600080fd5b82018360208201111561088957600080fd5b803590602001918460208302840111600160201b831117156108aa57600080fd5b91935091506001600160a01b038135169060200135611f2b565b610369600480360360808110156108da57600080fd5b81359190810190604081016020820135600160201b8111156108fb57600080fd5b82018360208201111561090d57600080fd5b803590602001918460208302840111600160201b8311171561092e57600080fd5b91935091506001600160a01b0381351690602001356121d6565b34801561095457600080fd5b506101c36004803603606081101561096b57600080fd5b5080359060208101359060400135612558565b34801561098a57600080fd5b5061029b600480360360e08110156109a157600080fd5b506001600160a01b038135811691602081013582169160408201359160608101359160808201359160a08101359091169060c00135612565565b610a21600480360360c08110156109f157600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a001356127a9565b60408051938452602084019290925282820152519081900360600190f35b348015610a4b57600080fd5b5061078e612a4e565b348015610a6057600080fd5b5061036960048036036040811015610a7757600080fd5b81359190810190604081016020820135600160201b811115610a9857600080fd5b820183602082011115610aaa57600080fd5b803590602001918460208302840111600160201b83111715610acb57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550612a72945050505050565b348015610b1557600080fd5b50610369600480360360a0811015610b2c57600080fd5b813591602081013591810190606081016040820135600160201b811115610b5257600080fd5b820183602082011115610b6457600080fd5b803590602001918460208302840111600160201b83111715610b8557600080fd5b91935091506001600160a01b038135169060200135612a9f565b348015610bab57600080fd5b50610a216004803603610100811015610bc357600080fd5b506001600160a01b038135811691602081013582169160408201359160608101359160808201359160a08101359160c0820135169060e00135612c2e565b348015610c0d57600080fd5b50610186600480360360a0811015610c2457600080fd5b813591602081013591810190606081016040820135600160201b811115610c4a57600080fd5b820183602082011115610c5c57600080fd5b803590602001918460208302840111600160201b83111715610c7d57600080fd5b91935091506001600160a01b038135169060200135612d6a565b6000610ca4848484612ff6565b949350505050565b60008142811015610cf2576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b610d21887f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd8989893089612565565b604080516370a0823160e01b81523060048201529051919450610da592508a9187916001600160a01b038416916370a0823191602480820192602092909190829003018186803b158015610d7457600080fd5b505afa158015610d88573d6000803e3d6000fd5b505050506040513d6020811015610d9e57600080fd5b50516130e6565b6040805163f3fef3a360e01b81523060048201526024810184905290516001600160a01b037f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd169163f3fef3a391604480830192600092919082900301818387803b158015610e1357600080fd5b505af1158015610e27573d6000803e3d6000fd5b50505050610e35848361323a565b509695505050505050565b6000806000610e907f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d8e7f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd613332565b9050600087610e9f578c610ea3565b6000195b6040805163d505accf60e01b815233600482015230602482015260448101839052606481018c905260ff8a16608482015260a4810189905260c4810188905290519192506001600160a01b0384169163d505accf9160e48082019260009290919082900301818387803b158015610f1957600080fd5b505af1158015610f2d573d6000803e3d6000fd5b50505050610f3f8e8e8e8e8e8e611953565b909f909e509c50505050505050505050505050565b6060610f817f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d84846133f2565b90505b92915050565b6000806000610fba7f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d8f8f613332565b9050600087610fc9578c610fcd565b6000195b6040805163d505accf60e01b815233600482015230602482015260448101839052606481018c905260ff8a16608482015260a4810189905260c4810188905290519192506001600160a01b0384169163d505accf9160e48082019260009290919082900301818387803b15801561104357600080fd5b505af1158015611057573d6000803e3d6000fd5b5050505061106a8f8f8f8f8f8f8f612565565b809450819550505050509b509b9950505050505050505050565b606081428110156110ca576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b7f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd6001600160a01b03168686600081811061110157fe5b905060200201356001600160a01b03166001600160a01b03161461115a576040805162461bcd60e51b815260206004820152601c60248201526000805160206145ea833981519152604482015290519081900360640190fd5b6111b87f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d3488888080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525061353f92505050565b915086826001845103815181106111cb57fe5b602002602001015110156112105760405162461bcd60e51b815260040180806020018281038252602a815260200180614407602a913960400191505060405180910390fd5b7f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd6001600160a01b031663d0e30db08360008151811061124c57fe5b60200260200101516040518263ffffffff1660e01b81526004016000604051808303818588803b15801561127f57600080fd5b505af1158015611293573d6000803e3d6000fd5b50505050507f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd6001600160a01b031663a9059cbb61132a7f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d898960008181106112f857fe5b905060200201356001600160a01b03168a8a600181811061131557fe5b905060200201356001600160a01b0316613332565b8460008151811061133757fe5b60200260200101516040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561138e57600080fd5b505af11580156113a2573d6000803e3d6000fd5b505050506040513d60208110156113b857600080fd5b50516113c057fe5b6113ff82878780806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250899250613676915050565b5095945050505050565b6060814281101561144f576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b6114ad7f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d8988888080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525061353f92505050565b915086826001845103815181106114c057fe5b602002602001015110156115055760405162461bcd60e51b815260040180806020018281038252602a815260200180614407602a913960400191505060405180910390fd5b61158e8686600081811061151557fe5b905060200201356001600160a01b0316336115747f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d8a8a600081811061155757fe5b905060200201356001600160a01b03168b8b600181811061131557fe5b8560008151811061158157fe5b60200260200101516138bc565b610e3582878780806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250899250613676915050565b60008061161b7f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d8d7f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd613332565b905060008661162a578b61162e565b6000195b6040805163d505accf60e01b815233600482015230602482015260448101839052606481018b905260ff8916608482015260a4810188905260c4810187905290519192506001600160a01b0384169163d505accf9160e48082019260009290919082900301818387803b1580156116a457600080fd5b505af11580156116b8573d6000803e3d6000fd5b505050506116ca8d8d8d8d8d8d610cac565b9d9c50505050505050505050505050565b804281101561171f576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b6117778585600081811061172f57fe5b905060200201356001600160a01b0316336117717f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d898960008181106112f857fe5b8a6138bc565b60008585600019810181811061178957fe5b905060200201356001600160a01b03166001600160a01b03166370a08231856040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156117ee57600080fd5b505afa158015611802573d6000803e3d6000fd5b505050506040513d602081101561181857600080fd5b5051604080516020888102828101820190935288825292935061185a929091899189918291850190849080828437600092019190915250889250613a19915050565b8661190c828888600019810181811061186f57fe5b905060200201356001600160a01b03166001600160a01b03166370a08231886040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156118d457600080fd5b505afa1580156118e8573d6000803e3d6000fd5b505050506040513d60208110156118fe57600080fd5b50519063ffffffff613d2416565b10156119495760405162461bcd60e51b815260040180806020018281038252602a815260200180614407602a913960400191505060405180910390fd5b5050505050505050565b600080824281101561199a576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b6119c9897f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd8a8a8a308a612565565b90935091506119d98986856130e6565b6040805163f3fef3a360e01b81523060048201526024810184905290516001600160a01b037f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd169163f3fef3a391604480830192600092919082900301818387803b158015611a4757600080fd5b505af1158015611a5b573d6000803e3d6000fd5b50505050611a69858361323a565b50965096945050505050565b6000610ca4848484613d74565b60608142811015611ac8576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b611b267f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d898888808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506133f292505050565b91508682600081518110611b3657fe5b602002602001015111156115055760405162461bcd60e51b81526004018080602001828103825260268152602001806144626026913960400191505060405180910390fd5b7f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd81565b8042811015611be3576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b7f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd6001600160a01b031685856000818110611c1a57fe5b905060200201356001600160a01b03166001600160a01b031614611c73576040805162461bcd60e51b815260206004820152601c60248201526000805160206145ea833981519152604482015290519081900360640190fd5b60003490507f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd6001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b158015611cd357600080fd5b505af1158015611ce7573d6000803e3d6000fd5b50505050507f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd6001600160a01b031663a9059cbb611d4c7f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d898960008181106112f857fe5b836040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b158015611d9c57600080fd5b505af1158015611db0573d6000803e3d6000fd5b505050506040513d6020811015611dc657600080fd5b5051611dce57fe5b600086866000198101818110611de057fe5b905060200201356001600160a01b03166001600160a01b03166370a08231866040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b158015611e4557600080fd5b505afa158015611e59573d6000803e3d6000fd5b505050506040513d6020811015611e6f57600080fd5b50516040805160208981028281018201909352898252929350611eb19290918a918a918291850190849080828437600092019190915250899250613a19915050565b8761190c8289896000198101818110611ec657fe5b905060200201356001600160a01b03166001600160a01b03166370a08231896040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156118d457600080fd5b60608142811015611f71576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b6001600160a01b037f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd1686866000198101818110611fab57fe5b905060200201356001600160a01b03166001600160a01b031614612004576040805162461bcd60e51b815260206004820152601c60248201526000805160206145ea833981519152604482015290519081900360640190fd5b6120627f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d898888808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506133f292505050565b9150868260008151811061207257fe5b602002602001015111156120b75760405162461bcd60e51b81526004018080602001828103825260268152602001806144626026913960400191505060405180910390fd5b6120c78686600081811061151557fe5b61210682878780806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250309250613676915050565b7f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd6001600160a01b031663f3fef3a3308460018651038151811061214657fe5b60200260200101516040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050600060405180830381600087803b15801561219d57600080fd5b505af11580156121b1573d6000803e3d6000fd5b50505050610e3584836001855103815181106121c957fe5b602002602001015161323a565b6060814281101561221c576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b7f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd6001600160a01b03168686600081811061225357fe5b905060200201356001600160a01b03166001600160a01b0316146122ac576040805162461bcd60e51b815260206004820152601c60248201526000805160206145ea833981519152604482015290519081900360640190fd5b61230a7f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d888888808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506133f292505050565b9150348260008151811061231a57fe5b6020026020010151111561235f5760405162461bcd60e51b81526004018080602001828103825260268152602001806144626026913960400191505060405180910390fd5b7f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd6001600160a01b031663d0e30db08360008151811061239b57fe5b60200260200101516040518263ffffffff1660e01b81526004016000604051808303818588803b1580156123ce57600080fd5b505af11580156123e2573d6000803e3d6000fd5b50505050507f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd6001600160a01b031663a9059cbb6124477f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d898960008181106112f857fe5b8460008151811061245457fe5b60200260200101516040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b1580156124ab57600080fd5b505af11580156124bf573d6000803e3d6000fd5b505050506040513d60208110156124d557600080fd5b50516124dd57fe5b61251c82878780806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250899250613676915050565b8160008151811061252957fe5b60200260200101513411156113ff576113ff338360008151811061254957fe5b6020026020010151340361323a565b6000610ca4848484613e64565b60008082428110156125ac576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b60006125d97f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d8c8c613332565b604080516323b872dd60e01b81523360048201526001600160a01b03831660248201819052604482018d9052915192935090916323b872dd916064808201926020929091908290030181600087803b15801561263457600080fd5b505af1158015612648573d6000803e3d6000fd5b505050506040513d602081101561265e57600080fd5b50506040805163226bf2d160e21b81526001600160a01b03888116600483015282516000938493928616926389afcb44926024808301939282900301818787803b1580156126ab57600080fd5b505af11580156126bf573d6000803e3d6000fd5b505050506040513d60408110156126d557600080fd5b508051602090910151909250905060006126ef8e8e613f10565b509050806001600160a01b03168e6001600160a01b031614612712578183612715565b82825b90975095508a8710156127595760405162461bcd60e51b81526004018080602001828103825260258152602001806145096025913960400191505060405180910390fd5b898610156127985760405162461bcd60e51b81526004018080602001828103825260258152602001806144886025913960400191505060405180910390fd5b505050505097509795505050505050565b600080600083428110156127f2576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b6128208a7f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd8b348c8c613fee565b909450925060006128727f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d8c7f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd613332565b90506128808b3383886138bc565b7f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd6001600160a01b031663d0e30db0856040518263ffffffff1660e01b81526004016000604051808303818588803b1580156128db57600080fd5b505af11580156128ef573d6000803e3d6000fd5b50505050507f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd6001600160a01b031663a9059cbb82866040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561297457600080fd5b505af1158015612988573d6000803e3d6000fd5b505050506040513d602081101561299e57600080fd5b50516129a657fe5b806001600160a01b0316636a627842886040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b03168152602001915050602060405180830381600087803b1580156129fe57600080fd5b505af1158015612a12573d6000803e3d6000fd5b505050506040513d6020811015612a2857600080fd5b5051925034841015612a4057612a403385340361323a565b505096509650969350505050565b7f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d81565b6060610f817f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d848461353f565b60608142811015612ae5576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b6001600160a01b037f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd1686866000198101818110612b1f57fe5b905060200201356001600160a01b03166001600160a01b031614612b78576040805162461bcd60e51b815260206004820152601c60248201526000805160206145ea833981519152604482015290519081900360640190fd5b612bd67f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d8988888080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525061353f92505050565b91508682600184510381518110612be957fe5b602002602001015110156120b75760405162461bcd60e51b815260040180806020018281038252602a815260200180614407602a913960400191505060405180910390fd5b60008060008342811015612c77576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b612c858c8c8c8c8c8c613fee565b90945092506000612cb77f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d8e8e613332565b9050612cc58d3383886138bc565b612cd18c3383876138bc565b806001600160a01b0316636a627842886040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b03168152602001915050602060405180830381600087803b158015612d2957600080fd5b505af1158015612d3d573d6000803e3d6000fd5b505050506040513d6020811015612d5357600080fd5b5051949d939c50939a509198505050505050505050565b8042811015612dae576040805162461bcd60e51b81526020600482015260176024820152600080516020614555833981519152604482015290519081900360640190fd5b6001600160a01b037f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd1685856000198101818110612de857fe5b905060200201356001600160a01b03166001600160a01b031614612e41576040805162461bcd60e51b815260206004820152601c60248201526000805160206145ea833981519152604482015290519081900360640190fd5b612e518585600081811061172f57fe5b612e8f858580806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250309250613a19915050565b604080516370a0823160e01b815230600482015290516000916001600160a01b037f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd16916370a0823191602480820192602092909190829003018186803b158015612ef957600080fd5b505afa158015612f0d573d6000803e3d6000fd5b505050506040513d6020811015612f2357600080fd5b5051905086811015612f665760405162461bcd60e51b815260040180806020018281038252602a815260200180614407602a913960400191505060405180910390fd5b6040805163f3fef3a360e01b81523060048201526024810183905290516001600160a01b037f00000000000000000000000080b5a32e4f032b2a058b4f29ec95eefeeb87adcd169163f3fef3a391604480830192600092919082900301818387803b158015612fd457600080fd5b505af1158015612fe8573d6000803e3d6000fd5b50505050611949848261323a565b60008084116130365760405162461bcd60e51b815260040180806020018281038252602a8152602001806144ad602a913960400191505060405180910390fd5b6000831180156130465750600082115b6130815760405162461bcd60e51b815260040180806020018281038252602781526020018061452e6027913960400191505060405180910390fd5b6000613095856103e563ffffffff61426216565b905060006130a9828563ffffffff61426216565b905060006130cf836130c3886103e863ffffffff61426216565b9063ffffffff6142c516565b90508082816130da57fe5b04979650505050505050565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b178152925182516000946060949389169392918291908083835b602083106131635780518252601f199092019160209182019101613144565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146131c5576040519150601f19603f3d011682016040523d82523d6000602084013e6131ca565b606091505b50915091508180156131f85750805115806131f857508080602001905160208110156131f557600080fd5b50515b6132335760405162461bcd60e51b815260040180806020018281038252602d8152602001806145bd602d913960400191505060405180910390fd5b5050505050565b604080516000808252602082019092526001600160a01b0384169083906040518082805190602001908083835b602083106132865780518252601f199092019160209182019101613267565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146132e8576040519150601f19603f3d011682016040523d82523d6000602084013e6132ed565b606091505b505090508061332d5760405162461bcd60e51b81526004018080602001828103825260328152602001806144d76032913960400191505060405180910390fd5b505050565b60008060006133418585613f10565b604080516bffffffffffffffffffffffff19606094851b811660208084019190915293851b81166034830152825160288184030181526048830184528051908501206001600160f81b031960688401529a90941b9093166069840152607d8301989098527f89bbd161b7f9309df13e388d6b1f71f5ff07259b5149560e726a4df10971bceb609d808401919091528851808403909101815260bd909201909752805196019590952095945050505050565b606060028251101561344b576040805162461bcd60e51b815260206004820152601d60248201527f46585377617056324c6962726172793a20494e56414c49445f50415448000000604482015290519081900360640190fd5b815167ffffffffffffffff8111801561346357600080fd5b5060405190808252806020026020018201604052801561348d578160200160208202803683370190505b50905082816001835103815181106134a157fe5b60209081029190910101528151600019015b8015613537576000806134f0878660018603815181106134cf57fe5b60200260200101518786815181106134e357fe5b6020026020010151614314565b9150915061351284848151811061350357fe5b60200260200101518383613d74565b84600185038151811061352157fe5b60209081029190910101525050600019016134b3565b509392505050565b6060600282511015613598576040805162461bcd60e51b815260206004820152601d60248201527f46585377617056324c6962726172793a20494e56414c49445f50415448000000604482015290519081900360640190fd5b815167ffffffffffffffff811180156135b057600080fd5b506040519080825280602002602001820160405280156135da578160200160208202803683370190505b50905082816000815181106135eb57fe5b60200260200101818152505060005b6001835103811015613537576000806136308786858151811061361957fe5b60200260200101518786600101815181106134e357fe5b9150915061365284848151811061364357fe5b60200260200101518383612ff6565b84846001018151811061366157fe5b602090810291909101015250506001016135fa565b60005b60018351038110156138b65760008084838151811061369457fe5b60200260200101518584600101815181106136ab57fe5b60200260200101519150915060006136c38383613f10565b50905060008785600101815181106136d757fe5b60200260200101519050600080836001600160a01b0316866001600160a01b03161461370557826000613709565b6000835b91509150600060028a510388106137205788613761565b6137617f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d878c8b6002018151811061375457fe5b6020026020010151613332565b905061378e7f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d8888613332565b6001600160a01b031663022c0d9f84848460006040519080825280601f01601f1916602001820160405280156137cb576020820181803683370190505b506040518563ffffffff1660e01b815260040180858152602001848152602001836001600160a01b03166001600160a01b0316815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561383c578181015183820152602001613824565b50505050905090810190601f1680156138695780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801561388b57600080fd5b505af115801561389f573d6000803e3d6000fd5b505060019099019850613679975050505050505050565b50505050565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b17815292518251600094606094938a169392918291908083835b602083106139415780518252601f199092019160209182019101613922565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146139a3576040519150601f19603f3d011682016040523d82523d6000602084013e6139a8565b606091505b50915091508180156139d65750805115806139d657508080602001905160208110156139d357600080fd5b50515b613a115760405162461bcd60e51b81526004018080602001828103825260318152602001806144316031913960400191505060405180910390fd5b505050505050565b60005b600183510381101561332d57600080848381518110613a3757fe5b6020026020010151858460010181518110613a4e57fe5b6020026020010151915091506000613a668383613f10565b5090506000613a967f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d8585613332565b9050600080600080846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015613ad757600080fd5b505afa158015613aeb573d6000803e3d6000fd5b505050506040513d6060811015613b0157600080fd5b5080516020909101516001600160701b0391821693501690506000806001600160a01b038a811690891614613b37578284613b3a565b83835b91509150613b98828b6001600160a01b03166370a082318a6040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156118d457600080fd5b9550613ba5868383612ff6565b945050505050600080856001600160a01b0316886001600160a01b031614613bcf57826000613bd3565b6000835b91509150600060028c51038a10613bea578a613c1e565b613c1e7f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d898e8d6002018151811061375457fe5b604080516000808252602082019283905263022c0d9f60e01b835260248201878152604483018790526001600160a01b038086166064850152608060848501908152845160a48601819052969750908c169563022c0d9f958a958a958a9591949193919260c486019290918190849084905b83811015613ca8578181015183820152602001613c90565b50505050905090810190601f168015613cd55780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b158015613cf757600080fd5b505af1158015613d0b573d6000803e3d6000fd5b50506001909b019a50613a1c9950505050505050505050565b80820382811115610f84576040805162461bcd60e51b815260206004820152601560248201527464732d6d6174682d7375622d756e646572666c6f7760581b604482015290519081900360640190fd5b6000808411613db45760405162461bcd60e51b815260040180806020018281038252602b8152602001806143dc602b913960400191505060405180910390fd5b600083118015613dc45750600082115b613dff5760405162461bcd60e51b815260040180806020018281038252602781526020018061452e6027913960400191505060405180910390fd5b6000613e236103e8613e17868863ffffffff61426216565b9063ffffffff61426216565b90506000613e3d6103e5613e17868963ffffffff613d2416565b9050613e5a6001828481613e4d57fe5b049063ffffffff6142c516565b9695505050505050565b6000808411613ea45760405162461bcd60e51b81526004018080602001828103825260248152602001806145996024913960400191505060405180910390fd5b600083118015613eb45750600082115b613eef5760405162461bcd60e51b815260040180806020018281038252602781526020018061452e6027913960400191505060405180910390fd5b82613f00858463ffffffff61426216565b81613f0757fe5b04949350505050565b600080826001600160a01b0316846001600160a01b03161415613f645760405162461bcd60e51b81526004018080602001828103825260248152602001806145756024913960400191505060405180910390fd5b826001600160a01b0316846001600160a01b031610613f84578284613f87565b83835b90925090506001600160a01b038216613fe7576040805162461bcd60e51b815260206004820152601d60248201527f46585377617056324c6962726172793a205a45524f5f41444452455353000000604482015290519081900360640190fd5b9250929050565b6040805163e6a4390560e01b81526001600160a01b03888116600483015287811660248301529151600092839283927f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d9092169163e6a4390591604480820192602092909190829003018186803b15801561406857600080fd5b505afa15801561407c573d6000803e3d6000fd5b505050506040513d602081101561409257600080fd5b50516001600160a01b0316141561414557604080516364e329cb60e11b81526001600160a01b038a81166004830152898116602483015291517f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d9092169163c9c65396916044808201926020929091908290030181600087803b15801561411857600080fd5b505af115801561412c573d6000803e3d6000fd5b505050506040513d602081101561414257600080fd5b50505b6000806141737f000000000000000000000000d55b6952be7d52f315246afd4cc64822d2b3d34d8b8b614314565b91509150816000148015614185575080155b1561419557879350869250614255565b60006141a2898484613e64565b90508781116141f557858110156141ea5760405162461bcd60e51b81526004018080602001828103825260258152602001806144886025913960400191505060405180910390fd5b889450925082614253565b6000614202898486613e64565b90508981111561420e57fe5b8781101561424d5760405162461bcd60e51b81526004018080602001828103825260258152602001806145096025913960400191505060405180910390fd5b94508793505b505b5050965096945050505050565b600081158061427d5750508082028282828161427a57fe5b04145b610f84576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6d756c2d6f766572666c6f7760601b604482015290519081900360640190fd5b80820182811015610f84576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6164642d6f766572666c6f7760601b604482015290519081900360640190fd5b60008060006143238585613f10565b509050600080614334888888613332565b6001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b15801561436c57600080fd5b505afa158015614380573d6000803e3d6000fd5b505050506040513d606081101561439657600080fd5b5080516020909101516001600160701b0391821693501690506001600160a01b03878116908416146143c95780826143cc565b81815b9099909850965050505050505056fe46585377617056324c6962726172793a20494e53554646494349454e545f4f55545055545f414d4f554e544658537761705632526f757465723a20494e53554646494349454e545f4f55545055545f414d4f554e545472616e7366657248656c7065723a3a7472616e7366657246726f6d3a207472616e7366657246726f6d206661696c65644658537761705632526f757465723a204558434553534956455f494e5055545f414d4f554e544658537761705632526f757465723a20494e53554646494349454e545f425f414d4f554e5446585377617056324c6962726172793a20494e53554646494349454e545f494e5055545f414d4f554e545472616e7366657248656c7065723a3a736166655472616e7366657246583a204658207472616e73666572206661696c65644658537761705632526f757465723a20494e53554646494349454e545f415f414d4f554e5446585377617056324c6962726172793a20494e53554646494349454e545f4c49515549444954594658537761705632526f757465723a204558504952454400000000000000000046585377617056324c6962726172793a204944454e544943414c5f41444452455353455346585377617056324c6962726172793a20494e53554646494349454e545f414d4f554e545472616e7366657248656c7065723a3a736166655472616e736665723a207472616e73666572206661696c65644658537761705632526f757465723a20494e56414c49445f5041544800000000a2646970667358221220998098d9101c4955f14434aa4692b1cc2d17013dc735c90e0944e1d65734fed364736f6c63430006060033