@pendle/core-v2 0.11.7-testnet → 0.11.9-testnet
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/core/PendleRouter.sol/PendleRouter.dbg.json +1 -1
- package/build/artifacts/contracts/core/PendleRouter.sol/PendleRouter.json +20 -2
- package/build/artifacts/contracts/core/actions/ActionAddRemoveLiq.sol/ActionAddRemoveLiq.dbg.json +1 -1
- package/build/artifacts/contracts/core/actions/ActionAddRemoveLiq.sol/ActionAddRemoveLiq.json +2 -2
- package/build/artifacts/contracts/core/actions/ActionCallback.sol/ActionCallback.dbg.json +1 -1
- package/build/artifacts/contracts/core/actions/ActionCallback.sol/ActionCallback.json +2 -2
- package/build/artifacts/contracts/core/actions/ActionMintRedeem.sol/ActionMintRedeem.dbg.json +1 -1
- package/build/artifacts/contracts/core/actions/ActionMintRedeem.sol/ActionMintRedeem.json +2 -2
- package/build/artifacts/contracts/core/actions/ActionSwapPT.sol/ActionSwapPT.dbg.json +1 -1
- package/build/artifacts/contracts/core/actions/ActionSwapPT.sol/ActionSwapPT.json +2 -2
- package/build/artifacts/contracts/core/actions/ActionSwapPTYT.sol/ActionSwapPTYT.dbg.json +4 -0
- package/build/artifacts/contracts/core/actions/ActionSwapPTYT.sol/ActionSwapPTYT.json +185 -0
- package/build/artifacts/contracts/core/actions/ActionSwapYT.sol/ActionSwapYT.dbg.json +1 -1
- package/build/artifacts/contracts/core/actions/ActionSwapYT.sol/ActionSwapYT.json +2 -2
- package/build/artifacts/contracts/core/actions/base/CallbackHelper.sol/CallbackHelper.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPActionAddRemoveLiq.sol/IPActionAddRemoveLiq.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPActionMintRedeem.sol/IPActionMintRedeem.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPActionSwapPT.sol/IPActionSwapPT.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPActionSwapPTYT.sol/IPActionSwapPTYT.dbg.json +4 -0
- package/build/artifacts/contracts/interfaces/IPActionSwapPTYT.sol/IPActionSwapPTYT.json +180 -0
- package/build/artifacts/contracts/interfaces/IPActionSwapYT.sol/IPActionSwapYT.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPAllAction.sol/IPAllAction.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPAllAction.sol/IPAllAction.json +169 -0
- package/build/artifacts/contracts/libraries/math/MarketApproxLib.sol/MarketApproxPtInLib.dbg.json +1 -1
- package/build/artifacts/contracts/libraries/math/MarketApproxLib.sol/MarketApproxPtInLib.json +2 -2
- package/build/artifacts/contracts/libraries/math/MarketApproxLib.sol/MarketApproxPtOutLib.dbg.json +1 -1
- package/build/artifacts/contracts/libraries/math/MarketApproxLib.sol/MarketApproxPtOutLib.json +2 -2
- package/build/artifacts/contracts/offchain-helpers/MarketMathStatic.sol/MarketMathStatic.dbg.json +1 -1
- package/build/artifacts/contracts/offchain-helpers/MarketMathStatic.sol/MarketMathStatic.json +2 -2
- package/build/artifacts/contracts/offchain-helpers/RouterStatic.sol/RouterStatic.dbg.json +1 -1
- package/build/artifacts/contracts/offchain-helpers/RouterStatic.sol/RouterStatic.json +150 -56
- package/contracts/core/PendleRouter.sol +8 -0
- package/contracts/core/actions/ActionCallback.sol +39 -0
- package/contracts/core/actions/ActionSwapPTYT.sol +86 -0
- package/contracts/core/actions/base/CallbackHelper.sol +49 -1
- package/contracts/interfaces/IPActionSwapPTYT.sol +31 -0
- package/contracts/interfaces/IPAllAction.sol +2 -0
- package/contracts/libraries/math/MarketApproxLib.sol +116 -0
- package/contracts/offchain-helpers/MarketMathStatic.sol +53 -0
- package/contracts/offchain-helpers/RouterStatic.sol +24 -0
- package/deployments/43113-core.json +1 -1
- package/package.json +1 -3
- package/typechain-types/ActionSwapPTYT.ts +233 -0
- package/typechain-types/IPActionSwapPTYT.ts +233 -0
- package/typechain-types/IPAllAction.ts +138 -0
- package/typechain-types/PendleRouter.ts +19 -0
- package/typechain-types/RouterStatic.ts +92 -0
- package/typechain-types/factories/ActionAddRemoveLiq__factory.ts +1 -1
- package/typechain-types/factories/ActionCallback__factory.ts +1 -1
- package/typechain-types/factories/ActionMintRedeem__factory.ts +1 -1
- package/typechain-types/factories/ActionSwapPTYT__factory.ts +238 -0
- package/typechain-types/factories/ActionSwapPT__factory.ts +1 -1
- package/typechain-types/factories/ActionSwapYT__factory.ts +1 -1
- package/typechain-types/factories/IPActionSwapPTYT__factory.ts +195 -0
- package/typechain-types/factories/IPAllAction__factory.ts +169 -0
- package/typechain-types/factories/MarketMathStatic__factory.ts +1 -1
- package/typechain-types/factories/PendleRouter__factory.ts +23 -1
- package/typechain-types/factories/RouterStatic__factory.ts +79 -1
- package/typechain-types/hardhat.d.ts +18 -198
- package/typechain-types/index.ts +4 -44
|
@@ -17,6 +17,7 @@ contract PendleRouter is Proxy, Initializable, UUPSUpgradeable, BoringOwnableUpg
|
|
|
17
17
|
address public immutable ACTION_ADD_REMOVE_LIQ;
|
|
18
18
|
address public immutable ACTION_SWAP_PT;
|
|
19
19
|
address public immutable ACTION_SWAP_YT;
|
|
20
|
+
address public immutable ACTION_SWAP_PTYT;
|
|
20
21
|
address public immutable ACTION_CALLBACK;
|
|
21
22
|
address public immutable ACTION_MISC;
|
|
22
23
|
|
|
@@ -25,6 +26,7 @@ contract PendleRouter is Proxy, Initializable, UUPSUpgradeable, BoringOwnableUpg
|
|
|
25
26
|
address _ACTION_ADD_REMOVE_LIQ,
|
|
26
27
|
address _ACTION_SWAP_PT,
|
|
27
28
|
address _ACTION_SWAP_YT,
|
|
29
|
+
address _ACTION_SWAP_PTYT,
|
|
28
30
|
address _ACTION_CALLBACK,
|
|
29
31
|
address _ACTION_MISC
|
|
30
32
|
) initializer {
|
|
@@ -32,6 +34,7 @@ contract PendleRouter is Proxy, Initializable, UUPSUpgradeable, BoringOwnableUpg
|
|
|
32
34
|
ACTION_ADD_REMOVE_LIQ = _ACTION_ADD_REMOVE_LIQ;
|
|
33
35
|
ACTION_SWAP_PT = _ACTION_SWAP_PT;
|
|
34
36
|
ACTION_SWAP_YT = _ACTION_SWAP_YT;
|
|
37
|
+
ACTION_SWAP_PTYT = _ACTION_SWAP_PTYT;
|
|
35
38
|
ACTION_CALLBACK = _ACTION_CALLBACK;
|
|
36
39
|
ACTION_MISC = _ACTION_MISC;
|
|
37
40
|
}
|
|
@@ -82,6 +85,11 @@ contract PendleRouter is Proxy, Initializable, UUPSUpgradeable, BoringOwnableUpg
|
|
|
82
85
|
sig == IPActionSwapYT.swapYtForExactScy.selector
|
|
83
86
|
) {
|
|
84
87
|
return ACTION_SWAP_YT;
|
|
88
|
+
} else if (
|
|
89
|
+
sig == IPActionSwapPTYT.swapExactPtForYt.selector ||
|
|
90
|
+
sig == IPActionSwapPTYT.swapExactYtForPt.selector
|
|
91
|
+
) {
|
|
92
|
+
return ACTION_SWAP_PTYT;
|
|
85
93
|
} else if (sig == IPMarketSwapCallback.swapCallback.selector) {
|
|
86
94
|
return ACTION_CALLBACK;
|
|
87
95
|
} else if (sig == IPActionMisc.consult.selector) {
|
|
@@ -15,6 +15,7 @@ contract ActionCallback is IPMarketSwapCallback, CallbackHelper {
|
|
|
15
15
|
using Math for uint256;
|
|
16
16
|
using SafeERC20 for ISuperComposableYield;
|
|
17
17
|
using SafeERC20 for IPYieldToken;
|
|
18
|
+
using SafeERC20 for IPPrincipalToken;
|
|
18
19
|
using SafeERC20 for IERC20;
|
|
19
20
|
using PYIndexLib for PYIndex;
|
|
20
21
|
using PYIndexLib for IPYieldToken;
|
|
@@ -48,6 +49,10 @@ contract ActionCallback is IPMarketSwapCallback, CallbackHelper {
|
|
|
48
49
|
_callbackSwapScyForExactYt(market, ptToAccount, scyToAccount, data);
|
|
49
50
|
} else if (swapType == ActionType.SwapYtForScy) {
|
|
50
51
|
_callbackSwapYtForScy(market, ptToAccount, scyToAccount, data);
|
|
52
|
+
} else if (swapType == ActionType.SwapExactYtForPt) {
|
|
53
|
+
_callbackSwapExactYtForPt(market, ptToAccount, scyToAccount, data);
|
|
54
|
+
} else if (swapType == ActionType.SwapExactPtForYt) {
|
|
55
|
+
_callbackSwapExactPtForYt(market, ptToAccount, scyToAccount, data);
|
|
51
56
|
} else {
|
|
52
57
|
require(false, "unknown swapType");
|
|
53
58
|
}
|
|
@@ -137,4 +142,38 @@ contract ActionCallback is IPMarketSwapCallback, CallbackHelper {
|
|
|
137
142
|
uint256[] memory amountScyOuts = YT.redeemPYMulti(receivers, amountPYToRedeems);
|
|
138
143
|
require(amountScyOuts[1] >= minScyOut, "insufficient SCY out");
|
|
139
144
|
}
|
|
145
|
+
|
|
146
|
+
function _callbackSwapExactPtForYt(
|
|
147
|
+
address market,
|
|
148
|
+
int256 ptToAccount,
|
|
149
|
+
int256, /*scyToAccount*/
|
|
150
|
+
bytes calldata data
|
|
151
|
+
) internal {
|
|
152
|
+
(address receiver, uint256 exactPtIn, uint256 minYtOut) = _decodeSwapExactPtForYt(data);
|
|
153
|
+
uint256 netPtOwed = ptToAccount.abs();
|
|
154
|
+
(, , IPYieldToken YT) = IPMarket(market).readTokens();
|
|
155
|
+
|
|
156
|
+
uint256 netPyOut = YT.mintPY(market, receiver);
|
|
157
|
+
require(netPyOut >= minYtOut, "insufficient YT out");
|
|
158
|
+
require(exactPtIn + netPyOut >= netPtOwed, "insufficient PT to pay");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function _callbackSwapExactYtForPt(
|
|
162
|
+
address market,
|
|
163
|
+
int256 ptToAccount,
|
|
164
|
+
int256 scyToAccount,
|
|
165
|
+
bytes calldata data
|
|
166
|
+
) internal {
|
|
167
|
+
(address receiver, uint256 exactYtIn, uint256 minPtOut) = _decodeSwapExactYtForPt(data);
|
|
168
|
+
(, IPPrincipalToken PT, IPYieldToken YT) = IPMarket(market).readTokens();
|
|
169
|
+
|
|
170
|
+
uint256 netScyOwed = scyToAccount.abs();
|
|
171
|
+
|
|
172
|
+
PT.safeTransfer(address(YT), exactYtIn);
|
|
173
|
+
uint256 netScyToMarket = YT.redeemPY(market);
|
|
174
|
+
|
|
175
|
+
require(netScyToMarket >= netScyOwed, "insufficient SCY to pay");
|
|
176
|
+
require(ptToAccount.Uint() - exactYtIn >= minPtOut, "insufficient PT out");
|
|
177
|
+
PT.safeTransfer(receiver, ptToAccount.Uint() - exactYtIn);
|
|
178
|
+
}
|
|
140
179
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity 0.8.15;
|
|
3
|
+
|
|
4
|
+
import "../../interfaces/IPActionSwapPTYT.sol";
|
|
5
|
+
import "../../interfaces/IPMarket.sol";
|
|
6
|
+
import "./base/CallbackHelper.sol";
|
|
7
|
+
|
|
8
|
+
contract ActionSwapPTYT is IPActionSwapPTYT, CallbackHelper {
|
|
9
|
+
using MarketMathCore for MarketState;
|
|
10
|
+
using MarketApproxPtInLib for MarketState;
|
|
11
|
+
using MarketApproxPtOutLib for MarketState;
|
|
12
|
+
using Math for uint256;
|
|
13
|
+
using Math for int256;
|
|
14
|
+
using SafeERC20 for IERC20;
|
|
15
|
+
using PYIndexLib for IPYieldToken;
|
|
16
|
+
using SafeERC20 for ISuperComposableYield;
|
|
17
|
+
using SafeERC20 for IPYieldToken;
|
|
18
|
+
using SafeERC20 for IPPrincipalToken;
|
|
19
|
+
|
|
20
|
+
/// @dev since this contract will be proxied, it must not contains non-immutable variables
|
|
21
|
+
constructor() //solhint-disable-next-line no-empty-blocks
|
|
22
|
+
{
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function swapExactPtForYt(
|
|
27
|
+
address receiver,
|
|
28
|
+
address market,
|
|
29
|
+
uint256 exactPtIn,
|
|
30
|
+
uint256 minYtOut,
|
|
31
|
+
ApproxParams calldata guessTotalPtToSwap
|
|
32
|
+
) external returns (uint256 netYtOut) {
|
|
33
|
+
(, IPPrincipalToken PT, IPYieldToken YT) = IPMarket(market).readTokens();
|
|
34
|
+
MarketState memory state = IPMarket(market).readState();
|
|
35
|
+
|
|
36
|
+
PT.safeTransferFrom(msg.sender, market, exactPtIn);
|
|
37
|
+
|
|
38
|
+
uint256 totalPtToSwap;
|
|
39
|
+
(netYtOut, , totalPtToSwap, ) = state.approxSwapExactPtForYt(
|
|
40
|
+
YT.newIndex(),
|
|
41
|
+
exactPtIn,
|
|
42
|
+
block.timestamp,
|
|
43
|
+
guessTotalPtToSwap
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
require(netYtOut >= minYtOut, "insufficient YT out");
|
|
47
|
+
IPMarket(market).swapExactPtForScy(
|
|
48
|
+
address(YT),
|
|
49
|
+
totalPtToSwap,
|
|
50
|
+
_encodeSwapExactPtForYt(receiver, exactPtIn, minYtOut)
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
emit SwapPtAndYt(msg.sender, market, receiver, exactPtIn.neg(), netYtOut.Int());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function swapExactYtForPt(
|
|
57
|
+
address receiver,
|
|
58
|
+
address market,
|
|
59
|
+
uint256 exactYtIn,
|
|
60
|
+
uint256 minPtOut,
|
|
61
|
+
ApproxParams calldata guessTotalPtSwapped
|
|
62
|
+
) external returns (uint256 netPtOut) {
|
|
63
|
+
(, , IPYieldToken YT) = IPMarket(market).readTokens();
|
|
64
|
+
MarketState memory state = IPMarket(market).readState();
|
|
65
|
+
|
|
66
|
+
YT.safeTransferFrom(msg.sender, address(YT), exactYtIn);
|
|
67
|
+
|
|
68
|
+
uint256 totalPtSwapped;
|
|
69
|
+
(netPtOut, , totalPtSwapped, ) = state.approxSwapExactYtForPt(
|
|
70
|
+
YT.newIndex(),
|
|
71
|
+
exactYtIn,
|
|
72
|
+
block.timestamp,
|
|
73
|
+
guessTotalPtSwapped
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
require(netPtOut >= minPtOut, "insufficient PT out");
|
|
77
|
+
|
|
78
|
+
IPMarket(market).swapScyForExactPt(
|
|
79
|
+
address(this),
|
|
80
|
+
totalPtSwapped,
|
|
81
|
+
_encodeSwapExactYtForPt(receiver, exactYtIn, minPtOut)
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
emit SwapPtAndYt(msg.sender, market, receiver, netPtOut.Int(), exactYtIn.neg());
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -5,7 +5,9 @@ abstract contract CallbackHelper {
|
|
|
5
5
|
enum ActionType {
|
|
6
6
|
SwapScyForExactYt,
|
|
7
7
|
SwapExactScyForYt,
|
|
8
|
-
SwapYtForScy
|
|
8
|
+
SwapYtForScy,
|
|
9
|
+
SwapExactYtForPt,
|
|
10
|
+
SwapExactPtForYt
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
/// ------------------------------------------------------------
|
|
@@ -72,6 +74,52 @@ abstract contract CallbackHelper {
|
|
|
72
74
|
(, receiver, minScyOut) = abi.decode(data, (ActionType, address, uint256));
|
|
73
75
|
}
|
|
74
76
|
|
|
77
|
+
function _encodeSwapExactYtForPt(
|
|
78
|
+
address receiver,
|
|
79
|
+
uint256 exactYtIn,
|
|
80
|
+
uint256 minPtOut
|
|
81
|
+
) internal pure returns (bytes memory) {
|
|
82
|
+
return abi.encode(ActionType.SwapExactYtForPt, receiver, exactYtIn, minPtOut);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function _decodeSwapExactYtForPt(bytes memory data)
|
|
86
|
+
internal
|
|
87
|
+
pure
|
|
88
|
+
returns (
|
|
89
|
+
address receiver,
|
|
90
|
+
uint256 exactYtIn,
|
|
91
|
+
uint256 minPtOut
|
|
92
|
+
)
|
|
93
|
+
{
|
|
94
|
+
(, receiver, exactYtIn, minPtOut) = abi.decode(
|
|
95
|
+
data,
|
|
96
|
+
(ActionType, address, uint256, uint256)
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function _encodeSwapExactPtForYt(
|
|
101
|
+
address receiver,
|
|
102
|
+
uint256 exactPtIn,
|
|
103
|
+
uint256 minYtOut
|
|
104
|
+
) internal pure returns (bytes memory) {
|
|
105
|
+
return abi.encode(ActionType.SwapExactPtForYt, receiver, exactPtIn, minYtOut);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function _decodeSwapExactPtForYt(bytes memory data)
|
|
109
|
+
internal
|
|
110
|
+
pure
|
|
111
|
+
returns (
|
|
112
|
+
address receiver,
|
|
113
|
+
uint256 exactPtIn,
|
|
114
|
+
uint256 minYtOut
|
|
115
|
+
)
|
|
116
|
+
{
|
|
117
|
+
(, receiver, exactPtIn, minYtOut) = abi.decode(
|
|
118
|
+
data,
|
|
119
|
+
(ActionType, address, uint256, uint256)
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
75
123
|
/// ------------------------------------------------------------
|
|
76
124
|
/// Misc functions
|
|
77
125
|
/// ------------------------------------------------------------
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity 0.8.15;
|
|
3
|
+
|
|
4
|
+
import "../libraries/math/MarketApproxLib.sol";
|
|
5
|
+
import "../libraries/kyberswap/KyberSwapHelper.sol";
|
|
6
|
+
|
|
7
|
+
interface IPActionSwapPTYT {
|
|
8
|
+
event SwapPtAndYt(
|
|
9
|
+
address indexed caller,
|
|
10
|
+
address indexed market,
|
|
11
|
+
address indexed receiver,
|
|
12
|
+
int256 netPtToAccount,
|
|
13
|
+
int256 netYtToAccount
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
function swapExactPtForYt(
|
|
17
|
+
address receiver,
|
|
18
|
+
address market,
|
|
19
|
+
uint256 exactPtIn,
|
|
20
|
+
uint256 minYtOut,
|
|
21
|
+
ApproxParams calldata guessTotalPtToSwap
|
|
22
|
+
) external returns (uint256 netYtOut);
|
|
23
|
+
|
|
24
|
+
function swapExactYtForPt(
|
|
25
|
+
address receiver,
|
|
26
|
+
address market,
|
|
27
|
+
uint256 exactYtIn,
|
|
28
|
+
uint256 minPtOut,
|
|
29
|
+
ApproxParams calldata guessTotalPtSwapped
|
|
30
|
+
) external returns (uint256 netPtOut);
|
|
31
|
+
}
|
|
@@ -5,6 +5,7 @@ pragma solidity 0.8.15;
|
|
|
5
5
|
import "./IPActionAddRemoveLiq.sol";
|
|
6
6
|
import "./IPActionSwapPT.sol";
|
|
7
7
|
import "./IPActionSwapYT.sol";
|
|
8
|
+
import "./IPActionSwapPTYT.sol";
|
|
8
9
|
import "./IPActionMintRedeem.sol";
|
|
9
10
|
import "./IPActionMisc.sol";
|
|
10
11
|
|
|
@@ -12,6 +13,7 @@ interface IPAllAction is
|
|
|
12
13
|
IPActionAddRemoveLiq,
|
|
13
14
|
IPActionSwapPT,
|
|
14
15
|
IPActionSwapYT,
|
|
16
|
+
IPActionSwapPTYT,
|
|
15
17
|
IPActionMintRedeem,
|
|
16
18
|
IPActionMisc
|
|
17
19
|
{}
|
|
@@ -272,6 +272,63 @@ library MarketApproxPtInLib {
|
|
|
272
272
|
revert("approx fail");
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
+
struct Args7 {
|
|
276
|
+
MarketState market;
|
|
277
|
+
PYIndex index;
|
|
278
|
+
uint256 maxPtIn;
|
|
279
|
+
uint256 blockTime;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function approxSwapExactPtForYt(
|
|
283
|
+
MarketState memory _market,
|
|
284
|
+
PYIndex _index,
|
|
285
|
+
uint256 _maxPtIn,
|
|
286
|
+
uint256 _blockTime,
|
|
287
|
+
ApproxParams memory _approx // approx for totalPtToSwap
|
|
288
|
+
)
|
|
289
|
+
internal
|
|
290
|
+
pure
|
|
291
|
+
returns (
|
|
292
|
+
uint256, /*netYtOut*/
|
|
293
|
+
uint256, /*netPtIn*/
|
|
294
|
+
uint256, /*totalPtToSwap*/
|
|
295
|
+
uint256 /*netScyToReserve*/
|
|
296
|
+
)
|
|
297
|
+
{
|
|
298
|
+
Args7 memory arg = Args7(_market, _index, _maxPtIn, _blockTime);
|
|
299
|
+
|
|
300
|
+
MarketPreCompute memory comp = arg.market.getMarketPreCompute(arg.index, arg.blockTime);
|
|
301
|
+
ApproxParamsPtIn memory p = newApproxParamsPtIn(_approx, comp.totalAsset);
|
|
302
|
+
|
|
303
|
+
p.guessMin = Math.max(p.guessMin, arg.maxPtIn);
|
|
304
|
+
|
|
305
|
+
for (uint256 iter = 0; iter < p.maxIteration; ++iter) {
|
|
306
|
+
(bool isGoodSlope, uint256 guess) = nextGuess(p, comp, arg.market.totalPt, iter);
|
|
307
|
+
|
|
308
|
+
if (!isGoodSlope) {
|
|
309
|
+
p.guessMax = guess;
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
(uint256 netAssetOut, uint256 netAssetToReserve) = calcAssetOut(
|
|
314
|
+
arg.market,
|
|
315
|
+
comp,
|
|
316
|
+
guess
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
uint256 netPtPayable = netAssetOut + arg.maxPtIn;
|
|
320
|
+
if (guess <= netPtPayable) {
|
|
321
|
+
uint256 netPtIn = guess - netAssetOut; // guess >= netAssetOut (market invariant)
|
|
322
|
+
if (Math.isASmallerApproxB(netPtIn, arg.maxPtIn, p.eps)) {
|
|
323
|
+
return (netAssetOut, netPtIn, guess, arg.index.assetToScy(netAssetToReserve));
|
|
324
|
+
}
|
|
325
|
+
} else {
|
|
326
|
+
p.guessMax = guess - 1;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
revert("approx fail");
|
|
330
|
+
}
|
|
331
|
+
|
|
275
332
|
////////////////////////////////////////////////////////////////////////////////
|
|
276
333
|
|
|
277
334
|
function calcAssetOut(
|
|
@@ -569,6 +626,65 @@ library MarketApproxPtOutLib {
|
|
|
569
626
|
revert("approx fail");
|
|
570
627
|
}
|
|
571
628
|
|
|
629
|
+
struct Args8 {
|
|
630
|
+
MarketState market;
|
|
631
|
+
PYIndex index;
|
|
632
|
+
uint256 maxYtIn;
|
|
633
|
+
uint256 blockTime;
|
|
634
|
+
uint256 maxScyRedeemableFromPY;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
function approxSwapExactYtForPt(
|
|
638
|
+
MarketState memory _market,
|
|
639
|
+
PYIndex _index,
|
|
640
|
+
uint256 _maxYtIn,
|
|
641
|
+
uint256 _blockTime,
|
|
642
|
+
ApproxParams memory _approx
|
|
643
|
+
)
|
|
644
|
+
internal
|
|
645
|
+
pure
|
|
646
|
+
returns (
|
|
647
|
+
uint256, /*netPtOut*/
|
|
648
|
+
uint256, /*netYtIn*/
|
|
649
|
+
uint256, /*totalPtSwapped*/
|
|
650
|
+
uint256 /*netScyToReserve*/
|
|
651
|
+
)
|
|
652
|
+
{
|
|
653
|
+
Args8 memory arg = Args8(
|
|
654
|
+
_market,
|
|
655
|
+
_index,
|
|
656
|
+
_maxYtIn,
|
|
657
|
+
_blockTime,
|
|
658
|
+
_index.assetToScy(_maxYtIn)
|
|
659
|
+
);
|
|
660
|
+
MarketPreCompute memory comp = arg.market.getMarketPreCompute(arg.index, arg.blockTime);
|
|
661
|
+
ApproxParamsPtOut memory p = newApproxParamsPtOut(_approx, comp, arg.market.totalPt);
|
|
662
|
+
|
|
663
|
+
p.guessMin = Math.max(p.guessMin, arg.maxYtIn);
|
|
664
|
+
|
|
665
|
+
for (uint256 iter = 0; iter < p.maxIteration; ++iter) {
|
|
666
|
+
uint256 guess = nextGuess(p, iter);
|
|
667
|
+
|
|
668
|
+
(uint256 netAssetIn, uint256 netAssetToReserve) = calcAssetIn(arg.market, comp, guess);
|
|
669
|
+
uint256 netScyIn = arg.index.assetToScyUp(netAssetIn);
|
|
670
|
+
|
|
671
|
+
if (netScyIn <= arg.maxScyRedeemableFromPY) {
|
|
672
|
+
p.guessMin = guess;
|
|
673
|
+
if (Math.isASmallerApproxB(netAssetIn, arg.maxYtIn, p.eps)) {
|
|
674
|
+
return (
|
|
675
|
+
guess - arg.maxYtIn,
|
|
676
|
+
arg.maxYtIn,
|
|
677
|
+
guess,
|
|
678
|
+
arg.index.assetToScy(netAssetToReserve)
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
} else {
|
|
682
|
+
p.guessMax = guess - 1;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
revert("approx fail");
|
|
686
|
+
}
|
|
687
|
+
|
|
572
688
|
////////////////////////////////////////////////////////////////////////////////
|
|
573
689
|
|
|
574
690
|
function calcAssetIn(
|
|
@@ -529,6 +529,59 @@ library MarketMathStatic {
|
|
|
529
529
|
);
|
|
530
530
|
}
|
|
531
531
|
|
|
532
|
+
// totalPtToSwap is the param to approx
|
|
533
|
+
function swapExactPtForYt(
|
|
534
|
+
address market,
|
|
535
|
+
uint256 exactPtIn,
|
|
536
|
+
ApproxParams memory approxParams
|
|
537
|
+
)
|
|
538
|
+
external
|
|
539
|
+
returns (
|
|
540
|
+
uint256 netYtOut,
|
|
541
|
+
uint256 totalPtToSwap,
|
|
542
|
+
uint256 netScyFee,
|
|
543
|
+
uint256 priceImpact
|
|
544
|
+
)
|
|
545
|
+
{
|
|
546
|
+
MarketState memory state = IPMarket(market).readState();
|
|
547
|
+
PYIndex index = pyIndex(market);
|
|
548
|
+
|
|
549
|
+
(netYtOut, , totalPtToSwap, netScyFee) = state.approxSwapExactPtForYt(
|
|
550
|
+
index,
|
|
551
|
+
exactPtIn,
|
|
552
|
+
block.timestamp,
|
|
553
|
+
approxParams
|
|
554
|
+
);
|
|
555
|
+
priceImpact = calcPriceImpact(market, totalPtToSwap.neg());
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// totalPtSwapped is the param to approx
|
|
559
|
+
function swapExactYtForPt(
|
|
560
|
+
address market,
|
|
561
|
+
uint256 exactYtIn,
|
|
562
|
+
ApproxParams memory approxParams
|
|
563
|
+
)
|
|
564
|
+
external
|
|
565
|
+
returns (
|
|
566
|
+
uint256 netPtOut,
|
|
567
|
+
uint256 totalPtSwapped,
|
|
568
|
+
uint256 netScyFee,
|
|
569
|
+
uint256 priceImpact
|
|
570
|
+
)
|
|
571
|
+
{
|
|
572
|
+
MarketState memory state = IPMarket(market).readState();
|
|
573
|
+
PYIndex index = pyIndex(market);
|
|
574
|
+
|
|
575
|
+
(netPtOut, , totalPtSwapped, netScyFee) = state.approxSwapExactYtForPt(
|
|
576
|
+
index,
|
|
577
|
+
exactYtIn,
|
|
578
|
+
block.timestamp,
|
|
579
|
+
approxParams
|
|
580
|
+
);
|
|
581
|
+
|
|
582
|
+
priceImpact = calcPriceImpact(market, totalPtSwapped.Int());
|
|
583
|
+
}
|
|
584
|
+
|
|
532
585
|
function pyIndex(address market) public returns (PYIndex index) {
|
|
533
586
|
(, , IPYieldToken YT) = IPMarket(market).readTokens();
|
|
534
587
|
|
|
@@ -570,6 +570,30 @@ contract RouterStatic is Initializable, BoringOwnableUpgradeable, UUPSUpgradeabl
|
|
|
570
570
|
);
|
|
571
571
|
}
|
|
572
572
|
|
|
573
|
+
function swapExactPtForYtStatic(address market, uint256 exactPtIn)
|
|
574
|
+
external
|
|
575
|
+
returns (
|
|
576
|
+
uint256 netYtOut,
|
|
577
|
+
uint256 totalPtToSwap,
|
|
578
|
+
uint256 netScyFee,
|
|
579
|
+
uint256 priceImpact
|
|
580
|
+
)
|
|
581
|
+
{
|
|
582
|
+
return MarketMathStatic.swapExactPtForYt(market, exactPtIn, getDefaultApproxParams());
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function swapExactYtForPtStatic(address market, uint256 exactYtIn)
|
|
586
|
+
external
|
|
587
|
+
returns (
|
|
588
|
+
uint256 netPtOut,
|
|
589
|
+
uint256 totalPtSwapped,
|
|
590
|
+
uint256 netScyFee,
|
|
591
|
+
uint256 priceImpact
|
|
592
|
+
)
|
|
593
|
+
{
|
|
594
|
+
return MarketMathStatic.swapExactYtForPt(market, exactYtIn, getDefaultApproxParams());
|
|
595
|
+
}
|
|
596
|
+
|
|
573
597
|
// ============= OTHER HELPERS =============
|
|
574
598
|
|
|
575
599
|
function mintPYFromScyStatic(address YT, uint256 amountScyToMint)
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"yieldContractFactory": "0x38E5A1D591553b5FF18b151B587745a4A9B206d2",
|
|
8
8
|
"marketFactory": "0xE646E5425fD448b2f9dDF6de12383CcF5275143B",
|
|
9
9
|
"router": "0xa4C21f51DE870a283f362A7331f0C4f8288c3e41",
|
|
10
|
-
"routerStatic": "
|
|
10
|
+
"routerStatic": "0x4ea00Cd73C773764A398e27ed2F789f50F168c52",
|
|
11
11
|
"startTime": 1657756800,
|
|
12
12
|
"vePendle": "0x3AE0fee115057cCF8A0B5255751027C26D83B912",
|
|
13
13
|
"votingController": "0x76815E13679C7F18a406f5BA94E352E656BeE378",
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@pendle/core-v2",
|
|
3
3
|
"description": "Core smart contracts of Pendle Protocol.",
|
|
4
4
|
"license": "BUSL-1.1",
|
|
5
|
-
"version": "0.11.
|
|
5
|
+
"version": "0.11.9-testnet",
|
|
6
6
|
"homepage": "https://pendle.finance",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"pendle",
|
|
@@ -37,8 +37,6 @@
|
|
|
37
37
|
"typescript": "^4.8.2"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
|
-
"prepublish": "yarn hardhat compile",
|
|
41
|
-
"publish": "npm publish",
|
|
42
40
|
"compile": "yarn hardhat compile",
|
|
43
41
|
"size": "yarn hardhat size-contracts",
|
|
44
42
|
"clean": "yarn hardhat clean",
|