@pendle/core-v2 0.8.0-beta → 0.8.0-beta-2
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/SCY-implementations/PendleYearnVaultScy.sol +8 -4
- package/contracts/SuperComposableYield/base-implementations/SCYBase.sol +1 -1
- package/contracts/core/Market/PendleMarket.sol +2 -2
- package/contracts/core/YieldContracts/PendleYieldToken.sol +26 -0
- package/contracts/core/actions/ActionCallback.sol +1 -3
- package/contracts/core/actions/base/ActionSCYAndPTBase.sol +2 -2
- package/contracts/core/actions/base/ActionSCYAndYTBase.sol +4 -1
- package/contracts/interfaces/IPRouterStatic.sol +7 -2
- package/contracts/interfaces/IYearnVault.sol +5 -1
- package/contracts/libraries/SCY/SCYIndex.sol +8 -1
- package/contracts/libraries/SCY/SCYUtils.sol +16 -0
- package/contracts/libraries/math/MarketMathCore.sol +21 -25
- package/contracts/libraries/math/Math.sol +0 -5
- package/contracts/offchain-helpers/RouterStatic.sol +137 -5
- package/deployments/43113-core.json +10 -10
- package/deployments/43113-markets/benqi-market-0x9f080Af83E84099ED92b1b9b4B4BbE4400f2A3CB.json +7 -0
- package/deployments/80001-core.json +9 -9
- package/deployments/80001-markets/benqi-market-0x78699fa58C484e9867B8047A12E959ccB8BaD90E.json +7 -0
- package/package.json +1 -1
- package/deployments/43113-markets/benqi-market-0xF3150c14F776c50C9D397054d38979c7B77FC41D.json +0 -7
- package/deployments/80001-markets/benqi-market-0x150b6eb90Bf636eC0c4328d13d1e1d4adDBAF904.json +0 -7
|
@@ -65,14 +65,18 @@ contract PendleYearnVaultSCY is SCYBase {
|
|
|
65
65
|
amountTokenOut = amountSharesToRedeem;
|
|
66
66
|
} else {
|
|
67
67
|
// tokenOut == underlying
|
|
68
|
-
uint256
|
|
68
|
+
uint256 preBalanceYvToken = _selfBalance(yvToken);
|
|
69
|
+
|
|
70
|
+
amountTokenOut = IYearnVault(yvToken).withdraw(
|
|
71
|
+
amountSharesToRedeem,
|
|
72
|
+
address(this),
|
|
73
|
+
10000
|
|
74
|
+
);
|
|
69
75
|
|
|
70
76
|
require(
|
|
71
|
-
|
|
77
|
+
preBalanceYvToken - _selfBalance(yvToken) == amountSharesToRedeem,
|
|
72
78
|
"Yearn Vault SCY: Not allowed to redeem all shares"
|
|
73
79
|
);
|
|
74
|
-
|
|
75
|
-
amountTokenOut = _selfBalance(underlying);
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
82
|
|
|
@@ -18,7 +18,7 @@ abstract contract SCYBase is ISuperComposableYield, PendleERC20, TokenHelper {
|
|
|
18
18
|
string memory _name,
|
|
19
19
|
string memory _symbol,
|
|
20
20
|
address _yieldToken
|
|
21
|
-
) PendleERC20(_name, _symbol,
|
|
21
|
+
) PendleERC20(_name, _symbol, IERC20Metadata(_yieldToken).decimals()) {
|
|
22
22
|
yieldToken = _yieldToken;
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -103,7 +103,7 @@ contract PendleMarket is PendleERC20, PendleGauge, IPMarket {
|
|
|
103
103
|
index,
|
|
104
104
|
scyDesired,
|
|
105
105
|
ptDesired,
|
|
106
|
-
|
|
106
|
+
block.timestamp
|
|
107
107
|
);
|
|
108
108
|
|
|
109
109
|
// initializing the market
|
|
@@ -133,7 +133,7 @@ contract PendleMarket is PendleERC20, PendleGauge, IPMarket {
|
|
|
133
133
|
uint256 lpToRemove = balanceOf(address(this));
|
|
134
134
|
_burn(address(this), lpToRemove);
|
|
135
135
|
|
|
136
|
-
(scyToAccount, ptToAccount) = market.removeLiquidity(lpToRemove
|
|
136
|
+
(scyToAccount, ptToAccount) = market.removeLiquidity(lpToRemove);
|
|
137
137
|
|
|
138
138
|
IERC20(SCY).safeTransfer(receiverScy, scyToAccount);
|
|
139
139
|
IERC20(PT).safeTransfer(receiverPt, ptToAccount);
|
|
@@ -197,6 +197,31 @@ contract PendleYieldToken is
|
|
|
197
197
|
return MiniHelpers.isCurrentlyExpired(expiry);
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
+
function getPostExpiryData()
|
|
201
|
+
external
|
|
202
|
+
view
|
|
203
|
+
returns (
|
|
204
|
+
uint256 firstScyIndex,
|
|
205
|
+
uint256 totalScyInterestForTreasury,
|
|
206
|
+
uint256[] memory firstRewardIndexes,
|
|
207
|
+
uint256[] memory userRewardOwed
|
|
208
|
+
)
|
|
209
|
+
{
|
|
210
|
+
require(postExpiry.firstScyIndex != 0, "PostExpiry data not set");
|
|
211
|
+
|
|
212
|
+
firstScyIndex = postExpiry.firstScyIndex;
|
|
213
|
+
totalScyInterestForTreasury = postExpiry.totalScyInterestForTreasury;
|
|
214
|
+
|
|
215
|
+
address[] memory tokens = getRewardTokens();
|
|
216
|
+
firstRewardIndexes = new uint256[](tokens.length);
|
|
217
|
+
userRewardOwed = new uint256[](tokens.length);
|
|
218
|
+
|
|
219
|
+
for (uint256 i = 0; i < tokens.length; ++i) {
|
|
220
|
+
firstRewardIndexes[i] = postExpiry.firstRewardIndex[tokens[i]];
|
|
221
|
+
userRewardOwed[i] = postExpiry.userRewardOwed[tokens[i]];
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
200
225
|
function _redeemPY(address[] memory receivers, uint256[] memory amountPYToRedeems)
|
|
201
226
|
internal
|
|
202
227
|
returns (uint256[] memory amountScyOuts)
|
|
@@ -370,6 +395,7 @@ contract PendleYieldToken is
|
|
|
370
395
|
address to,
|
|
371
396
|
uint256
|
|
372
397
|
) internal override {
|
|
398
|
+
_setPostExpiryData();
|
|
373
399
|
_updateAndDistributeRewardsForTwo(from, to);
|
|
374
400
|
_distributeInterestForTwo(from, to);
|
|
375
401
|
}
|
|
@@ -92,9 +92,7 @@ contract ActionCallback is IPMarketSwapCallback, CallbackHelper {
|
|
|
92
92
|
/// ------------------------------------------------------------
|
|
93
93
|
SCYIndex scyIndex = SCY.newIndex();
|
|
94
94
|
uint256 ptOwed = ptToAccount.abs();
|
|
95
|
-
uint256 totalScyNeed = scyIndex.
|
|
96
|
-
// to guard against precision issue of lacking a few units of SCY. rawDivUp is not Fixed-Point division
|
|
97
|
-
totalScyNeed += SCYIndex.unwrap(scyIndex).rawDivUp(SCYUtils.ONE);
|
|
95
|
+
uint256 totalScyNeed = scyIndex.assetToScyUp(ptOwed);
|
|
98
96
|
|
|
99
97
|
/// ------------------------------------------------------------
|
|
100
98
|
/// calc netScyToPull
|
|
@@ -45,7 +45,7 @@ abstract contract ActionSCYAndPTBase is ActionSCYAndPYBase {
|
|
|
45
45
|
SCY.newIndex(),
|
|
46
46
|
scyDesired,
|
|
47
47
|
ptDesired,
|
|
48
|
-
|
|
48
|
+
block.timestamp
|
|
49
49
|
);
|
|
50
50
|
|
|
51
51
|
// early-check
|
|
@@ -72,7 +72,7 @@ abstract contract ActionSCYAndPTBase is ActionSCYAndPYBase {
|
|
|
72
72
|
) internal returns (uint256 netScyOut, uint256 netPtOut) {
|
|
73
73
|
MarketState memory state = IPMarket(market).readState(false);
|
|
74
74
|
|
|
75
|
-
(netScyOut, netPtOut) = state.removeLiquidity(lpToRemove
|
|
75
|
+
(netScyOut, netPtOut) = state.removeLiquidity(lpToRemove);
|
|
76
76
|
|
|
77
77
|
// early-check
|
|
78
78
|
require(netScyOut >= scyOutMin, "insufficient SCY out");
|
|
@@ -109,13 +109,16 @@ abstract contract ActionSCYAndYTBase is ActionSCYAndPYBase, CallbackHelper {
|
|
|
109
109
|
uint256 exactYtOut,
|
|
110
110
|
uint256 maxScyIn
|
|
111
111
|
) internal returns (uint256 netScyIn) {
|
|
112
|
-
(, , IPYieldToken YT) = IPMarket(market).readTokens();
|
|
112
|
+
(ISuperComposableYield SCY, , IPYieldToken YT) = IPMarket(market).readTokens();
|
|
113
|
+
|
|
114
|
+
uint256 preScyBalance = SCY.balanceOf(msg.sender);
|
|
113
115
|
|
|
114
116
|
IPMarket(market).swapExactPtForScy(
|
|
115
117
|
address(YT),
|
|
116
118
|
exactYtOut, // exactPtIn = exactYtOut
|
|
117
119
|
_encodeSwapScyForExactYt(msg.sender, receiver, maxScyIn)
|
|
118
120
|
);
|
|
121
|
+
netScyIn = preScyBalance - SCY.balanceOf(msg.sender);
|
|
119
122
|
}
|
|
120
123
|
|
|
121
124
|
/**
|
|
@@ -104,16 +104,21 @@ interface IPRouterStatic {
|
|
|
104
104
|
view
|
|
105
105
|
returns (uint256 netScyOut, uint256 netPtOut);
|
|
106
106
|
|
|
107
|
-
function
|
|
107
|
+
function swapExactPtForScyStatic(address market, uint256 exactPtIn)
|
|
108
108
|
external
|
|
109
109
|
view
|
|
110
110
|
returns (uint256 netScyOut, uint256 netScyFee);
|
|
111
111
|
|
|
112
|
-
function
|
|
112
|
+
function swapScyForExactPtStatic(address market, uint256 exactPtOut)
|
|
113
113
|
external
|
|
114
114
|
view
|
|
115
115
|
returns (uint256 netScyIn, uint256 netScyFee);
|
|
116
116
|
|
|
117
|
+
function swapExactScyForPtStatic(address market, uint256 exactScyIn)
|
|
118
|
+
external
|
|
119
|
+
view
|
|
120
|
+
returns (uint256 netPtOut, uint256 netScyFee);
|
|
121
|
+
|
|
117
122
|
// ============= OTHER HELPERS =============
|
|
118
123
|
|
|
119
124
|
function scyIndex(address market) external view returns (SCYIndex index);
|
|
@@ -28,7 +28,11 @@ interface IYearnVault {
|
|
|
28
28
|
|
|
29
29
|
function deposit(uint256 amount, address recipient) external returns (uint256);
|
|
30
30
|
|
|
31
|
-
function withdraw(
|
|
31
|
+
function withdraw(
|
|
32
|
+
uint256 maxShares,
|
|
33
|
+
address recipient,
|
|
34
|
+
uint256 maxLoss
|
|
35
|
+
) external returns (uint256 amountTokenRedeemed);
|
|
32
36
|
|
|
33
37
|
function pricePerShare() external view returns (uint256);
|
|
34
38
|
|
|
@@ -34,6 +34,13 @@ library SCYIndexLib {
|
|
|
34
34
|
return SCYUtils.assetToScy(SCYIndex.unwrap(index), assetAmount);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
function assetToScyUp(SCYIndex index, uint256 assetAmount)
|
|
38
|
+
internal
|
|
39
|
+
pure
|
|
40
|
+
returns (uint256)
|
|
41
|
+
{
|
|
42
|
+
return SCYUtils.assetToScyUp(SCYIndex.unwrap(index), assetAmount);
|
|
43
|
+
}
|
|
37
44
|
|
|
38
45
|
function scyToAssetUp(SCYIndex index, uint256 scyAmount)
|
|
39
46
|
internal
|
|
@@ -41,7 +48,7 @@ library SCYIndexLib {
|
|
|
41
48
|
returns (uint256)
|
|
42
49
|
{
|
|
43
50
|
uint256 _index = SCYIndex.unwrap(index);
|
|
44
|
-
return SCYUtils.
|
|
51
|
+
return SCYUtils.scyToAssetUp(_index, scyAmount);
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
function scyToAsset(SCYIndex index, int256 scyAmount)
|
|
@@ -8,6 +8,14 @@ library SCYUtils {
|
|
|
8
8
|
return (scyAmount * exchangeRate) / ONE;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
function scyToAssetUp(uint256 exchangeRate, uint256 scyAmount)
|
|
12
|
+
internal
|
|
13
|
+
pure
|
|
14
|
+
returns (uint256)
|
|
15
|
+
{
|
|
16
|
+
return (scyAmount * exchangeRate + ONE - 1) / ONE;
|
|
17
|
+
}
|
|
18
|
+
|
|
11
19
|
function assetToScy(uint256 exchangeRate, uint256 assetAmount)
|
|
12
20
|
internal
|
|
13
21
|
pure
|
|
@@ -15,4 +23,12 @@ library SCYUtils {
|
|
|
15
23
|
{
|
|
16
24
|
return (assetAmount * ONE) / exchangeRate;
|
|
17
25
|
}
|
|
26
|
+
|
|
27
|
+
function assetToScyUp(uint256 exchangeRate, uint256 assetAmount)
|
|
28
|
+
internal
|
|
29
|
+
pure
|
|
30
|
+
returns (uint256)
|
|
31
|
+
{
|
|
32
|
+
return (assetAmount * ONE + exchangeRate - 1) / exchangeRate;
|
|
33
|
+
}
|
|
18
34
|
}
|
|
@@ -57,7 +57,7 @@ library MarketMathCore {
|
|
|
57
57
|
SCYIndex index,
|
|
58
58
|
uint256 scyDesired,
|
|
59
59
|
uint256 ptDesired,
|
|
60
|
-
|
|
60
|
+
uint256 blockTime
|
|
61
61
|
)
|
|
62
62
|
internal
|
|
63
63
|
pure
|
|
@@ -73,7 +73,7 @@ library MarketMathCore {
|
|
|
73
73
|
int256 _lpToAccount,
|
|
74
74
|
int256 _scyUsed,
|
|
75
75
|
int256 _otUsed
|
|
76
|
-
) = addLiquidityCore(market, index, scyDesired.Int(), ptDesired.Int(),
|
|
76
|
+
) = addLiquidityCore(market, index, scyDesired.Int(), ptDesired.Int(), blockTime);
|
|
77
77
|
|
|
78
78
|
lpToReserve = _lpToReserve.Uint();
|
|
79
79
|
lpToAccount = _lpToAccount.Uint();
|
|
@@ -81,15 +81,14 @@ library MarketMathCore {
|
|
|
81
81
|
ptUsed = _otUsed.Uint();
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
function removeLiquidity(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
function removeLiquidity(MarketState memory market, uint256 lpToRemove)
|
|
85
|
+
internal
|
|
86
|
+
pure
|
|
87
|
+
returns (uint256 scyToAccount, uint256 netPtToAccount)
|
|
88
|
+
{
|
|
89
89
|
(int256 _scyToAccount, int256 _ptToAccount) = removeLiquidityCore(
|
|
90
90
|
market,
|
|
91
|
-
lpToRemove.Int()
|
|
92
|
-
updateState
|
|
91
|
+
lpToRemove.Int()
|
|
93
92
|
);
|
|
94
93
|
|
|
95
94
|
scyToAccount = _scyToAccount.Uint();
|
|
@@ -139,7 +138,7 @@ library MarketMathCore {
|
|
|
139
138
|
SCYIndex index,
|
|
140
139
|
int256 scyDesired,
|
|
141
140
|
int256 ptDesired,
|
|
142
|
-
|
|
141
|
+
uint256 blockTime
|
|
143
142
|
)
|
|
144
143
|
internal
|
|
145
144
|
pure
|
|
@@ -154,6 +153,7 @@ library MarketMathCore {
|
|
|
154
153
|
/// CHECKS
|
|
155
154
|
/// ------------------------------------------------------------
|
|
156
155
|
require(scyDesired > 0 && ptDesired > 0, "ZERO_AMOUNTS");
|
|
156
|
+
require(!MiniHelpers.isExpired(market.expiry, blockTime), "market expired");
|
|
157
157
|
|
|
158
158
|
/// ------------------------------------------------------------
|
|
159
159
|
/// MATH
|
|
@@ -182,18 +182,16 @@ library MarketMathCore {
|
|
|
182
182
|
/// ------------------------------------------------------------
|
|
183
183
|
/// WRITE
|
|
184
184
|
/// ------------------------------------------------------------
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
market.totalLp += lpToAccount + lpToReserve;
|
|
189
|
-
}
|
|
185
|
+
market.totalScy += scyUsed;
|
|
186
|
+
market.totalPt += ptUsed;
|
|
187
|
+
market.totalLp += lpToAccount + lpToReserve;
|
|
190
188
|
}
|
|
191
189
|
|
|
192
|
-
function removeLiquidityCore(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
190
|
+
function removeLiquidityCore(MarketState memory market, int256 lpToRemove)
|
|
191
|
+
internal
|
|
192
|
+
pure
|
|
193
|
+
returns (int256 netScyToAccount, int256 netPtToAccount)
|
|
194
|
+
{
|
|
197
195
|
/// ------------------------------------------------------------
|
|
198
196
|
/// CHECKS
|
|
199
197
|
/// ------------------------------------------------------------
|
|
@@ -209,11 +207,9 @@ library MarketMathCore {
|
|
|
209
207
|
/// ------------------------------------------------------------
|
|
210
208
|
/// WRITE
|
|
211
209
|
/// ------------------------------------------------------------
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
market.totalScy = market.totalScy.subNoNeg(netScyToAccount);
|
|
216
|
-
}
|
|
210
|
+
market.totalLp = market.totalLp.subNoNeg(lpToRemove);
|
|
211
|
+
market.totalPt = market.totalPt.subNoNeg(netPtToAccount);
|
|
212
|
+
market.totalScy = market.totalScy.subNoNeg(netScyToAccount);
|
|
217
213
|
}
|
|
218
214
|
|
|
219
215
|
function executeTradeCore(
|
|
@@ -59,11 +59,6 @@ library Math {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
function rawDivUp(uint256 a, uint256 b) internal pure returns (uint256) {
|
|
63
|
-
require(b != 0, "divide by zero");
|
|
64
|
-
return (a + b - 1) / b;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
62
|
function abs(int256 x) internal pure returns (uint256) {
|
|
68
63
|
return uint256(x > 0 ? x : -x);
|
|
69
64
|
}
|
|
@@ -7,6 +7,7 @@ import "../interfaces/IPRouterStatic.sol";
|
|
|
7
7
|
import "../interfaces/IPMarket.sol";
|
|
8
8
|
import "../interfaces/IPYieldContractFactory.sol";
|
|
9
9
|
import "../interfaces/IPMarketFactory.sol";
|
|
10
|
+
import "../libraries/math/MarketApproxLib.sol";
|
|
10
11
|
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
|
11
12
|
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
|
|
12
13
|
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
|
@@ -14,12 +15,22 @@ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
|
|
14
15
|
/// EXCLUDED FROM ALL AUDITS, TO BE CALLED ONLY BY PENDLE's SDK
|
|
15
16
|
contract RouterStatic is IPRouterStatic, Initializable, UUPSUpgradeable, OwnableUpgradeable {
|
|
16
17
|
using MarketMathCore for MarketState;
|
|
18
|
+
using MarketApproxLib for MarketState;
|
|
17
19
|
using Math for uint256;
|
|
18
20
|
using Math for int256;
|
|
19
21
|
using LogExpMath for int256;
|
|
22
|
+
using SCYIndexLib for SCYIndex;
|
|
20
23
|
|
|
21
24
|
IPYieldContractFactory public immutable yieldContractFactory;
|
|
22
25
|
IPMarketFactory public immutable marketFactory;
|
|
26
|
+
ApproxParams public approxParams =
|
|
27
|
+
ApproxParams({
|
|
28
|
+
guessMin: 0,
|
|
29
|
+
guessMax: type(uint256).max,
|
|
30
|
+
guessOffchain: 0,
|
|
31
|
+
maxIteration: 256,
|
|
32
|
+
eps: 1e15
|
|
33
|
+
});
|
|
23
34
|
|
|
24
35
|
constructor(IPYieldContractFactory _yieldContractFactory, IPMarketFactory _marketFactory)
|
|
25
36
|
initializer
|
|
@@ -151,7 +162,7 @@ contract RouterStatic is IPRouterStatic, Initializable, UUPSUpgradeable, Ownable
|
|
|
151
162
|
scyIndex(market),
|
|
152
163
|
scyDesired,
|
|
153
164
|
ptDesired,
|
|
154
|
-
|
|
165
|
+
block.timestamp
|
|
155
166
|
);
|
|
156
167
|
}
|
|
157
168
|
|
|
@@ -161,10 +172,10 @@ contract RouterStatic is IPRouterStatic, Initializable, UUPSUpgradeable, Ownable
|
|
|
161
172
|
returns (uint256 netScyOut, uint256 netPtOut)
|
|
162
173
|
{
|
|
163
174
|
MarketState memory state = IPMarket(market).readState(false);
|
|
164
|
-
(netScyOut, netPtOut) = state.removeLiquidity(lpToRemove
|
|
175
|
+
(netScyOut, netPtOut) = state.removeLiquidity(lpToRemove);
|
|
165
176
|
}
|
|
166
177
|
|
|
167
|
-
function
|
|
178
|
+
function swapExactPtForScyStatic(address market, uint256 exactPtIn)
|
|
168
179
|
external
|
|
169
180
|
view
|
|
170
181
|
returns (uint256 netScyOut, uint256 netScyFee)
|
|
@@ -177,7 +188,7 @@ contract RouterStatic is IPRouterStatic, Initializable, UUPSUpgradeable, Ownable
|
|
|
177
188
|
);
|
|
178
189
|
}
|
|
179
190
|
|
|
180
|
-
function
|
|
191
|
+
function swapScyForExactPtStatic(address market, uint256 exactPtOut)
|
|
181
192
|
external
|
|
182
193
|
view
|
|
183
194
|
returns (uint256 netScyIn, uint256 netScyFee)
|
|
@@ -190,8 +201,110 @@ contract RouterStatic is IPRouterStatic, Initializable, UUPSUpgradeable, Ownable
|
|
|
190
201
|
);
|
|
191
202
|
}
|
|
192
203
|
|
|
204
|
+
function swapExactScyForPtStatic(address market, uint256 exactScyIn)
|
|
205
|
+
external
|
|
206
|
+
view
|
|
207
|
+
returns (uint256 netPtOut, uint256 netScyFee)
|
|
208
|
+
{
|
|
209
|
+
MarketState memory state = IPMarket(market).readState(false);
|
|
210
|
+
(netPtOut, , netScyFee) = state.approxSwapExactScyForPt(
|
|
211
|
+
scyIndex(market),
|
|
212
|
+
exactScyIn,
|
|
213
|
+
block.timestamp,
|
|
214
|
+
approxParams
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function swapScyForExactYtStatic(address market, uint256 exactYtOut)
|
|
219
|
+
external
|
|
220
|
+
view
|
|
221
|
+
returns (uint256 netScyIn, uint256 netScyFee)
|
|
222
|
+
{
|
|
223
|
+
MarketState memory state = IPMarket(market).readState(false);
|
|
224
|
+
|
|
225
|
+
SCYIndex index = scyIndex(market);
|
|
226
|
+
|
|
227
|
+
uint256 scyReceived;
|
|
228
|
+
(scyReceived, netScyFee) = state.swapExactPtForScy(
|
|
229
|
+
scyIndex(market),
|
|
230
|
+
exactYtOut,
|
|
231
|
+
block.timestamp
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
uint256 totalScyNeed = index.assetToScyUp(exactYtOut);
|
|
235
|
+
netScyIn = totalScyNeed.subMax0(scyReceived);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function swapExactScyForYtStatic(address market, uint256 exactScyIn)
|
|
239
|
+
external
|
|
240
|
+
view
|
|
241
|
+
returns (uint256 netYtOut, uint256 netScyFee)
|
|
242
|
+
{
|
|
243
|
+
MarketState memory state = IPMarket(market).readState(false);
|
|
244
|
+
SCYIndex index = scyIndex(market);
|
|
245
|
+
|
|
246
|
+
(netYtOut, , netScyFee) = state.approxSwapExactScyForYt(
|
|
247
|
+
index,
|
|
248
|
+
exactScyIn,
|
|
249
|
+
block.timestamp,
|
|
250
|
+
approxParams
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function swapExactYtForScyStatic(address market, uint256 exactYtIn)
|
|
255
|
+
external
|
|
256
|
+
view
|
|
257
|
+
returns (uint256 netScyOut, uint256 netScyFee)
|
|
258
|
+
{
|
|
259
|
+
MarketState memory state = IPMarket(market).readState(false);
|
|
260
|
+
|
|
261
|
+
SCYIndex index = scyIndex(market);
|
|
262
|
+
|
|
263
|
+
uint256 scyOwed;
|
|
264
|
+
(scyOwed, netScyFee) = state.swapScyForExactPt(index, exactYtIn, block.timestamp);
|
|
265
|
+
|
|
266
|
+
uint256 amountPYToRepayScyOwed = index.scyToAssetUp(scyOwed);
|
|
267
|
+
uint256 amountPYToRedeemScyOut = exactYtIn - amountPYToRepayScyOwed;
|
|
268
|
+
|
|
269
|
+
netScyOut = index.assetToScy(amountPYToRedeemScyOut);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function swapYtForExactScyStatic(address market, uint256 exactScyOut)
|
|
273
|
+
external
|
|
274
|
+
view
|
|
275
|
+
returns (uint256 netYtIn, uint256 netScyFee)
|
|
276
|
+
{
|
|
277
|
+
MarketState memory state = IPMarket(market).readState(false);
|
|
278
|
+
|
|
279
|
+
SCYIndex index = scyIndex(market);
|
|
280
|
+
|
|
281
|
+
(netYtIn, , netScyFee) = state.approxSwapYtForExactScy(
|
|
282
|
+
index,
|
|
283
|
+
exactScyOut,
|
|
284
|
+
block.timestamp,
|
|
285
|
+
approxParams
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
|
|
193
289
|
// ============= OTHER HELPERS =============
|
|
194
290
|
|
|
291
|
+
function previewMintPY(address YT, uint256 amountScyToMint)
|
|
292
|
+
external
|
|
293
|
+
returns (uint256 amountPY)
|
|
294
|
+
{
|
|
295
|
+
IPYieldToken _YT = IPYieldToken(YT);
|
|
296
|
+
require(!_YT.isExpired(), "YT is expired");
|
|
297
|
+
return amountScyToMint.mulDown(_YT.scyIndexCurrent());
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function previewRedeemPY(address YT, uint256 amountPYToRedeem)
|
|
301
|
+
external
|
|
302
|
+
returns (uint256 amountPY)
|
|
303
|
+
{
|
|
304
|
+
IPYieldToken _YT = IPYieldToken(YT);
|
|
305
|
+
return amountPYToRedeem.divDown(_YT.scyIndexCurrent());
|
|
306
|
+
}
|
|
307
|
+
|
|
195
308
|
function scyIndex(address market) public view returns (SCYIndex index) {
|
|
196
309
|
(ISuperComposableYield SCY, , ) = IPMarket(market).readTokens();
|
|
197
310
|
|
|
@@ -215,6 +328,25 @@ contract RouterStatic is IPRouterStatic, Initializable, UUPSUpgradeable, Ownable
|
|
|
215
328
|
return lnImpliedRate.exp();
|
|
216
329
|
}
|
|
217
330
|
|
|
331
|
+
function getExchangeRate(address market) public view returns (uint256) {
|
|
332
|
+
MarketState memory state = IPMarket(market).readState(false);
|
|
333
|
+
MarketPreCompute memory comp = state.getMarketPreCompute(
|
|
334
|
+
scyIndex(market),
|
|
335
|
+
block.timestamp
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
return
|
|
339
|
+
MarketMathCore
|
|
340
|
+
._getExchangeRate(
|
|
341
|
+
state.totalPt,
|
|
342
|
+
comp.totalAsset,
|
|
343
|
+
comp.rateScalar,
|
|
344
|
+
comp.rateAnchor,
|
|
345
|
+
0
|
|
346
|
+
)
|
|
347
|
+
.Uint();
|
|
348
|
+
}
|
|
349
|
+
|
|
218
350
|
function getUserPYInfo(address py, address user)
|
|
219
351
|
public
|
|
220
352
|
view
|
|
@@ -255,7 +387,7 @@ contract RouterStatic is IPRouterStatic, Initializable, UUPSUpgradeable, Ownable
|
|
|
255
387
|
userMarketInfo.market = market;
|
|
256
388
|
userMarketInfo.lpBalance = userLp;
|
|
257
389
|
|
|
258
|
-
MarketState memory state = _market.readState(
|
|
390
|
+
MarketState memory state = _market.readState(false);
|
|
259
391
|
uint256 totalLp = uint256(state.totalLp);
|
|
260
392
|
uint256 userPt = (userLp * uint256(state.totalPt)) / totalLp;
|
|
261
393
|
uint256 userScy = (userLp * uint256(state.totalScy)) / totalLp;
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
"deployer": "0x1FcCC097db89A86Bfc474A1028F93958295b1Fb7",
|
|
3
3
|
"network": 43113,
|
|
4
4
|
"celerBus": "0xE9533976C590200E32d95C53f06AE12d292cFc47",
|
|
5
|
-
"treasury": "
|
|
6
|
-
"governanceManager": "
|
|
7
|
-
"PENDLE": "
|
|
8
|
-
"yieldContractFactory": "
|
|
9
|
-
"marketFactory": "
|
|
10
|
-
"router": "
|
|
11
|
-
"routerStatic": "
|
|
5
|
+
"treasury": "0xf176fB51F4eB826136a54FDc71C50fCd2202E272",
|
|
6
|
+
"governanceManager": "0x0A60B5D39b27E18F63aa937aD09Acc2B3d46d2a1",
|
|
7
|
+
"PENDLE": "0x519f3907379491c291Cf7b98425F35036a698080",
|
|
8
|
+
"yieldContractFactory": "0x2ff0de5593c85e0609675d07A6a33093A3838b17",
|
|
9
|
+
"marketFactory": "0x30340f337C27768e84CA5E957Fb22dcBF95857cD",
|
|
10
|
+
"router": "0xFEdBED4682D136925d30FFb9B8977CC9b3a6c406",
|
|
11
|
+
"routerStatic": "0xc49d8fdA920a46B21E1821780238f9E7A0de68df",
|
|
12
12
|
"startTime": 1657756800,
|
|
13
|
-
"vePendle": "
|
|
14
|
-
"votingController": "
|
|
15
|
-
"gaugeController": "
|
|
13
|
+
"vePendle": "0x7786729eEe8b9d30fE7d91fDFf23A0f1D0C615D9",
|
|
14
|
+
"votingController": "0x1001940C59e87AdfdB9f3b50aec5232c59d40Bc4",
|
|
15
|
+
"gaugeController": "0x3d47dBfB525cf8869B8c266a4c42E2c128F5639C"
|
|
16
16
|
}
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
"deployer": "0x1FcCC097db89A86Bfc474A1028F93958295b1Fb7",
|
|
3
3
|
"network": 80001,
|
|
4
4
|
"celerBus": "0x7d43AABC515C356145049227CeE54B608342c0ad",
|
|
5
|
-
"treasury": "
|
|
6
|
-
"governanceManager": "
|
|
7
|
-
"PENDLE": "
|
|
8
|
-
"yieldContractFactory": "
|
|
9
|
-
"marketFactory": "
|
|
10
|
-
"router": "
|
|
11
|
-
"routerStatic": "
|
|
5
|
+
"treasury": "0xFF4a4515888AEf82C9557A56E37A55a5dDe6EFF1",
|
|
6
|
+
"governanceManager": "0xE4a112A028D93e9E9b207eBedB1e1D6Cf5FdCEe9",
|
|
7
|
+
"PENDLE": "0x6D998d832b82f6307c5a2592d59A4cba7f15167f",
|
|
8
|
+
"yieldContractFactory": "0x058Ceec78EB7F854daBfdDd894e841423Ca344c3",
|
|
9
|
+
"marketFactory": "0xD33F62424acC95704D43E725B11b9e770505B425",
|
|
10
|
+
"router": "0x24d7CEaFBA7c7b32BE200aD6dA38C03797F0611f",
|
|
11
|
+
"routerStatic": "0x9902C57F6bc1e7737238777Fc52dA8A2161759f7",
|
|
12
12
|
"startTime": 1657756800,
|
|
13
|
-
"vePendle": "
|
|
14
|
-
"gaugeController": "
|
|
13
|
+
"vePendle": "0x1b615005157B9B0DDc7c0Af817f4A570cE3b591e",
|
|
14
|
+
"gaugeController": "0x3663E54bf1334B60FC97d3781460Bcf73d008116"
|
|
15
15
|
}
|
package/package.json
CHANGED