forked from Synthetixio/synthetix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMixinPerpsV2MarketSettings.sol
190 lines (147 loc) · 8.51 KB
/
MixinPerpsV2MarketSettings.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
pragma solidity ^0.5.16;
pragma experimental ABIEncoderV2;
import "./MixinResolver.sol";
// Internal references
import "./interfaces/IFlexibleStorage.sol";
// https://docs.synthetix.io/contracts/source/contracts/MixinPerpsV2MarketSettings
contract MixinPerpsV2MarketSettings is MixinResolver {
/* ========== CONSTANTS ========== */
bytes32 internal constant SETTING_CONTRACT_NAME = "PerpsV2MarketSettings";
/* ---------- Parameter Names ---------- */
// Per-market settings
bytes32 internal constant PARAMETER_TAKER_FEE = "takerFee";
bytes32 internal constant PARAMETER_MAKER_FEE = "makerFee";
bytes32 internal constant PARAMETER_TAKER_FEE_DELAYED_ORDER = "takerFeeDelayedOrder";
bytes32 internal constant PARAMETER_MAKER_FEE_DELAYED_ORDER = "makerFeeDelayedOrder";
bytes32 internal constant PARAMETER_TAKER_FEE_OFFCHAIN_DELAYED_ORDER = "takerFeeOffchainDelayedOrder";
bytes32 internal constant PARAMETER_MAKER_FEE_OFFCHAIN_DELAYED_ORDER = "makerFeeOffchainDelayedOrder";
bytes32 internal constant PARAMETER_NEXT_PRICE_CONFIRM_WINDOW = "nextPriceConfirmWindow";
bytes32 internal constant PARAMETER_DELAYED_ORDER_CONFIRM_WINDOW = "delayedOrderConfirmWindow";
bytes32 internal constant PARAMETER_OFFCHAIN_DELAYED_ORDER_MIN_AGE = "offchainDelayedOrderMinAge";
bytes32 internal constant PARAMETER_OFFCHAIN_DELAYED_ORDER_MAX_AGE = "offchainDelayedOrderMaxAge";
bytes32 internal constant PARAMETER_MAX_LEVERAGE = "maxLeverage";
bytes32 internal constant PARAMETER_MAX_MARKET_VALUE = "maxMarketValue";
bytes32 internal constant PARAMETER_MAX_FUNDING_VELOCITY = "maxFundingVelocity";
bytes32 internal constant PARAMETER_MIN_SKEW_SCALE = "skewScale";
bytes32 internal constant PARAMETER_MIN_DELAY_TIME_DELTA = "minDelayTimeDelta";
bytes32 internal constant PARAMETER_MAX_DELAY_TIME_DELTA = "maxDelayTimeDelta";
bytes32 internal constant PARAMETER_OFFCHAIN_MARKET_KEY = "offchainMarketKey";
bytes32 internal constant PARAMETER_OFFCHAIN_PRICE_DIVERGENCE = "offchainPriceDivergence";
bytes32 internal constant PARAMETER_LIQUIDATION_PREMIUM_MULTIPLIER = "liquidationPremiumMultiplier";
bytes32 internal constant PARAMETER_MAX_LIQUIDAION_DELTA = "maxLiquidationDelta";
bytes32 internal constant PARAMETER_MAX_LIQUIDATION_PD = "maxPD";
// liquidation buffer to prevent negative margin upon liquidation
bytes32 internal constant PARAMETER_LIQUIDATION_BUFFER_RATIO = "liquidationBufferRatio";
// Global settings
// minimum liquidation fee payable to liquidator
bytes32 internal constant SETTING_MIN_KEEPER_FEE = "perpsV2MinKeeperFee";
// maximum liquidation fee payable to liquidator
bytes32 internal constant SETTING_MAX_KEEPER_FEE = "perpsV2MaxKeeperFee";
// liquidation fee basis points payed to liquidator
bytes32 internal constant SETTING_LIQUIDATION_FEE_RATIO = "perpsV2LiquidationFeeRatio";
// minimum initial margin
bytes32 internal constant SETTING_MIN_INITIAL_MARGIN = "perpsV2MinInitialMargin";
// fixed liquidation fee to be paid to liquidator keeper (not flagger)
bytes32 internal constant SETTING_KEEPER_LIQUIRATION_FEE = "keeperLiquidationFee";
/* ---------- Address Resolver Configuration ---------- */
bytes32 internal constant CONTRACT_FLEXIBLESTORAGE = "FlexibleStorage";
/* ========== CONSTRUCTOR ========== */
constructor(address _resolver) internal MixinResolver(_resolver) {}
/* ========== VIEWS ========== */
function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {
addresses = new bytes32[](1);
addresses[0] = CONTRACT_FLEXIBLESTORAGE;
}
function _flexibleStorage() internal view returns (IFlexibleStorage) {
return IFlexibleStorage(requireAndGetAddress(CONTRACT_FLEXIBLESTORAGE));
}
/* ---------- Internals ---------- */
function _parameter(bytes32 _marketKey, bytes32 key) internal view returns (uint value) {
return _flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, keccak256(abi.encodePacked(_marketKey, key)));
}
function _takerFee(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_TAKER_FEE);
}
function _makerFee(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_MAKER_FEE);
}
function _takerFeeDelayedOrder(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_TAKER_FEE_DELAYED_ORDER);
}
function _makerFeeDelayedOrder(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_MAKER_FEE_DELAYED_ORDER);
}
function _takerFeeOffchainDelayedOrder(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_TAKER_FEE_OFFCHAIN_DELAYED_ORDER);
}
function _makerFeeOffchainDelayedOrder(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_MAKER_FEE_OFFCHAIN_DELAYED_ORDER);
}
function _nextPriceConfirmWindow(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_NEXT_PRICE_CONFIRM_WINDOW);
}
function _delayedOrderConfirmWindow(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_DELAYED_ORDER_CONFIRM_WINDOW);
}
function _offchainDelayedOrderMinAge(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_OFFCHAIN_DELAYED_ORDER_MIN_AGE);
}
function _offchainDelayedOrderMaxAge(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_OFFCHAIN_DELAYED_ORDER_MAX_AGE);
}
function _maxLeverage(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_MAX_LEVERAGE);
}
function _maxMarketValue(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_MAX_MARKET_VALUE);
}
function _skewScale(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_MIN_SKEW_SCALE);
}
function _maxFundingVelocity(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_MAX_FUNDING_VELOCITY);
}
function _minDelayTimeDelta(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_MIN_DELAY_TIME_DELTA);
}
function _maxDelayTimeDelta(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_MAX_DELAY_TIME_DELTA);
}
function _offchainMarketKey(bytes32 _marketKey) internal view returns (bytes32) {
return
_flexibleStorage().getBytes32Value(
SETTING_CONTRACT_NAME,
keccak256(abi.encodePacked(_marketKey, PARAMETER_OFFCHAIN_MARKET_KEY))
);
}
function _offchainPriceDivergence(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_OFFCHAIN_PRICE_DIVERGENCE);
}
function _liquidationPremiumMultiplier(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_LIQUIDATION_PREMIUM_MULTIPLIER);
}
function _maxLiquidationDelta(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_MAX_LIQUIDAION_DELTA);
}
function _maxPD(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_MAX_LIQUIDATION_PD);
}
function _liquidationBufferRatio(bytes32 _marketKey) internal view returns (uint) {
return _parameter(_marketKey, PARAMETER_LIQUIDATION_BUFFER_RATIO);
}
function _minKeeperFee() internal view returns (uint) {
return _flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_MIN_KEEPER_FEE);
}
function _maxKeeperFee() internal view returns (uint) {
return _flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_MAX_KEEPER_FEE);
}
function _liquidationFeeRatio() internal view returns (uint) {
return _flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_LIQUIDATION_FEE_RATIO);
}
function _minInitialMargin() internal view returns (uint) {
return _flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_MIN_INITIAL_MARGIN);
}
function _keeperLiquidationFee() internal view returns (uint) {
return _flexibleStorage().getUIntValue(SETTING_CONTRACT_NAME, SETTING_KEEPER_LIQUIRATION_FEE);
}
}