@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
|
@@ -7,13 +7,15 @@ import "../../../interfaces/IPMarketAddRemoveCallback.sol";
|
|
|
7
7
|
import "../../../interfaces/IPMarketSwapCallback.sol";
|
|
8
8
|
import "../../../SuperComposableYield/SCYUtils.sol";
|
|
9
9
|
import "../../../libraries/math/MarketApproxLib.sol";
|
|
10
|
+
import "../../../libraries/math/MarketMathAux.sol";
|
|
10
11
|
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
|
11
12
|
|
|
12
13
|
abstract contract PendleRouterYTBaseUpg is IPMarketSwapCallback {
|
|
13
|
-
using
|
|
14
|
-
using
|
|
15
|
-
using
|
|
16
|
-
using
|
|
14
|
+
using Math for uint256;
|
|
15
|
+
using Math for int256;
|
|
16
|
+
using MarketMathCore for MarketState;
|
|
17
|
+
using MarketMathAux for MarketState;
|
|
18
|
+
using MarketApproxLib for MarketState;
|
|
17
19
|
using SafeERC20 for ISuperComposableYield;
|
|
18
20
|
using SafeERC20 for IPYieldToken;
|
|
19
21
|
|
|
@@ -21,7 +23,8 @@ abstract contract PendleRouterYTBaseUpg is IPMarketSwapCallback {
|
|
|
21
23
|
enum YT_SWAP_TYPE {
|
|
22
24
|
ExactYtForScy,
|
|
23
25
|
SCYForExactYt,
|
|
24
|
-
ExactScyForYt
|
|
26
|
+
ExactScyForYt,
|
|
27
|
+
YtForExactScy
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
address public immutable marketFactory;
|
|
@@ -42,40 +45,29 @@ abstract contract PendleRouterYTBaseUpg is IPMarketSwapCallback {
|
|
|
42
45
|
address receiver,
|
|
43
46
|
address market,
|
|
44
47
|
uint256 exactScyIn,
|
|
45
|
-
|
|
46
|
-
uint256 netYtOutGuessMin,
|
|
47
|
-
uint256 netYtOutGuessMax,
|
|
48
|
+
ApproxParams memory approx,
|
|
48
49
|
bool doPull
|
|
49
50
|
) internal returns (uint256 netYtOut) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
netYtOutGuessMin,
|
|
60
|
-
netYtOutGuessMax
|
|
61
|
-
);
|
|
62
|
-
require(netYtOut >= minYtOut, "insufficient out");
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (doPull) {
|
|
66
|
-
SCY.safeTransferFrom(msg.sender, address(YT), exactScyIn);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
51
|
+
(ISuperComposableYield SCY, , IPYieldToken YT) = IPMarket(market).readTokens();
|
|
52
|
+
MarketState memory state = IPMarket(market).readState(false);
|
|
53
|
+
|
|
54
|
+
(netYtOut, ) = state.approxSwapExactScyForYt(
|
|
55
|
+
SCYIndexLib.newIndex(SCY),
|
|
56
|
+
exactScyIn,
|
|
57
|
+
block.timestamp,
|
|
58
|
+
approx
|
|
59
|
+
);
|
|
69
60
|
|
|
70
|
-
{
|
|
71
|
-
|
|
72
|
-
IPMarket(market).swapExactOtForScy(
|
|
73
|
-
receiver,
|
|
74
|
-
exactOtIn,
|
|
75
|
-
1,
|
|
76
|
-
abi.encode(YT_SWAP_TYPE.ExactScyForYt, receiver)
|
|
77
|
-
);
|
|
61
|
+
if (doPull) {
|
|
62
|
+
SCY.safeTransferFrom(msg.sender, address(YT), exactScyIn);
|
|
78
63
|
}
|
|
64
|
+
|
|
65
|
+
IPMarket(market).swapExactOtForScy(
|
|
66
|
+
receiver,
|
|
67
|
+
netYtOut, // exactOtIn = netYtOut
|
|
68
|
+
1,
|
|
69
|
+
abi.encode(YT_SWAP_TYPE.ExactScyForYt, receiver)
|
|
70
|
+
);
|
|
79
71
|
}
|
|
80
72
|
|
|
81
73
|
/**
|
|
@@ -94,9 +86,6 @@ abstract contract PendleRouterYTBaseUpg is IPMarketSwapCallback {
|
|
|
94
86
|
) internal returns (uint256 netScyOut) {
|
|
95
87
|
(ISuperComposableYield SCY, , IPYieldToken YT) = IPMarket(market).readTokens();
|
|
96
88
|
|
|
97
|
-
// takes out the same amount of OT as exactYtIn, to pair together
|
|
98
|
-
uint256 exactOtOut = exactYtIn;
|
|
99
|
-
|
|
100
89
|
uint256 preBalanceScy = SCY.balanceOf(receiver);
|
|
101
90
|
|
|
102
91
|
if (doPull) {
|
|
@@ -105,7 +94,7 @@ abstract contract PendleRouterYTBaseUpg is IPMarketSwapCallback {
|
|
|
105
94
|
|
|
106
95
|
IPMarket(market).swapScyForExactOt(
|
|
107
96
|
receiver,
|
|
108
|
-
exactOtOut
|
|
97
|
+
exactYtIn, // exactOtOut = exactYtIn
|
|
109
98
|
type(uint256).max,
|
|
110
99
|
abi.encode(YT_SWAP_TYPE.ExactYtForScy, receiver)
|
|
111
100
|
);
|
|
@@ -127,12 +116,11 @@ abstract contract PendleRouterYTBaseUpg is IPMarketSwapCallback {
|
|
|
127
116
|
) internal returns (uint256 netScyIn) {
|
|
128
117
|
(ISuperComposableYield SCY, , ) = IPMarket(market).readTokens();
|
|
129
118
|
|
|
130
|
-
uint256 exactOtIn = exactYtOut;
|
|
131
119
|
uint256 preBalanceScy = SCY.balanceOf(receiver);
|
|
132
120
|
|
|
133
121
|
IPMarket(market).swapExactOtForScy(
|
|
134
122
|
receiver,
|
|
135
|
-
exactOtIn
|
|
123
|
+
exactYtOut, // exactOtIn = exactYtOut
|
|
136
124
|
1,
|
|
137
125
|
abi.encode(YT_SWAP_TYPE.SCYForExactYt, msg.sender, receiver)
|
|
138
126
|
);
|
|
@@ -142,6 +130,35 @@ abstract contract PendleRouterYTBaseUpg is IPMarketSwapCallback {
|
|
|
142
130
|
require(netScyIn <= maxScyIn, "exceed out limit");
|
|
143
131
|
}
|
|
144
132
|
|
|
133
|
+
function _swapYtForExactScy(
|
|
134
|
+
address receiver,
|
|
135
|
+
address market,
|
|
136
|
+
uint256 exactScyOut,
|
|
137
|
+
ApproxParams memory approx,
|
|
138
|
+
bool doPull
|
|
139
|
+
) internal returns (uint256 netYtIn) {
|
|
140
|
+
MarketState memory state = IPMarket(market).readState(false);
|
|
141
|
+
(ISuperComposableYield SCY, , IPYieldToken YT) = IPMarket(market).readTokens();
|
|
142
|
+
|
|
143
|
+
(netYtIn, ) = state.approxSwapYtForExactScy(
|
|
144
|
+
SCYIndexLib.newIndex(SCY),
|
|
145
|
+
exactScyOut,
|
|
146
|
+
block.timestamp,
|
|
147
|
+
approx
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
if (doPull) {
|
|
151
|
+
YT.safeTransferFrom(msg.sender, address(YT), netYtIn);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
IPMarket(market).swapScyForExactOt(
|
|
155
|
+
address(YT),
|
|
156
|
+
netYtIn, // exactOtOut = netYtIn
|
|
157
|
+
type(uint256).max,
|
|
158
|
+
abi.encode(YT_SWAP_TYPE.YtForExactScy, receiver)
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
145
162
|
function swapCallback(
|
|
146
163
|
int256 otToAccount,
|
|
147
164
|
int256 scyToAccount,
|
|
@@ -152,9 +169,11 @@ abstract contract PendleRouterYTBaseUpg is IPMarketSwapCallback {
|
|
|
152
169
|
if (swapType == YT_SWAP_TYPE.ExactScyForYt) {
|
|
153
170
|
_swapExactScyForYt_callback(msg.sender, data);
|
|
154
171
|
} else if (swapType == YT_SWAP_TYPE.ExactYtForScy) {
|
|
155
|
-
|
|
172
|
+
_swapYtForScy_callback(msg.sender, scyToAccount, data);
|
|
156
173
|
} else if (swapType == YT_SWAP_TYPE.SCYForExactYt) {
|
|
157
174
|
_swapScyForExactYt_callback(msg.sender, otToAccount, scyToAccount, data);
|
|
175
|
+
} else if (swapType == YT_SWAP_TYPE.YtForExactScy) {
|
|
176
|
+
_swapYtForScy_callback(msg.sender, scyToAccount, data);
|
|
158
177
|
} else {
|
|
159
178
|
require(false, "unknown swapType");
|
|
160
179
|
}
|
|
@@ -191,7 +210,7 @@ abstract contract PendleRouterYTBaseUpg is IPMarketSwapCallback {
|
|
|
191
210
|
/**
|
|
192
211
|
@dev receive OT -> pair with YT to redeem SCY -> payback SCY
|
|
193
212
|
*/
|
|
194
|
-
function
|
|
213
|
+
function _swapYtForScy_callback(
|
|
195
214
|
address market,
|
|
196
215
|
int256 scyToAccount,
|
|
197
216
|
bytes calldata data
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
pragma solidity 0.8.9;
|
|
3
3
|
|
|
4
4
|
import "./IPBaseToken.sol";
|
|
5
|
-
import "
|
|
5
|
+
import "./IPOwnershipToken.sol";
|
|
6
|
+
import "./IPYieldToken.sol";
|
|
7
|
+
import "../libraries/math/MarketMathCore.sol";
|
|
6
8
|
|
|
7
9
|
interface IPMarket is IPBaseToken {
|
|
8
10
|
function addLiquidity(
|
|
@@ -38,7 +40,7 @@ interface IPMarket is IPBaseToken {
|
|
|
38
40
|
bytes calldata data
|
|
39
41
|
) external returns (uint256 netScyIn, uint256 netScyToReserve);
|
|
40
42
|
|
|
41
|
-
function readState() external view returns (
|
|
43
|
+
function readState(bool updateRateOracle) external view returns (MarketState memory market);
|
|
42
44
|
|
|
43
45
|
function OT() external view returns (address);
|
|
44
46
|
|
|
@@ -11,9 +11,9 @@ interface IPRouterCore {
|
|
|
11
11
|
)
|
|
12
12
|
external
|
|
13
13
|
returns (
|
|
14
|
-
uint256
|
|
15
|
-
uint256
|
|
16
|
-
uint256
|
|
14
|
+
uint256,
|
|
15
|
+
uint256,
|
|
16
|
+
uint256
|
|
17
17
|
);
|
|
18
18
|
|
|
19
19
|
function removeLiquidity(
|
|
@@ -22,39 +22,41 @@ interface IPRouterCore {
|
|
|
22
22
|
uint256 lpToRemove,
|
|
23
23
|
uint256 scyOutMin,
|
|
24
24
|
uint256 otOutMin
|
|
25
|
-
) external returns (uint256
|
|
25
|
+
) external returns (uint256, uint256);
|
|
26
26
|
|
|
27
27
|
function swapExactOtForScy(
|
|
28
28
|
address receiver,
|
|
29
29
|
address market,
|
|
30
30
|
uint256 exactOtIn,
|
|
31
31
|
uint256 minScyOut
|
|
32
|
-
) external returns (uint256
|
|
32
|
+
) external returns (uint256);
|
|
33
33
|
|
|
34
34
|
function swapOtForExactScy(
|
|
35
35
|
address receiver,
|
|
36
36
|
address market,
|
|
37
|
-
uint256 maxOtIn,
|
|
38
37
|
uint256 exactScyOut,
|
|
39
|
-
uint256
|
|
40
|
-
uint256
|
|
41
|
-
|
|
38
|
+
uint256 otInGuessMin,
|
|
39
|
+
uint256 otInGuessMax,
|
|
40
|
+
uint256 maxIteration,
|
|
41
|
+
uint256 eps
|
|
42
|
+
) external returns (uint256);
|
|
42
43
|
|
|
43
44
|
function swapScyForExactOt(
|
|
44
45
|
address receiver,
|
|
45
46
|
address market,
|
|
46
47
|
uint256 exactOtOut,
|
|
47
48
|
uint256 maxScyIn
|
|
48
|
-
) external returns (uint256
|
|
49
|
+
) external returns (uint256);
|
|
49
50
|
|
|
50
51
|
function swapExactScyForOt(
|
|
51
52
|
address receiver,
|
|
52
53
|
address market,
|
|
53
54
|
uint256 exactScyIn,
|
|
54
|
-
uint256
|
|
55
|
-
uint256
|
|
56
|
-
uint256
|
|
57
|
-
|
|
55
|
+
uint256 otOutguessMin,
|
|
56
|
+
uint256 otOutguessMax,
|
|
57
|
+
uint256 maxIteration,
|
|
58
|
+
uint256 eps
|
|
59
|
+
) external returns (uint256);
|
|
58
60
|
|
|
59
61
|
function mintScyFromRawToken(
|
|
60
62
|
uint256 netRawTokenIn,
|
|
@@ -62,7 +64,7 @@ interface IPRouterCore {
|
|
|
62
64
|
uint256 minScyOut,
|
|
63
65
|
address receiver,
|
|
64
66
|
address[] calldata path
|
|
65
|
-
) external returns (uint256
|
|
67
|
+
) external returns (uint256);
|
|
66
68
|
|
|
67
69
|
function redeemScyToRawToken(
|
|
68
70
|
address SCY,
|
|
@@ -70,7 +72,7 @@ interface IPRouterCore {
|
|
|
70
72
|
uint256 minRawTokenOut,
|
|
71
73
|
address receiver,
|
|
72
74
|
address[] memory path
|
|
73
|
-
) external returns (uint256
|
|
75
|
+
) external returns (uint256);
|
|
74
76
|
|
|
75
77
|
function mintYoFromRawToken(
|
|
76
78
|
uint256 netRawTokenIn,
|
|
@@ -78,7 +80,7 @@ interface IPRouterCore {
|
|
|
78
80
|
uint256 minYoOut,
|
|
79
81
|
address receiver,
|
|
80
82
|
address[] calldata path
|
|
81
|
-
) external returns (uint256
|
|
83
|
+
) external returns (uint256);
|
|
82
84
|
|
|
83
85
|
function redeemYoToRawToken(
|
|
84
86
|
address YT,
|
|
@@ -86,16 +88,17 @@ interface IPRouterCore {
|
|
|
86
88
|
uint256 minRawTokenOut,
|
|
87
89
|
address receiver,
|
|
88
90
|
address[] memory path
|
|
89
|
-
) external returns (uint256
|
|
91
|
+
) external returns (uint256);
|
|
90
92
|
|
|
91
93
|
function swapExactRawTokenForOt(
|
|
92
94
|
uint256 exactRawTokenIn,
|
|
93
95
|
address receiver,
|
|
94
96
|
address[] calldata path,
|
|
95
97
|
address market,
|
|
96
|
-
uint256
|
|
97
|
-
uint256
|
|
98
|
-
uint256
|
|
98
|
+
uint256 otOutguessMin,
|
|
99
|
+
uint256 otOutguessMax,
|
|
100
|
+
uint256 maxIteration,
|
|
101
|
+
uint256 eps
|
|
99
102
|
) external returns (uint256 netOtOut);
|
|
100
103
|
|
|
101
104
|
function swapExactOtForRawToken(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
2
|
pragma solidity 0.8.9;
|
|
3
3
|
|
|
4
|
-
import "../libraries/math/
|
|
4
|
+
import "../libraries/math/MarketMathCore.sol";
|
|
5
5
|
|
|
6
6
|
interface IPRouterStatic {
|
|
7
7
|
function addLiquidityStatic(
|
|
@@ -32,4 +32,13 @@ interface IPRouterStatic {
|
|
|
32
32
|
function scyIndex(address market) external returns (SCYIndex index);
|
|
33
33
|
|
|
34
34
|
function getOtImpliedYield(address market) external view returns (int256);
|
|
35
|
+
|
|
36
|
+
function getPendleTokenType(address token)
|
|
37
|
+
external
|
|
38
|
+
view
|
|
39
|
+
returns (
|
|
40
|
+
bool isOT,
|
|
41
|
+
bool isYT,
|
|
42
|
+
bool isMarket
|
|
43
|
+
);
|
|
35
44
|
}
|
|
@@ -22,19 +22,31 @@ interface IPRouterYT is IPMarketSwapCallback {
|
|
|
22
22
|
address receiver,
|
|
23
23
|
address market,
|
|
24
24
|
uint256 exactScyIn,
|
|
25
|
-
uint256 minYtOut,
|
|
26
25
|
uint256 netYtOutGuessMin,
|
|
27
|
-
uint256 netYtOutGuessMax
|
|
26
|
+
uint256 netYtOutGuessMax,
|
|
27
|
+
uint256 maxIteration,
|
|
28
|
+
uint256 eps
|
|
28
29
|
) external returns (uint256 netYtOut);
|
|
29
30
|
|
|
31
|
+
function swapYtForExactScy(
|
|
32
|
+
address receiver,
|
|
33
|
+
address market,
|
|
34
|
+
uint256 exactScyOut,
|
|
35
|
+
uint256 netYtInGuessMin,
|
|
36
|
+
uint256 netYtInGuessMax,
|
|
37
|
+
uint256 maxIteration,
|
|
38
|
+
uint256 eps
|
|
39
|
+
) external returns (uint256 netYtIn);
|
|
40
|
+
|
|
30
41
|
function swapExactRawTokenForYt(
|
|
31
42
|
uint256 exactRawTokenIn,
|
|
32
43
|
address receiver,
|
|
33
44
|
address[] calldata path,
|
|
34
45
|
address market,
|
|
35
|
-
uint256 minYtOut,
|
|
36
46
|
uint256 netYtOutGuessMin,
|
|
37
|
-
uint256 netYtOutGuessMax
|
|
47
|
+
uint256 netYtOutGuessMax,
|
|
48
|
+
uint256 maxIteration,
|
|
49
|
+
uint256 eps
|
|
38
50
|
) external returns (uint256 netYtOut);
|
|
39
51
|
|
|
40
52
|
function swapExactYtForRawToken(
|
|
@@ -33,4 +33,8 @@ interface IPYieldContractFactory {
|
|
|
33
33
|
function interestFeeRate() external view returns (uint256);
|
|
34
34
|
|
|
35
35
|
function treasury() external view returns (address);
|
|
36
|
+
|
|
37
|
+
function isOT(address) external view returns (bool);
|
|
38
|
+
|
|
39
|
+
function isYT(address) external view returns (bool);
|
|
36
40
|
}
|
|
@@ -7,11 +7,9 @@ interface IPYieldToken is IPBaseToken {
|
|
|
7
7
|
|
|
8
8
|
function redeemYO(address receiver) external returns (uint256 amountScyOut);
|
|
9
9
|
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
function redeemDueRewards(address user, address receiver)
|
|
10
|
+
function redeemDueInterestAndRewards(address user)
|
|
13
11
|
external
|
|
14
|
-
returns (uint256[] memory rewardsOut);
|
|
12
|
+
returns (uint256 interestOut, uint256[] memory rewardsOut);
|
|
15
13
|
|
|
16
14
|
function SCY() external view returns (address);
|
|
17
15
|
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
pragma solidity 0.8.9;
|
|
3
3
|
import "../SuperComposableYield/ISuperComposableYield.sol";
|
|
4
4
|
import "../SuperComposableYield/SCYUtils.sol";
|
|
5
|
-
import "./math/
|
|
5
|
+
import "./math/Math.sol";
|
|
6
6
|
|
|
7
7
|
type SCYIndex is uint256;
|
|
8
8
|
|
|
9
9
|
library SCYIndexLib {
|
|
10
|
-
using
|
|
11
|
-
using
|
|
10
|
+
using Math for uint256;
|
|
11
|
+
using Math for int256;
|
|
12
12
|
|
|
13
13
|
function newIndex(ISuperComposableYield SCY) internal returns (SCYIndex) {
|
|
14
14
|
return SCYIndex.wrap(SCY.scyIndexCurrent());
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
13
13
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
14
14
|
|
|
15
|
-
pragma solidity 0.8.
|
|
15
|
+
pragma solidity ^0.8.0;
|
|
16
16
|
|
|
17
17
|
/* solhint-disable */
|
|
18
18
|
|
|
@@ -53,8 +53,6 @@ library LogExpMath {
|
|
|
53
53
|
int256 constant LN_36_LOWER_BOUND = ONE_18 - 1e17;
|
|
54
54
|
int256 constant LN_36_UPPER_BOUND = ONE_18 + 1e17;
|
|
55
55
|
|
|
56
|
-
uint256 constant MILD_EXPONENT_BOUND = 2**254 / uint256(ONE_20);
|
|
57
|
-
|
|
58
56
|
// 18 decimal constants
|
|
59
57
|
int256 constant x0 = 128000000000000000000; // 2ˆ7
|
|
60
58
|
int256 constant a0 = 38877084059945950922200000000000000000000000000000000000; // eˆ(x0) (no decimals)
|
|
@@ -83,64 +81,6 @@ library LogExpMath {
|
|
|
83
81
|
int256 constant x11 = 6250000000000000000; // 2ˆ-4
|
|
84
82
|
int256 constant a11 = 106449445891785942956; // eˆ(x11)
|
|
85
83
|
|
|
86
|
-
/**
|
|
87
|
-
* @dev Exponentiation (x^y) with unsigned 18 decimal fixed point base and exponent.
|
|
88
|
-
*
|
|
89
|
-
* Reverts if ln(x) * y is smaller than `MIN_NATURAL_EXPONENT`, or larger than `MAX_NATURAL_EXPONENT`.
|
|
90
|
-
*/
|
|
91
|
-
function pow(uint256 x, uint256 y) internal pure returns (uint256) {
|
|
92
|
-
unchecked {
|
|
93
|
-
if (y == 0) {
|
|
94
|
-
// We solve the 0^0 indetermination by making it equal one.
|
|
95
|
-
return uint256(ONE_18);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (x == 0) {
|
|
99
|
-
return 0;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Instead of computing x^y directly, we instead rely on the properties of logarithms and exponentiation to
|
|
103
|
-
// arrive at that result. In particular, exp(ln(x)) = x, and ln(x^y) = y * ln(x). This means
|
|
104
|
-
// x^y = exp(y * ln(x)).
|
|
105
|
-
|
|
106
|
-
// The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range.
|
|
107
|
-
require(x < 2**255, "X out of bounds");
|
|
108
|
-
int256 x_int256 = int256(x);
|
|
109
|
-
|
|
110
|
-
// We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In
|
|
111
|
-
// both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end.
|
|
112
|
-
|
|
113
|
-
// This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range.
|
|
114
|
-
require(y < MILD_EXPONENT_BOUND, "Y out of bounds");
|
|
115
|
-
int256 y_int256 = int256(y);
|
|
116
|
-
|
|
117
|
-
int256 logx_times_y;
|
|
118
|
-
if (LN_36_LOWER_BOUND < x_int256 && x_int256 < LN_36_UPPER_BOUND) {
|
|
119
|
-
int256 ln_36_x = _ln_36(x_int256);
|
|
120
|
-
|
|
121
|
-
// ln_36_x has 36 decimal places, so multiplying by y_int256 isn't as straightforward, since we can't just
|
|
122
|
-
// bring y_int256 to 36 decimal places, as it might overflow. Instead, we perform two 18 decimal
|
|
123
|
-
// multiplications and add the results: one with the first 18 decimals of ln_36_x, and one with the
|
|
124
|
-
// (downscaled) last 18 decimals.
|
|
125
|
-
logx_times_y = ((ln_36_x / ONE_18) *
|
|
126
|
-
y_int256 +
|
|
127
|
-
((ln_36_x % ONE_18) * y_int256) /
|
|
128
|
-
ONE_18);
|
|
129
|
-
} else {
|
|
130
|
-
logx_times_y = _ln(x_int256) * y_int256;
|
|
131
|
-
}
|
|
132
|
-
logx_times_y /= ONE_18;
|
|
133
|
-
|
|
134
|
-
// Finally, we compute exp(y * ln(x)) to arrive at x^y
|
|
135
|
-
require(
|
|
136
|
-
MIN_NATURAL_EXPONENT <= logx_times_y && logx_times_y <= MAX_NATURAL_EXPONENT,
|
|
137
|
-
"Product out of bounds"
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
return uint256(exp(logx_times_y));
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
84
|
/**
|
|
145
85
|
* @dev Natural exponentiation (e^x) with signed 18 decimal fixed point exponent.
|
|
146
86
|
*
|
|
@@ -285,35 +225,6 @@ library LogExpMath {
|
|
|
285
225
|
}
|
|
286
226
|
}
|
|
287
227
|
|
|
288
|
-
/**
|
|
289
|
-
* @dev Logarithm (log(arg, base), with signed 18 decimal fixed point base and argument.
|
|
290
|
-
*/
|
|
291
|
-
function log(int256 arg, int256 base) internal pure returns (int256) {
|
|
292
|
-
unchecked {
|
|
293
|
-
// This performs a simple base change: log(arg, base) = ln(arg) / ln(base).
|
|
294
|
-
|
|
295
|
-
// Both logBase and logArg are computed as 36 decimal fixed point numbers, either by using ln_36, or by
|
|
296
|
-
// upscaling.
|
|
297
|
-
|
|
298
|
-
int256 logBase;
|
|
299
|
-
if (LN_36_LOWER_BOUND < base && base < LN_36_UPPER_BOUND) {
|
|
300
|
-
logBase = _ln_36(base);
|
|
301
|
-
} else {
|
|
302
|
-
logBase = _ln(base) * ONE_18;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
int256 logArg;
|
|
306
|
-
if (LN_36_LOWER_BOUND < arg && arg < LN_36_UPPER_BOUND) {
|
|
307
|
-
logArg = _ln_36(arg);
|
|
308
|
-
} else {
|
|
309
|
-
logArg = _ln(arg) * ONE_18;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// When dividing, we multiply by ONE_18 to arrive at a result with 18 decimal places
|
|
313
|
-
return (logArg * ONE_18) / logBase;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
228
|
/**
|
|
318
229
|
* @dev Natural logarithm (ln(a)) with signed 18 decimal fixed point argument.
|
|
319
230
|
*/
|