@pendle/core-v2 5.8.4-redeem → 5.8.4
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/build/artifacts/contracts/offchain-helpers/deploy/PendleCommonPoolDeployHelperV2.sol/PendleCommonPoolDeployHelperV2.dbg.json +1 -1
- package/build/artifacts/contracts/offchain-helpers/deploy/PendleCommonPoolDeployHelperV2.sol/PendleCommonPoolDeployHelperV2.json +2 -2
- package/build/artifacts/contracts/offchain-helpers/deploy/PendleCommonSYFactory.sol/PendleCommonSYFactory.dbg.json +1 -1
- package/build/artifacts/contracts/offchain-helpers/deploy/PendleCommonSYFactory.sol/PendleCommonSYFactory.json +21 -2
- package/build/artifacts/contracts/offchain-helpers/deploy/PendlePoolDeployHelperV2.sol/PendlePoolDeployHelperV2.dbg.json +1 -1
- package/build/artifacts/contracts/offchain-helpers/deploy/PendlePoolDeployHelperV2.sol/PendlePoolDeployHelperV2.json +2 -2
- package/build/artifacts/contracts/router/swap-aggregator/OKXScaleHelper.sol/IOKXDexRouter.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/OKXScaleHelper.sol/OKXScaleHelper.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/IKyberScalingHelper.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/IOdosRouterV2.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/PendleSwap.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/PendleSwap.json +191 -2
- package/contracts/offchain-helpers/deploy/PendleCommonSYFactory.sol +2 -0
- package/contracts/offchain-helpers/deploy/PendlePoolDeployHelperV2.sol +1 -5
- package/contracts/router/swap-aggregator/OKXScaleHelper.sol +13 -10
- package/contracts/router/swap-aggregator/PendleSwap.sol +21 -1
- package/deployments/1-core.json +1 -1
- package/deployments/146-core.json +7 -8
- package/deployments/42161-core.json +2 -2
- package/deployments/5000-core.json +1 -1
- package/deployments/56-core.json +1 -1
- package/deployments/80094-core.json +1 -1
- package/deployments/8453-core.json +1 -1
- package/package.json +1 -1
- package/typechain-types/PendleCommonSYFactory.ts +31 -0
- package/typechain-types/PendleSwap.ts +280 -0
- package/typechain-types/factories/PendleCommonPoolDeployHelperV2__factory.ts +1 -1
- package/typechain-types/factories/PendleCommonSYFactory__factory.ts +20 -1
- package/typechain-types/factories/PendlePoolDeployHelperV2__factory.ts +1 -1
- package/typechain-types/factories/PendleSwap__factory.ts +190 -1
- package/build/artifacts/contracts/interfaces/IPLPWrapperFactory.sol/IPLPWrapperFactory.dbg.json +0 -4
- package/build/artifacts/contracts/interfaces/IPLPWrapperFactory.sol/IPLPWrapperFactory.json +0 -56
- package/build/artifacts/contracts/interfaces/IPMarketSwapNSeed.sol/IPMarketSwapNSeed.dbg.json +0 -4
- package/build/artifacts/contracts/interfaces/IPMarketSwapNSeed.sol/IPMarketSwapNSeed.json +0 -10
- package/build/artifacts/contracts/offchain-helpers/ExpiredLpPtRedeemer.sol/ExpiredLpPtRedeemer.dbg.json +0 -4
- package/build/artifacts/contracts/offchain-helpers/ExpiredLpPtRedeemer.sol/ExpiredLpPtRedeemer.json +0 -299
- package/build/artifacts/contracts/offchain-helpers/PendleLPWrapper.sol/PendleLPWrapper.dbg.json +0 -4
- package/build/artifacts/contracts/offchain-helpers/PendleLPWrapper.sol/PendleLPWrapper.json +0 -342
- package/build/artifacts/contracts/offchain-helpers/PendleLPWrapperFactory.sol/PendleLPWrapperFactory.dbg.json +0 -4
- package/build/artifacts/contracts/offchain-helpers/PendleLPWrapperFactory.sol/PendleLPWrapperFactory.json +0 -308
- package/build/artifacts/contracts/offchain-helpers/SwapNSeed.sol/MarketSwapNSeed.dbg.json +0 -4
- package/build/artifacts/contracts/offchain-helpers/SwapNSeed.sol/MarketSwapNSeed.json +0 -232
- package/contracts/interfaces/IPLPWrapperFactory.sol +0 -10
- package/contracts/interfaces/IPMarketSwapNSeed.sol +0 -10
- package/contracts/offchain-helpers/ExpiredLpPtRedeemer.sol +0 -79
- package/contracts/offchain-helpers/PendleLPWrapper.sol +0 -43
- package/contracts/offchain-helpers/PendleLPWrapperFactory.sol +0 -45
- package/contracts/offchain-helpers/SwapNSeed.sol +0 -221
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
|
|
3
|
-
pragma solidity ^0.8.17;
|
|
4
|
-
|
|
5
|
-
import "../interfaces/IPMarket.sol";
|
|
6
|
-
import "../router/math/MarketApproxLibOnchain.sol";
|
|
7
|
-
import "../router/base/ActionBase.sol";
|
|
8
|
-
import "../interfaces/IPMarketSwapNSeed.sol";
|
|
9
|
-
|
|
10
|
-
contract MarketSwapNSeed is ActionBase, IPMarketSwapNSeed {
|
|
11
|
-
using PMath for uint256;
|
|
12
|
-
using PMath for int256;
|
|
13
|
-
using PYIndexLib for PYIndex;
|
|
14
|
-
using MarketMathCore for MarketState;
|
|
15
|
-
using PYIndexLib for IPYieldToken;
|
|
16
|
-
|
|
17
|
-
address public immutable router;
|
|
18
|
-
|
|
19
|
-
uint256 public constant MAX_ITERATIONS = 30;
|
|
20
|
-
|
|
21
|
-
struct MarketTokens {
|
|
22
|
-
IStandardizedYield SY;
|
|
23
|
-
IPPrincipalToken PT;
|
|
24
|
-
IPYieldToken YT;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
constructor(address _router) {
|
|
28
|
-
router = _router;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function swapNSeed(
|
|
32
|
-
address receiver,
|
|
33
|
-
address market,
|
|
34
|
-
uint256 minLpOut,
|
|
35
|
-
uint256 minYtOut,
|
|
36
|
-
TokenInput calldata input,
|
|
37
|
-
SwapNSeedData calldata snsData
|
|
38
|
-
) external payable returns (int256 amountPYToAccount, uint256 netLpOut, uint256 netYtOut) {
|
|
39
|
-
MarketTokens memory tokens;
|
|
40
|
-
(tokens.SY, tokens.PT, tokens.YT) = IPMarket(market).readTokens();
|
|
41
|
-
|
|
42
|
-
_mintSyFromToken(address(this), address(tokens.SY), 1, input);
|
|
43
|
-
amountPYToAccount = _swapBeforeSeeding(receiver, market, tokens, snsData);
|
|
44
|
-
(netLpOut, netYtOut, ) = _addLiquiditySingleSyKeepYt(
|
|
45
|
-
receiver,
|
|
46
|
-
market,
|
|
47
|
-
tokens.SY,
|
|
48
|
-
tokens.YT,
|
|
49
|
-
_selfBalance(tokens.SY),
|
|
50
|
-
minLpOut,
|
|
51
|
-
minYtOut
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function _addLiquiditySingleSyKeepYt(
|
|
56
|
-
address receiver,
|
|
57
|
-
address market,
|
|
58
|
-
IStandardizedYield SY,
|
|
59
|
-
IPYieldToken YT,
|
|
60
|
-
uint256 netSyIn,
|
|
61
|
-
uint256 minLpOut,
|
|
62
|
-
uint256 minYtOut
|
|
63
|
-
) internal returns (uint256 netLpOut, uint256 netYtOut, uint256 netSyMintPy) {
|
|
64
|
-
MarketState memory state = _readMarket(market);
|
|
65
|
-
|
|
66
|
-
PYIndex pyIndex = YT.newIndex();
|
|
67
|
-
|
|
68
|
-
netSyMintPy =
|
|
69
|
-
(netSyIn * state.totalPt.Uint()) /
|
|
70
|
-
(state.totalPt.Uint() + pyIndex.syToAsset(state.totalSy.Uint()));
|
|
71
|
-
|
|
72
|
-
uint256 netSyAddLiquidity = netSyIn - netSyMintPy;
|
|
73
|
-
|
|
74
|
-
// transfer SY to mint PY
|
|
75
|
-
_transferOut(address(SY), address(YT), netSyMintPy);
|
|
76
|
-
|
|
77
|
-
// the rest of SY goes to market
|
|
78
|
-
_transferOut(address(SY), market, netSyAddLiquidity);
|
|
79
|
-
|
|
80
|
-
// PT goes to market, YT goes to receiver
|
|
81
|
-
netYtOut = YT.mintPY(market, receiver);
|
|
82
|
-
|
|
83
|
-
(netLpOut, , ) = IPMarket(market).mint(receiver, netSyAddLiquidity, netYtOut);
|
|
84
|
-
|
|
85
|
-
if (netLpOut < minLpOut) revert("Slippage: INSUFFICIENT_LP_OUT");
|
|
86
|
-
if (netYtOut < minYtOut) revert("Slippage: INSUFFICIENT_YT_OUT");
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function _swapBeforeSeeding(
|
|
90
|
-
address receiver,
|
|
91
|
-
address market,
|
|
92
|
-
MarketTokens memory tokens,
|
|
93
|
-
SwapNSeedData memory snsData
|
|
94
|
-
) internal returns (int256 amountPYToAccount) {
|
|
95
|
-
PYIndex index = _getPYIndex(market);
|
|
96
|
-
MarketState memory state = _readMarket(market);
|
|
97
|
-
MarketPreCompute memory comp = state.getMarketPreCompute(index, block.timestamp);
|
|
98
|
-
|
|
99
|
-
if (state.lastLnImpliedRate > snsData.targetLnImpliedRate) {
|
|
100
|
-
// Normalize maxPtToSwap
|
|
101
|
-
snsData.maxPtToSwap = PMath.min(
|
|
102
|
-
snsData.maxPtToSwap,
|
|
103
|
-
MarketApproxPtInLibOnchain.calcSoftMaxPtIn(state, comp)
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
(int256 amountPtToBuy, int256 amountSyToAccount) = _calcAmountPtToBuy(state, comp, index, snsData);
|
|
107
|
-
amountPYToAccount = amountPtToBuy;
|
|
108
|
-
|
|
109
|
-
_transferOut(address(tokens.SY), market, amountSyToAccount.abs());
|
|
110
|
-
IPMarket(market).swapSyForExactPt(receiver, amountPtToBuy.abs(), EMPTY_BYTES);
|
|
111
|
-
} else {
|
|
112
|
-
// Normalize maxPtToSwap
|
|
113
|
-
snsData.maxPtToSwap = PMath.min(
|
|
114
|
-
snsData.maxPtToSwap,
|
|
115
|
-
MarketApproxPtOutLibOnchain.calcMaxPtOut(comp, state.totalPt)
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
amountPYToAccount = _calcAmountPtToSell(state, comp, index, snsData);
|
|
119
|
-
uint256 amountPtToSell = amountPYToAccount.abs();
|
|
120
|
-
uint256 netPyOut = _mintPyFromSy(
|
|
121
|
-
address(this),
|
|
122
|
-
address(tokens.SY),
|
|
123
|
-
address(tokens.YT),
|
|
124
|
-
index.assetToSyUp(amountPtToSell),
|
|
125
|
-
amountPtToSell,
|
|
126
|
-
false
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
_transferOut(address(tokens.PT), market, netPyOut);
|
|
130
|
-
_transferOut(address(tokens.YT), receiver, netPyOut);
|
|
131
|
-
|
|
132
|
-
// this amount of SY will be used to add liquidity in later step
|
|
133
|
-
IPMarket(market).swapExactPtForSy(address(this), amountPtToSell, EMPTY_BYTES);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function _calcAmountPtToBuy(
|
|
138
|
-
MarketState memory state,
|
|
139
|
-
MarketPreCompute memory comp,
|
|
140
|
-
PYIndex index,
|
|
141
|
-
SwapNSeedData memory snsData
|
|
142
|
-
) internal pure returns (int256 amountPtToSwapToAccount, int256 amountSyToAccount) {
|
|
143
|
-
int256 refAmt = snsData.maxPtToSwap.Int();
|
|
144
|
-
int256 accPtToAccount = 0;
|
|
145
|
-
|
|
146
|
-
int256 lastGoodAmountSyToAccount = 0;
|
|
147
|
-
uint256 lastGoodRate = state.lastLnImpliedRate;
|
|
148
|
-
|
|
149
|
-
for (uint256 iter = 0; iter < MAX_ITERATIONS; ++iter) {
|
|
150
|
-
refAmt /= 2;
|
|
151
|
-
MarketState memory localState = _deepCopy(state);
|
|
152
|
-
int256 curPtToAccount = accPtToAccount + refAmt;
|
|
153
|
-
|
|
154
|
-
// Will not revert. maxPtToBuy should already be normalized
|
|
155
|
-
(int256 localAmountSyToAccount, , ) = localState.calcTrade(comp, index, curPtToAccount);
|
|
156
|
-
|
|
157
|
-
if (localState.lastLnImpliedRate > snsData.targetLnImpliedRate) {
|
|
158
|
-
accPtToAccount += refAmt;
|
|
159
|
-
lastGoodRate = localState.lastLnImpliedRate;
|
|
160
|
-
lastGoodAmountSyToAccount = localAmountSyToAccount;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (PMath.isAApproxB(snsData.targetLnImpliedRate, lastGoodRate, snsData.eps)) {
|
|
165
|
-
amountPtToSwapToAccount = accPtToAccount;
|
|
166
|
-
amountSyToAccount = lastGoodAmountSyToAccount;
|
|
167
|
-
} else {
|
|
168
|
-
revert("_calcAmountPtToBuy: failed");
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function _calcAmountPtToSell(
|
|
173
|
-
MarketState memory state,
|
|
174
|
-
MarketPreCompute memory comp,
|
|
175
|
-
PYIndex index,
|
|
176
|
-
SwapNSeedData memory snsData
|
|
177
|
-
) internal pure returns (int256 amountPtToSwapToAccount) {
|
|
178
|
-
int256 refAmt = snsData.maxPtToSwap.Int();
|
|
179
|
-
int256 accPtToAccount = 0;
|
|
180
|
-
uint256 lastGoodRate = state.lastLnImpliedRate;
|
|
181
|
-
|
|
182
|
-
for (uint256 iter = 0; iter < MAX_ITERATIONS; ++iter) {
|
|
183
|
-
refAmt /= 2;
|
|
184
|
-
MarketState memory localState = _deepCopy(state);
|
|
185
|
-
int256 curPtToAccount = accPtToAccount - refAmt;
|
|
186
|
-
|
|
187
|
-
// Will not revert. maxPtToSell should already be normalized
|
|
188
|
-
localState.calcTrade(comp, index, curPtToAccount);
|
|
189
|
-
|
|
190
|
-
if (localState.lastLnImpliedRate < snsData.targetLnImpliedRate) {
|
|
191
|
-
accPtToAccount -= refAmt;
|
|
192
|
-
lastGoodRate = localState.lastLnImpliedRate;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (PMath.isAApproxB(snsData.targetLnImpliedRate, lastGoodRate, snsData.eps)) {
|
|
197
|
-
amountPtToSwapToAccount = accPtToAccount;
|
|
198
|
-
} else {
|
|
199
|
-
revert("_calcAmountPtToSell: failed");
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function _getPYIndex(address market) internal returns (PYIndex) {
|
|
204
|
-
(, , IPYieldToken YT) = IPMarket(market).readTokens();
|
|
205
|
-
return PYIndex.wrap(YT.pyIndexCurrent());
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function _deepCopy(MarketState memory state) internal pure returns (MarketState memory copiedState) {
|
|
209
|
-
copiedState.totalPt = state.totalPt;
|
|
210
|
-
copiedState.totalSy = state.totalSy;
|
|
211
|
-
copiedState.totalLp = state.totalLp;
|
|
212
|
-
copiedState.treasury = state.treasury;
|
|
213
|
-
|
|
214
|
-
copiedState.scalarRoot = state.scalarRoot;
|
|
215
|
-
copiedState.expiry = state.expiry;
|
|
216
|
-
|
|
217
|
-
copiedState.lnFeeRateRoot = state.lnFeeRateRoot;
|
|
218
|
-
copiedState.reserveFeePercent = state.reserveFeePercent;
|
|
219
|
-
copiedState.lastLnImpliedRate = state.lastLnImpliedRate;
|
|
220
|
-
}
|
|
221
|
-
}
|