@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.
- package/contracts/SuperComposableYield/ISuperComposableYield.sol +1 -5
- package/contracts/SuperComposableYield/implementations/RewardManager.sol +2 -2
- package/contracts/SuperComposableYield/implementations/SCYBase.sol +2 -2
- package/contracts/SuperComposableYield/implementations/SCYBaseWithRewards.sol +4 -7
- package/contracts/core/PendleMarket.sol +24 -22
- package/contracts/core/PendleMarketFactory.sol +7 -6
- package/contracts/core/PendleSCYImpl/PendleBenQiErc20SCY.sol +1 -1
- package/contracts/core/PendleSCYImpl/PendleBtrflySCY.sol +2 -7
- package/contracts/core/PendleSCYImpl/PendleYearnVaultSCY.sol +2 -7
- package/contracts/core/PendleYieldContractFactory.sol +12 -7
- package/contracts/core/PendleYieldToken.sol +93 -55
- package/contracts/core/router/PendleRouterCoreUpg.sol +35 -21
- package/contracts/core/router/PendleRouterProxy.sol +12 -6
- package/contracts/core/router/PendleRouterStaticUpg.sol +43 -18
- package/contracts/core/router/PendleRouterYTUpg.sol +47 -13
- package/contracts/core/router/base/PendleRouterOTBaseUpg.sol +22 -32
- package/contracts/core/router/base/PendleRouterSCYAndForgeBaseUpg.sol +1 -1
- package/contracts/core/router/base/PendleRouterYTBaseUpg.sol +62 -43
- package/contracts/interfaces/IPMarket.sol +4 -2
- package/contracts/interfaces/{IPPermissionsV2.sol → IPPermissionsV2Upg.sol} +1 -1
- package/contracts/interfaces/IPRouterCore.sol +24 -21
- package/contracts/interfaces/IPRouterStatic.sol +10 -1
- package/contracts/interfaces/IPRouterYT.sol +16 -4
- package/contracts/interfaces/IPYieldContractFactory.sol +4 -0
- package/contracts/interfaces/IPYieldToken.sol +2 -4
- package/contracts/libraries/SCYIndex.sol +3 -3
- package/contracts/libraries/math/LogExpMath.sol +1 -90
- package/contracts/libraries/math/MarketApproxLib.sol +336 -94
- package/contracts/libraries/math/MarketMathAux.sol +101 -0
- package/contracts/libraries/math/MarketMathCore.sol +423 -0
- package/contracts/libraries/math/Math.sol +144 -0
- package/contracts/{core/misc → periphery}/PendleJoeSwapHelperUpg.sol +2 -2
- package/contracts/periphery/{PermissionsV2.sol → PermissionsV2Upg.sol} +2 -2
- package/package.json +1 -1
- package/typechain-types/IPMarket.ts +22 -11
- package/typechain-types/IPRouterCore.ts +68 -58
- package/typechain-types/IPRouterStatic.ts +52 -0
- package/typechain-types/IPRouterYT.ts +96 -12
- package/typechain-types/IPYieldContractFactory.ts +32 -0
- package/typechain-types/IPYieldToken.ts +14 -48
- package/typechain-types/IPermissionsV2Upg.ts +87 -0
- package/typechain-types/ISuperComposableYield.ts +3 -11
- package/typechain-types/OwnableUpgradeable.ts +165 -0
- package/typechain-types/PendleAaveV3SCY.ts +3 -11
- package/typechain-types/PendleBenQiErc20SCY.ts +3 -11
- package/typechain-types/PendleBtrflyScy.ts +3 -11
- package/typechain-types/PendleMarket.ts +22 -11
- package/typechain-types/PendleRouterCoreUpg.ts +66 -48
- package/typechain-types/PendleRouterProxy.ts +15 -118
- package/typechain-types/PendleRouterStaticUpg.ts +92 -0
- package/typechain-types/PendleRouterYTUpg.ts +96 -12
- package/typechain-types/PendleYearnVaultScy.ts +3 -11
- package/typechain-types/PendleYieldContractFactory.ts +40 -113
- package/typechain-types/PendleYieldToken.ts +106 -7
- package/typechain-types/PermissionsV2Upg.ts +87 -0
- package/typechain-types/SCYBase.ts +3 -11
- package/typechain-types/SCYBaseWithRewards.ts +3 -11
- package/typechain-types/factories/IPMarket__factory.ts +8 -2
- package/typechain-types/factories/IPRouterCore__factory.ts +38 -23
- package/typechain-types/factories/IPRouterStatic__factory.ts +29 -0
- package/typechain-types/factories/IPRouterYT__factory.ts +65 -6
- package/typechain-types/factories/IPYieldContractFactory__factory.ts +38 -0
- package/typechain-types/factories/IPYieldToken__factory.ts +1 -20
- package/typechain-types/factories/IPermissionsV2Upg__factory.ts +39 -0
- package/typechain-types/factories/ISuperComposableYield__factory.ts +0 -5
- package/typechain-types/factories/OwnableUpgradeable__factory.ts +78 -0
- package/typechain-types/factories/PendleAaveV3SCY__factory.ts +1 -6
- package/typechain-types/factories/PendleBenQiErc20SCY__factory.ts +1 -6
- package/typechain-types/factories/PendleBtrflyScy__factory.ts +1 -6
- package/typechain-types/factories/PendleMarketFactory__factory.ts +1 -1
- package/typechain-types/factories/PendleMarket__factory.ts +9 -3
- package/typechain-types/factories/PendleRouterCoreUpg__factory.ts +26 -11
- package/typechain-types/factories/PendleRouterProxy__factory.ts +14 -67
- package/typechain-types/factories/PendleRouterStaticUpg__factory.ts +63 -17
- package/typechain-types/factories/PendleRouterYTUpg__factory.ts +66 -7
- package/typechain-types/factories/PendleYearnVaultScy__factory.ts +1 -6
- package/typechain-types/factories/PendleYieldContractFactory__factory.ts +39 -54
- package/typechain-types/factories/PendleYieldToken__factory.ts +53 -2
- package/typechain-types/factories/PermissionsV2Upg__factory.ts +39 -0
- package/typechain-types/factories/SCYBaseWithRewards__factory.ts +0 -5
- package/typechain-types/factories/SCYBase__factory.ts +0 -5
- package/typechain-types/hardhat.d.ts +26 -53
- package/typechain-types/index.ts +8 -14
- package/contracts/core/misc/BoringOwnable.sol +0 -62
- package/contracts/core/misc/BoringOwnableUpg.sol +0 -64
- package/contracts/libraries/math/FixedPoint.sol +0 -205
- 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
|
|
16
|
-
using
|
|
17
|
-
using
|
|
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
|
|
78
|
-
uint256
|
|
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
|
-
|
|
87
|
-
|
|
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
|
|
108
|
-
uint256
|
|
109
|
-
uint256
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
|
181
|
-
uint256
|
|
182
|
-
uint256
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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,
|
|
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(
|
|
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
|
-
|
|
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
|
|
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
|
|
8
|
-
using
|
|
9
|
-
using
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
12
|
-
using
|
|
13
|
-
using
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
|
13
|
-
using
|
|
14
|
-
using
|
|
15
|
-
using
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
131
|
-
uint256 netOtInGuessMax,
|
|
132
|
+
ApproxParams memory approx,
|
|
132
133
|
bool doPull
|
|
133
134
|
) internal returns (uint256 netOtIn) {
|
|
134
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
191
|
-
uint256 netOtOutGuessMin,
|
|
192
|
-
uint256 netOtOutGuessMax,
|
|
189
|
+
ApproxParams memory approx,
|
|
193
190
|
bool doPull
|
|
194
191
|
) internal returns (uint256 netOtOut) {
|
|
195
|
-
|
|
192
|
+
MarketState memory state = IPMarket(market).readState(false);
|
|
196
193
|
address SCY = IPMarket(market).SCY();
|
|
197
194
|
|
|
198
|
-
|
|
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
|
-
|
|
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 "
|
|
5
|
+
import "../../../periphery/PendleJoeSwapHelperUpg.sol";
|
|
6
6
|
import "../../../SuperComposableYield/ISuperComposableYield.sol";
|
|
7
7
|
import "../../../interfaces/IPYieldToken.sol";
|
|
8
8
|
|