@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,207 @@
|
|
|
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 { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
|
23
|
+
|
|
24
|
+
import { IDolomiteMargin } from "../../protocol/interfaces/IDolomiteMargin.sol";
|
|
25
|
+
|
|
26
|
+
import { Account } from "../../protocol/lib/Account.sol";
|
|
27
|
+
import { Actions } from "../../protocol/lib/Actions.sol";
|
|
28
|
+
import { Types } from "../../protocol/lib/Types.sol";
|
|
29
|
+
import { Require } from "../../protocol/lib/Require.sol";
|
|
30
|
+
|
|
31
|
+
import { OnlyDolomiteMargin } from "../helpers/OnlyDolomiteMargin.sol";
|
|
32
|
+
|
|
33
|
+
import { ITransferProxy } from "../interfaces/ITransferProxy.sol";
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @title TransferProxy
|
|
38
|
+
* @author Dolomite
|
|
39
|
+
*
|
|
40
|
+
* Contract for sending internal balances within Dolomite to other users/margin accounts easily
|
|
41
|
+
*/
|
|
42
|
+
contract TransferProxy is ITransferProxy, OnlyDolomiteMargin, ReentrancyGuard {
|
|
43
|
+
|
|
44
|
+
// ============ Constants ============
|
|
45
|
+
|
|
46
|
+
bytes32 constant FILE = "TransferProxy";
|
|
47
|
+
|
|
48
|
+
// ============ State Variables ============
|
|
49
|
+
|
|
50
|
+
mapping(address => bool) public isCallerTrusted;
|
|
51
|
+
|
|
52
|
+
// ============ Modifiers ============
|
|
53
|
+
|
|
54
|
+
modifier isAuthorized(address sender) {
|
|
55
|
+
Require.that(
|
|
56
|
+
isCallerTrusted[sender],
|
|
57
|
+
FILE,
|
|
58
|
+
"unauthorized"
|
|
59
|
+
);
|
|
60
|
+
_;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ============ Constructor ============
|
|
64
|
+
|
|
65
|
+
constructor (
|
|
66
|
+
address dolomiteMargin
|
|
67
|
+
)
|
|
68
|
+
public
|
|
69
|
+
OnlyDolomiteMargin(dolomiteMargin)
|
|
70
|
+
{}
|
|
71
|
+
|
|
72
|
+
// ============ External Functions ============
|
|
73
|
+
|
|
74
|
+
function setIsCallerTrusted(address caller, bool isTrusted) external {
|
|
75
|
+
Require.that(
|
|
76
|
+
DOLOMITE_MARGIN.getIsGlobalOperator(msg.sender),
|
|
77
|
+
FILE,
|
|
78
|
+
"unauthorized"
|
|
79
|
+
);
|
|
80
|
+
isCallerTrusted[caller] = isTrusted;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function transfer(
|
|
84
|
+
uint fromAccountIndex,
|
|
85
|
+
address to,
|
|
86
|
+
uint toAccountIndex,
|
|
87
|
+
address token,
|
|
88
|
+
uint amount
|
|
89
|
+
)
|
|
90
|
+
external
|
|
91
|
+
nonReentrant
|
|
92
|
+
isAuthorized(msg.sender)
|
|
93
|
+
{
|
|
94
|
+
uint[] memory markets = new uint[](1);
|
|
95
|
+
markets[0] = DOLOMITE_MARGIN.getMarketIdByTokenAddress(token);
|
|
96
|
+
|
|
97
|
+
uint[] memory amounts = new uint[](1);
|
|
98
|
+
amounts[0] = amount;
|
|
99
|
+
|
|
100
|
+
_transferMultiple(
|
|
101
|
+
fromAccountIndex,
|
|
102
|
+
to,
|
|
103
|
+
toAccountIndex,
|
|
104
|
+
markets,
|
|
105
|
+
amounts
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function transferMultiple(
|
|
110
|
+
uint fromAccountIndex,
|
|
111
|
+
address to,
|
|
112
|
+
uint toAccountIndex,
|
|
113
|
+
address[] calldata tokens,
|
|
114
|
+
uint[] calldata amounts
|
|
115
|
+
)
|
|
116
|
+
external
|
|
117
|
+
nonReentrant
|
|
118
|
+
isAuthorized(msg.sender)
|
|
119
|
+
{
|
|
120
|
+
IDolomiteMargin dolomiteMargin = DOLOMITE_MARGIN;
|
|
121
|
+
uint[] memory markets = new uint[](tokens.length);
|
|
122
|
+
for (uint i = 0; i < markets.length; i++) {
|
|
123
|
+
markets[i] = dolomiteMargin.getMarketIdByTokenAddress(tokens[i]);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
_transferMultiple(
|
|
127
|
+
fromAccountIndex,
|
|
128
|
+
to,
|
|
129
|
+
toAccountIndex,
|
|
130
|
+
markets,
|
|
131
|
+
amounts
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function transferMultipleWithMarkets(
|
|
136
|
+
uint fromAccountIndex,
|
|
137
|
+
address to,
|
|
138
|
+
uint toAccountIndex,
|
|
139
|
+
uint[] calldata markets,
|
|
140
|
+
uint[] calldata amounts
|
|
141
|
+
)
|
|
142
|
+
external
|
|
143
|
+
nonReentrant
|
|
144
|
+
isAuthorized(msg.sender)
|
|
145
|
+
{
|
|
146
|
+
_transferMultiple(
|
|
147
|
+
fromAccountIndex,
|
|
148
|
+
to,
|
|
149
|
+
toAccountIndex,
|
|
150
|
+
markets,
|
|
151
|
+
amounts
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function _transferMultiple(
|
|
156
|
+
uint fromAccountIndex,
|
|
157
|
+
address to,
|
|
158
|
+
uint toAccountIndex,
|
|
159
|
+
uint[] memory markets,
|
|
160
|
+
uint[] memory amounts
|
|
161
|
+
)
|
|
162
|
+
internal
|
|
163
|
+
{
|
|
164
|
+
Require.that(
|
|
165
|
+
markets.length == amounts.length,
|
|
166
|
+
FILE,
|
|
167
|
+
"invalid params length"
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
Account.Info[] memory accounts = new Account.Info[](2);
|
|
171
|
+
accounts[0] = Account.Info(msg.sender, fromAccountIndex);
|
|
172
|
+
accounts[1] = Account.Info(to, toAccountIndex);
|
|
173
|
+
|
|
174
|
+
Actions.ActionArgs[] memory actions = new Actions.ActionArgs[](markets.length);
|
|
175
|
+
for (uint i = 0; i < markets.length; i++) {
|
|
176
|
+
Types.AssetAmount memory assetAmount;
|
|
177
|
+
if (amounts[i] == uint(- 1)) {
|
|
178
|
+
assetAmount = Types.AssetAmount(
|
|
179
|
+
true,
|
|
180
|
+
Types.AssetDenomination.Wei,
|
|
181
|
+
Types.AssetReference.Target,
|
|
182
|
+
0
|
|
183
|
+
);
|
|
184
|
+
} else {
|
|
185
|
+
assetAmount = Types.AssetAmount(
|
|
186
|
+
false,
|
|
187
|
+
Types.AssetDenomination.Wei,
|
|
188
|
+
Types.AssetReference.Delta,
|
|
189
|
+
amounts[i]
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
actions[i] = Actions.ActionArgs({
|
|
194
|
+
actionType : Actions.ActionType.Transfer,
|
|
195
|
+
accountId : 0,
|
|
196
|
+
amount : assetAmount,
|
|
197
|
+
primaryMarketId : markets[i],
|
|
198
|
+
secondaryMarketId : uint(- 1),
|
|
199
|
+
otherAddress : address(0),
|
|
200
|
+
otherAccountId : 1,
|
|
201
|
+
data : bytes("")
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
DOLOMITE_MARGIN.operate(accounts, actions);
|
|
206
|
+
}
|
|
207
|
+
}
|