@pendle/core-v2 0.2.1 → 0.2.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/core/PendleBaseToken.sol +0 -4
- package/contracts/core/PendleMarket.sol +4 -7
- package/contracts/core/PendleMarketFactory.sol +2 -2
- package/contracts/core/PendleOwnershipToken.sol +0 -2
- package/contracts/core/router/PendleRouterProxy.sol +15 -1
- package/contracts/core/router/PendleRouterStatic.sol +82 -0
- package/contracts/interfaces/IPRouterStatic.sol +35 -0
- package/contracts/libraries/math/FixedPoint.sol +4 -7
- package/contracts/libraries/math/LogExpMath.sol +377 -365
- package/contracts/libraries/math/MarketMathLib.sol +25 -17
- package/package.json +1 -1
- package/typechain-types/IPRouterStatic.ts +307 -0
- package/typechain-types/IPRouterView.ts +307 -0
- package/typechain-types/PendleBaseToken.ts +0 -30
- package/typechain-types/PendleMarket.ts +19 -46
- package/typechain-types/PendleMarketFactory.ts +5 -5
- package/typechain-types/PendleOwnershipToken.ts +0 -30
- package/typechain-types/PendleRouterProxy.ts +21 -0
- package/typechain-types/PendleRouterStaticUpg.ts +307 -0
- package/typechain-types/PendleRouterViewUpg.ts +307 -0
- package/typechain-types/PendleYieldToken.ts +0 -30
- package/typechain-types/factories/IPRouterStatic__factory.ts +190 -0
- package/typechain-types/factories/IPRouterView__factory.ts +187 -0
- package/typechain-types/factories/PendleAaveV3SCY__factory.ts +1 -1
- package/typechain-types/factories/PendleBaseToken__factory.ts +0 -38
- package/typechain-types/factories/PendleBenQiErc20SCY__factory.ts +1 -1
- package/typechain-types/factories/PendleBtrflyScy__factory.ts +1 -1
- package/typechain-types/factories/PendleMarketFactory__factory.ts +2 -2
- package/typechain-types/factories/PendleMarket__factory.ts +19 -57
- package/typechain-types/factories/PendleOwnershipToken__factory.ts +1 -39
- package/typechain-types/factories/PendleRouterCoreUpg__factory.ts +1 -1
- package/typechain-types/factories/PendleRouterProxy__factory.ts +23 -1
- package/typechain-types/factories/PendleRouterStaticUpg__factory.ts +269 -0
- package/typechain-types/factories/PendleRouterViewUpg__factory.ts +265 -0
- package/typechain-types/factories/PendleRouterYTUpg__factory.ts +1 -1
- package/typechain-types/factories/PendleYearnVaultScy__factory.ts +1 -1
- package/typechain-types/factories/PendleYieldContractFactory__factory.ts +1 -1
- package/typechain-types/factories/PendleYieldToken__factory.ts +1 -39
- package/typechain-types/hardhat.d.ts +18 -0
- package/typechain-types/index.ts +4 -0
|
@@ -12,10 +12,6 @@ abstract contract PendleBaseToken is ERC20, IPBaseToken {
|
|
|
12
12
|
uint256 public immutable expiry;
|
|
13
13
|
address public immutable factory;
|
|
14
14
|
|
|
15
|
-
event Burn(address indexed user, uint256 amount);
|
|
16
|
-
|
|
17
|
-
event Mint(address indexed user, uint256 amount);
|
|
18
|
-
|
|
19
15
|
constructor(
|
|
20
16
|
string memory _name,
|
|
21
17
|
string memory _symbol,
|
|
@@ -27,9 +27,6 @@ contract PendleMarket is PendleBaseToken, IPMarket, ReentrancyGuard {
|
|
|
27
27
|
|
|
28
28
|
string private constant NAME = "Pendle Market";
|
|
29
29
|
string private constant SYMBOL = "PENDLE-LPT";
|
|
30
|
-
uint256 private constant MINIMUM_LIQUIDITY = 10**3;
|
|
31
|
-
uint8 private constant DECIMALS = 18;
|
|
32
|
-
int256 internal constant RATE_PRECISION = 1e9;
|
|
33
30
|
|
|
34
31
|
address public immutable OT;
|
|
35
32
|
address public immutable SCY;
|
|
@@ -37,7 +34,7 @@ contract PendleMarket is PendleBaseToken, IPMarket, ReentrancyGuard {
|
|
|
37
34
|
|
|
38
35
|
int256 public immutable scalarRoot;
|
|
39
36
|
uint256 public immutable feeRateRoot; // allow fee to be changable?
|
|
40
|
-
int256 public immutable
|
|
37
|
+
int256 public immutable initialAnchor;
|
|
41
38
|
|
|
42
39
|
uint256 public immutable rateOracleTimeWindow;
|
|
43
40
|
int8 public immutable reserveFeePercent;
|
|
@@ -49,7 +46,7 @@ contract PendleMarket is PendleBaseToken, IPMarket, ReentrancyGuard {
|
|
|
49
46
|
uint256 _rateOracleTimeWindow,
|
|
50
47
|
uint256 _feeRateRoot,
|
|
51
48
|
int256 _scalarRoot,
|
|
52
|
-
int256
|
|
49
|
+
int256 _initialAnchor,
|
|
53
50
|
uint8 _reserveFeePercent
|
|
54
51
|
) PendleBaseToken(NAME, SYMBOL, 18, IPOwnershipToken(_OT).expiry()) {
|
|
55
52
|
OT = _OT;
|
|
@@ -61,7 +58,7 @@ contract PendleMarket is PendleBaseToken, IPMarket, ReentrancyGuard {
|
|
|
61
58
|
|
|
62
59
|
require(_reserveFeePercent <= 100, "invalid fee rate");
|
|
63
60
|
reserveFeePercent = int8(_reserveFeePercent);
|
|
64
|
-
|
|
61
|
+
initialAnchor = _initialAnchor;
|
|
65
62
|
}
|
|
66
63
|
|
|
67
64
|
function addLiquidity(
|
|
@@ -90,7 +87,7 @@ contract PendleMarket is PendleBaseToken, IPMarket, ReentrancyGuard {
|
|
|
90
87
|
|
|
91
88
|
// initializing the market
|
|
92
89
|
if (lpToReserve != 0) {
|
|
93
|
-
market.setInitialImpliedRate(index,
|
|
90
|
+
market.setInitialImpliedRate(index, initialAnchor, block.timestamp);
|
|
94
91
|
_mint(address(1), lpToReserve);
|
|
95
92
|
}
|
|
96
93
|
|
|
@@ -24,7 +24,7 @@ contract PendleMarketFactory is PermissionsV2, IPMarketFactory {
|
|
|
24
24
|
address OT,
|
|
25
25
|
uint256 feeRateRoot,
|
|
26
26
|
int256 scalarRoot,
|
|
27
|
-
int256
|
|
27
|
+
int256 initialAnchor,
|
|
28
28
|
uint8 reserveFeePercent,
|
|
29
29
|
uint256 rateOracleTimeWindow
|
|
30
30
|
) external returns (address market) {
|
|
@@ -42,7 +42,7 @@ contract PendleMarketFactory is PermissionsV2, IPMarketFactory {
|
|
|
42
42
|
rateOracleTimeWindow,
|
|
43
43
|
feeRateRoot,
|
|
44
44
|
scalarRoot,
|
|
45
|
-
|
|
45
|
+
initialAnchor,
|
|
46
46
|
reserveFeePercent
|
|
47
47
|
)
|
|
48
48
|
);
|
|
@@ -34,11 +34,9 @@ contract PendleOwnershipToken is PendleBaseToken, IPOwnershipToken {
|
|
|
34
34
|
|
|
35
35
|
function burnByYT(address user, uint256 amount) external onlyYT {
|
|
36
36
|
_burn(user, amount);
|
|
37
|
-
emit Burn(user, amount);
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
function mintByYT(address user, uint256 amount) external onlyYT {
|
|
41
40
|
_mint(user, amount);
|
|
42
|
-
emit Mint(user, amount);
|
|
43
41
|
}
|
|
44
42
|
}
|
|
@@ -7,6 +7,7 @@ import "../misc/BoringOwnableUpg.sol";
|
|
|
7
7
|
import "@openzeppelin/contracts/proxy/Proxy.sol";
|
|
8
8
|
import "../../interfaces/IPRouterCore.sol";
|
|
9
9
|
import "../../interfaces/IPRouterYT.sol";
|
|
10
|
+
import "../../interfaces/IPRouterStatic.sol";
|
|
10
11
|
|
|
11
12
|
/// @dev this contract will be deployed behind an ERC1967 proxy
|
|
12
13
|
/// calls to the ERC1967 proxy will be resolved at this contract, and proxied again to the
|
|
@@ -14,10 +15,12 @@ import "../../interfaces/IPRouterYT.sol";
|
|
|
14
15
|
contract PendleRouterProxy is Proxy, Initializable, UUPSUpgradeable, BoringOwnableUpg {
|
|
15
16
|
address public immutable PENDLE_ROUTER_CORE;
|
|
16
17
|
address public immutable PENDLE_ROUTER_YT;
|
|
18
|
+
address public immutable PENDLE_ROUTER_STATIC;
|
|
17
19
|
|
|
18
|
-
constructor(address _PENDLE_ROUTER_CORE, address _PENDLE_ROUTER_YT) {
|
|
20
|
+
constructor(address _PENDLE_ROUTER_CORE, address _PENDLE_ROUTER_YT, address _PENDLE_ROUTER_STATIC) {
|
|
19
21
|
PENDLE_ROUTER_CORE = _PENDLE_ROUTER_CORE;
|
|
20
22
|
PENDLE_ROUTER_YT = _PENDLE_ROUTER_YT;
|
|
23
|
+
PENDLE_ROUTER_STATIC = _PENDLE_ROUTER_STATIC;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
function initialize() external initializer {
|
|
@@ -53,6 +56,17 @@ contract PendleRouterProxy is Proxy, Initializable, UUPSUpgradeable, BoringOwnab
|
|
|
53
56
|
// only ROUTER_YT is doing callback
|
|
54
57
|
return PENDLE_ROUTER_YT;
|
|
55
58
|
}
|
|
59
|
+
/// FROM HERE ONWARDS, ONLY HAVE STATIC & VIEW FUNCTIONS
|
|
60
|
+
else if (
|
|
61
|
+
sig == IPRouterStatic.addLiquidityStatic.selector ||
|
|
62
|
+
sig == IPRouterStatic.removeLiquidityStatic.selector ||
|
|
63
|
+
sig == IPRouterStatic.swapOtForScyStatic.selector ||
|
|
64
|
+
sig == IPRouterStatic.swapScyForOtStatic.selector ||
|
|
65
|
+
sig == IPRouterStatic.scyIndex.selector ||
|
|
66
|
+
sig == IPRouterStatic.getOtImpliedYield.selector
|
|
67
|
+
) {
|
|
68
|
+
return PENDLE_ROUTER_STATIC;
|
|
69
|
+
}
|
|
56
70
|
require(false, "invalid market sig");
|
|
57
71
|
}
|
|
58
72
|
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity 0.8.9;
|
|
3
|
+
|
|
4
|
+
import "../../interfaces/IPRouterStatic.sol";
|
|
5
|
+
|
|
6
|
+
contract PendleRouterStaticUpg is IPRouterStatic {
|
|
7
|
+
using MarketMathLib for MarketParameters;
|
|
8
|
+
using FixedPoint for uint256;
|
|
9
|
+
using FixedPoint for int256;
|
|
10
|
+
using LogExpMath for int256;
|
|
11
|
+
|
|
12
|
+
/// @dev since this contract will be proxied, it must not contains non-immutable variabless
|
|
13
|
+
constructor(
|
|
14
|
+
address _joeRouter,
|
|
15
|
+
address _joeFactory,
|
|
16
|
+
address _marketFactory //solhint-disable-next-line no-empty-blocks
|
|
17
|
+
) {}
|
|
18
|
+
|
|
19
|
+
function addLiquidityStatic(
|
|
20
|
+
address market,
|
|
21
|
+
uint256 scyDesired,
|
|
22
|
+
uint256 otDesired
|
|
23
|
+
)
|
|
24
|
+
external
|
|
25
|
+
returns (
|
|
26
|
+
uint256 netLpOut,
|
|
27
|
+
uint256 scyUsed,
|
|
28
|
+
uint256 otUsed
|
|
29
|
+
)
|
|
30
|
+
{
|
|
31
|
+
MarketParameters memory state = IPMarket(market).readState();
|
|
32
|
+
(, netLpOut, scyUsed, otUsed) = state.addLiquidity(
|
|
33
|
+
scyIndex(market),
|
|
34
|
+
scyDesired,
|
|
35
|
+
otDesired
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function removeLiquidityStatic(address market, uint256 lpToRemove)
|
|
40
|
+
external
|
|
41
|
+
view
|
|
42
|
+
returns (uint256 netScyOut, uint256 netOtOut)
|
|
43
|
+
{
|
|
44
|
+
MarketParameters memory state = IPMarket(market).readState();
|
|
45
|
+
(netScyOut, netOtOut) = state.removeLiquidity(lpToRemove);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function swapOtForScyStatic(address market, uint256 exactOtIn)
|
|
49
|
+
external
|
|
50
|
+
returns (uint256 netScyOut, uint256 netScyFee)
|
|
51
|
+
{
|
|
52
|
+
MarketParameters memory state = IPMarket(market).readState();
|
|
53
|
+
(netScyOut, netScyFee) = state.swapExactOtForScy(
|
|
54
|
+
scyIndex(market),
|
|
55
|
+
exactOtIn,
|
|
56
|
+
block.timestamp
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function swapScyForOtStatic(address market, uint256 exactOtOut)
|
|
61
|
+
external
|
|
62
|
+
returns (uint256 netScyIn, uint256 netScyFee)
|
|
63
|
+
{
|
|
64
|
+
MarketParameters memory state = IPMarket(market).readState();
|
|
65
|
+
(netScyIn, netScyFee) = state.swapScyForExactOt(
|
|
66
|
+
scyIndex(market),
|
|
67
|
+
exactOtOut,
|
|
68
|
+
block.timestamp
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function scyIndex(address market) public returns (SCYIndex index) {
|
|
73
|
+
return SCYIndexLib.newIndex(IPMarket(market).SCY());
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function getOtImpliedYield(address market) external view returns (int256) {
|
|
77
|
+
MarketParameters memory state = IPMarket(market).readState();
|
|
78
|
+
|
|
79
|
+
int256 lnImpliedRate = (state.lastImpliedRate).Int();
|
|
80
|
+
return lnImpliedRate.exp();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity 0.8.9;
|
|
3
|
+
|
|
4
|
+
import "../libraries/math/MarketMathLib.sol";
|
|
5
|
+
|
|
6
|
+
interface IPRouterStatic {
|
|
7
|
+
function addLiquidityStatic(
|
|
8
|
+
address market,
|
|
9
|
+
uint256 scyDesired,
|
|
10
|
+
uint256 otDesired
|
|
11
|
+
)
|
|
12
|
+
external
|
|
13
|
+
returns (
|
|
14
|
+
uint256 netLpOut,
|
|
15
|
+
uint256 scyUsed,
|
|
16
|
+
uint256 otUsed
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
function removeLiquidityStatic(address market, uint256 lpToRemove)
|
|
20
|
+
external
|
|
21
|
+
view
|
|
22
|
+
returns (uint256 netScyOut, uint256 netOtOut);
|
|
23
|
+
|
|
24
|
+
function swapOtForScyStatic(address market, uint256 exactOtIn)
|
|
25
|
+
external
|
|
26
|
+
returns (uint256 netScyOut, uint256 netScyFee);
|
|
27
|
+
|
|
28
|
+
function swapScyForOtStatic(address market, uint256 exactOtOut)
|
|
29
|
+
external
|
|
30
|
+
returns (uint256 netScyIn, uint256 netScyFee);
|
|
31
|
+
|
|
32
|
+
function scyIndex(address market) external returns (SCYIndex index);
|
|
33
|
+
|
|
34
|
+
function getOtImpliedYield(address market) external view returns (int256);
|
|
35
|
+
}
|
|
@@ -24,9 +24,6 @@ library FixedPoint {
|
|
|
24
24
|
|
|
25
25
|
uint256 internal constant MAX_POW_RELATIVE_ERROR = 10000; // 10^(-14)
|
|
26
26
|
|
|
27
|
-
// Minimum base for the power function when the exponent is 'free' (larger than ONE).
|
|
28
|
-
uint256 internal constant MIN_POW_BASE_FREE_EXPONENT = 0.7e18;
|
|
29
|
-
|
|
30
27
|
function subMax0(uint256 a, uint256 b) internal pure returns (uint256) {
|
|
31
28
|
return (a >= b ? a - b : 0);
|
|
32
29
|
}
|
|
@@ -49,7 +46,7 @@ library FixedPoint {
|
|
|
49
46
|
|
|
50
47
|
function mulDown(int256 a, int256 b) internal pure returns (int256) {
|
|
51
48
|
int256 product = a * b;
|
|
52
|
-
return product /
|
|
49
|
+
return product / ONE_INT;
|
|
53
50
|
}
|
|
54
51
|
|
|
55
52
|
function mulDown(int256 a, uint256 b) internal pure returns (int256) {
|
|
@@ -89,7 +86,7 @@ library FixedPoint {
|
|
|
89
86
|
if (a == 0) {
|
|
90
87
|
return 0;
|
|
91
88
|
} else {
|
|
92
|
-
int256 aInflated = a *
|
|
89
|
+
int256 aInflated = a * ONE_INT;
|
|
93
90
|
return aInflated / b;
|
|
94
91
|
}
|
|
95
92
|
}
|
|
@@ -192,12 +189,12 @@ library FixedPoint {
|
|
|
192
189
|
}
|
|
193
190
|
|
|
194
191
|
function Int128(int256 x) internal pure returns (int128) {
|
|
195
|
-
require(
|
|
192
|
+
require(x <= type(int128).max);
|
|
196
193
|
return int128(x);
|
|
197
194
|
}
|
|
198
195
|
|
|
199
196
|
function Uint32(uint256 x) internal pure returns (uint32) {
|
|
200
|
-
require(
|
|
197
|
+
require(x <= type(uint32).max);
|
|
201
198
|
return uint32(x);
|
|
202
199
|
}
|
|
203
200
|
|