@pendle/core-v2 6.6.1 → 6.7.1

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.
Files changed (180) hide show
  1. package/build/artifacts/contracts/LiquidityMining/PendleMerkleDistributor.sol/PendleMerkleDistributor.dbg.json +1 -1
  2. package/build/artifacts/contracts/LiquidityMining/PendleMerkleDistributor.sol/PendleMerkleDistributor.json +2 -88
  3. package/build/artifacts/contracts/LiquidityMining/PendleMultiTokenMerkleDistributor.sol/PendleMultiTokenMerkleDistributor.dbg.json +1 -1
  4. package/build/artifacts/contracts/LiquidityMining/PendleMultiTokenMerkleDistributor.sol/PendleMultiTokenMerkleDistributor.json +2 -122
  5. package/build/artifacts/contracts/cross-chain/OFTPTSwapper.sol/OFTPTSwapper.dbg.json +4 -0
  6. package/build/artifacts/contracts/cross-chain/OFTPTSwapper.sol/OFTPTSwapper.json +99 -0
  7. package/build/artifacts/contracts/cross-chain/factory/PendleBridgePTFactory.sol/PendleBridgePTFactory.dbg.json +4 -0
  8. package/build/artifacts/contracts/cross-chain/factory/PendleBridgePTFactory.sol/PendleBridgePTFactory.json +1388 -0
  9. package/build/artifacts/contracts/cross-chain/funder/BridgeFunder.sol/BridgeFunder.dbg.json +1 -1
  10. package/build/artifacts/contracts/cross-chain/oftImpl/hub/OFTAdapterAltImpl.sol/OFTAdapterAltImpl.dbg.json +1 -1
  11. package/build/artifacts/contracts/cross-chain/oftImpl/hub/OFTAdapterAltImpl.sol/OFTAdapterAltImpl.json +46 -14
  12. package/build/artifacts/contracts/cross-chain/oftImpl/hub/OFTAdapterImpl.sol/OFTAdapterImpl.dbg.json +1 -1
  13. package/build/artifacts/contracts/cross-chain/oftImpl/hub/OFTAdapterImpl.sol/OFTAdapterImpl.json +46 -14
  14. package/build/artifacts/contracts/cross-chain/oftImpl/pendleOft/PendleOFT.sol/PendleOFT.dbg.json +4 -0
  15. package/build/artifacts/contracts/cross-chain/oftImpl/pendleOft/PendleOFT.sol/PendleOFT.json +1541 -0
  16. package/build/artifacts/contracts/cross-chain/oftImpl/pendleOft/PendleOFTAlt.sol/PendleOFTAlt.dbg.json +4 -0
  17. package/build/artifacts/contracts/cross-chain/oftImpl/pendleOft/PendleOFTAlt.sol/PendleOFTAlt.json +1570 -0
  18. package/build/artifacts/contracts/cross-chain/oftImpl/spoke/PendleBridgedPrincipalToken.sol/PendleBridgedPrincipalToken.dbg.json +1 -1
  19. package/build/artifacts/contracts/cross-chain/oftImpl/spoke/PendleBridgedPrincipalToken.sol/PendleBridgedPrincipalToken.json +57 -35
  20. package/build/artifacts/contracts/cross-chain/oftImpl/spoke/PendleBridgedPrincipalTokenAlt.sol/PendleBridgedPrincipalTokenAlt.dbg.json +1 -1
  21. package/build/artifacts/contracts/cross-chain/oftImpl/spoke/PendleBridgedPrincipalTokenAlt.sol/PendleBridgedPrincipalTokenAlt.json +57 -35
  22. package/build/artifacts/contracts/interfaces/IMarketSweed.sol/IMarketSweed.dbg.json +1 -1
  23. package/build/artifacts/contracts/interfaces/IPActionAddRemoveLiqV3.sol/IPActionAddRemoveLiqV3.dbg.json +1 -1
  24. package/build/artifacts/contracts/interfaces/IPActionCallbackV3.sol/IPActionCallbackV3.dbg.json +1 -1
  25. package/build/artifacts/contracts/interfaces/IPActionMarketAuxStatic.sol/IPActionMarketAuxStatic.dbg.json +1 -1
  26. package/build/artifacts/contracts/interfaces/IPActionMiscV3.sol/IPActionMiscV3.dbg.json +1 -1
  27. package/build/artifacts/contracts/interfaces/IPActionSimple.sol/IPActionSimple.dbg.json +1 -1
  28. package/build/artifacts/contracts/interfaces/IPActionStorageStatic.sol/IPActionStorageStatic.dbg.json +1 -1
  29. package/build/artifacts/contracts/interfaces/IPActionStorageV4.sol/IPActionStorageV4.dbg.json +1 -1
  30. package/build/artifacts/contracts/interfaces/IPActionSwapPTV3.sol/IPActionSwapPTV3.dbg.json +1 -1
  31. package/build/artifacts/contracts/interfaces/IPActionSwapYTV3.sol/IPActionSwapYTV3.dbg.json +1 -1
  32. package/build/artifacts/contracts/interfaces/IPAllActionV3.sol/IPAllActionV3.dbg.json +1 -1
  33. package/build/artifacts/contracts/interfaces/IPAllEventsV3.sol/IPActionAddRemoveLiqV3Events.dbg.json +1 -1
  34. package/build/artifacts/contracts/interfaces/IPAllEventsV3.sol/IPActionMiscV3Events.dbg.json +1 -1
  35. package/build/artifacts/contracts/interfaces/IPAllEventsV3.sol/IPActionStorageEvents.dbg.json +1 -1
  36. package/build/artifacts/contracts/interfaces/IPAllEventsV3.sol/IPActionSwapPTV3Events.dbg.json +1 -1
  37. package/build/artifacts/contracts/interfaces/IPAllEventsV3.sol/IPActionSwapYTV3Events.dbg.json +1 -1
  38. package/build/artifacts/contracts/interfaces/IPAllEventsV3.sol/IPAllEventsV3.dbg.json +1 -1
  39. package/build/artifacts/contracts/interfaces/IPBridgeFunder.sol/IPBridgeFunder.dbg.json +1 -1
  40. package/build/artifacts/contracts/interfaces/IPBridgePTFactory.sol/IPBridgePTFactory.dbg.json +4 -0
  41. package/build/artifacts/contracts/interfaces/IPBridgePTFactory.sol/IPBridgePTFactory.json +1026 -0
  42. package/build/artifacts/contracts/interfaces/IPBridgedPrincipalToken.sol/IPBridgedPrincipalToken.dbg.json +1 -1
  43. package/build/artifacts/contracts/interfaces/IPBridgedPrincipalToken.sol/IPBridgedPrincipalToken.json +11 -0
  44. package/build/artifacts/contracts/interfaces/IPLimitRouter.sol/IPLimitOrderType.dbg.json +1 -1
  45. package/build/artifacts/contracts/interfaces/IPLimitRouter.sol/IPLimitRouter.dbg.json +1 -1
  46. package/build/artifacts/contracts/interfaces/IPLimitRouter.sol/IPLimitRouterCallback.dbg.json +1 -1
  47. package/build/artifacts/contracts/interfaces/IPMerkleDistributor.sol/IPMerkleDistributor.dbg.json +1 -1
  48. package/build/artifacts/contracts/interfaces/IPMerkleDistributor.sol/IPMerkleDistributor.json +0 -67
  49. package/build/artifacts/contracts/interfaces/IPMultiTokenMerkleDistributor.sol/IPMultiTokenMerkleDistributor.dbg.json +1 -1
  50. package/build/artifacts/contracts/interfaces/IPMultiTokenMerkleDistributor.sol/IPMultiTokenMerkleDistributor.json +0 -120
  51. package/build/artifacts/contracts/interfaces/IPOFTPTSwapper.sol/IPOFTPTSwapper.dbg.json +4 -0
  52. package/build/artifacts/contracts/interfaces/{IPSwapHelper.sol/IPSwapHelper.json → IPOFTPTSwapper.sol/IPOFTPTSwapper.json} +2 -2
  53. package/build/artifacts/contracts/interfaces/IPRouterStatic.sol/IPRouterStatic.dbg.json +1 -1
  54. package/build/artifacts/contracts/limit/LimitMathCore.sol/LimitMathCore.dbg.json +1 -1
  55. package/build/artifacts/contracts/limit/LimitRouterBase.sol/LimitRouterBase.dbg.json +1 -1
  56. package/build/artifacts/contracts/limit/PendleLimitRouter.sol/PendleLimitRouter.dbg.json +1 -1
  57. package/build/artifacts/contracts/limit/PendleLimitRouter.sol/PendleLimitRouter.json +2 -2
  58. package/build/artifacts/contracts/limit/helpers/MintSyHelper.sol/MintSyHelper.dbg.json +1 -1
  59. package/build/artifacts/contracts/offchain-helpers/ExpiredLpPtRedeemer.sol/ExpiredLpPtRedeemer.dbg.json +1 -1
  60. package/build/artifacts/contracts/offchain-helpers/LimitBackendHelperV2.sol/LimitBackendHelperV2.dbg.json +1 -1
  61. package/build/artifacts/contracts/offchain-helpers/MarketSweed.sol/MarketSweed.dbg.json +1 -1
  62. package/build/artifacts/contracts/offchain-helpers/PendleFeeSetter.sol/PendleFeeSetter.dbg.json +1 -1
  63. package/build/artifacts/contracts/offchain-helpers/deploy/PendleCommonPoolDeployHelperV2.sol/PendleCommonPoolDeployHelperV2.dbg.json +1 -1
  64. package/build/artifacts/contracts/offchain-helpers/deploy/PendlePoolDeployHelper.sol/PendlePoolDeployHelper.dbg.json +1 -1
  65. package/build/artifacts/contracts/offchain-helpers/deploy/PendlePoolDeployHelperV2.sol/PendlePoolDeployHelperV2.dbg.json +1 -1
  66. package/build/artifacts/contracts/offchain-helpers/router-static/PendleRouterStatic.sol/PendleRouterStatic.dbg.json +1 -1
  67. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionInfoStatic.sol/ActionInfoStatic.dbg.json +1 -1
  68. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMarketAuxStatic.sol/ActionMarketAuxStatic.dbg.json +1 -1
  69. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMarketCoreStatic.sol/ActionMarketCoreStatic.dbg.json +1 -1
  70. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMintRedeemStatic.sol/ActionMintRedeemStatic.dbg.json +1 -1
  71. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionStorageStatic.sol/ActionStorageStatic.dbg.json +1 -1
  72. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionVePendleStatic.sol/ActionVePendleStatic.dbg.json +1 -1
  73. package/build/artifacts/contracts/offchain-helpers/router-static/base/MarketApproxLibV1.sol/MarketApproxPtInLibV1.dbg.json +1 -1
  74. package/build/artifacts/contracts/offchain-helpers/router-static/base/MarketApproxLibV1.sol/MarketApproxPtOutLibV1.dbg.json +1 -1
  75. package/build/artifacts/contracts/offchain-helpers/router-static/base/StorageLayout.sol/StorageLayout.dbg.json +1 -1
  76. package/build/artifacts/contracts/router/ActionStorageV4.sol/ActionStorageV4.dbg.json +1 -1
  77. package/build/artifacts/contracts/router/PendleRouterV4.sol/PendleRouterV4.dbg.json +1 -1
  78. package/build/artifacts/contracts/router/Reflector.sol/Reflector.dbg.json +1 -1
  79. package/build/artifacts/contracts/router/base/ActionBase.sol/ActionBase.dbg.json +1 -1
  80. package/build/artifacts/contracts/router/base/ActionDelegateBase.sol/ActionDelegateBase.dbg.json +1 -1
  81. package/build/artifacts/contracts/router/math/ApproxStateLib.sol/ApproxStateLib.dbg.json +1 -1
  82. package/build/artifacts/contracts/router/math/MarketApproxLibOnchain.sol/MarketApproxPtInLibOnchain.dbg.json +1 -1
  83. package/build/artifacts/contracts/router/math/MarketApproxLibOnchain.sol/MarketApproxPtOutLibOnchain.dbg.json +1 -1
  84. package/build/artifacts/contracts/router/math/MarketApproxLibV2.sol/MarketApproxPtInLibV2.dbg.json +1 -1
  85. package/build/artifacts/contracts/router/math/MarketApproxLibV2.sol/MarketApproxPtOutLibV2.dbg.json +1 -1
  86. package/build/artifacts/contracts/router/swap-aggregator/OKXScaleHelper.sol/IOKXDexRouter.dbg.json +1 -1
  87. package/build/artifacts/contracts/router/swap-aggregator/OKXScaleHelper.sol/OKXScaleHelper.dbg.json +1 -1
  88. package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/IKyberScalingHelper.dbg.json +1 -1
  89. package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/IOdosRouterV2.dbg.json +1 -1
  90. package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/PendleSwap.dbg.json +1 -1
  91. package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/PendleSwap.json +2 -2
  92. package/contracts/LiquidityMining/PendleMerkleDistributor.sol +1 -28
  93. package/contracts/LiquidityMining/PendleMultiTokenMerkleDistributor.sol +1 -36
  94. package/contracts/cross-chain/{PendleSwapHelper.sol → OFTPTSwapper.sol} +4 -3
  95. package/contracts/cross-chain/factory/PendleBridgePTFactory.sol +495 -0
  96. package/contracts/cross-chain/oftImpl/hub/OFTAdapterAltImpl.sol +5 -4
  97. package/contracts/cross-chain/oftImpl/hub/OFTAdapterImpl.sol +14 -6
  98. package/contracts/cross-chain/oftImpl/pendleOft/PendleOFT.sol +11 -0
  99. package/contracts/cross-chain/oftImpl/pendleOft/PendleOFTAlt.sol +52 -0
  100. package/contracts/cross-chain/oftImpl/spoke/PendleBridgedPrincipalToken.sol +33 -24
  101. package/contracts/cross-chain/oftImpl/spoke/PendleBridgedPrincipalTokenAlt.sol +4 -13
  102. package/contracts/interfaces/IPBridgePTFactory.sol +129 -0
  103. package/contracts/interfaces/IPBridgedPrincipalToken.sol +4 -2
  104. package/contracts/interfaces/IPMerkleDistributor.sol +0 -7
  105. package/contracts/interfaces/IPMultiTokenMerkleDistributor.sol +0 -10
  106. package/contracts/interfaces/{IPSwapHelper.sol → IPOFTPTSwapper.sol} +1 -1
  107. package/contracts/limit/LimitRouterBase.sol +1 -1
  108. package/contracts/router/swap-aggregator/OKXScaleHelper.sol +4 -1
  109. package/deployments/1-core.json +2 -1
  110. package/deployments/130-core.json +2 -1
  111. package/deployments/143-core.json +38 -1
  112. package/deployments/143-offchain-helper.json +11 -0
  113. package/deployments/42161-core.json +2 -1
  114. package/deployments/4217-core.json +3 -1
  115. package/deployments/43114-core.json +3 -1
  116. package/deployments/56-core.json +2 -1
  117. package/deployments/57073-core.json +4 -1
  118. package/deployments/747474-core.json +4 -1
  119. package/deployments/8453-core.json +2 -1
  120. package/deployments/9745-core.json +2 -1
  121. package/deployments/999-core.json +2 -1
  122. package/package.json +12 -9
  123. package/typechain-types/DVNOptions.ts +57 -0
  124. package/typechain-types/ExecutorOptions.ts +57 -0
  125. package/typechain-types/IPBridgePTFactory.ts +936 -0
  126. package/typechain-types/IPMerkleDistributor.ts +0 -90
  127. package/typechain-types/IPMultiTokenMerkleDistributor.ts +0 -158
  128. package/typechain-types/IPOFTPTSwapper.ts +161 -0
  129. package/typechain-types/OAppPreCrimeSimulatorUpgradeable.ts +410 -0
  130. package/typechain-types/OFTAdapterAltImpl.ts +50 -19
  131. package/typechain-types/OFTAdapterImpl.ts +50 -19
  132. package/typechain-types/OFTAdapterUpgradeable.ts +1337 -0
  133. package/typechain-types/OFTCoreUpgradeable.ts +1337 -0
  134. package/typechain-types/OFTPTSwapper.ts +161 -0
  135. package/typechain-types/OFTUpgradeable.ts +1681 -0
  136. package/typechain-types/OptionsBuilder.ts +57 -0
  137. package/typechain-types/PendleBridgePTFactory.ts +1311 -0
  138. package/typechain-types/PendleBridgedPrincipalToken.ts +67 -20
  139. package/typechain-types/PendleBridgedPrincipalTokenAlt.ts +67 -20
  140. package/typechain-types/PendleMerkleDistributor.ts +0 -106
  141. package/typechain-types/PendleMultiTokenMerkleDistributor.ts +0 -158
  142. package/typechain-types/PendleOFT.ts +1675 -0
  143. package/typechain-types/PendleOFTAlt.ts +1694 -0
  144. package/typechain-types/factories/DVNOptions__factory.ts +77 -0
  145. package/typechain-types/factories/ExecutorOptions__factory.ts +84 -0
  146. package/typechain-types/factories/IOFT__factory.ts +11 -0
  147. package/typechain-types/factories/IPBridgePTFactory__factory.ts +1041 -0
  148. package/typechain-types/factories/IPBridgedPrincipalToken__factory.ts +11 -0
  149. package/typechain-types/factories/IPMerkleDistributor__factory.ts +0 -67
  150. package/typechain-types/factories/IPMultiTokenMerkleDistributor__factory.ts +0 -120
  151. package/typechain-types/factories/IPOFTPTSwapper__factory.ts +114 -0
  152. package/typechain-types/factories/OAppPreCrimeSimulatorUpgradeable__factory.ts +311 -0
  153. package/typechain-types/factories/OFTAdapterAltImpl__factory.ts +49 -25
  154. package/typechain-types/factories/OFTAdapterImpl__factory.ts +49 -25
  155. package/typechain-types/factories/OFTAdapterUpgradeable__factory.ts +1287 -0
  156. package/typechain-types/factories/OFTAdapter__factory.ts +11 -0
  157. package/typechain-types/factories/OFTCoreUpgradeable__factory.ts +1283 -0
  158. package/typechain-types/factories/OFTCore__factory.ts +11 -0
  159. package/typechain-types/factories/OFTPTSwapper__factory.ts +149 -0
  160. package/typechain-types/factories/OFTUpgradeable__factory.ts +1553 -0
  161. package/typechain-types/factories/OFT__factory.ts +11 -0
  162. package/typechain-types/factories/OptionsBuilder__factory.ts +91 -0
  163. package/typechain-types/factories/PendleBridgePTFactory__factory.ts +1481 -0
  164. package/typechain-types/factories/PendleBridgedPrincipalTokenAlt__factory.ts +60 -58
  165. package/typechain-types/factories/PendleBridgedPrincipalToken__factory.ts +60 -58
  166. package/typechain-types/factories/PendleLimitRouter__factory.ts +1 -1
  167. package/typechain-types/factories/PendleMerkleDistributor__factory.ts +1 -87
  168. package/typechain-types/factories/PendleMultiTokenMerkleDistributor__factory.ts +1 -121
  169. package/typechain-types/factories/PendleOFTAlt__factory.ts +1628 -0
  170. package/typechain-types/factories/PendleOFT__factory.ts +1599 -0
  171. package/typechain-types/factories/PendlePTOFTAdapterFactory__factory.ts +1 -1
  172. package/typechain-types/factories/PendleSwap__factory.ts +1 -1
  173. package/typechain-types/hardhat.d.ts +107 -53
  174. package/typechain-types/index.ts +26 -12
  175. package/build/artifacts/contracts/cross-chain/PendleSwapHelper.sol/PendleSwapHelper.dbg.json +0 -4
  176. package/build/artifacts/contracts/cross-chain/PendleSwapHelper.sol/PendleSwapHelper.json +0 -99
  177. package/build/artifacts/contracts/cross-chain/factory/hub/PendlePTOFTAdapterFactory.sol/PendlePTOFTAdapterFactory.dbg.json +0 -4
  178. package/build/artifacts/contracts/cross-chain/factory/hub/PendlePTOFTAdapterFactory.sol/PendlePTOFTAdapterFactory.json +0 -280
  179. package/build/artifacts/contracts/interfaces/IPSwapHelper.sol/IPSwapHelper.dbg.json +0 -4
  180. package/contracts/cross-chain/factory/hub/PendlePTOFTAdapterFactory.sol +0 -38
@@ -3,11 +3,11 @@ pragma solidity ^0.8.0;
3
3
 
4
4
  import {TokenHelper} from "../core/libraries/TokenHelper.sol";
5
5
  import {IPFixedPricePTAMMV2} from "../interfaces/IPFixedPricePTAMMV2.sol";
6
- import {IPSwapHelper, TokenOutput} from "../interfaces/IPSwapHelper.sol";
6
+ import {IPOFTPTSwapper, TokenOutput} from "../interfaces/IPOFTPTSwapper.sol";
7
7
  import {IPSwapAggregator, SwapType} from "../router/swap-aggregator/IPSwapAggregator.sol";
8
8
  import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
9
9
 
10
- contract PendleSwapHelper is IPSwapHelper, TokenHelper {
10
+ contract OFTPTSwapper is IPOFTPTSwapper, TokenHelper {
11
11
  function swapWithFixedPricePTAMM(
12
12
  address receiver,
13
13
  address fixedPricePTAMM,
@@ -16,7 +16,8 @@ contract PendleSwapHelper is IPSwapHelper, TokenHelper {
16
16
  TokenOutput calldata out
17
17
  ) external returns (uint256 netTokenOut) {
18
18
  require(
19
- out.tokenRedeemSy == IPFixedPricePTAMMV2(fixedPricePTAMM).outputToken(), "SwapHelper: INVALID_TOKEN_REDEEM"
19
+ out.tokenRedeemSy == IPFixedPricePTAMMV2(fixedPricePTAMM).outputToken(),
20
+ "OFTPTSwapper: INVALID_TOKEN_REDEEM"
20
21
  );
21
22
 
22
23
  _transferFrom(IERC20(PT), msg.sender, fixedPricePTAMM, exactPtIn);
@@ -0,0 +1,495 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {IPBridgePTFactory} from "../../interfaces/IPBridgePTFactory.sol";
5
+
6
+ import {IPGovernanceProxy} from "../../interfaces/IPGovernanceProxy.sol";
7
+ import {IPPrincipalToken} from "../../interfaces/IPPrincipalToken.sol";
8
+ import {OFTAdapterImpl} from "../oftImpl/hub/OFTAdapterImpl.sol";
9
+ import {PendleBridgedPrincipalToken} from "../oftImpl/spoke/PendleBridgedPrincipalToken.sol";
10
+
11
+ import {
12
+ ILayerZeroEndpointV2,
13
+ IMessageLibManager
14
+ } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
15
+ import {SetConfigParam} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessageLibManager.sol";
16
+ import {AddressCast} from "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol";
17
+ import {
18
+ MessagingFee,
19
+ MessagingReceipt,
20
+ OAppUpgradeable,
21
+ Origin
22
+ } from "@layerzerolabs/oapp-evm-upgradeable/contracts/oapp/OAppUpgradeable.sol";
23
+ import {
24
+ EnforcedOptionParam,
25
+ IOAppOptionsType3
26
+ } from "@layerzerolabs/oapp-evm-upgradeable/contracts/oapp/libs/OAppOptionsType3Upgradeable.sol";
27
+ import {IOAppCore} from "@layerzerolabs/oapp-evm/contracts/oapp/interfaces/IOAppCore.sol";
28
+ import {OptionsBuilder} from "@layerzerolabs/oapp-evm/contracts/oapp/libs/OptionsBuilder.sol";
29
+ import {ITransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
30
+ import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
31
+
32
+ contract PendleBridgePTFactory is IPBridgePTFactory, OAppUpgradeable {
33
+ using AddressCast for address;
34
+ using AddressCast for bytes32;
35
+ using OptionsBuilder for bytes;
36
+
37
+ uint32 public immutable LZ_EID;
38
+ address public immutable LZ_SEND_ULN_302;
39
+ address public immutable LZ_RECEIVE_ULN_302;
40
+
41
+ IPGovernanceProxy public immutable GOV_PROXY;
42
+ address public immutable OFT_PROXY_ADMIN;
43
+
44
+ address public immutable HUB_PT_OFT_ADAPTER_CREATION_CODE;
45
+ address public immutable SPOKE_PT_OFT_CREATION_CODE;
46
+ address public immutable TRANSPARENT_PROXY_CREATION_CODE;
47
+
48
+ // hardcoded inside SendUln302 contract
49
+ uint32 internal constant LZ_CONFIG_TYPE_EXECUTOR = 1;
50
+ uint32 internal constant LZ_CONFIG_TYPE_ULN = 2;
51
+
52
+ // Hardcoded inside OFT contract. Also use as the enforced options type for this OApp
53
+ uint16 internal constant ENFORCED_OFT_SEND_MSGTYPE = 1;
54
+
55
+ uint128 internal constant DEFAULT_PT_OFT_ENFORCED_RECEIVE_GAS = 90_000;
56
+
57
+ // No prior receive library to grant grace to on first wiring
58
+ uint256 internal constant LZ_RECEIVE_LIB_GRACE_PERIOD = 0;
59
+
60
+ // Will not be changed most of the time
61
+ string public SELF_CHAIN_SHORT_NAME;
62
+
63
+ constructor(
64
+ address lzEndpoint,
65
+ address sendUln302_,
66
+ address receiveUln302_,
67
+ address govProxy_,
68
+ address oftProxyAdmin_,
69
+ address hubPtOftAdapterCreationCode,
70
+ address spokePtOftCreationCode,
71
+ address transparentProxyCreationCode
72
+ ) OAppUpgradeable(lzEndpoint) {
73
+ LZ_EID = ILayerZeroEndpointV2(lzEndpoint).eid();
74
+ LZ_SEND_ULN_302 = sendUln302_;
75
+ LZ_RECEIVE_ULN_302 = receiveUln302_;
76
+
77
+ GOV_PROXY = IPGovernanceProxy(govProxy_);
78
+ OFT_PROXY_ADMIN = oftProxyAdmin_;
79
+
80
+ HUB_PT_OFT_ADAPTER_CREATION_CODE = hubPtOftAdapterCreationCode;
81
+ SPOKE_PT_OFT_CREATION_CODE = spokePtOftCreationCode;
82
+ TRANSPARENT_PROXY_CREATION_CODE = transparentProxyCreationCode;
83
+
84
+ _disableInitializers();
85
+ }
86
+
87
+ function initialize(address delegateOwner, string memory selfChainShortName) external initializer {
88
+ __OApp_init(delegateOwner);
89
+
90
+ _transferOwnership(delegateOwner);
91
+ SELF_CHAIN_SHORT_NAME = selfChainShortName;
92
+ }
93
+
94
+ ////////////////////////////////////////////////////////////////////////////////
95
+ /// Getters
96
+ ////////////////////////////////////////////////////////////////////////////////
97
+
98
+ function derivePtOftAddress(uint32 peerLzEid, uint32 hubLzEid, address hubPt) public view returns (address) {
99
+ address peer;
100
+
101
+ if (peerLzEid == LZ_EID) {
102
+ peer = address(this);
103
+ } else {
104
+ bytes32 peerBytes32 = peers(peerLzEid);
105
+ require(peerBytes32 != bytes32(0), "PendleBridgePTFactory: peer not set");
106
+
107
+ peer = peerBytes32.toAddress();
108
+ }
109
+
110
+ bytes32 initCodeHash = keccak256(_getTransparentProxyInitCode(peer));
111
+
112
+ return Create2.computeAddress(_oftDeploymentSalt(hubLzEid, hubPt), initCodeHash, peer);
113
+ }
114
+
115
+ ////////////////////////////////////////////////////////////////////////////////
116
+ /// lzReceive
117
+ ////////////////////////////////////////////////////////////////////////////////
118
+
119
+ enum CrossChainMsgType {
120
+ DEPLOY_SPOKE_PT_OFT,
121
+ REMOTE_WIRE_PT_OFT,
122
+ REMOTE_SELF_WIRE
123
+ }
124
+
125
+ function _lzReceive(
126
+ Origin calldata origin,
127
+ bytes32, // guid
128
+ bytes calldata message,
129
+ address, // executor
130
+ bytes calldata // extraData
131
+ )
132
+ internal
133
+ override
134
+ {
135
+ CrossChainMsgType msgType = abi.decode(message[:32], (CrossChainMsgType));
136
+
137
+ if (msgType == CrossChainMsgType.DEPLOY_SPOKE_PT_OFT) {
138
+ (, SpokePtDeploymentParams memory params) =
139
+ abi.decode(message, (CrossChainMsgType, SpokePtDeploymentParams));
140
+ _lzReceive_deploySpokePtOft(origin.srcEid, params);
141
+ } else if (msgType == CrossChainMsgType.REMOTE_WIRE_PT_OFT) {
142
+ (, WirePtOftParams memory params) = abi.decode(message, (CrossChainMsgType, WirePtOftParams));
143
+ _lzReceive_remoteWirePtOft(params);
144
+ } else if (msgType == CrossChainMsgType.REMOTE_SELF_WIRE) {
145
+ (, SelfWireParams memory params) = abi.decode(message, (CrossChainMsgType, SelfWireParams));
146
+ _lzReceive_remoteSelfWire(params);
147
+ } else {
148
+ // unreachable
149
+ assert(false);
150
+ }
151
+ }
152
+
153
+ ////////////////////////////////////////////////////////////////////////////////
154
+ /// Deploy hub PT OFT adapter
155
+ ////////////////////////////////////////////////////////////////////////////////
156
+
157
+ function deployHubPtOftAdapter(address hubPt) external onlyOwner returns (address oft) {
158
+ return _deployOft_selfGrantScopedAccesses({
159
+ impl: _deployCreate(HUB_PT_OFT_ADAPTER_CREATION_CODE, abi.encode(hubPt, _lzEndpoint())),
160
+ initCall: abi.encodeCall(OFTAdapterImpl.initialize, address(GOV_PROXY)),
161
+ hubEid: LZ_EID,
162
+ hubPt: hubPt
163
+ });
164
+ }
165
+
166
+ function _deployOft_selfGrantScopedAccesses(address impl, bytes memory initCall, uint32 hubEid, address hubPt)
167
+ internal
168
+ returns (address oft)
169
+ {
170
+ oft = Create2.deploy(0, _oftDeploymentSalt(hubEid, hubPt), _getTransparentProxyInitCode(address(this)));
171
+ ITransparentUpgradeableProxy(oft).upgradeToAndCall(impl, initCall);
172
+ ITransparentUpgradeableProxy(oft).changeAdmin(OFT_PROXY_ADMIN);
173
+
174
+ {
175
+ address[] memory targets = new address[](1);
176
+ targets[0] = oft;
177
+ bool[] memory allowed = new bool[](1);
178
+ allowed[0] = true;
179
+
180
+ GOV_PROXY.modifyScopedAccess(address(this), targets, IOAppCore.setPeer.selector, allowed);
181
+ GOV_PROXY.modifyScopedAccess(address(this), targets, IOAppOptionsType3.setEnforcedOptions.selector, allowed);
182
+ }
183
+
184
+ emit PTOFTDeployed(hubEid, hubPt.toBytes32(), oft);
185
+ }
186
+
187
+ ////////////////////////////////////////////////////////////////////////////////
188
+ /// Deploy spoke PT OFT
189
+ ////////////////////////////////////////////////////////////////////////////////
190
+
191
+ function quoteDeploySpokePtOft(address hubPt, uint32 toPeerEid, bytes calldata options, bool payInLzToken)
192
+ external
193
+ view
194
+ returns (MessagingFee memory fee)
195
+ {
196
+ return _quote({
197
+ _dstEid: toPeerEid,
198
+ _message: _buildDeploySpokePtOftMsg(hubPt),
199
+ _options: options,
200
+ _payInLzToken: payInLzToken
201
+ });
202
+ }
203
+
204
+ function deploySpokePtOft(address hubPt, uint32 toPeerEid, bytes calldata options, MessagingFee memory fee)
205
+ external
206
+ payable
207
+ onlyOwner
208
+ returns (MessagingReceipt memory msgReceipt)
209
+ {
210
+ return _lzSend({
211
+ _dstEid: toPeerEid,
212
+ _message: _buildDeploySpokePtOftMsg(hubPt),
213
+ _options: options,
214
+ _fee: fee,
215
+ _refundAddress: msg.sender
216
+ });
217
+ }
218
+
219
+ function _lzReceive_deploySpokePtOft(uint32 hubEid, SpokePtDeploymentParams memory params) internal {
220
+ _deployOft_selfGrantScopedAccesses({
221
+ impl: _deployCreate(SPOKE_PT_OFT_CREATION_CODE, abi.encode(_lzEndpoint(), params.expiry, params.decimals)),
222
+ initCall: abi.encodeCall(
223
+ PendleBridgedPrincipalToken.initialize, (params.name, params.symbol, address(GOV_PROXY))
224
+ ),
225
+ hubEid: hubEid,
226
+ hubPt: params.hubPt
227
+ });
228
+ }
229
+
230
+ /// @dev Should only be called on the hub chain, where the hubPT is deployed
231
+ function _buildDeploySpokePtOftMsg(address hubPt) internal view returns (bytes memory) {
232
+ IPPrincipalToken pt = IPPrincipalToken(hubPt);
233
+ string memory selfChainShortName = SELF_CHAIN_SHORT_NAME;
234
+ SpokePtDeploymentParams memory params = SpokePtDeploymentParams({
235
+ hubPt: hubPt,
236
+ name: string.concat(pt.name(), " (", selfChainShortName, ")"),
237
+ symbol: string.concat(pt.symbol(), "-(", selfChainShortName, ")"),
238
+ expiry: pt.expiry(),
239
+ decimals: pt.decimals()
240
+ });
241
+ return abi.encode(CrossChainMsgType.DEPLOY_SPOKE_PT_OFT, params);
242
+ }
243
+
244
+ ////////////////////////////////////////////////////////////////////////////////
245
+ /// wirePtOft on the self chain
246
+ ////////////////////////////////////////////////////////////////////////////////
247
+
248
+ function wirePtOft(WirePtOftParams memory params) external onlyOwner {
249
+ _wirePtOft(params);
250
+ }
251
+
252
+ function _wirePtOft(WirePtOftParams memory params) internal {
253
+ _validateWirePtOftParams(params);
254
+ uint256 numCallsPerPt = 4;
255
+ if (params.setSendLib) numCallsPerPt++;
256
+ if (params.setReceiveLib) numCallsPerPt++;
257
+ IPGovernanceProxy.Call[] memory calls = new IPGovernanceProxy.Call[](numCallsPerPt * params.toPeerEids.length);
258
+ address thisOft = derivePtOftAddress(LZ_EID, params.hubLzEid, params.hubPt);
259
+
260
+ uint256 callIdx = 0;
261
+ for (uint256 i = 0; i < params.toPeerEids.length; i++) {
262
+ uint32 toPeerEid = params.toPeerEids[i];
263
+ address peerOft = derivePtOftAddress(toPeerEid, params.hubLzEid, params.hubPt);
264
+
265
+ uint128 enforcedReceiveGas = params.enforcedReceiveGas[i];
266
+ if (enforcedReceiveGas == 0) enforcedReceiveGas = DEFAULT_PT_OFT_ENFORCED_RECEIVE_GAS;
267
+
268
+ // setPeer
269
+ {
270
+ calls[callIdx].target = thisOft;
271
+ calls[callIdx].callData = abi.encodeCall(IOAppCore.setPeer, (toPeerEid, peerOft.toBytes32()));
272
+ callIdx++;
273
+ }
274
+
275
+ // setEnforcedOptions
276
+ {
277
+ EnforcedOptionParam[] memory enforcedOptions = new EnforcedOptionParam[](1);
278
+ enforcedOptions[0] = EnforcedOptionParam({
279
+ eid: toPeerEid,
280
+ msgType: ENFORCED_OFT_SEND_MSGTYPE,
281
+ options: OptionsBuilder.newOptions()
282
+ .addExecutorLzReceiveOption({_gas: enforcedReceiveGas, _value: 0})
283
+ });
284
+ calls[callIdx].target = thisOft;
285
+ calls[callIdx].callData = abi.encodeCall(IOAppOptionsType3.setEnforcedOptions, (enforcedOptions));
286
+ callIdx++;
287
+ }
288
+
289
+ // set send lib
290
+ if (params.setSendLib) {
291
+ calls[callIdx].target = address(_lzEndpoint());
292
+ calls[callIdx].callData =
293
+ abi.encodeCall(IMessageLibManager.setSendLibrary, (thisOft, toPeerEid, LZ_SEND_ULN_302));
294
+ callIdx++;
295
+ }
296
+
297
+ // set receive lib
298
+ if (params.setReceiveLib) {
299
+ calls[callIdx].target = address(_lzEndpoint());
300
+ calls[callIdx].callData = abi.encodeCall(
301
+ IMessageLibManager.setReceiveLibrary,
302
+ (thisOft, toPeerEid, LZ_RECEIVE_ULN_302, LZ_RECEIVE_LIB_GRACE_PERIOD)
303
+ );
304
+ callIdx++;
305
+ }
306
+
307
+ // setup send lib
308
+ {
309
+ SetConfigParam[] memory sendConfigParam = new SetConfigParam[](2);
310
+ sendConfigParam[0] = _getSelfLzConfig(LZ_SEND_ULN_302, toPeerEid, LZ_CONFIG_TYPE_ULN);
311
+ sendConfigParam[1] = _getSelfLzConfig(LZ_SEND_ULN_302, toPeerEid, LZ_CONFIG_TYPE_EXECUTOR);
312
+ calls[callIdx].target = address(_lzEndpoint());
313
+ calls[callIdx].callData =
314
+ abi.encodeCall(IMessageLibManager.setConfig, (thisOft, LZ_SEND_ULN_302, sendConfigParam));
315
+ callIdx++;
316
+ }
317
+
318
+ // setup receive lib
319
+ {
320
+ SetConfigParam[] memory receiveConfigParam = new SetConfigParam[](1);
321
+ receiveConfigParam[0] = _getSelfLzConfig(LZ_RECEIVE_ULN_302, toPeerEid, LZ_CONFIG_TYPE_ULN);
322
+ calls[callIdx].target = address(_lzEndpoint());
323
+ calls[callIdx].callData =
324
+ abi.encodeCall(IMessageLibManager.setConfig, (thisOft, LZ_RECEIVE_ULN_302, receiveConfigParam));
325
+ callIdx++;
326
+ }
327
+ }
328
+
329
+ GOV_PROXY.aggregateWithScopedAccess(calls);
330
+
331
+ emit PTOFTWired(params.hubLzEid, params.hubPt, params.toPeerEids);
332
+ }
333
+
334
+ function _getSelfLzConfig(address lib, uint32 toEid, uint32 configType)
335
+ internal
336
+ view
337
+ returns (SetConfigParam memory res)
338
+ {
339
+ res.eid = toEid;
340
+ res.configType = configType;
341
+ res.config = _lzEndpoint().getConfig(address(this), lib, toEid, configType);
342
+ }
343
+
344
+ ////////////////////////////////////////////////////////////////////////////////
345
+ /// Remote wirePtOft on the other chains
346
+ ////////////////////////////////////////////////////////////////////////////////
347
+
348
+ function quoteRemoteWirePtOft(
349
+ uint32 peerEid,
350
+ WirePtOftParams calldata wireParams,
351
+ bytes calldata options,
352
+ bool payInLzToken
353
+ ) public view returns (MessagingFee memory fee) {
354
+ return _quote({
355
+ _dstEid: peerEid,
356
+ _message: _buildRemoteWirePtOftMsg(wireParams),
357
+ _options: options,
358
+ _payInLzToken: payInLzToken
359
+ });
360
+ }
361
+
362
+ function remoteWirePtOft(
363
+ uint32 peerEid,
364
+ WirePtOftParams calldata wireParams,
365
+ bytes calldata options,
366
+ MessagingFee memory fee
367
+ ) public payable onlyOwner returns (MessagingReceipt memory msgReceipt) {
368
+ return _lzSend({
369
+ _dstEid: peerEid,
370
+ _message: _buildRemoteWirePtOftMsg(wireParams),
371
+ _options: options,
372
+ _fee: fee,
373
+ _refundAddress: msg.sender
374
+ });
375
+ }
376
+
377
+ function _lzReceive_remoteWirePtOft(WirePtOftParams memory wireParams) internal {
378
+ _wirePtOft(wireParams);
379
+ }
380
+
381
+ function _buildRemoteWirePtOftMsg(WirePtOftParams calldata wireParams) internal pure returns (bytes memory) {
382
+ _validateWirePtOftParams(wireParams);
383
+ return abi.encode(CrossChainMsgType.REMOTE_WIRE_PT_OFT, wireParams);
384
+ }
385
+
386
+ ////////////////////////////////////////////////////////////////////////////////
387
+ /// self wire
388
+ ////////////////////////////////////////////////////////////////////////////////
389
+
390
+ function selfWire(SelfWireParams memory params) external onlyOwner {
391
+ _selfWire(params);
392
+ }
393
+
394
+ function _selfWire(SelfWireParams memory params) internal {
395
+ _setPeer(params.peerEid, params.peer.toBytes32());
396
+ if (params.setSendLib) {
397
+ _lzEndpoint().setSendLibrary(address(this), params.peerEid, LZ_SEND_ULN_302);
398
+ }
399
+ if (params.setReceiveLib) {
400
+ _lzEndpoint()
401
+ .setReceiveLibrary(address(this), params.peerEid, LZ_RECEIVE_ULN_302, LZ_RECEIVE_LIB_GRACE_PERIOD);
402
+ }
403
+ _lzEndpoint().setConfig(address(this), LZ_SEND_ULN_302, params.sendConfigParam);
404
+ _lzEndpoint().setConfig(address(this), LZ_RECEIVE_ULN_302, params.receiveConfigParam);
405
+
406
+ emit FactoryWired(params.peerEid, params.peer);
407
+ }
408
+
409
+ // Source:
410
+ // https://github.com/LayerZero-Labs/devtools/blob/128b697838f4b0fd53ae748093fd66cc409ae5c4/packages/oapp-evm-upgradeable/contracts/oapp/OAppCoreUpgradeable.sol#L75-L78
411
+ // Change: `onlyOwner` modifier is removed
412
+ function _setPeer(uint32 _eid, bytes32 _peer) internal {
413
+ OAppCoreStorage storage $ = _getOAppCoreStorage();
414
+ $.peers[_eid] = _peer;
415
+ emit PeerSet(_eid, _peer);
416
+ }
417
+
418
+ ////////////////////////////////////////////////////////////////////////////////
419
+ /// Remote self wire
420
+ ////////////////////////////////////////////////////////////////////////////////
421
+
422
+ function quoteRemoteSelfWire(
423
+ uint32 peerEid,
424
+ SelfWireParams calldata wireParams,
425
+ bytes calldata options,
426
+ bool payInLzToken
427
+ ) external view returns (MessagingFee memory fee) {
428
+ return _quote({
429
+ _dstEid: peerEid,
430
+ _message: _buildRemoteSelfWireMsg(wireParams),
431
+ _options: options,
432
+ _payInLzToken: payInLzToken
433
+ });
434
+ }
435
+
436
+ function remoteSelfWire(
437
+ uint32 peerEid,
438
+ SelfWireParams calldata wireParams,
439
+ bytes calldata options,
440
+ MessagingFee memory fee
441
+ ) external payable onlyOwner returns (MessagingReceipt memory msgReceipt) {
442
+ return _lzSend({
443
+ _dstEid: peerEid,
444
+ _message: _buildRemoteSelfWireMsg(wireParams),
445
+ _options: options,
446
+ _fee: fee,
447
+ _refundAddress: msg.sender
448
+ });
449
+ }
450
+
451
+ function _buildRemoteSelfWireMsg(SelfWireParams memory params) internal pure returns (bytes memory message) {
452
+ return abi.encode(CrossChainMsgType.REMOTE_SELF_WIRE, params);
453
+ }
454
+
455
+ function _lzReceive_remoteSelfWire(SelfWireParams memory params) internal {
456
+ _selfWire(params);
457
+ }
458
+
459
+ ////////////////////////////////////////////////////////////////////////////////
460
+ /// Initcode internal helpers
461
+ ////////////////////////////////////////////////////////////////////////////////
462
+
463
+ function _oftDeploymentSalt(uint32 hubEid, address hubPt) internal pure returns (bytes32) {
464
+ return keccak256(abi.encode("PendleBridgePTFactory", hubEid, hubPt));
465
+ }
466
+
467
+ function _getTransparentProxyInitCode(address deployer) internal view returns (bytes memory initcode) {
468
+ // Make the deployer both the owner and logic, then replace it later
469
+ return abi.encodePacked(TRANSPARENT_PROXY_CREATION_CODE.code, abi.encode(deployer, deployer, bytes("")));
470
+ }
471
+
472
+ ////////////////////////////////////////////////////////////////////////////////
473
+ /// Other internal helpers
474
+ ////////////////////////////////////////////////////////////////////////////////
475
+
476
+ // alias super's property for clarity
477
+ function _lzEndpoint() internal view returns (ILayerZeroEndpointV2) {
478
+ return endpoint;
479
+ }
480
+
481
+ function _deployCreate(address codeAddr, bytes memory params) internal returns (address deployed) {
482
+ bytes memory initcode = abi.encodePacked(codeAddr.code, params);
483
+ assembly {
484
+ deployed := create(0, add(initcode, 0x20), mload(initcode))
485
+ }
486
+ require(deployed != address(0), "deployment failed");
487
+ }
488
+
489
+ function _validateWirePtOftParams(WirePtOftParams memory wireParams) internal pure {
490
+ require(
491
+ wireParams.toPeerEids.length == wireParams.enforcedReceiveGas.length,
492
+ "PendleBridgePTFactory: WirePtOftParams length mismatch"
493
+ );
494
+ }
495
+ }
@@ -10,9 +10,10 @@ import {
10
10
  } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
11
11
  import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
12
12
 
13
- // @notice Base OFT contract, without any additional functionality (like RateLimiter).
14
- // @dev This contract inherits Ownable from OpenZeppelin v4.
15
- // @dev Sender is set as the contract owner at deployment.
13
+ /// @notice Base OFT contract, without any additional functionality (like RateLimiter).
14
+ /// @notice Contract deployer must be IPBridgePTFactory for additional information.
15
+ /// This is for deterministic deployment.
16
+ /// @dev This contract inherits Ownable from OpenZeppelin v4.
16
17
  contract OFTAdapterAltImpl is OFTAdapterImpl {
17
18
  using SafeERC20 for IERC20;
18
19
 
@@ -21,7 +22,7 @@ contract OFTAdapterAltImpl is OFTAdapterImpl {
21
22
 
22
23
  address public immutable nativeToken;
23
24
 
24
- constructor(address _token, address _endpoint, address _delegate) OFTAdapterImpl(_token, _endpoint, _delegate) {
25
+ constructor(address _token, address _lzEndpoint) OFTAdapterImpl(_token, _lzEndpoint) {
25
26
  nativeToken = endpoint.nativeToken();
26
27
  }
27
28
 
@@ -2,11 +2,19 @@
2
2
 
3
3
  pragma solidity ^0.8.0;
4
4
 
5
- import {OFTAdapter} from "@layerzerolabs/oft-evm/contracts/OFTAdapter.sol";
5
+ import {OFTAdapterUpgradeable} from "@layerzerolabs/oft-evm-upgradeable/contracts/oft/OFTAdapterUpgradeable.sol";
6
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) {}
7
+ /// @notice Base OFT contract, without any additional functionality (like RateLimiter).
8
+ /// @notice Contract deployer must be IPBridgePTFactory for additional information.
9
+ /// This is for deterministic deployment.
10
+ /// @dev This contract inherits Ownable from OpenZeppelin v4.
11
+ contract OFTAdapterImpl is OFTAdapterUpgradeable {
12
+ constructor(address _token, address _lzEndpoint) OFTAdapterUpgradeable(_token, _lzEndpoint) {
13
+ _disableInitializers();
14
+ }
15
+
16
+ function initialize(address ownerDelegate) external initializer {
17
+ __OFTAdapter_init(ownerDelegate);
18
+ _transferOwnership(ownerDelegate);
19
+ }
12
20
  }
@@ -0,0 +1,11 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ pragma solidity ^0.8.22;
3
+
4
+ import {OFT} from "@layerzerolabs/oft-evm/contracts/OFT.sol";
5
+
6
+ /// @dev This contract inherits Ownable from OpenZeppelin v4.
7
+ contract PendleOFT is OFT {
8
+ constructor(address _lzEndpoint, address _delegate) OFT("Pendle", "PENDLE", _lzEndpoint, _delegate) {
9
+ _transferOwnership(_delegate);
10
+ }
11
+ }
@@ -0,0 +1,52 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ pragma solidity ^0.8.22;
3
+
4
+ import {PendleOFT} from "./PendleOFT.sol";
5
+ import {
6
+ MessagingParams,
7
+ MessagingFee,
8
+ MessagingReceipt
9
+ } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
10
+ import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
11
+
12
+ /// @dev This contract inherits Ownable from OpenZeppelin v4.
13
+ contract PendleOFTAlt is PendleOFT {
14
+ using SafeERC20 for IERC20;
15
+
16
+ error MsgValueNotZero(uint256 msgValue);
17
+ error NativeTokenUnavailable();
18
+
19
+ address public immutable nativeToken;
20
+
21
+ constructor(address _lzEndpoint, address _delegate) PendleOFT(_lzEndpoint, _delegate) {
22
+ nativeToken = endpoint.nativeToken();
23
+ }
24
+
25
+ function _lzSend(
26
+ uint32 _dstEid,
27
+ bytes memory _message,
28
+ bytes memory _options,
29
+ MessagingFee memory _fee,
30
+ address _refundAddress
31
+ ) internal override returns (MessagingReceipt memory receipt) {
32
+ // In Alt implementation, msg.value should always be 0 since we use ERC20 tokens for fees
33
+ if (msg.value > 0) revert MsgValueNotZero(msg.value);
34
+
35
+ // Push corresponding fees to the endpoint, any excess is sent back to the _refundAddress from the endpoint.
36
+ _payNative(_fee.nativeFee);
37
+ if (_fee.lzTokenFee > 0) _payLzToken(_fee.lzTokenFee);
38
+
39
+ return endpoint.send(
40
+ MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _fee.lzTokenFee > 0), _refundAddress
41
+ );
42
+ }
43
+
44
+ function _payNative(uint256 _nativeFee) internal override returns (uint256 nativeFee) {
45
+ if (nativeToken == address(0)) revert NativeTokenUnavailable();
46
+
47
+ // Pay Native token fee by sending tokens to the endpoint.
48
+ IERC20(nativeToken).safeTransferFrom(msg.sender, address(endpoint), _nativeFee);
49
+
50
+ return _nativeFee;
51
+ }
52
+ }