@pendle/core-v2 5.4.2 → 5.4.4-beta-okx-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.
- package/build/artifacts/contracts/LiquidityMining/PendleMultiTokenMerkleDistributor.sol/PendleMultiTokenMerkleDistributor.dbg.json +4 -0
- package/build/artifacts/contracts/LiquidityMining/PendleMultiTokenMerkleDistributor.sol/PendleMultiTokenMerkleDistributor.json +462 -0
- package/build/artifacts/contracts/interfaces/IPActionAddRemoveLiqV3.sol/IPActionAddRemoveLiqV3.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPActionMarketAuxStatic.sol/IPActionMarketAuxStatic.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPActionMiscV3.sol/IPActionMiscV3.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPActionSimple.sol/IPActionSimple.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPActionStorageStatic.sol/IPActionStorageStatic.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPActionStorageV4.sol/IPActionStorageV4.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPActionSwapPTV3.sol/IPActionSwapPTV3.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPActionSwapYTV3.sol/IPActionSwapYTV3.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPAllActionV3.sol/IPAllActionV3.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPAllEventsV3.sol/IPActionAddRemoveLiqV3Events.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPAllEventsV3.sol/IPActionMiscV3Events.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPAllEventsV3.sol/IPActionStorageEvents.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPAllEventsV3.sol/IPActionSwapPTV3Events.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPAllEventsV3.sol/IPActionSwapYTV3Events.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPAllEventsV3.sol/IPAllEventsV3.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPMultiTokenMerkleDistributor.sol/IPMultiTokenMerkleDistributor.dbg.json +4 -0
- package/build/artifacts/contracts/interfaces/IPMultiTokenMerkleDistributor.sol/IPMultiTokenMerkleDistributor.json +251 -0
- package/build/artifacts/contracts/interfaces/IPRouterStatic.sol/IPRouterStatic.dbg.json +1 -1
- package/build/artifacts/contracts/offchain-helpers/PendlePoolDeployHelper.sol/PendlePoolDeployHelper.dbg.json +1 -1
- package/build/artifacts/contracts/offchain-helpers/PendlePoolDeployHelper.sol/PendlePoolDeployHelper.json +2 -2
- package/build/artifacts/contracts/offchain-helpers/router-static/PendleRouterStatic.sol/PendleRouterStatic.dbg.json +1 -1
- package/build/artifacts/contracts/offchain-helpers/router-static/PendleRouterStatic.sol/PendleRouterStatic.json +2 -2
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionInfoStatic.sol/ActionInfoStatic.dbg.json +1 -1
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionInfoStatic.sol/ActionInfoStatic.json +2 -2
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMarketAuxStatic.sol/ActionMarketAuxStatic.dbg.json +1 -1
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMarketAuxStatic.sol/ActionMarketAuxStatic.json +2 -2
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMarketCoreStatic.sol/ActionMarketCoreStatic.dbg.json +1 -1
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMarketCoreStatic.sol/ActionMarketCoreStatic.json +2 -2
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMintRedeemStatic.sol/ActionMintRedeemStatic.dbg.json +1 -1
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMintRedeemStatic.sol/ActionMintRedeemStatic.json +2 -2
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionStorageStatic.sol/ActionStorageStatic.dbg.json +1 -1
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionStorageStatic.sol/ActionStorageStatic.json +2 -2
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionVePendleStatic.sol/ActionVePendleStatic.dbg.json +1 -1
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionVePendleStatic.sol/ActionVePendleStatic.json +2 -2
- package/build/artifacts/contracts/offchain-helpers/router-static/base/MarketApproxLibV1.sol/MarketApproxPtInLibV1.dbg.json +1 -1
- package/build/artifacts/contracts/offchain-helpers/router-static/base/MarketApproxLibV1.sol/MarketApproxPtInLibV1.json +2 -2
- package/build/artifacts/contracts/offchain-helpers/router-static/base/MarketApproxLibV1.sol/MarketApproxPtOutLibV1.dbg.json +1 -1
- package/build/artifacts/contracts/offchain-helpers/router-static/base/MarketApproxLibV1.sol/MarketApproxPtOutLibV1.json +2 -2
- package/build/artifacts/contracts/offchain-helpers/router-static/base/StorageLayout.sol/StorageLayout.dbg.json +1 -1
- package/build/artifacts/contracts/router/ActionAddRemoveLiqV3.sol/ActionAddRemoveLiqV3.dbg.json +1 -1
- package/build/artifacts/contracts/router/ActionAddRemoveLiqV3.sol/ActionAddRemoveLiqV3.json +2 -2
- package/build/artifacts/contracts/router/ActionMiscV3.sol/ActionMiscV3.dbg.json +1 -1
- package/build/artifacts/contracts/router/ActionMiscV3.sol/ActionMiscV3.json +2 -2
- package/build/artifacts/contracts/router/ActionSimple.sol/ActionSimple.dbg.json +1 -1
- package/build/artifacts/contracts/router/ActionSimple.sol/ActionSimple.json +2 -2
- package/build/artifacts/contracts/router/ActionStorageV4.sol/ActionStorageV4.dbg.json +1 -1
- package/build/artifacts/contracts/router/ActionStorageV4.sol/ActionStorageV4.json +2 -2
- package/build/artifacts/contracts/router/ActionSwapPTV3.sol/ActionSwapPTV3.dbg.json +1 -1
- package/build/artifacts/contracts/router/ActionSwapPTV3.sol/ActionSwapPTV3.json +2 -2
- package/build/artifacts/contracts/router/ActionSwapYTV3.sol/ActionSwapYTV3.dbg.json +1 -1
- package/build/artifacts/contracts/router/ActionSwapYTV3.sol/ActionSwapYTV3.json +2 -2
- package/build/artifacts/contracts/router/PendleRouterV4.sol/PendleRouterV4.dbg.json +1 -1
- package/build/artifacts/contracts/router/PendleRouterV4.sol/PendleRouterV4.json +2 -2
- package/build/artifacts/contracts/router/Reflector.sol/Reflector.dbg.json +1 -1
- package/build/artifacts/contracts/router/Reflector.sol/Reflector.json +2 -2
- package/build/artifacts/contracts/router/base/ActionBase.sol/ActionBase.dbg.json +1 -1
- package/build/artifacts/contracts/router/base/ActionDelegateBase.sol/ActionDelegateBase.dbg.json +1 -1
- package/build/artifacts/contracts/router/base/ActionDelegateBase.sol/ActionDelegateBase.json +2 -2
- package/build/artifacts/contracts/router/math/ApproxStateLib.sol/ApproxStateLib.dbg.json +1 -1
- package/build/artifacts/contracts/router/math/ApproxStateLib.sol/ApproxStateLib.json +2 -2
- package/build/artifacts/contracts/router/math/MarketApproxLibOnchain.sol/MarketApproxPtInLibOnchain.dbg.json +1 -1
- package/build/artifacts/contracts/router/math/MarketApproxLibOnchain.sol/MarketApproxPtInLibOnchain.json +2 -2
- package/build/artifacts/contracts/router/math/MarketApproxLibOnchain.sol/MarketApproxPtOutLibOnchain.dbg.json +1 -1
- package/build/artifacts/contracts/router/math/MarketApproxLibOnchain.sol/MarketApproxPtOutLibOnchain.json +2 -2
- package/build/artifacts/contracts/router/math/MarketApproxLibV2.sol/MarketApproxPtInLibV2.dbg.json +1 -1
- package/build/artifacts/contracts/router/math/MarketApproxLibV2.sol/MarketApproxPtInLibV2.json +2 -2
- package/build/artifacts/contracts/router/math/MarketApproxLibV2.sol/MarketApproxPtOutLibV2.dbg.json +1 -1
- package/build/artifacts/contracts/router/math/MarketApproxLibV2.sol/MarketApproxPtOutLibV2.json +2 -2
- package/build/artifacts/contracts/router/swap-aggregator/IPSwapAggregator.sol/IPSwapAggregator.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/IPSwapAggregator.sol/IPSwapAggregator.json +0 -40
- package/build/artifacts/contracts/router/swap-aggregator/OKXScaleHelper.sol/IOKXDexRouter.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/OKXScaleHelper.sol/IOKXDexRouter.json +407 -0
- package/build/artifacts/contracts/router/swap-aggregator/OKXScaleHelper.sol/OKXScaleHelper.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/OKXScaleHelper.sol/OKXScaleHelper.json +10 -0
- package/build/artifacts/contracts/router/swap-aggregator/OneInchScaleHelper.sol/I1inchAggregationRouterV6.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/OneInchScaleHelper.sol/I1inchAggregationRouterV6.json +214 -0
- package/build/artifacts/contracts/router/swap-aggregator/OneInchScaleHelper.sol/I1inchCommonType.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/OneInchScaleHelper.sol/I1inchCommonType.json +10 -0
- package/build/artifacts/contracts/router/swap-aggregator/OneInchScaleHelper.sol/OneInchScaleHelper.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/OneInchScaleHelper.sol/OneInchScaleHelper.json +10 -0
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/IKyberScalingHelper.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/IOdosRouterV2.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/PendleSwap.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/PendleSwap.json +2 -55
- package/contracts/LiquidityMining/PendleMultiTokenMerkleDistributor.sol +117 -0
- package/contracts/interfaces/IPMultiTokenMerkleDistributor.sol +33 -0
- package/contracts/router/swap-aggregator/IPSwapAggregator.sol +0 -2
- package/contracts/router/swap-aggregator/OKXScaleHelper.sol +215 -0
- package/contracts/router/swap-aggregator/OneInchScaleHelper.sol +120 -0
- package/contracts/router/swap-aggregator/PendleSwap.sol +24 -7
- package/deployments/1-core.json +2 -1
- package/deployments/10-core.json +2 -1
- package/deployments/42161-core.json +2 -1
- package/deployments/5000-core.json +2 -1
- package/deployments/56-core.json +2 -1
- package/deployments/8453-core.json +2 -1
- package/package.json +1 -1
- package/typechain-types/I1inchAggregationRouterV6.ts +337 -0
- package/typechain-types/IPMultiTokenMerkleDistributor.ts +363 -0
- package/typechain-types/IPSwapAggregator.ts +0 -39
- package/typechain-types/PendleMultiTokenMerkleDistributor.ts +677 -0
- package/typechain-types/PendleSwap.ts +0 -60
- package/typechain-types/factories/ActionAddRemoveLiqV3__factory.ts +1 -1
- package/typechain-types/factories/ActionInfoStatic__factory.ts +1 -1
- package/typechain-types/factories/ActionMarketAuxStatic__factory.ts +1 -1
- package/typechain-types/factories/ActionMarketCoreStatic__factory.ts +1 -1
- package/typechain-types/factories/ActionMintRedeemStatic__factory.ts +1 -1
- package/typechain-types/factories/ActionMiscV3__factory.ts +1 -1
- package/typechain-types/factories/ActionSimple__factory.ts +1 -1
- package/typechain-types/factories/ActionStorageStatic__factory.ts +1 -1
- package/typechain-types/factories/ActionStorageV4__factory.ts +1 -1
- package/typechain-types/factories/ActionSwapPTV3__factory.ts +1 -1
- package/typechain-types/factories/ActionSwapYTV3__factory.ts +1 -1
- package/typechain-types/factories/ActionVePendleStatic__factory.ts +1 -1
- package/typechain-types/factories/I1inchAggregationRouterV6__factory.ts +233 -0
- package/typechain-types/factories/IPMultiTokenMerkleDistributor__factory.ts +270 -0
- package/typechain-types/factories/IPSwapAggregator__factory.ts +0 -40
- package/typechain-types/factories/PendleMultiTokenMerkleDistributor__factory.ts +523 -0
- package/typechain-types/factories/PendlePoolDeployHelper__factory.ts +1 -1
- package/typechain-types/factories/PendleRouterStatic__factory.ts +1 -1
- package/typechain-types/factories/PendleRouterV4__factory.ts +1 -1
- package/typechain-types/factories/PendleSwap__factory.ts +1 -54
- package/typechain-types/factories/Reflector__factory.ts +1 -1
- package/typechain-types/hardhat.d.ts +36 -9
- package/typechain-types/index.ts +8 -2
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity ^0.8.17;
|
|
3
|
+
|
|
4
|
+
import "../../core/libraries/TokenHelper.sol";
|
|
5
|
+
import "./IPSwapAggregator.sol";
|
|
6
|
+
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
|
7
|
+
|
|
8
|
+
abstract contract OKXScaleHelper {
|
|
9
|
+
function _okx_getTokenApprove() internal view returns (address) {
|
|
10
|
+
if (block.chainid == 1) {
|
|
11
|
+
return 0x40aA958dd87FC8305b97f2BA922CDdCa374bcD7f;
|
|
12
|
+
}
|
|
13
|
+
if (block.chainid == 10) {
|
|
14
|
+
return 0x68D6B739D2020067D1e2F713b999dA97E4d54812;
|
|
15
|
+
}
|
|
16
|
+
if (block.chainid == 56) {
|
|
17
|
+
return 0x2c34A2Fb1d0b4f55de51E1d0bDEfaDDce6b7cDD6;
|
|
18
|
+
}
|
|
19
|
+
if (block.chainid == 42161) {
|
|
20
|
+
return 0x70cBb871E8f30Fc8Ce23609E9E0Ea87B6b222F58;
|
|
21
|
+
}
|
|
22
|
+
if (block.chainid == 8453) {
|
|
23
|
+
return 0x57df6092665eb6058DE53939612413ff4B09114E;
|
|
24
|
+
}
|
|
25
|
+
if (block.chainid == 5000) {
|
|
26
|
+
return 0x57df6092665eb6058DE53939612413ff4B09114E;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
revert("PendleSwap: OKX Chain not supported");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function _okxScaling(
|
|
33
|
+
bytes calldata rawCallData,
|
|
34
|
+
uint256 actualAmount
|
|
35
|
+
) internal pure returns (bytes memory scaledCallData) {
|
|
36
|
+
bytes4 selector = bytes4(rawCallData[:4]);
|
|
37
|
+
bytes calldata dataToDecode = rawCallData[4:];
|
|
38
|
+
|
|
39
|
+
if (selector == IOKXDexRouter.uniswapV3SwapTo.selector) {
|
|
40
|
+
(uint256 receiver, uint256 amount, uint256 minReturn, uint256[] memory pools) = abi.decode(
|
|
41
|
+
dataToDecode,
|
|
42
|
+
(uint256, uint256, uint256, uint256[])
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
minReturn = (minReturn * actualAmount) / amount;
|
|
46
|
+
amount = actualAmount;
|
|
47
|
+
|
|
48
|
+
return abi.encodeWithSelector(selector, receiver, amount, minReturn, pools);
|
|
49
|
+
} else if (selector == IOKXDexRouter.smartSwapTo.selector) {
|
|
50
|
+
(
|
|
51
|
+
uint256 orderId,
|
|
52
|
+
address receiver,
|
|
53
|
+
IOKXDexRouter.BaseRequest memory baseRequest,
|
|
54
|
+
uint256[] memory batchesAmount,
|
|
55
|
+
IOKXDexRouter.RouterPath[][] memory batches,
|
|
56
|
+
IOKXDexRouter.PMMSwapRequest[] memory extraData
|
|
57
|
+
) = abi.decode(
|
|
58
|
+
dataToDecode,
|
|
59
|
+
(
|
|
60
|
+
uint256,
|
|
61
|
+
address,
|
|
62
|
+
IOKXDexRouter.BaseRequest,
|
|
63
|
+
uint256[],
|
|
64
|
+
IOKXDexRouter.RouterPath[][],
|
|
65
|
+
IOKXDexRouter.PMMSwapRequest[]
|
|
66
|
+
)
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
batchesAmount = _scaleArray(batchesAmount, actualAmount, baseRequest.fromTokenAmount);
|
|
70
|
+
baseRequest.minReturnAmount = (baseRequest.minReturnAmount * actualAmount) / baseRequest.fromTokenAmount;
|
|
71
|
+
baseRequest.fromTokenAmount = actualAmount;
|
|
72
|
+
|
|
73
|
+
return abi.encodeWithSelector(selector, orderId, receiver, baseRequest, batchesAmount, batches, extraData);
|
|
74
|
+
} else if (selector == IOKXDexRouter.unxswapTo.selector) {
|
|
75
|
+
(uint256 srcToken, uint256 amount, uint256 minReturn, address receiver, bytes32[] memory pools) = abi
|
|
76
|
+
.decode(dataToDecode, (uint256, uint256, uint256, address, bytes32[]));
|
|
77
|
+
|
|
78
|
+
minReturn = (minReturn * actualAmount) / amount;
|
|
79
|
+
amount = actualAmount;
|
|
80
|
+
|
|
81
|
+
return abi.encodeWithSelector(selector, srcToken, amount, minReturn, receiver, pools);
|
|
82
|
+
} else if (selector == IOKXDexRouter.unxswapByOrderId.selector) {
|
|
83
|
+
(uint256 srcToken, uint256 amount, uint256 minReturn, bytes32[] memory pools) = abi.decode(
|
|
84
|
+
dataToDecode,
|
|
85
|
+
(uint256, uint256, uint256, bytes32[])
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
minReturn = (minReturn * actualAmount) / amount;
|
|
89
|
+
amount = actualAmount;
|
|
90
|
+
|
|
91
|
+
return abi.encodeWithSelector(selector, srcToken, amount, minReturn, pools);
|
|
92
|
+
} else if (selector == IOKXDexRouter.smartSwapByOrderId.selector) {
|
|
93
|
+
(
|
|
94
|
+
uint256 orderId,
|
|
95
|
+
IOKXDexRouter.BaseRequest memory baseRequest,
|
|
96
|
+
uint256[] memory batchesAmount,
|
|
97
|
+
IOKXDexRouter.RouterPath[][] memory batches,
|
|
98
|
+
IOKXDexRouter.PMMSwapRequest[] memory extraData
|
|
99
|
+
) = abi.decode(
|
|
100
|
+
dataToDecode,
|
|
101
|
+
(
|
|
102
|
+
uint256,
|
|
103
|
+
IOKXDexRouter.BaseRequest,
|
|
104
|
+
uint256[],
|
|
105
|
+
IOKXDexRouter.RouterPath[][],
|
|
106
|
+
IOKXDexRouter.PMMSwapRequest[]
|
|
107
|
+
)
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
batchesAmount = _scaleArray(batchesAmount, actualAmount, baseRequest.fromTokenAmount);
|
|
111
|
+
baseRequest.minReturnAmount = (baseRequest.minReturnAmount * actualAmount) / baseRequest.fromTokenAmount;
|
|
112
|
+
baseRequest.fromTokenAmount = actualAmount;
|
|
113
|
+
|
|
114
|
+
return abi.encodeWithSelector(selector, orderId, baseRequest, batchesAmount, batches, extraData);
|
|
115
|
+
} else {
|
|
116
|
+
revert("PendleSwap: OKX selector not supported");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function _scaleArray(
|
|
121
|
+
uint256[] memory arr,
|
|
122
|
+
uint256 newAmount,
|
|
123
|
+
uint256 oldAmount
|
|
124
|
+
) internal pure returns (uint256[] memory scaledArr) {
|
|
125
|
+
scaledArr = new uint256[](arr.length);
|
|
126
|
+
for (uint256 i = 0; i < arr.length; i++) {
|
|
127
|
+
scaledArr[i] = (arr[i] * newAmount) / oldAmount;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface IOKXDexRouter {
|
|
133
|
+
struct BaseRequest {
|
|
134
|
+
uint256 fromToken;
|
|
135
|
+
address toToken;
|
|
136
|
+
uint256 fromTokenAmount;
|
|
137
|
+
uint256 minReturnAmount;
|
|
138
|
+
uint256 deadLine;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
struct RouterPath {
|
|
142
|
+
address[] mixAdapters;
|
|
143
|
+
address[] assetTo;
|
|
144
|
+
uint256[] rawData;
|
|
145
|
+
bytes[] extraData;
|
|
146
|
+
uint256 fromToken;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
struct PMMSwapRequest {
|
|
150
|
+
uint256 pathIndex;
|
|
151
|
+
address payer;
|
|
152
|
+
address fromToken;
|
|
153
|
+
address toToken;
|
|
154
|
+
uint256 fromTokenAmountMax;
|
|
155
|
+
uint256 toTokenAmountMax;
|
|
156
|
+
uint256 salt;
|
|
157
|
+
uint256 deadLine;
|
|
158
|
+
bool isPushOrder;
|
|
159
|
+
bytes extension;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// // address marketMaker;
|
|
163
|
+
// // uint256 subIndex;
|
|
164
|
+
// // bytes signature;
|
|
165
|
+
// // uint256 source; 1byte type + 1byte bool(reverse) + 0...0 + 20 bytes address
|
|
166
|
+
|
|
167
|
+
// function smartSwapByInvest(
|
|
168
|
+
// BaseRequest calldata baseRequest,
|
|
169
|
+
// uint256[] calldata batchesAmount,
|
|
170
|
+
// RouterPath[][] calldata batches,
|
|
171
|
+
// PMMSwapRequest[] calldata extraData,
|
|
172
|
+
// address to
|
|
173
|
+
// ) external payable;
|
|
174
|
+
|
|
175
|
+
function uniswapV3SwapTo(
|
|
176
|
+
uint256 receiver,
|
|
177
|
+
uint256 amount,
|
|
178
|
+
uint256 minReturn,
|
|
179
|
+
uint256[] calldata pools
|
|
180
|
+
) external payable returns (uint256 returnAmount);
|
|
181
|
+
|
|
182
|
+
function smartSwapTo(
|
|
183
|
+
uint256 orderId,
|
|
184
|
+
address receiver,
|
|
185
|
+
BaseRequest calldata baseRequest,
|
|
186
|
+
uint256[] calldata batchesAmount,
|
|
187
|
+
RouterPath[][] calldata batches,
|
|
188
|
+
PMMSwapRequest[] calldata extraData
|
|
189
|
+
) external payable;
|
|
190
|
+
|
|
191
|
+
function unxswapTo(
|
|
192
|
+
uint256 srcToken,
|
|
193
|
+
uint256 amount,
|
|
194
|
+
uint256 minReturn,
|
|
195
|
+
address receiver,
|
|
196
|
+
// solhint-disable-next-line no-unused-vars
|
|
197
|
+
bytes32[] calldata pools
|
|
198
|
+
) external payable returns (uint256 returnAmount);
|
|
199
|
+
|
|
200
|
+
function unxswapByOrderId(
|
|
201
|
+
uint256 srcToken,
|
|
202
|
+
uint256 amount,
|
|
203
|
+
uint256 minReturn,
|
|
204
|
+
// solhint-disable-next-line no-unused-vars
|
|
205
|
+
bytes32[] calldata pools
|
|
206
|
+
) external payable returns (uint256 returnAmount);
|
|
207
|
+
|
|
208
|
+
function smartSwapByOrderId(
|
|
209
|
+
uint256 orderId,
|
|
210
|
+
BaseRequest calldata baseRequest,
|
|
211
|
+
uint256[] calldata batchesAmount,
|
|
212
|
+
RouterPath[][] calldata batches,
|
|
213
|
+
PMMSwapRequest[] calldata extraData
|
|
214
|
+
) external payable returns (uint256 returnAmount);
|
|
215
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity ^0.8.17;
|
|
3
|
+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
4
|
+
|
|
5
|
+
interface I1inchCommonType {
|
|
6
|
+
type Address256 is uint256;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
abstract contract OneInchScaleHelper is I1inchCommonType {
|
|
10
|
+
function _rescaleMinAmount(
|
|
11
|
+
uint256 minAmount,
|
|
12
|
+
uint256 oldAmount,
|
|
13
|
+
uint256 newAmount
|
|
14
|
+
) internal pure returns (uint256) {
|
|
15
|
+
return (minAmount * newAmount) / oldAmount;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _oneInchScaling(bytes calldata rawCallData, uint256 actualAmount) internal pure returns (bytes memory) {
|
|
19
|
+
bytes4 selector = bytes4(rawCallData[:4]);
|
|
20
|
+
bytes memory args = rawCallData[4:];
|
|
21
|
+
|
|
22
|
+
if (selector == I1inchAggregationRouterV6.unoswapTo.selector) {
|
|
23
|
+
(Address256 to, Address256 token, uint256 amount, uint256 minReturn, Address256 dex) = abi.decode(
|
|
24
|
+
args,
|
|
25
|
+
(Address256, Address256, uint256, uint256, Address256)
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
minReturn = (minReturn * actualAmount) / amount;
|
|
29
|
+
amount = actualAmount;
|
|
30
|
+
return abi.encodeWithSelector(selector, to, token, amount, minReturn, dex);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (selector == I1inchAggregationRouterV6.unoswapTo2.selector) {
|
|
34
|
+
(Address256 to, Address256 token, uint256 amount, uint256 minReturn, Address256 dex, Address256 dex2) = abi
|
|
35
|
+
.decode(args, (Address256, Address256, uint256, uint256, Address256, Address256));
|
|
36
|
+
|
|
37
|
+
minReturn = (minReturn * actualAmount) / amount;
|
|
38
|
+
amount = actualAmount;
|
|
39
|
+
|
|
40
|
+
return abi.encodeWithSelector(selector, to, token, amount, minReturn, dex, dex2);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (selector == I1inchAggregationRouterV6.unoswapTo3.selector) {
|
|
44
|
+
(
|
|
45
|
+
Address256 to,
|
|
46
|
+
Address256 token,
|
|
47
|
+
uint256 amount,
|
|
48
|
+
uint256 minReturn,
|
|
49
|
+
Address256 dex,
|
|
50
|
+
Address256 dex2,
|
|
51
|
+
Address256 dex3
|
|
52
|
+
) = abi.decode(args, (Address256, Address256, uint256, uint256, Address256, Address256, Address256));
|
|
53
|
+
|
|
54
|
+
minReturn = (minReturn * actualAmount) / amount;
|
|
55
|
+
amount = actualAmount;
|
|
56
|
+
|
|
57
|
+
return abi.encodeWithSelector(selector, to, token, amount, minReturn, dex, dex2, dex3);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (selector == I1inchAggregationRouterV6.swap.selector) {
|
|
61
|
+
(address executor, I1inchAggregationRouterV6.SwapDescription memory desc, bytes memory data) = abi.decode(
|
|
62
|
+
args,
|
|
63
|
+
(address, I1inchAggregationRouterV6.SwapDescription, bytes)
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
desc.minReturnAmount = (desc.minReturnAmount * actualAmount) / desc.amount;
|
|
67
|
+
desc.amount = actualAmount;
|
|
68
|
+
return abi.encodeWithSelector(selector, executor, desc, data);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
revert("1inch: unsupported selector");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface I1inchAggregationRouterV6 is I1inchCommonType {
|
|
76
|
+
struct SwapDescription {
|
|
77
|
+
IERC20 srcToken;
|
|
78
|
+
IERC20 dstToken;
|
|
79
|
+
address payable srcReceiver;
|
|
80
|
+
address payable dstReceiver;
|
|
81
|
+
uint256 amount;
|
|
82
|
+
uint256 minReturnAmount;
|
|
83
|
+
uint256 flags;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// we ignore the non-to version since it's guarantee this contract won't receive tokens
|
|
87
|
+
|
|
88
|
+
function unoswapTo(
|
|
89
|
+
Address256 to,
|
|
90
|
+
Address256 token,
|
|
91
|
+
uint256 amount,
|
|
92
|
+
uint256 minReturn,
|
|
93
|
+
Address256 dex
|
|
94
|
+
) external returns (uint256 returnAmount);
|
|
95
|
+
|
|
96
|
+
function unoswapTo2(
|
|
97
|
+
Address256 to,
|
|
98
|
+
Address256 token,
|
|
99
|
+
uint256 amount,
|
|
100
|
+
uint256 minReturn,
|
|
101
|
+
Address256 dex,
|
|
102
|
+
Address256 dex2
|
|
103
|
+
) external returns (uint256 returnAmount);
|
|
104
|
+
|
|
105
|
+
function unoswapTo3(
|
|
106
|
+
Address256 to,
|
|
107
|
+
Address256 token,
|
|
108
|
+
uint256 amount,
|
|
109
|
+
uint256 minReturn,
|
|
110
|
+
Address256 dex,
|
|
111
|
+
Address256 dex2,
|
|
112
|
+
Address256 dex3
|
|
113
|
+
) external returns (uint256 returnAmount);
|
|
114
|
+
|
|
115
|
+
function swap(
|
|
116
|
+
address executor,
|
|
117
|
+
SwapDescription calldata desc,
|
|
118
|
+
bytes calldata data
|
|
119
|
+
) external payable returns (uint256 returnAmount, uint256 spentAmount);
|
|
120
|
+
}
|
|
@@ -3,14 +3,18 @@ pragma solidity ^0.8.17;
|
|
|
3
3
|
|
|
4
4
|
import "../../core/libraries/TokenHelper.sol";
|
|
5
5
|
import "./IPSwapAggregator.sol";
|
|
6
|
+
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
|
7
|
+
import "./OKXScaleHelper.sol";
|
|
8
|
+
import "./OneInchScaleHelper.sol";
|
|
6
9
|
|
|
7
|
-
contract PendleSwap is IPSwapAggregator, TokenHelper {
|
|
10
|
+
contract PendleSwap is IPSwapAggregator, TokenHelper, OKXScaleHelper, OneInchScaleHelper {
|
|
8
11
|
using Address for address;
|
|
12
|
+
using SafeERC20 for IERC20;
|
|
9
13
|
|
|
10
|
-
address
|
|
14
|
+
address private constant KYBER_SCALING_HELPER = 0x2f577A41BeC1BE1152AeEA12e73b7391d15f655D;
|
|
11
15
|
|
|
12
16
|
function swap(address tokenIn, uint256 amountIn, SwapData calldata data) external payable {
|
|
13
|
-
|
|
17
|
+
_approveForExtRouter(tokenIn, data);
|
|
14
18
|
data.extRouter.functionCallWithValue(
|
|
15
19
|
data.needScale ? _getScaledInputData(data.swapType, data.extCalldata, amountIn) : data.extCalldata,
|
|
16
20
|
tokenIn == NATIVE ? amountIn : 0
|
|
@@ -19,11 +23,20 @@ contract PendleSwap is IPSwapAggregator, TokenHelper {
|
|
|
19
23
|
emit SwapSingle(data.swapType, tokenIn, amountIn);
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
function _approveForExtRouter(address token, SwapData calldata data) internal {
|
|
27
|
+
if (token == NATIVE) return;
|
|
28
|
+
|
|
29
|
+
if (data.swapType == SwapType.OKX) {
|
|
30
|
+
_safeApproveInfV2(IERC20(token), _okx_getTokenApprove());
|
|
31
|
+
} else {
|
|
32
|
+
_safeApproveInfV2(IERC20(token), data.extRouter);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function _safeApproveInfV2(IERC20 token, address spender) internal {
|
|
37
|
+
if (token.allowance(address(this), spender) < type(uint256).max) {
|
|
38
|
+
token.forceApprove(spender, type(uint256).max);
|
|
25
39
|
}
|
|
26
|
-
data.extRouter.functionCallWithValue(data.extCalldata, msg.value);
|
|
27
40
|
}
|
|
28
41
|
|
|
29
42
|
function _getScaledInputData(
|
|
@@ -41,6 +54,10 @@ contract PendleSwap is IPSwapAggregator, TokenHelper {
|
|
|
41
54
|
require(isSuccess, "PendleSwap: Kyber scaling failed");
|
|
42
55
|
} else if (swapType == SwapType.ODOS) {
|
|
43
56
|
scaledCallData = _odosScaling(rawCallData, amountIn);
|
|
57
|
+
} else if (swapType == SwapType.OKX) {
|
|
58
|
+
scaledCallData = _okxScaling(rawCallData, amountIn);
|
|
59
|
+
} else if (swapType == SwapType.ONE_INCH) {
|
|
60
|
+
scaledCallData = _oneInchScaling(rawCallData, amountIn);
|
|
44
61
|
} else {
|
|
45
62
|
assert(false);
|
|
46
63
|
}
|
package/deployments/1-core.json
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"ActionStorageV4": "0x6a0Ed0A9193FCBe7ae9B0F3D90F88e365Cca64fC"
|
|
32
32
|
},
|
|
33
33
|
"routerStatic": "0x263833d47eA3fA4a30f269323aba6a107f9eB14C",
|
|
34
|
-
"pendleSwap": "
|
|
34
|
+
"pendleSwap": "0x313e7Ef7d52f5C10aC04ebaa4d33CDc68634c212",
|
|
35
35
|
"pyYtLpOracle": "0x9a9fa8338dd5e5b2188006f1cd2ef26d921650c2",
|
|
36
36
|
"yieldContractFactoryV3": "0xdF3601014686674e53d1Fa52F7602525483F9122",
|
|
37
37
|
"marketFactoryV3": "0x1A6fCc85557BC4fB7B534ed835a03EF056552D52",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"gaugeController": "0x47D74516B33eD5D70ddE7119A40839f6Fcc24e57",
|
|
50
50
|
"feeDistributor": "0xd7b34a6fDCb2A7ceD2115FF7f5fdD72aa6aA4dE2",
|
|
51
51
|
"feeDistributorV2": "0x8C237520a8E14D658170A633D96F8e80764433b9",
|
|
52
|
+
"multiTokenDistributor": "0x3942F7B55094250644cFfDa7160226Caa349A38E",
|
|
52
53
|
"sparkLinearDiscountOracleFactory": "0xA9A924A4BB95509F77868E086154C25e934F6171",
|
|
53
54
|
"beta": {
|
|
54
55
|
"PendleChainlinkOracleFactory": "0x2A73e899389cABa2a2f648BaBA35e67f5C00EFee"
|
package/deployments/10-core.json
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"ActionStorageV4": "0x6a0Ed0A9193FCBe7ae9B0F3D90F88e365Cca64fC"
|
|
31
31
|
},
|
|
32
32
|
"routerStatic": "0x704478Dd72FD7F9B83d1F1e0fc18C14B54F034d0",
|
|
33
|
-
"pendleSwap": "
|
|
33
|
+
"pendleSwap": "0x313e7Ef7d52f5C10aC04ebaa4d33CDc68634c212",
|
|
34
34
|
"pyYtLpOracle": "0x9a9fa8338dd5e5b2188006f1cd2ef26d921650c2",
|
|
35
35
|
"yieldContractFactoryV3": "0xfa6B22FC4c3Ad88B68c16b3061a16b1714F6Bd57",
|
|
36
36
|
"marketFactoryV3": "0x4A2B38b9cBd83c86F261a4d64c243795D4d44aBC",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"vePendle": "0xd5C47D2383Fddc19596489280C0A33AC42b2bB18",
|
|
47
47
|
"gaugeController": "0x6875e4A945E498FE1B90BbB13CFbAF0b68658C9C",
|
|
48
48
|
"sparkLinearDiscountOracleFactory": "0xA9A924A4BB95509F77868E086154C25e934F6171",
|
|
49
|
+
"multiTokenDistributor": "0x3942F7B55094250644cFfDa7160226Caa349A38E",
|
|
49
50
|
"beta": {
|
|
50
51
|
"PendleChainlinkOracleFactory": "0x2A73e899389cABa2a2f648BaBA35e67f5C00EFee"
|
|
51
52
|
}
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"ActionStorageV4": "0x6a0Ed0A9193FCBe7ae9B0F3D90F88e365Cca64fC"
|
|
31
31
|
},
|
|
32
32
|
"routerStatic": "0xAdB09F65bd90d19e3148D9ccb693F3161C6DB3E8",
|
|
33
|
-
"pendleSwap": "
|
|
33
|
+
"pendleSwap": "0x313e7Ef7d52f5C10aC04ebaa4d33CDc68634c212",
|
|
34
34
|
"pyYtLpOracle": "0x9a9fa8338dd5e5b2188006f1cd2ef26d921650c2",
|
|
35
35
|
"yieldContractFactoryV3": "0xEb38531db128EcA928aea1B1CE9E5609B15ba146",
|
|
36
36
|
"marketFactoryV3": "0x2FCb47B58350cD377f94d3821e7373Df60bD9Ced",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"arbMerkleDistribution": "0x23a102e78D1FF1645a3666691495174764a5FCAF",
|
|
49
49
|
"linearDistributor": "0x83d85AEDD308261d847C3eb8d7146457bD8F38E8",
|
|
50
50
|
"sparkLinearDiscountOracleFactory": "0xA9A924A4BB95509F77868E086154C25e934F6171",
|
|
51
|
+
"multiTokenDistributor": "0x3942F7B55094250644cFfDa7160226Caa349A38E",
|
|
51
52
|
"beta": {
|
|
52
53
|
"PendleChainlinkOracleFactory": "0x2A73e899389cABa2a2f648BaBA35e67f5C00EFee"
|
|
53
54
|
}
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"ActionStorageV4": "0x6a0Ed0A9193FCBe7ae9B0F3D90F88e365Cca64fC"
|
|
29
29
|
},
|
|
30
30
|
"routerStatic": "0xCAd502Bb55d1A3F79952F969BFF3f011CF30a94a",
|
|
31
|
-
"pendleSwap": "
|
|
31
|
+
"pendleSwap": "0x313e7Ef7d52f5C10aC04ebaa4d33CDc68634c212",
|
|
32
32
|
"pyYtLpOracle": "0x9a9fa8338dd5e5b2188006f1cd2ef26d921650c2",
|
|
33
33
|
"yieldContractFactoryV3": "0x964840644B88C583500F473E4B829Ab629aF96A8",
|
|
34
34
|
"marketFactoryV3": "0xD228EC1f7D4313fe321fab511A872475D07F5bA6",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"vePendle": "0x30c6d4e892871220B5Ab66c10db577da96Fb974b",
|
|
45
45
|
"gaugeController": "0x428f2f93afAc3F96B0DE59854038c585e06165C8",
|
|
46
46
|
"sparkLinearDiscountOracleFactory": "0xA9A924A4BB95509F77868E086154C25e934F6171",
|
|
47
|
+
"multiTokenDistributor": "0x3942F7B55094250644cFfDa7160226Caa349A38E",
|
|
47
48
|
"beta": {
|
|
48
49
|
"PendleChainlinkOracleFactory": "0x2A73e899389cABa2a2f648BaBA35e67f5C00EFee"
|
|
49
50
|
}
|
package/deployments/56-core.json
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"ActionStorageV4": "0x6a0Ed0A9193FCBe7ae9B0F3D90F88e365Cca64fC"
|
|
31
31
|
},
|
|
32
32
|
"routerStatic": "0x2700ADB035F82a11899ce1D3f1BF8451c296eABb",
|
|
33
|
-
"pendleSwap": "
|
|
33
|
+
"pendleSwap": "0x313e7Ef7d52f5C10aC04ebaa4d33CDc68634c212",
|
|
34
34
|
"pyYtLpOracle": "0x9a9fa8338dd5e5b2188006f1cd2ef26d921650c2",
|
|
35
35
|
"yieldContractFactoryV3": "0x40Ae6da2d92aa3DCb7f8d7a7209FD12BDfcb7C85",
|
|
36
36
|
"marketFactoryV3": "0xC40fEbF5A33b8C92B187d9be0fD3fe0ac2E4B07c",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"vePendle": "0x8A09574b0401A856d89d1b583eE22E8cb0C5530B",
|
|
47
47
|
"gaugeController": "0x704478Dd72FD7F9B83d1F1e0fc18C14B54F034d0",
|
|
48
48
|
"sparkLinearDiscountOracleFactory": "0xA9A924A4BB95509F77868E086154C25e934F6171",
|
|
49
|
+
"multiTokenDistributor": "0x3942F7B55094250644cFfDa7160226Caa349A38E",
|
|
49
50
|
"beta": {
|
|
50
51
|
"PendleChainlinkOracleFactory": "0x2A73e899389cABa2a2f648BaBA35e67f5C00EFee"
|
|
51
52
|
}
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"ActionStorageV4": "0x6a0Ed0A9193FCBe7ae9B0F3D90F88e365Cca64fC"
|
|
31
31
|
},
|
|
32
32
|
"routerStatic": "0xB4205a645c7e920BD8504181B1D7f2c5C955C3e7",
|
|
33
|
-
"pendleSwap": "
|
|
33
|
+
"pendleSwap": "0x313e7Ef7d52f5C10aC04ebaa4d33CDc68634c212",
|
|
34
34
|
"pyYtLpOracle": "0x9a9fa8338dd5e5b2188006f1cd2ef26d921650c2",
|
|
35
35
|
"reflector": "0x5039Da22E5126e7c4e9284376116716A91782faF",
|
|
36
36
|
"receiverEndpoint": "0xeE708FC793a02F1eDd5BB9DBD7fD13010D1F7136",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"vePendle": "0x051dcd6a80f11fE68F77Fb0EBdE03853FA96B1fD",
|
|
40
40
|
"gaugeController": "0x17F100fB4bE2707675c6439468d38249DD993d58",
|
|
41
41
|
"sparkLinearDiscountOracleFactory": "0xA9A924A4BB95509F77868E086154C25e934F6171",
|
|
42
|
+
"multiTokenDistributor": "0x3942F7B55094250644cFfDa7160226Caa349A38E",
|
|
42
43
|
"beta": {
|
|
43
44
|
"PendleChainlinkOracleFactory": "0x2A73e899389cABa2a2f648BaBA35e67f5C00EFee"
|
|
44
45
|
}
|