@pendle/core-v2 0.4.0 → 0.5.1-beta

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 (97) hide show
  1. package/contracts/SuperComposableYield/implementations/IRewardManager.sol +16 -0
  2. package/contracts/SuperComposableYield/implementations/RewardManager.sol +24 -5
  3. package/contracts/core/PendleMarket.sol +10 -18
  4. package/contracts/core/PendleMarketFactory.sol +49 -22
  5. package/contracts/core/PendleRouter.sol +74 -0
  6. package/contracts/core/PendleYieldToken.sol +20 -12
  7. package/contracts/core/RouterStatic.sol +234 -0
  8. package/contracts/core/actions/ActionCallback.sol +101 -0
  9. package/contracts/core/{router/PendleRouterCoreUpg.sol → actions/ActionCore.sol} +6 -10
  10. package/contracts/core/{router/PendleRouterYTUpg.sol → actions/ActionYT.sol} +6 -11
  11. package/contracts/core/{router/base/PendleRouterOTBaseUpg.sol → actions/base/ActionSCYAndOTBase.sol} +1 -5
  12. package/contracts/core/{router/base/PendleRouterSCYAndForgeBaseUpg.sol → actions/base/ActionSCYAndYOBase.sol} +3 -5
  13. package/contracts/core/{router/base/PendleRouterYTBaseUpg.sol → actions/base/ActionSCYAndYTBase.sol} +7 -99
  14. package/contracts/core/actions/base/ActionType.sol +11 -0
  15. package/contracts/interfaces/{IPRouterCore.sol → IPActionCore.sol} +1 -1
  16. package/contracts/interfaces/{IPRouterYT.sol → IPActionYT.sol} +1 -3
  17. package/contracts/interfaces/IPAllAction.sol +9 -0
  18. package/contracts/interfaces/IPMarketFactory.sol +11 -0
  19. package/contracts/interfaces/IPRouterStatic.sol +27 -0
  20. package/contracts/interfaces/IPYieldToken.sol +21 -3
  21. package/contracts/libraries/math/MarketMathCore.sol +3 -2
  22. package/package.json +1 -1
  23. package/typechain-types/{PendleRouterYTBaseUpg.ts → ActionCallback.ts} +5 -5
  24. package/typechain-types/{PendleRouterCoreUpg.ts → ActionCore.ts} +5 -5
  25. package/typechain-types/{PendleRouterSCYAndForgeBaseUpg.ts → ActionSCYAndYOBase.ts} +5 -6
  26. package/typechain-types/{BoringOwnableData.ts → ActionSCYAndYTBase.ts} +21 -24
  27. package/typechain-types/{PendleRouterStaticUpg.ts → ActionStatic.ts} +5 -5
  28. package/typechain-types/{IPRouterYT.ts → ActionYT.ts} +27 -42
  29. package/typechain-types/IPActionAll.ts +1431 -0
  30. package/typechain-types/{IPRouterCore.ts → IPActionCore.ts} +5 -5
  31. package/typechain-types/{IPRouterView.ts → IPActionStatic.ts} +57 -5
  32. package/typechain-types/{PendleRouterYTUpg.ts → IPActionYT.ts} +5 -97
  33. package/typechain-types/IPAllAction.ts +1431 -0
  34. package/typechain-types/IPMarket.ts +3 -0
  35. package/typechain-types/IPMarketFactory.ts +46 -0
  36. package/typechain-types/IPYieldToken.ts +342 -14
  37. package/typechain-types/IRewardManager.ts +178 -0
  38. package/typechain-types/PendleAaveV3SCY.ts +70 -64
  39. package/typechain-types/PendleBenQiErc20SCY.ts +70 -64
  40. package/typechain-types/PendleMarket.ts +3 -59
  41. package/typechain-types/PendleMarketFactory.ts +150 -24
  42. package/typechain-types/{PendleRouterProxy.ts → PendleRouter.ts} +29 -39
  43. package/typechain-types/PendleYieldToken.ts +116 -101
  44. package/typechain-types/RewardManager.ts +48 -42
  45. package/typechain-types/{PendleRouterViewUpg.ts → RouterStatic.ts} +97 -5
  46. package/typechain-types/SCYBaseWithRewards.ts +70 -64
  47. package/typechain-types/factories/ActionCallback__factory.ts +116 -0
  48. package/typechain-types/factories/ActionCore__factory.ts +632 -0
  49. package/typechain-types/factories/{PendleRouterSCYAndForgeBaseUpg__factory.ts → ActionSCYAndYOBase__factory.ts} +8 -12
  50. package/typechain-types/factories/ActionSCYAndYTBase__factory.ts +52 -0
  51. package/typechain-types/factories/ActionStatic__factory.ts +308 -0
  52. package/typechain-types/factories/ActionYT__factory.ts +370 -0
  53. package/typechain-types/factories/IPActionAll__factory.ts +983 -0
  54. package/typechain-types/factories/{IPRouterCore__factory.ts → IPActionCore__factory.ts} +6 -6
  55. package/typechain-types/factories/{IPRouterView__factory.ts → IPActionStatic__factory.ts} +38 -6
  56. package/typechain-types/factories/{IPRouterYT__factory.ts → IPActionYT__factory.ts} +6 -29
  57. package/typechain-types/factories/IPAllAction__factory.ts +983 -0
  58. package/typechain-types/factories/IPMarketFactory__factory.ts +28 -0
  59. package/typechain-types/factories/IPMarket__factory.ts +7 -2
  60. package/typechain-types/factories/IPYieldToken__factory.ts +158 -1
  61. package/typechain-types/factories/IRewardManager__factory.ts +92 -0
  62. package/typechain-types/factories/PendleAaveV3SCY__factory.ts +34 -34
  63. package/typechain-types/factories/PendleBenQiErc20SCY__factory.ts +34 -34
  64. package/typechain-types/factories/PendleBtrflyScy__factory.ts +1 -1
  65. package/typechain-types/factories/PendleMarketFactory__factory.ts +112 -17
  66. package/typechain-types/factories/PendleMarket__factory.ts +8 -69
  67. package/typechain-types/factories/PendleRouter__factory.ts +282 -0
  68. package/typechain-types/factories/PendleYearnVaultScy__factory.ts +1 -1
  69. package/typechain-types/factories/PendleYieldContractFactory__factory.ts +1 -1
  70. package/typechain-types/factories/PendleYieldToken__factory.ts +58 -58
  71. package/typechain-types/factories/RewardManager__factory.ts +18 -18
  72. package/typechain-types/factories/RouterStatic__factory.ts +308 -0
  73. package/typechain-types/factories/SCYBaseWithRewards__factory.ts +33 -33
  74. package/typechain-types/hardhat.d.ts +93 -75
  75. package/typechain-types/index.ts +22 -18
  76. package/contracts/core/router/PendleRouterProxy.sol +0 -84
  77. package/contracts/core/router/PendleRouterStaticUpg.sol +0 -107
  78. package/contracts/interfaces/IPFlashCallBack.sol +0 -10
  79. package/typechain-types/BoringOwnable.ts +0 -194
  80. package/typechain-types/BoringOwnableUpg.ts +0 -194
  81. package/typechain-types/BoringOwnableUpgData.ts +0 -100
  82. package/typechain-types/IPFlashCallback.ts +0 -115
  83. package/typechain-types/IPermissionsV2.ts +0 -87
  84. package/typechain-types/PermissionsV2.ts +0 -87
  85. package/typechain-types/factories/BoringOwnableData__factory.ts +0 -90
  86. package/typechain-types/factories/BoringOwnableUpgData__factory.ts +0 -94
  87. package/typechain-types/factories/BoringOwnableUpg__factory.ts +0 -139
  88. package/typechain-types/factories/BoringOwnable__factory.ts +0 -149
  89. package/typechain-types/factories/IPFlashCallback__factory.ts +0 -49
  90. package/typechain-types/factories/IPermissionsV2__factory.ts +0 -39
  91. package/typechain-types/factories/PendleRouterCoreUpg__factory.ts +0 -635
  92. package/typechain-types/factories/PendleRouterProxy__factory.ts +0 -285
  93. package/typechain-types/factories/PendleRouterStaticUpg__factory.ts +0 -315
  94. package/typechain-types/factories/PendleRouterViewUpg__factory.ts +0 -265
  95. package/typechain-types/factories/PendleRouterYTBaseUpg__factory.ts +0 -66
  96. package/typechain-types/factories/PendleRouterYTUpg__factory.ts +0 -422
  97. package/typechain-types/factories/PermissionsV2__factory.ts +0 -36
@@ -0,0 +1,101 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ pragma solidity 0.8.9;
3
+
4
+ import "../../interfaces/IPMarketFactory.sol";
5
+ import "../../interfaces/IPMarket.sol";
6
+ import "../../interfaces/IPMarketAddRemoveCallback.sol";
7
+ import "../../interfaces/IPMarketSwapCallback.sol";
8
+ import "../../SuperComposableYield/SCYUtils.sol";
9
+ import "../../libraries/math/MarketApproxLib.sol";
10
+ import "../../libraries/math/MarketMathAux.sol";
11
+ import "./base/ActionSCYAndYOBase.sol";
12
+ import "./base/ActionType.sol";
13
+ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
14
+
15
+ contract ActionCallback is IPMarketSwapCallback, ActionType {
16
+ address public immutable marketFactory;
17
+ using Math for int256;
18
+ using Math for uint256;
19
+ using SafeERC20 for ISuperComposableYield;
20
+ using SafeERC20 for IPYieldToken;
21
+
22
+ modifier onlyPendleMarket(address market) {
23
+ require(IPMarketFactory(marketFactory).isValidMarket(market), "INVALID_MARKET");
24
+ _;
25
+ }
26
+
27
+ /// @dev since this contract will be proxied, it must not contains non-immutable variables
28
+ constructor(address _marketFactory) {
29
+ marketFactory = _marketFactory;
30
+ }
31
+
32
+ function swapCallback(
33
+ int256 otToAccount,
34
+ int256 scyToAccount,
35
+ bytes calldata data
36
+ ) external override onlyPendleMarket(msg.sender) {
37
+ (ACTION_TYPE swapType, ) = abi.decode(data, (ACTION_TYPE, bytes));
38
+
39
+ if (swapType == ACTION_TYPE.SwapExactScyForYt) {
40
+ _swapExactScyForYt_callback(msg.sender, data);
41
+ } else if (swapType == ACTION_TYPE.SwapSCYForExactYt) {
42
+ _swapScyForExactYt_callback(msg.sender, otToAccount, scyToAccount, data);
43
+ } else if (
44
+ swapType == ACTION_TYPE.SwapYtForExactScy || swapType == ACTION_TYPE.SwapExactYtForScy
45
+ ) {
46
+ _swapYtForScy_callback(msg.sender, scyToAccount, data);
47
+ } else {
48
+ require(false, "unknown swapType");
49
+ }
50
+ }
51
+
52
+ function _swapExactScyForYt_callback(address market, bytes calldata data) internal {
53
+ (, , IPYieldToken YT) = IPMarket(market).readTokens();
54
+ (, address receiver) = abi.decode(data, (ACTION_TYPE, address));
55
+
56
+ YT.mintYO(market, receiver);
57
+ }
58
+
59
+ function _swapScyForExactYt_callback(
60
+ address market,
61
+ int256 otToAccount,
62
+ int256 scyToAccount,
63
+ bytes calldata data
64
+ ) internal {
65
+ (, address payer, address receiver) = abi.decode(data, (ACTION_TYPE, address, address));
66
+ (ISuperComposableYield SCY, , IPYieldToken YT) = IPMarket(market).readTokens();
67
+
68
+ uint256 otOwed = otToAccount.neg().Uint();
69
+ uint256 scyReceived = scyToAccount.Uint();
70
+
71
+ // otOwed = totalAsset
72
+ uint256 scyNeedTotal = SCYUtils.assetToScy(SCY.scyIndexCurrent(), otOwed);
73
+
74
+ uint256 netScyToPull = scyNeedTotal.subMax0(scyReceived);
75
+ SCY.safeTransferFrom(payer, address(YT), netScyToPull);
76
+
77
+ YT.mintYO(market, receiver);
78
+ }
79
+
80
+ /**
81
+ @dev receive OT -> pair with YT to redeem SCY -> payback SCY
82
+ */
83
+ function _swapYtForScy_callback(
84
+ address market,
85
+ int256 scyToAccount,
86
+ bytes calldata data
87
+ ) internal {
88
+ (, address receiver) = abi.decode(data, (ACTION_TYPE, address));
89
+ (ISuperComposableYield SCY, , IPYieldToken YT) = IPMarket(market).readTokens();
90
+
91
+ uint256 scyOwed = scyToAccount.neg().Uint();
92
+
93
+ uint256 netScyReceived = YT.redeemYO(address(this));
94
+
95
+ SCY.safeTransfer(market, scyOwed);
96
+
97
+ if (receiver != address(this)) {
98
+ SCY.safeTransfer(receiver, netScyReceived - scyOwed);
99
+ }
100
+ }
101
+ }
@@ -1,18 +1,14 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-or-later
2
2
  pragma solidity 0.8.9;
3
3
 
4
- import "./base/PendleRouterSCYAndForgeBaseUpg.sol";
5
- import "./base/PendleRouterOTBaseUpg.sol";
4
+ import "./base/ActionSCYAndOTBase.sol";
5
+ import "./base/ActionSCYAndYOBase.sol";
6
6
  import "../../interfaces/IPOwnershipToken.sol";
7
7
  import "../../interfaces/IPYieldToken.sol";
8
- import "../../interfaces/IPRouterCore.sol";
8
+ import "../../interfaces/IPActionCore.sol";
9
9
  import "../../libraries/math/MarketMathAux.sol";
10
10
 
11
- contract PendleRouterCoreUpg is
12
- IPRouterCore,
13
- PendleRouterSCYAndForgeBaseUpg,
14
- PendleRouterOTBaseUpg
15
- {
11
+ contract ActionCore is IPActionCore, ActionSCYAndOTBase, ActionSCYAndYOBase {
16
12
  using MarketMathCore for MarketState;
17
13
  using MarketMathAux for MarketState;
18
14
  using Math for uint256;
@@ -24,8 +20,8 @@ contract PendleRouterCoreUpg is
24
20
  address _joeFactory,
25
21
  address _marketFactory
26
22
  )
27
- PendleRouterSCYAndForgeBaseUpg(_joeRouter, _joeFactory)
28
- PendleRouterOTBaseUpg()
23
+ ActionSCYAndYOBase(_joeRouter, _joeFactory)
24
+ ActionSCYAndOTBase()
29
25
  //solhint-disable-next-line no-empty-blocks
30
26
  {
31
27
 
@@ -1,27 +1,22 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-or-later
2
2
  pragma solidity 0.8.9;
3
3
 
4
- import "./base/PendleRouterSCYAndForgeBaseUpg.sol";
5
- import "./base/PendleRouterYTBaseUpg.sol";
4
+ import "./base/ActionSCYAndYTBase.sol";
6
5
  import "../../interfaces/IPOwnershipToken.sol";
7
6
  import "../../interfaces/IPYieldToken.sol";
8
- import "../../interfaces/IPRouterYT.sol";
7
+ import "../../interfaces/IPActionYT.sol";
9
8
  import "../../libraries/math/MarketMathAux.sol";
10
9
 
11
- contract PendleRouterYTUpg is IPRouterYT, PendleRouterSCYAndForgeBaseUpg, PendleRouterYTBaseUpg {
10
+ contract ActionYT is IPActionYT, ActionSCYAndYTBase {
12
11
  using MarketMathCore for MarketState;
13
12
  using MarketMathAux for MarketState;
14
13
  using Math for uint256;
15
14
  using Math for int256;
16
15
 
17
16
  /// @dev since this contract will be proxied, it must not contains non-immutable variables
18
- constructor(
19
- address _joeRouter,
20
- address _joeFactory,
21
- address _marketFactory
22
- )
23
- PendleRouterSCYAndForgeBaseUpg(_joeRouter, _joeFactory)
24
- PendleRouterYTBaseUpg(_marketFactory)
17
+ constructor(address _joeRouter, address _joeFactory)
18
+ ActionSCYAndYOBase(_joeRouter, _joeFactory)
19
+ ActionSCYAndYTBase()
25
20
  //solhint-disable-next-line no-empty-blocks
26
21
  {
27
22
 
@@ -9,7 +9,7 @@ import "../../../libraries/math/MarketApproxLib.sol";
9
9
  import "../../../libraries/math/MarketMathAux.sol";
10
10
  import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
11
11
 
12
- abstract contract PendleRouterOTBaseUpg {
12
+ abstract contract ActionSCYAndOTBase {
13
13
  using Math for uint256;
14
14
  using Math for int256;
15
15
  using MarketMathCore for MarketState;
@@ -18,10 +18,6 @@ abstract contract PendleRouterOTBaseUpg {
18
18
  using SafeERC20 for IERC20;
19
19
 
20
20
  /// @dev since this contract will be proxied, it must not contains non-immutable variables
21
- constructor() //solhint-disable-next-line no-empty-blocks
22
- {
23
-
24
- }
25
21
 
26
22
  /**
27
23
  * @notice addLiquidity to the market, using both SCY & OT, the receiver will receive LP before
@@ -6,16 +6,14 @@ import "../../../periphery/PendleJoeSwapHelperUpg.sol";
6
6
  import "../../../SuperComposableYield/ISuperComposableYield.sol";
7
7
  import "../../../interfaces/IPYieldToken.sol";
8
8
 
9
- abstract contract PendleRouterSCYAndForgeBaseUpg is PendleJoeSwapHelperUpg {
9
+ // solhint-disable no-empty-blocks
10
+ abstract contract ActionSCYAndYOBase is PendleJoeSwapHelperUpg {
10
11
  using SafeERC20 for IERC20;
11
12
 
12
13
  /// @dev since this contract will be proxied, it must not contains non-immutable variables
13
14
  constructor(address _joeRouter, address _joeFactory)
14
15
  PendleJoeSwapHelperUpg(_joeRouter, _joeFactory)
15
- // solhint-disable-next-line no-empty-blocks
16
- {
17
-
18
- }
16
+ {}
19
17
 
20
18
  /**
21
19
  * @notice swap rawToken to baseToken -> baseToken to mint SCY
@@ -3,14 +3,14 @@ pragma solidity 0.8.9;
3
3
 
4
4
  import "../../../interfaces/IPMarketFactory.sol";
5
5
  import "../../../interfaces/IPMarket.sol";
6
- import "../../../interfaces/IPMarketAddRemoveCallback.sol";
7
- import "../../../interfaces/IPMarketSwapCallback.sol";
8
6
  import "../../../SuperComposableYield/SCYUtils.sol";
9
7
  import "../../../libraries/math/MarketApproxLib.sol";
10
8
  import "../../../libraries/math/MarketMathAux.sol";
9
+ import "./ActionSCYAndYOBase.sol";
10
+ import "./ActionType.sol";
11
11
  import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
12
12
 
13
- abstract contract PendleRouterYTBaseUpg is IPMarketSwapCallback {
13
+ abstract contract ActionSCYAndYTBase is ActionSCYAndYOBase, ActionType {
14
14
  using Math for uint256;
15
15
  using Math for int256;
16
16
  using MarketMathCore for MarketState;
@@ -19,28 +19,6 @@ abstract contract PendleRouterYTBaseUpg is IPMarketSwapCallback {
19
19
  using SafeERC20 for ISuperComposableYield;
20
20
  using SafeERC20 for IPYieldToken;
21
21
 
22
- // solhint-disable-next-line
23
- enum YT_SWAP_TYPE {
24
- ExactYtForScy,
25
- SCYForExactYt,
26
- ExactScyForYt,
27
- YtForExactScy
28
- }
29
-
30
- address public immutable marketFactory;
31
-
32
- modifier onlyPendleMarket(address market) {
33
- require(IPMarketFactory(marketFactory).isValidMarket(market), "INVALID_MARKET");
34
- _;
35
- }
36
-
37
- /// @dev since this contract will be proxied, it must not contains non-immutable variables
38
- constructor(
39
- address _marketFactory //solhint-disable-next-line no-empty-blocks
40
- ) {
41
- marketFactory = _marketFactory;
42
- }
43
-
44
22
  function _swapExactScyForYt(
45
23
  address receiver,
46
24
  address market,
@@ -66,7 +44,7 @@ abstract contract PendleRouterYTBaseUpg is IPMarketSwapCallback {
66
44
  receiver,
67
45
  netYtOut, // exactOtIn = netYtOut
68
46
  1,
69
- abi.encode(YT_SWAP_TYPE.ExactScyForYt, receiver)
47
+ abi.encode(ACTION_TYPE.SwapExactScyForYt, receiver)
70
48
  );
71
49
  }
72
50
 
@@ -96,7 +74,7 @@ abstract contract PendleRouterYTBaseUpg is IPMarketSwapCallback {
96
74
  receiver,
97
75
  exactYtIn, // exactOtOut = exactYtIn
98
76
  type(uint256).max,
99
- abi.encode(YT_SWAP_TYPE.ExactYtForScy, receiver)
77
+ abi.encode(ACTION_TYPE.SwapExactYtForScy, receiver)
100
78
  );
101
79
 
102
80
  netScyOut = SCY.balanceOf(receiver) - preBalanceScy;
@@ -122,7 +100,7 @@ abstract contract PendleRouterYTBaseUpg is IPMarketSwapCallback {
122
100
  receiver,
123
101
  exactYtOut, // exactOtIn = exactYtOut
124
102
  1,
125
- abi.encode(YT_SWAP_TYPE.SCYForExactYt, msg.sender, receiver)
103
+ abi.encode(ACTION_TYPE.SwapSCYForExactYt, msg.sender, receiver)
126
104
  );
127
105
 
128
106
  netScyIn = preBalanceScy - SCY.balanceOf(receiver);
@@ -155,77 +133,7 @@ abstract contract PendleRouterYTBaseUpg is IPMarketSwapCallback {
155
133
  address(YT),
156
134
  netYtIn, // exactOtOut = netYtIn
157
135
  type(uint256).max,
158
- abi.encode(YT_SWAP_TYPE.YtForExactScy, receiver)
136
+ abi.encode(ACTION_TYPE.SwapYtForExactScy, receiver)
159
137
  );
160
138
  }
161
-
162
- function swapCallback(
163
- int256 otToAccount,
164
- int256 scyToAccount,
165
- bytes calldata data
166
- ) external override onlyPendleMarket(msg.sender) {
167
- (YT_SWAP_TYPE swapType, ) = abi.decode(data, (YT_SWAP_TYPE, bytes));
168
-
169
- if (swapType == YT_SWAP_TYPE.ExactScyForYt) {
170
- _swapExactScyForYt_callback(msg.sender, data);
171
- } else if (swapType == YT_SWAP_TYPE.ExactYtForScy) {
172
- _swapYtForScy_callback(msg.sender, scyToAccount, data);
173
- } else if (swapType == YT_SWAP_TYPE.SCYForExactYt) {
174
- _swapScyForExactYt_callback(msg.sender, otToAccount, scyToAccount, data);
175
- } else if (swapType == YT_SWAP_TYPE.YtForExactScy) {
176
- _swapYtForScy_callback(msg.sender, scyToAccount, data);
177
- } else {
178
- require(false, "unknown swapType");
179
- }
180
- }
181
-
182
- function _swapExactScyForYt_callback(address market, bytes calldata data) internal {
183
- (, , IPYieldToken YT) = IPMarket(market).readTokens();
184
- (, address receiver) = abi.decode(data, (YT_SWAP_TYPE, address));
185
-
186
- YT.mintYO(market, receiver);
187
- }
188
-
189
- function _swapScyForExactYt_callback(
190
- address market,
191
- int256 otToAccount,
192
- int256 scyToAccount,
193
- bytes calldata data
194
- ) internal {
195
- (, address payer, address receiver) = abi.decode(data, (YT_SWAP_TYPE, address, address));
196
- (ISuperComposableYield SCY, , IPYieldToken YT) = IPMarket(market).readTokens();
197
-
198
- uint256 otOwed = otToAccount.neg().Uint();
199
- uint256 scyReceived = scyToAccount.Uint();
200
-
201
- // otOwed = totalAsset
202
- uint256 scyNeedTotal = SCYUtils.assetToScy(SCY.scyIndexCurrent(), otOwed);
203
-
204
- uint256 netScyToPull = scyNeedTotal.subMax0(scyReceived);
205
- SCY.safeTransferFrom(payer, address(YT), netScyToPull);
206
-
207
- YT.mintYO(market, receiver);
208
- }
209
-
210
- /**
211
- @dev receive OT -> pair with YT to redeem SCY -> payback SCY
212
- */
213
- function _swapYtForScy_callback(
214
- address market,
215
- int256 scyToAccount,
216
- bytes calldata data
217
- ) internal {
218
- (, address receiver) = abi.decode(data, (YT_SWAP_TYPE, address));
219
- (ISuperComposableYield SCY, , IPYieldToken YT) = IPMarket(market).readTokens();
220
-
221
- uint256 scyOwed = scyToAccount.neg().Uint();
222
-
223
- uint256 netScyReceived = YT.redeemYO(address(this));
224
-
225
- SCY.safeTransfer(market, scyOwed);
226
-
227
- if (receiver != address(this)) {
228
- SCY.safeTransfer(receiver, netScyReceived - scyOwed);
229
- }
230
- }
231
139
  }
@@ -0,0 +1,11 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ pragma solidity 0.8.9;
3
+
4
+ abstract contract ActionType {
5
+ enum ACTION_TYPE {
6
+ SwapExactYtForScy,
7
+ SwapSCYForExactYt,
8
+ SwapExactScyForYt,
9
+ SwapYtForExactScy
10
+ }
11
+ }
@@ -1,7 +1,7 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-or-later
2
2
  pragma solidity 0.8.9;
3
3
 
4
- interface IPRouterCore {
4
+ interface IPActionCore {
5
5
  function addLiquidity(
6
6
  address receiver,
7
7
  address market,
@@ -1,9 +1,7 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-or-later
2
2
  pragma solidity 0.8.9;
3
3
 
4
- import "./IPMarketSwapCallback.sol";
5
-
6
- interface IPRouterYT is IPMarketSwapCallback {
4
+ interface IPActionYT {
7
5
  function swapExactYtForScy(
8
6
  address receiver,
9
7
  address market,
@@ -0,0 +1,9 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+ pragma solidity 0.8.9;
4
+
5
+ import "./IPActionCore.sol";
6
+ import "./IPActionYT.sol";
7
+ import "./IPRouterStatic.sol";
8
+
9
+ interface IPAllAction is IPActionCore, IPActionYT, IPRouterStatic {}
@@ -5,4 +5,15 @@ interface IPMarketFactory {
5
5
  function isValidMarket(address market) external view returns (bool);
6
6
 
7
7
  function treasury() external view returns (address);
8
+
9
+ // If this is changed, change the readState function in market as well
10
+ function marketConfig()
11
+ external
12
+ view
13
+ returns (
14
+ address treasury,
15
+ uint96 feeRateRoot,
16
+ uint32 rateOracleTimeWindow,
17
+ uint8 reserveFeePercent
18
+ );
8
19
  }
@@ -4,6 +4,33 @@ pragma solidity 0.8.9;
4
4
  import "../libraries/math/MarketMathCore.sol";
5
5
 
6
6
  interface IPRouterStatic {
7
+ struct TokenAmount {
8
+ address token;
9
+ uint256 amount;
10
+ }
11
+
12
+ struct RewardIndex {
13
+ address rewardToken;
14
+ uint256 index;
15
+ }
16
+
17
+ struct UserYOInfo {
18
+ address yt;
19
+ address ot;
20
+ uint256 ytBalance;
21
+ uint256 otBalance;
22
+ TokenAmount unclaimedInterest;
23
+ TokenAmount[] unclaimedRewards;
24
+ }
25
+
26
+ struct UserMarketInfo {
27
+ address market;
28
+ uint256 lpBalance;
29
+ TokenAmount otBalance;
30
+ TokenAmount scyBalance;
31
+ TokenAmount assetBalance;
32
+ }
33
+
7
34
  function addLiquidityStatic(
8
35
  address market,
9
36
  uint256 scyDesired,
@@ -1,15 +1,33 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-or-later
2
2
  pragma solidity 0.8.9;
3
3
  import "./IPBaseToken.sol";
4
+ import "../SuperComposableYield/implementations/IRewardManager.sol";
4
5
 
5
- interface IPYieldToken is IPBaseToken {
6
+ interface IPYieldToken is IPBaseToken, IRewardManager {
6
7
  function mintYO(address receiverOT, address receiverYT) external returns (uint256 amountYOOut);
7
8
 
8
9
  function redeemYO(address receiver) external returns (uint256 amountScyOut);
9
10
 
10
- function redeemDueInterestAndRewards(address user)
11
+ // minimum of OT & YT balance
12
+
13
+ function redeemDueInterest(address user) external returns (uint256 interestOut);
14
+
15
+ function redeemDueRewards(address user) external returns (uint256[] memory rewardsOut);
16
+
17
+ function updateGlobalReward() external;
18
+
19
+ function updateUserReward(address user) external;
20
+
21
+ function updateUserInterest(address user) external;
22
+
23
+ function getInterestData(address user)
11
24
  external
12
- returns (uint256 interestOut, uint256[] memory rewardsOut);
25
+ view
26
+ returns (uint256 lastScyIndex, uint256 dueInterest);
27
+
28
+ function getScyIndexBeforeExpiry() external returns (uint256 res);
29
+
30
+ function withdrawFeeToTreasury() external;
13
31
 
14
32
  function SCY() external view returns (address);
15
33
 
@@ -10,12 +10,13 @@ struct MarketState {
10
10
  int256 totalScy;
11
11
  int256 totalLp;
12
12
  uint256 oracleRate;
13
+ address treasury;
13
14
  /// immutable variables ///
14
15
  int256 scalarRoot;
15
16
  uint256 feeRateRoot;
16
17
  uint256 rateOracleTimeWindow;
17
18
  uint256 expiry;
18
- int256 reserveFeePercent; // base 100
19
+ uint256 reserveFeePercent; // base 100
19
20
  /// last trade data ///
20
21
  uint256 lastImpliedRate;
21
22
  uint256 lastTradeTime;
@@ -222,7 +223,7 @@ library MarketMathCore {
222
223
  fee = ((preFeeAssetToAccount * (Math.IONE - fee)) / fee).neg();
223
224
  }
224
225
 
225
- netAssetToReserve = (fee * market.reserveFeePercent) / PERCENTAGE_DECIMALS;
226
+ netAssetToReserve = (fee * market.reserveFeePercent.Int()) / PERCENTAGE_DECIMALS;
226
227
  netAssetToAccount = preFeeAssetToAccount - fee;
227
228
  // netAssetToMarket = (preFeeAssetToAccount - fee + netAssetToReserve)
228
229
  // .neg();
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.4.0",
5
+ "version": "0.5.1-beta",
6
6
  "homepage": "https://pendle.finance",
7
7
  "keywords": [
8
8
  "pendle",
@@ -22,8 +22,8 @@ import type {
22
22
  OnEvent,
23
23
  } from "./common";
24
24
 
25
- export interface PendleRouterYTBaseUpgInterface extends utils.Interface {
26
- contractName: "PendleRouterYTBaseUpg";
25
+ export interface ActionCallbackInterface extends utils.Interface {
26
+ contractName: "ActionCallback";
27
27
  functions: {
28
28
  "marketFactory()": FunctionFragment;
29
29
  "swapCallback(int256,int256,bytes)": FunctionFragment;
@@ -50,13 +50,13 @@ export interface PendleRouterYTBaseUpgInterface extends utils.Interface {
50
50
  events: {};
51
51
  }
52
52
 
53
- export interface PendleRouterYTBaseUpg extends BaseContract {
54
- contractName: "PendleRouterYTBaseUpg";
53
+ export interface ActionCallback extends BaseContract {
54
+ contractName: "ActionCallback";
55
55
  connect(signerOrProvider: Signer | Provider | string): this;
56
56
  attach(addressOrName: string): this;
57
57
  deployed(): Promise<this>;
58
58
 
59
- interface: PendleRouterYTBaseUpgInterface;
59
+ interface: ActionCallbackInterface;
60
60
 
61
61
  queryFilter<TEvent extends TypedEvent>(
62
62
  event: TypedEventFilter<TEvent>,
@@ -22,8 +22,8 @@ import type {
22
22
  OnEvent,
23
23
  } from "./common";
24
24
 
25
- export interface PendleRouterCoreUpgInterface extends utils.Interface {
26
- contractName: "PendleRouterCoreUpg";
25
+ export interface ActionCoreInterface extends utils.Interface {
26
+ contractName: "ActionCore";
27
27
  functions: {
28
28
  "addLiquidity(address,address,uint256,uint256,uint256)": FunctionFragment;
29
29
  "joeFactory()": FunctionFragment;
@@ -174,13 +174,13 @@ export interface PendleRouterCoreUpgInterface extends utils.Interface {
174
174
  events: {};
175
175
  }
176
176
 
177
- export interface PendleRouterCoreUpg extends BaseContract {
178
- contractName: "PendleRouterCoreUpg";
177
+ export interface ActionCore extends BaseContract {
178
+ contractName: "ActionCore";
179
179
  connect(signerOrProvider: Signer | Provider | string): this;
180
180
  attach(addressOrName: string): this;
181
181
  deployed(): Promise<this>;
182
182
 
183
- interface: PendleRouterCoreUpgInterface;
183
+ interface: ActionCoreInterface;
184
184
 
185
185
  queryFilter<TEvent extends TypedEvent>(
186
186
  event: TypedEventFilter<TEvent>,
@@ -19,9 +19,8 @@ import type {
19
19
  OnEvent,
20
20
  } from "./common";
21
21
 
22
- export interface PendleRouterSCYAndForgeBaseUpgInterface
23
- extends utils.Interface {
24
- contractName: "PendleRouterSCYAndForgeBaseUpg";
22
+ export interface ActionSCYAndYOBaseInterface extends utils.Interface {
23
+ contractName: "ActionSCYAndYOBase";
25
24
  functions: {
26
25
  "joeFactory()": FunctionFragment;
27
26
  "joeRouter()": FunctionFragment;
@@ -39,13 +38,13 @@ export interface PendleRouterSCYAndForgeBaseUpgInterface
39
38
  events: {};
40
39
  }
41
40
 
42
- export interface PendleRouterSCYAndForgeBaseUpg extends BaseContract {
43
- contractName: "PendleRouterSCYAndForgeBaseUpg";
41
+ export interface ActionSCYAndYOBase extends BaseContract {
42
+ contractName: "ActionSCYAndYOBase";
44
43
  connect(signerOrProvider: Signer | Provider | string): this;
45
44
  attach(addressOrName: string): this;
46
45
  deployed(): Promise<this>;
47
46
 
48
- interface: PendleRouterSCYAndForgeBaseUpgInterface;
47
+ interface: ActionSCYAndYOBaseInterface;
49
48
 
50
49
  queryFilter<TEvent extends TypedEvent>(
51
50
  event: TypedEventFilter<TEvent>,