@pendle/core-v2 2.5.0-mainnet → 2.5.1-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 (56) 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 +747 -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 +891 -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 +168 -0
  39. package/contracts/router/PendleRouterHelper.sol +358 -0
  40. package/contracts/router/base/ActionBaseMintRedeem.sol +5 -4
  41. package/package.json +2 -2
  42. package/typechain-types/factories/ActionAddRemoveLiq__factory.ts +1 -1
  43. package/typechain-types/factories/ActionInfoStatic__factory.ts +1 -1
  44. package/typechain-types/factories/ActionMarketAuxStatic__factory.ts +1 -1
  45. package/typechain-types/factories/ActionMarketCoreStatic__factory.ts +1 -1
  46. package/typechain-types/factories/ActionMintRedeemStatic__factory.ts +1 -1
  47. package/typechain-types/factories/ActionMintRedeem__factory.ts +1 -1
  48. package/typechain-types/factories/ActionStorageStatic__factory.ts +1 -1
  49. package/typechain-types/factories/ActionSwapPT__factory.ts +1 -1
  50. package/typechain-types/factories/ActionSwapYT__factory.ts +1 -1
  51. package/typechain-types/factories/ActionVePendleStatic__factory.ts +1 -1
  52. package/typechain-types/factories/PendleRouterHelper__factory.ts +1 -1
  53. package/typechain-types/factories/PendleRouterStatic__factory.ts +1 -1
  54. package/typechain-types/factories/PendleRouter__factory.ts +1 -1
  55. package/typechain-types/hardhat.d.ts +0 -27
  56. package/typechain-types/index.ts +0 -6
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../../build-info/6b18eba6d50d13d3fa953207318c13bb.json"
3
+ "buildInfo": "../../../../build-info/09f510c98a811488a40a53c67d65a3e9.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/09f510c98a811488a40a53c67d65a3e9.json"
4
4
  }
@@ -0,0 +1,168 @@
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
+ }
@@ -0,0 +1,358 @@
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
+ }
19
+
20
+ function _getWETHAddress(IAddressProvider provider, uint256 providerId)
21
+ internal
22
+ view
23
+ returns (address)
24
+ {
25
+ return provider.get(providerId);
26
+ }
27
+
28
+ receive() external payable {}
29
+
30
+ /**
31
+ * @dev all the parameters for this function should be generated in the same way as they are
32
+ generated for the main Router, except that input.tokenIn & swapData should be generated
33
+ for tokenIn == WETH instead of ETH
34
+ */
35
+ function addLiquiditySingleTokenKeepYtWithEth(
36
+ address receiver,
37
+ address market,
38
+ uint256 minLpOut,
39
+ uint256 minYtOut,
40
+ TokenInput calldata input
41
+ ) external payable returns (uint256 netLpOut, uint256 netYtOut) {
42
+ require(input.tokenIn == WETH);
43
+
44
+ _transferIn(NATIVE, msg.sender, input.netTokenIn);
45
+
46
+ _wrap_unwrap_ETH(NATIVE, WETH, input.netTokenIn);
47
+ (netLpOut, netYtOut) = ROUTER.addLiquiditySingleTokenKeepYt(
48
+ receiver,
49
+ market,
50
+ minLpOut,
51
+ minYtOut,
52
+ input
53
+ );
54
+
55
+ emit AddLiquiditySingleTokenKeepYt(
56
+ msg.sender,
57
+ market,
58
+ NATIVE,
59
+ msg.sender,
60
+ input.netTokenIn,
61
+ netLpOut,
62
+ netYtOut
63
+ );
64
+ }
65
+
66
+ function transferLiquidityDifferentSyNormal(
67
+ RemoveLiquiditySingleTokenStruct calldata fromMarket,
68
+ AddLiquiditySingleTokenStruct calldata toMarket
69
+ )
70
+ external
71
+ returns (
72
+ uint256 netLpOut,
73
+ uint256 netTokenZapIn,
74
+ uint256 netSyFeeOfRemove,
75
+ uint256 netSyFeeOfAdd
76
+ )
77
+ {
78
+ (netTokenZapIn, netSyFeeOfRemove) = _removeLiquiditySingleToken(fromMarket);
79
+ (netLpOut, netSyFeeOfAdd) = _addLiquiditySingleToken(
80
+ toMarket,
81
+ fromMarket.output.tokenOut,
82
+ netTokenZapIn
83
+ );
84
+ }
85
+
86
+ function transferLiquidityDifferentSyKeepYt(
87
+ RemoveLiquiditySingleTokenStruct calldata fromMarket,
88
+ AddLiquiditySingleTokenKeepYtStruct calldata toMarket
89
+ )
90
+ external
91
+ returns (
92
+ uint256 netLpOut,
93
+ uint256 netYtOut,
94
+ uint256 netTokenZapIn,
95
+ uint256 netSyFeeOfRemove
96
+ )
97
+ {
98
+ (netTokenZapIn, netSyFeeOfRemove) = _removeLiquiditySingleToken(fromMarket);
99
+ (netLpOut, netYtOut) = _addLiquiditySingleTokenKeepYt(
100
+ toMarket,
101
+ fromMarket.output.tokenOut,
102
+ netTokenZapIn
103
+ );
104
+ }
105
+
106
+ function transferLiquiditySameSyNormal(
107
+ RemoveLiquiditySingleSyStruct calldata fromMarket,
108
+ AddLiquiditySingleSyStruct calldata toMarket
109
+ )
110
+ external
111
+ returns (
112
+ uint256 netLpOut,
113
+ uint256 netSyZapIn,
114
+ uint256 netSyFeeOfRemove,
115
+ uint256 netSyFeeOfAdd
116
+ )
117
+ {
118
+ (netSyZapIn, netSyFeeOfRemove) = _removeLiquiditySingleSy(fromMarket);
119
+ (netLpOut, netSyFeeOfAdd) = _addLiquiditySingleSy(toMarket, netSyZapIn);
120
+ }
121
+
122
+ function transferLiquiditySameSyKeepYt(
123
+ RemoveLiquiditySingleSyStruct calldata fromMarket,
124
+ AddLiquiditySingleSyKeepYtStruct calldata toMarket
125
+ )
126
+ external
127
+ returns (
128
+ uint256 netLpOut,
129
+ uint256 netYtOut,
130
+ uint256 netSyZapIn,
131
+ uint256 netSyFeeOfRemove
132
+ )
133
+ {
134
+ (netSyZapIn, netSyFeeOfRemove) = _removeLiquiditySingleSy(fromMarket);
135
+ (netLpOut, netYtOut) = _addLiquiditySingleSyKeepYt(toMarket, netSyZapIn);
136
+ }
137
+
138
+ function _removeLiquiditySingleToken(RemoveLiquiditySingleTokenStruct calldata fromMarket)
139
+ internal
140
+ returns (uint256 netTokenOut, uint256 netSyFee)
141
+ {
142
+ _transferFrom(
143
+ IERC20(fromMarket.market),
144
+ msg.sender,
145
+ address(this),
146
+ fromMarket.netLpToRemove
147
+ );
148
+
149
+ _safeApproveInf(fromMarket.market, address(ROUTER));
150
+
151
+ (netTokenOut, netSyFee) = ROUTER.removeLiquiditySingleToken(
152
+ address(this),
153
+ fromMarket.market,
154
+ fromMarket.netLpToRemove,
155
+ fromMarket.output
156
+ );
157
+
158
+ if (fromMarket.doRedeemRewards) {
159
+ IPMarket(fromMarket.market).redeemRewards(msg.sender);
160
+ }
161
+
162
+ emit RemoveLiquiditySingleToken(
163
+ msg.sender,
164
+ fromMarket.market,
165
+ fromMarket.output.tokenOut,
166
+ msg.sender,
167
+ fromMarket.netLpToRemove,
168
+ netTokenOut
169
+ );
170
+ }
171
+
172
+ function _removeLiquiditySingleSy(RemoveLiquiditySingleSyStruct calldata fromMarket)
173
+ internal
174
+ returns (uint256 netSyOut, uint256 netSyFee)
175
+ {
176
+ _transferFrom(
177
+ IERC20(fromMarket.market),
178
+ msg.sender,
179
+ address(this),
180
+ fromMarket.netLpToRemove
181
+ );
182
+
183
+ _safeApproveInf(fromMarket.market, address(ROUTER));
184
+
185
+ (netSyOut, netSyFee) = ROUTER.removeLiquiditySingleSy(
186
+ address(this),
187
+ fromMarket.market,
188
+ fromMarket.netLpToRemove,
189
+ 0
190
+ );
191
+
192
+ if (fromMarket.doRedeemRewards) {
193
+ IPMarket(fromMarket.market).redeemRewards(msg.sender);
194
+ }
195
+
196
+ emit RemoveLiquiditySingleSy(
197
+ msg.sender,
198
+ fromMarket.market,
199
+ msg.sender,
200
+ fromMarket.netLpToRemove,
201
+ netSyOut
202
+ );
203
+ }
204
+
205
+ function _addLiquiditySingleToken(
206
+ AddLiquiditySingleTokenStruct calldata toMarket,
207
+ address tokenToZapIn,
208
+ uint256 actualNetTokenIn
209
+ ) internal returns (uint256 netLpOut, uint256 netSyFee) {
210
+ uint256 netNativeToAttach;
211
+ if (tokenToZapIn == NATIVE) {
212
+ netNativeToAttach = actualNetTokenIn;
213
+ }
214
+
215
+ _safeApproveInf(tokenToZapIn, address(ROUTER));
216
+
217
+ (netLpOut, netSyFee) = ROUTER.addLiquiditySingleToken{ value: netNativeToAttach }(
218
+ msg.sender,
219
+ toMarket.market,
220
+ toMarket.minLpOut,
221
+ _scaleApproxParams(
222
+ toMarket.guessPtReceivedFromSy,
223
+ toMarket.guessNetTokenIn,
224
+ actualNetTokenIn
225
+ ),
226
+ _newTokenInputStruct(tokenToZapIn, actualNetTokenIn, toMarket.bulk)
227
+ );
228
+
229
+ emit AddLiquiditySingleToken(
230
+ msg.sender,
231
+ toMarket.market,
232
+ tokenToZapIn,
233
+ msg.sender,
234
+ actualNetTokenIn,
235
+ netLpOut
236
+ );
237
+ }
238
+
239
+ function _addLiquiditySingleSy(
240
+ AddLiquiditySingleSyStruct calldata toMarket,
241
+ uint256 actualNetSyIn
242
+ ) internal returns (uint256 netLpOut, uint256 netSyFee) {
243
+ (IStandardizedYield SY, , ) = IPMarket(toMarket.market).readTokens();
244
+
245
+ _safeApproveInf(address(SY), address(ROUTER));
246
+
247
+ (netLpOut, netSyFee) = ROUTER.addLiquiditySingleSy(
248
+ msg.sender,
249
+ toMarket.market,
250
+ actualNetSyIn,
251
+ toMarket.minLpOut,
252
+ _scaleApproxParams(
253
+ toMarket.guessPtReceivedFromSy,
254
+ toMarket.guessNetSyIn,
255
+ actualNetSyIn
256
+ )
257
+ );
258
+
259
+ emit AddLiquiditySingleSy(
260
+ msg.sender,
261
+ toMarket.market,
262
+ msg.sender,
263
+ actualNetSyIn,
264
+ netLpOut
265
+ );
266
+ }
267
+
268
+ function _addLiquiditySingleTokenKeepYt(
269
+ AddLiquiditySingleTokenKeepYtStruct calldata toMarket,
270
+ address tokenToZapIn,
271
+ uint256 actualNetTokenIn
272
+ ) internal returns (uint256 netLpOut, uint256 netYtOut) {
273
+ if (tokenToZapIn == NATIVE) {
274
+ tokenToZapIn = WETH;
275
+ _wrap_unwrap_ETH(NATIVE, WETH, actualNetTokenIn);
276
+ }
277
+
278
+ _safeApproveInf(tokenToZapIn, address(ROUTER));
279
+
280
+ (netLpOut, netYtOut) = ROUTER.addLiquiditySingleTokenKeepYt(
281
+ msg.sender,
282
+ toMarket.market,
283
+ toMarket.minLpOut,
284
+ toMarket.minYtOut,
285
+ _newTokenInputStruct(tokenToZapIn, actualNetTokenIn, toMarket.bulk)
286
+ );
287
+
288
+ emit AddLiquiditySingleTokenKeepYt(
289
+ msg.sender,
290
+ toMarket.market,
291
+ tokenToZapIn,
292
+ msg.sender,
293
+ actualNetTokenIn,
294
+ netLpOut,
295
+ netYtOut
296
+ );
297
+ }
298
+
299
+ function _addLiquiditySingleSyKeepYt(
300
+ AddLiquiditySingleSyKeepYtStruct calldata toMarket,
301
+ uint256 actualNetSyIn
302
+ ) internal returns (uint256 netLpOut, uint256 netYtOut) {
303
+ (IStandardizedYield SY, , ) = IPMarket(toMarket.market).readTokens();
304
+
305
+ _safeApproveInf(address(SY), address(ROUTER));
306
+
307
+ (netLpOut, netYtOut) = ROUTER.addLiquiditySingleSyKeepYt(
308
+ msg.sender,
309
+ toMarket.market,
310
+ actualNetSyIn,
311
+ toMarket.minLpOut,
312
+ toMarket.minYtOut
313
+ );
314
+
315
+ emit AddLiquiditySingleSyKeepYt(
316
+ msg.sender,
317
+ toMarket.market,
318
+ msg.sender,
319
+ actualNetSyIn,
320
+ netLpOut,
321
+ netYtOut
322
+ );
323
+ }
324
+
325
+ // ============ struct helpers ============
326
+
327
+ function _newTokenInputStruct(
328
+ address tokenIn,
329
+ uint256 netTokenIn,
330
+ address bulk
331
+ ) internal pure returns (TokenInput memory res) {
332
+ res.tokenIn = res.tokenMintSy = tokenIn;
333
+ res.netTokenIn = netTokenIn;
334
+ res.bulk = bulk;
335
+ return res;
336
+ }
337
+
338
+ /// @dev either SY or Token here is good since token->sy conversion is almost linearly proportional
339
+ function _scaleApproxParams(
340
+ ApproxParams calldata params,
341
+ uint256 guessNetTokenIn,
342
+ uint256 actualNetTokenIn
343
+ ) internal pure returns (ApproxParams memory) {
344
+ if (params.guessOffchain == 0) {
345
+ require(params.guessMin == 0 && params.guessMax == type(uint256).max, "invalid guess");
346
+ return params;
347
+ }
348
+
349
+ return
350
+ ApproxParams({
351
+ guessMin: (params.guessMin * actualNetTokenIn) / guessNetTokenIn,
352
+ guessMax: (params.guessMax * actualNetTokenIn) / guessNetTokenIn,
353
+ guessOffchain: (params.guessOffchain * actualNetTokenIn) / guessNetTokenIn,
354
+ maxIteration: params.maxIteration,
355
+ eps: params.eps
356
+ });
357
+ }
358
+ }
@@ -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
  }
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.5.1-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",