@pendle/core-v2 0.5.1-beta-4 → 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.
Files changed (126) hide show
  1. package/contracts/SuperComposableYield/ISuperComposableYield.sol +2 -0
  2. package/contracts/SuperComposableYield/implementations/RewardManager.sol +35 -20
  3. package/contracts/SuperComposableYield/implementations/SCYBase.sol +39 -19
  4. package/contracts/SuperComposableYield/implementations/SCYBaseWithRewards.sol +26 -14
  5. package/contracts/core/PendleBaseToken.sol +2 -2
  6. package/contracts/core/PendleMarket.sol +145 -61
  7. package/contracts/core/PendleMarketFactory.sol +30 -19
  8. package/contracts/core/{PendleOwnershipToken.sol → PendlePrincipalToken.sol} +14 -2
  9. package/contracts/core/PendleRouter.sol +23 -9
  10. package/contracts/core/PendleSCYImpl/AaveV3/PendleAaveV3SCY.sol +21 -20
  11. package/contracts/core/PendleSCYImpl/PendleBenQiErc20SCY.sol +22 -16
  12. package/contracts/core/PendleSCYImpl/PendleBtrflySCY.sol +13 -13
  13. package/contracts/core/PendleSCYImpl/PendleStETHSCY.sol +107 -0
  14. package/contracts/core/PendleSCYImpl/PendleYearnVaultSCY.sol +14 -15
  15. package/contracts/core/PendleYieldContractFactory.sol +29 -14
  16. package/contracts/core/PendleYieldToken.sol +130 -76
  17. package/contracts/core/RouterStatic.sol +16 -157
  18. package/contracts/core/actions/ActionCallback.sol +36 -18
  19. package/contracts/core/actions/ActionCore.sol +41 -88
  20. package/contracts/core/actions/ActionRedeem.sol +36 -0
  21. package/contracts/core/actions/ActionYT.sol +41 -59
  22. package/contracts/core/actions/base/{ActionSCYAndOTBase.sol → ActionSCYAndPTBase.sol} +59 -45
  23. package/contracts/core/actions/base/{ActionSCYAndYOBase.sol → ActionSCYAndPYBase.sol} +57 -19
  24. package/contracts/core/actions/base/ActionSCYAndYTBase.sol +31 -21
  25. package/contracts/interfaces/IPActionCore.sol +21 -28
  26. package/contracts/interfaces/IPActionRedeem.sol +17 -0
  27. package/contracts/interfaces/IPActionYT.sol +5 -12
  28. package/contracts/interfaces/IPAllAction.sol +2 -2
  29. package/contracts/interfaces/IPMarket.sol +33 -10
  30. package/contracts/interfaces/IPMarketAddRemoveCallback.sol +2 -2
  31. package/contracts/interfaces/IPMarketFactory.sol +3 -1
  32. package/contracts/interfaces/IPMarketSwapCallback.sol +1 -1
  33. package/contracts/interfaces/{IPOwnershipToken.sol → IPPrincipalToken.sol} +1 -1
  34. package/contracts/interfaces/IPRouterStatic.sol +7 -82
  35. package/contracts/interfaces/IPYieldContractFactory.sol +10 -2
  36. package/contracts/interfaces/IPYieldToken.sol +14 -5
  37. package/contracts/interfaces/IWstETH.sol +10 -0
  38. package/contracts/libraries/JoeLibrary.sol +1 -1
  39. package/contracts/libraries/math/LogExpMath.sol +1 -1
  40. package/contracts/libraries/math/MarketApproxLib.sol +128 -88
  41. package/contracts/libraries/math/MarketMathAux.sol +13 -13
  42. package/contracts/libraries/math/MarketMathCore.sol +62 -93
  43. package/contracts/libraries/math/Math.sol +14 -2
  44. package/contracts/periphery/PendleGovernanceManager.sol +5 -3
  45. package/package.json +3 -2
  46. package/typechain-types/ActionCallback.ts +5 -5
  47. package/typechain-types/ActionCore.ts +312 -234
  48. package/typechain-types/ActionRedeem.ts +125 -0
  49. package/typechain-types/ActionSCYAndPYBase.ts +223 -0
  50. package/typechain-types/ActionSCYAndYOBase.ts +129 -3
  51. package/typechain-types/ActionSCYAndYTBase.ts +149 -3
  52. package/typechain-types/ActionYT.ts +192 -94
  53. package/typechain-types/IPActionCore.ts +183 -231
  54. package/typechain-types/IPActionRedeem.ts +125 -0
  55. package/typechain-types/IPActionYT.ts +43 -91
  56. package/typechain-types/IPAllAction.ts +258 -321
  57. package/typechain-types/IPMarket.ts +150 -50
  58. package/typechain-types/IPMarketAddRemoveCallback.ts +10 -10
  59. package/typechain-types/IPMarketFactory.ts +28 -6
  60. package/typechain-types/IPMarketSwapCallback.ts +5 -5
  61. package/typechain-types/{IPOwnershipToken.ts → IPPrincipalToken.ts} +5 -5
  62. package/typechain-types/IPRouterStatic.ts +50 -530
  63. package/typechain-types/IPYieldContractFactory.ts +85 -19
  64. package/typechain-types/IPYieldToken.ts +138 -37
  65. package/typechain-types/ISuperComposableYield.ts +13 -0
  66. package/typechain-types/IWstETH.ts +149 -0
  67. package/typechain-types/PendleAaveV3SCY.ts +110 -0
  68. package/typechain-types/PendleBaseToken.ts +1 -1
  69. package/typechain-types/PendleBenQiErc20SCY.ts +55 -12
  70. package/typechain-types/PendleBtrflyScy.ts +27 -23
  71. package/typechain-types/PendleGovernanceManager.ts +5 -5
  72. package/typechain-types/PendleMarket.ts +197 -100
  73. package/typechain-types/PendleMarketFactory.ts +96 -34
  74. package/typechain-types/{PendleOwnershipToken.ts → PendlePrincipalToken.ts} +15 -6
  75. package/typechain-types/PendleRouter.ts +19 -0
  76. package/typechain-types/PendleRouterRedeemUpg.ts +125 -0
  77. package/typechain-types/PendleStEthSCY.ts +872 -0
  78. package/typechain-types/PendleYearnVaultScy.ts +27 -23
  79. package/typechain-types/PendleYieldContractFactory.ts +94 -28
  80. package/typechain-types/PendleYieldToken.ts +142 -57
  81. package/typechain-types/RewardManager.ts +21 -0
  82. package/typechain-types/RouterStatic.ts +50 -530
  83. package/typechain-types/SCYBase.ts +25 -0
  84. package/typechain-types/SCYBaseWithRewards.ts +64 -0
  85. package/typechain-types/factories/ActionCallback__factory.ts +2 -2
  86. package/typechain-types/factories/ActionCore__factory.ts +263 -79
  87. package/typechain-types/factories/ActionRedeem__factory.ts +105 -0
  88. package/typechain-types/factories/ActionSCYAndPYBase__factory.ts +200 -0
  89. package/typechain-types/factories/ActionSCYAndYOBase__factory.ts +148 -0
  90. package/typechain-types/factories/ActionSCYAndYTBase__factory.ts +173 -0
  91. package/typechain-types/factories/ActionYT__factory.ts +265 -56
  92. package/typechain-types/factories/IPActionCore__factory.ts +114 -78
  93. package/typechain-types/factories/IPActionRedeem__factory.ts +70 -0
  94. package/typechain-types/factories/IPActionYT__factory.ts +90 -54
  95. package/typechain-types/factories/IPAllAction__factory.ts +254 -138
  96. package/typechain-types/factories/IPMarketAddRemoveCallback__factory.ts +2 -2
  97. package/typechain-types/factories/IPMarketFactory__factory.ts +26 -1
  98. package/typechain-types/factories/IPMarketSwapCallback__factory.ts +1 -1
  99. package/typechain-types/factories/IPMarket__factory.ts +125 -13
  100. package/typechain-types/factories/{IPOwnershipToken__factory.ts → IPPrincipalToken__factory.ts} +8 -8
  101. package/typechain-types/factories/IPRouterStatic__factory.ts +12 -628
  102. package/typechain-types/factories/IPYieldContractFactory__factory.ts +72 -2
  103. package/typechain-types/factories/IPYieldToken__factory.ts +93 -7
  104. package/typechain-types/factories/ISuperComposableYield__factory.ts +13 -0
  105. package/typechain-types/factories/IWstETH__factory.ts +74 -0
  106. package/typechain-types/factories/PendleAaveV3SCY__factory.ts +97 -3
  107. package/typechain-types/factories/PendleBaseToken__factory.ts +1 -1
  108. package/typechain-types/factories/PendleBenQiErc20SCY__factory.ts +62 -7
  109. package/typechain-types/factories/PendleBtrflyScy__factory.ts +42 -19
  110. package/typechain-types/factories/PendleGovernanceManager__factory.ts +2 -2
  111. package/typechain-types/factories/PendleMarketFactory__factory.ts +66 -15
  112. package/typechain-types/factories/PendleMarket__factory.ts +170 -53
  113. package/typechain-types/factories/PendlePrincipalToken__factory.ts +540 -0
  114. package/typechain-types/factories/PendleRouterRedeemUpg__factory.ts +112 -0
  115. package/typechain-types/factories/PendleRouter__factory.ts +23 -1
  116. package/typechain-types/factories/PendleStEthSCY__factory.ts +716 -0
  117. package/typechain-types/factories/PendleYearnVaultScy__factory.ts +41 -18
  118. package/typechain-types/factories/PendleYieldContractFactory__factory.ts +75 -5
  119. package/typechain-types/factories/PendleYieldToken__factory.ts +102 -33
  120. package/typechain-types/factories/RewardManager__factory.ts +13 -0
  121. package/typechain-types/factories/RouterStatic__factory.ts +13 -629
  122. package/typechain-types/factories/SCYBaseWithRewards__factory.ts +60 -2
  123. package/typechain-types/factories/SCYBase__factory.ts +28 -2
  124. package/typechain-types/hardhat.d.ts +52 -16
  125. package/typechain-types/index.ts +14 -6
  126. package/typechain-types/factories/PendleOwnershipToken__factory.ts +0 -527
@@ -6,19 +6,19 @@ import "./LogExpMath.sol";
6
6
  import "../SCYIndex.sol";
7
7
 
8
8
  struct MarketState {
9
- int256 totalOt;
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 feeRateRoot;
16
+ uint256 lnFeeRateRoot;
17
17
  uint256 rateOracleTimeWindow;
18
18
  uint256 expiry;
19
19
  uint256 reserveFeePercent; // base 100
20
20
  /// last trade data ///
21
- uint256 lastImpliedRate;
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 feeRate;
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 otDesired,
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 otUsed
60
+ int256 ptUsed
69
61
  )
70
62
  {
71
63
  /// ------------------------------------------------------------
72
64
  /// CHECKS
73
65
  /// ------------------------------------------------------------
74
- require(scyDesired > 0 && otDesired > 0, "ZERO_AMOUNTS");
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
- otUsed = otDesired;
75
+ ptUsed = ptDesired;
84
76
  } else {
85
- int256 netLpByOt = (otDesired * market.totalLp) / market.totalOt;
77
+ int256 netLpByPt = (ptDesired * market.totalLp) / market.totalPt;
86
78
  int256 netLpByScy = (scyDesired * market.totalLp) / market.totalScy;
87
- if (netLpByOt < netLpByScy) {
88
- lpToAccount = netLpByOt;
89
- otUsed = otDesired;
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
- otUsed = (market.totalOt * lpToAccount) / market.totalLp;
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.totalOt += otUsed;
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 netOtToAccount) {
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
- netOtToAccount = (lpToRemove * market.totalOt) / market.totalLp;
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.totalOt = market.totalOt.subNoNeg(netOtToAccount);
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 netOtToAccount,
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.totalOt > netOtToAccount, "insufficient liquidity");
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
- netOtToAccount
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
- netOtToAccount,
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.totalOt != 0 && res.totalAsset != 0, "invalid market state");
182
+ require(market.totalPt != 0 && res.totalAsset != 0, "invalid market state");
191
183
 
192
184
  res.rateAnchor = _getRateAnchor(
193
- market.totalOt,
194
- market.lastImpliedRate,
185
+ market.totalPt,
186
+ market.lastLnImpliedRate,
195
187
  res.totalAsset,
196
188
  res.rateScalar,
197
189
  timeToExpiry
198
190
  );
199
- res.feeRate = _getExchangeRateFromImpliedRate(market.feeRateRoot, timeToExpiry);
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 netOtToAccount
197
+ int256 netPtToAccount
206
198
  ) internal pure returns (int256 netAssetToAccount, int256 netAssetToReserve) {
207
199
  int256 preFeeExchangeRate = _getExchangeRate(
208
- market.totalOt,
200
+ market.totalPt,
209
201
  comp.totalAsset,
210
202
  comp.rateScalar,
211
203
  comp.rateAnchor,
212
- netOtToAccount
204
+ netPtToAccount
213
205
  );
214
206
 
215
- int256 preFeeAssetToAccount = netOtToAccount.divDown(preFeeExchangeRate).neg();
216
- int256 fee = comp.feeRate;
207
+ int256 preFeeAssetToAccount = netPtToAccount.divDown(preFeeExchangeRate).neg();
208
+ int256 fee = comp.lnFeeRate;
217
209
 
218
- if (netOtToAccount > 0) {
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 netOtToAccount,
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.totalOt = market.totalOt.subNoNeg(netOtToAccount);
236
+ market.totalPt = market.totalPt.subNoNeg(netPtToAccount);
245
237
  market.totalScy = market.totalScy.subNoNeg(netScyToAccount);
246
238
 
247
- market.lastImpliedRate = _getImpliedRate(
248
- market.totalOt,
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.lastImpliedRate != 0, "zero impliedRate");
246
+ require(market.lastLnImpliedRate != 0, "zero lnImpliedRate");
255
247
  }
256
248
 
257
249
  function _getRateAnchor(
258
- int256 totalOt,
259
- uint256 lastImpliedRate,
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
- // This is the exchange rate at the new time to expiry
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
- // totalOt / (totalOt + totalAsset)
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 impliedRate the implied rate
282
- function _getImpliedRate(
283
- int256 totalOt,
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 impliedRate) {
277
+ ) internal pure returns (uint256 lnImpliedRate) {
289
278
  // This will check for exchange rates < Math.IONE
290
- int256 exchangeRate = _getExchangeRate(totalOt, totalAsset, rateScalar, rateAnchor, 0);
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
- impliedRate = (lnRate * IMPLIED_RATE_TIME) / timeToExpiry;
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 impliedRate, uint256 timeToExpiry)
289
+ function _getExchangeRateFromImpliedRate(uint256 lnImpliedRate, uint256 timeToExpiry)
301
290
  internal
302
291
  pure
303
292
  returns (int256 exchangeRate)
304
293
  {
305
- uint256 rt = (impliedRate * timeToExpiry) / IMPLIED_RATE_TIME;
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 totalOt,
300
+ int256 totalPt,
317
301
  int256 totalAsset,
318
302
  int256 rateScalar,
319
303
  int256 rateAnchor,
320
- int256 netOtToAccount
304
+ int256 netPtToAccount
321
305
  ) internal pure returns (int256 exchangeRate) {
322
- int256 numerator = totalOt.subNoNeg(netOtToAccount);
323
-
324
- // This is the proportion scaled by Math.IONE
325
- // (totalOt - netOtToAccount) / (totalOt + totalAsset)
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 setInitialImpliedRate(
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.lastImpliedRate = _getImpliedRate(
386
- market.totalOt,
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 updateNewRateOracle(MarketState memory market, uint256 blockTime)
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
- market.oracleRate = market.lastImpliedRate;
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.lastImpliedRate
408
- market.oracleRate = market.lastImpliedRate;
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
- market.oracleRate = newOracleRate;
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 _governance The address to transfer ownership to.
32
+ * @param newGovernance The address to transfer ownership to.
32
33
  */
33
- function transferGovernance(address _governance) external onlyGovernance {
34
- pendingGovernance = _governance;
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.1-beta-4",
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": {
@@ -81,7 +81,7 @@ export interface ActionCallback extends BaseContract {
81
81
  marketFactory(overrides?: CallOverrides): Promise<[string]>;
82
82
 
83
83
  swapCallback(
84
- otToAccount: BigNumberish,
84
+ ptToAccount: BigNumberish,
85
85
  scyToAccount: BigNumberish,
86
86
  data: BytesLike,
87
87
  overrides?: Overrides & { from?: string | Promise<string> }
@@ -91,7 +91,7 @@ export interface ActionCallback extends BaseContract {
91
91
  marketFactory(overrides?: CallOverrides): Promise<string>;
92
92
 
93
93
  swapCallback(
94
- otToAccount: BigNumberish,
94
+ ptToAccount: BigNumberish,
95
95
  scyToAccount: BigNumberish,
96
96
  data: BytesLike,
97
97
  overrides?: Overrides & { from?: string | Promise<string> }
@@ -101,7 +101,7 @@ export interface ActionCallback extends BaseContract {
101
101
  marketFactory(overrides?: CallOverrides): Promise<string>;
102
102
 
103
103
  swapCallback(
104
- otToAccount: BigNumberish,
104
+ ptToAccount: BigNumberish,
105
105
  scyToAccount: BigNumberish,
106
106
  data: BytesLike,
107
107
  overrides?: CallOverrides
@@ -114,7 +114,7 @@ export interface ActionCallback extends BaseContract {
114
114
  marketFactory(overrides?: CallOverrides): Promise<BigNumber>;
115
115
 
116
116
  swapCallback(
117
- otToAccount: BigNumberish,
117
+ ptToAccount: BigNumberish,
118
118
  scyToAccount: BigNumberish,
119
119
  data: BytesLike,
120
120
  overrides?: Overrides & { from?: string | Promise<string> }
@@ -125,7 +125,7 @@ export interface ActionCallback extends BaseContract {
125
125
  marketFactory(overrides?: CallOverrides): Promise<PopulatedTransaction>;
126
126
 
127
127
  swapCallback(
128
- otToAccount: BigNumberish,
128
+ ptToAccount: BigNumberish,
129
129
  scyToAccount: BigNumberish,
130
130
  data: BytesLike,
131
131
  overrides?: Overrides & { from?: string | Promise<string> }