@pendle/core-v2 0.16.4-testnet → 0.16.5-testnet

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.
@@ -155,7 +155,7 @@ contract BulkSeller is IPBulkSeller, Initializable, TokenHelper, ReentrancyGuard
155
155
 
156
156
  // ----------------- BulkSeller management -----------------
157
157
 
158
- function increaseReserve(uint256 netTokenIn, uint256 netSyIn) external onlyMaintainer {
158
+ function increaseReserve(uint256 netTokenIn, uint256 netSyIn) external payable onlyMaintainer {
159
159
  BulkSellerState memory state = readState();
160
160
 
161
161
  state.totalToken += netTokenIn;
@@ -240,11 +240,20 @@ contract BulkSeller is IPBulkSeller, Initializable, TokenHelper, ReentrancyGuard
240
240
 
241
241
  function _depositToken(uint256 netTokenDeposit) internal returns (uint256 netSyFromToken) {
242
242
  _safeApprove(token, SY, netTokenDeposit);
243
- return IStandardizedYield(SY).deposit(address(this), token, netTokenDeposit, 0);
243
+ uint256 nativeToDeposit = token == NATIVE ? netTokenDeposit : 0;
244
+ return
245
+ IStandardizedYield(SY).deposit{ value: nativeToDeposit }(
246
+ address(this),
247
+ token,
248
+ netTokenDeposit,
249
+ 0
250
+ );
244
251
  }
245
252
 
246
253
  function _redeemSy(uint256 netSyRedeem) internal returns (uint256 netTokenFromSy) {
247
254
  _transferOut(SY, SY, netSyRedeem);
248
255
  return IStandardizedYield(SY).redeem(address(this), netSyRedeem, token, 0, true);
249
256
  }
257
+
258
+ receive() external payable {}
250
259
  }
@@ -58,6 +58,8 @@ contract BulkSellerFactory is
58
58
 
59
59
  syToBulkSeller[token][SY] = bulk;
60
60
 
61
+ emit BulkSellerCreated(token, SY, bulk);
62
+
61
63
  return bulk;
62
64
  }
63
65
 
@@ -119,8 +119,8 @@ library BulkSellerMathCore {
119
119
 
120
120
  function setRate(
121
121
  BulkSellerState memory state,
122
- uint256 rateTokenToSy,
123
122
  uint256 rateSyToToken,
123
+ uint256 rateTokenToSy,
124
124
  uint256 maxDiff
125
125
  ) internal pure {
126
126
  if (
@@ -2,6 +2,8 @@
2
2
  pragma solidity 0.8.17;
3
3
 
4
4
  interface IPBulkSellerFactory {
5
+ event BulkSellerCreated(address indexed token, address indexed sy, address indexed bulk);
6
+
5
7
  event UpgradedBeacon(address indexed implementation);
6
8
 
7
9
  function get(address token, address SY) external view returns (address);
@@ -3,6 +3,7 @@ pragma solidity 0.8.17;
3
3
 
4
4
  import "../core/BulkSeller/BulkSellerMathCore.sol";
5
5
  import "../core/BulkSeller/BulkSeller.sol";
6
+ import "hardhat/console.sol";
6
7
 
7
8
  // upgradable bla bla
8
9
  contract BulkSellerOffchain {
@@ -20,17 +21,34 @@ contract BulkSellerOffchain {
20
21
  address token = bulk.token();
21
22
 
22
23
  {
23
- uint256 hypoTotalToken = state.totalToken +
24
- state.calcSwapExactSyForToken(state.totalSy);
24
+ uint256 hypoTotalToken = state.totalToken + state.totalSy.mulDown(state.rateSyToToken);
25
25
  uint256 netSyFromToken = IStandardizedYield(SY).previewDeposit(token, hypoTotalToken);
26
26
 
27
27
  rateTokenToSy = netSyFromToken.divDown(hypoTotalToken);
28
28
  }
29
29
 
30
30
  {
31
- uint256 hypoTotalSy = state.totalSy + state.calcSwapExactTokenForSy(state.totalToken);
31
+ uint256 hypoTotalSy = state.totalSy + state.totalToken.mulDown(state.rateTokenToSy);
32
32
  uint256 netTokenFromSy = IStandardizedYield(SY).previewRedeem(token, hypoTotalSy);
33
+ rateSyToToken = netTokenFromSy.divDown(hypoTotalSy);
34
+ }
35
+ }
33
36
 
37
+ function calcCurrentRatesWithAmount(
38
+ IPBulkSeller bulk,
39
+ uint256 hypoTotalToken,
40
+ uint256 hypoTotalSy
41
+ ) external view returns (uint256 rateTokenToSy, uint256 rateSyToToken) {
42
+ address SY = bulk.SY();
43
+ address token = bulk.token();
44
+
45
+ {
46
+ uint256 netSyFromToken = IStandardizedYield(SY).previewDeposit(token, hypoTotalToken);
47
+ rateTokenToSy = netSyFromToken.divDown(hypoTotalToken);
48
+ }
49
+
50
+ {
51
+ uint256 netTokenFromSy = IStandardizedYield(SY).previewRedeem(token, hypoTotalSy);
34
52
  rateSyToToken = netTokenFromSy.divDown(hypoTotalSy);
35
53
  }
36
54
  }
@@ -575,7 +575,7 @@ library MarketApproxPtOutLib {
575
575
  {
576
576
  uint256 netSyRemaining = a.totalSyIn - netSyIn;
577
577
  uint256 newTotalPt = a.market.totalPt.Uint() - guess;
578
- uint256 netTotalSy = comp.totalAsset.Uint() + netSyIn - netSyFee;
578
+ uint256 netTotalSy = a.market.totalSy.Uint() + netSyIn - netSyFee;
579
579
 
580
580
  // it is desired that
581
581
  // netPtFromSwap / newTotalPt = netSyRemaining / netTotalSy
@@ -4,5 +4,6 @@
4
4
  "expiry": 1669852800,
5
5
  "PT": "0xEAa59b2532D7e49b6f8CAC1b4AdAb6a6F868C7eB",
6
6
  "YT": "0xb899c25fF3c73127F0B96aDAb9997a703C3Fd88D",
7
- "market": "0xA9905Bd9d4813a78c4F9Ed4Ba285b49DE50F7406"
7
+ "market": "0xA9905Bd9d4813a78c4F9Ed4Ba285b49DE50F7406",
8
+ "bulkSeller": "0x6A9908669a0D751EE2d8706155eC7CbB0291f09E"
8
9
  }
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.16.4-testnet",
5
+ "version": "0.16.5-testnet",
6
6
  "homepage": "https://pendle.finance",
7
7
  "keywords": [
8
8
  "pendle",