diff --git a/contracts/interfaces/external/IDMMFactory.sol b/contracts/interfaces/external/IDMMFactory.sol new file mode 100644 index 000000000..e58d87770 --- /dev/null +++ b/contracts/interfaces/external/IDMMFactory.sol @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.6.10; + +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; + +interface IDMMFactory { + function createPool( + IERC20 tokenA, + IERC20 tokenB, + uint32 ampBps + ) external returns (address pool); + + function setFeeConfiguration(address feeTo, uint16 governmentFeeBps) external; + + function setFeeToSetter(address) external; + + function getFeeConfiguration() external view returns (address feeTo, uint16 governmentFeeBps); + + function feeToSetter() external view returns (address); + + function allPools(uint256) external view returns (address pool); + + function allPoolsLength() external view returns (uint256); + + function getUnamplifiedPool(IERC20 token0, IERC20 token1) external view returns (address); + + function getPools(IERC20 token0, IERC20 token1) + external + view + returns (address[] memory _tokenPools); + + function isPool( + IERC20 token0, + IERC20 token1, + address pool + ) external view returns (bool); +} diff --git a/contracts/interfaces/external/IDMMPool.sol b/contracts/interfaces/external/IDMMPool.sol new file mode 100644 index 000000000..1a29a69c4 --- /dev/null +++ b/contracts/interfaces/external/IDMMPool.sol @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.6.10; + +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; + +import "./IDMMFactory.sol"; + +interface IDMMPool { + function mint(address to) external returns (uint256 liquidity); + + function burn(address to) external returns (uint256 amount0, uint256 amount1); + + function swap( + uint256 amount0Out, + uint256 amount1Out, + address to, + bytes calldata data + ) external; + + function sync() external; + + function getReserves() external view returns (uint112 reserve0, uint112 reserve1); + + function getTradeInfo() + external + view + returns ( + uint112 _vReserve0, + uint112 _vReserve1, + uint112 reserve0, + uint112 reserve1, + uint256 feeInPrecision + ); + + function token0() external view returns (IERC20); + + function token1() external view returns (IERC20); + + function ampBps() external view returns (uint32); + + function factory() external view returns (IDMMFactory); + + function kLast() external view returns (uint256); +} \ No newline at end of file diff --git a/contracts/protocol/integration/index-exchange/KyberV3IndexExchangeAdapter.sol b/contracts/protocol/integration/index-exchange/KyberV3IndexExchangeAdapter.sol new file mode 100644 index 000000000..d58e3c70f --- /dev/null +++ b/contracts/protocol/integration/index-exchange/KyberV3IndexExchangeAdapter.sol @@ -0,0 +1,139 @@ +/* + Copyright 2021 Set Labs Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + SPDX-License-Identifier: Apache License, Version 2.0 +*/ + +pragma solidity 0.6.10; +pragma experimental "ABIEncoderV2"; + +import { BytesLib } from "external/contracts/uniswap/v3/lib/BytesLib.sol"; +import { IDMMFactory } from "../../../interfaces/external/IDMMFactory.sol"; +import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import { IIndexExchangeAdapter } from "../../../interfaces/IIndexExchangeAdapter.sol"; + +/** + * @title KyberV3IndexExchangeAdapter + * @author Set Protocol + * + * A Kyber V3 DMM exchange adapter that returns calldata for trading with GeneralIndexModule, allows encoding a trade with a fixed input quantity or + * a fixed output quantity. + */ +contract KyberV3IndexExchangeAdapter is IIndexExchangeAdapter { + + using BytesLib for bytes; + + /* ============ Constants ============ */ + + // DMMRouter function string for swapping exact tokens for a minimum of receive tokens + string internal constant SWAP_EXACT_TOKENS_FOR_TOKENS = "swapExactTokensForTokens(uint256,uint256,address[],address[],address,uint256)"; + // DMMRouter function string for swapping tokens for an exact amount of receive tokens + string internal constant SWAP_TOKENS_FOR_EXACT_TOKENS = "swapTokensForExactTokens(uint256,uint256,address[],address[],address,uint256)"; + + /* ============ State Variables ============ */ + + address public immutable dmmRouter; + IDMMFactory public immutable dmmFactory; + + /* ============ Constructor ============ */ + + /** + * Set state variables + * + * @param _dmmRouter Address of Kyber V3 DMM Router + * @param _dmmFactory Address of Kyber V3 DMM Factory + */ + constructor(address _dmmRouter, IDMMFactory _dmmFactory) public { + dmmRouter = _dmmRouter; + dmmFactory = _dmmFactory; + } + + /* ============ External Getter Functions ============ */ + + /** + * Return calldata for trading with Kyber V3 DMM Router. Trade paths are created from _sourceToken and + * _destinationToken. On Kyber DMM exchange, for each token pair, there can be possibly many multiple pools with + * different configurations for the pricing curve. Hence the address of the pool to be used for trading must be passed + * in the _data parameter. + * + * --------------------------------------------------------------------------------------------------------------- + * _isSendTokenFixed | Parameter | Amount | + * --------------------------------------------------------------------------------------------------------------- + * True | _sourceQuantity | Fixed amount of _sourceToken to trade | + * | _destinationQuantity | Minimum amount of _destinationToken willing to receive | + * --------------------------------------------------------------------------------------------------------------- + * False | _sourceQuantity | Maximum amount of _sourceToken to trade | + * | _destinationQuantity | Fixed amount of _destinationToken want to receive | + * --------------------------------------------------------------------------------------------------------------- + * + * @param _sourceToken Address of source token to be sold + * @param _destinationToken Address of destination token to buy + * @param _destinationAddress Address that assets should be transferred to + * @param _isSendTokenFixed Boolean indicating if the send quantity is fixed, used to determine correct trade interface + * @param _sourceQuantity Fixed/Max amount of source token to sell + * @param _destinationQuantity Min/Fixed amount of destination token to buy + * @param _data Arbitray bytes containing the pool address to be used for trading. Can use + * `getPoolWithBestLiquidity()` to get the most liquid pool for a given pair of tokens + * on the Kyber DMM exchange. + * + * @return address Target contract address + * @return uint256 Call value + * @return bytes Trade calldata + */ + function getTradeCalldata( + address _sourceToken, + address _destinationToken, + address _destinationAddress, + bool _isSendTokenFixed, + uint256 _sourceQuantity, + uint256 _destinationQuantity, + bytes memory _data + ) + external + view + override + returns (address, uint256, bytes memory) + { + + address[] memory path = new address[](2); + path[0] = _sourceToken; + path[1] = _destinationToken; + + address[] memory poolsPath = new address[](1); + poolsPath[0] = _data.toAddress(0); + + require(dmmFactory.isPool(IERC20(_sourceToken), IERC20(_destinationToken), poolsPath[0]), "Invalid pool address"); + + bytes memory callData = abi.encodeWithSignature( + _isSendTokenFixed ? SWAP_EXACT_TOKENS_FOR_TOKENS : SWAP_TOKENS_FOR_EXACT_TOKENS, + _isSendTokenFixed ? _sourceQuantity : _destinationQuantity, + _isSendTokenFixed ? _destinationQuantity : _sourceQuantity, + poolsPath, + path, + _destinationAddress, + block.timestamp + ); + return (dmmRouter, 0, callData); + } + + /** + * Returns the address to approve source tokens to for trading. This is the Kyber DMM Router. + * + * @return address Address of the contract to approve tokens to + */ + function getSpender() external view override returns (address) { + return dmmRouter; + } +} \ No newline at end of file diff --git a/external/abi/kyber/DMMFactory.json b/external/abi/kyber/DMMFactory.json new file mode 100644 index 000000000..12838d060 --- /dev/null +++ b/external/abi/kyber/DMMFactory.json @@ -0,0 +1,343 @@ +{ + + "contractName": "DMMFactory", + "abi": [ + { + "inputs": [ + { + "internalType": "address", + "name": "_feeToSetter", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "contract IERC20", + "name": "token0", + "type": "address" + }, + { + "indexed": true, + "internalType": "contract IERC20", + "name": "token1", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint32", + "name": "ampBps", + "type": "uint32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "totalPool", + "type": "uint256" + } + ], + "name": "PoolCreated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "feeTo", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint16", + "name": "governmentFeeBps", + "type": "uint16" + } + ], + "name": "SetFeeConfiguration", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "feeToSetter", + "type": "address" + } + ], + "name": "SetFeeToSetter", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "allPools", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "allPoolsLength", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "tokenA", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "tokenB", + "type": "address" + }, + { + "internalType": "uint32", + "name": "ampBps", + "type": "uint32" + } + ], + "name": "createPool", + "outputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "feeToSetter", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getFeeConfiguration", + "outputs": [ + { + "internalType": "address", + "name": "_feeTo", + "type": "address" + }, + { + "internalType": "uint16", + "name": "_governmentFeeBps", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "token0", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "token1", + "type": "address" + }, + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "getPoolAtIndex", + "outputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "token0", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "token1", + "type": "address" + } + ], + "name": "getPools", + "outputs": [ + { + "internalType": "address[]", + "name": "_tokenPools", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "token0", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "token1", + "type": "address" + } + ], + "name": "getPoolsLength", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "", + "type": "address" + } + ], + "name": "getUnamplifiedPool", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "token0", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "token1", + "type": "address" + }, + { + "internalType": "address", + "name": "pool", + "type": "address" + } + ], + "name": "isPool", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_feeTo", + "type": "address" + }, + { + "internalType": "uint16", + "name": "_governmentFeeBps", + "type": "uint16" + } + ], + "name": "setFeeConfiguration", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_feeToSetter", + "type": "address" + } + ], + "name": "setFeeToSetter", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ], + "bytecode": "0x608060405234801561001057600080fd5b50604051615e62380380615e628339818101604052602081101561003357600080fd5b5051600180546001600160a01b0319166001600160a01b03909216919091179055615dff806100636000396000f3fe60806040523480156200001157600080fd5b5060043610620000e85760003560e01c806365da9289116200008d578063ad5cb2e11162000063578063ad5cb2e11462000369578063eb787f6114620003a6578063efde4e64146200040257620000e8565b806365da928914620002a05780638fd6484014620002e6578063a2e74af6146200033357620000e8565b806341d1de9711620000c357806341d1de9714620001a0578063538633df14620001c05780635b1dc86f146200021057620000e8565b8063094b741514620000ed5780632900909d14620001205780633d82497e1462000162575b600080fd5b620000f76200040c565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b62000160600480360360408110156200013857600080fd5b50803573ffffffffffffffffffffffffffffffffffffffff16906020013561ffff1662000428565b005b620000f7600480360360408110156200017a57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516620005f9565b620000f760048036036020811015620001b857600080fd5b50356200062c565b620001fe60048036036040811015620001d857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602001351662000661565b60408051918252519081900360200190f35b6200024e600480360360408110156200022857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516620006a9565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156200028c57818101518382015260200162000272565b505050509050019250505060405180910390f35b620000f760048036036060811015620002b857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060400135620007c1565b620000f760048036036060811015620002fe57600080fd5b50803573ffffffffffffffffffffffffffffffffffffffff908116916020810135909116906040013563ffffffff1662000809565b62000160600480360360208110156200034b57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1662000d51565b6200037362000e51565b6040805173ffffffffffffffffffffffffffffffffffffffff909316835261ffff90911660208301528051918290030190f35b620003ee60048036036060811015620003be57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101358216916040909101351662000e8c565b604080519115158252519081900360200190f35b620001fe62000ecc565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b60015473ffffffffffffffffffffffffffffffffffffffff163314620004af57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f444d4d3a20464f5242494444454e000000000000000000000000000000000000604482015290519081900360640190fd5b60008161ffff16118015620004c957506107d08161ffff16105b6200053557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f444d4d3a20494e56414c49442046454500000000000000000000000000000000604482015290519081900360640190fd5b6000805461ffff83167401000000000000000000000000000000000000000081027fffffffffffffffffffff0000ffffffffffffffffffffffffffffffffffffffff73ffffffffffffffffffffffffffffffffffffffff87167fffffffffffffffffffffffff00000000000000000000000000000000000000009094168417161790925560408051918252602082019290925281517fce65ee4e1b50c25affcecb736ecf577b5c46ff900efade2a6214267a8707628e929181900390910190a15050565b600360209081526000928352604080842090915290825290205473ffffffffffffffffffffffffffffffffffffffff1681565b600481815481106200063a57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16905081565b73ffffffffffffffffffffffffffffffffffffffff80831660009081526002602090815260408083209385168352929052908120620006a09062000ed2565b90505b92915050565b73ffffffffffffffffffffffffffffffffffffffff8083166000908152600260209081526040808320938516835292905290812060609190620006ec9062000ed2565b90508067ffffffffffffffff811180156200070657600080fd5b5060405190808252806020026020018201604052801562000731578160200160208202803683370190505b50915060005b81811015620007b95773ffffffffffffffffffffffffffffffffffffffff80861660009081526002602090815260408083209388168352929052206200077e908262000edf565b8382815181106200078b57fe5b73ffffffffffffffffffffffffffffffffffffffff9092166020928302919091019091015260010162000737565b505092915050565b73ffffffffffffffffffffffffffffffffffffffff8084166000908152600260209081526040808320938616835292905290812062000801908362000edf565b949350505050565b60008273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161415620008a757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f444d4d3a204944454e544943414c5f4144445245535345530000000000000000604482015290519081900360640190fd5b6000808473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff1610620008e6578486620008e9565b85855b909250905073ffffffffffffffffffffffffffffffffffffffff82166200097157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f444d4d3a205a45524f5f41444452455353000000000000000000000000000000604482015290519081900360640190fd5b6127108463ffffffff161015620009e957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f444d4d3a20494e56414c49445f42505300000000000000000000000000000000604482015290519081900360640190fd5b6127108463ffffffff1614158062000a33575073ffffffffffffffffffffffffffffffffffffffff8281166000908152600360209081526040808320858516845290915290205416155b62000a9f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f444d4d3a20554e414d504c49464945445f504f4f4c5f45584953545300000000604482015290519081900360640190fd5b60405162000aad9062001021565b604051809103906000f08015801562000aca573d6000803e3d6000fd5b5092508273ffffffffffffffffffffffffffffffffffffffff16636ecf2b228383876040518463ffffffff1660e01b8152600401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018263ffffffff1681526020019350505050600060405180830381600087803b15801562000b6357600080fd5b505af115801562000b78573d6000803e3d6000fd5b50505073ffffffffffffffffffffffffffffffffffffffff808416600090815260026020908152604080832093861683529290522062000bba91508462000eed565b5073ffffffffffffffffffffffffffffffffffffffff808216600090815260026020908152604080832093861683529290522062000bf9908462000eed565b506127108463ffffffff16141562000c845773ffffffffffffffffffffffffffffffffffffffff8083166000818152600360208181526040808420878716855282528084208054968a167fffffffffffffffffffffffff0000000000000000000000000000000000000000978816811790915592825280842094845293905291902080549092161790555b6004805460018101825560008290527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b01805473ffffffffffffffffffffffffffffffffffffffff8087167fffffffffffffffffffffffff0000000000000000000000000000000000000000909216821790925591546040805193845263ffffffff88166020850152838101919091525183821692918516917ffc574402c445e75f2b79b67884ff9c662244dce454c5ae68935fcd0bebb7c8ff919081900360600190a350509392505050565b60015473ffffffffffffffffffffffffffffffffffffffff16331462000dd857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f444d4d3a20464f5242494444454e000000000000000000000000000000000000604482015290519081900360640190fd5b6001805473ffffffffffffffffffffffffffffffffffffffff83167fffffffffffffffffffffffff0000000000000000000000000000000000000000909116811790915560408051918252517f66330d9620e4f36ed52d5f7b79fa819b71c33037004c3889a3601b06c68da7cc9181900360200190a150565b60005473ffffffffffffffffffffffffffffffffffffffff8116917401000000000000000000000000000000000000000090910461ffff1690565b73ffffffffffffffffffffffffffffffffffffffff8084166000908152600260209081526040808320938616835292905290812062000801908362000f11565b60045490565b6000620006a38262000f35565b6000620006a0838362000f39565b6000620006a08373ffffffffffffffffffffffffffffffffffffffff841662000fba565b6000620006a08373ffffffffffffffffffffffffffffffffffffffff841662001009565b5490565b8154600090821062000f97576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602281526020018062005da86022913960400191505060405180910390fd5b82600001828154811062000fa757fe5b9060005260206000200154905092915050565b600062000fc8838362001009565b6200100057508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155620006a3565b506000620006a3565b60009081526001919091016020526040902054151590565b614d7880620010308339019056fe60806040523480156200001157600080fd5b5060006040518060400160405280600b81526020016a04b79626572444d4d204c560ac1b815250604051806040016040528060068152602001650444d4d2d4c560d41b815250604051806040016040528060018152602001603160f81b815250828281600390805190602001906200008b929190620001ee565b508051620000a1906004906020840190620001ee565b50506005805460ff19166012179055508251602093840120815191840191909120604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f818701528082019390935260608301919091524660808301523060a0808401919091528151808403909101815260c09092019052805192019190912060065550600160085560098054600160801b6001600160801b038085169182026001600160801b03199093169190911716179055620001624362000198565b600a80546001600160801b03928316600160801b02921691909117905550600b80546001600160a01b0319163317905562000280565b60006001600160801b03821115620001ea576040805162461bcd60e51b815260206004820152601060248201526f0deeccae4ccd8deee40ead2dce86264760831b604482015290519081900360640190fd5b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200023157805160ff191683800117855562000261565b8280016001018555821562000261579182015b828111156200026157825182559160200191906001019062000244565b50620001ea9291505b80821115620001ea57600081556001016200026a565b614ae880620002906000396000f3fe608060405234801561001057600080fd5b50600436106101da5760003560e01c80637464fc3d11610104578063bc25cf77116100a2578063d669402711610071578063d669402714610736578063dd62ed3e14610780578063f698da25146107bb578063fff6cae9146107c3576101da565b8063bc25cf7714610695578063c45a0155146106c8578063d21220a7146106d0578063d505accf146106d8576101da565b806395d89b41116100de57806395d89b4114610613578063a457c2d71461061b578063a9059cbb14610654578063ba9a7a561461068d576101da565b80637464fc3d1461058c5780637ecebe001461059457806389afcb44146105c7576101da565b806323b872dd1161017c57806349386b161161014b57806349386b16146104bb5780636a627842146104dc5780636ecf2b221461050f57806370a0823114610559576101da565b806323b872dd1461041957806330adf81f1461045c578063313ce567146104645780633950935114610482576101da565b8063095ea7b3116101b8578063095ea7b31461033c5780630d94d50b146103895780630dfe1681146103ce57806318160ddd146103ff576101da565b8063022c0d9f146101df57806306fdde031461027a5780630902f1ac146102f7575b600080fd5b610278600480360360808110156101f557600080fd5b81359160208101359173ffffffffffffffffffffffffffffffffffffffff604083013516919081019060808101606082013564010000000081111561023957600080fd5b82018360208201111561024b57600080fd5b8035906020019184600183028401116401000000008311171561026d57600080fd5b5090925090506107cb565b005b610282610e6a565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102bc5781810151838201526020016102a4565b50505050905090810190601f1680156102e95780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102ff611282565b60405180836dffffffffffffffffffffffffffff168152602001826dffffffffffffffffffffffffffff1681526020019250505060405180910390f35b6103756004803603604081101561035257600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356112af565b604080519115158252519081900360200190f35b6103916112cd565b604080516fffffffffffffffffffffffffffffffff9586168152938516602085015291841683830152909216606082015290519081900360800190f35b6103d661130c565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b610407611328565b60408051918252519081900360200190f35b6103756004803603606081101561042f57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020810135909116906040013561132e565b6104076113d0565b61046c6113f4565b6040805160ff9092168252519081900360200190f35b6103756004803603604081101561049857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356113fd565b6104c3611458565b6040805163ffffffff9092168252519081900360200190f35b610407600480360360208110156104f257600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611484565b6102786004803603606081101561052557600080fd5b50803573ffffffffffffffffffffffffffffffffffffffff908116916020810135909116906040013563ffffffff166118f4565b6104076004803603602081101561056f57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611a22565b610407611a4e565b610407600480360360208110156105aa57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611a54565b6105fa600480360360208110156105dd57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611a66565b6040805192835260208301919091528051918290030190f35b610282612044565b6103756004803603604081101561063157600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813516906020013561238c565b6103756004803603604081101561066a57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135612401565b610407612415565b610278600480360360208110156106ab57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661241b565b6103d661263d565b6103d6612659565b610278600480360360e08110156106ee57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135612675565b61073e612941565b604080516dffffffffffffffffffffffffffff968716815294861660208601529285168484015293166060830152608082019290925290519081900360a00190f35b6104076004803603604081101561079657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160200135166129dd565b610407612a15565b610278612a1b565b6002600854141561083d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b6002600855841515806108505750600084115b6108bb57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f444d4d3a20494e53554646494349454e545f4f55545055545f414d4f554e5400604482015290519081900360640190fd5b60006108c5614891565b6108cd612cd8565b80519193509150871080156108e55750806020015186105b61095057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f444d4d3a20494e53554646494349454e545f4c49515549444954590000000000604482015290519081900360640190fd5b610958614891565b600c54600d5473ffffffffffffffffffffffffffffffffffffffff9182169190811690881682148015906109b857508073ffffffffffffffffffffffffffffffffffffffff168873ffffffffffffffffffffffffffffffffffffffff1614155b610a2357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f444d4d3a20494e56414c49445f544f0000000000000000000000000000000000604482015290519081900360640190fd5b8915610a4a57610a4a73ffffffffffffffffffffffffffffffffffffffff8316898c612d7c565b8815610a7157610a7173ffffffffffffffffffffffffffffffffffffffff8216898b612d7c565b8515610b3d578773ffffffffffffffffffffffffffffffffffffffff166381279c7e338c8c8b8b6040518663ffffffff1660e01b8152600401808673ffffffffffffffffffffffffffffffffffffffff168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b158015610b2457600080fd5b505af1158015610b38573d6000803e3d6000fd5b505050505b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8416916370a08231916024808301926020929190829003018186803b158015610ba957600080fd5b505afa158015610bbd573d6000803e3d6000fd5b505050506040513d6020811015610bd357600080fd5b50518352604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8316916370a08231916024808301926020929190829003018186803b158015610c4357600080fd5b505afa158015610c57573d6000803e3d6000fd5b505050506040513d6020811015610c6d57600080fd5b505160208401528415610cc157835183516040860151610c989291610c929190612e0e565b90612e82565b6040840152602080850151908401516060860151610cbb9291610c929190612e0e565b60608401525b5050815181516000918a900310610cd9576000610ce4565b82518251908a900390035b9050600088846020015103836020015111610d00576000610d0e565b888460200151038360200151035b90506000821180610d1f5750600081115b610d8a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f444d4d3a20494e53554646494349454e545f494e5055545f414d4f554e540000604482015290519081900360640190fd5b6000610de4838388610d9d578751610da3565b87604001515b89610db2578860200151610db8565b88606001515b8a610dc4578851610dca565b88604001515b8b610dd9578960200151610ddf565b89606001515b612ef9565b9050610df0868561305e565b60408051848152602081018490528082018d9052606081018c905260808101839052905173ffffffffffffffffffffffffffffffffffffffff8b169133917f606ecd02b3e3b4778f8e97b2e03351de14224efaa5fa64e62200afc9395c24999181900360a00190a350506001600855505050505050505050565b600c54600d54604080517f95d89b41000000000000000000000000000000000000000000000000000000008152905160609373ffffffffffffffffffffffffffffffffffffffff90811693169183916395d89b4191600480820192600092909190829003018186803b158015610edf57600080fd5b505afa158015610ef3573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682016040526020811015610f3a57600080fd5b8101908080516040519392919084640100000000821115610f5a57600080fd5b908301906020820185811115610f6f57600080fd5b8251640100000000811182820188101715610f8957600080fd5b82525081516020918201929091019080838360005b83811015610fb6578181015183820152602001610f9e565b50505050905090810190601f168015610fe35780820380516001836020036101000a031916815260200191505b506040525050508173ffffffffffffffffffffffffffffffffffffffff166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b15801561103057600080fd5b505afa158015611044573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052602081101561108b57600080fd5b81019080805160405193929190846401000000008211156110ab57600080fd5b9083019060208201858111156110c057600080fd5b82516401000000008111828201881017156110da57600080fd5b82525081516020918201929091019080838360005b838110156111075781810151838201526020016110ef565b50505050905090810190601f1680156111345780820380516001836020036101000a031916815260200191505b5060405250505060405160200180807f4b79626572444d4d204c50200000000000000000000000000000000000000000815250600c0183805190602001908083835b602083106111b357805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611176565b6001836020036101000a038019825116818451168082178552505050505050905001807f2d0000000000000000000000000000000000000000000000000000000000000081525060010182805190602001908083835b6020831061124657805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611209565b6001836020036101000a038019825116818451168082178552505050505050905001925050506040516020818303038152906040529250505090565b600e546dffffffffffffffffffffffffffff808216926e0100000000000000000000000000009092041690565b60006112c36112bc6131f9565b84846131fd565b5060015b92915050565b600954600a546fffffffffffffffffffffffffffffffff8083169370010000000000000000000000000000000093849004821693838316930490911690565b600c5473ffffffffffffffffffffffffffffffffffffffff1681565b60025490565b600061133b848484613344565b6113c5846113476131f9565b6113c0856040518060600160405280602881526020016149b06028913973ffffffffffffffffffffffffffffffffffffffff8a166000908152600160205260408120906113926131f9565b73ffffffffffffffffffffffffffffffffffffffff1681526020810191909152604001600020549190613514565b6131fd565b5060015b9392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b60055460ff1690565b60006112c361140a6131f9565b846113c0856001600061141b6131f9565b73ffffffffffffffffffffffffffffffffffffffff908116825260208083019390935260409182016000908120918c168152925290205490612e0e565b600e547c0100000000000000000000000000000000000000000000000000000000900463ffffffff1681565b6000600260085414156114f857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b60026008556000611507614891565b61150f612cd8565b9150915061151b614891565b600c54604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b15801561158c57600080fd5b505afa1580156115a0573d6000803e3d6000fd5b505050506040513d60208110156115b657600080fd5b50518152600d54604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b15801561162b57600080fd5b505afa15801561163f573d6000803e3d6000fd5b505050506040513d602081101561165557600080fd5b505160208201528151815160009161166d9190612e82565b9050600061168c84602001518460200151612e8290919063ffffffff16565b9050600061169a86866135c5565b905060006116a6611328565b90508061177457861561172957600e54855163ffffffff7c0100000000000000000000000000000000000000000000000000000000909204821691612710916116f191849061373416565b816116f857fe5b04604087015260208601516127109061171a9063ffffffff8085169061373416565b8161172157fe5b046060870152505b6117416103e8610c9261173c8787613734565b6137a7565b975061176f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6103e86137f8565b611827565b85516117b1906117848684613734565b8161178b57fe5b0487602001516117a4848761373490919063ffffffff16565b816117ab57fe5b04613929565b975086156118275760006117c58983612e0e565b90506117f4826117e2838a6040015161373490919063ffffffff16565b816117e957fe5b04876000015161393f565b6040870152606087015161182090839061180e9084613734565b8161181557fe5b04876020015161393f565b6060870152505b60008811611880576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806149d86022913960400191505060405180910390fd5b61188a89896137f8565b611894878661305e565b81156118a8576118a4878661394f565b6010555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600855509395945050505050565b600b5473ffffffffffffffffffffffffffffffffffffffff16331461197a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f444d4d3a20464f5242494444454e000000000000000000000000000000000000604482015290519081900360640190fd5b600c805473ffffffffffffffffffffffffffffffffffffffff9485167fffffffffffffffffffffffff000000000000000000000000000000000000000091821617909155600d805493909416921691909117909155600e805463ffffffff9092167c0100000000000000000000000000000000000000000000000000000000027bffffffffffffffffffffffffffffffffffffffffffffffffffffffff909216919091179055565b73ffffffffffffffffffffffffffffffffffffffff81166000908152602081905260409020545b919050565b60105481565b60076020526000908152604090205481565b60008060026008541415611adb57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b60026008556000611aea614891565b611af2612cd8565b600c54600d54604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905194965092945073ffffffffffffffffffffffffffffffffffffffff9182169391169160009184916370a08231916024808301926020929190829003018186803b158015611b7357600080fd5b505afa158015611b87573d6000803e3d6000fd5b505050506040513d6020811015611b9d57600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191925060009173ffffffffffffffffffffffffffffffffffffffff8516916370a08231916024808301926020929190829003018186803b158015611c1157600080fd5b505afa158015611c25573d6000803e3d6000fd5b505050506040513d6020811015611c3b57600080fd5b505185519091508210801590611c55575084602001518110155b611cc057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f444d4d3a20554e53594e435f5245534552564553000000000000000000000000604482015290519081900360640190fd5b6000611ccb30611a22565b90506000611cd988886135c5565b90506000611ce5611328565b905080611cf28487613734565b81611cf957fe5b049a5080611d078486613734565b81611d0e57fe5b04995060008b118015611d21575060008a115b611d76576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602281526020018061496d6022913960400191505060405180910390fd5b611d803084613975565b611da173ffffffffffffffffffffffffffffffffffffffff88168d8d612d7c565b611dc273ffffffffffffffffffffffffffffffffffffffff87168d8c612d7c565b611dca614891565b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8a16916370a08231916024808301926020929190829003018186803b158015611e3657600080fd5b505afa158015611e4a573d6000803e3d6000fd5b505050506040513d6020811015611e6057600080fd5b50518152604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8916916370a08231916024808301926020929190829003018186803b158015611ed057600080fd5b505afa158015611ee4573d6000803e3d6000fd5b505050506040513d6020811015611efa57600080fd5b505160208201528915611fa25788518151600091611f4091611f1c9086613734565b81611f2357fe5b048b602001516117a486866020015161373490919063ffffffff16565b9050611f6f83611f5d838d6040015161373490919063ffffffff16565b81611f6457fe5b04836000015161393f565b604083015260608a0151611f9b908490611f899084613734565b81611f9057fe5b04836020015161393f565b6060830152505b611fac8a8261305e565b8215611fc057611fbc8a8261394f565b6010555b8c73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d819364968e8e604051808381526020018281526020019250505060405180910390a3505050505050505050506001600881905550915091565b600c54600d54604080517f95d89b41000000000000000000000000000000000000000000000000000000008152905160609373ffffffffffffffffffffffffffffffffffffffff90811693169183916395d89b4191600480820192600092909190829003018186803b1580156120b957600080fd5b505afa1580156120cd573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052602081101561211457600080fd5b810190808051604051939291908464010000000082111561213457600080fd5b90830190602082018581111561214957600080fd5b825164010000000081118282018810171561216357600080fd5b82525081516020918201929091019080838360005b83811015612190578181015183820152602001612178565b50505050905090810190601f1680156121bd5780820380516001836020036101000a031916815260200191505b506040525050508173ffffffffffffffffffffffffffffffffffffffff166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b15801561220a57600080fd5b505afa15801561221e573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052602081101561226557600080fd5b810190808051604051939291908464010000000082111561228557600080fd5b90830190602082018581111561229a57600080fd5b82516401000000008111828201881017156122b457600080fd5b82525081516020918201929091019080838360005b838110156122e15781810151838201526020016122c9565b50505050905090810190601f16801561230e5780820380516001836020036101000a031916815260200191505b5060405250505060405160200180807f444d4d2d4c5020000000000000000000000000000000000000000000000000008152506007018380519060200190808383602083106111b357805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611176565b60006112c36123996131f9565b846113c085604051806060016040528060258152602001614a8e60259139600160006123c36131f9565b73ffffffffffffffffffffffffffffffffffffffff908116825260208083019390935260409182016000908120918d16815292529020549190613514565b60006112c361240e6131f9565b8484613344565b6103e881565b6002600854141561248d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b6002600855600e54600c54604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051612574938593612554936dffffffffffffffffffffffffffff9092169273ffffffffffffffffffffffffffffffffffffffff909116916370a08231916024808301926020929190829003018186803b15801561252257600080fd5b505afa158015612536573d6000803e3d6000fd5b505050506040513d602081101561254c57600080fd5b505190612e82565b600c5473ffffffffffffffffffffffffffffffffffffffff169190612d7c565b600e54600d54604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051612635938593612615936e0100000000000000000000000000009092046dffffffffffffffffffffffffffff169273ffffffffffffffffffffffffffffffffffffffff909116916370a08231916024808301926020929190829003018186803b15801561252257600080fd5b600d5473ffffffffffffffffffffffffffffffffffffffff169190612d7c565b506001600855565b600b5473ffffffffffffffffffffffffffffffffffffffff1681565b600d5473ffffffffffffffffffffffffffffffffffffffff1681565b428410156126e457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f45524332305065726d69743a2045585049524544000000000000000000000000604482015290519081900360640190fd5b60065473ffffffffffffffffffffffffffffffffffffffff80891660008181526007602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e0850182528051908301207f19010000000000000000000000000000000000000000000000000000000000006101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e2808201937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081019281900390910190855afa158015612845573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff8116158015906128c057508873ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16145b61292b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f45524332305065726d69743a20494e56414c49445f5349474e41545552450000604482015290519081900360640190fd5b6129368989896131fd565b505050505050505050565b600e54600f546dffffffffffffffffffffffffffff808316926e0100000000000000000000000000008082048316938381169391900416906000907c0100000000000000000000000000000000000000000000000000000000900463ffffffff166127108114156129b3578593508492505b60006129be43613abf565b90506129d26129cc82613c63565b83613e44565b925050509091929394565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260016020908152604080832093909416825291909152205490565b60065481565b60026008541415612a8d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b60026008556000612a9c614891565b612aa4612cd8565b915091506000612ab483836135c5565b9050612abe614891565b600c54604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b158015612b2f57600080fd5b505afa158015612b43573d6000803e3d6000fd5b505050506040513d6020811015612b5957600080fd5b50518152600d54604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b158015612bce57600080fd5b505afa158015612be2573d6000803e3d6000fd5b505050506040513d6020811015612bf857600080fd5b505160208201528315612caf576000612c0f611328565b84518351919250600091612c4c9190612c289085613734565b81612c2f57fe5b0486602001516117a485876020015161373490919063ffffffff16565b9050612c7b82612c6983886040015161373490919063ffffffff16565b81612c7057fe5b04846000015161393f565b60408401526060850151612ca7908390612c959084613734565b81612c9c57fe5b04846020015161393f565b606084015250505b612cb9848261305e565b8115612ccd57612cc9848261394f565b6010555b505060016008555050565b6000612ce2614891565b600e546dffffffffffffffffffffffffffff80821683526e010000000000000000000000000000820416602083015263ffffffff7c0100000000000000000000000000000000000000000000000000000000909104166127101480159250612d7857600f546dffffffffffffffffffffffffffff80821660408401526e0100000000000000000000000000009091041660608201525b9091565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052612e09908490613ea0565b505050565b6000828201838110156113c957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b600082821115612ef357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b600080612f1a88612f1487612f0e8a8c613734565b90613f78565b90612e0e565b90506000612f284383613ff9565b9050612f64612f3682613c63565b600e547c0100000000000000000000000000000000000000000000000000000000900463ffffffff16613e44565b92506000612f7a86670de0b6b3a7640000613734565b9050612f90612f898b86613734565b8290612e82565b9050670de0b6b3a7640000810490506000612fb386670de0b6b3a7640000613734565b9050612fc2612f898b87613734565b670de0b6b3a764000090049050612fd98989613734565b612fe38383613734565b101561305057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600660248201527f444d4d3a204b0000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b505050509695505050505050565b80516130699061434c565b600e80547fffffffffffffffffffffffffffffffffffff0000000000000000000000000000166dffffffffffffffffffffffffffff9290921691909117905560208101516130b69061434c565b600e806101000a8154816dffffffffffffffffffffffffffff02191690836dffffffffffffffffffffffffffff16021790555081156131a157805160408201511080159061310c57508060200151816060015110155b61311257fe5b61311f816040015161434c565b600f80547fffffffffffffffffffffffffffffffffffff0000000000000000000000000000166dffffffffffffffffffffffffffff92909216919091179055606081015161316c9061434c565b600f600e6101000a8154816dffffffffffffffffffffffffffff02191690836dffffffffffffffffffffffffffff1602179055505b6040808201516060808401518451602080870151865195865290850192909252838501529082015290517f2f9d55abfefdfd4c3a83e00a1b419b3c2fe4b83100c559f0e2213e57f6e0bba99181900360800190a15050565b3390565b73ffffffffffffffffffffffffffffffffffffffff8316613269576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180614a406024913960400191505060405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff82166132d5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806148ff6022913960400191505060405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b73ffffffffffffffffffffffffffffffffffffffff83166133b0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180614a1b6025913960400191505060405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff821661341c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806148ba6023913960400191505060405180910390fd5b613427838383612e09565b613471816040518060600160405280602681526020016149216026913973ffffffffffffffffffffffffffffffffffffffff86166000908152602081905260409020549190613514565b73ffffffffffffffffffffffffffffffffffffffff80851660009081526020819052604080822093909355908416815220546134ad9082612e0e565b73ffffffffffffffffffffffffffffffffffffffff8084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600081848411156135bd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561358257818101518382015260200161356a565b50505050905090810190601f1680156135af5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000806000600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5cb2e16040518163ffffffff1660e01b8152600401604080518083038186803b15801561363157600080fd5b505afa158015613645573d6000803e3d6000fd5b505050506040513d604081101561365b57600080fd5b50805160209091015160105473ffffffffffffffffffffffffffffffffffffffff831615801596509294509092509061371f57801561371a5760006136a361173c888861394f565b905060006136b0836137a7565b9050808211156137175760006136df61ffff86166136d96136d18686612e82565b6136d9611328565b90613734565b905060006136f36113886136d98686612e0e565b9050600081838161370057fe5b04905080156137135761371388826137f8565b5050505b50505b61372b565b801561372b5760006010555b50505092915050565b600082613743575060006112c7565b8282028284828161375057fe5b04146113c9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602181526020018061498f6021913960400191505060405180910390fd5b600060038211156137ea575080600160028204015b818110156137e4578091506002818285816137d357fe5b0401816137dc57fe5b0490506137bc565b50611a49565b8115611a4957506001919050565b73ffffffffffffffffffffffffffffffffffffffff821661387a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b61388660008383612e09565b6002546138939082612e0e565b60025573ffffffffffffffffffffffffffffffffffffffff82166000908152602081905260409020546138c69082612e0e565b73ffffffffffffffffffffffffffffffffffffffff83166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b600081831061393857816113c9565b5090919050565b60008183101561393857816113c9565b6000826139635760208201518251026113c9565b50606081015160409091015102919050565b73ffffffffffffffffffffffffffffffffffffffff82166139e1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806149fa6021913960400191505060405180910390fd5b6139ed82600083612e09565b613a37816040518060600160405280602281526020016148dd6022913973ffffffffffffffffffffffffffffffffffffffff85166000908152602081905260409020549190613514565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260208190526040902055600254613a6a9082612e82565b60025560408051828152905160009173ffffffffffffffffffffffffffffffffffffffff8516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b600a5460009070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff16820380613b3057600954613b28906fffffffffffffffffffffffffffffffff808216917001000000000000000000000000000000009004166143cf565b915050611a49565b600954600090613b77906fffffffffffffffffffffffffffffffff16611519671bc16d674ec800005b600a54919004906fffffffffffffffffffffffffffffffff166143f1565b600954909150600090613bbb9070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff16612a31671bc16d674ec80000613b59565b9050613c0b613c047fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8501611519671bc16d674ec800005b04670de0b6b3a76400000390614452565b8390614523565b9150613c4e613c477fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8501612a31671bc16d674ec80000613bf3565b8290614523565b9050613c5a82826143cf565b95945050505050565b6000671480cc142da92a848210613c825750661550f7dca70000611a49565b670de0b6b3a76400008210613d8a576710a741a462780000821115613d2b577fffffffffffffffffffffffffffffffffffffffffffffffffef58be5b9d88000082016000613cd1826003614452565b9050612710613d1a613cf1846009680d8d726b7177a800005b0490614523565b612f14613d0a85601b69043c33c1937564800000613cea565b6801fa48421ec7b1ed0990612e0e565b81613d2157fe5b0492505050611a49565b6710a741a4627800008290036000613d44826003614452565b9050612710613d1a613d61846009680d8d726b7177a80000613cea565b610c92613d7a85601b69043c33c1937564800000613cea565b6801fa48421ec7b1ed0990612e82565b6000670b9a1192183a00008311613dac57670b9a1192183a0000839003613dd0565b7ffffffffffffffffffffffffffffffffffffffffffffffffff465ee6de7c6000083015b9050613ddd816002614452565b90506000613e06613df48365b5e620f48000612e0e565b612f0e674563918244f4000085613734565b9050670b9a1192183a0000841115613e2e57612710613d1a6801161163ae0de59a9283612e0e565b612710613d1a6801161163ae0de59a9283612e82565b6000614e208263ffffffff1611613e5c5750816112c7565b61c3508263ffffffff1611613e7a57601e601484025b0490506112c7565b62030d408263ffffffff1611613e9557601e600a8402613e72565b601e60048402613e72565b6060613f02826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff1661453f9092919063ffffffff16565b805190915015612e0957808060200190516020811015613f2157600080fd5b5051612e09576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a815260200180614a64602a913960400191505060405180910390fd5b6000808211613fe857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b818381613ff157fe5b049392505050565b600a5460009070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff168303806140f457600a5461408a9061404f906fffffffffffffffffffffffffffffffff1685612e0e565b6040518060400160405280601a81526020017f766f6c756d6520657863656564732076616c69642072616e6765000000000000815250614556565b600a80547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff9283161790556009546140ec91818116917001000000000000000000000000000000009004166143cf565b9150506112c7565b600a546009546fffffffffffffffffffffffffffffffff918216916000916141289116611519671bc16d674ec80000613b59565b60095490915060009061416c9070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff16612a31671bc16d674ec80000613b59565b90506141a8613c047fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8601611519671bc16d674ec80000613bf3565b91506141e4613c477fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8601612a31671bc16d674ec80000613bf3565b90506141ef826145da565b600980547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff92909216919091179055614239816145da565b600980546fffffffffffffffffffffffffffffffff928316700100000000000000000000000000000000029216919091179055614275866145da565b600a80547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff929092169190911790556142bf876145da565b600a80546fffffffffffffffffffffffffffffffff9283167001000000000000000000000000000000000290831617905560408051848152602081018490529185168282015260608201869052517f96e2c334d3c0fa98c8b728ee84471864ffe5b28e05f46e52f8a469d0ab3a8b8b9181900360800190a161434182826143cf565b979650505050505050565b60006dffffffffffffffffffffffffffff8211156143cb57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f444d4d3a204f564552464c4f5700000000000000000000000000000000000000604482015290519081900360640190fd5b5090565b6000816143de575060006112c7565b81670de0b6b3a7640000840281613ff157fe5b6000670de0b6b3a7640000831061440457fe5b670de0b6b3a7640000826fffffffffffffffffffffffffffffffff168402856fffffffffffffffffffffffffffffffff1685670de0b6b3a76400000302018161444957fe5b04949350505050565b6000670de0b6b3a76400008311156144cb57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4d6174684578743a2078203e20505245434953494f4e00000000000000000000604482015290519081900360640190fd5b600282066144e157670de0b6b3a76400006144e3565b825b90506002820491505b81156112c757670de0b6b3a7640000838002049250600282061561451857670de0b6b3a7640000908302045b6002820491506144ec565b6000670de0b6b3a76400006145388484613734565b81613ff157fe5b606061454e848460008561465b565b949350505050565b6000816fffffffffffffffffffffffffffffffff8411156145d2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181815283516024840152835190928392604490910191908501908083836000831561358257818101518382015260200161356a565b509192915050565b60006fffffffffffffffffffffffffffffffff8211156143cb57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f6f766572666c6f772075696e7431323800000000000000000000000000000000604482015290519081900360640190fd5b6060824710156146b6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806149476026913960400191505060405180910390fd5b6146bf8561480b565b61472a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b600060608673ffffffffffffffffffffffffffffffffffffffff1685876040518082805190602001908083835b6020831061479457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101614757565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146147f6576040519150601f19603f3d011682016040523d82523d6000602084013e6147fb565b606091505b5091509150614341828286614811565b3b151590565b606083156148205750816113c9565b8251156148305782518084602001fd5b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181815284516024840152845185939192839260440191908501908083836000831561358257818101518382015260200161356a565b604051806080016040528060008152602001600081526020016000815260200160008152509056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e6365416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c444d4d3a20494e53554646494349454e545f4c49515549444954595f4255524e4544536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365444d4d3a20494e53554646494349454e545f4c49515549444954595f4d494e54454445524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f20616464726573735361666545524332303a204552433230206f7065726174696f6e20646964206e6f74207375636365656445524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa264697066735822122049f6f8528b3e4b37e72b9bde0aa804ce74fda17a3dc51ea424bf85cf5943707e64736f6c634300060c0033456e756d657261626c655365743a20696e646578206f7574206f6620626f756e6473a264697066735822122079bb062e3983edf62a4ed05c5ab952eea5f73f4c883c4cce38725087a2b9026564736f6c634300060c0033", + "deployedBytecode": "", + "linkReferences": {}, + "deployedLinkReferences": {} +} diff --git a/external/abi/kyber/DMMPool.json b/external/abi/kyber/DMMPool.json new file mode 100644 index 000000000..d6604f655 --- /dev/null +++ b/external/abi/kyber/DMMPool.json @@ -0,0 +1,810 @@ +{ + "contractName": "DMMPool", + "abi": [ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "Burn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + } + ], + "name": "Mint", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0In", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1In", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0Out", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1Out", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "feeInPrecision", + "type": "uint256" + } + ], + "name": "Swap", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "vReserve0", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "vReserve1", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "reserve0", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "reserve1", + "type": "uint256" + } + ], + "name": "Sync", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "shortEMA", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "longEMA", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "lastBlockVolume", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "skipBlock", + "type": "uint256" + } + ], + "name": "UpdateEMA", + "type": "event" + }, + { + "inputs": [], + "name": "MINIMUM_LIQUIDITY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PERMIT_TYPEHASH", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ampBps", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "burn", + "outputs": [ + { + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "subtractedValue", + "type": "uint256" + } + ], + "name": "decreaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "domainSeparator", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "factory", + "outputs": [ + { + "internalType": "contract IDMMFactory", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getReserves", + "outputs": [ + { + "internalType": "uint112", + "name": "_reserve0", + "type": "uint112" + }, + { + "internalType": "uint112", + "name": "_reserve1", + "type": "uint112" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getTradeInfo", + "outputs": [ + { + "internalType": "uint112", + "name": "_reserve0", + "type": "uint112" + }, + { + "internalType": "uint112", + "name": "_reserve1", + "type": "uint112" + }, + { + "internalType": "uint112", + "name": "_vReserve0", + "type": "uint112" + }, + { + "internalType": "uint112", + "name": "_vReserve1", + "type": "uint112" + }, + { + "internalType": "uint256", + "name": "feeInPrecision", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getVolumeTrendData", + "outputs": [ + { + "internalType": "uint128", + "name": "_shortEMA", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "_longEMA", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "_currentBlockVolume", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "_lastTradeBlock", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "addedValue", + "type": "uint256" + } + ], + "name": "increaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "_token0", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "_token1", + "type": "address" + }, + { + "internalType": "uint32", + "name": "_ampBps", + "type": "uint32" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "kLast", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "mint", + "outputs": [ + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "nonces", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + }, + { + "internalType": "uint8", + "name": "v", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + } + ], + "name": "permit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "skim", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amount0Out", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount1Out", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "bytes", + "name": "callbackData", + "type": "bytes" + } + ], + "name": "swap", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "sync", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "token0", + "outputs": [ + { + "internalType": "contract IERC20", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "token1", + "outputs": [ + { + "internalType": "contract IERC20", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } + ], + "bytecode": "0x60806040523480156200001157600080fd5b5060006040518060400160405280600b81526020016a04b79626572444d4d204c560ac1b815250604051806040016040528060068152602001650444d4d2d4c560d41b815250604051806040016040528060018152602001603160f81b815250828281600390805190602001906200008b929190620001ee565b508051620000a1906004906020840190620001ee565b50506005805460ff19166012179055508251602093840120815191840191909120604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f818701528082019390935260608301919091524660808301523060a0808401919091528151808403909101815260c09092019052805192019190912060065550600160085560098054600160801b6001600160801b038085169182026001600160801b03199093169190911716179055620001624362000198565b600a80546001600160801b03928316600160801b02921691909117905550600b80546001600160a01b0319163317905562000280565b60006001600160801b03821115620001ea576040805162461bcd60e51b815260206004820152601060248201526f0deeccae4ccd8deee40ead2dce86264760831b604482015290519081900360640190fd5b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200023157805160ff191683800117855562000261565b8280016001018555821562000261579182015b828111156200026157825182559160200191906001019062000244565b50620001ea9291505b80821115620001ea57600081556001016200026a565b614ae880620002906000396000f3fe608060405234801561001057600080fd5b50600436106101da5760003560e01c80637464fc3d11610104578063bc25cf77116100a2578063d669402711610071578063d669402714610736578063dd62ed3e14610780578063f698da25146107bb578063fff6cae9146107c3576101da565b8063bc25cf7714610695578063c45a0155146106c8578063d21220a7146106d0578063d505accf146106d8576101da565b806395d89b41116100de57806395d89b4114610613578063a457c2d71461061b578063a9059cbb14610654578063ba9a7a561461068d576101da565b80637464fc3d1461058c5780637ecebe001461059457806389afcb44146105c7576101da565b806323b872dd1161017c57806349386b161161014b57806349386b16146104bb5780636a627842146104dc5780636ecf2b221461050f57806370a0823114610559576101da565b806323b872dd1461041957806330adf81f1461045c578063313ce567146104645780633950935114610482576101da565b8063095ea7b3116101b8578063095ea7b31461033c5780630d94d50b146103895780630dfe1681146103ce57806318160ddd146103ff576101da565b8063022c0d9f146101df57806306fdde031461027a5780630902f1ac146102f7575b600080fd5b610278600480360360808110156101f557600080fd5b81359160208101359173ffffffffffffffffffffffffffffffffffffffff604083013516919081019060808101606082013564010000000081111561023957600080fd5b82018360208201111561024b57600080fd5b8035906020019184600183028401116401000000008311171561026d57600080fd5b5090925090506107cb565b005b610282610e6a565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102bc5781810151838201526020016102a4565b50505050905090810190601f1680156102e95780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102ff611282565b60405180836dffffffffffffffffffffffffffff168152602001826dffffffffffffffffffffffffffff1681526020019250505060405180910390f35b6103756004803603604081101561035257600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356112af565b604080519115158252519081900360200190f35b6103916112cd565b604080516fffffffffffffffffffffffffffffffff9586168152938516602085015291841683830152909216606082015290519081900360800190f35b6103d661130c565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b610407611328565b60408051918252519081900360200190f35b6103756004803603606081101561042f57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020810135909116906040013561132e565b6104076113d0565b61046c6113f4565b6040805160ff9092168252519081900360200190f35b6103756004803603604081101561049857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356113fd565b6104c3611458565b6040805163ffffffff9092168252519081900360200190f35b610407600480360360208110156104f257600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611484565b6102786004803603606081101561052557600080fd5b50803573ffffffffffffffffffffffffffffffffffffffff908116916020810135909116906040013563ffffffff166118f4565b6104076004803603602081101561056f57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611a22565b610407611a4e565b610407600480360360208110156105aa57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611a54565b6105fa600480360360208110156105dd57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611a66565b6040805192835260208301919091528051918290030190f35b610282612044565b6103756004803603604081101561063157600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813516906020013561238c565b6103756004803603604081101561066a57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135612401565b610407612415565b610278600480360360208110156106ab57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661241b565b6103d661263d565b6103d6612659565b610278600480360360e08110156106ee57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135612675565b61073e612941565b604080516dffffffffffffffffffffffffffff968716815294861660208601529285168484015293166060830152608082019290925290519081900360a00190f35b6104076004803603604081101561079657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160200135166129dd565b610407612a15565b610278612a1b565b6002600854141561083d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b6002600855841515806108505750600084115b6108bb57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f444d4d3a20494e53554646494349454e545f4f55545055545f414d4f554e5400604482015290519081900360640190fd5b60006108c5614891565b6108cd612cd8565b80519193509150871080156108e55750806020015186105b61095057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f444d4d3a20494e53554646494349454e545f4c49515549444954590000000000604482015290519081900360640190fd5b610958614891565b600c54600d5473ffffffffffffffffffffffffffffffffffffffff9182169190811690881682148015906109b857508073ffffffffffffffffffffffffffffffffffffffff168873ffffffffffffffffffffffffffffffffffffffff1614155b610a2357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f444d4d3a20494e56414c49445f544f0000000000000000000000000000000000604482015290519081900360640190fd5b8915610a4a57610a4a73ffffffffffffffffffffffffffffffffffffffff8316898c612d7c565b8815610a7157610a7173ffffffffffffffffffffffffffffffffffffffff8216898b612d7c565b8515610b3d578773ffffffffffffffffffffffffffffffffffffffff166381279c7e338c8c8b8b6040518663ffffffff1660e01b8152600401808673ffffffffffffffffffffffffffffffffffffffff168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b158015610b2457600080fd5b505af1158015610b38573d6000803e3d6000fd5b505050505b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8416916370a08231916024808301926020929190829003018186803b158015610ba957600080fd5b505afa158015610bbd573d6000803e3d6000fd5b505050506040513d6020811015610bd357600080fd5b50518352604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8316916370a08231916024808301926020929190829003018186803b158015610c4357600080fd5b505afa158015610c57573d6000803e3d6000fd5b505050506040513d6020811015610c6d57600080fd5b505160208401528415610cc157835183516040860151610c989291610c929190612e0e565b90612e82565b6040840152602080850151908401516060860151610cbb9291610c929190612e0e565b60608401525b5050815181516000918a900310610cd9576000610ce4565b82518251908a900390035b9050600088846020015103836020015111610d00576000610d0e565b888460200151038360200151035b90506000821180610d1f5750600081115b610d8a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f444d4d3a20494e53554646494349454e545f494e5055545f414d4f554e540000604482015290519081900360640190fd5b6000610de4838388610d9d578751610da3565b87604001515b89610db2578860200151610db8565b88606001515b8a610dc4578851610dca565b88604001515b8b610dd9578960200151610ddf565b89606001515b612ef9565b9050610df0868561305e565b60408051848152602081018490528082018d9052606081018c905260808101839052905173ffffffffffffffffffffffffffffffffffffffff8b169133917f606ecd02b3e3b4778f8e97b2e03351de14224efaa5fa64e62200afc9395c24999181900360a00190a350506001600855505050505050505050565b600c54600d54604080517f95d89b41000000000000000000000000000000000000000000000000000000008152905160609373ffffffffffffffffffffffffffffffffffffffff90811693169183916395d89b4191600480820192600092909190829003018186803b158015610edf57600080fd5b505afa158015610ef3573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682016040526020811015610f3a57600080fd5b8101908080516040519392919084640100000000821115610f5a57600080fd5b908301906020820185811115610f6f57600080fd5b8251640100000000811182820188101715610f8957600080fd5b82525081516020918201929091019080838360005b83811015610fb6578181015183820152602001610f9e565b50505050905090810190601f168015610fe35780820380516001836020036101000a031916815260200191505b506040525050508173ffffffffffffffffffffffffffffffffffffffff166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b15801561103057600080fd5b505afa158015611044573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052602081101561108b57600080fd5b81019080805160405193929190846401000000008211156110ab57600080fd5b9083019060208201858111156110c057600080fd5b82516401000000008111828201881017156110da57600080fd5b82525081516020918201929091019080838360005b838110156111075781810151838201526020016110ef565b50505050905090810190601f1680156111345780820380516001836020036101000a031916815260200191505b5060405250505060405160200180807f4b79626572444d4d204c50200000000000000000000000000000000000000000815250600c0183805190602001908083835b602083106111b357805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611176565b6001836020036101000a038019825116818451168082178552505050505050905001807f2d0000000000000000000000000000000000000000000000000000000000000081525060010182805190602001908083835b6020831061124657805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611209565b6001836020036101000a038019825116818451168082178552505050505050905001925050506040516020818303038152906040529250505090565b600e546dffffffffffffffffffffffffffff808216926e0100000000000000000000000000009092041690565b60006112c36112bc6131f9565b84846131fd565b5060015b92915050565b600954600a546fffffffffffffffffffffffffffffffff8083169370010000000000000000000000000000000093849004821693838316930490911690565b600c5473ffffffffffffffffffffffffffffffffffffffff1681565b60025490565b600061133b848484613344565b6113c5846113476131f9565b6113c0856040518060600160405280602881526020016149b06028913973ffffffffffffffffffffffffffffffffffffffff8a166000908152600160205260408120906113926131f9565b73ffffffffffffffffffffffffffffffffffffffff1681526020810191909152604001600020549190613514565b6131fd565b5060015b9392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b60055460ff1690565b60006112c361140a6131f9565b846113c0856001600061141b6131f9565b73ffffffffffffffffffffffffffffffffffffffff908116825260208083019390935260409182016000908120918c168152925290205490612e0e565b600e547c0100000000000000000000000000000000000000000000000000000000900463ffffffff1681565b6000600260085414156114f857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b60026008556000611507614891565b61150f612cd8565b9150915061151b614891565b600c54604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b15801561158c57600080fd5b505afa1580156115a0573d6000803e3d6000fd5b505050506040513d60208110156115b657600080fd5b50518152600d54604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b15801561162b57600080fd5b505afa15801561163f573d6000803e3d6000fd5b505050506040513d602081101561165557600080fd5b505160208201528151815160009161166d9190612e82565b9050600061168c84602001518460200151612e8290919063ffffffff16565b9050600061169a86866135c5565b905060006116a6611328565b90508061177457861561172957600e54855163ffffffff7c0100000000000000000000000000000000000000000000000000000000909204821691612710916116f191849061373416565b816116f857fe5b04604087015260208601516127109061171a9063ffffffff8085169061373416565b8161172157fe5b046060870152505b6117416103e8610c9261173c8787613734565b6137a7565b975061176f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6103e86137f8565b611827565b85516117b1906117848684613734565b8161178b57fe5b0487602001516117a4848761373490919063ffffffff16565b816117ab57fe5b04613929565b975086156118275760006117c58983612e0e565b90506117f4826117e2838a6040015161373490919063ffffffff16565b816117e957fe5b04876000015161393f565b6040870152606087015161182090839061180e9084613734565b8161181557fe5b04876020015161393f565b6060870152505b60008811611880576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806149d86022913960400191505060405180910390fd5b61188a89896137f8565b611894878661305e565b81156118a8576118a4878661394f565b6010555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600855509395945050505050565b600b5473ffffffffffffffffffffffffffffffffffffffff16331461197a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f444d4d3a20464f5242494444454e000000000000000000000000000000000000604482015290519081900360640190fd5b600c805473ffffffffffffffffffffffffffffffffffffffff9485167fffffffffffffffffffffffff000000000000000000000000000000000000000091821617909155600d805493909416921691909117909155600e805463ffffffff9092167c0100000000000000000000000000000000000000000000000000000000027bffffffffffffffffffffffffffffffffffffffffffffffffffffffff909216919091179055565b73ffffffffffffffffffffffffffffffffffffffff81166000908152602081905260409020545b919050565b60105481565b60076020526000908152604090205481565b60008060026008541415611adb57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b60026008556000611aea614891565b611af2612cd8565b600c54600d54604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905194965092945073ffffffffffffffffffffffffffffffffffffffff9182169391169160009184916370a08231916024808301926020929190829003018186803b158015611b7357600080fd5b505afa158015611b87573d6000803e3d6000fd5b505050506040513d6020811015611b9d57600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191925060009173ffffffffffffffffffffffffffffffffffffffff8516916370a08231916024808301926020929190829003018186803b158015611c1157600080fd5b505afa158015611c25573d6000803e3d6000fd5b505050506040513d6020811015611c3b57600080fd5b505185519091508210801590611c55575084602001518110155b611cc057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f444d4d3a20554e53594e435f5245534552564553000000000000000000000000604482015290519081900360640190fd5b6000611ccb30611a22565b90506000611cd988886135c5565b90506000611ce5611328565b905080611cf28487613734565b81611cf957fe5b049a5080611d078486613734565b81611d0e57fe5b04995060008b118015611d21575060008a115b611d76576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602281526020018061496d6022913960400191505060405180910390fd5b611d803084613975565b611da173ffffffffffffffffffffffffffffffffffffffff88168d8d612d7c565b611dc273ffffffffffffffffffffffffffffffffffffffff87168d8c612d7c565b611dca614891565b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8a16916370a08231916024808301926020929190829003018186803b158015611e3657600080fd5b505afa158015611e4a573d6000803e3d6000fd5b505050506040513d6020811015611e6057600080fd5b50518152604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8916916370a08231916024808301926020929190829003018186803b158015611ed057600080fd5b505afa158015611ee4573d6000803e3d6000fd5b505050506040513d6020811015611efa57600080fd5b505160208201528915611fa25788518151600091611f4091611f1c9086613734565b81611f2357fe5b048b602001516117a486866020015161373490919063ffffffff16565b9050611f6f83611f5d838d6040015161373490919063ffffffff16565b81611f6457fe5b04836000015161393f565b604083015260608a0151611f9b908490611f899084613734565b81611f9057fe5b04836020015161393f565b6060830152505b611fac8a8261305e565b8215611fc057611fbc8a8261394f565b6010555b8c73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d819364968e8e604051808381526020018281526020019250505060405180910390a3505050505050505050506001600881905550915091565b600c54600d54604080517f95d89b41000000000000000000000000000000000000000000000000000000008152905160609373ffffffffffffffffffffffffffffffffffffffff90811693169183916395d89b4191600480820192600092909190829003018186803b1580156120b957600080fd5b505afa1580156120cd573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052602081101561211457600080fd5b810190808051604051939291908464010000000082111561213457600080fd5b90830190602082018581111561214957600080fd5b825164010000000081118282018810171561216357600080fd5b82525081516020918201929091019080838360005b83811015612190578181015183820152602001612178565b50505050905090810190601f1680156121bd5780820380516001836020036101000a031916815260200191505b506040525050508173ffffffffffffffffffffffffffffffffffffffff166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b15801561220a57600080fd5b505afa15801561221e573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052602081101561226557600080fd5b810190808051604051939291908464010000000082111561228557600080fd5b90830190602082018581111561229a57600080fd5b82516401000000008111828201881017156122b457600080fd5b82525081516020918201929091019080838360005b838110156122e15781810151838201526020016122c9565b50505050905090810190601f16801561230e5780820380516001836020036101000a031916815260200191505b5060405250505060405160200180807f444d4d2d4c5020000000000000000000000000000000000000000000000000008152506007018380519060200190808383602083106111b357805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611176565b60006112c36123996131f9565b846113c085604051806060016040528060258152602001614a8e60259139600160006123c36131f9565b73ffffffffffffffffffffffffffffffffffffffff908116825260208083019390935260409182016000908120918d16815292529020549190613514565b60006112c361240e6131f9565b8484613344565b6103e881565b6002600854141561248d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b6002600855600e54600c54604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051612574938593612554936dffffffffffffffffffffffffffff9092169273ffffffffffffffffffffffffffffffffffffffff909116916370a08231916024808301926020929190829003018186803b15801561252257600080fd5b505afa158015612536573d6000803e3d6000fd5b505050506040513d602081101561254c57600080fd5b505190612e82565b600c5473ffffffffffffffffffffffffffffffffffffffff169190612d7c565b600e54600d54604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051612635938593612615936e0100000000000000000000000000009092046dffffffffffffffffffffffffffff169273ffffffffffffffffffffffffffffffffffffffff909116916370a08231916024808301926020929190829003018186803b15801561252257600080fd5b600d5473ffffffffffffffffffffffffffffffffffffffff169190612d7c565b506001600855565b600b5473ffffffffffffffffffffffffffffffffffffffff1681565b600d5473ffffffffffffffffffffffffffffffffffffffff1681565b428410156126e457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f45524332305065726d69743a2045585049524544000000000000000000000000604482015290519081900360640190fd5b60065473ffffffffffffffffffffffffffffffffffffffff80891660008181526007602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e0850182528051908301207f19010000000000000000000000000000000000000000000000000000000000006101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e2808201937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081019281900390910190855afa158015612845573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff8116158015906128c057508873ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16145b61292b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f45524332305065726d69743a20494e56414c49445f5349474e41545552450000604482015290519081900360640190fd5b6129368989896131fd565b505050505050505050565b600e54600f546dffffffffffffffffffffffffffff808316926e0100000000000000000000000000008082048316938381169391900416906000907c0100000000000000000000000000000000000000000000000000000000900463ffffffff166127108114156129b3578593508492505b60006129be43613abf565b90506129d26129cc82613c63565b83613e44565b925050509091929394565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260016020908152604080832093909416825291909152205490565b60065481565b60026008541415612a8d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b60026008556000612a9c614891565b612aa4612cd8565b915091506000612ab483836135c5565b9050612abe614891565b600c54604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b158015612b2f57600080fd5b505afa158015612b43573d6000803e3d6000fd5b505050506040513d6020811015612b5957600080fd5b50518152600d54604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b158015612bce57600080fd5b505afa158015612be2573d6000803e3d6000fd5b505050506040513d6020811015612bf857600080fd5b505160208201528315612caf576000612c0f611328565b84518351919250600091612c4c9190612c289085613734565b81612c2f57fe5b0486602001516117a485876020015161373490919063ffffffff16565b9050612c7b82612c6983886040015161373490919063ffffffff16565b81612c7057fe5b04846000015161393f565b60408401526060850151612ca7908390612c959084613734565b81612c9c57fe5b04846020015161393f565b606084015250505b612cb9848261305e565b8115612ccd57612cc9848261394f565b6010555b505060016008555050565b6000612ce2614891565b600e546dffffffffffffffffffffffffffff80821683526e010000000000000000000000000000820416602083015263ffffffff7c0100000000000000000000000000000000000000000000000000000000909104166127101480159250612d7857600f546dffffffffffffffffffffffffffff80821660408401526e0100000000000000000000000000009091041660608201525b9091565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052612e09908490613ea0565b505050565b6000828201838110156113c957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b600082821115612ef357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b600080612f1a88612f1487612f0e8a8c613734565b90613f78565b90612e0e565b90506000612f284383613ff9565b9050612f64612f3682613c63565b600e547c0100000000000000000000000000000000000000000000000000000000900463ffffffff16613e44565b92506000612f7a86670de0b6b3a7640000613734565b9050612f90612f898b86613734565b8290612e82565b9050670de0b6b3a7640000810490506000612fb386670de0b6b3a7640000613734565b9050612fc2612f898b87613734565b670de0b6b3a764000090049050612fd98989613734565b612fe38383613734565b101561305057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600660248201527f444d4d3a204b0000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b505050509695505050505050565b80516130699061434c565b600e80547fffffffffffffffffffffffffffffffffffff0000000000000000000000000000166dffffffffffffffffffffffffffff9290921691909117905560208101516130b69061434c565b600e806101000a8154816dffffffffffffffffffffffffffff02191690836dffffffffffffffffffffffffffff16021790555081156131a157805160408201511080159061310c57508060200151816060015110155b61311257fe5b61311f816040015161434c565b600f80547fffffffffffffffffffffffffffffffffffff0000000000000000000000000000166dffffffffffffffffffffffffffff92909216919091179055606081015161316c9061434c565b600f600e6101000a8154816dffffffffffffffffffffffffffff02191690836dffffffffffffffffffffffffffff1602179055505b6040808201516060808401518451602080870151865195865290850192909252838501529082015290517f2f9d55abfefdfd4c3a83e00a1b419b3c2fe4b83100c559f0e2213e57f6e0bba99181900360800190a15050565b3390565b73ffffffffffffffffffffffffffffffffffffffff8316613269576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180614a406024913960400191505060405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff82166132d5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806148ff6022913960400191505060405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b73ffffffffffffffffffffffffffffffffffffffff83166133b0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180614a1b6025913960400191505060405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff821661341c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806148ba6023913960400191505060405180910390fd5b613427838383612e09565b613471816040518060600160405280602681526020016149216026913973ffffffffffffffffffffffffffffffffffffffff86166000908152602081905260409020549190613514565b73ffffffffffffffffffffffffffffffffffffffff80851660009081526020819052604080822093909355908416815220546134ad9082612e0e565b73ffffffffffffffffffffffffffffffffffffffff8084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600081848411156135bd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561358257818101518382015260200161356a565b50505050905090810190601f1680156135af5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000806000600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5cb2e16040518163ffffffff1660e01b8152600401604080518083038186803b15801561363157600080fd5b505afa158015613645573d6000803e3d6000fd5b505050506040513d604081101561365b57600080fd5b50805160209091015160105473ffffffffffffffffffffffffffffffffffffffff831615801596509294509092509061371f57801561371a5760006136a361173c888861394f565b905060006136b0836137a7565b9050808211156137175760006136df61ffff86166136d96136d18686612e82565b6136d9611328565b90613734565b905060006136f36113886136d98686612e0e565b9050600081838161370057fe5b04905080156137135761371388826137f8565b5050505b50505b61372b565b801561372b5760006010555b50505092915050565b600082613743575060006112c7565b8282028284828161375057fe5b04146113c9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602181526020018061498f6021913960400191505060405180910390fd5b600060038211156137ea575080600160028204015b818110156137e4578091506002818285816137d357fe5b0401816137dc57fe5b0490506137bc565b50611a49565b8115611a4957506001919050565b73ffffffffffffffffffffffffffffffffffffffff821661387a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b61388660008383612e09565b6002546138939082612e0e565b60025573ffffffffffffffffffffffffffffffffffffffff82166000908152602081905260409020546138c69082612e0e565b73ffffffffffffffffffffffffffffffffffffffff83166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b600081831061393857816113c9565b5090919050565b60008183101561393857816113c9565b6000826139635760208201518251026113c9565b50606081015160409091015102919050565b73ffffffffffffffffffffffffffffffffffffffff82166139e1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806149fa6021913960400191505060405180910390fd5b6139ed82600083612e09565b613a37816040518060600160405280602281526020016148dd6022913973ffffffffffffffffffffffffffffffffffffffff85166000908152602081905260409020549190613514565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260208190526040902055600254613a6a9082612e82565b60025560408051828152905160009173ffffffffffffffffffffffffffffffffffffffff8516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b600a5460009070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff16820380613b3057600954613b28906fffffffffffffffffffffffffffffffff808216917001000000000000000000000000000000009004166143cf565b915050611a49565b600954600090613b77906fffffffffffffffffffffffffffffffff16611519671bc16d674ec800005b600a54919004906fffffffffffffffffffffffffffffffff166143f1565b600954909150600090613bbb9070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff16612a31671bc16d674ec80000613b59565b9050613c0b613c047fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8501611519671bc16d674ec800005b04670de0b6b3a76400000390614452565b8390614523565b9150613c4e613c477fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8501612a31671bc16d674ec80000613bf3565b8290614523565b9050613c5a82826143cf565b95945050505050565b6000671480cc142da92a848210613c825750661550f7dca70000611a49565b670de0b6b3a76400008210613d8a576710a741a462780000821115613d2b577fffffffffffffffffffffffffffffffffffffffffffffffffef58be5b9d88000082016000613cd1826003614452565b9050612710613d1a613cf1846009680d8d726b7177a800005b0490614523565b612f14613d0a85601b69043c33c1937564800000613cea565b6801fa48421ec7b1ed0990612e0e565b81613d2157fe5b0492505050611a49565b6710a741a4627800008290036000613d44826003614452565b9050612710613d1a613d61846009680d8d726b7177a80000613cea565b610c92613d7a85601b69043c33c1937564800000613cea565b6801fa48421ec7b1ed0990612e82565b6000670b9a1192183a00008311613dac57670b9a1192183a0000839003613dd0565b7ffffffffffffffffffffffffffffffffffffffffffffffffff465ee6de7c6000083015b9050613ddd816002614452565b90506000613e06613df48365b5e620f48000612e0e565b612f0e674563918244f4000085613734565b9050670b9a1192183a0000841115613e2e57612710613d1a6801161163ae0de59a9283612e0e565b612710613d1a6801161163ae0de59a9283612e82565b6000614e208263ffffffff1611613e5c5750816112c7565b61c3508263ffffffff1611613e7a57601e601484025b0490506112c7565b62030d408263ffffffff1611613e9557601e600a8402613e72565b601e60048402613e72565b6060613f02826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff1661453f9092919063ffffffff16565b805190915015612e0957808060200190516020811015613f2157600080fd5b5051612e09576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a815260200180614a64602a913960400191505060405180910390fd5b6000808211613fe857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b818381613ff157fe5b049392505050565b600a5460009070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff168303806140f457600a5461408a9061404f906fffffffffffffffffffffffffffffffff1685612e0e565b6040518060400160405280601a81526020017f766f6c756d6520657863656564732076616c69642072616e6765000000000000815250614556565b600a80547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff9283161790556009546140ec91818116917001000000000000000000000000000000009004166143cf565b9150506112c7565b600a546009546fffffffffffffffffffffffffffffffff918216916000916141289116611519671bc16d674ec80000613b59565b60095490915060009061416c9070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff16612a31671bc16d674ec80000613b59565b90506141a8613c047fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8601611519671bc16d674ec80000613bf3565b91506141e4613c477fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8601612a31671bc16d674ec80000613bf3565b90506141ef826145da565b600980547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff92909216919091179055614239816145da565b600980546fffffffffffffffffffffffffffffffff928316700100000000000000000000000000000000029216919091179055614275866145da565b600a80547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff929092169190911790556142bf876145da565b600a80546fffffffffffffffffffffffffffffffff9283167001000000000000000000000000000000000290831617905560408051848152602081018490529185168282015260608201869052517f96e2c334d3c0fa98c8b728ee84471864ffe5b28e05f46e52f8a469d0ab3a8b8b9181900360800190a161434182826143cf565b979650505050505050565b60006dffffffffffffffffffffffffffff8211156143cb57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f444d4d3a204f564552464c4f5700000000000000000000000000000000000000604482015290519081900360640190fd5b5090565b6000816143de575060006112c7565b81670de0b6b3a7640000840281613ff157fe5b6000670de0b6b3a7640000831061440457fe5b670de0b6b3a7640000826fffffffffffffffffffffffffffffffff168402856fffffffffffffffffffffffffffffffff1685670de0b6b3a76400000302018161444957fe5b04949350505050565b6000670de0b6b3a76400008311156144cb57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4d6174684578743a2078203e20505245434953494f4e00000000000000000000604482015290519081900360640190fd5b600282066144e157670de0b6b3a76400006144e3565b825b90506002820491505b81156112c757670de0b6b3a7640000838002049250600282061561451857670de0b6b3a7640000908302045b6002820491506144ec565b6000670de0b6b3a76400006145388484613734565b81613ff157fe5b606061454e848460008561465b565b949350505050565b6000816fffffffffffffffffffffffffffffffff8411156145d2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181815283516024840152835190928392604490910191908501908083836000831561358257818101518382015260200161356a565b509192915050565b60006fffffffffffffffffffffffffffffffff8211156143cb57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f6f766572666c6f772075696e7431323800000000000000000000000000000000604482015290519081900360640190fd5b6060824710156146b6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806149476026913960400191505060405180910390fd5b6146bf8561480b565b61472a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b600060608673ffffffffffffffffffffffffffffffffffffffff1685876040518082805190602001908083835b6020831061479457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101614757565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146147f6576040519150601f19603f3d011682016040523d82523d6000602084013e6147fb565b606091505b5091509150614341828286614811565b3b151590565b606083156148205750816113c9565b8251156148305782518084602001fd5b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181815284516024840152845185939192839260440191908501908083836000831561358257818101518382015260200161356a565b604051806080016040528060008152602001600081526020016000815260200160008152509056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e6365416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c444d4d3a20494e53554646494349454e545f4c49515549444954595f4255524e4544536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365444d4d3a20494e53554646494349454e545f4c49515549444954595f4d494e54454445524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f20616464726573735361666545524332303a204552433230206f7065726174696f6e20646964206e6f74207375636365656445524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa264697066735822122049f6f8528b3e4b37e72b9bde0aa804ce74fda17a3dc51ea424bf85cf5943707e64736f6c634300060c0033", + "deployedBytecode": "", + "linkReferences": {}, + "deployedLinkReferences": {} +} diff --git a/external/abi/kyber/DMMRouter02.json b/external/abi/kyber/DMMRouter02.json new file mode 100644 index 000000000..cd8fe3200 --- /dev/null +++ b/external/abi/kyber/DMMRouter02.json @@ -0,0 +1,1155 @@ +{ + "contractName": "DMMRouter02", + "abi": [ + { + "inputs": [ + { + "internalType": "address", + "name": "_factory", + "type": "address" + }, + { + "internalType": "contract IWETH", + "name": "_weth", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "tokenA", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "tokenB", + "type": "address" + }, + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amountADesired", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountBDesired", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountAMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountBMin", + "type": "uint256" + }, + { + "internalType": "uint256[2]", + "name": "vReserveRatioBounds", + "type": "uint256[2]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "addLiquidity", + "outputs": [ + { + "internalType": "uint256", + "name": "amountA", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountB", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "token", + "type": "address" + }, + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amountTokenDesired", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountTokenMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETHMin", + "type": "uint256" + }, + { + "internalType": "uint256[2]", + "name": "vReserveRatioBounds", + "type": "uint256[2]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "addLiquidityETH", + "outputs": [ + { + "internalType": "uint256", + "name": "amountToken", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETH", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "tokenA", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "tokenB", + "type": "address" + }, + { + "internalType": "uint32", + "name": "ampBps", + "type": "uint32" + }, + { + "internalType": "uint256", + "name": "amountADesired", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountBDesired", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountAMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountBMin", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "addLiquidityNewPool", + "outputs": [ + { + "internalType": "uint256", + "name": "amountA", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountB", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "token", + "type": "address" + }, + { + "internalType": "uint32", + "name": "ampBps", + "type": "uint32" + }, + { + "internalType": "uint256", + "name": "amountTokenDesired", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountTokenMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETHMin", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "addLiquidityNewPoolETH", + "outputs": [ + { + "internalType": "uint256", + "name": "amountToken", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETH", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "factory", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountOut", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "poolsPath", + "type": "address[]" + }, + { + "internalType": "contract IERC20[]", + "name": "path", + "type": "address[]" + } + ], + "name": "getAmountsIn", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountIn", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "poolsPath", + "type": "address[]" + }, + { + "internalType": "contract IERC20[]", + "name": "path", + "type": "address[]" + } + ], + "name": "getAmountsOut", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountA", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "reserveA", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "reserveB", + "type": "uint256" + } + ], + "name": "quote", + "outputs": [ + { + "internalType": "uint256", + "name": "amountB", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "tokenA", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "tokenB", + "type": "address" + }, + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountAMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountBMin", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "removeLiquidity", + "outputs": [ + { + "internalType": "uint256", + "name": "amountA", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountB", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "token", + "type": "address" + }, + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountTokenMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETHMin", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "removeLiquidityETH", + "outputs": [ + { + "internalType": "uint256", + "name": "amountToken", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETH", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "token", + "type": "address" + }, + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountTokenMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETHMin", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "removeLiquidityETHSupportingFeeOnTransferTokens", + "outputs": [ + { + "internalType": "uint256", + "name": "amountETH", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "token", + "type": "address" + }, + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountTokenMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETHMin", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "approveMax", + "type": "bool" + }, + { + "internalType": "uint8", + "name": "v", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + } + ], + "name": "removeLiquidityETHWithPermit", + "outputs": [ + { + "internalType": "uint256", + "name": "amountToken", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETH", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "token", + "type": "address" + }, + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountTokenMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountETHMin", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "approveMax", + "type": "bool" + }, + { + "internalType": "uint8", + "name": "v", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + } + ], + "name": "removeLiquidityETHWithPermitSupportingFeeOnTransferTokens", + "outputs": [ + { + "internalType": "uint256", + "name": "amountETH", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "tokenA", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "tokenB", + "type": "address" + }, + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountAMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountBMin", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "approveMax", + "type": "bool" + }, + { + "internalType": "uint8", + "name": "v", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + } + ], + "name": "removeLiquidityWithPermit", + "outputs": [ + { + "internalType": "uint256", + "name": "amountA", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountB", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountOut", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "poolsPath", + "type": "address[]" + }, + { + "internalType": "contract IERC20[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapETHForExactTokens", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountOutMin", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "poolsPath", + "type": "address[]" + }, + { + "internalType": "contract IERC20[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapExactETHForTokens", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountOutMin", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "poolsPath", + "type": "address[]" + }, + { + "internalType": "contract IERC20[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapExactETHForTokensSupportingFeeOnTransferTokens", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountOutMin", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "poolsPath", + "type": "address[]" + }, + { + "internalType": "contract IERC20[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapExactTokensForETH", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountOutMin", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "poolsPath", + "type": "address[]" + }, + { + "internalType": "contract IERC20[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapExactTokensForETHSupportingFeeOnTransferTokens", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountOutMin", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "poolsPath", + "type": "address[]" + }, + { + "internalType": "contract IERC20[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapExactTokensForTokens", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountOutMin", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "poolsPath", + "type": "address[]" + }, + { + "internalType": "contract IERC20[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapExactTokensForTokensSupportingFeeOnTransferTokens", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountInMax", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "poolsPath", + "type": "address[]" + }, + { + "internalType": "contract IERC20[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapTokensForExactETH", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountInMax", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "poolsPath", + "type": "address[]" + }, + { + "internalType": "contract IERC20[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swapTokensForExactTokens", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "weth", + "outputs": [ + { + "internalType": "contract IWETH", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" + } + ], + "bytecode": "0x60c06040523480156200001157600080fd5b506040516200611038038062006110833981810160405260408110156200003757600080fd5b5080516020909101516001600160601b0319606092831b8116608052911b1660a05260805160601c60a05160601c615ff762000119600039806101ac528061189952806119815280611a305280611d965280611f755280612083528061211852806122d352806125cf52806126f2528061280152806129b152806130b752806132e752806133be52806134f75280613549528061378152806137ac52806137ff52806138975280613ee25280613fce52806140d55280614302525080611492528061158152806126b552806127c452806135eb52806144535250615ff76000f3fe60806040526004361061018f5760003560e01c8063a8312b1d116100d6578063ceb757d51161007f578063e8898b5f11610059578063e8898b5f146110cc578063ebb5d2e914611227578063fc5b8bce14611291576101d5565b8063ceb757d514610e60578063d72c144714610fbb578063e1f4a7841461105b576101d5565b8063af55e31f116100b0578063af55e31f14610cfc578063b56b681d14610de1578063c45a015514610e4b576101d5565b8063a8312b1d14610a95578063ad615dec14610b6b578063ae8290b714610ba1576101d5565b80634c17fd7c1161013857806389c275941161011257806389c275941461083d5780639e269b6814610934578063a4aabb0814610a0a576101d5565b80634c17fd7c146105ea5780636dce49ae146106955780637d41a422146107dc576101d5565b80632daaa818116101695780632daaa818146103d05780633e741fca146104b55780633fc8cef3146105ac576101d5565b80630e2f024c146101da5780631c5d0a6b146102775780632434193414610313576101d5565b366101d5573373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016146101d357fe5b005b600080fd5b3480156101e657600080fd5b5061026560048036036101608110156101fe57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013582169160408201359160608101359160808201359160a08101359091169060c08101359060e081013515159060ff6101008201351690610120810135906101400135611376565b60408051918252519081900360200190f35b34801561028357600080fd5b506102f5600480360361012081101561029b57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013582169163ffffffff6040830135169160608101359160808201359160a08101359160c08201359160e081013590911690610100013561147a565b60408051938452602084019290925282820152519081900360600190f35b34801561031f57600080fd5b506102f5600480360361016081101561033757600080fd5b60408051808201825273ffffffffffffffffffffffffffffffffffffffff84358116946020810135821694848201359092169360608201359360808301359360a08401359360c0810135939181019290916101208301919060e084019060029083908390808284376000920191909152509194505073ffffffffffffffffffffffffffffffffffffffff823516925050602001356116cf565b6101d3600480360360a08110156103e657600080fd5b8135919081019060408101602082013564010000000081111561040857600080fd5b82018360208201111561041a57600080fd5b8035906020019184602083028401116401000000008311171561043c57600080fd5b91939092909160208101903564010000000081111561045a57600080fd5b82018360208201111561046c57600080fd5b8035906020019184602083028401116401000000008311171561048e57600080fd5b919350915073ffffffffffffffffffffffffffffffffffffffff8135169060200135611827565b3480156104c157600080fd5b506101d3600480360360c08110156104d857600080fd5b8135916020810135918101906060810160408201356401000000008111156104ff57600080fd5b82018360208201111561051157600080fd5b8035906020019184602083028401116401000000008311171561053357600080fd5b91939092909160208101903564010000000081111561055157600080fd5b82018360208201111561056357600080fd5b8035906020019184602083028401116401000000008311171561058557600080fd5b919350915073ffffffffffffffffffffffffffffffffffffffff8135169060200135611d0f565b3480156105b857600080fd5b506105c1612116565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b3480156105f657600080fd5b5061067c600480360361018081101561060e57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020810135821691604082013581169160608101359160808201359160a08101359160c0820135169060e08101359061010081013515159060ff610120820135169061014081013590610160013561213a565b6040805192835260208301919091528051918290030190f35b3480156106a157600080fd5b5061078c600480360360c08110156106b857600080fd5b8135916020810135918101906060810160408201356401000000008111156106df57600080fd5b8201836020820111156106f157600080fd5b8035906020019184602083028401116401000000008311171561071357600080fd5b91939092909160208101903564010000000081111561073157600080fd5b82018360208201111561074357600080fd5b8035906020019184602083028401116401000000008311171561076557600080fd5b919350915073ffffffffffffffffffffffffffffffffffffffff813516906020013561224a565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156107c85781810151838201526020016107b0565b505050509050019250505060405180910390f35b6102f5600480360360e08110156107f257600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169163ffffffff6020820135169160408201359160608101359160808201359160a08101359091169060c0013561269d565b34801561084957600080fd5b5061078c600480360360c081101561086057600080fd5b81359160208101359181019060608101604082013564010000000081111561088757600080fd5b82018360208201111561089957600080fd5b803590602001918460208302840111640100000000831117156108bb57600080fd5b9193909290916020810190356401000000008111156108d957600080fd5b8201836020820111156108eb57600080fd5b8035906020019184602083028401116401000000008311171561090d57600080fd5b919350915073ffffffffffffffffffffffffffffffffffffffff8135169060200135612928565b34801561094057600080fd5b5061078c6004803603606081101561095757600080fd5b8135919081019060408101602082013564010000000081111561097957600080fd5b82018360208201111561098b57600080fd5b803590602001918460208302840111640100000000831117156109ad57600080fd5b9193909290916020810190356401000000008111156109cb57600080fd5b8201836020820111156109dd57600080fd5b803590602001918460208302840111640100000000831117156109ff57600080fd5b509092509050612be8565b348015610a1657600080fd5b5061067c6004803603610160811015610a2e57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013582169160408201359160608101359160808201359160a08101359091169060c08101359060e081013515159060ff6101008201351690610120810135906101400135612ccf565b348015610aa157600080fd5b5061078c60048036036060811015610ab857600080fd5b81359190810190604081016020820135640100000000811115610ada57600080fd5b820183602082011115610aec57600080fd5b80359060200191846020830284011164010000000083111715610b0e57600080fd5b919390929091602081019035640100000000811115610b2c57600080fd5b820183602082011115610b3e57600080fd5b80359060200191846020830284011164010000000083111715610b6057600080fd5b509092509050612dd9565b348015610b7757600080fd5b5061026560048036036060811015610b8e57600080fd5b5080359060208101359060400135612eb6565b348015610bad57600080fd5b5061078c600480360360c0811015610bc457600080fd5b813591602081013591810190606081016040820135640100000000811115610beb57600080fd5b820183602082011115610bfd57600080fd5b80359060200191846020830284011164010000000083111715610c1f57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050640100000000811115610c6f57600080fd5b820183602082011115610c8157600080fd5b80359060200191846020830284011164010000000083111715610ca357600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295505073ffffffffffffffffffffffffffffffffffffffff8335169350505060200135612ecd565b61078c600480360360a0811015610d1257600080fd5b81359190810190604081016020820135640100000000811115610d3457600080fd5b820183602082011115610d4657600080fd5b80359060200191846020830284011164010000000083111715610d6857600080fd5b919390929091602081019035640100000000811115610d8657600080fd5b820183602082011115610d9857600080fd5b80359060200191846020830284011164010000000083111715610dba57600080fd5b919350915073ffffffffffffffffffffffffffffffffffffffff8135169060200135613043565b348015610ded57600080fd5b5061067c600480360360e0811015610e0457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013582169160408201359160608101359160808201359160a08101359091169060c0013561347e565b348015610e5757600080fd5b506105c16135e9565b348015610e6c57600080fd5b5061078c600480360360c0811015610e8357600080fd5b813591602081013591810190606081016040820135640100000000811115610eaa57600080fd5b820183602082011115610ebc57600080fd5b80359060200191846020830284011164010000000083111715610ede57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050640100000000811115610f2e57600080fd5b820183602082011115610f4057600080fd5b80359060200191846020830284011164010000000083111715610f6257600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295505073ffffffffffffffffffffffffffffffffffffffff833516935050506020013561360d565b6102f56004803603610120811015610fd257600080fd5b60408051808201825273ffffffffffffffffffffffffffffffffffffffff84358116946020810135909116938382013593606083013593608084013593928301929160e08301919060a084019060029083908390808284376000920191909152509194505073ffffffffffffffffffffffffffffffffffffffff82351692505060200135613706565b34801561106757600080fd5b5061067c600480360361010081101561107f57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020810135821691604082013581169160608101359160808201359160a08101359160c0820135169060e0013561397c565b3480156110d857600080fd5b506101d3600480360360c08110156110ef57600080fd5b81359160208101359181019060608101604082013564010000000081111561111657600080fd5b82018360208201111561112857600080fd5b8035906020019184602083028401116401000000008311171561114a57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929594936020810193503591505064010000000081111561119a57600080fd5b8201836020820111156111ac57600080fd5b803590602001918460208302840111640100000000831117156111ce57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295505073ffffffffffffffffffffffffffffffffffffffff8335169350505060200135613bff565b34801561123357600080fd5b50610265600480360360e081101561124a57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013582169160408201359160608101359160808201359160a08101359091169060c00135613e6a565b61078c600480360360a08110156112a757600080fd5b813591908101906040810160208201356401000000008111156112c957600080fd5b8201836020820111156112db57600080fd5b803590602001918460208302840111640100000000831117156112fd57600080fd5b91939092909160208101903564010000000081111561131b57600080fd5b82018360208201111561132d57600080fd5b8035906020019184602083028401116401000000008311171561134f57600080fd5b919350915073ffffffffffffffffffffffffffffffffffffffff8135169060200135614061565b60008085611384578a6113a6565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5b604080517fd505accf00000000000000000000000000000000000000000000000000000000815233600482015230602482015260448101839052606481018a905260ff8816608482015260a4810187905260c48101869052905191925073ffffffffffffffffffffffffffffffffffffffff8e169163d505accf9160e48082019260009290919082900301818387803b15801561144257600080fd5b505af1158015611456573d6000803e3d6000fd5b505050506114698d8d8d8d8d8d8d613e6a565b9d9c50505050505050505050505050565b6000806000806127108b63ffffffff161415611564577f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16633d82497e8e8e6040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060206040518083038186803b15801561153557600080fd5b505afa158015611549573d6000803e3d6000fd5b505050506040513d602081101561155f57600080fd5b505190505b73ffffffffffffffffffffffffffffffffffffffff8116611663577f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16638fd648408e8e8e6040518463ffffffff1660e01b8152600401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018263ffffffff1681526020019350505050602060405180830381600087803b15801561163457600080fd5b505af1158015611648573d6000803e3d6000fd5b505050506040513d602081101561165e57600080fd5b505190505b61166b615e3b565b5060408051808201909152600081527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60208201526116b28e8e848e8e8e8e888f8f6116cf565b809550819650829750505050505099509950999650505050505050565b6000806000834281101561174457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f444d4d526f757465723a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b61174f8e8e8e614451565b61175f8e8e8e8e8e8e8e8e6145b0565b90945092506117708e338e876147a7565b61177c8d338e866147a7565b8b73ffffffffffffffffffffffffffffffffffffffff16636a627842876040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600087803b1580156117e557600080fd5b505af11580156117f9573d6000803e3d6000fd5b505050506040513d602081101561180f57600080fd5b5051939e929d50929b50909950505050505050505050565b804281101561189757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f444d4d526f757465723a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16858560008181106118db57fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461197a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f444d4d526f757465723a20494e56414c49445f50415448000000000000000000604482015290519081900360640190fd5b60003490507f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b1580156119e757600080fd5b505af11580156119fb573d6000803e3d6000fd5b5050505050611a7488886000818110611a1057fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff16827f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166148429092919063ffffffff16565b600086867fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8101818110611aa457fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231866040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015611b2757600080fd5b505afa158015611b3b573d6000803e3d6000fd5b505050506040513d6020811015611b5157600080fd5b50516040805160208b810282810182019093528b8252929350611bc49290918c918c91829185019084908082843760009201919091525050604080516020808d0282810182019093528c82529093508c92508b9182918501908490808284376000920191909152508a92506148cf915050565b89611cac8289897fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8101818110611bf757fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231896040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015611c7a57600080fd5b505afa158015611c8e573d6000803e3d6000fd5b505050506040513d6020811015611ca457600080fd5b505190614b93565b1015611d03576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180615ee46025913960400191505060405180910390fd5b50505050505050505050565b8042811015611d7f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f444d4d526f757465723a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001685857fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8101818110611de457fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611e8357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f444d4d526f757465723a20494e56414c49445f50415448000000000000000000604482015290519081900360640190fd5b611f023388886000818110611e9457fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff168b88886000818110611ebf57fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166147a7909392919063ffffffff16565b611f7187878080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808b0282810182019093528a82529093508a9250899182918501908490808284376000920191909152503092506148cf915050565b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015611ffa57600080fd5b505afa15801561200e573d6000803e3d6000fd5b505050506040513d602081101561202457600080fd5b5051905088811015612081576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180615ee46025913960400191505060405180910390fd5b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16632e1a7d4d826040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b1580156120f457600080fd5b505af1158015612108573d6000803e3d6000fd5b50505050611d038482614c0f565b7f000000000000000000000000000000000000000000000000000000000000000081565b60008060008661214a578b61216c565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5b604080517fd505accf00000000000000000000000000000000000000000000000000000000815233600482015230602482015260448101839052606481018b905260ff8916608482015260a4810188905260c48101879052905191925073ffffffffffffffffffffffffffffffffffffffff8f169163d505accf9160e48082019260009290919082900301818387803b15801561220857600080fd5b505af115801561221c573d6000803e3d6000fd5b505050506122308f8f8f8f8f8f8f8f61397c565b8093508194505050509c509c9a5050505050505050505050565b606081428110156122bc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f444d4d526f757465723a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001686867fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff810181811061232157fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146123c057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f444d4d526f757465723a20494e56414c49445f50415448000000000000000000604482015290519081900360640190fd5b61242d88888080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808c0282810182019093528b82529093508b92508a918291850190849080828437600092019190915250614d4792505050565b61249b8a89898080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808d0282810182019093528c82529093508c92508b918291850190849080828437600092019190915250614e8692505050565b915088826001845103815181106124ae57fe5b6020026020010151101561250d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180615ee46025913960400191505060405180910390fd5b61255d338989600081811061251e57fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff168460008151811061254857fe5b602002602001015189896000818110611ebf57fe5b6125cd8289898080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808d0282810182019093528c82529093508c92508b918291850190849080828437600092019190915250309250614fa3915050565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16632e1a7d4d8360018551038151811061261957fe5b60200260200101516040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561265757600080fd5b505af115801561266b573d6000803e3d6000fd5b50505050612690848360018551038151811061268357fe5b6020026020010151614c0f565b5098975050505050505050565b6000806000806127108a63ffffffff1614156127a7577f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16633d82497e8c7f00000000000000000000000000000000000000000000000000000000000000006040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060206040518083038186803b15801561277857600080fd5b505afa15801561278c573d6000803e3d6000fd5b505050506040513d60208110156127a257600080fd5b505190505b73ffffffffffffffffffffffffffffffffffffffff81166128c6577f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16638fd648408c7f00000000000000000000000000000000000000000000000000000000000000008d6040518463ffffffff1660e01b8152600401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018263ffffffff1681526020019350505050602060405180830381600087803b15801561289757600080fd5b505af11580156128ab573d6000803e3d6000fd5b505050506040513d60208110156128c157600080fd5b505190505b6128ce615e3b565b5060408051808201909152600081527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60208201526129138c838c8c8c868d8d613706565b919e909d50909b509950505050505050505050565b6060814281101561299a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f444d4d526f757465723a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001686867fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81018181106129ff57fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612a9e57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f444d4d526f757465723a20494e56414c49445f50415448000000000000000000604482015290519081900360640190fd5b612b0b88888080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808c0282810182019093528b82529093508b92508a918291850190849080828437600092019190915250614d4792505050565b612b798a89898080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808d0282810182019093528c82529093508c92508b9182918501908490808284376000920191909152506151ec92505050565b91508882600081518110612b8957fe5b6020026020010151111561250d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180615e5a6021913960400191505060405180910390fd5b6060612c5785858080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808902828101820190935288825290935088925087918291850190849080828437600092019190915250614d4792505050565b612cc58686868080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808a028281018201909352898252909350899250889182918501908490808284376000920191909152506151ec92505050565b9695505050505050565b600080600086612cdf578b612d01565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5b604080517fd505accf00000000000000000000000000000000000000000000000000000000815233600482015230602482015260448101839052606481018b905260ff8916608482015260a4810188905260c48101879052905191925073ffffffffffffffffffffffffffffffffffffffff8f169163d505accf9160e48082019260009290919082900301818387803b158015612d9d57600080fd5b505af1158015612db1573d6000803e3d6000fd5b50505050612dc48e8e8e8e8e8e8e61347e565b909f909e509c50505050505050505050505050565b6060612e4885858080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808902828101820190935288825290935088925087918291850190849080828437600092019190915250614d4792505050565b612cc58686868080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808a02828101820190935289825290935089925088918291850190849080828437600092019190915250614e8692505050565b6000612ec3848484615334565b90505b9392505050565b60608142811015612f3f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f444d4d526f757465723a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b612f498686614d47565b612f548887876151ec565b91508682600081518110612f6457fe5b60200260200101511115612fc3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180615e5a6021913960400191505060405180910390fd5b61302c3387600081518110612fd457fe5b602002602001015184600081518110612fe957fe5b602002602001015188600081518110612ffe57fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff166147a7909392919063ffffffff16565b61303882878787614fa3565b509695505050505050565b606081428110156130b557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f444d4d526f757465723a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16868660008181106130f957fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461319857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f444d4d526f757465723a20494e56414c49445f50415448000000000000000000604482015290519081900360640190fd5b61320588888080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808c0282810182019093528b82529093508b92508a918291850190849080828437600092019190915250614d4792505050565b6132733489898080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808d0282810182019093528c82529093508c92508b918291850190849080828437600092019190915250614e8692505050565b9150888260018451038151811061328657fe5b602002602001015110156132e5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180615ee46025913960400191505060405180910390fd5b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663d0e30db08360008151811061332e57fe5b60200260200101516040518263ffffffff1660e01b81526004016000604051808303818588803b15801561336157600080fd5b505af1158015613375573d6000803e3d6000fd5b50505050506134028888600081811061338a57fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff16836000815181106133b457fe5b60200260200101517f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166148429092919063ffffffff16565b6134728289898080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808d0282810182019093528c82529093508c92508b9182918501908490808284376000920191909152508a9250614fa3915050565b50979650505050505050565b60008082428110156134f157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f444d4d526f757465723a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b6135218a7f00000000000000000000000000000000000000000000000000000000000000008b8b8b8b308b61397c565b909350915061354773ffffffffffffffffffffffffffffffffffffffff8b168685614842565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16632e1a7d4d836040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b1580156135ba57600080fd5b505af11580156135ce573d6000803e3d6000fd5b505050506135dc8583614c0f565b5097509795505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6060814281101561367f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f444d4d526f757465723a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b6136898686614d47565b613694888787614e86565b915086826001845103815181106136a757fe5b60200260200101511015612fc3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180615ee46025913960400191505060405180910390fd5b6000806000834281101561377b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f444d4d526f757465723a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b6137a68c7f00000000000000000000000000000000000000000000000000000000000000008d614451565b6137d68c7f00000000000000000000000000000000000000000000000000000000000000008d8d348e8e8e6145b0565b90945092506137fd73ffffffffffffffffffffffffffffffffffffffff8d16338d876147a7565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663d0e30db0846040518263ffffffff1660e01b81526004016000604051808303818588803b15801561386557600080fd5b505af1158015613879573d6000803e3d6000fd5b506138c293505073ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001691508d905085614842565b8a73ffffffffffffffffffffffffffffffffffffffff16636a627842876040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600087803b15801561392b57600080fd5b505af115801561393f573d6000803e3d6000fd5b505050506040513d602081101561395557600080fd5b505191503483101561396d5761396d33843403614c0f565b50985098509895505050505050565b60008082428110156139ef57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f444d4d526f757465723a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b6139fa8b8b8b614451565b613a1c73ffffffffffffffffffffffffffffffffffffffff8a16338b8b6147a7565b6000808a73ffffffffffffffffffffffffffffffffffffffff166389afcb44886040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1681526020019150506040805180830381600087803b158015613a8757600080fd5b505af1158015613a9b573d6000803e3d6000fd5b505050506040513d6040811015613ab157600080fd5b50805160209091015190925090506000613acb8e8e615424565b5090508073ffffffffffffffffffffffffffffffffffffffff168e73ffffffffffffffffffffffffffffffffffffffff1614613b08578183613b0b565b82825b909650945089861015613b7f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f444d4d526f757465723a20494e53554646494349454e545f415f414d4f554e54604482015290519081900360640190fd5b88851015613bee57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f444d4d526f757465723a20494e53554646494349454e545f425f414d4f554e54604482015290519081900360640190fd5b505050509850989650505050505050565b8042811015613c6f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f444d4d526f757465723a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b613c963386600081518110613c8057fe5b60200260200101518987600081518110612ffe57fe5b600084600186510381518110613ca857fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff166370a08231856040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015613d1657600080fd5b505afa158015613d2a573d6000803e3d6000fd5b505050506040513d6020811015613d4057600080fd5b50519050613d4f8686866148cf565b600085600187510381518110613d6157fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff166370a08231866040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015613dcf57600080fd5b505afa158015613de3573d6000803e3d6000fd5b505050506040513d6020811015613df957600080fd5b50519050613e07828961558d565b811015613e5f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180615ee46025913960400191505060405180910390fd5b505050505050505050565b60008142811015613edc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f444d4d526f757465723a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b613f0c897f00000000000000000000000000000000000000000000000000000000000000008a8a8a8a308a61397c565b604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051919450613fcc9250869173ffffffffffffffffffffffffffffffffffffffff8d16916370a08231916024808301926020929190829003018186803b158015613f8257600080fd5b505afa158015613f96573d6000803e3d6000fd5b505050506040513d6020811015613fac57600080fd5b505173ffffffffffffffffffffffffffffffffffffffff8c169190614842565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16632e1a7d4d836040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561403f57600080fd5b505af1158015614053573d6000803e3d6000fd5b505050506134728483614c0f565b606081428110156140d357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f444d4d526f757465723a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168686600081811061411757fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146141b657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f444d4d526f757465723a20494e56414c49445f50415448000000000000000000604482015290519081900360640190fd5b61422388888080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808c0282810182019093528b82529093508b92508a918291850190849080828437600092019190915250614d4792505050565b6142918989898080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808d0282810182019093528c82529093508c92508b9182918501908490808284376000920191909152506151ec92505050565b915034826000815181106142a157fe5b60200260200101511115614300576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180615e5a6021913960400191505060405180910390fd5b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663d0e30db08360008151811061434957fe5b60200260200101516040518263ffffffff1660e01b81526004016000604051808303818588803b15801561437c57600080fd5b505af1158015614390573d6000803e3d6000fd5b50505050506143a58888600081811061338a57fe5b6144158289898080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050604080516020808d0282810182019093528c82529093508c92508b9182918501908490808284376000920191909152508a9250614fa3915050565b8160008151811061442257fe5b602002602001015134111561347257613472338360008151811061444257fe5b60200260200101513403614c0f565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663eb787f618484846040518463ffffffff1660e01b8152600401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff168152602001935050505060206040518083038186803b15801561451457600080fd5b505afa158015614528573d6000803e3d6000fd5b505050506040513d602081101561453e57600080fd5b50516145ab57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f444d4d526f757465723a20494e56414c49445f504f4f4c000000000000000000604482015290519081900360640190fd5b505050565b6000806000806000806145c48c8f8f615601565b5093509350935093508360001480156145db575082155b156145eb578a9550899450613bee565b60006145f88c8686615334565b90508a811161467b578881101561467057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f444d4d526f757465723a20494e53554646494349454e545f425f414d4f554e54604482015290519081900360640190fd5b8b9650945084614709565b60006146888c8688615334565b90508c81111561469457fe5b8a81101561470357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f444d4d526f757465723a20494e53554646494349454e545f415f414d4f554e54604482015290519081900360640190fd5b96508a95505b6000836e01000000000000000000000000000084028161472557fe5b8a519190049150811080159061473f575060208901518111155b614794576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180615fa16021913960400191505060405180910390fd5b5050505050509850989650505050505050565b6040805173ffffffffffffffffffffffffffffffffffffffff80861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f23b872dd0000000000000000000000000000000000000000000000000000000017905261483c908590615715565b50505050565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001790526145ab908490615715565b6148d98383614d47565b60005b600183510381101561483c576000808483815181106148f757fe5b602002602001015185846001018151811061490e57fe5b60200260200101519150915060006149268383615424565b509050600087858151811061493757fe5b602002602001015190506000806000806000806149688e8c8151811061495957fe5b60200260200101518b8b615601565b9450945094509450945060006149df868c73ffffffffffffffffffffffffffffffffffffffff166370a082318b6040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015611c7a57600080fd5b90506149ef8187878787876157ed565b96505050505050506000808473ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff1614614a3557826000614a39565b6000835b91509150600060028b51038910614a505789614a68565b8b8960010181518110614a5f57fe5b60200260200101515b60408051600080825260208201928390527f022c0d9f000000000000000000000000000000000000000000000000000000008352602482018781526044830187905273ffffffffffffffffffffffffffffffffffffffff8086166064850152608060848501908152845160a48601819052969750908b169563022c0d9f958a958a958a9591949193919260c486019290918190849084905b83811015614b18578181015183820152602001614b00565b50505050905090810190601f168015614b455780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b158015614b6757600080fd5b505af1158015614b7b573d6000803e3d6000fd5b50506001909a0199506148dc98505050505050505050565b600082821115614c0457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b508082035b92915050565b6040805160008082526020820190925273ffffffffffffffffffffffffffffffffffffffff84169083906040518082805190602001908083835b60208310614c8657805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101614c49565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114614ce8576040519150601f19603f3d011682016040523d82523d6000602084013e614ced565b606091505b50509050806145ab576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180615f2f6023913960400191505060405180910390fd5b600281511015614db857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f444d4d526f757465723a20494e56414c49445f50415448000000000000000000604482015290519081900360640190fd5b6001815103825114614e2b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f444d4d526f757465723a20494e56414c49445f504f4f4c535f50415448000000604482015290519081900360640190fd5b60005b82518110156145ab57614e7e828281518110614e4657fe5b6020026020010151838360010181518110614e5d57fe5b6020026020010151858481518110614e7157fe5b6020026020010151614451565b600101614e2e565b6060815167ffffffffffffffff81118015614ea057600080fd5b50604051908082528060200260200182016040528015614eca578160200160208202803683370190505b5090508381600081518110614edb57fe5b60200260200101818152505060005b6001835103811015614f9b576000806000806000614f45898781518110614f0d57fe5b6020026020010151898881518110614f2157fe5b60200260200101518a8960010181518110614f3857fe5b6020026020010151615601565b94509450945094509450614f70878781518110614f5e57fe5b602002602001015186868686866157ed565b878760010181518110614f7f57fe5b6020908102919091010152505060019093019250614eea915050565b509392505050565b60005b60018351038110156151e557600080848381518110614fc157fe5b6020026020010151858460010181518110614fd857fe5b6020026020010151915091506000614ff08383615424565b509050600088856001018151811061500457fe5b602002602001015190506000808373ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff161461504c57826000615050565b6000835b91509150600060028a51038810615067578861507f565b8a886001018151811061507657fe5b60200260200101515b90508a888151811061508d57fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1663022c0d9f848484600067ffffffffffffffff811180156150cb57600080fd5b506040519080825280601f01601f1916602001820160405280156150f6576020820181803683370190505b506040518563ffffffff1660e01b8152600401808581526020018481526020018373ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561516b578181015183820152602001615153565b50505050905090810190601f1680156151985780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b1580156151ba57600080fd5b505af11580156151ce573d6000803e3d6000fd5b505060019099019850614fa6975050505050505050565b5050505050565b6060815167ffffffffffffffff8111801561520657600080fd5b50604051908082528060200260200182016040528015615230578160200160208202803683370190505b509050838160018351038151811061524457fe5b602090810291909101015281517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff015b8015614f9b5760008060008060006152bf89600188038151811061529457fe5b60200260200101518960018903815181106152ab57fe5b60200260200101518a8981518110614f3857fe5b945094509450945094506152ea8787815181106152d857fe5b60200260200101518686868686615963565b8760018803815181106152f957fe5b602090810291909101015250507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9093019250615274915050565b60008084116153a457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f444d4d4c6962726172793a20494e53554646494349454e545f414d4f554e5400604482015290519081900360640190fd5b6000831180156153b45750600082115b615409576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180615e7b6022913960400191505060405180910390fd5b826154148584615ab9565b8161541b57fe5b04949350505050565b6000808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614156154c257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f444d4d4c6962726172793a204944454e544943414c5f41444452455353455300604482015290519081900360640190fd5b8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16106154fc5782846154ff565b83835b909250905073ffffffffffffffffffffffffffffffffffffffff821661558657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f444d4d4c6962726172793a205a45524f5f414444524553530000000000000000604482015290519081900360640190fd5b9250929050565b600082820183811015612ec657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b6000806000806000806156148888615424565b5090506000806000808c73ffffffffffffffffffffffffffffffffffffffff1663d66940276040518163ffffffff1660e01b815260040160a06040518083038186803b15801561566357600080fd5b505afa158015615677573d6000803e3d6000fd5b505050506040513d60a081101561568d57600080fd5b50805160208201516040830151606084015160809094015199506dffffffffffffffffffffffffffff928316975090821695508116935016905073ffffffffffffffffffffffffffffffffffffffff8c8116908616146156f057828482846156f5565b838383835b809a50819b50829c50839d50505050505050505050939792965093509350565b6060615777826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16615b2c9092919063ffffffff16565b8051909150156145ab5780806020019051602081101561579657600080fd5b50516145ab576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a815260200180615f77602a913960400191505060405180910390fd5b6000808711615847576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180615f526025913960400191505060405180910390fd5b6000861180156158575750600085115b6158ac576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180615e7b6022913960400191505060405180910390fd5b60006158d4670de0b6b3a76400006158ce6158c78287614b93565b8b90615ab9565b90615b3b565b905060006158e28286615ab9565b905060006158f0878461558d565b90506158fc8282615b3b565b9350838811615956576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180615e7b6022913960400191505060405180910390fd5b5050509695505050505050565b60008087116159bd576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180615f096026913960400191505060405180910390fd5b6000861180156159cc57508685115b615a21576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180615e7b6022913960400191505060405180910390fd5b6000615a2d8589615ab9565b90506000615a3b858a614b93565b9050615a526001615a4c8484615b3b565b9061558d565b9250615a6683670de0b6b3a7640000615ab9565b9150615a7a670de0b6b3a764000085614b93565b9050615aac816158ce847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff830161558d565b9998505050505050505050565b600082615ac857506000614c09565b82820282848281615ad557fe5b0414612ec6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180615ec36021913960400191505060405180910390fd5b6060612ec38484600085615bbc565b6000808211615bab57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b818381615bb457fe5b049392505050565b606082471015615c17576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180615e9d6026913960400191505060405180910390fd5b615c2085615d77565b615c8b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b600060608673ffffffffffffffffffffffffffffffffffffffff1685876040518082805190602001908083835b60208310615cf557805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101615cb8565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114615d57576040519150601f19603f3d011682016040523d82523d6000602084013e615d5c565b606091505b5091509150615d6c828286615d7d565b979650505050505050565b3b151590565b60608315615d8c575081612ec6565b825115615d9c5782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015615e00578181015183820152602001615de8565b50505050905090810190601f168015615e2d5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b6040518060400160405280600290602082028036833750919291505056fe444d4d526f757465723a204558434553534956455f494e5055545f414d4f554e54444d4d4c6962726172793a20494e53554646494349454e545f4c4951554944495459416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77444d4d526f757465723a20494e53554646494349454e545f4f55545055545f414d4f554e54444d4d4c6962726172793a20494e53554646494349454e545f4f55545055545f414d4f554e545472616e7366657248656c7065723a204554485f5452414e534645525f4641494c4544444d4d4c6962726172793a20494e53554646494349454e545f494e5055545f414d4f554e545361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564444d4d526f757465723a204f55545f4f465f424f554e44535f5652455345525645a2646970667358221220f37c2f506ca49cb898a2a392882b1ebba5f9cbce2ee4a30ae1d8f78dac365d2a64736f6c634300060c0033", + "deployedBytecode": "", + "linkReferences": {}, + "deployedLinkReferences": {} +} diff --git a/external/contracts/kyber/DMMFactory.sol b/external/contracts/kyber/DMMFactory.sol new file mode 100644 index 000000000..56d3daa90 --- /dev/null +++ b/external/contracts/kyber/DMMFactory.sol @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.6.12; + +import "@openzeppelin/contracts/utils/EnumerableSet.sol"; + +import "./interfaces/IDMMFactory.sol"; +import "./DMMPool.sol"; + +contract DMMFactory is IDMMFactory { + using EnumerableSet for EnumerableSet.AddressSet; + + uint256 internal constant BPS = 10000; + + address private feeTo; + uint16 private governmentFeeBps; + address public override feeToSetter; + + mapping(IERC20 => mapping(IERC20 => EnumerableSet.AddressSet)) internal tokenPools; + mapping(IERC20 => mapping(IERC20 => address)) public override getUnamplifiedPool; + address[] public override allPools; + + event PoolCreated( + IERC20 indexed token0, + IERC20 indexed token1, + address pool, + uint32 ampBps, + uint256 totalPool + ); + event SetFeeConfiguration(address feeTo, uint16 governmentFeeBps); + event SetFeeToSetter(address feeToSetter); + + constructor(address _feeToSetter) public { + feeToSetter = _feeToSetter; + } + + function createPool( + IERC20 tokenA, + IERC20 tokenB, + uint32 ampBps + ) external override returns (address pool) { + require(tokenA != tokenB, "DMM: IDENTICAL_ADDRESSES"); + (IERC20 token0, IERC20 token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); + require(address(token0) != address(0), "DMM: ZERO_ADDRESS"); + require(ampBps >= BPS, "DMM: INVALID_BPS"); + // only exist 1 unamplified pool of a pool. + require( + ampBps != BPS || getUnamplifiedPool[token0][token1] == address(0), + "DMM: UNAMPLIFIED_POOL_EXISTS" + ); + pool = address(new DMMPool()); + DMMPool(pool).initialize(token0, token1, ampBps); + // populate mapping in the reverse direction + tokenPools[token0][token1].add(pool); + tokenPools[token1][token0].add(pool); + if (ampBps == BPS) { + getUnamplifiedPool[token0][token1] = pool; + getUnamplifiedPool[token1][token0] = pool; + } + allPools.push(pool); + + emit PoolCreated(token0, token1, pool, ampBps, allPools.length); + } + + function setFeeConfiguration(address _feeTo, uint16 _governmentFeeBps) external override { + require(msg.sender == feeToSetter, "DMM: FORBIDDEN"); + require(_governmentFeeBps > 0 && _governmentFeeBps < 2000, "DMM: INVALID FEE"); + feeTo = _feeTo; + governmentFeeBps = _governmentFeeBps; + + emit SetFeeConfiguration(_feeTo, _governmentFeeBps); + } + + function setFeeToSetter(address _feeToSetter) external override { + require(msg.sender == feeToSetter, "DMM: FORBIDDEN"); + feeToSetter = _feeToSetter; + + emit SetFeeToSetter(_feeToSetter); + } + + function getFeeConfiguration() + external + override + view + returns (address _feeTo, uint16 _governmentFeeBps) + { + _feeTo = feeTo; + _governmentFeeBps = governmentFeeBps; + } + + function allPoolsLength() external override view returns (uint256) { + return allPools.length; + } + + function getPools(IERC20 token0, IERC20 token1) + external + override + view + returns (address[] memory _tokenPools) + { + uint256 length = tokenPools[token0][token1].length(); + _tokenPools = new address[](length); + for (uint256 i = 0; i < length; i++) { + _tokenPools[i] = tokenPools[token0][token1].at(i); + } + } + + function getPoolsLength(IERC20 token0, IERC20 token1) external view returns (uint256) { + return tokenPools[token0][token1].length(); + } + + function getPoolAtIndex( + IERC20 token0, + IERC20 token1, + uint256 index + ) external view returns (address pool) { + return tokenPools[token0][token1].at(index); + } + + function isPool( + IERC20 token0, + IERC20 token1, + address pool + ) external override view returns (bool) { + return tokenPools[token0][token1].contains(pool); + } +} \ No newline at end of file diff --git a/external/contracts/kyber/DMMPool.sol b/external/contracts/kyber/DMMPool.sol new file mode 100644 index 000000000..da257db36 --- /dev/null +++ b/external/contracts/kyber/DMMPool.sol @@ -0,0 +1,376 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.6.12; + +import "@openzeppelin/contracts/math/SafeMath.sol"; +import "@openzeppelin/contracts/math/Math.sol"; +import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; + +import "./libraries/MathExt.sol"; +import "./libraries/FeeFomula.sol"; +import "./libraries/ERC20Permit.sol"; + +import "./interfaces/IDMMFactory.sol"; +import "./interfaces/IDMMCallee.sol"; +import "./interfaces/IDMMPool.sol"; +import "./interfaces/IERC20Metadata.sol"; +import "./VolumeTrendRecorder.sol"; + +contract DMMPool is IDMMPool, ERC20Permit, ReentrancyGuard, VolumeTrendRecorder { + using SafeMath for uint256; + using SafeERC20 for IERC20; + + uint256 internal constant MAX_UINT112 = 2**112 - 1; + uint256 internal constant BPS = 10000; + + struct ReserveData { + uint256 reserve0; + uint256 reserve1; + uint256 vReserve0; + uint256 vReserve1; // only used when isAmpPool = true + } + + uint256 public constant MINIMUM_LIQUIDITY = 10**3; + /// @dev To make etherscan auto-verify new pool, these variables are not immutable + IDMMFactory public override factory; + IERC20 public override token0; + IERC20 public override token1; + + /// @dev uses single storage slot, accessible via getReservesData + uint112 internal reserve0; + uint112 internal reserve1; + uint32 public override ampBps; + /// @dev addition param only when amplification factor > 1 + uint112 internal vReserve0; + uint112 internal vReserve1; + + /// @dev vReserve0 * vReserve1, as of immediately after the most recent liquidity event + uint256 public override kLast; + + event Mint(address indexed sender, uint256 amount0, uint256 amount1); + event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to); + event Swap( + address indexed sender, + uint256 amount0In, + uint256 amount1In, + uint256 amount0Out, + uint256 amount1Out, + address indexed to, + uint256 feeInPrecision + ); + event Sync(uint256 vReserve0, uint256 vReserve1, uint256 reserve0, uint256 reserve1); + + constructor() public ERC20Permit("KyberDMM LP", "DMM-LP", "1") VolumeTrendRecorder(0) { + factory = IDMMFactory(msg.sender); + } + + // called once by the factory at time of deployment + function initialize( + IERC20 _token0, + IERC20 _token1, + uint32 _ampBps + ) external { + require(msg.sender == address(factory), "DMM: FORBIDDEN"); + token0 = _token0; + token1 = _token1; + ampBps = _ampBps; + } + + /// @dev this low-level function should be called from a contract + /// which performs important safety checks + function mint(address to) external override nonReentrant returns (uint256 liquidity) { + (bool isAmpPool, ReserveData memory data) = getReservesData(); + ReserveData memory _data; + _data.reserve0 = token0.balanceOf(address(this)); + _data.reserve1 = token1.balanceOf(address(this)); + uint256 amount0 = _data.reserve0.sub(data.reserve0); + uint256 amount1 = _data.reserve1.sub(data.reserve1); + + bool feeOn = _mintFee(isAmpPool, data); + uint256 _totalSupply = totalSupply(); // gas savings, must be defined here since totalSupply can update in _mintFee + if (_totalSupply == 0) { + if (isAmpPool) { + uint32 _ampBps = ampBps; + _data.vReserve0 = _data.reserve0.mul(_ampBps) / BPS; + _data.vReserve1 = _data.reserve1.mul(_ampBps) / BPS; + } + liquidity = MathExt.sqrt(amount0.mul(amount1)).sub(MINIMUM_LIQUIDITY); + _mint(address(-1), MINIMUM_LIQUIDITY); // permanently lock the first MINIMUM_LIQUIDITY tokens + } else { + liquidity = Math.min( + amount0.mul(_totalSupply) / data.reserve0, + amount1.mul(_totalSupply) / data.reserve1 + ); + if (isAmpPool) { + uint256 b = liquidity.add(_totalSupply); + _data.vReserve0 = Math.max(data.vReserve0.mul(b) / _totalSupply, _data.reserve0); + _data.vReserve1 = Math.max(data.vReserve1.mul(b) / _totalSupply, _data.reserve1); + } + } + require(liquidity > 0, "DMM: INSUFFICIENT_LIQUIDITY_MINTED"); + _mint(to, liquidity); + + _update(isAmpPool, _data); + if (feeOn) kLast = getK(isAmpPool, _data); + emit Mint(msg.sender, amount0, amount1); + } + + /// @dev this low-level function should be called from a contract + /// @dev which performs important safety checks + /// @dev user must transfer LP token to this contract before call burn + function burn(address to) + external + override + nonReentrant + returns (uint256 amount0, uint256 amount1) + { + (bool isAmpPool, ReserveData memory data) = getReservesData(); // gas savings + IERC20 _token0 = token0; // gas savings + IERC20 _token1 = token1; // gas savings + + uint256 balance0 = _token0.balanceOf(address(this)); + uint256 balance1 = _token1.balanceOf(address(this)); + require(balance0 >= data.reserve0 && balance1 >= data.reserve1, "DMM: UNSYNC_RESERVES"); + uint256 liquidity = balanceOf(address(this)); + + bool feeOn = _mintFee(isAmpPool, data); + uint256 _totalSupply = totalSupply(); // gas savings, must be defined here since totalSupply can update in _mintFee + amount0 = liquidity.mul(balance0) / _totalSupply; // using balances ensures pro-rata distribution + amount1 = liquidity.mul(balance1) / _totalSupply; // using balances ensures pro-rata distribution + require(amount0 > 0 && amount1 > 0, "DMM: INSUFFICIENT_LIQUIDITY_BURNED"); + _burn(address(this), liquidity); + _token0.safeTransfer(to, amount0); + _token1.safeTransfer(to, amount1); + ReserveData memory _data; + _data.reserve0 = _token0.balanceOf(address(this)); + _data.reserve1 = _token1.balanceOf(address(this)); + if (isAmpPool) { + uint256 b = Math.min( + _data.reserve0.mul(_totalSupply) / data.reserve0, + _data.reserve1.mul(_totalSupply) / data.reserve1 + ); + _data.vReserve0 = Math.max(data.vReserve0.mul(b) / _totalSupply, _data.reserve0); + _data.vReserve1 = Math.max(data.vReserve1.mul(b) / _totalSupply, _data.reserve1); + } + _update(isAmpPool, _data); + if (feeOn) kLast = getK(isAmpPool, _data); // data are up-to-date + emit Burn(msg.sender, amount0, amount1, to); + } + + /// @dev this low-level function should be called from a contract + /// @dev which performs important safety checks + function swap( + uint256 amount0Out, + uint256 amount1Out, + address to, + bytes calldata callbackData + ) external override nonReentrant { + require(amount0Out > 0 || amount1Out > 0, "DMM: INSUFFICIENT_OUTPUT_AMOUNT"); + (bool isAmpPool, ReserveData memory data) = getReservesData(); // gas savings + require( + amount0Out < data.reserve0 && amount1Out < data.reserve1, + "DMM: INSUFFICIENT_LIQUIDITY" + ); + + ReserveData memory newData; + { + // scope for _token{0,1}, avoids stack too deep errors + IERC20 _token0 = token0; + IERC20 _token1 = token1; + require(to != address(_token0) && to != address(_token1), "DMM: INVALID_TO"); + if (amount0Out > 0) _token0.safeTransfer(to, amount0Out); // optimistically transfer tokens + if (amount1Out > 0) _token1.safeTransfer(to, amount1Out); // optimistically transfer tokens + if (callbackData.length > 0) + IDMMCallee(to).dmmSwapCall(msg.sender, amount0Out, amount1Out, callbackData); + newData.reserve0 = _token0.balanceOf(address(this)); + newData.reserve1 = _token1.balanceOf(address(this)); + if (isAmpPool) { + newData.vReserve0 = data.vReserve0.add(newData.reserve0).sub(data.reserve0); + newData.vReserve1 = data.vReserve1.add(newData.reserve1).sub(data.reserve1); + } + } + uint256 amount0In = newData.reserve0 > data.reserve0 - amount0Out + ? newData.reserve0 - (data.reserve0 - amount0Out) + : 0; + uint256 amount1In = newData.reserve1 > data.reserve1 - amount1Out + ? newData.reserve1 - (data.reserve1 - amount1Out) + : 0; + require(amount0In > 0 || amount1In > 0, "DMM: INSUFFICIENT_INPUT_AMOUNT"); + uint256 feeInPrecision = verifyBalanceAndUpdateEma( + amount0In, + amount1In, + isAmpPool ? data.vReserve0 : data.reserve0, + isAmpPool ? data.vReserve1 : data.reserve1, + isAmpPool ? newData.vReserve0 : newData.reserve0, + isAmpPool ? newData.vReserve1 : newData.reserve1 + ); + + _update(isAmpPool, newData); + emit Swap(msg.sender, amount0In, amount1In, amount0Out, amount1Out, to, feeInPrecision); + } + + /// @dev force balances to match reserves + function skim(address to) external nonReentrant { + token0.safeTransfer(to, token0.balanceOf(address(this)).sub(reserve0)); + token1.safeTransfer(to, token1.balanceOf(address(this)).sub(reserve1)); + } + + /// @dev force reserves to match balances + function sync() external override nonReentrant { + (bool isAmpPool, ReserveData memory data) = getReservesData(); + bool feeOn = _mintFee(isAmpPool, data); + ReserveData memory newData; + newData.reserve0 = IERC20(token0).balanceOf(address(this)); + newData.reserve1 = IERC20(token1).balanceOf(address(this)); + // update virtual reserves if this is amp pool + if (isAmpPool) { + uint256 _totalSupply = totalSupply(); + uint256 b = Math.min( + newData.reserve0.mul(_totalSupply) / data.reserve0, + newData.reserve1.mul(_totalSupply) / data.reserve1 + ); + newData.vReserve0 = Math.max(data.vReserve0.mul(b) / _totalSupply, newData.reserve0); + newData.vReserve1 = Math.max(data.vReserve1.mul(b) / _totalSupply, newData.reserve1); + } + _update(isAmpPool, newData); + if (feeOn) kLast = getK(isAmpPool, newData); + } + + /// @dev returns data to calculate amountIn, amountOut + function getTradeInfo() + external + virtual + override + view + returns ( + uint112 _reserve0, + uint112 _reserve1, + uint112 _vReserve0, + uint112 _vReserve1, + uint256 feeInPrecision + ) + { + // gas saving to read reserve data + _reserve0 = reserve0; + _reserve1 = reserve1; + uint32 _ampBps = ampBps; + _vReserve0 = vReserve0; + _vReserve1 = vReserve1; + if (_ampBps == BPS) { + _vReserve0 = _reserve0; + _vReserve1 = _reserve1; + } + uint256 rFactorInPrecision = getRFactor(block.number); + feeInPrecision = getFinalFee(FeeFomula.getFee(rFactorInPrecision), _ampBps); + } + + /// @dev returns reserve data to calculate amount to add liquidity + function getReserves() external override view returns (uint112 _reserve0, uint112 _reserve1) { + _reserve0 = reserve0; + _reserve1 = reserve1; + } + + function name() public override view returns (string memory) { + IERC20Metadata _token0 = IERC20Metadata(address(token0)); + IERC20Metadata _token1 = IERC20Metadata(address(token1)); + return string(abi.encodePacked("KyberDMM LP ", _token0.symbol(), "-", _token1.symbol())); + } + + function symbol() public override view returns (string memory) { + IERC20Metadata _token0 = IERC20Metadata(address(token0)); + IERC20Metadata _token1 = IERC20Metadata(address(token1)); + return string(abi.encodePacked("DMM-LP ", _token0.symbol(), "-", _token1.symbol())); + } + + function verifyBalanceAndUpdateEma( + uint256 amount0In, + uint256 amount1In, + uint256 beforeReserve0, + uint256 beforeReserve1, + uint256 afterReserve0, + uint256 afterReserve1 + ) internal virtual returns (uint256 feeInPrecision) { + // volume = beforeReserve0 * amount1In / beforeReserve1 + amount0In (normalized into amount in token 0) + uint256 volume = beforeReserve0.mul(amount1In).div(beforeReserve1).add(amount0In); + uint256 rFactorInPrecision = recordNewUpdatedVolume(block.number, volume); + feeInPrecision = getFinalFee(FeeFomula.getFee(rFactorInPrecision), ampBps); + // verify balance update matches with fomula + uint256 balance0Adjusted = afterReserve0.mul(PRECISION); + balance0Adjusted = balance0Adjusted.sub(amount0In.mul(feeInPrecision)); + balance0Adjusted = balance0Adjusted / PRECISION; + uint256 balance1Adjusted = afterReserve1.mul(PRECISION); + balance1Adjusted = balance1Adjusted.sub(amount1In.mul(feeInPrecision)); + balance1Adjusted = balance1Adjusted / PRECISION; + require( + balance0Adjusted.mul(balance1Adjusted) >= beforeReserve0.mul(beforeReserve1), + "DMM: K" + ); + } + + /// @dev update reserves + function _update(bool isAmpPool, ReserveData memory data) internal { + reserve0 = safeUint112(data.reserve0); + reserve1 = safeUint112(data.reserve1); + if (isAmpPool) { + assert(data.vReserve0 >= data.reserve0 && data.vReserve1 >= data.reserve1); // never happen + vReserve0 = safeUint112(data.vReserve0); + vReserve1 = safeUint112(data.vReserve1); + } + emit Sync(data.vReserve0, data.vReserve1, data.reserve0, data.reserve1); + } + + /// @dev if fee is on, mint liquidity equivalent to configured fee of the growth in sqrt(k) + function _mintFee(bool isAmpPool, ReserveData memory data) internal returns (bool feeOn) { + (address feeTo, uint16 governmentFeeBps) = factory.getFeeConfiguration(); + feeOn = feeTo != address(0); + uint256 _kLast = kLast; // gas savings + if (feeOn) { + if (_kLast != 0) { + uint256 rootK = MathExt.sqrt(getK(isAmpPool, data)); + uint256 rootKLast = MathExt.sqrt(_kLast); + if (rootK > rootKLast) { + uint256 numerator = totalSupply().mul(rootK.sub(rootKLast)).mul( + governmentFeeBps + ); + uint256 denominator = rootK.add(rootKLast).mul(5000); + uint256 liquidity = numerator / denominator; + if (liquidity > 0) _mint(feeTo, liquidity); + } + } + } else if (_kLast != 0) { + kLast = 0; + } + } + + /// @dev gas saving to read reserve data + function getReservesData() internal view returns (bool isAmpPool, ReserveData memory data) { + data.reserve0 = reserve0; + data.reserve1 = reserve1; + isAmpPool = ampBps != BPS; + if (isAmpPool) { + data.vReserve0 = vReserve0; + data.vReserve1 = vReserve1; + } + } + + function getFinalFee(uint256 feeInPrecision, uint32 _ampBps) internal pure returns (uint256) { + if (_ampBps <= 20000) { + return feeInPrecision; + } else if (_ampBps <= 50000) { + return (feeInPrecision * 20) / 30; + } else if (_ampBps <= 200000) { + return (feeInPrecision * 10) / 30; + } else { + return (feeInPrecision * 4) / 30; + } + } + + function getK(bool isAmpPool, ReserveData memory data) internal pure returns (uint256) { + return isAmpPool ? data.vReserve0 * data.vReserve1 : data.reserve0 * data.reserve1; + } + + function safeUint112(uint256 x) internal pure returns (uint112) { + require(x <= MAX_UINT112, "DMM: OVERFLOW"); + return uint112(x); + } +} diff --git a/package-lock.json b/package-lock.json index b3e243431..a791b9ea1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@setprotocol/set-protocol-v2", - "version": "0.0.38", + "version": "0.0.43", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index bc2a30098..5a4743ebf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@setprotocol/set-protocol-v2", - "version": "0.0.42", + "version": "0.0.43", "description": "", "main": "dist", "types": "dist/types", diff --git a/test/fixtures/kyberV3DMM.spec.ts b/test/fixtures/kyberV3DMM.spec.ts new file mode 100644 index 000000000..86b79b37c --- /dev/null +++ b/test/fixtures/kyberV3DMM.spec.ts @@ -0,0 +1,177 @@ +import "module-alias/register"; + +import { Account } from "@utils/test/types"; +import { + ether, +} from "@utils/index"; +import { + addSnapshotBeforeRestoreAfterEach, + getAccounts, + getSystemFixture, + getKyberV3DMMFixture, + getWaffleExpect, +} from "@utils/test/index"; +import { SystemFixture, KyberV3DMMFixture } from "@utils/fixtures"; +import { ZERO, MAX_UINT_256 } from "@utils/constants"; +import { BigNumber } from "@ethersproject/bignumber"; +import { Address } from "@utils/types"; +import { DMMPool } from "../../typechain/DMMPool"; + +const expect = getWaffleExpect(); + +describe("KyberV3DMMFixture", () => { + let owner: Account; + + let setup: SystemFixture; + let kyberSetup: KyberV3DMMFixture; + + before(async () => { + [ + owner, + ] = await getAccounts(); + + setup = getSystemFixture(owner.address); + kyberSetup = getKyberV3DMMFixture(owner.address); + + await setup.initialize(); + }); + + addSnapshotBeforeRestoreAfterEach(); + + describe("#initialize", async () => { + let subjectOwner: Account; + let subjectWethAddress: Address; + let subjectWbtcAddress: Address; + let subjectDaiAddress: Address; + + beforeEach(async () => { + subjectOwner = owner; + subjectWethAddress = setup.weth.address; + subjectWbtcAddress = setup.wbtc.address; + subjectDaiAddress = setup.dai.address; + }); + + async function subject(): Promise { + await kyberSetup.initialize( + subjectOwner, + subjectWethAddress, + subjectWbtcAddress, + subjectDaiAddress + ); + } + + it("should deploy a WETH/DAI pool", async () => { + await subject(); + + const poolTokenZero = await kyberSetup.wethDaiPool.token0(); + const poolTokenOne = await kyberSetup.wethDaiPool.token1(); + + const [expectedTokenZero, expectedTokenOne] = kyberSetup.getTokenOrder( + setup.weth.address, + setup.dai.address + ); + + expect(poolTokenZero).to.eq(expectedTokenZero); + expect(poolTokenOne).to.eq(expectedTokenOne); + }); + + it("should deploy a WETH/WBTC pool", async () => { + await subject(); + + const poolTokenZero = await kyberSetup.wethWbtcPool.token0(); + const poolTokenOne = await kyberSetup.wethWbtcPool.token1(); + + const [expectedTokenZero, expectedTokenOne] = kyberSetup.getTokenOrder( + setup.weth.address, + setup.wbtc.address + ); + + expect(poolTokenZero).to.eq(expectedTokenZero); + expect(poolTokenOne).to.eq(expectedTokenOne); + }); + }); + + describe("#createNewPool", async () => { + let subjectTokenA: Address; + let subjectTokenB: Address; + let subjectAmpBps: BigNumber; + + beforeEach(async () => { + await kyberSetup.initialize(owner, setup.weth.address, setup.wbtc.address, setup.dai.address); + + subjectTokenA = setup.weth.address; + subjectTokenB = setup.dai.address; + subjectAmpBps = BigNumber.from(19000); + }); + + async function subject(): Promise { + return await kyberSetup.createNewPool( + subjectTokenA, + subjectTokenB, + subjectAmpBps + ); + } + + it("should create a new pool with correct amplification factor", async () => { + const pool = await subject(); + + const ampFactor = await pool.ampBps(); + const poolTokenZero = await pool.token0(); + const poolTokenOne = await pool.token1(); + + const expectedAmpFactor = BigNumber.from(19000); + const [expectedTokenZero, expectedTokenOne] = kyberSetup.getTokenOrder( + setup.weth.address, + setup.dai.address + ); + + expect(ampFactor).to.eq(expectedAmpFactor); + expect(poolTokenZero).to.eq(expectedTokenZero); + expect(poolTokenOne).to.eq(expectedTokenOne); + }); + }); + + describe("mint WETH/DAI pool share", async () => { + beforeEach(async () => { + await kyberSetup.initialize( + owner, + setup.weth.address, + setup.wbtc.address, + setup.dai.address + ); + + await setup.weth.approve(kyberSetup.dmmRouter.address, ether(1)); + await setup.dai.approve(kyberSetup.dmmRouter.address, ether(350)); + }); + + async function subject(): Promise { + await kyberSetup.dmmRouter.addLiquidity( + setup.weth.address, + setup.dai.address, + kyberSetup.wethDaiPool.address, + ether(1), + ether(350), + ether(.99), + ether(347.5), + [0, MAX_UINT_256], + owner.address, + MAX_UINT_256 + ); + } + + it("should return lp token to owner and decrement amounts", async () => { + const preDaiBalance = await setup.dai.balanceOf(owner.address); + const preWethBalance = await setup.weth.balanceOf(owner.address); + + await subject(); + + const postDaiBalance = await setup.dai.balanceOf(owner.address); + const postWethBalance = await setup.weth.balanceOf(owner.address); + const lpTokenBalance = await kyberSetup.wethDaiPool.balanceOf(owner.address); + + expect(preDaiBalance.sub(ether(350))).to.eq(postDaiBalance); + expect(preWethBalance.sub(ether(1))).to.eq(postWethBalance); + expect(lpTokenBalance).to.be.gt(ZERO); + }); + }); +}); \ No newline at end of file diff --git a/test/fixtures/uniswapV3.spec.ts b/test/fixtures/uniswapV3.spec.ts index fccdfaee4..998f966d7 100644 --- a/test/fixtures/uniswapV3.spec.ts +++ b/test/fixtures/uniswapV3.spec.ts @@ -87,7 +87,7 @@ describe("UniswapV3Fixture", () => { }); async function subject(): Promise { - return uniswapV3Fixture.createNewPair(subjectTokenOne, subjectTokenTwo, subjectFee, subjectRatio); + return await uniswapV3Fixture.createNewPair(subjectTokenOne, subjectTokenTwo, subjectFee, subjectRatio); } it("should create a V3 pool with the correct initial price", async () => { diff --git a/test/protocol/integration/index-exchange/kyberV3IndexExchangeAdapter.spec.ts b/test/protocol/integration/index-exchange/kyberV3IndexExchangeAdapter.spec.ts new file mode 100644 index 000000000..d1d0a2a6c --- /dev/null +++ b/test/protocol/integration/index-exchange/kyberV3IndexExchangeAdapter.spec.ts @@ -0,0 +1,213 @@ +import "module-alias/register"; + +import { BigNumber } from "@ethersproject/bignumber"; + +import { Address, Bytes } from "@utils/types"; +import { Account } from "@utils/test/types"; +import { ADDRESS_ZERO, ZERO } from "@utils/constants"; +import { KyberV3IndexExchangeAdapter } from "@utils/contracts"; +import DeployHelper from "@utils/deploys"; +import { + ether, +} from "@utils/index"; +import { + addSnapshotBeforeRestoreAfterEach, + getAccounts, + getSystemFixture, + getKyberV3DMMFixture, + getWaffleExpect, + getLastBlockTimestamp, + getRandomAddress +} from "@utils/test/index"; + +import { SystemFixture, KyberV3DMMFixture } from "@utils/fixtures"; + +const expect = getWaffleExpect(); + +describe("KyberV3IndexExchangeAdapter", () => { + let owner: Account; + let mockSetToken: Account; + let deployer: DeployHelper; + let setup: SystemFixture; + let kyberSetup: KyberV3DMMFixture; + + let kyberV3ExchangeAdapter: KyberV3IndexExchangeAdapter; + + before(async () => { + [ + owner, + mockSetToken, + ] = await getAccounts(); + + deployer = new DeployHelper(owner.wallet); + setup = getSystemFixture(owner.address); + await setup.initialize(); + + kyberSetup = getKyberV3DMMFixture(owner.address); + await kyberSetup.initialize(owner, setup.weth.address, setup.wbtc.address, setup.dai.address); + + kyberV3ExchangeAdapter = await deployer.adapters.deployKyberV3IndexExchangeAdapter( + kyberSetup.dmmRouter.address, + kyberSetup.dmmFactory.address + ); + }); + + addSnapshotBeforeRestoreAfterEach(); + + describe("constructor", async () => { + let subjectDMMRouter: Address; + let subjectDMMFactory: Address; + + beforeEach(async () => { + subjectDMMRouter = kyberSetup.dmmRouter.address; + subjectDMMFactory = kyberSetup.dmmFactory.address; + }); + + async function subject(): Promise { + return await deployer.adapters.deployKyberV3IndexExchangeAdapter(subjectDMMRouter, subjectDMMFactory); + } + + it("should have the correct router address", async () => { + const deployedKyberV3IndexExchangeAdapter = await subject(); + + const routerAddress = await deployedKyberV3IndexExchangeAdapter.dmmRouter(); + const expectedRouterAddress = kyberSetup.dmmRouter.address; + + expect(routerAddress).to.eq(expectedRouterAddress); + }); + + it("should have the correct factory address", async () => { + const deployedKyberV3IndexExchangeAdapter = await subject(); + + const factoryAddress = await deployedKyberV3IndexExchangeAdapter.dmmFactory(); + const expectedFactoryAddress = kyberSetup.dmmFactory.address; + + expect(factoryAddress).to.eq(expectedFactoryAddress); + }); + }); + + describe("getSpender", async () => { + async function subject(): Promise { + return await kyberV3ExchangeAdapter.getSpender(); + } + + it("should return the correct spender address", async () => { + const spender = await subject(); + const expectedSpender = kyberSetup.dmmRouter.address; + + expect(spender).to.eq(expectedSpender); + }); + }); + + describe("getTradeCalldata", async () => { + let sourceToken: Address; + let destinationToken: Address; + let sourceQuantity: BigNumber; + let destinationQuantity: BigNumber; + let poolAddress: Address; + + let subjectMockSetToken: Address; + let subjectSourceToken: Address; + let subjectDestinationToken: Address; + let subjectIsSendTokenFixed: boolean; + let subjectSourceQuantity: BigNumber; + let subjectDestinationQuantity: BigNumber; + let subjectData: Bytes; + + beforeEach(async () => { + sourceToken = kyberSetup.knc.address; // KNC Address + sourceQuantity = ether(100); // Trade 100 KNC + destinationToken = setup.weth.address; // WETH Address + destinationQuantity = ether(10); // Receive at least 10 ETH + poolAddress = (kyberSetup.kncWethPool.address).toLowerCase(); + + subjectSourceToken = sourceToken; + subjectDestinationToken = destinationToken; + subjectMockSetToken = mockSetToken.address; + subjectIsSendTokenFixed = true; + subjectSourceQuantity = sourceQuantity; + subjectDestinationQuantity = destinationQuantity; + subjectData = poolAddress; + }); + + async function subject(): Promise { + return await kyberV3ExchangeAdapter.getTradeCalldata( + subjectSourceToken, + subjectDestinationToken, + subjectMockSetToken, + subjectIsSendTokenFixed, + subjectSourceQuantity, + subjectDestinationQuantity, + subjectData, + ); + } + + describe("when boolean to swap exact tokens for tokens is true", async () => { + it("should return the correct trade calldata", async () => { + const calldata = await subject(); + const callTimestamp = await getLastBlockTimestamp(); + const expectedCallData = kyberSetup.dmmRouter.interface.encodeFunctionData("swapExactTokensForTokens", [ + sourceQuantity, + destinationQuantity, + [poolAddress], + [sourceToken, destinationToken], + subjectMockSetToken, + callTimestamp, + ]); + expect(JSON.stringify(calldata)).to.eq(JSON.stringify([kyberSetup.dmmRouter.address, ZERO, expectedCallData])); + }); + }); + + describe("when boolean to swap exact tokens for tokens is false", async () => { + beforeEach(async () => { + subjectIsSendTokenFixed = false; + }); + + it("should return the correct trade calldata", async () => { + const calldata = await subject(); + const callTimestamp = await getLastBlockTimestamp(); + const expectedCallData = kyberSetup.dmmRouter.interface.encodeFunctionData("swapTokensForExactTokens", [ + destinationQuantity, // Source and destination quantity are flipped for swapTokensForExactTokens + sourceQuantity, + [poolAddress], + [sourceToken, destinationToken], + subjectMockSetToken, + callTimestamp, + ]); + expect(JSON.stringify(calldata)).to.eq(JSON.stringify([kyberSetup.dmmRouter.address, ZERO, expectedCallData])); + }); + }); + + describe("when pool address is invalid", async () => { + describe("when pool address is zero address", async () => { + beforeEach(async () => { + subjectData = ADDRESS_ZERO; + }); + + it("should revert", async () => { + await expect(subject()).to.be.revertedWith("Invalid pool address"); + }); + }); + + describe("when pool address is random address", async () => { + beforeEach(async () => { + subjectData = (await getRandomAddress()).toLowerCase(); + }); + + it("should revert", async () => { + await expect(subject()).to.be.revertedWith("Invalid pool address"); + }); + }); + + describe("when pool address is for another token pair", async () => { + beforeEach(async () => { + subjectData = kyberSetup.wethDaiPool.address.toLowerCase(); + }); + + it("should revert", async () => { + await expect(subject()).to.be.revertedWith("Invalid pool address"); + }); + }); + }); + }); +}); \ No newline at end of file diff --git a/test/protocol/integration/wrap/kyberMigrationWrapAdapter.spec.ts b/test/protocol/integration/wrap/kyberMigrationWrapAdapter.spec.ts index 406f8d141..a4940040d 100644 --- a/test/protocol/integration/wrap/kyberMigrationWrapAdapter.spec.ts +++ b/test/protocol/integration/wrap/kyberMigrationWrapAdapter.spec.ts @@ -5,7 +5,7 @@ import { Address } from "@utils/types"; import { Account } from "@utils/test/types"; import { ZERO } from "@utils/constants"; import { KyberMigrationWrapAdapter } from "@utils/contracts"; -import { KyberNetworkTokenV2 } from "@utils/contracts/kyber"; +import { KyberNetworkTokenV2 } from "@utils/contracts/kyberV3"; import DeployHelper from "@utils/deploys"; import { ether, diff --git a/test/protocol/modules/generalIndexModule.spec.ts b/test/protocol/modules/generalIndexModule.spec.ts index dd38150c3..d4d48abfd 100644 --- a/test/protocol/modules/generalIndexModule.spec.ts +++ b/test/protocol/modules/generalIndexModule.spec.ts @@ -11,7 +11,9 @@ import { GeneralIndexModule, SetToken, UniswapV2IndexExchangeAdapter, - UniswapV3IndexExchangeAdapter } from "@utils/contracts"; + UniswapV3IndexExchangeAdapter, + KyberV3IndexExchangeAdapter +} from "@utils/contracts"; import DeployHelper from "@utils/deploys"; import { bitcoin, @@ -26,6 +28,7 @@ import { getAccounts, getBalancerFixture, getLastBlockTimestamp, + getKyberV3DMMFixture, getRandomAccount, getRandomAddress, getSystemFixture, @@ -33,7 +36,7 @@ import { getUniswapV3Fixture, getWaffleExpect } from "@utils/test/index"; -import { BalancerFixture, SystemFixture, UniswapFixture, UniswapV3Fixture } from "@utils/fixtures"; +import { BalancerFixture, KyberV3DMMFixture, SystemFixture, UniswapFixture, UniswapV3Fixture } from "@utils/fixtures"; import { ContractTransaction } from "ethers"; const expect = getWaffleExpect(); @@ -49,6 +52,7 @@ describe("GeneralIndexModule", () => { let sushiswapSetup: UniswapFixture; let balancerSetup: BalancerFixture; let uniswapV3Setup: UniswapV3Fixture; + let kyberV3Setup: KyberV3DMMFixture; let index: SetToken; let indexWithWeth: SetToken; @@ -58,11 +62,13 @@ describe("GeneralIndexModule", () => { let sushiswapAdapterName: string; let uniswapAdapterName: string; let uniswapV3AdapterName: string; + let kyberV3AdapterName: string; let balancerExchangeAdapter: BalancerV1IndexExchangeAdapter; let sushiswapExchangeAdapter: UniswapV2IndexExchangeAdapter; let uniswapExchangeAdapter: UniswapV2IndexExchangeAdapter; let uniswapV3ExchangeAdapter: UniswapV3IndexExchangeAdapter; + let kyberV3ExchangeAdapter: KyberV3IndexExchangeAdapter; let indexComponents: Address[]; let indexUnits: BigNumber[]; @@ -84,6 +90,7 @@ describe("GeneralIndexModule", () => { sushiswapSetup = getUniswapFixture(owner.address); balancerSetup = getBalancerFixture(owner.address); uniswapV3Setup = getUniswapV3Fixture(owner.address); + kyberV3Setup = getKyberV3DMMFixture(owner.address); await setup.initialize(); await uniswapSetup.initialize(owner, setup.weth.address, setup.wbtc.address, setup.dai.address); @@ -97,6 +104,7 @@ describe("GeneralIndexModule", () => { 9000, setup.dai ); + await kyberV3Setup.initialize(owner, setup.weth.address, setup.wbtc.address, setup.dai.address); indexModule = await deployer.modules.deployGeneralIndexModule( setup.controller.address, @@ -109,21 +117,27 @@ describe("GeneralIndexModule", () => { sushiswapExchangeAdapter = await deployer.adapters.deployUniswapV2IndexExchangeAdapter(sushiswapSetup.router.address); uniswapExchangeAdapter = await deployer.adapters.deployUniswapV2IndexExchangeAdapter(uniswapSetup.router.address); uniswapV3ExchangeAdapter = await deployer.adapters.deployUniswapV3IndexExchangeAdapter(uniswapV3Setup.swapRouter.address); + kyberV3ExchangeAdapter = await deployer.adapters.deployKyberV3IndexExchangeAdapter( + kyberV3Setup.dmmRouter.address, + kyberV3Setup.dmmFactory.address + ); balancerAdapterName = "BALANCER"; sushiswapAdapterName = "SUSHISWAP"; uniswapAdapterName = "UNISWAP"; uniswapV3AdapterName = "UNISWAPV3"; + kyberV3AdapterName = "KYBERV3"; await setup.integrationRegistry.batchAddIntegration( - [indexModule.address, indexModule.address, indexModule.address, indexModule.address], - [balancerAdapterName, sushiswapAdapterName, uniswapAdapterName, uniswapV3AdapterName], + [indexModule.address, indexModule.address, indexModule.address, indexModule.address, indexModule.address], + [balancerAdapterName, sushiswapAdapterName, uniswapAdapterName, uniswapV3AdapterName, kyberV3AdapterName], [ balancerExchangeAdapter.address, sushiswapExchangeAdapter.address, uniswapExchangeAdapter.address, uniswapV3ExchangeAdapter.address, + kyberV3ExchangeAdapter.address, ] ); }); @@ -204,15 +218,45 @@ describe("GeneralIndexModule", () => { ); await setup.weth.connect(owner.wallet).approve(uniswapV3Setup.nftPositionManager.address, ether(100)); - await setup.dai.connect(owner.wallet).approve(uniswapV3Setup.nftPositionManager.address, bitcoin(23000)); + await setup.dai.connect(owner.wallet).approve(uniswapV3Setup.nftPositionManager.address, ether(23000)); await uniswapV3Setup.addLiquidityWide( setup.weth, setup.dai, 3000, ether(100), - bitcoin(23000), + ether(23000), owner.address ); + + await setup.weth.connect(owner.wallet).approve(kyberV3Setup.dmmRouter.address, ether(1000)); + await setup.wbtc.connect(owner.wallet).approve(kyberV3Setup.dmmRouter.address, bitcoin(26)); + await kyberV3Setup.dmmRouter.connect(owner.wallet).addLiquidity( + setup.weth.address, + setup.wbtc.address, + kyberV3Setup.wethWbtcPool.address, + ether(1000), + bitcoin(26), + ether(999), + bitcoin(25.3), + [0, MAX_UINT_256], + owner.address, + MAX_UINT_256 + ); + + await setup.weth.connect(owner.wallet).approve(kyberV3Setup.dmmRouter.address, ether(100)); + await setup.dai.connect(owner.wallet).approve(kyberV3Setup.dmmRouter.address, ether(23000)); + await kyberV3Setup.dmmRouter.connect(owner.wallet).addLiquidity( + setup.weth.address, + setup.dai.address, + kyberV3Setup.wethDaiPool.address, + ether(100), + ether(23000), + ether(99), + ether(22950), + [0, MAX_UINT_256], + owner.address, + MAX_UINT_256 + ); }); describe("#constructor", async () => { @@ -309,8 +353,8 @@ describe("GeneralIndexModule", () => { ); }); - it("should revert", async() => { - await expect(subject()).to.be.revertedWith("External positions not allowed"); + it("should revert", async () => { + await expect(subject()).to.be.revertedWith("External positions not allowed"); }); }); }); @@ -338,10 +382,10 @@ describe("GeneralIndexModule", () => { // initialize indexModule on both SetTokens await initSetToken( index, - [uniswapSetup.uni.address, setup.wbtc.address, setup.dai.address, sushiswapSetup.uni.address], - [ether(800), bitcoin(.1), ether(1000), ether(500)], - [uniswapAdapterName, sushiswapAdapterName, balancerAdapterName, sushiswapAdapterName], - [ONE_MINUTE_IN_SECONDS.mul(3), ONE_MINUTE_IN_SECONDS, ONE_MINUTE_IN_SECONDS.mul(2), ONE_MINUTE_IN_SECONDS] + [uniswapSetup.uni.address, setup.wbtc.address, setup.dai.address, sushiswapSetup.uni.address], + [ether(800), bitcoin(.1), ether(1000), ether(500)], + [uniswapAdapterName, sushiswapAdapterName, balancerAdapterName, sushiswapAdapterName], + [ONE_MINUTE_IN_SECONDS.mul(3), ONE_MINUTE_IN_SECONDS, ONE_MINUTE_IN_SECONDS.mul(2), ONE_MINUTE_IN_SECONDS] ); await initSetToken( @@ -462,8 +506,8 @@ describe("GeneralIndexModule", () => { ); }); - it("should revert", async() => { - await expect(subject()).to.be.revertedWith("External positions not allowed"); + it("should revert", async () => { + await expect(subject()).to.be.revertedWith("External positions not allowed"); }); }); }); @@ -1033,7 +1077,7 @@ describe("GeneralIndexModule", () => { }); afterEach(async () => { - await indexModule.setExchanges(subjectSetToken.address, [setup.dai.address], [sushiswapAdapterName]); + await indexModule.setExchanges(subjectSetToken.address, [setup.dai.address], [balancerAdapterName]); }); it("the position units and lastTradeTimestamp should be set as expected", async () => { @@ -1125,6 +1169,112 @@ describe("GeneralIndexModule", () => { }); }); + describe("when exchange is Kyber V3 DMM", async () => { + describe("when component is beling sold using Kyber V3 DMM exchange", async () => { + beforeEach(async () => { + await indexModule.setExchanges(subjectSetToken.address, [setup.dai.address], [kyberV3AdapterName]); + await indexModule.setExchangeData(subjectSetToken.address, [setup.dai.address], [kyberV3Setup.wethDaiPool.address.toLowerCase()]); + + [, expectedOut] = await kyberV3Setup.dmmRouter.getAmountsOut( + ether(1000), + [kyberV3Setup.wethDaiPool.address], + [setup.dai.address, setup.weth.address] + ); + + subjectEthQuantityLimit = expectedOut; + }); + + afterEach(async () => { + await indexModule.setExchanges(subjectSetToken.address, [setup.dai.address], [balancerAdapterName]); + }); + + it("the position units and lastTradeTimestamp should be set as expected", async () => { + const currentDaiAmount = await setup.dai.balanceOf(subjectSetToken.address); + const currentWethAmount = await setup.weth.balanceOf(subjectSetToken.address); + const totalSupply = await subjectSetToken.totalSupply(); + + await subject(); + + const lastBlockTimestamp = await getLastBlockTimestamp(); + + const expectedWethPositionUnits = preciseDiv(currentWethAmount.add(expectedOut), totalSupply); + const expectedDaiPositionUnits = preciseDiv(currentDaiAmount.sub(ether(1000)), totalSupply); + + const wethPositionUnits = await subjectSetToken.getDefaultPositionRealUnit(setup.weth.address); + const daiPositionUnits = await subjectSetToken.getDefaultPositionRealUnit(setup.dai.address); + + const lastTrade = (await indexModule.executionInfo(subjectSetToken.address, setup.dai.address)).lastTradeTimestamp; + + expect(wethPositionUnits).to.eq(expectedWethPositionUnits); + expect(daiPositionUnits).to.eq(expectedDaiPositionUnits); + expect(lastTrade).to.eq(lastBlockTimestamp); + }); + + it("emits the correct TradeExecuted event", async () => { + await expect(subject()).to.emit(indexModule, "TradeExecuted").withArgs( + subjectSetToken.address, + setup.dai.address, + setup.weth.address, + kyberV3ExchangeAdapter.address, + trader.address, + ether(1000), + expectedOut, + ZERO + ); + }); + }); + + describe("when component is being bought using KyberV3", async () => { + beforeEach(async () => { + await subject(); // sell DAI for ETH on Balancer, as we would need ETH to buy WBTC on KyberV3 + + await indexModule.setExchanges(subjectSetToken.address, [setup.wbtc.address], [kyberV3AdapterName]); + await indexModule.setExchangeData(subjectSetToken.address, [setup.wbtc.address], [kyberV3Setup.wethWbtcPool.address]); + + subjectComponent = setup.wbtc.address; + subjectEthQuantityLimit = MAX_UINT_256; + }); + + afterEach(async () => { + await indexModule.setExchanges(subjectSetToken.address, [setup.wbtc.address], [sushiswapAdapterName]); + }); + + it("the position units and lastTradeTimestamp should be set as expected", async () => { + const amountOut = bitcoin(0.1); + const [expectedIn, ] = await kyberV3Setup.dmmRouter.getAmountsIn( + amountOut, + [kyberV3Setup.wethWbtcPool.address], + [setup.weth.address, setup.wbtc.address] + ); + + const currentWbtcAmount = await setup.wbtc.balanceOf(subjectSetToken.address); + const currentWethAmount = await setup.weth.balanceOf(subjectSetToken.address); + + const wethUnit = await subjectSetToken.getDefaultPositionRealUnit(setup.weth.address); + const wbtcUnit = await subjectSetToken.getDefaultPositionRealUnit(setup.wbtc.address); + const totalSupply = await subjectSetToken.totalSupply(); + + await subject(); + + const lastBlockTimestamp = await getLastBlockTimestamp(); + + const wbtcExcess = currentWbtcAmount.sub(preciseMul(totalSupply, wbtcUnit)); + const wethExcess = currentWethAmount.sub(preciseMul(totalSupply, wethUnit)); + + const expectedWethPositionUnits = preciseDiv(currentWethAmount.sub(expectedIn).sub(wethExcess), totalSupply); + const expectedWbtcPositionUnits = preciseDiv(currentWbtcAmount.add(amountOut).sub(wbtcExcess), totalSupply); + + const wethPositionUnits = await subjectSetToken.getDefaultPositionRealUnit(setup.weth.address); + const wbtcPositionUnits = await subjectSetToken.getDefaultPositionRealUnit(setup.wbtc.address); + const lastTrade = (await indexModule.executionInfo(subjectSetToken.address, setup.wbtc.address)).lastTradeTimestamp; + + expect(wbtcPositionUnits).to.eq(expectedWbtcPositionUnits); + expect(wethPositionUnits).to.eq(expectedWethPositionUnits); + expect(lastTrade).to.eq(lastBlockTimestamp); + }); + }); + }); + describe("when exchange doesn't return minimum receive eth amount, while selling component", async () => { beforeEach(async () => { expectedOut = (await balancerSetup.exchange.viewSplitExactIn( @@ -1217,7 +1367,7 @@ describe("GeneralIndexModule", () => { }); }); - describe("when the component is weth", async() => { + describe("when the component is weth", async () => { beforeEach(async () => { subjectComponent = setup.weth.address; }); @@ -1242,8 +1392,8 @@ describe("GeneralIndexModule", () => { ); }); - it("should revert", async() => { - await expect(subject()).to.be.revertedWith("External positions not allowed"); + it("should revert", async () => { + await expect(subject()).to.be.revertedWith("External positions not allowed"); }); }); @@ -1535,15 +1685,15 @@ describe("GeneralIndexModule", () => { }); beforeEach(async () => { - await setup.weth.connect(owner.wallet).approve(sushiswapSetup.router.address, ether(1000)); - await sushiswapSetup.uni.connect(owner.wallet).approve(sushiswapSetup.router.address, ether(200000)); + await setup.weth.connect(owner.wallet).approve(sushiswapSetup.router.address, ether(100)); + await sushiswapSetup.uni.connect(owner.wallet).approve(sushiswapSetup.router.address, ether(20000)); await sushiswapSetup.router.connect(owner.wallet).addLiquidity( setup.weth.address, sushiswapSetup.uni.address, - ether(1000), - ether(200000), - ether(800), - ether(100000), + ether(100), + ether(20000), + ether(90), + ether(19000), owner.address, MAX_UINT_256 ); @@ -1752,7 +1902,7 @@ describe("GeneralIndexModule", () => { }); describe("when the prototol fee percentage is 100", async () => { - beforeEach(async() => { + beforeEach(async () => { subjectFeePercentage = ether(100); await setup.controller.editFee( indexModule.address, @@ -1767,7 +1917,7 @@ describe("GeneralIndexModule", () => { }); describe("when the prototol fee percentage is MAX_UINT_256", async () => { - beforeEach(async() => { + beforeEach(async () => { subjectFeePercentage = ether(100); await setup.controller.editFee( indexModule.address, @@ -1843,8 +1993,8 @@ describe("GeneralIndexModule", () => { ); }); - it("should revert", async() => { - await expect(subject()).to.be.revertedWith("External positions not allowed"); + it("should revert", async () => { + await expect(subject()).to.be.revertedWith("External positions not allowed"); }); }); @@ -2545,7 +2695,7 @@ describe("GeneralIndexModule", () => { expect(postConditionTrader).to.be.false; }); - it("the tradersHistory should be updated correctly", async() => { + it("the tradersHistory should be updated correctly", async () => { const preConditionTraders = await indexModule.getAllowedTraders(subjectSetToken.address); expect(preConditionTraders).to.deep.equal(subjectTraders); diff --git a/utils/contracts/index.ts b/utils/contracts/index.ts index edd7cac40..a0341df19 100644 --- a/utils/contracts/index.ts +++ b/utils/contracts/index.ts @@ -43,6 +43,7 @@ export { InvokeMock } from "../../typechain/InvokeMock"; export { ISetValuer } from "../../typechain/ISetValuer"; export { IssuanceModule } from "../../typechain/IssuanceModule"; export { KyberExchangeAdapter } from "../../typechain/KyberExchangeAdapter"; +export { KyberV3IndexExchangeAdapter } from "../../typechain/KyberV3IndexExchangeAdapter"; export { KyberMigrationWrapAdapter } from "../../typechain/KyberMigrationWrapAdapter"; export { KyberNetworkProxyMock } from "../../typechain/KyberNetworkProxyMock"; export { LendToAaveMigrator } from "../../typechain/LendToAaveMigrator"; diff --git a/utils/contracts/kyber.ts b/utils/contracts/kyber.ts deleted file mode 100644 index 9d7a2e257..000000000 --- a/utils/contracts/kyber.ts +++ /dev/null @@ -1,2 +0,0 @@ -// External Kyber contracts -export { KyberNetworkTokenV2 } from "../../typechain/KyberNetworkTokenV2"; \ No newline at end of file diff --git a/utils/contracts/kyberV3.ts b/utils/contracts/kyberV3.ts new file mode 100644 index 000000000..aa7de0d31 --- /dev/null +++ b/utils/contracts/kyberV3.ts @@ -0,0 +1,5 @@ +// External Kyber contracts +export { KyberNetworkTokenV2 } from "../../typechain/KyberNetworkTokenV2"; +export { DMMFactory } from "../../typechain/DMMFactory"; +export { DMMPool } from "../../typechain/DMMPool"; +export { DMMRouter02 } from "../../typechain/DMMRouter02"; \ No newline at end of file diff --git a/utils/deploys/deployAdapters.ts b/utils/deploys/deployAdapters.ts index b40f2d3af..2c28ec247 100644 --- a/utils/deploys/deployAdapters.ts +++ b/utils/deploys/deployAdapters.ts @@ -8,6 +8,7 @@ import { CompoundLikeGovernanceAdapter, CurveStakingAdapter, KyberExchangeAdapter, + KyberV3IndexExchangeAdapter, KyberMigrationWrapAdapter, OneInchExchangeAdapter, AaveMigrationWrapAdapter, @@ -37,6 +38,7 @@ import { BalancerV1IndexExchangeAdapter__factory } from "../../typechain/factori import { CompoundLikeGovernanceAdapter__factory } from "../../typechain/factories/CompoundLikeGovernanceAdapter__factory"; import { CurveStakingAdapter__factory } from "../../typechain/factories/CurveStakingAdapter__factory"; import { KyberExchangeAdapter__factory } from "../../typechain/factories/KyberExchangeAdapter__factory"; +import { KyberV3IndexExchangeAdapter__factory } from "../../typechain/factories/KyberV3IndexExchangeAdapter__factory"; import { KyberMigrationWrapAdapter__factory } from "../../typechain/factories/KyberMigrationWrapAdapter__factory"; import { OneInchExchangeAdapter__factory } from "../../typechain/factories/OneInchExchangeAdapter__factory"; import { ZeroExApiAdapter__factory } from "../../typechain/factories/ZeroExApiAdapter__factory"; @@ -133,7 +135,7 @@ export default class DeployAdapters { public async deployCompoundWrapAdapter(libraryName: string, libraryAddress: Address): Promise { const linkId = convertLibraryNameToLinkId(libraryName); return await new CompoundWrapAdapter__factory( - // @ts-ignore + // @ts-ignore { [linkId]: libraryAddress, }, @@ -200,4 +202,8 @@ export default class DeployAdapters { public async deployUniswapV3ExchangeAdapter(swapRouter: Address): Promise { return await new UniswapV3ExchangeAdapter__factory(this._deployerSigner).deploy(swapRouter); } + + public async deployKyberV3IndexExchangeAdapter(dmmRouter: Address, dmmFactory: Address): Promise { + return await new KyberV3IndexExchangeAdapter__factory(this._deployerSigner).deploy(dmmRouter, dmmFactory); + } } diff --git a/utils/deploys/deployExternal.ts b/utils/deploys/deployExternal.ts index de1ece93b..4d46ab6ae 100644 --- a/utils/deploys/deployExternal.ts +++ b/utils/deploys/deployExternal.ts @@ -132,7 +132,15 @@ import { import { Registry__factory } from "../../typechain/factories/Registry__factory"; import { Vault__factory } from "../../typechain/factories/Vault__factory"; -import { KyberNetworkTokenV2 } from "../contracts/kyber"; +import { + KyberNetworkTokenV2, + DMMFactory, + DMMPool, + DMMRouter02 +} from "../contracts/kyberV3"; +import { DMMFactory__factory } from "../../typechain/factories/DMMFactory__factory"; +import { DMMRouter02__factory } from "../../typechain/factories/DMMRouter02__factory"; +import { DMMPool__factory } from "../../typechain/factories/DMMPool__factory"; import { KyberNetworkTokenV2__factory } from "../../typechain/factories/KyberNetworkTokenV2__factory"; @@ -568,11 +576,23 @@ export default class DeployExternalContracts { return await new Registry__factory(this._deployerSigner).deploy(); } - // KYBER + // KYBER V3 DMM public async deployKyberNetworkTokenV2(): Promise { return await new KyberNetworkTokenV2__factory(this._deployerSigner).deploy(); } + public async deployDMMFactory(_feeToSetter: string): Promise { + return await new DMMFactory__factory(this._deployerSigner).deploy(_feeToSetter); + } + + public async deployDMMRouter02(_factory: Address, _weth: Address): Promise { + return await new DMMRouter02__factory(this._deployerSigner).deploy(_factory, _weth); + } + + public async deployDMMPool(): Promise { + return await new DMMPool__factory(this._deployerSigner).deploy(); + } + // AXIE-INFINITY public async deployTokenSwap(oldToken: Address, newToken: Address): Promise { return await new TokenSwap__factory(this._deployerSigner).deploy(oldToken, newToken); diff --git a/utils/fixtures/index.ts b/utils/fixtures/index.ts index 963f70800..dd750ffe9 100644 --- a/utils/fixtures/index.ts +++ b/utils/fixtures/index.ts @@ -2,6 +2,7 @@ export { AaveFixture } from "./aaveFixture"; export { BalancerFixture } from "./balancerFixture"; export { CompoundFixture } from "./compoundFixture"; export { CurveFixture } from "./curveFixture"; +export { KyberV3DMMFixture } from "./kyberV3DMMFixture"; export { SystemFixture } from "./systemFixture"; export { UniswapFixture } from "./uniswapFixture"; export { UniswapV3Fixture } from "./uniswapV3Fixture"; diff --git a/utils/fixtures/kyberV3DMMFixture.ts b/utils/fixtures/kyberV3DMMFixture.ts new file mode 100644 index 000000000..1a8eba3fc --- /dev/null +++ b/utils/fixtures/kyberV3DMMFixture.ts @@ -0,0 +1,76 @@ +import DeployHelper from "../deploys"; +import { Signer } from "ethers"; +import { JsonRpcProvider, Web3Provider } from "@ethersproject/providers"; +import { Address } from "../types"; +import { Account } from "../test/types"; +import { BigNumber } from "@ethersproject/bignumber"; + +import { StandardTokenMock } from "../contracts"; +import { + DMMPool, + DMMFactory, + DMMRouter02 +} from "../contracts/kyberV3"; + +import { ether } from "../common"; +import { DMMPool__factory } from "../../typechain/factories/DMMPool__factory"; + +export class KyberV3DMMFixture { + private _deployer: DeployHelper; + private _ownerSigner: Signer; + + public owner: Account; + public knc: StandardTokenMock; + public dmmFactory: DMMFactory; + public dmmRouter: DMMRouter02; + + public kncWethPool: DMMPool; + public wethDaiPool: DMMPool; + public wethWbtcPool: DMMPool; + + constructor(provider: Web3Provider | JsonRpcProvider, ownerAddress: Address) { + this._ownerSigner = provider.getSigner(ownerAddress); + this._deployer = new DeployHelper(this._ownerSigner); + } + + public async initialize(_owner: Account, _weth: Address, _wbtc: Address, _dai: Address): Promise { + this.owner = _owner; + this.dmmFactory = await this._deployer.external.deployDMMFactory(this.owner.address); + this.dmmRouter = await this._deployer.external.deployDMMRouter02(this.dmmFactory.address, _weth); + this.knc = await this._deployer.mocks.deployTokenMock(this.owner.address, ether(100000), 18); + this.kncWethPool = await this.createNewPool( + _weth, + this.knc.address, + BigNumber.from(19000) // Amp factor of 1.9 (in BPS) because correlated assets + ); + this.wethDaiPool = await this.createNewPool( + _weth, + _dai, + BigNumber.from(10000) // Amp factor of 1 (in BPS) because un-correlated assets + ); + this.wethWbtcPool = await this.createNewPool( + _weth, + _wbtc, + BigNumber.from(15000) // Amp factor of 1.5 (in BPS) because correlated assets + ); + } + + /** + * Creates new DMM pool. The token addresses are interchangeable. + * NOTE: There can be at most 1 unamplified pool for a token pair, ie. only 1 pool can exist with ampBps = BPS (10000). + * Should there already be an existing unamplified pool, attempts to create another one will fail. + * + * @param _token0 address of token 1 + * @param _token1 address of token 2 + * @param _ampBps Amplification factor (in BPS) + */ + public async createNewPool(_tokenA: Address, _tokenB: Address, _ampBps: BigNumber): Promise { + await this.dmmFactory.createPool(_tokenA, _tokenB, _ampBps); + const poolAddress = await this.dmmFactory.allPools((await this.dmmFactory.allPoolsLength()).sub(1)); + return new DMMPool__factory(this._ownerSigner).attach(poolAddress); + } + + public getTokenOrder(_tokenOne: Address, _tokenTwo: Address): [Address, Address] { + return _tokenOne.toLowerCase() < _tokenTwo.toLowerCase() ? [_tokenOne, _tokenTwo] : [_tokenTwo, _tokenOne]; + } +} diff --git a/utils/test/index.ts b/utils/test/index.ts index 0c06360ef..dd49fb1ab 100644 --- a/utils/test/index.ts +++ b/utils/test/index.ts @@ -2,7 +2,17 @@ import { ethers } from "hardhat"; import { Address } from "../types"; -import { AaveFixture, BalancerFixture, CompoundFixture, CurveFixture, SystemFixture, UniswapFixture, YearnFixture, UniswapV3Fixture } from "../fixtures"; +import { + AaveFixture, + BalancerFixture, + CompoundFixture, + CurveFixture, + KyberV3DMMFixture, + SystemFixture, + UniswapFixture, + YearnFixture, + UniswapV3Fixture +} from "../fixtures"; import { Blockchain, ProtocolUtils } from "../common"; // Hardhat-Provider Aware Exports @@ -14,6 +24,7 @@ export const getAaveFixture = (ownerAddress: Address) => new AaveFixture(provide export const getBalancerFixture = (ownerAddress: Address) => new BalancerFixture(provider, ownerAddress); export const getCurveFixture = (ownerAddress: Address) => new CurveFixture(provider, ownerAddress); export const getCompoundFixture = (ownerAddress: Address) => new CompoundFixture(provider, ownerAddress); +export const getKyberV3DMMFixture = (ownerAddress: Address) => new KyberV3DMMFixture(provider, ownerAddress); export const getUniswapFixture = (ownerAddress: Address) => new UniswapFixture(provider, ownerAddress); export const getYearnFixture = (ownerAddress: Address) => new YearnFixture(provider, ownerAddress); export const getUniswapV3Fixture = (ownerAddress: Address) => new UniswapV3Fixture(provider, ownerAddress);