@dolomite-exchange/dolomite-margin 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/build/contracts/Account.json +11 -11
  2. package/build/contracts/Actions.json +11 -11
  3. package/build/contracts/Address.json +1 -1
  4. package/build/contracts/Admin.json +23 -23
  5. package/build/contracts/AdminImpl.json +35 -307
  6. package/build/contracts/AdvancedMath.json +7 -7
  7. package/build/contracts/AmmRebalancerProxy.json +577 -621
  8. package/build/contracts/AmmRebalancerProxyV1.json +78 -32
  9. package/build/contracts/Babylonian.json +1 -1
  10. package/build/contracts/Bits.json +9 -9
  11. package/build/contracts/Cache.json +13 -13
  12. package/build/contracts/ChainlinkPriceOracleV1.json +16 -16
  13. package/build/contracts/Context.json +1 -1
  14. package/build/contracts/CustomTestToken.json +9 -9
  15. package/build/contracts/Decimal.json +9 -9
  16. package/build/contracts/DelayedMultiSig.json +9 -9
  17. package/build/contracts/DolomiteAmmERC20.json +11 -11
  18. package/build/contracts/DolomiteAmmFactory.json +14 -52
  19. package/build/contracts/DolomiteAmmLibrary.json +24 -24
  20. package/build/contracts/DolomiteAmmPair.json +27 -27
  21. package/build/contracts/DolomiteAmmRouterProxy.json +30 -363
  22. package/build/contracts/DolomiteMargin.json +21 -67
  23. package/build/contracts/DoubleExponentInterestSetter.json +15 -21
  24. package/build/contracts/EnumerableSet.json +7 -7
  25. package/build/contracts/ErroringOmiseToken.json +9 -9
  26. package/build/contracts/ErroringToken.json +10 -10
  27. package/build/contracts/Events.json +17 -17
  28. package/build/contracts/ExcessivelySafeCall.json +35 -35
  29. package/build/contracts/Exchange.json +15 -15
  30. package/build/contracts/Expiry.json +36 -36
  31. package/build/contracts/Getters.json +33 -33
  32. package/build/contracts/IAutoTrader.json +9 -9
  33. package/build/contracts/ICallee.json +7 -7
  34. package/build/contracts/IChainlinkAggregator.json +5 -5
  35. package/build/contracts/IDolomiteAmmERC20.json +5 -5
  36. package/build/contracts/IDolomiteAmmFactory.json +9 -9
  37. package/build/contracts/IDolomiteAmmPair.json +9 -9
  38. package/build/contracts/IDolomiteMargin.json +23 -23
  39. package/build/contracts/IERC20.json +1 -1
  40. package/build/contracts/IERC20Detailed.json +5 -5
  41. package/build/contracts/IExchangeWrapper.json +5 -5
  42. package/build/contracts/IExpiry.json +9 -9
  43. package/build/contracts/IInterestSetter.json +7 -7
  44. package/build/contracts/ILiquidationCallback.json +7 -7
  45. package/build/contracts/IMakerOracle.json +5 -5
  46. package/build/contracts/IOasisDex.json +5 -5
  47. package/build/contracts/IPriceOracle.json +7 -7
  48. package/build/contracts/IRecyclable.json +9 -9
  49. package/build/contracts/ITransferProxy.json +5 -5
  50. package/build/contracts/IUniswapV2Callee.json +5 -5
  51. package/build/contracts/IUniswapV2Factory.json +5 -5
  52. package/build/contracts/IUniswapV2Pair.json +5 -5
  53. package/build/contracts/IUniswapV2Router.json +5 -5
  54. package/build/contracts/IWETH.json +5 -5
  55. package/build/contracts/Interest.json +15 -15
  56. package/build/contracts/LiquidateOrVaporizeImpl.json +32 -83
  57. package/build/contracts/LiquidatorProxyHelper.json +23 -23
  58. package/build/contracts/LiquidatorProxyV1.json +30 -36
  59. package/build/contracts/LiquidatorProxyV1WithAmm.json +49 -105
  60. package/build/contracts/Math.json +1 -1
  61. package/build/contracts/Migrations.json +8 -14
  62. package/build/contracts/Monetary.json +7 -7
  63. package/build/contracts/MultiCall.json +8 -14
  64. package/build/contracts/MultiSig.json +7 -7
  65. package/build/contracts/OmiseToken.json +8 -8
  66. package/build/contracts/OnlyDolomiteMargin.json +11 -11
  67. package/build/contracts/Operation.json +15 -15
  68. package/build/contracts/OperationImpl.json +39 -47
  69. package/build/contracts/Ownable.json +1 -1
  70. package/build/contracts/PartiallyDelayedMultiSig.json +9 -9
  71. package/build/contracts/PayableProxy.json +17 -23
  72. package/build/contracts/Permission.json +11 -11
  73. package/build/contracts/PolynomialInterestSetter.json +13 -13
  74. package/build/contracts/RecyclableTokenProxy.json +25 -25
  75. package/build/contracts/ReentrancyGuard.json +1 -1
  76. package/build/contracts/Require.json +7 -7
  77. package/build/contracts/SafeERC20.json +1 -1
  78. package/build/contracts/SafeETH.json +7 -7
  79. package/build/contracts/SafeLiquidationCallback.json +17 -17
  80. package/build/contracts/SafeMath.json +1 -1
  81. package/build/contracts/SignedOperationProxy.json +21 -104
  82. package/build/contracts/SimpleFeeOwner.json +18 -63
  83. package/build/contracts/State.json +9 -9
  84. package/build/contracts/Storage.json +37 -37
  85. package/build/contracts/TestAmmRebalancerProxy.json +32 -58
  86. package/build/contracts/TestAutoTrader.json +22 -22
  87. package/build/contracts/TestBtcUsdChainlinkAggregator.json +10 -10
  88. package/build/contracts/TestCallee.json +19 -19
  89. package/build/contracts/TestChainlinkPriceOracleV1.json +10 -94
  90. package/build/contracts/TestCounter.json +7 -7
  91. package/build/contracts/TestDaiUsdChainlinkAggregator.json +11 -11
  92. package/build/contracts/TestDolomiteMargin.json +22 -22
  93. package/build/contracts/TestDoubleExponentInterestSetter.json +10 -10
  94. package/build/contracts/TestEthUsdChainlinkAggregator.json +11 -11
  95. package/build/contracts/TestExchangeWrapper.json +28 -28
  96. package/build/contracts/TestInterestSetter.json +13 -13
  97. package/build/contracts/TestLib.json +22 -22
  98. package/build/contracts/TestLinkUsdChainlinkAggregator.json +11 -11
  99. package/build/contracts/TestLiquidateCallback.json +719 -719
  100. package/build/contracts/TestLiquidationCallback.json +13 -13
  101. package/build/contracts/TestLrcEthChainlinkAggregator.json +11 -11
  102. package/build/contracts/TestMakerOracle.json +10 -10
  103. package/build/contracts/TestMaticUsdChainlinkAggregator.json +10 -10
  104. package/build/contracts/TestOasisDex.json +12 -12
  105. package/build/contracts/TestOperationImpl.json +14 -14
  106. package/build/contracts/TestPolynomialInterestSetter.json +10 -10
  107. package/build/contracts/TestPriceAggregator.json +9 -9
  108. package/build/contracts/TestPriceOracle.json +13 -13
  109. package/build/contracts/TestRecyclableToken.json +9 -9
  110. package/build/contracts/TestSimpleCallee.json +15 -15
  111. package/build/contracts/TestToken.json +9 -9
  112. package/build/contracts/TestTrader.json +17 -17
  113. package/build/contracts/TestUniswapAmmRebalancerProxy.json +16 -16
  114. package/build/contracts/TestUsdcUsdChainlinkAggregator.json +11 -11
  115. package/build/contracts/TestWETH.json +9 -9
  116. package/build/contracts/Time.json +9 -9
  117. package/build/contracts/Token.json +9 -9
  118. package/build/contracts/TokenA.json +10 -10
  119. package/build/contracts/TokenB.json +10 -10
  120. package/build/contracts/TokenC.json +10 -10
  121. package/build/contracts/TokenD.json +10 -10
  122. package/build/contracts/TokenE.json +10 -10
  123. package/build/contracts/TokenF.json +10 -10
  124. package/build/contracts/TransferProxy.json +22 -28
  125. package/build/contracts/TypedSignature.json +9 -9
  126. package/build/contracts/Types.json +9 -9
  127. package/build/contracts/UQ112x112.json +7 -7
  128. package/build/contracts/UniswapV2ERC20.json +7 -7
  129. package/build/contracts/UniswapV2Factory.json +12 -12
  130. package/build/contracts/UniswapV2Library.json +20 -20
  131. package/build/contracts/UniswapV2Pair.json +17 -17
  132. package/build/contracts/UniswapV2Router02.json +16 -16
  133. package/build/contracts/WETH9.json +1 -1
  134. package/contracts/external/amm/DolomiteAmmERC20.sol +135 -0
  135. package/contracts/external/amm/DolomiteAmmFactory.sol +122 -0
  136. package/contracts/external/amm/DolomiteAmmPair.sol +573 -0
  137. package/contracts/external/amm/SimpleFeeOwner.sol +107 -0
  138. package/contracts/external/helpers/LiquidatorProxyHelper.sol +252 -0
  139. package/contracts/external/helpers/OnlyDolomiteMargin.sol +63 -0
  140. package/contracts/external/interestsetters/DoubleExponentInterestSetter.sol +212 -0
  141. package/contracts/external/interestsetters/PolynomialInterestSetter.sol +205 -0
  142. package/contracts/external/interfaces/IChainlinkAggregator.sol +33 -0
  143. package/contracts/external/interfaces/IDolomiteAmmERC20.sol +52 -0
  144. package/contracts/external/interfaces/IDolomiteAmmFactory.sol +42 -0
  145. package/contracts/external/interfaces/IDolomiteAmmPair.sol +116 -0
  146. package/contracts/external/interfaces/IExpiry.sol +70 -0
  147. package/contracts/external/interfaces/IMakerOracle.sol +52 -0
  148. package/contracts/external/interfaces/IOasisDex.sol +326 -0
  149. package/contracts/external/interfaces/ITransferProxy.sol +53 -0
  150. package/contracts/external/interfaces/IUniswapV2Router.sol +134 -0
  151. package/contracts/external/lib/AdvancedMath.sol +23 -0
  152. package/contracts/external/lib/DolomiteAmmLibrary.sol +323 -0
  153. package/contracts/external/lib/TypedSignature.sol +120 -0
  154. package/contracts/external/lib/UQ112x112.sol +22 -0
  155. package/contracts/external/multisig/DelayedMultiSig.sol +206 -0
  156. package/contracts/external/multisig/MultiSig.sol +571 -0
  157. package/contracts/external/multisig/PartiallyDelayedMultiSig.sol +174 -0
  158. package/contracts/external/oracles/ChainlinkPriceOracleV1.sol +197 -0
  159. package/contracts/external/oracles/TestChainlinkPriceOracleV1.sol +98 -0
  160. package/contracts/external/proxies/AmmRebalancerProxyV1.sol +465 -0
  161. package/contracts/external/proxies/DolomiteAmmRouterProxy.sol +877 -0
  162. package/contracts/external/proxies/LiquidatorProxyV1.sol +507 -0
  163. package/contracts/external/proxies/LiquidatorProxyV1WithAmm.sol +574 -0
  164. package/contracts/external/proxies/PayableProxy.sol +146 -0
  165. package/contracts/external/proxies/RecyclableTokenProxy.sol +463 -0
  166. package/contracts/external/proxies/SignedOperationProxy.sol +553 -0
  167. package/contracts/external/proxies/TransferProxy.sol +207 -0
  168. package/contracts/external/traders/Expiry.sol +532 -0
  169. package/contracts/external/uniswap-v2/UniswapV2ERC20.sol +118 -0
  170. package/contracts/external/uniswap-v2/UniswapV2Factory.sol +67 -0
  171. package/contracts/external/uniswap-v2/UniswapV2Pair.sol +283 -0
  172. package/contracts/external/uniswap-v2/UniswapV2Router02.sol +566 -0
  173. package/contracts/external/uniswap-v2/interfaces/IUniswapV2Callee.sol +13 -0
  174. package/contracts/external/uniswap-v2/interfaces/IUniswapV2Factory.sol +18 -0
  175. package/contracts/external/uniswap-v2/interfaces/IUniswapV2Pair.sol +67 -0
  176. package/contracts/external/uniswap-v2/interfaces/IWETH.sol +7 -0
  177. package/contracts/external/uniswap-v2/libraries/SafeETH.sol +29 -0
  178. package/contracts/external/uniswap-v2/libraries/UniswapV2Library.sol +117 -0
  179. package/contracts/external/utils/MultiCall.sol +95 -0
  180. package/contracts/protocol/impl/artifacts/OperationImpl.json +80 -0
  181. package/contracts/protocol/impl/artifacts/OperationImpl_metadata.json +193 -0
  182. package/dist/build/published_contracts/AdminImpl.json +2 -2
  183. package/dist/build/published_contracts/AmmRebalancerProxyV1.json +5 -0
  184. package/dist/build/published_contracts/ChainlinkPriceOracleV1.json +1 -1
  185. package/dist/build/published_contracts/DolomiteAmmFactory.json +1 -1
  186. package/dist/build/published_contracts/DolomiteAmmRouterProxy.json +1 -1
  187. package/dist/build/published_contracts/DoubleExponentInterestSetter.json +2 -2
  188. package/dist/build/published_contracts/Expiry.json +1 -1
  189. package/dist/build/published_contracts/LiquidatorProxyV1.json +1 -1
  190. package/dist/build/published_contracts/LiquidatorProxyV1WithAmm.json +1 -1
  191. package/dist/build/published_contracts/MultiCall.json +1 -1
  192. package/dist/build/published_contracts/PayableProxy.json +2 -2
  193. package/dist/build/published_contracts/SignedOperationProxy.json +2 -2
  194. package/dist/build/published_contracts/SimpleFeeOwner.json +1 -1
  195. package/dist/build/published_contracts/TestUniswapAmmRebalancerProxy.json +140 -0
  196. package/dist/build/published_contracts/TransferProxy.json +1 -1
  197. package/dist/src/lib/Contracts.d.ts +3 -1
  198. package/dist/src/lib/Contracts.js +7 -3
  199. package/dist/src/lib/Contracts.js.map +1 -1
  200. package/package.json +2 -1
@@ -0,0 +1,117 @@
1
+ pragma solidity >=0.5.0;
2
+
3
+ import "@openzeppelin/contracts/math/SafeMath.sol";
4
+
5
+ import "../interfaces/IUniswapV2Factory.sol";
6
+ import "../interfaces/IUniswapV2Pair.sol";
7
+
8
+
9
+ library UniswapV2Library {
10
+ using SafeMath for uint;
11
+
12
+ bytes32 private constant PAIR_INIT_CODE_HASH = 0x5a9f5c3574970dea87031a97b794f46fbe4a0f2c3bf2d6e322a3edfb9ff6d0b5;
13
+
14
+ function getPairInitCodeHash() internal pure returns (bytes32) {
15
+ return PAIR_INIT_CODE_HASH;
16
+ }
17
+
18
+ // returns sorted token addresses, used to handle return values from pairs sorted in this order
19
+ function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
20
+ require(tokenA != tokenB, "UniswapV2Library: IDENTICAL_ADDRESSES");
21
+ (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
22
+ require(token0 != address(0), "UniswapV2Library: ZERO_ADDRESS");
23
+ }
24
+
25
+ // calculates the CREATE2 address for a pair without making any external calls
26
+ function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
27
+ (address token0, address token1) = sortTokens(tokenA, tokenB);
28
+ pair = address(
29
+ uint(
30
+ keccak256(
31
+ abi.encodePacked(
32
+ hex"ff",
33
+ factory,
34
+ keccak256(abi.encodePacked(token0, token1)),
35
+ PAIR_INIT_CODE_HASH
36
+ )
37
+ )
38
+ )
39
+ );
40
+ }
41
+
42
+ // fetches and sorts the reserves for a pair
43
+ function getReserves(
44
+ address factory,
45
+ address tokenA,
46
+ address tokenB
47
+ )
48
+ internal
49
+ view
50
+ returns (uint reserveA, uint reserveB) {
51
+ (address token0,) = sortTokens(tokenA, tokenB);
52
+ (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
53
+ (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
54
+ }
55
+
56
+ // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
57
+ function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
58
+ require(amountA > 0, "UniswapV2Library: INSUFFICIENT_AMOUNT");
59
+ require(reserveA > 0 && reserveB > 0, "UniswapV2Library: INSUFFICIENT_LIQUIDITY");
60
+ amountB = amountA.mul(reserveB) / reserveA;
61
+ }
62
+
63
+ // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
64
+ function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
65
+ require(amountIn > 0, "UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT");
66
+ require(reserveIn > 0 && reserveOut > 0, "UniswapV2Library: INSUFFICIENT_LIQUIDITY");
67
+ uint amountInWithFee = amountIn.mul(997);
68
+ uint numerator = amountInWithFee.mul(reserveOut);
69
+ uint denominator = reserveIn.mul(1000).add(amountInWithFee);
70
+ amountOut = numerator / denominator;
71
+ }
72
+
73
+ // given an output amount of an asset and pair reserves, returns a required input amount of the other asset
74
+ function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
75
+ require(amountOut > 0, "UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT");
76
+ require(reserveIn > 0 && reserveOut > 0, "UniswapV2Library: INSUFFICIENT_LIQUIDITY");
77
+ uint numerator = reserveIn.mul(amountOut).mul(1000);
78
+ uint denominator = reserveOut.sub(amountOut).mul(997);
79
+ amountIn = (numerator / denominator).add(1);
80
+ }
81
+
82
+ // performs chained getAmountOut calculations on any number of pairs
83
+ function getAmountsOut(
84
+ address factory,
85
+ uint amountIn,
86
+ address[] memory path
87
+ )
88
+ internal
89
+ view
90
+ returns (uint[] memory amounts) {
91
+ require(path.length >= 2, "UniswapV2Library: INVALID_PATH");
92
+ amounts = new uint[](path.length);
93
+ amounts[0] = amountIn;
94
+ for (uint i; i < path.length - 1; i++) {
95
+ (uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
96
+ amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
97
+ }
98
+ }
99
+
100
+ // performs chained getAmountIn calculations on any number of pairs
101
+ function getAmountsIn(
102
+ address factory,
103
+ uint amountOut,
104
+ address[] memory path
105
+ )
106
+ internal
107
+ view
108
+ returns (uint[] memory amounts) {
109
+ require(path.length >= 2, "UniswapV2Library: INVALID_PATH");
110
+ amounts = new uint[](path.length);
111
+ amounts[amounts.length - 1] = amountOut;
112
+ for (uint i = path.length - 1; i > 0; i--) {
113
+ (uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
114
+ amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
115
+ }
116
+ }
117
+ }
@@ -0,0 +1,95 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.5.0;
4
+ pragma experimental ABIEncoderV2;
5
+
6
+
7
+
8
+ /**
9
+ * @title MultiCall - Aggregate results from multiple read-only function calls
10
+ * @author Michael Elliot <mike@makerdao.com>
11
+ * @author Joshua Levine <joshua@makerdao.com>
12
+ * @author Nick Johnson <arachnid@notdot.net>
13
+ * @author Corey Caplan <corey@dolomite.io>
14
+ */
15
+ contract MultiCall {
16
+
17
+ struct Call {
18
+ address target;
19
+ bytes callData;
20
+ }
21
+
22
+ function aggregate(Call[] memory calls) public returns (uint256 blockNumber, bytes[] memory returnData) {
23
+ blockNumber = block.number;
24
+ returnData = new bytes[](calls.length);
25
+ for (uint256 i = 0; i < calls.length; i++) {
26
+ // solium-disable-next-line security/no-low-level-calls
27
+ (bool success, bytes memory result) = calls[i].target.call(calls[i].callData);
28
+ if (!success) {
29
+ if (result.length < 68) {
30
+ string memory targetString = _addressToString(calls[i].target);
31
+ revert(string(abi.encodePacked("Multicall::aggregate: revert at <", targetString, ">")));
32
+ } else {
33
+ // solium-disable-next-line security/no-inline-assembly
34
+ assembly {
35
+ result := add(result, 0x04)
36
+ }
37
+ string memory targetString = _addressToString(calls[i].target);
38
+ revert(
39
+ string(
40
+ abi.encodePacked(
41
+ "Multicall::aggregate: revert at <",
42
+ targetString,
43
+ "> with reason: ",
44
+ abi.decode(result, (string))
45
+ )
46
+ )
47
+ );
48
+ }
49
+ }
50
+ returnData[i] = result;
51
+ }
52
+ }
53
+
54
+ // Helper functions
55
+ function getEthBalance(address addr) public view returns (uint256 balance) {
56
+ balance = addr.balance;
57
+ }
58
+
59
+ function getBlockHash(uint256 blockNumber) public view returns (bytes32 blockHash) {
60
+ blockHash = blockhash(blockNumber);
61
+ }
62
+
63
+ function getLastBlockHash() public view returns (bytes32 blockHash) {
64
+ blockHash = blockhash(block.number - 1);
65
+ }
66
+
67
+ function getCurrentBlockTimestamp() public view returns (uint256 timestamp) {
68
+ timestamp = block.timestamp;
69
+ }
70
+
71
+ function getCurrentBlockDifficulty() public view returns (uint256 difficulty) {
72
+ difficulty = block.difficulty;
73
+ }
74
+
75
+ function getCurrentBlockGasLimit() public view returns (uint256 gaslimit) {
76
+ gaslimit = block.gaslimit;
77
+ }
78
+
79
+ function getCurrentBlockCoinbase() public view returns (address coinbase) {
80
+ coinbase = block.coinbase;
81
+ }
82
+
83
+ function _addressToString(address _address) internal pure returns(string memory) {
84
+ bytes32 _bytes = bytes32(uint256(_address));
85
+ bytes memory HEX = "0123456789abcdef";
86
+ bytes memory _string = new bytes(42);
87
+ _string[0] = "0";
88
+ _string[1] = "x";
89
+ for (uint i = 0; i < 20; i++) {
90
+ _string[2 + i * 2] = HEX[uint8(_bytes[i + 12] >> 4)];
91
+ _string[3 + i * 2] = HEX[uint8(_bytes[i + 12] & 0x0f)];
92
+ }
93
+ return string(_string);
94
+ }
95
+ }