@pendle/core-v2 6.0.0 → 6.1.0-cross-chain-pt
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/cross-chain/FixedPricePTAMM.sol/FixedPricePTAMM.dbg.json +4 -0
- package/build/artifacts/contracts/cross-chain/FixedPricePTAMM.sol/FixedPricePTAMM.json +466 -0
- package/build/artifacts/contracts/cross-chain/factory/hub/PendlePTOFTAdapterFactory.sol/PendlePTOFTAdapterFactory.dbg.json +4 -0
- package/build/artifacts/contracts/cross-chain/factory/hub/PendlePTOFTAdapterFactory.sol/PendlePTOFTAdapterFactory.json +191 -0
- package/build/artifacts/contracts/cross-chain/oftImpl/hub/OFTAdapterImpl.sol/OFTAdapterImpl.dbg.json +4 -0
- package/build/artifacts/contracts/cross-chain/oftImpl/hub/OFTAdapterImpl.sol/OFTAdapterImpl.json +1265 -0
- package/build/artifacts/contracts/cross-chain/oftImpl/spoke/PendleBridgedPrincipalToken.sol/BasePendleBridgedPrincipalToken.dbg.json +4 -0
- package/build/artifacts/contracts/cross-chain/oftImpl/spoke/PendleBridgedPrincipalToken.sol/BasePendleBridgedPrincipalToken.json +1527 -0
- package/build/artifacts/contracts/cross-chain/oftImpl/spoke/PendleBridgedPrincipalToken.sol/PendleBridgedPrincipalToken_18Decimals.dbg.json +4 -0
- package/build/artifacts/contracts/cross-chain/oftImpl/spoke/PendleBridgedPrincipalToken.sol/PendleBridgedPrincipalToken_18Decimals.json +1558 -0
- package/build/artifacts/contracts/cross-chain/oftImpl/spoke/PendleBridgedPrincipalToken.sol/PendleBridgedPrincipalToken_6Decimals.dbg.json +4 -0
- package/build/artifacts/contracts/cross-chain/oftImpl/spoke/PendleBridgedPrincipalToken.sol/PendleBridgedPrincipalToken_6Decimals.json +1558 -0
- package/build/artifacts/contracts/cross-chain/oftImpl/spoke/PendleBridgedPrincipalToken.sol/PendleBridgedPrincipalToken_8Decimals.dbg.json +4 -0
- package/build/artifacts/contracts/cross-chain/oftImpl/spoke/PendleBridgedPrincipalToken.sol/PendleBridgedPrincipalToken_8Decimals.json +1558 -0
- package/build/artifacts/contracts/interfaces/IPBridgedPrincipalToken.sol/IPBridgedPrincipalToken.dbg.json +4 -0
- package/build/artifacts/contracts/interfaces/IPBridgedPrincipalToken.sol/IPBridgedPrincipalToken.json +928 -0
- package/build/artifacts/contracts/interfaces/IPChainlinkOracleEssential.sol/IPChainlinkOracleEssential.dbg.json +4 -0
- package/build/artifacts/contracts/interfaces/IPChainlinkOracleEssential.sol/IPChainlinkOracleEssential.json +57 -0
- package/build/artifacts/contracts/interfaces/IPFixedPricePTAMM.sol/IPFixedPricePTAMM.dbg.json +4 -0
- package/build/artifacts/contracts/interfaces/IPFixedPricePTAMM.sol/IPFixedPricePTAMM.json +302 -0
- package/build/artifacts/contracts/interfaces/IPFixedPricePTAMM.sol/IPFixedPricePTAMMSwapCallback.dbg.json +4 -0
- package/build/artifacts/contracts/interfaces/IPFixedPricePTAMM.sol/IPFixedPricePTAMMSwapCallback.json +34 -0
- package/build/artifacts/contracts/interfaces/IPPTOFTAdapterFactory.sol/IPPTOFTAdapterFactory.dbg.json +4 -0
- package/build/artifacts/contracts/interfaces/IPPTOFTAdapterFactory.sol/IPPTOFTAdapterFactory.json +81 -0
- package/build/artifacts/contracts/oracles/internal/PendleSparkLinearDiscountOracle.sol/PTExpiry.dbg.json +1 -1
- package/build/artifacts/contracts/oracles/internal/PendleSparkLinearDiscountOracle.sol/PendleSparkLinearDiscountOracle.dbg.json +1 -1
- package/build/artifacts/contracts/oracles/internal/PendleSparkLinearDiscountOracle.sol/PendleSparkLinearDiscountOracle.json +2 -2
- package/build/artifacts/contracts/oracles/internal/PendleSparkLinearDiscountOracleFactory.sol/PendleSparkLinearDiscountOracleFactory.dbg.json +1 -1
- package/build/artifacts/contracts/oracles/internal/PendleSparkLinearDiscountOracleFactory.sol/PendleSparkLinearDiscountOracleFactory.json +2 -2
- package/contracts/cross-chain/FixedPricePTAMM.sol +121 -0
- package/contracts/cross-chain/factory/hub/PendlePTOFTAdapterFactory.sol +33 -0
- package/contracts/cross-chain/oftImpl/hub/OFTAdapterImpl.sol +12 -0
- package/contracts/cross-chain/oftImpl/spoke/PendleBridgedPrincipalToken.sol +61 -0
- package/contracts/interfaces/IPBridgedPrincipalToken.sol +11 -0
- package/contracts/interfaces/IPChainlinkOracleEssential.sol +11 -0
- package/contracts/interfaces/IPFixedPricePTAMM.sol +54 -0
- package/contracts/interfaces/IPPTOFTAdapterFactory.sol +12 -0
- package/contracts/oracles/internal/PendleSparkLinearDiscountOracle.sol +3 -1
- package/deployments/1-core.json +2 -1
- package/package.json +4 -1
- package/typechain-types/factories/PendleSparkLinearDiscountOracleFactory__factory.ts +1 -1
- package/typechain-types/factories/PendleSparkLinearDiscountOracle__factory.ts +1 -1
- package/typechain-types/hardhat.d.ts +108 -0
- package/typechain-types/index.ts +24 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import {IPFixedPricePTAMM, IPFixedPricePTAMMSwapCallback} from "../interfaces/IPFixedPricePTAMM.sol";
|
|
5
|
+
import {IPChainlinkOracleEssential} from "../interfaces/IPChainlinkOracleEssential.sol";
|
|
6
|
+
import {IPBridgedPrincipalToken} from "../interfaces/IPBridgedPrincipalToken.sol";
|
|
7
|
+
|
|
8
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
9
|
+
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
|
|
10
|
+
|
|
11
|
+
import {PMath} from "../core/libraries/math/PMath.sol";
|
|
12
|
+
import {BoringOwnableUpgradeableV2} from "../core/libraries/BoringOwnableUpgradeableV2.sol";
|
|
13
|
+
import {TokenHelper} from "../core/libraries/TokenHelper.sol";
|
|
14
|
+
|
|
15
|
+
contract FixedPricePTAMM is IPFixedPricePTAMM, BoringOwnableUpgradeableV2, ReentrancyGuardUpgradeable, TokenHelper {
|
|
16
|
+
// cast index-erc7201 "pendle.FixedPricePTAMM.storage"
|
|
17
|
+
uint256 internal constant STORAGE_SLOT = 0xbbf04d9aae855c6bd76c8f4ba7a918994ad0d002f537323e58c83cbfe5249000;
|
|
18
|
+
|
|
19
|
+
error OracleNotSet(address PT, address token);
|
|
20
|
+
error InsufficientTokenForTrade(address token, uint256 actualAmount, uint256 requiredAmount);
|
|
21
|
+
error InsufficientPtReceived(address PT, uint256 actualAmount, uint256 requiredAmount);
|
|
22
|
+
|
|
23
|
+
using PMath for uint256;
|
|
24
|
+
using PMath for int256;
|
|
25
|
+
|
|
26
|
+
constructor() {
|
|
27
|
+
_disableInitializers();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function initialize(address _owner) external initializer {
|
|
31
|
+
__BoringOwnableV2_init(_owner);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
struct Storage {
|
|
35
|
+
mapping(address PT => mapping(address token => address oracle)) priceOracle;
|
|
36
|
+
mapping(address token => uint256) totalToken;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function $() internal pure returns (Storage storage res) {
|
|
40
|
+
assembly ("memory-safe") {
|
|
41
|
+
res.slot := STORAGE_SLOT
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function priceOracle(address PT, address token) public view returns (IPChainlinkOracleEssential) {
|
|
46
|
+
address res = $().priceOracle[PT][token];
|
|
47
|
+
if (res == address(0)) revert OracleNotSet(PT, token);
|
|
48
|
+
return IPChainlinkOracleEssential(res);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getPtToTokenPrice(address PT, address token) public view returns (uint256) {
|
|
52
|
+
(, int256 ptPrice, , , ) = priceOracle(PT, token).latestRoundData();
|
|
53
|
+
return ptPrice.Uint();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function swapPtForExactToken(
|
|
57
|
+
address receiver,
|
|
58
|
+
address PT,
|
|
59
|
+
address token,
|
|
60
|
+
uint256 exactTokenOut,
|
|
61
|
+
bytes calldata data
|
|
62
|
+
) external payable nonReentrant returns (uint256 netPtIn) {
|
|
63
|
+
netPtIn = exactTokenOut.divDown(getPtToTokenPrice(PT, token));
|
|
64
|
+
_swap(receiver, PT, netPtIn, token, exactTokenOut, data);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function swapExactPtForToken(
|
|
68
|
+
address receiver,
|
|
69
|
+
address PT,
|
|
70
|
+
uint256 exactPtIn,
|
|
71
|
+
address token,
|
|
72
|
+
bytes calldata data
|
|
73
|
+
) external payable nonReentrant returns (uint256 netTokenOut) {
|
|
74
|
+
netTokenOut = exactPtIn.mulDown(getPtToTokenPrice(PT, token));
|
|
75
|
+
_swap(receiver, PT, exactPtIn, token, netTokenOut, data);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function _swap(
|
|
79
|
+
address receiver,
|
|
80
|
+
address PT,
|
|
81
|
+
uint256 exactPtIn,
|
|
82
|
+
address token,
|
|
83
|
+
uint256 exactTokenOut,
|
|
84
|
+
bytes calldata data
|
|
85
|
+
) internal {
|
|
86
|
+
if ($().totalToken[token] < exactTokenOut)
|
|
87
|
+
revert InsufficientTokenForTrade(token, $().totalToken[token], exactTokenOut);
|
|
88
|
+
|
|
89
|
+
_transferOut(token, receiver, exactTokenOut);
|
|
90
|
+
$().totalToken[token] -= exactTokenOut;
|
|
91
|
+
|
|
92
|
+
if (data.length > 0) {
|
|
93
|
+
IPFixedPricePTAMMSwapCallback(msg.sender).swapCallback(exactTokenOut, exactPtIn, data);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
$().totalToken[PT] += exactPtIn;
|
|
97
|
+
if (_selfBalance(PT) < $().totalToken[PT])
|
|
98
|
+
revert InsufficientPtReceived(PT, _selfBalance(PT), $().totalToken[PT]);
|
|
99
|
+
|
|
100
|
+
emit Swap(msg.sender, receiver, PT, exactPtIn, token, exactTokenOut);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Admin functions
|
|
104
|
+
|
|
105
|
+
function setPriceOracle(address PT, address token, address _priceOracle) external onlyOwner {
|
|
106
|
+
$().priceOracle[PT][token] = _priceOracle;
|
|
107
|
+
emit PriceOracleUpdated(PT, token, _priceOracle);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function addFund(address token, uint256 amount) external payable onlyOwner {
|
|
111
|
+
_transferIn(token, owner, amount);
|
|
112
|
+
$().totalToken[token] += amount;
|
|
113
|
+
emit Seeded(token, amount);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function removeFund(address token, uint256 amount) external onlyOwner {
|
|
117
|
+
_transferOut(token, owner, amount);
|
|
118
|
+
$().totalToken[token] -= amount;
|
|
119
|
+
emit Unseeded(token, amount);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import {IPPTOFTAdapterFactory} from "../../../interfaces/IPPTOFTAdapterFactory.sol";
|
|
5
|
+
import {BoringOwnableUpgradeableV2} from "../../../core/libraries/BoringOwnableUpgradeableV2.sol";
|
|
6
|
+
import {OFTAdapterImpl} from "../..//oftImpl/hub/OFTAdapterImpl.sol";
|
|
7
|
+
|
|
8
|
+
contract PendlePTOFTAdapterFactory is IPPTOFTAdapterFactory, BoringOwnableUpgradeableV2 {
|
|
9
|
+
error PTOFTAdapterExisted(address pt);
|
|
10
|
+
|
|
11
|
+
address internal immutable _lzEndpoint;
|
|
12
|
+
|
|
13
|
+
constructor(address lzEndpoint) {
|
|
14
|
+
_disableInitializers();
|
|
15
|
+
_lzEndpoint = lzEndpoint;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function initialize(address _owner) external initializer {
|
|
19
|
+
__BoringOwnableV2_init(_owner);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
mapping(address pt => address) public ptAdapter;
|
|
23
|
+
|
|
24
|
+
function createPtAdapter(address pt) external override onlyOwner returns (address) {
|
|
25
|
+
if (ptAdapter[pt] != address(0)) revert PTOFTAdapterExisted(pt);
|
|
26
|
+
|
|
27
|
+
OFTAdapterImpl adapter = new OFTAdapterImpl(pt, _lzEndpoint, owner);
|
|
28
|
+
adapter.transferOwnership(owner);
|
|
29
|
+
emit PtAdapterCreated(pt, address(adapter));
|
|
30
|
+
|
|
31
|
+
return ptAdapter[pt] = address(adapter);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.0;
|
|
4
|
+
|
|
5
|
+
import {OFTAdapter} from "@layerzerolabs/oft-evm/contracts/OFTAdapter.sol";
|
|
6
|
+
|
|
7
|
+
// @notice Base OFT contract, without any additional functionality (like RateLimiter).
|
|
8
|
+
// @dev This contract inherits Ownable from OpenZeppelin v4.
|
|
9
|
+
// @dev Sender is set as the contract owner at deployment.
|
|
10
|
+
contract OFTAdapterImpl is OFTAdapter {
|
|
11
|
+
constructor(address _token, address _endpoint, address _delegate) OFTAdapter(_token, _endpoint, _delegate) {}
|
|
12
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import {IPBridgedPrincipalToken} from "../../../interfaces/IPBridgedPrincipalToken.sol";
|
|
5
|
+
import {OFT, OFTCore, IOFT} from "@layerzerolabs/oft-evm/contracts/OFT.sol";
|
|
6
|
+
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
|
7
|
+
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
8
|
+
|
|
9
|
+
abstract contract BasePendleBridgedPrincipalToken is IPBridgedPrincipalToken, OFT {
|
|
10
|
+
uint256 public immutable expiry;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
string memory _name,
|
|
14
|
+
string memory _symbol,
|
|
15
|
+
address _lzEndpoint,
|
|
16
|
+
address _delegate,
|
|
17
|
+
uint256 _expiry
|
|
18
|
+
) OFT(_name, _symbol, _lzEndpoint, _delegate) {
|
|
19
|
+
expiry = _expiry;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The below contracts only overrides the `decimals()` and `sharedDecimals()` function
|
|
25
|
+
* - For Pendle PT, the decimals are based on the underlying asset. So we need
|
|
26
|
+
* to set the decimals correctly at **deployment**.
|
|
27
|
+
* - For technical reason, in OFT's constructor, the `decimals()` function was
|
|
28
|
+
* invoked.
|
|
29
|
+
* (https://github.com/LayerZero-Labs/devtools/blob/feb000c1717ee89f965996cc9ab5a8a75effbcab/packages/oft-evm/contracts/OFT.sol#L25)
|
|
30
|
+
* - The current best way to do this is to hard-code the decimals in the contracts.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
// prettier-ignore
|
|
34
|
+
contract PendleBridgedPrincipalToken_18Decimals is BasePendleBridgedPrincipalToken {
|
|
35
|
+
constructor(string memory _name, string memory _symbol, address _lzEndpoint, address _delegate, uint256 _expiry)
|
|
36
|
+
BasePendleBridgedPrincipalToken(_name, _symbol, _lzEndpoint, _delegate, _expiry)
|
|
37
|
+
{}
|
|
38
|
+
|
|
39
|
+
function decimals() public pure override(ERC20, IERC20Metadata) returns (uint8) { return 18; }
|
|
40
|
+
function sharedDecimals() public pure override(OFTCore, IOFT) returns (uint8) { return 6; }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// prettier-ignore
|
|
44
|
+
contract PendleBridgedPrincipalToken_6Decimals is BasePendleBridgedPrincipalToken {
|
|
45
|
+
constructor(string memory _name, string memory _symbol, address _lzEndpoint, address _delegate, uint256 _expiry)
|
|
46
|
+
BasePendleBridgedPrincipalToken(_name, _symbol, _lzEndpoint, _delegate, _expiry)
|
|
47
|
+
{}
|
|
48
|
+
|
|
49
|
+
function decimals() public pure override(ERC20, IERC20Metadata) returns (uint8) { return 6; }
|
|
50
|
+
function sharedDecimals() public pure override(OFTCore, IOFT) returns (uint8) { return 6; }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// prettier-ignore
|
|
54
|
+
contract PendleBridgedPrincipalToken_8Decimals is BasePendleBridgedPrincipalToken {
|
|
55
|
+
constructor(string memory _name, string memory _symbol, address _lzEndpoint, address _delegate, uint256 _expiry)
|
|
56
|
+
BasePendleBridgedPrincipalToken(_name, _symbol, _lzEndpoint, _delegate, _expiry)
|
|
57
|
+
{}
|
|
58
|
+
|
|
59
|
+
function decimals() public pure override(ERC20, IERC20Metadata) returns (uint8) { return 8; }
|
|
60
|
+
function sharedDecimals() public pure override(OFTCore, IOFT) returns (uint8) { return 6; }
|
|
61
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
5
|
+
import {IOFT} from "@layerzerolabs/oft-evm/contracts/interfaces/IOFT.sol";
|
|
6
|
+
import {IOAppCore} from "@layerzerolabs/oapp-evm/contracts/oapp/interfaces/IOAppCore.sol";
|
|
7
|
+
import {IOAppOptionsType3} from "@layerzerolabs/oapp-evm/contracts/oapp/interfaces/IOAppOptionsType3.sol";
|
|
8
|
+
|
|
9
|
+
interface IPBridgedPrincipalToken is IOFT, IOAppCore, IOAppOptionsType3, IERC20Metadata {
|
|
10
|
+
function expiry() external view returns (uint256);
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
interface IPChainlinkOracleEssential {
|
|
5
|
+
function decimals() external view returns (uint8);
|
|
6
|
+
|
|
7
|
+
function latestRoundData()
|
|
8
|
+
external
|
|
9
|
+
view
|
|
10
|
+
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
|
|
11
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import {IPBridgedPrincipalToken} from "./IPBridgedPrincipalToken.sol";
|
|
5
|
+
import {IPChainlinkOracleEssential} from "../interfaces/IPChainlinkOracleEssential.sol";
|
|
6
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
7
|
+
|
|
8
|
+
interface IPFixedPricePTAMM {
|
|
9
|
+
event Swap(
|
|
10
|
+
address indexed caller,
|
|
11
|
+
address indexed receiver,
|
|
12
|
+
address PT,
|
|
13
|
+
uint256 netPtIn,
|
|
14
|
+
address token,
|
|
15
|
+
uint256 netTokenOut
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
event PriceOracleUpdated(address indexed PT, address indexed token, address indexed priceOracle);
|
|
19
|
+
|
|
20
|
+
event Seeded(address indexed token, uint256 amount);
|
|
21
|
+
event Unseeded(address indexed token, uint256 amount);
|
|
22
|
+
|
|
23
|
+
function priceOracle(address PT, address token) external view returns (IPChainlinkOracleEssential);
|
|
24
|
+
|
|
25
|
+
function getPtToTokenPrice(address PT, address token) external view returns (uint256);
|
|
26
|
+
|
|
27
|
+
function swapPtForExactToken(
|
|
28
|
+
address receiver,
|
|
29
|
+
address PT,
|
|
30
|
+
address token,
|
|
31
|
+
uint256 exactTokenOut,
|
|
32
|
+
bytes calldata data
|
|
33
|
+
) external payable returns (uint256 netPtIn);
|
|
34
|
+
|
|
35
|
+
function swapExactPtForToken(
|
|
36
|
+
address receiver,
|
|
37
|
+
address PT,
|
|
38
|
+
uint256 exactPtIn,
|
|
39
|
+
address token,
|
|
40
|
+
bytes calldata data
|
|
41
|
+
) external payable returns (uint256 netTokenOut);
|
|
42
|
+
|
|
43
|
+
// Admin functions
|
|
44
|
+
|
|
45
|
+
function setPriceOracle(address PT, address token, address priceOracle) external;
|
|
46
|
+
|
|
47
|
+
function addFund(address token, uint256 amount) external payable;
|
|
48
|
+
|
|
49
|
+
function removeFund(address token, uint256 amount) external;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface IPFixedPricePTAMMSwapCallback {
|
|
53
|
+
function swapCallback(uint256 exactTokenOut, uint256 netPtIn, bytes calldata data) external;
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
interface IPPTOFTAdapterFactory {
|
|
5
|
+
event PtAdapterCreated(address indexed pt, address indexed adapter);
|
|
6
|
+
|
|
7
|
+
function initialize(address _owner) external;
|
|
8
|
+
|
|
9
|
+
function createPtAdapter(address pt) external returns (address);
|
|
10
|
+
|
|
11
|
+
function ptAdapter(address pt) external view returns (address);
|
|
12
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
|
|
2
2
|
pragma solidity ^0.8.19;
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import {IPChainlinkOracleEssential} from "../../interfaces/IPChainlinkOracleEssential.sol";
|
|
5
|
+
|
|
6
|
+
contract PendleSparkLinearDiscountOracle is IPChainlinkOracleEssential {
|
|
5
7
|
uint256 private constant SECONDS_PER_YEAR = 365 days;
|
|
6
8
|
uint256 private constant ONE = 1e18;
|
|
7
9
|
|
package/deployments/1-core.json
CHANGED
|
@@ -60,5 +60,6 @@
|
|
|
60
60
|
"feeDistributor": "0xd7b34a6fDCb2A7ceD2115FF7f5fdD72aa6aA4dE2",
|
|
61
61
|
"feeDistributorV2": "0x8C237520a8E14D658170A633D96F8e80764433b9",
|
|
62
62
|
"lpWrapperFactory": "0x12930Bd944bb34B0A21CCc2E7d32a6834Bd58e19",
|
|
63
|
-
"decimalsFactory": "0x992ec6a490a4b7f256bd59e63746951d98b29be9"
|
|
63
|
+
"decimalsFactory": "0x992ec6a490a4b7f256bd59e63746951d98b29be9",
|
|
64
|
+
"ptOftAdapterFactory": "0x6f2a9b773778188727cc1f49c57213b1a758555e"
|
|
64
65
|
}
|
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": "6.
|
|
5
|
+
"version": "6.1.0-cross-chain-pt",
|
|
6
6
|
"homepage": "https://pendle.finance",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"pendle",
|
|
@@ -46,6 +46,9 @@
|
|
|
46
46
|
"packageManager": "yarn@4.9.2",
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@chainlink/contracts": "^0.8.0",
|
|
49
|
+
"@layerzerolabs/lz-evm-protocol-v2": "^3.0.75",
|
|
50
|
+
"@layerzerolabs/oapp-evm": "^0.3.2",
|
|
51
|
+
"@layerzerolabs/oft-evm": "^3.1.4",
|
|
49
52
|
"@openzeppelin/contracts": "4.9.3",
|
|
50
53
|
"@openzeppelin/contracts-upgradeable": "4.9.3",
|
|
51
54
|
"ethers": "^5.7.2"
|
|
@@ -85,7 +85,7 @@ const _abi = [
|
|
|
85
85
|
];
|
|
86
86
|
|
|
87
87
|
const _bytecode =
|
|
88
|
-
"
|
|
88
|
+
"0x608060405234801561001057600080fd5b50610800806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80633b8863cc1461003b57806380245dad1461006a575b600080fd5b61004e6100493660046101ef565b61007d565b6040516001600160a01b03909116815260200160405180910390f35b61004e6100783660046101ef565b610159565b600080836001600160a01b0316632c8ce6bc6040518163ffffffff1660e01b8152600401606060405180830381865afa1580156100be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100e2919061021b565b50915050600081846040516100f6906101ca565b610101929190610268565b604051809103906000f08015801561011d573d6000803e3d6000fd5b509050816001600160a01b03166000805160206107ab8339815191528583604051610149929190610281565b60405180910390a2949350505050565b60008282604051610169906101ca565b610174929190610268565b604051809103906000f080158015610190573d6000803e3d6000fd5b509050826001600160a01b03166000805160206107ab83398151915283836040516101bc929190610281565b60405180910390a292915050565b6105128061029983390190565b6001600160a01b03811681146101ec57600080fd5b50565b6000806040838503121561020257600080fd5b823561020d816101d7565b946020939093013593505050565b60008060006060848603121561023057600080fd5b835161023b816101d7565b602085015190935061024c816101d7565b604085015190925061025d816101d7565b809150509250925092565b6001600160a01b03929092168252602082015260400190565b9182526001600160a01b031660208201526040019056fe60e060405234801561001057600080fd5b5060405161051238038061051283398101604081905261002f9161013e565b670de0b6b3a764000081111561007f5760405162461bcd60e51b815260206004820152601060248201526f1a5b9d985b1a5908191a5cd8dbdd5b9d60821b60448201526064015b60405180910390fd5b6001600160a01b0382166100c45760405162461bcd60e51b815260206004820152600c60248201526b7a65726f206164647265737360a01b6044820152606401610076565b6001600160a01b0382166080819052604080516370c264df60e11b8152905163e184c9be916004808201926020929091908290030181865afa15801561010e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101329190610178565b60a05260c05250610191565b6000806040838503121561015157600080fd5b82516001600160a01b038116811461016857600080fd5b6020939093015192949293505050565b60006020828403121561018a57600080fd5b5051919050565b60805160a05160c0516103406101d26000396000818160c80152610171015260008181606c015281816101b201526101e30152600060ef01526103406000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c8063204f83f9146100675780632336dbe4146100a1578063313ce567146100b4578063598e5451146100c3578063d94073d4146100ea578063feaf968c14610129575b600080fd5b61008e7f000000000000000000000000000000000000000000000000000000000000000081565b6040519081526020015b60405180910390f35b61008e6100af36600461028f565b610165565b60405160128152602001610098565b61008e7f000000000000000000000000000000000000000000000000000000000000000081565b6101117f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610098565b6101316101a6565b604080516001600160501b03968716815260208101959095528401929092526060830152909116608082015260a001610098565b60006301e133806101967f0000000000000000000000000000000000000000000000000000000000000000846102be565b6101a091906102d5565b92915050565b600080600080600080427f0000000000000000000000000000000000000000000000000000000000000000116101dd576000610207565b610207427f00000000000000000000000000000000000000000000000000000000000000006102f7565b9050600061021482610165565b9050670de0b6b3a76400008111156102665760405162461bcd60e51b8152602060048201526011602482015270646973636f756e74206f766572666c6f7760781b604482015260640160405180910390fd5b600061027a82670de0b6b3a76400006102f7565b90989097506000965086955085945092505050565b6000602082840312156102a157600080fd5b5035919050565b634e487b7160e01b600052601160045260246000fd5b80820281158282048414176101a0576101a06102a8565b6000826102f257634e487b7160e01b600052601260045260246000fd5b500490565b818103818111156101a0576101a06102a856fea26469706673582212203b38d5b3d373e8d71219c535741f4b4451f433200aeb18038fac8733d9d816ab64736f6c6343000817003390ee845759e3368e15efca97a228f30ad3e506893c7f9215b13c393b31f8e620a2646970667358221220b6bf8283b7d182dee5753b84248257da63548e639c298d03ce59dce4414d64ea64736f6c63430008170033";
|
|
89
89
|
|
|
90
90
|
type PendleSparkLinearDiscountOracleFactoryConstructorParams =
|
|
91
91
|
| [signer?: Signer]
|
|
@@ -139,7 +139,7 @@ const _abi = [
|
|
|
139
139
|
];
|
|
140
140
|
|
|
141
141
|
const _bytecode =
|
|
142
|
-
"
|
|
142
|
+
"0x60e060405234801561001057600080fd5b5060405161051238038061051283398101604081905261002f9161013e565b670de0b6b3a764000081111561007f5760405162461bcd60e51b815260206004820152601060248201526f1a5b9d985b1a5908191a5cd8dbdd5b9d60821b60448201526064015b60405180910390fd5b6001600160a01b0382166100c45760405162461bcd60e51b815260206004820152600c60248201526b7a65726f206164647265737360a01b6044820152606401610076565b6001600160a01b0382166080819052604080516370c264df60e11b8152905163e184c9be916004808201926020929091908290030181865afa15801561010e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101329190610178565b60a05260c05250610191565b6000806040838503121561015157600080fd5b82516001600160a01b038116811461016857600080fd5b6020939093015192949293505050565b60006020828403121561018a57600080fd5b5051919050565b60805160a05160c0516103406101d26000396000818160c80152610171015260008181606c015281816101b201526101e30152600060ef01526103406000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c8063204f83f9146100675780632336dbe4146100a1578063313ce567146100b4578063598e5451146100c3578063d94073d4146100ea578063feaf968c14610129575b600080fd5b61008e7f000000000000000000000000000000000000000000000000000000000000000081565b6040519081526020015b60405180910390f35b61008e6100af36600461028f565b610165565b60405160128152602001610098565b61008e7f000000000000000000000000000000000000000000000000000000000000000081565b6101117f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610098565b6101316101a6565b604080516001600160501b03968716815260208101959095528401929092526060830152909116608082015260a001610098565b60006301e133806101967f0000000000000000000000000000000000000000000000000000000000000000846102be565b6101a091906102d5565b92915050565b600080600080600080427f0000000000000000000000000000000000000000000000000000000000000000116101dd576000610207565b610207427f00000000000000000000000000000000000000000000000000000000000000006102f7565b9050600061021482610165565b9050670de0b6b3a76400008111156102665760405162461bcd60e51b8152602060048201526011602482015270646973636f756e74206f766572666c6f7760781b604482015260640160405180910390fd5b600061027a82670de0b6b3a76400006102f7565b90989097506000965086955085945092505050565b6000602082840312156102a157600080fd5b5035919050565b634e487b7160e01b600052601160045260246000fd5b80820281158282048414176101a0576101a06102a8565b6000826102f257634e487b7160e01b600052601260045260246000fd5b500490565b818103818111156101a0576101a06102a856fea26469706673582212203b38d5b3d373e8d71219c535741f4b4451f433200aeb18038fac8733d9d816ab64736f6c63430008170033";
|
|
143
143
|
|
|
144
144
|
type PendleSparkLinearDiscountOracleConstructorParams =
|
|
145
145
|
| [signer?: Signer]
|
|
@@ -308,6 +308,34 @@ declare module "hardhat/types/runtime" {
|
|
|
308
308
|
name: "PendleYieldToken",
|
|
309
309
|
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
310
310
|
): Promise<Contracts.PendleYieldToken__factory>;
|
|
311
|
+
getContractFactory(
|
|
312
|
+
name: "PendlePTOFTAdapterFactory",
|
|
313
|
+
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
314
|
+
): Promise<Contracts.PendlePTOFTAdapterFactory__factory>;
|
|
315
|
+
getContractFactory(
|
|
316
|
+
name: "FixedPricePTAMM",
|
|
317
|
+
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
318
|
+
): Promise<Contracts.FixedPricePTAMM__factory>;
|
|
319
|
+
getContractFactory(
|
|
320
|
+
name: "OFTAdapterImpl",
|
|
321
|
+
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
322
|
+
): Promise<Contracts.OFTAdapterImpl__factory>;
|
|
323
|
+
getContractFactory(
|
|
324
|
+
name: "BasePendleBridgedPrincipalToken",
|
|
325
|
+
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
326
|
+
): Promise<Contracts.BasePendleBridgedPrincipalToken__factory>;
|
|
327
|
+
getContractFactory(
|
|
328
|
+
name: "PendleBridgedPrincipalToken_18Decimals",
|
|
329
|
+
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
330
|
+
): Promise<Contracts.PendleBridgedPrincipalToken_18Decimals__factory>;
|
|
331
|
+
getContractFactory(
|
|
332
|
+
name: "PendleBridgedPrincipalToken_6Decimals",
|
|
333
|
+
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
334
|
+
): Promise<Contracts.PendleBridgedPrincipalToken_6Decimals__factory>;
|
|
335
|
+
getContractFactory(
|
|
336
|
+
name: "PendleBridgedPrincipalToken_8Decimals",
|
|
337
|
+
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
338
|
+
): Promise<Contracts.PendleBridgedPrincipalToken_8Decimals__factory>;
|
|
311
339
|
getContractFactory(
|
|
312
340
|
name: "PendleFeeDistributor",
|
|
313
341
|
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
@@ -412,10 +440,18 @@ declare module "hardhat/types/runtime" {
|
|
|
412
440
|
name: "IPAllEventsV3",
|
|
413
441
|
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
414
442
|
): Promise<Contracts.IPAllEventsV3__factory>;
|
|
443
|
+
getContractFactory(
|
|
444
|
+
name: "IPBridgedPrincipalToken",
|
|
445
|
+
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
446
|
+
): Promise<Contracts.IPBridgedPrincipalToken__factory>;
|
|
415
447
|
getContractFactory(
|
|
416
448
|
name: "IPChainlinkOracle",
|
|
417
449
|
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
418
450
|
): Promise<Contracts.IPChainlinkOracle__factory>;
|
|
451
|
+
getContractFactory(
|
|
452
|
+
name: "IPChainlinkOracleEssential",
|
|
453
|
+
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
454
|
+
): Promise<Contracts.IPChainlinkOracleEssential__factory>;
|
|
419
455
|
getContractFactory(
|
|
420
456
|
name: "IPChainlinkOracleFactory",
|
|
421
457
|
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
@@ -444,6 +480,14 @@ declare module "hardhat/types/runtime" {
|
|
|
444
480
|
name: "IPFeeDistributorV2",
|
|
445
481
|
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
446
482
|
): Promise<Contracts.IPFeeDistributorV2__factory>;
|
|
483
|
+
getContractFactory(
|
|
484
|
+
name: "IPFixedPricePTAMM",
|
|
485
|
+
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
486
|
+
): Promise<Contracts.IPFixedPricePTAMM__factory>;
|
|
487
|
+
getContractFactory(
|
|
488
|
+
name: "IPFixedPricePTAMMSwapCallback",
|
|
489
|
+
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
490
|
+
): Promise<Contracts.IPFixedPricePTAMMSwapCallback__factory>;
|
|
447
491
|
getContractFactory(
|
|
448
492
|
name: "IPGauge",
|
|
449
493
|
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
@@ -544,6 +588,10 @@ declare module "hardhat/types/runtime" {
|
|
|
544
588
|
name: "IPPrincipalToken",
|
|
545
589
|
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
546
590
|
): Promise<Contracts.IPPrincipalToken__factory>;
|
|
591
|
+
getContractFactory(
|
|
592
|
+
name: "IPPTOFTAdapterFactory",
|
|
593
|
+
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
594
|
+
): Promise<Contracts.IPPTOFTAdapterFactory__factory>;
|
|
547
595
|
getContractFactory(
|
|
548
596
|
name: "IPPYLpOracle",
|
|
549
597
|
signerOrOptions?: ethers.Signer | FactoryOptions
|
|
@@ -1303,6 +1351,41 @@ declare module "hardhat/types/runtime" {
|
|
|
1303
1351
|
address: string,
|
|
1304
1352
|
signer?: ethers.Signer
|
|
1305
1353
|
): Promise<Contracts.PendleYieldToken>;
|
|
1354
|
+
getContractAt(
|
|
1355
|
+
name: "PendlePTOFTAdapterFactory",
|
|
1356
|
+
address: string,
|
|
1357
|
+
signer?: ethers.Signer
|
|
1358
|
+
): Promise<Contracts.PendlePTOFTAdapterFactory>;
|
|
1359
|
+
getContractAt(
|
|
1360
|
+
name: "FixedPricePTAMM",
|
|
1361
|
+
address: string,
|
|
1362
|
+
signer?: ethers.Signer
|
|
1363
|
+
): Promise<Contracts.FixedPricePTAMM>;
|
|
1364
|
+
getContractAt(
|
|
1365
|
+
name: "OFTAdapterImpl",
|
|
1366
|
+
address: string,
|
|
1367
|
+
signer?: ethers.Signer
|
|
1368
|
+
): Promise<Contracts.OFTAdapterImpl>;
|
|
1369
|
+
getContractAt(
|
|
1370
|
+
name: "BasePendleBridgedPrincipalToken",
|
|
1371
|
+
address: string,
|
|
1372
|
+
signer?: ethers.Signer
|
|
1373
|
+
): Promise<Contracts.BasePendleBridgedPrincipalToken>;
|
|
1374
|
+
getContractAt(
|
|
1375
|
+
name: "PendleBridgedPrincipalToken_18Decimals",
|
|
1376
|
+
address: string,
|
|
1377
|
+
signer?: ethers.Signer
|
|
1378
|
+
): Promise<Contracts.PendleBridgedPrincipalToken_18Decimals>;
|
|
1379
|
+
getContractAt(
|
|
1380
|
+
name: "PendleBridgedPrincipalToken_6Decimals",
|
|
1381
|
+
address: string,
|
|
1382
|
+
signer?: ethers.Signer
|
|
1383
|
+
): Promise<Contracts.PendleBridgedPrincipalToken_6Decimals>;
|
|
1384
|
+
getContractAt(
|
|
1385
|
+
name: "PendleBridgedPrincipalToken_8Decimals",
|
|
1386
|
+
address: string,
|
|
1387
|
+
signer?: ethers.Signer
|
|
1388
|
+
): Promise<Contracts.PendleBridgedPrincipalToken_8Decimals>;
|
|
1306
1389
|
getContractAt(
|
|
1307
1390
|
name: "PendleFeeDistributor",
|
|
1308
1391
|
address: string,
|
|
@@ -1433,11 +1516,21 @@ declare module "hardhat/types/runtime" {
|
|
|
1433
1516
|
address: string,
|
|
1434
1517
|
signer?: ethers.Signer
|
|
1435
1518
|
): Promise<Contracts.IPAllEventsV3>;
|
|
1519
|
+
getContractAt(
|
|
1520
|
+
name: "IPBridgedPrincipalToken",
|
|
1521
|
+
address: string,
|
|
1522
|
+
signer?: ethers.Signer
|
|
1523
|
+
): Promise<Contracts.IPBridgedPrincipalToken>;
|
|
1436
1524
|
getContractAt(
|
|
1437
1525
|
name: "IPChainlinkOracle",
|
|
1438
1526
|
address: string,
|
|
1439
1527
|
signer?: ethers.Signer
|
|
1440
1528
|
): Promise<Contracts.IPChainlinkOracle>;
|
|
1529
|
+
getContractAt(
|
|
1530
|
+
name: "IPChainlinkOracleEssential",
|
|
1531
|
+
address: string,
|
|
1532
|
+
signer?: ethers.Signer
|
|
1533
|
+
): Promise<Contracts.IPChainlinkOracleEssential>;
|
|
1441
1534
|
getContractAt(
|
|
1442
1535
|
name: "IPChainlinkOracleFactory",
|
|
1443
1536
|
address: string,
|
|
@@ -1473,6 +1566,16 @@ declare module "hardhat/types/runtime" {
|
|
|
1473
1566
|
address: string,
|
|
1474
1567
|
signer?: ethers.Signer
|
|
1475
1568
|
): Promise<Contracts.IPFeeDistributorV2>;
|
|
1569
|
+
getContractAt(
|
|
1570
|
+
name: "IPFixedPricePTAMM",
|
|
1571
|
+
address: string,
|
|
1572
|
+
signer?: ethers.Signer
|
|
1573
|
+
): Promise<Contracts.IPFixedPricePTAMM>;
|
|
1574
|
+
getContractAt(
|
|
1575
|
+
name: "IPFixedPricePTAMMSwapCallback",
|
|
1576
|
+
address: string,
|
|
1577
|
+
signer?: ethers.Signer
|
|
1578
|
+
): Promise<Contracts.IPFixedPricePTAMMSwapCallback>;
|
|
1476
1579
|
getContractAt(
|
|
1477
1580
|
name: "IPGauge",
|
|
1478
1581
|
address: string,
|
|
@@ -1598,6 +1701,11 @@ declare module "hardhat/types/runtime" {
|
|
|
1598
1701
|
address: string,
|
|
1599
1702
|
signer?: ethers.Signer
|
|
1600
1703
|
): Promise<Contracts.IPPrincipalToken>;
|
|
1704
|
+
getContractAt(
|
|
1705
|
+
name: "IPPTOFTAdapterFactory",
|
|
1706
|
+
address: string,
|
|
1707
|
+
signer?: ethers.Signer
|
|
1708
|
+
): Promise<Contracts.IPPTOFTAdapterFactory>;
|
|
1601
1709
|
getContractAt(
|
|
1602
1710
|
name: "IPPYLpOracle",
|
|
1603
1711
|
address: string,
|