@pendle/core-v2 0.5.1-beta-5 → 0.6.0
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/contracts/SuperComposableYield/ISuperComposableYield.sol +2 -0
- package/contracts/SuperComposableYield/implementations/RewardManager.sol +35 -20
- package/contracts/SuperComposableYield/implementations/SCYBase.sol +39 -19
- package/contracts/SuperComposableYield/implementations/SCYBaseWithRewards.sol +26 -14
- package/contracts/core/PendleBaseToken.sol +2 -2
- package/contracts/core/PendleMarket.sol +145 -61
- package/contracts/core/PendleMarketFactory.sol +30 -19
- package/contracts/core/{PendleOwnershipToken.sol → PendlePrincipalToken.sol} +14 -2
- package/contracts/core/PendleRouter.sol +23 -9
- package/contracts/core/PendleSCYImpl/AaveV3/PendleAaveV3SCY.sol +21 -20
- package/contracts/core/PendleSCYImpl/PendleBenQiErc20SCY.sol +22 -16
- package/contracts/core/PendleSCYImpl/PendleBtrflySCY.sol +13 -13
- package/contracts/core/PendleSCYImpl/PendleStETHSCY.sol +107 -0
- package/contracts/core/PendleSCYImpl/PendleYearnVaultSCY.sol +14 -15
- package/contracts/core/PendleYieldContractFactory.sol +29 -14
- package/contracts/core/PendleYieldToken.sol +130 -76
- package/contracts/core/RouterStatic.sol +16 -157
- package/contracts/core/actions/ActionCallback.sol +36 -18
- package/contracts/core/actions/ActionCore.sol +41 -88
- package/contracts/core/actions/ActionRedeem.sol +36 -0
- package/contracts/core/actions/ActionYT.sol +41 -59
- package/contracts/core/actions/base/{ActionSCYAndOTBase.sol → ActionSCYAndPTBase.sol} +59 -45
- package/contracts/core/actions/base/{ActionSCYAndYOBase.sol → ActionSCYAndPYBase.sol} +57 -19
- package/contracts/core/actions/base/ActionSCYAndYTBase.sol +31 -21
- package/contracts/interfaces/IPActionCore.sol +21 -28
- package/contracts/interfaces/IPActionRedeem.sol +17 -0
- package/contracts/interfaces/IPActionYT.sol +5 -12
- package/contracts/interfaces/IPAllAction.sol +2 -2
- package/contracts/interfaces/IPMarket.sol +33 -10
- package/contracts/interfaces/IPMarketAddRemoveCallback.sol +2 -2
- package/contracts/interfaces/IPMarketFactory.sol +3 -1
- package/contracts/interfaces/IPMarketSwapCallback.sol +1 -1
- package/contracts/interfaces/{IPOwnershipToken.sol → IPPrincipalToken.sol} +1 -1
- package/contracts/interfaces/IPRouterStatic.sol +7 -82
- package/contracts/interfaces/IPYieldContractFactory.sol +10 -2
- package/contracts/interfaces/IPYieldToken.sol +14 -5
- package/contracts/interfaces/IWstETH.sol +10 -0
- package/contracts/libraries/JoeLibrary.sol +1 -1
- package/contracts/libraries/math/LogExpMath.sol +1 -1
- package/contracts/libraries/math/MarketApproxLib.sol +128 -88
- package/contracts/libraries/math/MarketMathAux.sol +13 -13
- package/contracts/libraries/math/MarketMathCore.sol +62 -93
- package/contracts/libraries/math/Math.sol +14 -2
- package/contracts/periphery/PendleGovernanceManager.sol +5 -3
- package/package.json +3 -2
|
@@ -6,19 +6,19 @@ import "./LogExpMath.sol";
|
|
|
6
6
|
import "../SCYIndex.sol";
|
|
7
7
|
|
|
8
8
|
struct MarketState {
|
|
9
|
-
int256
|
|
9
|
+
int256 totalPt;
|
|
10
10
|
int256 totalScy;
|
|
11
11
|
int256 totalLp;
|
|
12
12
|
uint256 oracleRate;
|
|
13
13
|
address treasury;
|
|
14
14
|
/// immutable variables ///
|
|
15
15
|
int256 scalarRoot;
|
|
16
|
-
uint256
|
|
16
|
+
uint256 lnFeeRateRoot;
|
|
17
17
|
uint256 rateOracleTimeWindow;
|
|
18
18
|
uint256 expiry;
|
|
19
19
|
uint256 reserveFeePercent; // base 100
|
|
20
20
|
/// last trade data ///
|
|
21
|
-
uint256
|
|
21
|
+
uint256 lastLnImpliedRate;
|
|
22
22
|
uint256 lastTradeTime;
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -27,15 +27,7 @@ struct MarketPreCompute {
|
|
|
27
27
|
int256 rateScalar;
|
|
28
28
|
int256 totalAsset;
|
|
29
29
|
int256 rateAnchor;
|
|
30
|
-
int256
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
struct MarketStorage {
|
|
34
|
-
int128 totalOt;
|
|
35
|
-
int128 totalScy;
|
|
36
|
-
uint112 lastImpliedRate;
|
|
37
|
-
uint112 oracleRate;
|
|
38
|
-
uint32 lastTradeTime;
|
|
30
|
+
int256 lnFeeRate;
|
|
39
31
|
}
|
|
40
32
|
|
|
41
33
|
// solhint-disable ordering
|
|
@@ -56,7 +48,7 @@ library MarketMathCore {
|
|
|
56
48
|
MarketState memory market,
|
|
57
49
|
SCYIndex index,
|
|
58
50
|
int256 scyDesired,
|
|
59
|
-
int256
|
|
51
|
+
int256 ptDesired,
|
|
60
52
|
bool updateState
|
|
61
53
|
)
|
|
62
54
|
internal
|
|
@@ -65,13 +57,13 @@ library MarketMathCore {
|
|
|
65
57
|
int256 lpToReserve,
|
|
66
58
|
int256 lpToAccount,
|
|
67
59
|
int256 scyUsed,
|
|
68
|
-
int256
|
|
60
|
+
int256 ptUsed
|
|
69
61
|
)
|
|
70
62
|
{
|
|
71
63
|
/// ------------------------------------------------------------
|
|
72
64
|
/// CHECKS
|
|
73
65
|
/// ------------------------------------------------------------
|
|
74
|
-
require(scyDesired > 0 &&
|
|
66
|
+
require(scyDesired > 0 && ptDesired > 0, "ZERO_AMOUNTS");
|
|
75
67
|
|
|
76
68
|
/// ------------------------------------------------------------
|
|
77
69
|
/// MATH
|
|
@@ -80,18 +72,18 @@ library MarketMathCore {
|
|
|
80
72
|
lpToAccount = index.scyToAsset(scyDesired).subNoNeg(MINIMUM_LIQUIDITY);
|
|
81
73
|
lpToReserve = MINIMUM_LIQUIDITY;
|
|
82
74
|
scyUsed = scyDesired;
|
|
83
|
-
|
|
75
|
+
ptUsed = ptDesired;
|
|
84
76
|
} else {
|
|
85
|
-
int256
|
|
77
|
+
int256 netLpByPt = (ptDesired * market.totalLp) / market.totalPt;
|
|
86
78
|
int256 netLpByScy = (scyDesired * market.totalLp) / market.totalScy;
|
|
87
|
-
if (
|
|
88
|
-
lpToAccount =
|
|
89
|
-
|
|
79
|
+
if (netLpByPt < netLpByScy) {
|
|
80
|
+
lpToAccount = netLpByPt;
|
|
81
|
+
ptUsed = ptDesired;
|
|
90
82
|
scyUsed = (market.totalScy * lpToAccount) / market.totalLp;
|
|
91
83
|
} else {
|
|
92
84
|
lpToAccount = netLpByScy;
|
|
93
85
|
scyUsed = scyDesired;
|
|
94
|
-
|
|
86
|
+
ptUsed = (market.totalPt * lpToAccount) / market.totalLp;
|
|
95
87
|
}
|
|
96
88
|
}
|
|
97
89
|
|
|
@@ -102,7 +94,7 @@ library MarketMathCore {
|
|
|
102
94
|
/// ------------------------------------------------------------
|
|
103
95
|
if (updateState) {
|
|
104
96
|
market.totalScy += scyUsed;
|
|
105
|
-
market.
|
|
97
|
+
market.totalPt += ptUsed;
|
|
106
98
|
market.totalLp += lpToAccount + lpToReserve;
|
|
107
99
|
}
|
|
108
100
|
}
|
|
@@ -111,7 +103,7 @@ library MarketMathCore {
|
|
|
111
103
|
MarketState memory market,
|
|
112
104
|
int256 lpToRemove,
|
|
113
105
|
bool updateState
|
|
114
|
-
) internal pure returns (int256 scyToAccount, int256
|
|
106
|
+
) internal pure returns (int256 scyToAccount, int256 netPtToAccount) {
|
|
115
107
|
/// ------------------------------------------------------------
|
|
116
108
|
/// CHECKS
|
|
117
109
|
/// ------------------------------------------------------------
|
|
@@ -121,14 +113,14 @@ library MarketMathCore {
|
|
|
121
113
|
/// MATH
|
|
122
114
|
/// ------------------------------------------------------------
|
|
123
115
|
scyToAccount = (lpToRemove * market.totalScy) / market.totalLp;
|
|
124
|
-
|
|
116
|
+
netPtToAccount = (lpToRemove * market.totalPt) / market.totalLp;
|
|
125
117
|
|
|
126
118
|
/// ------------------------------------------------------------
|
|
127
119
|
/// WRITE
|
|
128
120
|
/// ------------------------------------------------------------
|
|
129
121
|
if (updateState) {
|
|
130
122
|
market.totalLp = market.totalLp.subNoNeg(lpToRemove);
|
|
131
|
-
market.
|
|
123
|
+
market.totalPt = market.totalPt.subNoNeg(netPtToAccount);
|
|
132
124
|
market.totalScy = market.totalScy.subNoNeg(scyToAccount);
|
|
133
125
|
}
|
|
134
126
|
}
|
|
@@ -136,7 +128,7 @@ library MarketMathCore {
|
|
|
136
128
|
function executeTradeCore(
|
|
137
129
|
MarketState memory market,
|
|
138
130
|
SCYIndex index,
|
|
139
|
-
int256
|
|
131
|
+
int256 netPtToAccount,
|
|
140
132
|
uint256 blockTime,
|
|
141
133
|
bool updateState
|
|
142
134
|
) internal pure returns (int256 netScyToAccount, int256 netScyToReserve) {
|
|
@@ -144,7 +136,7 @@ library MarketMathCore {
|
|
|
144
136
|
/// CHECKS
|
|
145
137
|
/// ------------------------------------------------------------
|
|
146
138
|
require(blockTime < market.expiry, "market expired");
|
|
147
|
-
require(market.
|
|
139
|
+
require(market.totalPt > netPtToAccount, "insufficient liquidity");
|
|
148
140
|
|
|
149
141
|
/// ------------------------------------------------------------
|
|
150
142
|
/// MATH
|
|
@@ -154,7 +146,7 @@ library MarketMathCore {
|
|
|
154
146
|
(int256 netAssetToAccount, int256 netAssetToReserve) = calcTrade(
|
|
155
147
|
market,
|
|
156
148
|
comp,
|
|
157
|
-
|
|
149
|
+
netPtToAccount
|
|
158
150
|
);
|
|
159
151
|
|
|
160
152
|
netScyToAccount = index.assetToScy(netAssetToAccount);
|
|
@@ -168,7 +160,7 @@ library MarketMathCore {
|
|
|
168
160
|
market,
|
|
169
161
|
comp,
|
|
170
162
|
index,
|
|
171
|
-
|
|
163
|
+
netPtToAccount,
|
|
172
164
|
netScyToAccount,
|
|
173
165
|
blockTime
|
|
174
166
|
);
|
|
@@ -187,35 +179,35 @@ library MarketMathCore {
|
|
|
187
179
|
res.rateScalar = _getRateScalar(market, timeToExpiry);
|
|
188
180
|
res.totalAsset = index.scyToAsset(market.totalScy);
|
|
189
181
|
|
|
190
|
-
require(market.
|
|
182
|
+
require(market.totalPt != 0 && res.totalAsset != 0, "invalid market state");
|
|
191
183
|
|
|
192
184
|
res.rateAnchor = _getRateAnchor(
|
|
193
|
-
market.
|
|
194
|
-
market.
|
|
185
|
+
market.totalPt,
|
|
186
|
+
market.lastLnImpliedRate,
|
|
195
187
|
res.totalAsset,
|
|
196
188
|
res.rateScalar,
|
|
197
189
|
timeToExpiry
|
|
198
190
|
);
|
|
199
|
-
res.
|
|
191
|
+
res.lnFeeRate = _getExchangeRateFromImpliedRate(market.lnFeeRateRoot, timeToExpiry);
|
|
200
192
|
}
|
|
201
193
|
|
|
202
194
|
function calcTrade(
|
|
203
195
|
MarketState memory market,
|
|
204
196
|
MarketPreCompute memory comp,
|
|
205
|
-
int256
|
|
197
|
+
int256 netPtToAccount
|
|
206
198
|
) internal pure returns (int256 netAssetToAccount, int256 netAssetToReserve) {
|
|
207
199
|
int256 preFeeExchangeRate = _getExchangeRate(
|
|
208
|
-
market.
|
|
200
|
+
market.totalPt,
|
|
209
201
|
comp.totalAsset,
|
|
210
202
|
comp.rateScalar,
|
|
211
203
|
comp.rateAnchor,
|
|
212
|
-
|
|
204
|
+
netPtToAccount
|
|
213
205
|
);
|
|
214
206
|
|
|
215
|
-
int256 preFeeAssetToAccount =
|
|
216
|
-
int256 fee = comp.
|
|
207
|
+
int256 preFeeAssetToAccount = netPtToAccount.divDown(preFeeExchangeRate).neg();
|
|
208
|
+
int256 fee = comp.lnFeeRate;
|
|
217
209
|
|
|
218
|
-
if (
|
|
210
|
+
if (netPtToAccount > 0) {
|
|
219
211
|
int256 postFeeExchangeRate = preFeeExchangeRate.divDown(fee);
|
|
220
212
|
require(postFeeExchangeRate >= Math.IONE, "exchange rate below 1");
|
|
221
213
|
fee = preFeeAssetToAccount.mulDown(Math.IONE - fee);
|
|
@@ -233,7 +225,7 @@ library MarketMathCore {
|
|
|
233
225
|
MarketState memory market,
|
|
234
226
|
MarketPreCompute memory comp,
|
|
235
227
|
SCYIndex index,
|
|
236
|
-
int256
|
|
228
|
+
int256 netPtToAccount,
|
|
237
229
|
int256 netScyToAccount,
|
|
238
230
|
uint256 blockTime
|
|
239
231
|
) internal pure {
|
|
@@ -241,112 +233,92 @@ library MarketMathCore {
|
|
|
241
233
|
|
|
242
234
|
market.lastTradeTime = blockTime;
|
|
243
235
|
|
|
244
|
-
market.
|
|
236
|
+
market.totalPt = market.totalPt.subNoNeg(netPtToAccount);
|
|
245
237
|
market.totalScy = market.totalScy.subNoNeg(netScyToAccount);
|
|
246
238
|
|
|
247
|
-
market.
|
|
248
|
-
market.
|
|
239
|
+
market.lastLnImpliedRate = _getLnImpliedRate(
|
|
240
|
+
market.totalPt,
|
|
249
241
|
index.scyToAsset(market.totalScy),
|
|
250
242
|
comp.rateScalar,
|
|
251
243
|
comp.rateAnchor,
|
|
252
244
|
timeToExpiry
|
|
253
245
|
);
|
|
254
|
-
require(market.
|
|
246
|
+
require(market.lastLnImpliedRate != 0, "zero lnImpliedRate");
|
|
255
247
|
}
|
|
256
248
|
|
|
257
249
|
function _getRateAnchor(
|
|
258
|
-
int256
|
|
259
|
-
uint256
|
|
250
|
+
int256 totalPt,
|
|
251
|
+
uint256 lastLnImpliedRate,
|
|
260
252
|
int256 totalAsset,
|
|
261
253
|
int256 rateScalar,
|
|
262
254
|
uint256 timeToExpiry
|
|
263
255
|
) internal pure returns (int256 rateAnchor) {
|
|
264
|
-
|
|
265
|
-
int256 newExchangeRate = _getExchangeRateFromImpliedRate(lastImpliedRate, timeToExpiry);
|
|
256
|
+
int256 newExchangeRate = _getExchangeRateFromImpliedRate(lastLnImpliedRate, timeToExpiry);
|
|
266
257
|
|
|
267
258
|
require(newExchangeRate >= Math.IONE, "exchange rate below 1");
|
|
268
259
|
|
|
269
260
|
{
|
|
270
|
-
|
|
271
|
-
int256 proportion = totalOt.divDown(totalOt + totalAsset);
|
|
261
|
+
int256 proportion = totalPt.divDown(totalPt + totalAsset);
|
|
272
262
|
|
|
273
263
|
int256 lnProportion = _logProportion(proportion);
|
|
274
264
|
|
|
275
|
-
// newExchangeRate - ln(proportion / (1 - proportion)) / rateScalar
|
|
276
265
|
rateAnchor = newExchangeRate - lnProportion.divDown(rateScalar);
|
|
277
266
|
}
|
|
278
267
|
}
|
|
279
268
|
|
|
280
269
|
/// @notice Calculates the current market implied rate.
|
|
281
|
-
/// @return
|
|
282
|
-
function
|
|
283
|
-
int256
|
|
270
|
+
/// @return lnImpliedRate the implied rate
|
|
271
|
+
function _getLnImpliedRate(
|
|
272
|
+
int256 totalPt,
|
|
284
273
|
int256 totalAsset,
|
|
285
274
|
int256 rateScalar,
|
|
286
275
|
int256 rateAnchor,
|
|
287
276
|
uint256 timeToExpiry
|
|
288
|
-
) internal pure returns (uint256
|
|
277
|
+
) internal pure returns (uint256 lnImpliedRate) {
|
|
289
278
|
// This will check for exchange rates < Math.IONE
|
|
290
|
-
int256 exchangeRate = _getExchangeRate(
|
|
279
|
+
int256 exchangeRate = _getExchangeRate(totalPt, totalAsset, rateScalar, rateAnchor, 0);
|
|
291
280
|
|
|
292
281
|
// exchangeRate >= 1 so its ln >= 0
|
|
293
282
|
uint256 lnRate = exchangeRate.ln().Uint();
|
|
294
283
|
|
|
295
|
-
|
|
284
|
+
lnImpliedRate = (lnRate * IMPLIED_RATE_TIME) / timeToExpiry;
|
|
296
285
|
}
|
|
297
286
|
|
|
298
287
|
/// @notice Converts an implied rate to an exchange rate given a time to expiry. The
|
|
299
288
|
/// formula is E = e^rt
|
|
300
|
-
function _getExchangeRateFromImpliedRate(uint256
|
|
289
|
+
function _getExchangeRateFromImpliedRate(uint256 lnImpliedRate, uint256 timeToExpiry)
|
|
301
290
|
internal
|
|
302
291
|
pure
|
|
303
292
|
returns (int256 exchangeRate)
|
|
304
293
|
{
|
|
305
|
-
uint256 rt = (
|
|
294
|
+
uint256 rt = (lnImpliedRate * timeToExpiry) / IMPLIED_RATE_TIME;
|
|
306
295
|
|
|
307
296
|
exchangeRate = LogExpMath.exp(rt.Int());
|
|
308
297
|
}
|
|
309
298
|
|
|
310
|
-
/// @notice Returns the exchange rate between OT and Asset for the given market
|
|
311
|
-
/// Calculates the following exchange rate:
|
|
312
|
-
/// (1 / rateScalar) * ln(proportion / (1 - proportion)) + rateAnchor
|
|
313
|
-
/// where:
|
|
314
|
-
/// proportion = totalOt / (totalOt + totalUnderlyingAsset)
|
|
315
299
|
function _getExchangeRate(
|
|
316
|
-
int256
|
|
300
|
+
int256 totalPt,
|
|
317
301
|
int256 totalAsset,
|
|
318
302
|
int256 rateScalar,
|
|
319
303
|
int256 rateAnchor,
|
|
320
|
-
int256
|
|
304
|
+
int256 netPtToAccount
|
|
321
305
|
) internal pure returns (int256 exchangeRate) {
|
|
322
|
-
int256 numerator =
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
int256 proportion = (numerator.divDown(totalOt + totalAsset));
|
|
327
|
-
|
|
328
|
-
// This limit is here to prevent the market from reaching extremely high interest rates via an
|
|
329
|
-
// excessively large proportion (high amounts of OT relative to Asset).
|
|
330
|
-
// Market proportion can only increase via swapping OT to SCY (OT is added to the market and SCY is
|
|
331
|
-
// removed). Over time, the yield from SCY will slightly decrease the proportion (the
|
|
332
|
-
// amount of Asset in the market must be monotonically increasing). Therefore it is not
|
|
333
|
-
// possible for the proportion to go over max market proportion unless borrowing occurs.
|
|
306
|
+
int256 numerator = totalPt.subNoNeg(netPtToAccount);
|
|
307
|
+
|
|
308
|
+
int256 proportion = (numerator.divDown(totalPt + totalAsset));
|
|
309
|
+
|
|
334
310
|
require(proportion <= MAX_MARKET_PROPORTION, "max proportion exceeded");
|
|
335
311
|
|
|
336
312
|
int256 lnProportion = _logProportion(proportion);
|
|
337
313
|
|
|
338
|
-
// lnProportion / rateScalar + rateAnchor
|
|
339
314
|
exchangeRate = lnProportion.divDown(rateScalar) + rateAnchor;
|
|
340
315
|
|
|
341
|
-
// Do not succeed if interest rates fall below 1
|
|
342
316
|
require(exchangeRate >= Math.IONE, "exchange rate below 1");
|
|
343
317
|
}
|
|
344
318
|
|
|
345
319
|
function _logProportion(int256 proportion) internal pure returns (int256 res) {
|
|
346
|
-
// This will result in divide by zero, short circuit
|
|
347
320
|
require(proportion != Math.IONE, "proportion must not be one");
|
|
348
321
|
|
|
349
|
-
// Convert proportion to what is used inside the logit function (p / (1-p))
|
|
350
322
|
int256 logitP = proportion.divDown(Math.IONE - proportion);
|
|
351
323
|
|
|
352
324
|
res = logitP.ln();
|
|
@@ -361,7 +333,7 @@ library MarketMathCore {
|
|
|
361
333
|
require(rateScalar > 0, "rateScalar underflow");
|
|
362
334
|
}
|
|
363
335
|
|
|
364
|
-
function
|
|
336
|
+
function setInitialLnImpliedRate(
|
|
365
337
|
MarketState memory market,
|
|
366
338
|
SCYIndex index,
|
|
367
339
|
int256 initialAnchor,
|
|
@@ -382,8 +354,8 @@ library MarketMathCore {
|
|
|
382
354
|
/// ------------------------------------------------------------
|
|
383
355
|
/// WRITE
|
|
384
356
|
/// ------------------------------------------------------------
|
|
385
|
-
market.
|
|
386
|
-
market.
|
|
357
|
+
market.lastLnImpliedRate = _getLnImpliedRate(
|
|
358
|
+
market.totalPt,
|
|
387
359
|
totalAsset,
|
|
388
360
|
rateScalar,
|
|
389
361
|
initialAnchor,
|
|
@@ -391,22 +363,20 @@ library MarketMathCore {
|
|
|
391
363
|
);
|
|
392
364
|
}
|
|
393
365
|
|
|
394
|
-
function
|
|
366
|
+
function getNewRateOracle(MarketState memory market, uint256 blockTime)
|
|
395
367
|
internal
|
|
396
368
|
pure
|
|
397
369
|
returns (uint256)
|
|
398
370
|
{
|
|
399
371
|
// This can occur when using a view function get to a market state in the past
|
|
400
372
|
if (market.lastTradeTime > blockTime) {
|
|
401
|
-
|
|
402
|
-
return market.oracleRate;
|
|
373
|
+
return market.lastLnImpliedRate;
|
|
403
374
|
}
|
|
404
375
|
|
|
405
376
|
uint256 timeDiff = blockTime - market.lastTradeTime;
|
|
406
377
|
if (timeDiff > market.rateOracleTimeWindow) {
|
|
407
|
-
// If past the time window just return the market.
|
|
408
|
-
|
|
409
|
-
return market.oracleRate;
|
|
378
|
+
// If past the time window just return the market.lastLnImpliedRate
|
|
379
|
+
return market.lastLnImpliedRate;
|
|
410
380
|
}
|
|
411
381
|
|
|
412
382
|
// (currentTs - previousTs) / timeWindow
|
|
@@ -418,7 +388,6 @@ library MarketMathCore {
|
|
|
418
388
|
uint256 newOracleRate = market.lastTradeTime.mulDown(lastTradeWeight) +
|
|
419
389
|
market.oracleRate.mulDown(oracleWeight);
|
|
420
390
|
|
|
421
|
-
|
|
422
|
-
return market.oracleRate;
|
|
391
|
+
return newOracleRate;
|
|
423
392
|
}
|
|
424
393
|
}
|
|
@@ -22,8 +22,6 @@ library Math {
|
|
|
22
22
|
uint256 internal constant ONE = 1e18; // 18 decimal places
|
|
23
23
|
int256 internal constant IONE = 1e18; // 18 decimal places
|
|
24
24
|
|
|
25
|
-
uint256 internal constant MAX_POW_RELATIVE_ERROR = 10000; // 10^(-14)
|
|
26
|
-
|
|
27
25
|
function subMax0(uint256 a, uint256 b) internal pure returns (uint256) {
|
|
28
26
|
unchecked {
|
|
29
27
|
return (a >= b ? a - b : 0);
|
|
@@ -65,6 +63,15 @@ library Math {
|
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
65
|
|
|
66
|
+
function rawDivUp(uint256 a, uint256 b) internal pure returns (uint256) {
|
|
67
|
+
if (a == 0) return 0;
|
|
68
|
+
else {
|
|
69
|
+
unchecked {
|
|
70
|
+
return (a + b - 1) / b;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
68
75
|
function abs(int256 x) internal pure returns (uint256) {
|
|
69
76
|
return uint256(x > 0 ? x : -x);
|
|
70
77
|
}
|
|
@@ -118,6 +125,11 @@ library Math {
|
|
|
118
125
|
return uint112(x);
|
|
119
126
|
}
|
|
120
127
|
|
|
128
|
+
function Uint96(uint256 x) internal pure returns (uint96) {
|
|
129
|
+
require(x < (1 << 96)); // unsigned, lim = bit
|
|
130
|
+
return uint96(x);
|
|
131
|
+
}
|
|
132
|
+
|
|
121
133
|
function isAApproxB(
|
|
122
134
|
uint256 a,
|
|
123
135
|
uint256 b,
|
|
@@ -13,6 +13,7 @@ contract PendleGovernanceManager {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
constructor(address _governance) {
|
|
16
|
+
require(_governance != address(0), "zero address");
|
|
16
17
|
governance = _governance;
|
|
17
18
|
}
|
|
18
19
|
|
|
@@ -28,9 +29,10 @@ contract PendleGovernanceManager {
|
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* @dev Allows the current governance to set the pendingGovernance address.
|
|
31
|
-
* @param
|
|
32
|
+
* @param newGovernance The address to transfer ownership to.
|
|
32
33
|
*/
|
|
33
|
-
function transferGovernance(address
|
|
34
|
-
|
|
34
|
+
function transferGovernance(address newGovernance) external onlyGovernance {
|
|
35
|
+
require(newGovernance != address(0), "zero address");
|
|
36
|
+
pendingGovernance = newGovernance;
|
|
35
37
|
}
|
|
36
38
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@pendle/core-v2",
|
|
3
3
|
"description": "Core smart contracts of Pendle Protocol.",
|
|
4
4
|
"license": "BUSL-1.1",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.6.0",
|
|
6
6
|
"homepage": "https://pendle.finance",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"pendle",
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"scripts": {
|
|
37
37
|
"compile": "yarn hardhat compile",
|
|
38
38
|
"size": "yarn hardhat size-contracts",
|
|
39
|
-
"clean": "yarn hardhat clean"
|
|
39
|
+
"clean": "yarn hardhat clean",
|
|
40
|
+
"fcompile": "yarn clean && yarn compile"
|
|
40
41
|
},
|
|
41
42
|
"packageManager": "yarn@3.1.1",
|
|
42
43
|
"dependencies": {
|