@pendle/core-v2 0.2.3 → 0.3.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 (87) hide show
  1. package/contracts/SuperComposableYield/ISuperComposableYield.sol +1 -5
  2. package/contracts/SuperComposableYield/implementations/RewardManager.sol +2 -2
  3. package/contracts/SuperComposableYield/implementations/SCYBase.sol +2 -2
  4. package/contracts/SuperComposableYield/implementations/SCYBaseWithRewards.sol +4 -7
  5. package/contracts/core/PendleMarket.sol +24 -22
  6. package/contracts/core/PendleMarketFactory.sol +7 -6
  7. package/contracts/core/PendleSCYImpl/PendleBenQiErc20SCY.sol +1 -1
  8. package/contracts/core/PendleSCYImpl/PendleBtrflySCY.sol +2 -7
  9. package/contracts/core/PendleSCYImpl/PendleYearnVaultSCY.sol +2 -7
  10. package/contracts/core/PendleYieldContractFactory.sol +12 -7
  11. package/contracts/core/PendleYieldToken.sol +93 -55
  12. package/contracts/core/router/PendleRouterCoreUpg.sol +35 -21
  13. package/contracts/core/router/PendleRouterProxy.sol +12 -6
  14. package/contracts/core/router/PendleRouterStaticUpg.sol +43 -18
  15. package/contracts/core/router/PendleRouterYTUpg.sol +47 -13
  16. package/contracts/core/router/base/PendleRouterOTBaseUpg.sol +22 -32
  17. package/contracts/core/router/base/PendleRouterSCYAndForgeBaseUpg.sol +1 -1
  18. package/contracts/core/router/base/PendleRouterYTBaseUpg.sol +62 -43
  19. package/contracts/interfaces/IPMarket.sol +4 -2
  20. package/contracts/interfaces/{IPPermissionsV2.sol → IPPermissionsV2Upg.sol} +1 -1
  21. package/contracts/interfaces/IPRouterCore.sol +24 -21
  22. package/contracts/interfaces/IPRouterStatic.sol +10 -1
  23. package/contracts/interfaces/IPRouterYT.sol +16 -4
  24. package/contracts/interfaces/IPYieldContractFactory.sol +4 -0
  25. package/contracts/interfaces/IPYieldToken.sol +2 -4
  26. package/contracts/libraries/SCYIndex.sol +3 -3
  27. package/contracts/libraries/math/LogExpMath.sol +1 -90
  28. package/contracts/libraries/math/MarketApproxLib.sol +336 -94
  29. package/contracts/libraries/math/MarketMathAux.sol +101 -0
  30. package/contracts/libraries/math/MarketMathCore.sol +423 -0
  31. package/contracts/libraries/math/Math.sol +144 -0
  32. package/contracts/{core/misc → periphery}/PendleJoeSwapHelperUpg.sol +2 -2
  33. package/contracts/periphery/{PermissionsV2.sol → PermissionsV2Upg.sol} +2 -2
  34. package/package.json +1 -1
  35. package/typechain-types/IPMarket.ts +22 -11
  36. package/typechain-types/IPRouterCore.ts +68 -58
  37. package/typechain-types/IPRouterStatic.ts +52 -0
  38. package/typechain-types/IPRouterYT.ts +96 -12
  39. package/typechain-types/IPYieldContractFactory.ts +32 -0
  40. package/typechain-types/IPYieldToken.ts +14 -48
  41. package/typechain-types/IPermissionsV2Upg.ts +87 -0
  42. package/typechain-types/ISuperComposableYield.ts +3 -11
  43. package/typechain-types/OwnableUpgradeable.ts +165 -0
  44. package/typechain-types/PendleAaveV3SCY.ts +3 -11
  45. package/typechain-types/PendleBenQiErc20SCY.ts +3 -11
  46. package/typechain-types/PendleBtrflyScy.ts +3 -11
  47. package/typechain-types/PendleMarket.ts +22 -11
  48. package/typechain-types/PendleRouterCoreUpg.ts +66 -48
  49. package/typechain-types/PendleRouterProxy.ts +15 -118
  50. package/typechain-types/PendleRouterStaticUpg.ts +92 -0
  51. package/typechain-types/PendleRouterYTUpg.ts +96 -12
  52. package/typechain-types/PendleYearnVaultScy.ts +3 -11
  53. package/typechain-types/PendleYieldContractFactory.ts +40 -113
  54. package/typechain-types/PendleYieldToken.ts +106 -7
  55. package/typechain-types/PermissionsV2Upg.ts +87 -0
  56. package/typechain-types/SCYBase.ts +3 -11
  57. package/typechain-types/SCYBaseWithRewards.ts +3 -11
  58. package/typechain-types/factories/IPMarket__factory.ts +8 -2
  59. package/typechain-types/factories/IPRouterCore__factory.ts +38 -23
  60. package/typechain-types/factories/IPRouterStatic__factory.ts +29 -0
  61. package/typechain-types/factories/IPRouterYT__factory.ts +65 -6
  62. package/typechain-types/factories/IPYieldContractFactory__factory.ts +38 -0
  63. package/typechain-types/factories/IPYieldToken__factory.ts +1 -20
  64. package/typechain-types/factories/IPermissionsV2Upg__factory.ts +39 -0
  65. package/typechain-types/factories/ISuperComposableYield__factory.ts +0 -5
  66. package/typechain-types/factories/OwnableUpgradeable__factory.ts +78 -0
  67. package/typechain-types/factories/PendleAaveV3SCY__factory.ts +1 -6
  68. package/typechain-types/factories/PendleBenQiErc20SCY__factory.ts +1 -6
  69. package/typechain-types/factories/PendleBtrflyScy__factory.ts +1 -6
  70. package/typechain-types/factories/PendleMarketFactory__factory.ts +1 -1
  71. package/typechain-types/factories/PendleMarket__factory.ts +9 -3
  72. package/typechain-types/factories/PendleRouterCoreUpg__factory.ts +26 -11
  73. package/typechain-types/factories/PendleRouterProxy__factory.ts +14 -67
  74. package/typechain-types/factories/PendleRouterStaticUpg__factory.ts +63 -17
  75. package/typechain-types/factories/PendleRouterYTUpg__factory.ts +66 -7
  76. package/typechain-types/factories/PendleYearnVaultScy__factory.ts +1 -6
  77. package/typechain-types/factories/PendleYieldContractFactory__factory.ts +39 -54
  78. package/typechain-types/factories/PendleYieldToken__factory.ts +53 -2
  79. package/typechain-types/factories/PermissionsV2Upg__factory.ts +39 -0
  80. package/typechain-types/factories/SCYBaseWithRewards__factory.ts +0 -5
  81. package/typechain-types/factories/SCYBase__factory.ts +0 -5
  82. package/typechain-types/hardhat.d.ts +26 -53
  83. package/typechain-types/index.ts +8 -14
  84. package/contracts/core/misc/BoringOwnable.sol +0 -62
  85. package/contracts/core/misc/BoringOwnableUpg.sol +0 -64
  86. package/contracts/libraries/math/FixedPoint.sol +0 -205
  87. package/contracts/libraries/math/MarketMathLib.sol +0 -614
@@ -6,15 +6,17 @@ import "./base/PendleRouterOTBaseUpg.sol";
6
6
  import "../../interfaces/IPOwnershipToken.sol";
7
7
  import "../../interfaces/IPYieldToken.sol";
8
8
  import "../../interfaces/IPRouterCore.sol";
9
+ import "../../libraries/math/MarketMathAux.sol";
9
10
 
10
11
  contract PendleRouterCoreUpg is
11
12
  IPRouterCore,
12
13
  PendleRouterSCYAndForgeBaseUpg,
13
14
  PendleRouterOTBaseUpg
14
15
  {
15
- using MarketMathLib for MarketParameters;
16
- using FixedPoint for uint256;
17
- using FixedPoint for int256;
16
+ using MarketMathCore for MarketState;
17
+ using MarketMathAux for MarketState;
18
+ using Math for uint256;
19
+ using Math for int256;
18
20
 
19
21
  /// @dev since this contract will be proxied, it must not contains non-immutable variabless
20
22
  constructor(
@@ -72,19 +74,23 @@ contract PendleRouterCoreUpg is
72
74
  function swapOtForExactScy(
73
75
  address receiver,
74
76
  address market,
75
- uint256 maxOtIn,
76
77
  uint256 exactScyOut,
77
- uint256 netOtInGuessMin,
78
- uint256 netOtInGuessMax
78
+ uint256 otInGuessMin,
79
+ uint256 otInGuessMax,
80
+ uint256 maxIteration,
81
+ uint256 eps
79
82
  ) external returns (uint256) {
80
83
  return
81
84
  _swapOtForExactScy(
82
85
  receiver,
83
86
  market,
84
- maxOtIn,
85
87
  exactScyOut,
86
- netOtInGuessMin,
87
- netOtInGuessMax,
88
+ ApproxParams({
89
+ guessMin: otInGuessMin,
90
+ guessMax: otInGuessMax,
91
+ eps: eps,
92
+ maxIteration: maxIteration
93
+ }),
88
94
  true
89
95
  );
90
96
  }
@@ -104,18 +110,22 @@ contract PendleRouterCoreUpg is
104
110
  address receiver,
105
111
  address market,
106
112
  uint256 exactScyIn,
107
- uint256 minOtOut,
108
- uint256 netOtOutGuessMin,
109
- uint256 netOtOutGuessMax
113
+ uint256 otOutguessMin,
114
+ uint256 otOutguessMax,
115
+ uint256 maxIteration,
116
+ uint256 eps
110
117
  ) external returns (uint256) {
111
118
  return
112
119
  _swapExactScyForOt(
113
120
  receiver,
114
121
  market,
115
122
  exactScyIn,
116
- minOtOut,
117
- netOtOutGuessMin,
118
- netOtOutGuessMax,
123
+ ApproxParams({
124
+ guessMin: otOutguessMin,
125
+ guessMax: otOutguessMax,
126
+ eps: eps,
127
+ maxIteration: maxIteration
128
+ }),
119
129
  true
120
130
  );
121
131
  }
@@ -177,9 +187,10 @@ contract PendleRouterCoreUpg is
177
187
  address receiver,
178
188
  address[] calldata path,
179
189
  address market,
180
- uint256 minOtOut,
181
- uint256 netOtOutGuessMin,
182
- uint256 netOtOutGuessMax
190
+ uint256 otOutguessMin,
191
+ uint256 otOutguessMax,
192
+ uint256 maxIteration,
193
+ uint256 eps
183
194
  ) external returns (uint256 netOtOut) {
184
195
  address SCY = IPMarket(market).SCY();
185
196
  uint256 netScyUseToBuyOt = _mintScyFromRawToken(
@@ -194,9 +205,12 @@ contract PendleRouterCoreUpg is
194
205
  receiver,
195
206
  market,
196
207
  netScyUseToBuyOt,
197
- minOtOut,
198
- netOtOutGuessMin,
199
- netOtOutGuessMax,
208
+ ApproxParams({
209
+ guessMin: otOutguessMin,
210
+ guessMax: otOutguessMax,
211
+ eps: eps,
212
+ maxIteration: maxIteration
213
+ }),
200
214
  false
201
215
  );
202
216
  }
@@ -3,21 +3,26 @@ pragma solidity 0.8.9;
3
3
 
4
4
  import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
5
5
  import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
6
- import "../misc/BoringOwnableUpg.sol";
7
6
  import "@openzeppelin/contracts/proxy/Proxy.sol";
8
7
  import "../../interfaces/IPRouterCore.sol";
9
8
  import "../../interfaces/IPRouterYT.sol";
10
9
  import "../../interfaces/IPRouterStatic.sol";
10
+ import "../../periphery/PermissionsV2Upg.sol";
11
11
 
12
12
  /// @dev this contract will be deployed behind an ERC1967 proxy
13
13
  /// calls to the ERC1967 proxy will be resolved at this contract, and proxied again to the
14
14
  /// corresponding implementation contracts
15
- contract PendleRouterProxy is Proxy, Initializable, UUPSUpgradeable, BoringOwnableUpg {
15
+ contract PendleRouterProxy is Proxy, Initializable, UUPSUpgradeable, PermissionsV2Upg {
16
16
  address public immutable PENDLE_ROUTER_CORE;
17
17
  address public immutable PENDLE_ROUTER_YT;
18
18
  address public immutable PENDLE_ROUTER_STATIC;
19
19
 
20
- constructor(address _PENDLE_ROUTER_CORE, address _PENDLE_ROUTER_YT, address _PENDLE_ROUTER_STATIC) {
20
+ constructor(
21
+ address _PENDLE_ROUTER_CORE,
22
+ address _PENDLE_ROUTER_YT,
23
+ address _PENDLE_ROUTER_STATIC,
24
+ address _governanceManager
25
+ ) PermissionsV2Upg(_governanceManager) initializer {
21
26
  PENDLE_ROUTER_CORE = _PENDLE_ROUTER_CORE;
22
27
  PENDLE_ROUTER_YT = _PENDLE_ROUTER_YT;
23
28
  PENDLE_ROUTER_STATIC = _PENDLE_ROUTER_STATIC;
@@ -25,7 +30,7 @@ contract PendleRouterProxy is Proxy, Initializable, UUPSUpgradeable, BoringOwnab
25
30
 
26
31
  function initialize() external initializer {
27
32
  __UUPSUpgradeable_init();
28
- __BoringOwnable_init();
33
+ // no need to initialize PermissionsV2Upg
29
34
  }
30
35
 
31
36
  function getRouterImplementation(bytes4 sig) public view returns (address) {
@@ -63,7 +68,8 @@ contract PendleRouterProxy is Proxy, Initializable, UUPSUpgradeable, BoringOwnab
63
68
  sig == IPRouterStatic.swapOtForScyStatic.selector ||
64
69
  sig == IPRouterStatic.swapScyForOtStatic.selector ||
65
70
  sig == IPRouterStatic.scyIndex.selector ||
66
- sig == IPRouterStatic.getOtImpliedYield.selector
71
+ sig == IPRouterStatic.getOtImpliedYield.selector ||
72
+ sig == IPRouterStatic.getPendleTokenType.selector
67
73
  ) {
68
74
  return PENDLE_ROUTER_STATIC;
69
75
  }
@@ -74,5 +80,5 @@ contract PendleRouterProxy is Proxy, Initializable, UUPSUpgradeable, BoringOwnab
74
80
  return getRouterImplementation(msg.sig);
75
81
  }
76
82
 
77
- function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
83
+ function _authorizeUpgrade(address newImplementation) internal override onlyGovernance {}
78
84
  }
@@ -2,19 +2,27 @@
2
2
  pragma solidity 0.8.9;
3
3
 
4
4
  import "../../interfaces/IPRouterStatic.sol";
5
+ import "../../interfaces/IPMarket.sol";
6
+ import "../../interfaces/IPYieldContractFactory.sol";
7
+ import "../../interfaces/IPMarketFactory.sol";
8
+ import "../../libraries/math/MarketMathAux.sol";
9
+ import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
10
+ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
5
11
 
6
12
  contract PendleRouterStaticUpg is IPRouterStatic {
7
- using MarketMathLib for MarketParameters;
8
- using FixedPoint for uint256;
9
- using FixedPoint for int256;
13
+ using MarketMathCore for MarketState;
14
+ using MarketMathAux for MarketState;
15
+ using Math for uint256;
16
+ using Math for int256;
10
17
  using LogExpMath for int256;
11
18
 
12
- /// @dev since this contract will be proxied, it must not contains non-immutable variabless
13
- constructor(
14
- address _joeRouter,
15
- address _joeFactory,
16
- address _marketFactory //solhint-disable-next-line no-empty-blocks
17
- ) {}
19
+ IPYieldContractFactory public immutable yieldContractFactory;
20
+ IPMarketFactory public immutable marketFactory;
21
+
22
+ constructor(IPYieldContractFactory _yieldContractFactory, IPMarketFactory _marketFactory) {
23
+ yieldContractFactory = _yieldContractFactory;
24
+ marketFactory = _marketFactory;
25
+ }
18
26
 
19
27
  function addLiquidityStatic(
20
28
  address market,
@@ -28,11 +36,12 @@ contract PendleRouterStaticUpg is IPRouterStatic {
28
36
  uint256 otUsed
29
37
  )
30
38
  {
31
- MarketParameters memory state = IPMarket(market).readState();
39
+ MarketState memory state = IPMarket(market).readState(false);
32
40
  (, netLpOut, scyUsed, otUsed) = state.addLiquidity(
33
41
  scyIndex(market),
34
42
  scyDesired,
35
- otDesired
43
+ otDesired,
44
+ false
36
45
  );
37
46
  }
38
47
 
@@ -41,19 +50,20 @@ contract PendleRouterStaticUpg is IPRouterStatic {
41
50
  view
42
51
  returns (uint256 netScyOut, uint256 netOtOut)
43
52
  {
44
- MarketParameters memory state = IPMarket(market).readState();
45
- (netScyOut, netOtOut) = state.removeLiquidity(lpToRemove);
53
+ MarketState memory state = IPMarket(market).readState(false);
54
+ (netScyOut, netOtOut) = state.removeLiquidity(lpToRemove, false);
46
55
  }
47
56
 
48
57
  function swapOtForScyStatic(address market, uint256 exactOtIn)
49
58
  external
50
59
  returns (uint256 netScyOut, uint256 netScyFee)
51
60
  {
52
- MarketParameters memory state = IPMarket(market).readState();
61
+ MarketState memory state = IPMarket(market).readState(false);
53
62
  (netScyOut, netScyFee) = state.swapExactOtForScy(
54
63
  scyIndex(market),
55
64
  exactOtIn,
56
- block.timestamp
65
+ block.timestamp,
66
+ false
57
67
  );
58
68
  }
59
69
 
@@ -61,11 +71,12 @@ contract PendleRouterStaticUpg is IPRouterStatic {
61
71
  external
62
72
  returns (uint256 netScyIn, uint256 netScyFee)
63
73
  {
64
- MarketParameters memory state = IPMarket(market).readState();
74
+ MarketState memory state = IPMarket(market).readState(false);
65
75
  (netScyIn, netScyFee) = state.swapScyForExactOt(
66
76
  scyIndex(market),
67
77
  exactOtOut,
68
- block.timestamp
78
+ block.timestamp,
79
+ false
69
80
  );
70
81
  }
71
82
 
@@ -74,9 +85,23 @@ contract PendleRouterStaticUpg is IPRouterStatic {
74
85
  }
75
86
 
76
87
  function getOtImpliedYield(address market) external view returns (int256) {
77
- MarketParameters memory state = IPMarket(market).readState();
88
+ MarketState memory state = IPMarket(market).readState(false);
78
89
 
79
90
  int256 lnImpliedRate = (state.lastImpliedRate).Int();
80
91
  return lnImpliedRate.exp();
81
92
  }
93
+
94
+ function getPendleTokenType(address token)
95
+ external
96
+ view
97
+ returns (
98
+ bool isOT,
99
+ bool isYT,
100
+ bool isMarket
101
+ )
102
+ {
103
+ if (yieldContractFactory.isOT(token)) isOT = true;
104
+ else if (yieldContractFactory.isYT(token)) isYT = true;
105
+ else if (marketFactory.isValidMarket(token)) isMarket = true;
106
+ }
82
107
  }
@@ -6,11 +6,13 @@ import "./base/PendleRouterYTBaseUpg.sol";
6
6
  import "../../interfaces/IPOwnershipToken.sol";
7
7
  import "../../interfaces/IPYieldToken.sol";
8
8
  import "../../interfaces/IPRouterYT.sol";
9
+ import "../../libraries/math/MarketMathAux.sol";
9
10
 
10
11
  contract PendleRouterYTUpg is IPRouterYT, PendleRouterSCYAndForgeBaseUpg, PendleRouterYTBaseUpg {
11
- using MarketMathLib for MarketParameters;
12
- using FixedPoint for uint256;
13
- using FixedPoint for int256;
12
+ using MarketMathCore for MarketState;
13
+ using MarketMathAux for MarketState;
14
+ using Math for uint256;
15
+ using Math for int256;
14
16
 
15
17
  /// @dev since this contract will be proxied, it must not contains non-immutable variables
16
18
  constructor(
@@ -47,18 +49,46 @@ contract PendleRouterYTUpg is IPRouterYT, PendleRouterSCYAndForgeBaseUpg, Pendle
47
49
  address receiver,
48
50
  address market,
49
51
  uint256 exactScyIn,
50
- uint256 minYtOut,
51
52
  uint256 netYtOutGuessMin,
52
- uint256 netYtOutGuessMax
53
+ uint256 netYtOutGuessMax,
54
+ uint256 maxIteration,
55
+ uint256 eps
53
56
  ) external returns (uint256) {
54
57
  return
55
58
  _swapExactScyForYt(
56
59
  receiver,
57
60
  market,
58
61
  exactScyIn,
59
- minYtOut,
60
- netYtOutGuessMin,
61
- netYtOutGuessMax,
62
+ ApproxParams({
63
+ guessMin: netYtOutGuessMin,
64
+ guessMax: netYtOutGuessMax,
65
+ eps: eps,
66
+ maxIteration: maxIteration
67
+ }),
68
+ true
69
+ );
70
+ }
71
+
72
+ function swapYtForExactScy(
73
+ address receiver,
74
+ address market,
75
+ uint256 exactScyOut,
76
+ uint256 netYtInGuessMin,
77
+ uint256 netYtInGuessMax,
78
+ uint256 maxIteration,
79
+ uint256 eps
80
+ ) external returns (uint256 netYtIn) {
81
+ return
82
+ _swapYtForExactScy(
83
+ receiver,
84
+ market,
85
+ exactScyOut,
86
+ ApproxParams({
87
+ guessMin: netYtInGuessMin,
88
+ guessMax: netYtInGuessMax,
89
+ eps: eps,
90
+ maxIteration: maxIteration
91
+ }),
62
92
  true
63
93
  );
64
94
  }
@@ -76,9 +106,10 @@ contract PendleRouterYTUpg is IPRouterYT, PendleRouterSCYAndForgeBaseUpg, Pendle
76
106
  address receiver,
77
107
  address[] calldata path,
78
108
  address market,
79
- uint256 minYtOut,
80
109
  uint256 netYtOutGuessMin,
81
- uint256 netYtOutGuessMax
110
+ uint256 netYtOutGuessMax,
111
+ uint256 maxIteration,
112
+ uint256 eps
82
113
  ) external returns (uint256 netYtOut) {
83
114
  (ISuperComposableYield SCY, , IPYieldToken YT) = IPMarket(market).readTokens();
84
115
 
@@ -95,9 +126,12 @@ contract PendleRouterYTUpg is IPRouterYT, PendleRouterSCYAndForgeBaseUpg, Pendle
95
126
  receiver,
96
127
  market,
97
128
  netScyUsedToBuyYT,
98
- minYtOut,
99
- netYtOutGuessMin,
100
- netYtOutGuessMax,
129
+ ApproxParams({
130
+ guessMin: netYtOutGuessMin,
131
+ guessMax: netYtOutGuessMax,
132
+ eps: eps,
133
+ maxIteration: maxIteration
134
+ }),
101
135
  false
102
136
  );
103
137
  }
@@ -6,13 +6,15 @@ import "../../../interfaces/IPMarket.sol";
6
6
  import "../../../interfaces/IPMarketAddRemoveCallback.sol";
7
7
  import "../../../interfaces/IPMarketSwapCallback.sol";
8
8
  import "../../../libraries/math/MarketApproxLib.sol";
9
+ import "../../../libraries/math/MarketMathAux.sol";
9
10
  import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
10
11
 
11
12
  abstract contract PendleRouterOTBaseUpg {
12
- using FixedPoint for uint256;
13
- using FixedPoint for int256;
14
- using MarketMathLib for MarketParameters;
15
- using MarketApproxLib for MarketParameters;
13
+ using Math for uint256;
14
+ using Math for int256;
15
+ using MarketMathCore for MarketState;
16
+ using MarketMathAux for MarketState;
17
+ using MarketApproxLib for MarketState;
16
18
  using SafeERC20 for IERC20;
17
19
 
18
20
  /// @dev since this contract will be proxied, it must not contains non-immutable variables
@@ -46,11 +48,12 @@ abstract contract PendleRouterOTBaseUpg {
46
48
  {
47
49
  (ISuperComposableYield SCY, IPOwnershipToken OT, ) = IPMarket(market).readTokens();
48
50
 
49
- MarketParameters memory state = IPMarket(market).readState();
51
+ MarketState memory state = IPMarket(market).readState(false);
50
52
  (, netLpOut, scyUsed, otUsed) = state.addLiquidity(
51
53
  SCYIndexLib.newIndex(SCY),
52
54
  scyDesired,
53
- otDesired
55
+ otDesired,
56
+ false
54
57
  );
55
58
 
56
59
  require(netLpOut >= minLpOut, "insufficient lp out");
@@ -79,9 +82,9 @@ abstract contract PendleRouterOTBaseUpg {
79
82
  uint256 otOutMin,
80
83
  bool doPull
81
84
  ) internal returns (uint256 netScyOut, uint256 netOtOut) {
82
- MarketParameters memory state = IPMarket(market).readState();
85
+ MarketState memory state = IPMarket(market).readState(false);
83
86
 
84
- (netScyOut, netOtOut) = state.removeLiquidity(lpToRemove);
87
+ (netScyOut, netOtOut) = state.removeLiquidity(lpToRemove, false);
85
88
  require(netScyOut >= scyOutMin, "insufficient scy out");
86
89
  require(netOtOut >= otOutMin, "insufficient ot out");
87
90
 
@@ -125,25 +128,20 @@ abstract contract PendleRouterOTBaseUpg {
125
128
  function _swapOtForExactScy(
126
129
  address receiver,
127
130
  address market,
128
- uint256 maxOtIn,
129
131
  uint256 exactScyOut,
130
- uint256 netOtInGuessMin,
131
- uint256 netOtInGuessMax,
132
+ ApproxParams memory approx,
132
133
  bool doPull
133
134
  ) internal returns (uint256 netOtIn) {
134
- MarketParameters memory state = IPMarket(market).readState();
135
+ MarketState memory state = IPMarket(market).readState(false);
135
136
  (ISuperComposableYield SCY, IPOwnershipToken OT, ) = IPMarket(market).readTokens();
136
137
 
137
- netOtIn = state.approxSwapOtForExactScy(
138
+ (netOtIn, ) = state.approxSwapOtForExactScy(
138
139
  SCYIndexLib.newIndex(SCY),
139
140
  exactScyOut,
140
141
  block.timestamp,
141
- netOtInGuessMin,
142
- netOtInGuessMax
142
+ approx
143
143
  );
144
144
 
145
- require(netOtIn <= maxOtIn, "ot in exceed limit");
146
-
147
145
  if (doPull) {
148
146
  IERC20(OT).safeTransferFrom(msg.sender, market, netOtIn);
149
147
  }
@@ -166,13 +164,14 @@ abstract contract PendleRouterOTBaseUpg {
166
164
  uint256 maxScyIn,
167
165
  bool doPull
168
166
  ) internal returns (uint256 netScyIn) {
169
- MarketParameters memory state = IPMarket(market).readState();
167
+ MarketState memory state = IPMarket(market).readState(false);
170
168
  address SCY = IPMarket(market).SCY();
171
169
 
172
170
  (netScyIn, ) = state.swapScyForExactOt(
173
171
  SCYIndexLib.newIndex(SCY),
174
172
  exactOtOut,
175
- block.timestamp
173
+ block.timestamp,
174
+ false
176
175
  );
177
176
  require(netScyIn <= maxScyIn, "exceed limit scy in");
178
177
 
@@ -187,28 +186,19 @@ abstract contract PendleRouterOTBaseUpg {
187
186
  address receiver,
188
187
  address market,
189
188
  uint256 exactScyIn,
190
- uint256 minOtOut,
191
- uint256 netOtOutGuessMin,
192
- uint256 netOtOutGuessMax,
189
+ ApproxParams memory approx,
193
190
  bool doPull
194
191
  ) internal returns (uint256 netOtOut) {
195
- MarketParameters memory state = IPMarket(market).readState();
192
+ MarketState memory state = IPMarket(market).readState(false);
196
193
  address SCY = IPMarket(market).SCY();
197
194
 
198
- if (netOtOutGuessMax == type(uint256).max) {
199
- netOtOutGuessMax = state.totalOt.Uint();
200
- }
201
-
202
- netOtOut = state.approxSwapExactScyForOt(
195
+ (netOtOut, ) = state.approxSwapExactScyForOt(
203
196
  SCYIndexLib.newIndex(SCY),
204
197
  exactScyIn,
205
198
  block.timestamp,
206
- netOtOutGuessMin,
207
- netOtOutGuessMax
199
+ approx
208
200
  );
209
201
 
210
- require(netOtOut >= minOtOut, "insufficient out");
211
-
212
202
  if (doPull) {
213
203
  IERC20(SCY).safeTransferFrom(msg.sender, market, exactScyIn);
214
204
  }
@@ -2,7 +2,7 @@
2
2
  pragma solidity 0.8.9;
3
3
 
4
4
  import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
5
- import "../../misc/PendleJoeSwapHelperUpg.sol";
5
+ import "../../../periphery/PendleJoeSwapHelperUpg.sol";
6
6
  import "../../../SuperComposableYield/ISuperComposableYield.sol";
7
7
  import "../../../interfaces/IPYieldToken.sol";
8
8