@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.
- package/build/contracts/Account.json +11 -11
- package/build/contracts/Actions.json +11 -11
- package/build/contracts/Address.json +1 -1
- package/build/contracts/Admin.json +23 -23
- package/build/contracts/AdminImpl.json +35 -307
- package/build/contracts/AdvancedMath.json +7 -7
- package/build/contracts/AmmRebalancerProxy.json +577 -621
- package/build/contracts/AmmRebalancerProxyV1.json +78 -32
- package/build/contracts/Babylonian.json +1 -1
- package/build/contracts/Bits.json +9 -9
- package/build/contracts/Cache.json +13 -13
- package/build/contracts/ChainlinkPriceOracleV1.json +16 -16
- package/build/contracts/Context.json +1 -1
- package/build/contracts/CustomTestToken.json +9 -9
- package/build/contracts/Decimal.json +9 -9
- package/build/contracts/DelayedMultiSig.json +9 -9
- package/build/contracts/DolomiteAmmERC20.json +11 -11
- package/build/contracts/DolomiteAmmFactory.json +14 -52
- package/build/contracts/DolomiteAmmLibrary.json +24 -24
- package/build/contracts/DolomiteAmmPair.json +27 -27
- package/build/contracts/DolomiteAmmRouterProxy.json +30 -363
- package/build/contracts/DolomiteMargin.json +21 -67
- package/build/contracts/DoubleExponentInterestSetter.json +15 -21
- package/build/contracts/EnumerableSet.json +7 -7
- package/build/contracts/ErroringOmiseToken.json +9 -9
- package/build/contracts/ErroringToken.json +10 -10
- package/build/contracts/Events.json +17 -17
- package/build/contracts/ExcessivelySafeCall.json +35 -35
- package/build/contracts/Exchange.json +15 -15
- package/build/contracts/Expiry.json +36 -36
- package/build/contracts/Getters.json +33 -33
- package/build/contracts/IAutoTrader.json +9 -9
- package/build/contracts/ICallee.json +7 -7
- package/build/contracts/IChainlinkAggregator.json +5 -5
- package/build/contracts/IDolomiteAmmERC20.json +5 -5
- package/build/contracts/IDolomiteAmmFactory.json +9 -9
- package/build/contracts/IDolomiteAmmPair.json +9 -9
- package/build/contracts/IDolomiteMargin.json +23 -23
- package/build/contracts/IERC20.json +1 -1
- package/build/contracts/IERC20Detailed.json +5 -5
- package/build/contracts/IExchangeWrapper.json +5 -5
- package/build/contracts/IExpiry.json +9 -9
- package/build/contracts/IInterestSetter.json +7 -7
- package/build/contracts/ILiquidationCallback.json +7 -7
- package/build/contracts/IMakerOracle.json +5 -5
- package/build/contracts/IOasisDex.json +5 -5
- package/build/contracts/IPriceOracle.json +7 -7
- package/build/contracts/IRecyclable.json +9 -9
- package/build/contracts/ITransferProxy.json +5 -5
- package/build/contracts/IUniswapV2Callee.json +5 -5
- package/build/contracts/IUniswapV2Factory.json +5 -5
- package/build/contracts/IUniswapV2Pair.json +5 -5
- package/build/contracts/IUniswapV2Router.json +5 -5
- package/build/contracts/IWETH.json +5 -5
- package/build/contracts/Interest.json +15 -15
- package/build/contracts/LiquidateOrVaporizeImpl.json +32 -83
- package/build/contracts/LiquidatorProxyHelper.json +23 -23
- package/build/contracts/LiquidatorProxyV1.json +30 -36
- package/build/contracts/LiquidatorProxyV1WithAmm.json +49 -105
- package/build/contracts/Math.json +1 -1
- package/build/contracts/Migrations.json +8 -14
- package/build/contracts/Monetary.json +7 -7
- package/build/contracts/MultiCall.json +8 -14
- package/build/contracts/MultiSig.json +7 -7
- package/build/contracts/OmiseToken.json +8 -8
- package/build/contracts/OnlyDolomiteMargin.json +11 -11
- package/build/contracts/Operation.json +15 -15
- package/build/contracts/OperationImpl.json +39 -47
- package/build/contracts/Ownable.json +1 -1
- package/build/contracts/PartiallyDelayedMultiSig.json +9 -9
- package/build/contracts/PayableProxy.json +17 -23
- package/build/contracts/Permission.json +11 -11
- package/build/contracts/PolynomialInterestSetter.json +13 -13
- package/build/contracts/RecyclableTokenProxy.json +25 -25
- package/build/contracts/ReentrancyGuard.json +1 -1
- package/build/contracts/Require.json +7 -7
- package/build/contracts/SafeERC20.json +1 -1
- package/build/contracts/SafeETH.json +7 -7
- package/build/contracts/SafeLiquidationCallback.json +17 -17
- package/build/contracts/SafeMath.json +1 -1
- package/build/contracts/SignedOperationProxy.json +21 -104
- package/build/contracts/SimpleFeeOwner.json +18 -63
- package/build/contracts/State.json +9 -9
- package/build/contracts/Storage.json +37 -37
- package/build/contracts/TestAmmRebalancerProxy.json +32 -58
- package/build/contracts/TestAutoTrader.json +22 -22
- package/build/contracts/TestBtcUsdChainlinkAggregator.json +10 -10
- package/build/contracts/TestCallee.json +19 -19
- package/build/contracts/TestChainlinkPriceOracleV1.json +10 -94
- package/build/contracts/TestCounter.json +7 -7
- package/build/contracts/TestDaiUsdChainlinkAggregator.json +11 -11
- package/build/contracts/TestDolomiteMargin.json +22 -22
- package/build/contracts/TestDoubleExponentInterestSetter.json +10 -10
- package/build/contracts/TestEthUsdChainlinkAggregator.json +11 -11
- package/build/contracts/TestExchangeWrapper.json +28 -28
- package/build/contracts/TestInterestSetter.json +13 -13
- package/build/contracts/TestLib.json +22 -22
- package/build/contracts/TestLinkUsdChainlinkAggregator.json +11 -11
- package/build/contracts/TestLiquidateCallback.json +719 -719
- package/build/contracts/TestLiquidationCallback.json +13 -13
- package/build/contracts/TestLrcEthChainlinkAggregator.json +11 -11
- package/build/contracts/TestMakerOracle.json +10 -10
- package/build/contracts/TestMaticUsdChainlinkAggregator.json +10 -10
- package/build/contracts/TestOasisDex.json +12 -12
- package/build/contracts/TestOperationImpl.json +14 -14
- package/build/contracts/TestPolynomialInterestSetter.json +10 -10
- package/build/contracts/TestPriceAggregator.json +9 -9
- package/build/contracts/TestPriceOracle.json +13 -13
- package/build/contracts/TestRecyclableToken.json +9 -9
- package/build/contracts/TestSimpleCallee.json +15 -15
- package/build/contracts/TestToken.json +9 -9
- package/build/contracts/TestTrader.json +17 -17
- package/build/contracts/TestUniswapAmmRebalancerProxy.json +16 -16
- package/build/contracts/TestUsdcUsdChainlinkAggregator.json +11 -11
- package/build/contracts/TestWETH.json +9 -9
- package/build/contracts/Time.json +9 -9
- package/build/contracts/Token.json +9 -9
- package/build/contracts/TokenA.json +10 -10
- package/build/contracts/TokenB.json +10 -10
- package/build/contracts/TokenC.json +10 -10
- package/build/contracts/TokenD.json +10 -10
- package/build/contracts/TokenE.json +10 -10
- package/build/contracts/TokenF.json +10 -10
- package/build/contracts/TransferProxy.json +22 -28
- package/build/contracts/TypedSignature.json +9 -9
- package/build/contracts/Types.json +9 -9
- package/build/contracts/UQ112x112.json +7 -7
- package/build/contracts/UniswapV2ERC20.json +7 -7
- package/build/contracts/UniswapV2Factory.json +12 -12
- package/build/contracts/UniswapV2Library.json +20 -20
- package/build/contracts/UniswapV2Pair.json +17 -17
- package/build/contracts/UniswapV2Router02.json +16 -16
- package/build/contracts/WETH9.json +1 -1
- package/contracts/external/amm/DolomiteAmmERC20.sol +135 -0
- package/contracts/external/amm/DolomiteAmmFactory.sol +122 -0
- package/contracts/external/amm/DolomiteAmmPair.sol +573 -0
- package/contracts/external/amm/SimpleFeeOwner.sol +107 -0
- package/contracts/external/helpers/LiquidatorProxyHelper.sol +252 -0
- package/contracts/external/helpers/OnlyDolomiteMargin.sol +63 -0
- package/contracts/external/interestsetters/DoubleExponentInterestSetter.sol +212 -0
- package/contracts/external/interestsetters/PolynomialInterestSetter.sol +205 -0
- package/contracts/external/interfaces/IChainlinkAggregator.sol +33 -0
- package/contracts/external/interfaces/IDolomiteAmmERC20.sol +52 -0
- package/contracts/external/interfaces/IDolomiteAmmFactory.sol +42 -0
- package/contracts/external/interfaces/IDolomiteAmmPair.sol +116 -0
- package/contracts/external/interfaces/IExpiry.sol +70 -0
- package/contracts/external/interfaces/IMakerOracle.sol +52 -0
- package/contracts/external/interfaces/IOasisDex.sol +326 -0
- package/contracts/external/interfaces/ITransferProxy.sol +53 -0
- package/contracts/external/interfaces/IUniswapV2Router.sol +134 -0
- package/contracts/external/lib/AdvancedMath.sol +23 -0
- package/contracts/external/lib/DolomiteAmmLibrary.sol +323 -0
- package/contracts/external/lib/TypedSignature.sol +120 -0
- package/contracts/external/lib/UQ112x112.sol +22 -0
- package/contracts/external/multisig/DelayedMultiSig.sol +206 -0
- package/contracts/external/multisig/MultiSig.sol +571 -0
- package/contracts/external/multisig/PartiallyDelayedMultiSig.sol +174 -0
- package/contracts/external/oracles/ChainlinkPriceOracleV1.sol +197 -0
- package/contracts/external/oracles/TestChainlinkPriceOracleV1.sol +98 -0
- package/contracts/external/proxies/AmmRebalancerProxyV1.sol +465 -0
- package/contracts/external/proxies/DolomiteAmmRouterProxy.sol +877 -0
- package/contracts/external/proxies/LiquidatorProxyV1.sol +507 -0
- package/contracts/external/proxies/LiquidatorProxyV1WithAmm.sol +574 -0
- package/contracts/external/proxies/PayableProxy.sol +146 -0
- package/contracts/external/proxies/RecyclableTokenProxy.sol +463 -0
- package/contracts/external/proxies/SignedOperationProxy.sol +553 -0
- package/contracts/external/proxies/TransferProxy.sol +207 -0
- package/contracts/external/traders/Expiry.sol +532 -0
- package/contracts/external/uniswap-v2/UniswapV2ERC20.sol +118 -0
- package/contracts/external/uniswap-v2/UniswapV2Factory.sol +67 -0
- package/contracts/external/uniswap-v2/UniswapV2Pair.sol +283 -0
- package/contracts/external/uniswap-v2/UniswapV2Router02.sol +566 -0
- package/contracts/external/uniswap-v2/interfaces/IUniswapV2Callee.sol +13 -0
- package/contracts/external/uniswap-v2/interfaces/IUniswapV2Factory.sol +18 -0
- package/contracts/external/uniswap-v2/interfaces/IUniswapV2Pair.sol +67 -0
- package/contracts/external/uniswap-v2/interfaces/IWETH.sol +7 -0
- package/contracts/external/uniswap-v2/libraries/SafeETH.sol +29 -0
- package/contracts/external/uniswap-v2/libraries/UniswapV2Library.sol +117 -0
- package/contracts/external/utils/MultiCall.sol +95 -0
- package/contracts/protocol/impl/artifacts/OperationImpl.json +80 -0
- package/contracts/protocol/impl/artifacts/OperationImpl_metadata.json +193 -0
- package/dist/build/published_contracts/AdminImpl.json +2 -2
- package/dist/build/published_contracts/AmmRebalancerProxyV1.json +5 -0
- package/dist/build/published_contracts/ChainlinkPriceOracleV1.json +1 -1
- package/dist/build/published_contracts/DolomiteAmmFactory.json +1 -1
- package/dist/build/published_contracts/DolomiteAmmRouterProxy.json +1 -1
- package/dist/build/published_contracts/DoubleExponentInterestSetter.json +2 -2
- package/dist/build/published_contracts/Expiry.json +1 -1
- package/dist/build/published_contracts/LiquidatorProxyV1.json +1 -1
- package/dist/build/published_contracts/LiquidatorProxyV1WithAmm.json +1 -1
- package/dist/build/published_contracts/MultiCall.json +1 -1
- package/dist/build/published_contracts/PayableProxy.json +2 -2
- package/dist/build/published_contracts/SignedOperationProxy.json +2 -2
- package/dist/build/published_contracts/SimpleFeeOwner.json +1 -1
- package/dist/build/published_contracts/TestUniswapAmmRebalancerProxy.json +140 -0
- package/dist/build/published_contracts/TransferProxy.json +1 -1
- package/dist/src/lib/Contracts.d.ts +3 -1
- package/dist/src/lib/Contracts.js +7 -3
- package/dist/src/lib/Contracts.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Copyright 2019 dYdX Trading Inc.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
pragma solidity ^0.5.7;
|
|
20
|
+
pragma experimental ABIEncoderV2;
|
|
21
|
+
|
|
22
|
+
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
|
|
23
|
+
import { IInterestSetter } from "../../protocol/interfaces/IInterestSetter.sol";
|
|
24
|
+
import { Interest } from "../../protocol/lib/Interest.sol";
|
|
25
|
+
import { Math } from "../../protocol/lib/Math.sol";
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @title PolynomialInterestSetter
|
|
30
|
+
* @author dYdX
|
|
31
|
+
*
|
|
32
|
+
* Interest setter that sets interest based on a polynomial of the usage percentage of the market.
|
|
33
|
+
*/
|
|
34
|
+
contract PolynomialInterestSetter is
|
|
35
|
+
IInterestSetter
|
|
36
|
+
{
|
|
37
|
+
using Math for uint256;
|
|
38
|
+
using SafeMath for uint256;
|
|
39
|
+
|
|
40
|
+
// ============ Constants ============
|
|
41
|
+
|
|
42
|
+
uint256 constant PERCENT = 100;
|
|
43
|
+
|
|
44
|
+
uint256 constant BASE = 10 ** 18;
|
|
45
|
+
|
|
46
|
+
uint256 constant SECONDS_IN_A_YEAR = 60 * 60 * 24 * 365;
|
|
47
|
+
|
|
48
|
+
uint256 constant BYTE = 8;
|
|
49
|
+
|
|
50
|
+
// ============ Structs ============
|
|
51
|
+
|
|
52
|
+
struct PolyStorage {
|
|
53
|
+
uint128 maxAPR;
|
|
54
|
+
uint128 coefficients;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ============ Storage ============
|
|
58
|
+
|
|
59
|
+
PolyStorage g_storage;
|
|
60
|
+
|
|
61
|
+
// ============ Constructor ============
|
|
62
|
+
|
|
63
|
+
constructor(
|
|
64
|
+
PolyStorage memory params
|
|
65
|
+
)
|
|
66
|
+
public
|
|
67
|
+
{
|
|
68
|
+
// verify that all coefficients add up to 100%
|
|
69
|
+
uint256 sumOfCoefficients = 0;
|
|
70
|
+
for (
|
|
71
|
+
uint256 coefficients = params.coefficients;
|
|
72
|
+
coefficients != 0;
|
|
73
|
+
coefficients >>= BYTE
|
|
74
|
+
) {
|
|
75
|
+
sumOfCoefficients += coefficients % 256;
|
|
76
|
+
}
|
|
77
|
+
require(
|
|
78
|
+
sumOfCoefficients == PERCENT,
|
|
79
|
+
"Coefficients must sum to 100"
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// store the params
|
|
83
|
+
g_storage = params;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ============ Public Functions ============
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Get the interest rate given some borrowed and supplied amounts. The interest function is a
|
|
90
|
+
* polynomial function of the utilization (borrowWei / supplyWei) of the market.
|
|
91
|
+
*
|
|
92
|
+
* - If borrowWei > supplyWei then the utilization is considered to be equal to 1.
|
|
93
|
+
* - If both are zero, then the utilization is considered to be equal to 0.
|
|
94
|
+
*
|
|
95
|
+
* @return The interest rate per second (times 10 ** 18)
|
|
96
|
+
*/
|
|
97
|
+
function getInterestRate(
|
|
98
|
+
address /* token */,
|
|
99
|
+
uint256 borrowWei,
|
|
100
|
+
uint256 supplyWei
|
|
101
|
+
)
|
|
102
|
+
external
|
|
103
|
+
view
|
|
104
|
+
returns (Interest.Rate memory)
|
|
105
|
+
{
|
|
106
|
+
if (borrowWei == 0) {
|
|
107
|
+
return Interest.Rate({
|
|
108
|
+
value: 0
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
PolyStorage memory s = g_storage;
|
|
113
|
+
uint256 maxAPR = s.maxAPR;
|
|
114
|
+
|
|
115
|
+
if (borrowWei >= supplyWei) {
|
|
116
|
+
return Interest.Rate({
|
|
117
|
+
value: maxAPR / SECONDS_IN_A_YEAR
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
uint256 result = 0;
|
|
122
|
+
uint256 polynomial = BASE;
|
|
123
|
+
|
|
124
|
+
// for each non-zero coefficient...
|
|
125
|
+
uint256 coefficients = s.coefficients;
|
|
126
|
+
while (true) {
|
|
127
|
+
// gets the lowest-order byte
|
|
128
|
+
uint256 coefficient = coefficients % 256;
|
|
129
|
+
|
|
130
|
+
// if non-zero, add to result
|
|
131
|
+
if (coefficient != 0) {
|
|
132
|
+
// no safeAdd since there are at most 16 coefficients
|
|
133
|
+
// no safeMul since (coefficient < 256 && polynomial <= 10**18)
|
|
134
|
+
result += coefficient * polynomial;
|
|
135
|
+
|
|
136
|
+
// break if this is the last non-zero coefficient
|
|
137
|
+
if (coefficient == coefficients) {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// increase the order of the polynomial term
|
|
143
|
+
// no safeDiv since supplyWei must be strictly larger than borrowWei
|
|
144
|
+
polynomial = polynomial.mul(borrowWei) / supplyWei;
|
|
145
|
+
|
|
146
|
+
// move to next coefficient
|
|
147
|
+
coefficients >>= BYTE;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// normalize the result
|
|
151
|
+
// no safeMul since result fits within 72 bits and maxAPR fits within 128 bits
|
|
152
|
+
// no safeDiv since the divisor is a non-zero constant
|
|
153
|
+
return Interest.Rate({
|
|
154
|
+
value: result * maxAPR / (SECONDS_IN_A_YEAR * BASE * PERCENT)
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Get the maximum APR that this interestSetter will return. The actual APY may be higher
|
|
160
|
+
* depending on how often the interest is compounded.
|
|
161
|
+
*
|
|
162
|
+
* @return The maximum APR
|
|
163
|
+
*/
|
|
164
|
+
function getMaxAPR()
|
|
165
|
+
external
|
|
166
|
+
view
|
|
167
|
+
returns (uint256)
|
|
168
|
+
{
|
|
169
|
+
return g_storage.maxAPR;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Get all of the coefficients of the interest calculation, starting from the coefficient for
|
|
174
|
+
* the first-order utilization variable.
|
|
175
|
+
*
|
|
176
|
+
* @return The coefficients
|
|
177
|
+
*/
|
|
178
|
+
function getCoefficients()
|
|
179
|
+
external
|
|
180
|
+
view
|
|
181
|
+
returns (uint256[] memory)
|
|
182
|
+
{
|
|
183
|
+
// allocate new array with maximum of 16 coefficients
|
|
184
|
+
uint256[] memory result = new uint256[](16);
|
|
185
|
+
|
|
186
|
+
// add the coefficients to the array
|
|
187
|
+
uint256 numCoefficients = 0;
|
|
188
|
+
for (
|
|
189
|
+
uint256 coefficients = g_storage.coefficients;
|
|
190
|
+
coefficients != 0;
|
|
191
|
+
coefficients >>= BYTE
|
|
192
|
+
) {
|
|
193
|
+
result[numCoefficients] = coefficients % 256;
|
|
194
|
+
numCoefficients++;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// modify result.length to match numCoefficients
|
|
198
|
+
/* solium-disable-next-line security/no-inline-assembly */
|
|
199
|
+
assembly {
|
|
200
|
+
mstore(result, numCoefficients)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Copyright 2020 Dolomite.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
pragma solidity ^0.5.7;
|
|
20
|
+
pragma experimental ABIEncoderV2;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @title IChainlinkAggregator
|
|
25
|
+
* @author Dolomite
|
|
26
|
+
*
|
|
27
|
+
* Gets the latest price from the Chainlink Oracle Network. Amount of decimals depends on the base.
|
|
28
|
+
*/
|
|
29
|
+
contract IChainlinkAggregator {
|
|
30
|
+
|
|
31
|
+
function latestAnswer() public view returns (int256);
|
|
32
|
+
|
|
33
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Copyright 2021 Dolomite.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
pragma solidity >=0.5.0;
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
contract IDolomiteAmmERC20 {
|
|
23
|
+
event Approval(address indexed owner, address indexed spender, uint value);
|
|
24
|
+
event Transfer(address indexed from, address indexed to, uint value);
|
|
25
|
+
|
|
26
|
+
function totalSupply() external view returns (uint);
|
|
27
|
+
function balanceOf(address owner) external view returns (uint);
|
|
28
|
+
function allowance(address owner, address spender) external view returns (uint);
|
|
29
|
+
|
|
30
|
+
function approve(address spender, uint value) external returns (bool);
|
|
31
|
+
function transfer(address to, uint value) external returns (bool);
|
|
32
|
+
function transferFrom(address from, address to, uint value) external returns (bool);
|
|
33
|
+
|
|
34
|
+
function DOMAIN_SEPARATOR() external view returns (bytes32);
|
|
35
|
+
function PERMIT_TYPEHASH() external pure returns (bytes32);
|
|
36
|
+
function nonces(address owner) external view returns (uint);
|
|
37
|
+
|
|
38
|
+
function permit(
|
|
39
|
+
address owner,
|
|
40
|
+
address spender,
|
|
41
|
+
uint value,
|
|
42
|
+
uint deadline,
|
|
43
|
+
uint8 v,
|
|
44
|
+
bytes32 r,
|
|
45
|
+
bytes32 s
|
|
46
|
+
)
|
|
47
|
+
external;
|
|
48
|
+
|
|
49
|
+
function name() public view returns (string memory);
|
|
50
|
+
function symbol() public view returns (string memory);
|
|
51
|
+
function decimals() public pure returns (uint8);
|
|
52
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Copyright 2021 Dolomite.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
pragma solidity >=0.5.0;
|
|
20
|
+
pragma experimental ABIEncoderV2;
|
|
21
|
+
|
|
22
|
+
import "../../protocol/lib/Account.sol";
|
|
23
|
+
import "../../protocol/lib/Actions.sol";
|
|
24
|
+
|
|
25
|
+
interface IDolomiteAmmFactory {
|
|
26
|
+
|
|
27
|
+
function feeTo() external view returns (address);
|
|
28
|
+
function feeToSetter() external view returns (address);
|
|
29
|
+
function dolomiteMargin() external view returns (address);
|
|
30
|
+
|
|
31
|
+
function getPair(address tokenA, address tokenB) external view returns (address pair);
|
|
32
|
+
function allPairs(uint) external view returns (address pair);
|
|
33
|
+
function allPairsLength() external view returns (uint);
|
|
34
|
+
function getPairInitCode() external pure returns (bytes memory);
|
|
35
|
+
function getPairInitCodeHash() external pure returns (bytes32);
|
|
36
|
+
|
|
37
|
+
function createPair(address tokenA, address tokenB) external returns (address pair);
|
|
38
|
+
|
|
39
|
+
function setFeeTo(address) external;
|
|
40
|
+
function setFeeToSetter(address) external;
|
|
41
|
+
|
|
42
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Copyright 2021 Dolomite.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
pragma solidity >=0.5.0;
|
|
20
|
+
pragma experimental ABIEncoderV2;
|
|
21
|
+
|
|
22
|
+
import "../../protocol/lib/Account.sol";
|
|
23
|
+
import "../../protocol/lib/Types.sol";
|
|
24
|
+
|
|
25
|
+
interface IDolomiteAmmPair {
|
|
26
|
+
|
|
27
|
+
event Approval(address indexed owner, address indexed spender, uint value);
|
|
28
|
+
event Transfer(address indexed from, address indexed to, uint value);
|
|
29
|
+
|
|
30
|
+
function name() external view returns (string memory);
|
|
31
|
+
|
|
32
|
+
function symbol() external view returns (string memory);
|
|
33
|
+
|
|
34
|
+
function decimals() external pure returns (uint8);
|
|
35
|
+
|
|
36
|
+
function totalSupply() external view returns (uint);
|
|
37
|
+
|
|
38
|
+
function balanceOf(address owner) external view returns (uint);
|
|
39
|
+
|
|
40
|
+
function allowance(address owner, address spender) external view returns (uint);
|
|
41
|
+
|
|
42
|
+
function approve(address spender, uint value) external returns (bool);
|
|
43
|
+
|
|
44
|
+
function transfer(address to, uint value) external returns (bool);
|
|
45
|
+
|
|
46
|
+
function transferFrom(address from, address to, uint value) external returns (bool);
|
|
47
|
+
|
|
48
|
+
function DOMAIN_SEPARATOR() external view returns (bytes32);
|
|
49
|
+
|
|
50
|
+
function PERMIT_TYPEHASH() external pure returns (bytes32);
|
|
51
|
+
|
|
52
|
+
function nonces(address owner) external view returns (uint);
|
|
53
|
+
|
|
54
|
+
function permit(
|
|
55
|
+
address owner,
|
|
56
|
+
address spender,
|
|
57
|
+
uint value,
|
|
58
|
+
uint deadline,
|
|
59
|
+
uint8 v,
|
|
60
|
+
bytes32 r,
|
|
61
|
+
bytes32 s
|
|
62
|
+
) external;
|
|
63
|
+
|
|
64
|
+
event Mint(address indexed sender, uint amount0Wei, uint amount1Wei);
|
|
65
|
+
event Burn(address indexed sender, uint amount0Wei, uint amount1Wei, address indexed to);
|
|
66
|
+
event Swap(
|
|
67
|
+
address indexed sender,
|
|
68
|
+
uint amount0In,
|
|
69
|
+
uint amount1In,
|
|
70
|
+
uint amount0Out,
|
|
71
|
+
uint amount1Out,
|
|
72
|
+
address indexed to
|
|
73
|
+
);
|
|
74
|
+
event Sync(uint112 reserve0, uint112 reserve1);
|
|
75
|
+
|
|
76
|
+
function MINIMUM_LIQUIDITY() external pure returns (uint);
|
|
77
|
+
|
|
78
|
+
function factory() external view returns (address);
|
|
79
|
+
|
|
80
|
+
function token0() external view returns (address);
|
|
81
|
+
|
|
82
|
+
function token1() external view returns (address);
|
|
83
|
+
|
|
84
|
+
function getReservesWei() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
|
|
85
|
+
|
|
86
|
+
function getReservesPar() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
|
|
87
|
+
|
|
88
|
+
function price0CumulativeLast() external view returns (uint);
|
|
89
|
+
|
|
90
|
+
function price1CumulativeLast() external view returns (uint);
|
|
91
|
+
|
|
92
|
+
function kLast() external view returns (uint);
|
|
93
|
+
|
|
94
|
+
function mint(address to) external returns (uint liquidity);
|
|
95
|
+
|
|
96
|
+
function burn(address to, uint toAccountNumber) external returns (uint amount0Wei, uint amount1Wei);
|
|
97
|
+
|
|
98
|
+
function getTradeCost(
|
|
99
|
+
uint256 inputMarketId,
|
|
100
|
+
uint256 outputMarketId,
|
|
101
|
+
Account.Info calldata makerAccount,
|
|
102
|
+
Account.Info calldata takerAccount,
|
|
103
|
+
Types.Par calldata,
|
|
104
|
+
Types.Par calldata,
|
|
105
|
+
Types.Wei calldata inputWei,
|
|
106
|
+
bytes calldata data
|
|
107
|
+
)
|
|
108
|
+
external
|
|
109
|
+
returns (Types.AssetAmount memory);
|
|
110
|
+
|
|
111
|
+
function skim(address to, uint toAccountNumber) external;
|
|
112
|
+
|
|
113
|
+
function sync() external;
|
|
114
|
+
|
|
115
|
+
function initialize(address _token0, address _token1, address _transferProxy) external;
|
|
116
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Copyright 2021 Dolomite.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
pragma solidity ^0.5.7;
|
|
20
|
+
pragma experimental ABIEncoderV2;
|
|
21
|
+
|
|
22
|
+
import {Account} from "../../protocol/lib/Account.sol";
|
|
23
|
+
import {Monetary} from "../../protocol/lib/Monetary.sol";
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @title IExpiry
|
|
28
|
+
* @author Dolomite
|
|
29
|
+
*/
|
|
30
|
+
contract IExpiry {
|
|
31
|
+
|
|
32
|
+
// ============ Enums ============
|
|
33
|
+
|
|
34
|
+
enum CallFunctionType {
|
|
35
|
+
SetExpiry,
|
|
36
|
+
SetApproval
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ============ Structs ============
|
|
40
|
+
|
|
41
|
+
struct SetExpiryArg {
|
|
42
|
+
Account.Info account;
|
|
43
|
+
uint256 marketId;
|
|
44
|
+
uint32 timeDelta;
|
|
45
|
+
bool forceUpdate;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
struct SetApprovalArg {
|
|
49
|
+
address sender;
|
|
50
|
+
uint32 minTimeDelta;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getSpreadAdjustedPrices(
|
|
54
|
+
uint256 heldMarketId,
|
|
55
|
+
uint256 owedMarketId,
|
|
56
|
+
uint32 expiry
|
|
57
|
+
)
|
|
58
|
+
public
|
|
59
|
+
view
|
|
60
|
+
returns (Monetary.Price memory heldPrice, Monetary.Price memory owedPriceAdj);
|
|
61
|
+
|
|
62
|
+
function getExpiry(
|
|
63
|
+
Account.Info memory account,
|
|
64
|
+
uint256 marketId
|
|
65
|
+
)
|
|
66
|
+
public
|
|
67
|
+
view
|
|
68
|
+
returns (uint32);
|
|
69
|
+
|
|
70
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Copyright 2019 dYdX Trading Inc.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
pragma solidity ^0.5.7;
|
|
20
|
+
pragma experimental ABIEncoderV2;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @title IMakerOracle
|
|
25
|
+
* @author dYdX
|
|
26
|
+
*
|
|
27
|
+
* Interface for the price oracles run by MakerDao
|
|
28
|
+
*/
|
|
29
|
+
interface IMakerOracle {
|
|
30
|
+
|
|
31
|
+
// Event that is logged when the `note` modifier is used
|
|
32
|
+
event LogNote(
|
|
33
|
+
bytes4 indexed msgSig,
|
|
34
|
+
address indexed msgSender,
|
|
35
|
+
bytes32 indexed arg1,
|
|
36
|
+
bytes32 indexed arg2,
|
|
37
|
+
uint256 msgValue,
|
|
38
|
+
bytes msgData
|
|
39
|
+
) anonymous;
|
|
40
|
+
|
|
41
|
+
// returns the current value (ETH/USD * 10**18) as a bytes32
|
|
42
|
+
function peek()
|
|
43
|
+
external
|
|
44
|
+
view
|
|
45
|
+
returns (bytes32, bool);
|
|
46
|
+
|
|
47
|
+
// requires a fresh price and then returns the current value
|
|
48
|
+
function read()
|
|
49
|
+
external
|
|
50
|
+
view
|
|
51
|
+
returns (bytes32);
|
|
52
|
+
}
|