@pendle/core-v2 2.5.0-mainnet → 2.6.0-mainnet

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 (75) hide show
  1. package/build/artifacts/contracts/interfaces/IPActionAddRemoveLiq.sol/IPActionAddRemoveLiq.dbg.json +1 -1
  2. package/build/artifacts/contracts/interfaces/IPActionMintRedeem.sol/IPActionMintRedeem.dbg.json +1 -1
  3. package/build/artifacts/contracts/interfaces/IPActionStorageStatic.sol/IPActionStorageStatic.dbg.json +1 -1
  4. package/build/artifacts/contracts/interfaces/IPActionSwapPT.sol/IPActionSwapPT.dbg.json +1 -1
  5. package/build/artifacts/contracts/interfaces/IPActionSwapYT.sol/IPActionSwapYT.dbg.json +1 -1
  6. package/build/artifacts/contracts/interfaces/IPAllAction.sol/IPAllAction.dbg.json +1 -1
  7. package/build/artifacts/contracts/interfaces/IPRouterHelper.sol/IPRouterHelper.dbg.json +4 -0
  8. package/build/artifacts/contracts/interfaces/IPRouterHelper.sol/IPRouterHelper.json +888 -0
  9. package/build/artifacts/contracts/interfaces/IPRouterStatic.sol/IPRouterStatic.dbg.json +1 -1
  10. package/build/artifacts/contracts/offchain-helpers/router-static/PendleRouterStatic.sol/PendleRouterStatic.dbg.json +1 -1
  11. package/build/artifacts/contracts/offchain-helpers/router-static/PendleRouterStatic.sol/PendleRouterStatic.json +2 -2
  12. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionInfoStatic.sol/ActionInfoStatic.dbg.json +1 -1
  13. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionInfoStatic.sol/ActionInfoStatic.json +2 -2
  14. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMarketAuxStatic.sol/ActionMarketAuxStatic.dbg.json +1 -1
  15. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMarketAuxStatic.sol/ActionMarketAuxStatic.json +2 -2
  16. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMarketCoreStatic.sol/ActionMarketCoreStatic.dbg.json +1 -1
  17. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMarketCoreStatic.sol/ActionMarketCoreStatic.json +2 -2
  18. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMintRedeemStatic.sol/ActionMintRedeemStatic.dbg.json +1 -1
  19. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMintRedeemStatic.sol/ActionMintRedeemStatic.json +2 -2
  20. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionStorageStatic.sol/ActionStorageStatic.dbg.json +1 -1
  21. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionStorageStatic.sol/ActionStorageStatic.json +2 -2
  22. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionVePendleStatic.sol/ActionVePendleStatic.dbg.json +1 -1
  23. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionVePendleStatic.sol/ActionVePendleStatic.json +2 -2
  24. package/build/artifacts/contracts/router/ActionAddRemoveLiq.sol/ActionAddRemoveLiq.dbg.json +1 -1
  25. package/build/artifacts/contracts/router/ActionAddRemoveLiq.sol/ActionAddRemoveLiq.json +2 -2
  26. package/build/artifacts/contracts/router/ActionMintRedeem.sol/ActionMintRedeem.dbg.json +1 -1
  27. package/build/artifacts/contracts/router/ActionMintRedeem.sol/ActionMintRedeem.json +2 -2
  28. package/build/artifacts/contracts/router/ActionSwapPT.sol/ActionSwapPT.dbg.json +1 -1
  29. package/build/artifacts/contracts/router/ActionSwapPT.sol/ActionSwapPT.json +2 -2
  30. package/build/artifacts/contracts/router/ActionSwapYT.sol/ActionSwapYT.dbg.json +1 -1
  31. package/build/artifacts/contracts/router/ActionSwapYT.sol/ActionSwapYT.json +2 -2
  32. package/build/artifacts/contracts/router/PendleRouter.sol/PendleRouter.dbg.json +1 -1
  33. package/build/artifacts/contracts/router/PendleRouter.sol/PendleRouter.json +2 -2
  34. package/build/artifacts/contracts/router/PendleRouterHelper.sol/PendleRouterHelper.dbg.json +4 -0
  35. package/build/artifacts/contracts/router/PendleRouterHelper.sol/PendleRouterHelper.json +1032 -0
  36. package/build/artifacts/contracts/router/base/ActionBaseCallback.sol/ActionBaseCallback.dbg.json +1 -1
  37. package/build/artifacts/contracts/router/base/ActionBaseMintRedeem.sol/ActionBaseMintRedeem.dbg.json +1 -1
  38. package/contracts/interfaces/IPRouterHelper.sol +176 -0
  39. package/contracts/router/PendleRouterHelper.sol +359 -0
  40. package/contracts/router/base/ActionBaseMintRedeem.sol +5 -4
  41. package/deployments/1-core.json +1 -1
  42. package/deployments/42161-core.json +1 -1
  43. package/package.json +2 -2
  44. package/typechain-types/AggregatorInterface.ts +233 -0
  45. package/typechain-types/AggregatorV2V3Interface.ts +385 -0
  46. package/typechain-types/AggregatorV3Interface.ts +221 -0
  47. package/typechain-types/IPRouterHelper.ts +84 -12
  48. package/typechain-types/PendlePtAssetOracle.ts +167 -0
  49. package/typechain-types/PendlePtChainlinkOracle.ts +215 -0
  50. package/typechain-types/PendlePtSingleAssetOracle.ts +167 -0
  51. package/typechain-types/PendlePtUSDOracle.ts +215 -0
  52. package/typechain-types/PendleRouterHelper.ts +84 -12
  53. package/typechain-types/factories/ActionAddRemoveLiq__factory.ts +1 -1
  54. package/typechain-types/factories/ActionInfoStatic__factory.ts +1 -1
  55. package/typechain-types/factories/ActionMarketAuxStatic__factory.ts +1 -1
  56. package/typechain-types/factories/ActionMarketCoreStatic__factory.ts +1 -1
  57. package/typechain-types/factories/ActionMintRedeemStatic__factory.ts +1 -1
  58. package/typechain-types/factories/ActionMintRedeem__factory.ts +1 -1
  59. package/typechain-types/factories/ActionStorageStatic__factory.ts +1 -1
  60. package/typechain-types/factories/ActionSwapPT__factory.ts +1 -1
  61. package/typechain-types/factories/ActionSwapYT__factory.ts +1 -1
  62. package/typechain-types/factories/ActionVePendleStatic__factory.ts +1 -1
  63. package/typechain-types/factories/AggregatorInterface__factory.ts +153 -0
  64. package/typechain-types/factories/AggregatorV2V3Interface__factory.ts +268 -0
  65. package/typechain-types/factories/AggregatorV3Interface__factory.ts +141 -0
  66. package/typechain-types/factories/IPRouterHelper__factory.ts +141 -0
  67. package/typechain-types/factories/PendlePtAssetOracle__factory.ts +199 -0
  68. package/typechain-types/factories/PendlePtChainlinkOracle__factory.ts +251 -0
  69. package/typechain-types/factories/PendlePtSingleAssetOracle__factory.ts +203 -0
  70. package/typechain-types/factories/PendlePtUSDOracle__factory.ts +247 -0
  71. package/typechain-types/factories/PendleRouterHelper__factory.ts +142 -1
  72. package/typechain-types/factories/PendleRouterStatic__factory.ts +1 -1
  73. package/typechain-types/factories/PendleRouter__factory.ts +1 -1
  74. package/typechain-types/hardhat.d.ts +45 -27
  75. package/typechain-types/index.ts +10 -6
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../../build-info/6b18eba6d50d13d3fa953207318c13bb.json"
3
+ "buildInfo": "../../../../build-info/ab2554ba7dc9de84a88881282a151fdb.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../../build-info/6b18eba6d50d13d3fa953207318c13bb.json"
3
+ "buildInfo": "../../../../build-info/ab2554ba7dc9de84a88881282a151fdb.json"
4
4
  }
@@ -0,0 +1,176 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ pragma solidity 0.8.17;
3
+
4
+ import "../router/base/MarketApproxLib.sol";
5
+ import "../router/base/ActionBaseMintRedeem.sol";
6
+
7
+ interface IPRouterHelper {
8
+ /**
9
+ * @param output This output struct should be filled the same way as the normal removeLiquiditySingleToken
10
+ operation (This means all BulkSeller, PendleSwap still works the same way). Note that the
11
+ output.tokenOut will also be used as the input token for the addLiquidity
12
+ */
13
+ struct RemoveLiquiditySingleTokenStruct {
14
+ address market;
15
+ uint256 netLpToRemove;
16
+ bool doRedeemRewards;
17
+ TokenOutput output;
18
+ }
19
+
20
+ /**
21
+ * @param guessNetTokenIn the predicted amount of tokenIn that will be used to add liquidity. This
22
+ should be the same amount that was used to generate guessPtReceivedFromSy (if any).
23
+ * @param guessPtReceivedFromSy the same guess struct in the normal addLiquiditySingleToken operation.
24
+ Again, note that this struct, if not empty (i.e. if guessOffchain == 0), should be generated
25
+ using `guessNetTokenIn` amount of tokenIn
26
+ * @dev tokenIn is the output.tokenOut of the removeLiquiditySingleTokenStruct
27
+ */
28
+ struct AddLiquiditySingleTokenStruct {
29
+ address market;
30
+ uint256 minLpOut;
31
+ uint256 guessNetTokenIn;
32
+ ApproxParams guessPtReceivedFromSy;
33
+ address bulk;
34
+ }
35
+
36
+ /**
37
+ * @dev tokenIn is the output.tokenOut of the removeLiquiditySingleTokenStruct
38
+ */
39
+ struct AddLiquiditySingleTokenKeepYtStruct {
40
+ address market;
41
+ uint256 minLpOut;
42
+ uint256 minYtOut;
43
+ address bulk;
44
+ }
45
+
46
+ struct RemoveLiquiditySingleSyStruct {
47
+ address market;
48
+ uint256 netLpToRemove;
49
+ bool doRedeemRewards;
50
+ }
51
+
52
+ /**
53
+ * @dev guessNetSyIn & guessPtReceivedFromSy have similar meanings to AddLiquiditySingleTokenStruct
54
+ */
55
+ struct AddLiquiditySingleSyStruct {
56
+ address market;
57
+ uint256 minLpOut;
58
+ uint256 guessNetSyIn;
59
+ ApproxParams guessPtReceivedFromSy;
60
+ }
61
+
62
+ struct AddLiquiditySingleSyKeepYtStruct {
63
+ address market;
64
+ uint256 minLpOut;
65
+ uint256 minYtOut;
66
+ }
67
+
68
+ event RemoveLiquiditySingleToken(
69
+ address indexed caller,
70
+ address indexed market,
71
+ address indexed token,
72
+ address receiver,
73
+ uint256 netLpToRemove,
74
+ uint256 netTokenOut
75
+ );
76
+
77
+ event RemoveLiquiditySingleSy(
78
+ address indexed caller,
79
+ address indexed market,
80
+ address indexed receiver,
81
+ uint256 netLpToRemove,
82
+ uint256 netSyOut
83
+ );
84
+
85
+ event AddLiquiditySingleToken(
86
+ address indexed caller,
87
+ address indexed market,
88
+ address indexed token,
89
+ address receiver,
90
+ uint256 netTokenIn,
91
+ uint256 netLpOut
92
+ );
93
+
94
+ event AddLiquiditySingleSy(
95
+ address indexed caller,
96
+ address indexed market,
97
+ address indexed receiver,
98
+ uint256 netSyIn,
99
+ uint256 netLpOut
100
+ );
101
+
102
+ event AddLiquiditySingleTokenKeepYt(
103
+ address indexed caller,
104
+ address indexed market,
105
+ address indexed token,
106
+ address receiver,
107
+ uint256 netTokenIn,
108
+ uint256 netLpOut,
109
+ uint256 netYtOut
110
+ );
111
+
112
+ event AddLiquiditySingleSyKeepYt(
113
+ address indexed caller,
114
+ address indexed market,
115
+ address indexed receiver,
116
+ uint256 netSyIn,
117
+ uint256 netLpOut,
118
+ uint256 netYtOut
119
+ );
120
+
121
+ function transferLiquidityDifferentSyNormal(
122
+ RemoveLiquiditySingleTokenStruct calldata fromMarket,
123
+ AddLiquiditySingleTokenStruct calldata toMarket
124
+ )
125
+ external
126
+ returns (
127
+ uint256 netLpOut,
128
+ uint256 netTokenZapIn,
129
+ uint256 netSyFeeOfRemove,
130
+ uint256 netSyFeeOfAdd
131
+ );
132
+
133
+ function transferLiquidityDifferentSyKeepYt(
134
+ RemoveLiquiditySingleTokenStruct calldata fromMarket,
135
+ AddLiquiditySingleTokenKeepYtStruct calldata toMarket
136
+ )
137
+ external
138
+ returns (
139
+ uint256 netLpOut,
140
+ uint256 netYtOut,
141
+ uint256 netTokenZapIn,
142
+ uint256 netSyFeeOfRemove
143
+ );
144
+
145
+ function transferLiquiditySameSyNormal(
146
+ RemoveLiquiditySingleSyStruct calldata fromMarket,
147
+ AddLiquiditySingleSyStruct calldata toMarket
148
+ )
149
+ external
150
+ returns (
151
+ uint256 netLpOut,
152
+ uint256 netSyZapIn,
153
+ uint256 netSyFeeOfRemove,
154
+ uint256 netSyFeeOfAdd
155
+ );
156
+
157
+ function transferLiquiditySameSyKeepYt(
158
+ RemoveLiquiditySingleSyStruct calldata fromMarket,
159
+ AddLiquiditySingleSyKeepYtStruct calldata toMarket
160
+ )
161
+ external
162
+ returns (
163
+ uint256 netLpOut,
164
+ uint256 netYtOut,
165
+ uint256 netSyZapIn,
166
+ uint256 netSyFeeOfRemove
167
+ );
168
+
169
+ function removeLiquiditySingleToken(RemoveLiquiditySingleTokenStruct calldata fromMarket)
170
+ external
171
+ returns (uint256 netTokenOut, uint256 netSyFee);
172
+
173
+ function removeLiquiditySingleSy(RemoveLiquiditySingleSyStruct calldata fromMarket)
174
+ external
175
+ returns (uint256 netSyOut, uint256 netSyFee);
176
+ }
@@ -0,0 +1,359 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ pragma solidity 0.8.17;
3
+
4
+ import "../interfaces/IPAllAction.sol";
5
+ import "../interfaces/IPMarket.sol";
6
+ import "../interfaces/IPRouterHelper.sol";
7
+ import "./base/ActionBaseMintRedeem.sol";
8
+ import "./base/MarketApproxLib.sol";
9
+ import "../interfaces/IAddressProvider.sol";
10
+
11
+ contract PendleRouterHelper is TokenHelper, IPRouterHelper {
12
+ IPAllAction public immutable ROUTER;
13
+ address public immutable WETH;
14
+
15
+ constructor(address _ROUTER, IAddressProvider provider) {
16
+ ROUTER = IPAllAction(_ROUTER);
17
+ WETH = _getWETHAddress(provider, 1);
18
+ _safeApproveInf(WETH, address(ROUTER));
19
+ }
20
+
21
+ function _getWETHAddress(IAddressProvider provider, uint256 providerId)
22
+ internal
23
+ view
24
+ returns (address)
25
+ {
26
+ return provider.get(providerId);
27
+ }
28
+
29
+ receive() external payable {}
30
+
31
+ /**
32
+ * @dev all the parameters for this function should be generated in the same way as they are
33
+ generated for the main Router, except that input.tokenIn & swapData should be generated
34
+ for tokenIn == WETH instead of ETH
35
+ */
36
+ function addLiquiditySingleTokenKeepYtWithEth(
37
+ address receiver,
38
+ address market,
39
+ uint256 minLpOut,
40
+ uint256 minYtOut,
41
+ TokenInput calldata input
42
+ ) external payable returns (uint256 netLpOut, uint256 netYtOut) {
43
+ require(input.tokenIn == WETH);
44
+
45
+ _transferIn(NATIVE, msg.sender, input.netTokenIn);
46
+
47
+ _wrap_unwrap_ETH(NATIVE, WETH, input.netTokenIn);
48
+ (netLpOut, netYtOut) = ROUTER.addLiquiditySingleTokenKeepYt(
49
+ receiver,
50
+ market,
51
+ minLpOut,
52
+ minYtOut,
53
+ input
54
+ );
55
+
56
+ emit AddLiquiditySingleTokenKeepYt(
57
+ msg.sender,
58
+ market,
59
+ NATIVE,
60
+ msg.sender,
61
+ input.netTokenIn,
62
+ netLpOut,
63
+ netYtOut
64
+ );
65
+ }
66
+
67
+ function transferLiquidityDifferentSyNormal(
68
+ RemoveLiquiditySingleTokenStruct calldata fromMarket,
69
+ AddLiquiditySingleTokenStruct calldata toMarket
70
+ )
71
+ external
72
+ returns (
73
+ uint256 netLpOut,
74
+ uint256 netTokenZapIn,
75
+ uint256 netSyFeeOfRemove,
76
+ uint256 netSyFeeOfAdd
77
+ )
78
+ {
79
+ (netTokenZapIn, netSyFeeOfRemove) = removeLiquiditySingleToken(fromMarket);
80
+ (netLpOut, netSyFeeOfAdd) = _addLiquiditySingleToken(
81
+ toMarket,
82
+ fromMarket.output.tokenOut,
83
+ netTokenZapIn
84
+ );
85
+ }
86
+
87
+ function transferLiquidityDifferentSyKeepYt(
88
+ RemoveLiquiditySingleTokenStruct calldata fromMarket,
89
+ AddLiquiditySingleTokenKeepYtStruct calldata toMarket
90
+ )
91
+ external
92
+ returns (
93
+ uint256 netLpOut,
94
+ uint256 netYtOut,
95
+ uint256 netTokenZapIn,
96
+ uint256 netSyFeeOfRemove
97
+ )
98
+ {
99
+ (netTokenZapIn, netSyFeeOfRemove) = removeLiquiditySingleToken(fromMarket);
100
+ (netLpOut, netYtOut) = _addLiquiditySingleTokenKeepYt(
101
+ toMarket,
102
+ fromMarket.output.tokenOut,
103
+ netTokenZapIn
104
+ );
105
+ }
106
+
107
+ function transferLiquiditySameSyNormal(
108
+ RemoveLiquiditySingleSyStruct calldata fromMarket,
109
+ AddLiquiditySingleSyStruct calldata toMarket
110
+ )
111
+ external
112
+ returns (
113
+ uint256 netLpOut,
114
+ uint256 netSyZapIn,
115
+ uint256 netSyFeeOfRemove,
116
+ uint256 netSyFeeOfAdd
117
+ )
118
+ {
119
+ (netSyZapIn, netSyFeeOfRemove) = removeLiquiditySingleSy(fromMarket);
120
+ (netLpOut, netSyFeeOfAdd) = _addLiquiditySingleSy(toMarket, netSyZapIn);
121
+ }
122
+
123
+ function transferLiquiditySameSyKeepYt(
124
+ RemoveLiquiditySingleSyStruct calldata fromMarket,
125
+ AddLiquiditySingleSyKeepYtStruct calldata toMarket
126
+ )
127
+ external
128
+ returns (
129
+ uint256 netLpOut,
130
+ uint256 netYtOut,
131
+ uint256 netSyZapIn,
132
+ uint256 netSyFeeOfRemove
133
+ )
134
+ {
135
+ (netSyZapIn, netSyFeeOfRemove) = removeLiquiditySingleSy(fromMarket);
136
+ (netLpOut, netYtOut) = _addLiquiditySingleSyKeepYt(toMarket, netSyZapIn);
137
+ }
138
+
139
+ function removeLiquiditySingleToken(RemoveLiquiditySingleTokenStruct calldata fromMarket)
140
+ public
141
+ returns (uint256 netTokenOut, uint256 netSyFee)
142
+ {
143
+ _transferFrom(
144
+ IERC20(fromMarket.market),
145
+ msg.sender,
146
+ address(this),
147
+ fromMarket.netLpToRemove
148
+ );
149
+
150
+ _safeApproveInf(fromMarket.market, address(ROUTER));
151
+
152
+ (netTokenOut, netSyFee) = ROUTER.removeLiquiditySingleToken(
153
+ address(this),
154
+ fromMarket.market,
155
+ fromMarket.netLpToRemove,
156
+ fromMarket.output
157
+ );
158
+
159
+ if (fromMarket.doRedeemRewards) {
160
+ IPMarket(fromMarket.market).redeemRewards(msg.sender);
161
+ }
162
+
163
+ emit RemoveLiquiditySingleToken(
164
+ msg.sender,
165
+ fromMarket.market,
166
+ fromMarket.output.tokenOut,
167
+ msg.sender,
168
+ fromMarket.netLpToRemove,
169
+ netTokenOut
170
+ );
171
+ }
172
+
173
+ function removeLiquiditySingleSy(RemoveLiquiditySingleSyStruct calldata fromMarket)
174
+ public
175
+ returns (uint256 netSyOut, uint256 netSyFee)
176
+ {
177
+ _transferFrom(
178
+ IERC20(fromMarket.market),
179
+ msg.sender,
180
+ address(this),
181
+ fromMarket.netLpToRemove
182
+ );
183
+
184
+ _safeApproveInf(fromMarket.market, address(ROUTER));
185
+
186
+ (netSyOut, netSyFee) = ROUTER.removeLiquiditySingleSy(
187
+ address(this),
188
+ fromMarket.market,
189
+ fromMarket.netLpToRemove,
190
+ 0
191
+ );
192
+
193
+ if (fromMarket.doRedeemRewards) {
194
+ IPMarket(fromMarket.market).redeemRewards(msg.sender);
195
+ }
196
+
197
+ emit RemoveLiquiditySingleSy(
198
+ msg.sender,
199
+ fromMarket.market,
200
+ msg.sender,
201
+ fromMarket.netLpToRemove,
202
+ netSyOut
203
+ );
204
+ }
205
+
206
+ function _addLiquiditySingleToken(
207
+ AddLiquiditySingleTokenStruct calldata toMarket,
208
+ address tokenToZapIn,
209
+ uint256 actualNetTokenIn
210
+ ) internal returns (uint256 netLpOut, uint256 netSyFee) {
211
+ uint256 netNativeToAttach;
212
+ if (tokenToZapIn == NATIVE) {
213
+ netNativeToAttach = actualNetTokenIn;
214
+ }
215
+
216
+ _safeApproveInf(tokenToZapIn, address(ROUTER));
217
+
218
+ (netLpOut, netSyFee) = ROUTER.addLiquiditySingleToken{ value: netNativeToAttach }(
219
+ msg.sender,
220
+ toMarket.market,
221
+ toMarket.minLpOut,
222
+ _scaleApproxParams(
223
+ toMarket.guessPtReceivedFromSy,
224
+ toMarket.guessNetTokenIn,
225
+ actualNetTokenIn
226
+ ),
227
+ _newTokenInputStruct(tokenToZapIn, actualNetTokenIn, toMarket.bulk)
228
+ );
229
+
230
+ emit AddLiquiditySingleToken(
231
+ msg.sender,
232
+ toMarket.market,
233
+ tokenToZapIn,
234
+ msg.sender,
235
+ actualNetTokenIn,
236
+ netLpOut
237
+ );
238
+ }
239
+
240
+ function _addLiquiditySingleSy(
241
+ AddLiquiditySingleSyStruct calldata toMarket,
242
+ uint256 actualNetSyIn
243
+ ) internal returns (uint256 netLpOut, uint256 netSyFee) {
244
+ (IStandardizedYield SY, , ) = IPMarket(toMarket.market).readTokens();
245
+
246
+ _safeApproveInf(address(SY), address(ROUTER));
247
+
248
+ (netLpOut, netSyFee) = ROUTER.addLiquiditySingleSy(
249
+ msg.sender,
250
+ toMarket.market,
251
+ actualNetSyIn,
252
+ toMarket.minLpOut,
253
+ _scaleApproxParams(
254
+ toMarket.guessPtReceivedFromSy,
255
+ toMarket.guessNetSyIn,
256
+ actualNetSyIn
257
+ )
258
+ );
259
+
260
+ emit AddLiquiditySingleSy(
261
+ msg.sender,
262
+ toMarket.market,
263
+ msg.sender,
264
+ actualNetSyIn,
265
+ netLpOut
266
+ );
267
+ }
268
+
269
+ function _addLiquiditySingleTokenKeepYt(
270
+ AddLiquiditySingleTokenKeepYtStruct calldata toMarket,
271
+ address tokenToZapIn,
272
+ uint256 actualNetTokenIn
273
+ ) internal returns (uint256 netLpOut, uint256 netYtOut) {
274
+ if (tokenToZapIn == NATIVE) {
275
+ tokenToZapIn = WETH;
276
+ _wrap_unwrap_ETH(NATIVE, WETH, actualNetTokenIn);
277
+ }
278
+
279
+ _safeApproveInf(tokenToZapIn, address(ROUTER));
280
+
281
+ (netLpOut, netYtOut) = ROUTER.addLiquiditySingleTokenKeepYt(
282
+ msg.sender,
283
+ toMarket.market,
284
+ toMarket.minLpOut,
285
+ toMarket.minYtOut,
286
+ _newTokenInputStruct(tokenToZapIn, actualNetTokenIn, toMarket.bulk)
287
+ );
288
+
289
+ emit AddLiquiditySingleTokenKeepYt(
290
+ msg.sender,
291
+ toMarket.market,
292
+ tokenToZapIn,
293
+ msg.sender,
294
+ actualNetTokenIn,
295
+ netLpOut,
296
+ netYtOut
297
+ );
298
+ }
299
+
300
+ function _addLiquiditySingleSyKeepYt(
301
+ AddLiquiditySingleSyKeepYtStruct calldata toMarket,
302
+ uint256 actualNetSyIn
303
+ ) internal returns (uint256 netLpOut, uint256 netYtOut) {
304
+ (IStandardizedYield SY, , ) = IPMarket(toMarket.market).readTokens();
305
+
306
+ _safeApproveInf(address(SY), address(ROUTER));
307
+
308
+ (netLpOut, netYtOut) = ROUTER.addLiquiditySingleSyKeepYt(
309
+ msg.sender,
310
+ toMarket.market,
311
+ actualNetSyIn,
312
+ toMarket.minLpOut,
313
+ toMarket.minYtOut
314
+ );
315
+
316
+ emit AddLiquiditySingleSyKeepYt(
317
+ msg.sender,
318
+ toMarket.market,
319
+ msg.sender,
320
+ actualNetSyIn,
321
+ netLpOut,
322
+ netYtOut
323
+ );
324
+ }
325
+
326
+ // ============ struct helpers ============
327
+
328
+ function _newTokenInputStruct(
329
+ address tokenIn,
330
+ uint256 netTokenIn,
331
+ address bulk
332
+ ) internal pure returns (TokenInput memory res) {
333
+ res.tokenIn = res.tokenMintSy = tokenIn;
334
+ res.netTokenIn = netTokenIn;
335
+ res.bulk = bulk;
336
+ return res;
337
+ }
338
+
339
+ /// @dev either SY or Token here is good since token->sy conversion is almost linearly proportional
340
+ function _scaleApproxParams(
341
+ ApproxParams calldata params,
342
+ uint256 guessNetTokenIn,
343
+ uint256 actualNetTokenIn
344
+ ) internal pure returns (ApproxParams memory) {
345
+ if (params.guessOffchain == 0) {
346
+ require(params.guessMin == 0 && params.guessMax == type(uint256).max, "invalid guess");
347
+ return params;
348
+ }
349
+
350
+ return
351
+ ApproxParams({
352
+ guessMin: (params.guessMin * actualNetTokenIn) / guessNetTokenIn,
353
+ guessMax: (params.guessMax * actualNetTokenIn) / guessNetTokenIn,
354
+ guessOffchain: (params.guessOffchain * actualNetTokenIn) / guessNetTokenIn,
355
+ maxIteration: params.maxIteration,
356
+ eps: params.eps
357
+ });
358
+ }
359
+ }
@@ -193,10 +193,11 @@ abstract contract ActionBaseMintRedeem is TokenHelper {
193
193
  if (netSyOut < minSyOut) revert Errors.RouterInsufficientSyOut(netSyOut, minSyOut);
194
194
  }
195
195
 
196
- function _syOrBulk(
197
- address SY,
198
- TokenOutput calldata output
199
- ) internal pure returns (address addr) {
196
+ function _syOrBulk(address SY, TokenOutput calldata output)
197
+ internal
198
+ pure
199
+ returns (address addr)
200
+ {
200
201
  return output.bulk != address(0) ? output.bulk : SY;
201
202
  }
202
203
  }
@@ -28,5 +28,5 @@
28
28
  "votingController": "0x44087E105137a5095c008AaB6a6530182821F2F0",
29
29
  "gaugeController": "0x47D74516B33eD5D70ddE7119A40839f6Fcc24e57",
30
30
  "feeDistributor": "0xd7b34a6fDCb2A7ceD2115FF7f5fdD72aa6aA4dE2",
31
- "routerHelper": "0xeb984195D54Df02BaF757e21B0705032FaEFde2E"
31
+ "routerHelper": "0x462206b11d185ef6F64B41D344325401C37EC335"
32
32
  }
@@ -23,5 +23,5 @@
23
23
  "receiverEndpoint": "0xC9215ae9EC67385F38C755D862C8eE3702B5793A",
24
24
  "vePendle": "0x3209E9412cca80B18338f2a56ADA59c484c39644",
25
25
  "gaugeController": "0x1e56299ebc8a1010cec26005d12e3e5c5cc2db00",
26
- "routerHelper": "0xeb984195D54Df02BaF757e21B0705032FaEFde2E"
26
+ "routerHelper": "0x462206b11d185ef6F64B41D344325401C37EC335"
27
27
  }
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": "2.5.0-mainnet",
5
+ "version": "2.6.0-mainnet",
6
6
  "homepage": "https://pendle.finance",
7
7
  "keywords": [
8
8
  "pendle",
@@ -27,7 +27,7 @@
27
27
  "@typechain/hardhat": "^4.0.0",
28
28
  "hardhat": "^2.13.0",
29
29
  "hardhat-contract-sizer": "^2.8.0",
30
- "prettier": "^2.8.4",
30
+ "prettier": "^2.8.5",
31
31
  "prettier-plugin-solidity": "^1.1.3",
32
32
  "solc": "^0.8.19",
33
33
  "solhint": "^3.4.1",