@pendle/core-v2 0.6.0 → 0.6.3
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/core/RouterStatic.sol +142 -1
- package/contracts/interfaces/IPRouterStatic.sol +75 -0
- package/package.json +1 -1
- package/typechain-types/IPRouterStatic.ts +480 -0
- package/typechain-types/RouterStatic.ts +484 -4
- package/typechain-types/factories/IPRouterStatic__factory.ts +616 -0
- package/typechain-types/factories/PendleRouter__factory.ts +1 -1
- package/typechain-types/factories/RouterStatic__factory.ts +619 -3
- package/typechain-types/ActionSCYAndYOBase.ts +0 -223
- package/typechain-types/PendleRouterRedeemUpg.ts +0 -125
- package/typechain-types/factories/ActionSCYAndYOBase__factory.ts +0 -200
- package/typechain-types/factories/PendleRouterRedeemUpg__factory.ts +0 -112
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
2
|
pragma solidity 0.8.9;
|
|
3
3
|
|
|
4
|
+
import "../SuperComposableYield/ISuperComposableYield.sol";
|
|
5
|
+
import "../SuperComposableYield/implementations/IRewardManager.sol";
|
|
4
6
|
import "../interfaces/IPRouterStatic.sol";
|
|
5
7
|
import "../interfaces/IPMarket.sol";
|
|
6
8
|
import "../interfaces/IPYieldContractFactory.sol";
|
|
@@ -84,7 +86,7 @@ contract RouterStatic is IPRouterStatic {
|
|
|
84
86
|
return SCYIndexLib.newIndex(IPMarket(market).SCY());
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
function getPtImpliedYield(address market)
|
|
89
|
+
function getPtImpliedYield(address market) public view returns (int256) {
|
|
88
90
|
MarketState memory state = IPMarket(market).readState(false);
|
|
89
91
|
|
|
90
92
|
int256 lnImpliedRate = (state.lastLnImpliedRate).Int();
|
|
@@ -104,4 +106,143 @@ contract RouterStatic is IPRouterStatic {
|
|
|
104
106
|
else if (yieldContractFactory.isYT(token)) isYT = true;
|
|
105
107
|
else if (marketFactory.isValidMarket(token)) isMarket = true;
|
|
106
108
|
}
|
|
109
|
+
|
|
110
|
+
function getUserPYInfo(address py, address user)
|
|
111
|
+
public
|
|
112
|
+
view
|
|
113
|
+
returns (UserPYInfo memory userPYInfo)
|
|
114
|
+
{
|
|
115
|
+
(userPYInfo.yt, userPYInfo.pt) = getPY(py);
|
|
116
|
+
IPYieldToken YT = IPYieldToken(userPYInfo.yt);
|
|
117
|
+
userPYInfo.ytBalance = YT.balanceOf(user);
|
|
118
|
+
userPYInfo.ptBalance = IPPrincipalToken(userPYInfo.pt).balanceOf(user);
|
|
119
|
+
userPYInfo.unclaimedInterest.token = YT.SCY();
|
|
120
|
+
(, userPYInfo.unclaimedInterest.amount) = YT.getInterestData(user);
|
|
121
|
+
address[] memory rewardTokens = YT.getRewardTokens();
|
|
122
|
+
TokenAmount[] memory unclaimedRewards = new TokenAmount[](rewardTokens.length);
|
|
123
|
+
uint256 length = 0;
|
|
124
|
+
for (uint256 i = 0; i < rewardTokens.length; ++i) {
|
|
125
|
+
address rewardToken = rewardTokens[i];
|
|
126
|
+
(, uint256 amount) = YT.getUserReward(user, rewardToken);
|
|
127
|
+
if (amount > 0) {
|
|
128
|
+
unclaimedRewards[length].token = rewardToken;
|
|
129
|
+
unclaimedRewards[length].amount = amount;
|
|
130
|
+
++length;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
userPYInfo.unclaimedRewards = new TokenAmount[](length);
|
|
134
|
+
for (uint256 i = 0; i < length; ++i) {
|
|
135
|
+
userPYInfo.unclaimedRewards[i] = unclaimedRewards[i];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function getPYInfo(address py)
|
|
140
|
+
external
|
|
141
|
+
returns (
|
|
142
|
+
uint256 exchangeRate,
|
|
143
|
+
uint256 totalSupply,
|
|
144
|
+
RewardIndex[] memory rewardIndexes
|
|
145
|
+
)
|
|
146
|
+
{
|
|
147
|
+
(address yt, ) = getPY(py);
|
|
148
|
+
IPYieldToken YT = IPYieldToken(yt);
|
|
149
|
+
(, exchangeRate) = YT.getScyIndex();
|
|
150
|
+
totalSupply = YT.totalSupply();
|
|
151
|
+
address[] memory rewardTokens = YT.getRewardTokens();
|
|
152
|
+
rewardIndexes = new RewardIndex[](rewardTokens.length);
|
|
153
|
+
for (uint256 i = 0; i < rewardTokens.length; ++i) {
|
|
154
|
+
address rewardToken = rewardTokens[i];
|
|
155
|
+
rewardIndexes[i].rewardToken = rewardToken;
|
|
156
|
+
(, rewardIndexes[i].index) = YT.getGlobalReward(rewardToken);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function getPY(address py) public view returns (address pt, address yt) {
|
|
161
|
+
if (yieldContractFactory.isYT(py)) {
|
|
162
|
+
yt = py;
|
|
163
|
+
pt = IPYieldToken(py).PT();
|
|
164
|
+
} else {
|
|
165
|
+
yt = IPPrincipalToken(py).YT();
|
|
166
|
+
pt = py;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function getMarketInfo(address market)
|
|
171
|
+
external
|
|
172
|
+
view
|
|
173
|
+
returns (
|
|
174
|
+
address pt,
|
|
175
|
+
address scy,
|
|
176
|
+
MarketState memory state,
|
|
177
|
+
int256 impliedYield,
|
|
178
|
+
uint256 exchangeRate
|
|
179
|
+
)
|
|
180
|
+
{
|
|
181
|
+
IPMarket _market = IPMarket(market);
|
|
182
|
+
pt = _market.PT();
|
|
183
|
+
scy = _market.SCY();
|
|
184
|
+
state = _market.readState(true);
|
|
185
|
+
impliedYield = getPtImpliedYield(market);
|
|
186
|
+
exchangeRate = 0; // TODO: get the actual exchange rate
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function getUserMarketInfo(address market, address user)
|
|
190
|
+
public
|
|
191
|
+
view
|
|
192
|
+
returns (UserMarketInfo memory userMarketInfo)
|
|
193
|
+
{
|
|
194
|
+
IPMarket _market = IPMarket(market);
|
|
195
|
+
userMarketInfo.market = market;
|
|
196
|
+
userMarketInfo.lpBalance = _market.balanceOf(user);
|
|
197
|
+
// TODO: Is there a way to convert LP to PT and SCY?
|
|
198
|
+
userMarketInfo.ptBalance = TokenAmount(_market.PT(), 0);
|
|
199
|
+
userMarketInfo.scyBalance = TokenAmount(_market.SCY(), 0);
|
|
200
|
+
// TODO: Get this from SCY once it is in the interface
|
|
201
|
+
userMarketInfo.assetBalance = TokenAmount(address(0), 0);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function getUserPYPositionsByPYs(address user, address[] calldata pys)
|
|
205
|
+
external
|
|
206
|
+
view
|
|
207
|
+
returns (UserPYInfo[] memory userPYPositions)
|
|
208
|
+
{
|
|
209
|
+
userPYPositions = new UserPYInfo[](pys.length);
|
|
210
|
+
for (uint256 i = 0; i < pys.length; ++i) {
|
|
211
|
+
userPYPositions[i] = getUserPYInfo(pys[i], user);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function getUserMarketPositions(address user, address[] calldata markets)
|
|
216
|
+
external
|
|
217
|
+
view
|
|
218
|
+
returns (UserMarketInfo[] memory userMarketPositions)
|
|
219
|
+
{
|
|
220
|
+
userMarketPositions = new UserMarketInfo[](markets.length);
|
|
221
|
+
for (uint256 i = 0; i < markets.length; ++i) {
|
|
222
|
+
userMarketPositions[i] = getUserMarketInfo(markets[i], user);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function hasPYPosition(UserPYInfo memory userPYInfo) public pure returns (bool hasPosition) {
|
|
227
|
+
hasPosition = (userPYInfo.ytBalance > 0 ||
|
|
228
|
+
userPYInfo.ptBalance > 0 ||
|
|
229
|
+
userPYInfo.unclaimedInterest.amount > 0 ||
|
|
230
|
+
userPYInfo.unclaimedRewards.length > 0);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function getUserSCYInfo(address scy, address user)
|
|
234
|
+
external
|
|
235
|
+
view
|
|
236
|
+
returns (uint256 balance, TokenAmount[] memory rewards)
|
|
237
|
+
{
|
|
238
|
+
ISuperComposableYield SCY = ISuperComposableYield(scy);
|
|
239
|
+
balance = SCY.balanceOf(scy);
|
|
240
|
+
address[] memory rewardTokens = SCY.getRewardTokens();
|
|
241
|
+
rewards = new TokenAmount[](rewardTokens.length);
|
|
242
|
+
for (uint256 i = 0; i < rewardTokens.length; ++i) {
|
|
243
|
+
address rewardToken = rewardTokens[i];
|
|
244
|
+
rewards[i].token = rewardToken;
|
|
245
|
+
(, rewards[i].amount) = IRewardManager(scy).getUserReward(user, rewardToken);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
107
248
|
}
|
|
@@ -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 UserPYInfo {
|
|
18
|
+
address yt;
|
|
19
|
+
address pt;
|
|
20
|
+
uint256 ytBalance;
|
|
21
|
+
uint256 ptBalance;
|
|
22
|
+
TokenAmount unclaimedInterest;
|
|
23
|
+
TokenAmount[] unclaimedRewards;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
struct UserMarketInfo {
|
|
27
|
+
address market;
|
|
28
|
+
uint256 lpBalance;
|
|
29
|
+
TokenAmount ptBalance;
|
|
30
|
+
TokenAmount scyBalance;
|
|
31
|
+
TokenAmount assetBalance;
|
|
32
|
+
}
|
|
33
|
+
|
|
7
34
|
function addLiquidityStatic(
|
|
8
35
|
address market,
|
|
9
36
|
uint256 scyDesired,
|
|
@@ -41,4 +68,52 @@ interface IPRouterStatic {
|
|
|
41
68
|
bool isYT,
|
|
42
69
|
bool isMarket
|
|
43
70
|
);
|
|
71
|
+
|
|
72
|
+
function getUserPYInfo(address py, address user)
|
|
73
|
+
external
|
|
74
|
+
view
|
|
75
|
+
returns (UserPYInfo memory userPYInfo);
|
|
76
|
+
|
|
77
|
+
function getPYInfo(address py)
|
|
78
|
+
external
|
|
79
|
+
returns (
|
|
80
|
+
uint256 exchangeRate,
|
|
81
|
+
uint256 totalSupply,
|
|
82
|
+
RewardIndex[] memory rewardIndexes
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
function getPY(address py) external view returns (address yt, address pt);
|
|
86
|
+
|
|
87
|
+
function getMarketInfo(address market)
|
|
88
|
+
external
|
|
89
|
+
view
|
|
90
|
+
returns (
|
|
91
|
+
address pt,
|
|
92
|
+
address scy,
|
|
93
|
+
MarketState memory state,
|
|
94
|
+
int256 impliedYield,
|
|
95
|
+
uint256 exchangeRate
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
function getUserMarketInfo(address market, address user)
|
|
99
|
+
external
|
|
100
|
+
view
|
|
101
|
+
returns (UserMarketInfo memory userMarketInfo);
|
|
102
|
+
|
|
103
|
+
function getUserPYPositionsByPYs(address user, address[] calldata pys)
|
|
104
|
+
external
|
|
105
|
+
view
|
|
106
|
+
returns (UserPYInfo[] memory userPYPositions);
|
|
107
|
+
|
|
108
|
+
function getUserMarketPositions(address user, address[] calldata markets)
|
|
109
|
+
external
|
|
110
|
+
view
|
|
111
|
+
returns (UserMarketInfo[] memory userMarketPositions);
|
|
112
|
+
|
|
113
|
+
function hasPYPosition(UserPYInfo memory userPYInfo) external pure returns (bool hasPosition);
|
|
114
|
+
|
|
115
|
+
function getUserSCYInfo(address scy, address user)
|
|
116
|
+
external
|
|
117
|
+
view
|
|
118
|
+
returns (uint256 balance, TokenAmount[] memory rewards);
|
|
44
119
|
}
|