@pendle/core-v2 2.15.1 → 2.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/contracts/offchain-helpers/MarketExchangeRateLib.sol +43 -0
- package/contracts/router/swap-aggregator/{PendleSwapEthereum.sol → PendleSwap.sol} +8 -12
- package/contracts/router/swap-aggregator/kyberswap/{arbitrum/IExecutorHelper1.sol → IExecutorHelper.sol} +65 -21
- package/contracts/router/swap-aggregator/kyberswap/{arbitrum/IMetaAggregationRouterV2.sol → IMetaAggregationRouterV2.sol} +4 -3
- package/contracts/router/swap-aggregator/kyberswap/KyberInputScalingHelper.sol +235 -0
- package/contracts/router/swap-aggregator/kyberswap/{arbitrum/ScaleDataHelperArbitrum.sol → ScalingDataLib.sol} +56 -25
- package/deployments/1-core.json +1 -1
- package/deployments/42161-core.json +1 -1
- package/package.json +1 -1
- package/contracts/router/swap-aggregator/1inch/I1inchAggregationRouterV5.sol +0 -39
- package/contracts/router/swap-aggregator/1inch/OneInchAggregationRouterHelper.sol +0 -68
- package/contracts/router/swap-aggregator/PendleSwapArbitrum.sol +0 -45
- package/contracts/router/swap-aggregator/kyberswap/arbitrum/IExecutorHelper2.sol +0 -10
- package/contracts/router/swap-aggregator/kyberswap/arbitrum/KyberHelperArbitrum.sol +0 -200
- package/contracts/router/swap-aggregator/kyberswap/ethereum/IAggregationExecutor.sol +0 -17
- package/contracts/router/swap-aggregator/kyberswap/ethereum/IExecutorHelperEthereum1.sol +0 -191
- package/contracts/router/swap-aggregator/kyberswap/ethereum/IHashflow.sol +0 -30
- package/contracts/router/swap-aggregator/kyberswap/ethereum/IMetaAggregationRouterV2.sol +0 -41
- package/contracts/router/swap-aggregator/kyberswap/ethereum/KyberHelperEthereum.sol +0 -201
- package/contracts/router/swap-aggregator/kyberswap/ethereum/ScaleDataHelperEthereum.sol +0 -147
- /package/contracts/router/swap-aggregator/kyberswap/{arbitrum/IAggregationExecutor.sol → IAggregationExecutor.sol} +0 -0
- /package/contracts/router/swap-aggregator/kyberswap/{arbitrum/IHashflow.sol → IHashflow.sol} +0 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity 0.8.17;
|
|
3
|
+
|
|
4
|
+
import "../core/Market/MarketMathCore.sol";
|
|
5
|
+
import "../interfaces/IPMarket.sol";
|
|
6
|
+
|
|
7
|
+
library MarketExchangeRateLib {
|
|
8
|
+
using Math for int256;
|
|
9
|
+
using MarketMathCore for MarketState;
|
|
10
|
+
using MarketMathCore for MarketPreCompute;
|
|
11
|
+
|
|
12
|
+
function getMarketExchangeRate(address market) internal view returns (uint256) {
|
|
13
|
+
MarketState memory state = IPMarket(market).readState(address(0));
|
|
14
|
+
MarketPreCompute memory comp = state.getMarketPreCompute(
|
|
15
|
+
_getPYIndexCurrent(market),
|
|
16
|
+
block.timestamp
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
return
|
|
20
|
+
MarketMathCore
|
|
21
|
+
._getExchangeRate(
|
|
22
|
+
state.totalPt,
|
|
23
|
+
comp.totalAsset,
|
|
24
|
+
comp.rateScalar,
|
|
25
|
+
comp.rateAnchor,
|
|
26
|
+
0
|
|
27
|
+
)
|
|
28
|
+
.Uint();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function _getPYIndexCurrent(address market) private view returns (PYIndex) {
|
|
32
|
+
(IStandardizedYield SY, , IPYieldToken YT) = IPMarket(market).readTokens();
|
|
33
|
+
uint256 ytIndex = YT.pyIndexStored();
|
|
34
|
+
uint256 pyIndexCurrent;
|
|
35
|
+
if (YT.doCacheIndexSameBlock() && YT.pyIndexLastUpdatedBlock() == block.number) {
|
|
36
|
+
pyIndexCurrent = ytIndex;
|
|
37
|
+
} else {
|
|
38
|
+
uint256 syIndex = SY.exchangeRate();
|
|
39
|
+
pyIndexCurrent = Math.max(syIndex, ytIndex);
|
|
40
|
+
}
|
|
41
|
+
return PYIndex.wrap(pyIndexCurrent);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
2
|
pragma solidity 0.8.17;
|
|
3
3
|
|
|
4
|
-
import "@openzeppelin/contracts/utils/Address.sol";
|
|
5
4
|
import "../../core/libraries/TokenHelper.sol";
|
|
6
|
-
import "../../core/libraries/Errors.sol";
|
|
7
5
|
import "./IPSwapAggregator.sol";
|
|
8
|
-
import "./
|
|
9
|
-
import "./kyberswap/ethereum/KyberHelperEthereum.sol";
|
|
6
|
+
import "./kyberswap/KyberInputScalingHelper.sol";
|
|
10
7
|
|
|
11
|
-
contract
|
|
12
|
-
IPSwapAggregator,
|
|
13
|
-
TokenHelper,
|
|
14
|
-
KyberHelperEthereum,
|
|
15
|
-
OneInchAggregationRouterHelper
|
|
16
|
-
{
|
|
8
|
+
contract PendleSwap is IPSwapAggregator, TokenHelper, KyberInputScalingHelper {
|
|
17
9
|
using Address for address;
|
|
18
10
|
|
|
19
|
-
function swap(
|
|
11
|
+
function swap(
|
|
12
|
+
address tokenIn,
|
|
13
|
+
uint256 amountIn,
|
|
14
|
+
SwapData calldata data
|
|
15
|
+
) external payable {
|
|
20
16
|
_safeApproveInf(tokenIn, data.extRouter);
|
|
21
17
|
data.extRouter.functionCallWithValue(
|
|
22
18
|
data.needScale
|
|
@@ -34,7 +30,7 @@ contract PendleSwapEthereum is
|
|
|
34
30
|
if (swapType == SwapType.KYBERSWAP) {
|
|
35
31
|
scaledCallData = _getKyberScaledInputData(rawCallData, amountIn);
|
|
36
32
|
} else if (swapType == SwapType.ONE_INCH) {
|
|
37
|
-
|
|
33
|
+
revert("not supported");
|
|
38
34
|
} else {
|
|
39
35
|
assert(false);
|
|
40
36
|
}
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity 0.8.17;
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
interface IExecutorHelper {
|
|
5
|
+
struct Swap {
|
|
6
|
+
bytes data;
|
|
7
|
+
bytes4 functionSelector;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
struct SwapExecutorDescription {
|
|
11
|
+
Swap[][] swapSequences;
|
|
12
|
+
address tokenIn;
|
|
13
|
+
address tokenOut;
|
|
14
|
+
uint256 minTotalAmountOut;
|
|
15
|
+
address to;
|
|
16
|
+
uint256 deadline;
|
|
17
|
+
bytes destTokenFeeData;
|
|
18
|
+
}
|
|
5
19
|
|
|
6
|
-
interface IExecutorHelper1 {
|
|
7
20
|
struct UniSwap {
|
|
8
21
|
address pool;
|
|
9
22
|
address tokenIn;
|
|
@@ -51,15 +64,6 @@ interface IExecutorHelper1 {
|
|
|
51
64
|
uint160 sqrtPriceLimitX96;
|
|
52
65
|
bool isUniV3; // true = UniV3, false = ProMM
|
|
53
66
|
}
|
|
54
|
-
struct SwapCallbackData {
|
|
55
|
-
bytes path;
|
|
56
|
-
address payer;
|
|
57
|
-
}
|
|
58
|
-
struct SwapCallbackDataPath {
|
|
59
|
-
address pool;
|
|
60
|
-
address tokenIn;
|
|
61
|
-
address tokenOut;
|
|
62
|
-
}
|
|
63
67
|
|
|
64
68
|
struct BalancerV2 {
|
|
65
69
|
address vault;
|
|
@@ -70,14 +74,6 @@ interface IExecutorHelper1 {
|
|
|
70
74
|
uint256 limit;
|
|
71
75
|
}
|
|
72
76
|
|
|
73
|
-
struct KyberRFQ {
|
|
74
|
-
address rfq;
|
|
75
|
-
bytes order;
|
|
76
|
-
bytes signature;
|
|
77
|
-
uint256 amount;
|
|
78
|
-
address payable target;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
77
|
struct DODO {
|
|
82
78
|
address recipient;
|
|
83
79
|
address pool;
|
|
@@ -110,9 +106,27 @@ interface IExecutorHelper1 {
|
|
|
110
106
|
bool useAtomicExchange;
|
|
111
107
|
}
|
|
112
108
|
|
|
113
|
-
struct
|
|
109
|
+
struct Platypus {
|
|
110
|
+
address pool;
|
|
111
|
+
address tokenIn;
|
|
112
|
+
address tokenOut;
|
|
113
|
+
address recipient;
|
|
114
|
+
uint256 collectAmount; // amount that should be transferred to the pool
|
|
115
|
+
uint256 limitReturnAmount;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
struct PSM {
|
|
114
119
|
address router;
|
|
115
|
-
|
|
120
|
+
address tokenIn;
|
|
121
|
+
address tokenOut;
|
|
122
|
+
uint256 amountIn;
|
|
123
|
+
address recipient;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
struct WSTETH {
|
|
127
|
+
address pool;
|
|
128
|
+
uint256 amount;
|
|
129
|
+
bool isWrapping;
|
|
116
130
|
}
|
|
117
131
|
|
|
118
132
|
function executeUniSwap(
|
|
@@ -175,6 +189,18 @@ interface IExecutorHelper1 {
|
|
|
175
189
|
uint256 previousAmountOut
|
|
176
190
|
) external payable returns (uint256);
|
|
177
191
|
|
|
192
|
+
function executePlatypusSwap(
|
|
193
|
+
uint256 index,
|
|
194
|
+
bytes memory data,
|
|
195
|
+
uint256 previousAmountOut
|
|
196
|
+
) external payable returns (uint256);
|
|
197
|
+
|
|
198
|
+
function executeWrappedstETHSwap(
|
|
199
|
+
uint256 index,
|
|
200
|
+
bytes memory data,
|
|
201
|
+
uint256 previousAmountOut
|
|
202
|
+
) external payable returns (uint256);
|
|
203
|
+
|
|
178
204
|
function executeSynthetixSwap(
|
|
179
205
|
uint256 index,
|
|
180
206
|
bytes memory data,
|
|
@@ -187,9 +213,27 @@ interface IExecutorHelper1 {
|
|
|
187
213
|
uint256 previousAmountOut
|
|
188
214
|
) external payable returns (uint256);
|
|
189
215
|
|
|
216
|
+
function executePSMSwap(
|
|
217
|
+
uint256 index,
|
|
218
|
+
bytes memory data,
|
|
219
|
+
uint256 previousAmountOut
|
|
220
|
+
) external payable returns (uint256);
|
|
221
|
+
|
|
222
|
+
function executeFraxSwap(
|
|
223
|
+
uint256 index,
|
|
224
|
+
bytes memory data,
|
|
225
|
+
uint256 previousAmountOut
|
|
226
|
+
) external payable returns (uint256);
|
|
227
|
+
|
|
190
228
|
function executeCamelotSwap(
|
|
191
229
|
uint256 index,
|
|
192
230
|
bytes memory data,
|
|
193
231
|
uint256 previousAmountOut
|
|
194
232
|
) external payable returns (uint256);
|
|
233
|
+
|
|
234
|
+
function executeKyberLimitOrder(
|
|
235
|
+
uint256 index,
|
|
236
|
+
bytes memory data,
|
|
237
|
+
uint256 previousAmountOut
|
|
238
|
+
) external payable returns (uint256);
|
|
195
239
|
}
|
|
@@ -28,9 +28,10 @@ interface IMetaAggregationRouterV2 {
|
|
|
28
28
|
bytes clientData;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
function swap(
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
function swap(SwapExecutionParams calldata execution)
|
|
32
|
+
external
|
|
33
|
+
payable
|
|
34
|
+
returns (uint256, uint256);
|
|
34
35
|
|
|
35
36
|
function swapSimpleMode(
|
|
36
37
|
IAggregationExecutor caller,
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity 0.8.17;
|
|
4
|
+
import "./IMetaAggregationRouterV2.sol";
|
|
5
|
+
import "./IHashflow.sol";
|
|
6
|
+
import "./IExecutorHelper.sol";
|
|
7
|
+
import "./ScalingDataLib.sol";
|
|
8
|
+
|
|
9
|
+
abstract contract KyberInputScalingHelper {
|
|
10
|
+
uint256 private constant _PARTIAL_FILL = 0x01;
|
|
11
|
+
uint256 private constant _REQUIRES_EXTRA_ETH = 0x02;
|
|
12
|
+
uint256 private constant _SHOULD_CLAIM = 0x04;
|
|
13
|
+
uint256 private constant _BURN_FROM_MSG_SENDER = 0x08;
|
|
14
|
+
uint256 private constant _BURN_FROM_TX_ORIGIN = 0x10;
|
|
15
|
+
uint256 private constant _SIMPLE_SWAP = 0x20;
|
|
16
|
+
|
|
17
|
+
// fee data in case taking in dest token
|
|
18
|
+
struct PositiveSlippageFeeData {
|
|
19
|
+
uint256 partnerPSInfor; // [partnerReceiver (160 bit) + partnerPercent(96bits)]
|
|
20
|
+
uint256 expectedReturnAmount;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
struct Swap {
|
|
24
|
+
bytes data;
|
|
25
|
+
bytes4 functionSelector;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
struct SimpleSwapData {
|
|
29
|
+
address[] firstPools;
|
|
30
|
+
uint256[] firstSwapAmounts;
|
|
31
|
+
bytes[] swapDatas;
|
|
32
|
+
uint256 deadline;
|
|
33
|
+
bytes positiveSlippageData;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
struct SwapExecutorDescription {
|
|
37
|
+
Swap[][] swapSequences;
|
|
38
|
+
address tokenIn;
|
|
39
|
+
address tokenOut;
|
|
40
|
+
uint256 minTotalAmountOut;
|
|
41
|
+
address to;
|
|
42
|
+
uint256 deadline;
|
|
43
|
+
bytes positiveSlippageData;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function _getKyberScaledInputData(bytes calldata inputData, uint256 newAmount)
|
|
47
|
+
internal
|
|
48
|
+
pure
|
|
49
|
+
returns (bytes memory)
|
|
50
|
+
{
|
|
51
|
+
bytes4 selector = bytes4(inputData[:4]);
|
|
52
|
+
bytes calldata dataToDecode = inputData[4:];
|
|
53
|
+
|
|
54
|
+
if (selector == IMetaAggregationRouterV2.swap.selector) {
|
|
55
|
+
IMetaAggregationRouterV2.SwapExecutionParams memory params = abi.decode(
|
|
56
|
+
dataToDecode,
|
|
57
|
+
(IMetaAggregationRouterV2.SwapExecutionParams)
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
(params.desc, params.targetData) = _getScaledInputDataV2(
|
|
61
|
+
params.desc,
|
|
62
|
+
params.targetData,
|
|
63
|
+
newAmount,
|
|
64
|
+
_flagsChecked(params.desc.flags, _SIMPLE_SWAP)
|
|
65
|
+
);
|
|
66
|
+
return abi.encodeWithSelector(selector, params);
|
|
67
|
+
} else if (selector == IMetaAggregationRouterV2.swapSimpleMode.selector) {
|
|
68
|
+
(
|
|
69
|
+
address callTarget,
|
|
70
|
+
IMetaAggregationRouterV2.SwapDescriptionV2 memory desc,
|
|
71
|
+
bytes memory targetData,
|
|
72
|
+
bytes memory clientData
|
|
73
|
+
) = abi.decode(
|
|
74
|
+
dataToDecode,
|
|
75
|
+
(address, IMetaAggregationRouterV2.SwapDescriptionV2, bytes, bytes)
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
(desc, targetData) = _getScaledInputDataV2(desc, targetData, newAmount, true);
|
|
79
|
+
return abi.encodeWithSelector(selector, callTarget, desc, targetData, clientData);
|
|
80
|
+
} else revert("InputScalingHelper: Invalid selector");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function _getScaledInputDataV2(
|
|
84
|
+
IMetaAggregationRouterV2.SwapDescriptionV2 memory desc,
|
|
85
|
+
bytes memory executorData,
|
|
86
|
+
uint256 newAmount,
|
|
87
|
+
bool isSimpleMode
|
|
88
|
+
) internal pure returns (IMetaAggregationRouterV2.SwapDescriptionV2 memory, bytes memory) {
|
|
89
|
+
uint256 oldAmount = desc.amount;
|
|
90
|
+
if (oldAmount == newAmount) {
|
|
91
|
+
return (desc, executorData);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// simple mode swap
|
|
95
|
+
if (isSimpleMode) {
|
|
96
|
+
return (
|
|
97
|
+
_scaledSwapDescriptionV2(desc, oldAmount, newAmount),
|
|
98
|
+
_scaledSimpleSwapData(executorData, oldAmount, newAmount)
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//normal mode swap
|
|
103
|
+
return (
|
|
104
|
+
_scaledSwapDescriptionV2(desc, oldAmount, newAmount),
|
|
105
|
+
_scaledExecutorCallBytesData(executorData, oldAmount, newAmount)
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/// @dev Scale the swap description
|
|
110
|
+
function _scaledSwapDescriptionV2(
|
|
111
|
+
IMetaAggregationRouterV2.SwapDescriptionV2 memory desc,
|
|
112
|
+
uint256 oldAmount,
|
|
113
|
+
uint256 newAmount
|
|
114
|
+
) internal pure returns (IMetaAggregationRouterV2.SwapDescriptionV2 memory) {
|
|
115
|
+
desc.minReturnAmount = (desc.minReturnAmount * newAmount) / oldAmount;
|
|
116
|
+
if (desc.minReturnAmount == 0) desc.minReturnAmount = 1;
|
|
117
|
+
desc.amount = newAmount;
|
|
118
|
+
|
|
119
|
+
uint256 nReceivers = desc.srcReceivers.length;
|
|
120
|
+
for (uint256 i = 0; i < nReceivers; ) {
|
|
121
|
+
desc.srcAmounts[i] = (desc.srcAmounts[i] * newAmount) / oldAmount;
|
|
122
|
+
unchecked {
|
|
123
|
+
++i;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return desc;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/// @dev Scale the executorData in case swapSimpleMode
|
|
130
|
+
function _scaledSimpleSwapData(
|
|
131
|
+
bytes memory data,
|
|
132
|
+
uint256 oldAmount,
|
|
133
|
+
uint256 newAmount
|
|
134
|
+
) internal pure returns (bytes memory) {
|
|
135
|
+
SimpleSwapData memory swapData = abi.decode(data, (SimpleSwapData));
|
|
136
|
+
|
|
137
|
+
uint256 nPools = swapData.firstPools.length;
|
|
138
|
+
for (uint256 i = 0; i < nPools; ) {
|
|
139
|
+
swapData.firstSwapAmounts[i] = (swapData.firstSwapAmounts[i] * newAmount) / oldAmount;
|
|
140
|
+
unchecked {
|
|
141
|
+
++i;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
swapData.positiveSlippageData = _scaledPositiveSlippageFeeData(
|
|
145
|
+
swapData.positiveSlippageData,
|
|
146
|
+
oldAmount,
|
|
147
|
+
newAmount
|
|
148
|
+
);
|
|
149
|
+
return abi.encode(swapData);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/// @dev Scale the executorData in case normal swap
|
|
153
|
+
function _scaledExecutorCallBytesData(
|
|
154
|
+
bytes memory data,
|
|
155
|
+
uint256 oldAmount,
|
|
156
|
+
uint256 newAmount
|
|
157
|
+
) internal pure returns (bytes memory) {
|
|
158
|
+
SwapExecutorDescription memory executorDesc = abi.decode(data, (SwapExecutorDescription));
|
|
159
|
+
executorDesc.minTotalAmountOut = (executorDesc.minTotalAmountOut * newAmount) / oldAmount;
|
|
160
|
+
executorDesc.positiveSlippageData = _scaledPositiveSlippageFeeData(
|
|
161
|
+
executorDesc.positiveSlippageData,
|
|
162
|
+
oldAmount,
|
|
163
|
+
newAmount
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
uint256 nSequences = executorDesc.swapSequences.length;
|
|
167
|
+
for (uint256 i = 0; i < nSequences; ) {
|
|
168
|
+
Swap memory swap = executorDesc.swapSequences[i][0];
|
|
169
|
+
bytes4 functionSelector = swap.functionSelector;
|
|
170
|
+
|
|
171
|
+
if (functionSelector == IExecutorHelper.executeUniSwap.selector) {
|
|
172
|
+
swap.data = ScalingDataLib.newUniSwap(swap.data, oldAmount, newAmount);
|
|
173
|
+
} else if (functionSelector == IExecutorHelper.executeStableSwap.selector) {
|
|
174
|
+
swap.data = ScalingDataLib.newStableSwap(swap.data, oldAmount, newAmount);
|
|
175
|
+
} else if (functionSelector == IExecutorHelper.executeCurveSwap.selector) {
|
|
176
|
+
swap.data = ScalingDataLib.newCurveSwap(swap.data, oldAmount, newAmount);
|
|
177
|
+
} else if (functionSelector == IExecutorHelper.executeKyberDMMSwap.selector) {
|
|
178
|
+
swap.data = ScalingDataLib.newKyberDMM(swap.data, oldAmount, newAmount);
|
|
179
|
+
} else if (functionSelector == IExecutorHelper.executeUniV3ProMMSwap.selector) {
|
|
180
|
+
swap.data = ScalingDataLib.newUniV3ProMM(swap.data, oldAmount, newAmount);
|
|
181
|
+
} else if (functionSelector == IExecutorHelper.executeRfqSwap.selector) {
|
|
182
|
+
revert("InputScalingHelper: Can not scale RFQ swap");
|
|
183
|
+
} else if (functionSelector == IExecutorHelper.executeBalV2Swap.selector) {
|
|
184
|
+
swap.data = ScalingDataLib.newBalancerV2(swap.data, oldAmount, newAmount);
|
|
185
|
+
} else if (functionSelector == IExecutorHelper.executeWrappedstETHSwap.selector) {
|
|
186
|
+
swap.data = ScalingDataLib.newWrappedstETHSwap(swap.data, oldAmount, newAmount);
|
|
187
|
+
} else if (functionSelector == IExecutorHelper.executeDODOSwap.selector) {
|
|
188
|
+
swap.data = ScalingDataLib.newDODO(swap.data, oldAmount, newAmount);
|
|
189
|
+
} else if (functionSelector == IExecutorHelper.executeVelodromeSwap.selector) {
|
|
190
|
+
swap.data = ScalingDataLib.newVelodrome(swap.data, oldAmount, newAmount);
|
|
191
|
+
} else if (functionSelector == IExecutorHelper.executeGMXSwap.selector) {
|
|
192
|
+
swap.data = ScalingDataLib.newGMX(swap.data, oldAmount, newAmount);
|
|
193
|
+
} else if (functionSelector == IExecutorHelper.executeSynthetixSwap.selector) {
|
|
194
|
+
swap.data = ScalingDataLib.newSynthetix(swap.data, oldAmount, newAmount);
|
|
195
|
+
} else if (functionSelector == IExecutorHelper.executeHashflowSwap.selector) {
|
|
196
|
+
revert("InputScalingHelper: Can not scale RFQ swap");
|
|
197
|
+
} else if (functionSelector == IExecutorHelper.executeCamelotSwap.selector) {
|
|
198
|
+
swap.data = ScalingDataLib.newCamelot(swap.data, oldAmount, newAmount);
|
|
199
|
+
} else if (functionSelector == IExecutorHelper.executeKyberLimitOrder.selector) {
|
|
200
|
+
revert("InputScalingHelper: Can not scale RFQ swap");
|
|
201
|
+
} else if (functionSelector == IExecutorHelper.executePSMSwap.selector) {
|
|
202
|
+
swap.data = ScalingDataLib.newPSM(swap.data, oldAmount, newAmount);
|
|
203
|
+
} else if (functionSelector == IExecutorHelper.executeFraxSwap.selector) {
|
|
204
|
+
swap.data = ScalingDataLib.newFrax(swap.data, oldAmount, newAmount);
|
|
205
|
+
} else if (functionSelector == IExecutorHelper.executePlatypusSwap.selector) {
|
|
206
|
+
swap.data = ScalingDataLib.newPlatypus(swap.data, oldAmount, newAmount);
|
|
207
|
+
} else revert("AggregationExecutor: Dex type not supported");
|
|
208
|
+
unchecked {
|
|
209
|
+
++i;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return abi.encode(executorDesc);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function _scaledPositiveSlippageFeeData(
|
|
216
|
+
bytes memory data,
|
|
217
|
+
uint256 oldAmount,
|
|
218
|
+
uint256 newAmount
|
|
219
|
+
) internal pure returns (bytes memory newData) {
|
|
220
|
+
if (data.length > 32) {
|
|
221
|
+
PositiveSlippageFeeData memory psData = abi.decode(data, (PositiveSlippageFeeData));
|
|
222
|
+
psData.expectedReturnAmount = (psData.expectedReturnAmount * newAmount) / oldAmount;
|
|
223
|
+
data = abi.encode(psData);
|
|
224
|
+
} else if (data.length == 32) {
|
|
225
|
+
uint256 expectedReturnAmount = abi.decode(data, (uint256));
|
|
226
|
+
expectedReturnAmount = (expectedReturnAmount * newAmount) / oldAmount;
|
|
227
|
+
data = abi.encode(expectedReturnAmount);
|
|
228
|
+
}
|
|
229
|
+
return data;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function _flagsChecked(uint256 number, uint256 flag) internal pure returns (bool) {
|
|
233
|
+
return number & flag != 0;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity 0.8.17;
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import "./IExecutorHelper.sol";
|
|
5
5
|
|
|
6
|
-
library
|
|
6
|
+
library ScalingDataLib {
|
|
7
7
|
function newUniSwap(
|
|
8
8
|
bytes memory data,
|
|
9
9
|
uint256 oldAmount,
|
|
10
10
|
uint256 newAmount
|
|
11
11
|
) internal pure returns (bytes memory) {
|
|
12
|
-
|
|
12
|
+
IExecutorHelper.UniSwap memory uniSwap = abi.decode(data, (IExecutorHelper.UniSwap));
|
|
13
13
|
uniSwap.collectAmount = (uniSwap.collectAmount * newAmount) / oldAmount;
|
|
14
14
|
return abi.encode(uniSwap);
|
|
15
15
|
}
|
|
@@ -19,9 +19,9 @@ library ScaleDataHelperArbitrum {
|
|
|
19
19
|
uint256 oldAmount,
|
|
20
20
|
uint256 newAmount
|
|
21
21
|
) internal pure returns (bytes memory) {
|
|
22
|
-
|
|
22
|
+
IExecutorHelper.StableSwap memory stableSwap = abi.decode(
|
|
23
23
|
data,
|
|
24
|
-
(
|
|
24
|
+
(IExecutorHelper.StableSwap)
|
|
25
25
|
);
|
|
26
26
|
stableSwap.dx = (stableSwap.dx * newAmount) / oldAmount;
|
|
27
27
|
return abi.encode(stableSwap);
|
|
@@ -32,10 +32,7 @@ library ScaleDataHelperArbitrum {
|
|
|
32
32
|
uint256 oldAmount,
|
|
33
33
|
uint256 newAmount
|
|
34
34
|
) internal pure returns (bytes memory) {
|
|
35
|
-
|
|
36
|
-
data,
|
|
37
|
-
(IExecutorHelper1.CurveSwap)
|
|
38
|
-
);
|
|
35
|
+
IExecutorHelper.CurveSwap memory curveSwap = abi.decode(data, (IExecutorHelper.CurveSwap));
|
|
39
36
|
curveSwap.dx = (curveSwap.dx * newAmount) / oldAmount;
|
|
40
37
|
return abi.encode(curveSwap);
|
|
41
38
|
}
|
|
@@ -45,10 +42,7 @@ library ScaleDataHelperArbitrum {
|
|
|
45
42
|
uint256 oldAmount,
|
|
46
43
|
uint256 newAmount
|
|
47
44
|
) internal pure returns (bytes memory) {
|
|
48
|
-
|
|
49
|
-
data,
|
|
50
|
-
(IExecutorHelper1.UniSwap)
|
|
51
|
-
);
|
|
45
|
+
IExecutorHelper.UniSwap memory kyberDMMSwap = abi.decode(data, (IExecutorHelper.UniSwap));
|
|
52
46
|
kyberDMMSwap.collectAmount = (kyberDMMSwap.collectAmount * newAmount) / oldAmount;
|
|
53
47
|
return abi.encode(kyberDMMSwap);
|
|
54
48
|
}
|
|
@@ -58,9 +52,9 @@ library ScaleDataHelperArbitrum {
|
|
|
58
52
|
uint256 oldAmount,
|
|
59
53
|
uint256 newAmount
|
|
60
54
|
) internal pure returns (bytes memory) {
|
|
61
|
-
|
|
55
|
+
IExecutorHelper.UniSwapV3ProMM memory uniSwapV3ProMM = abi.decode(
|
|
62
56
|
data,
|
|
63
|
-
(
|
|
57
|
+
(IExecutorHelper.UniSwapV3ProMM)
|
|
64
58
|
);
|
|
65
59
|
uniSwapV3ProMM.swapAmount = (uniSwapV3ProMM.swapAmount * newAmount) / oldAmount;
|
|
66
60
|
|
|
@@ -72,9 +66,9 @@ library ScaleDataHelperArbitrum {
|
|
|
72
66
|
uint256 oldAmount,
|
|
73
67
|
uint256 newAmount
|
|
74
68
|
) internal pure returns (bytes memory) {
|
|
75
|
-
|
|
69
|
+
IExecutorHelper.BalancerV2 memory balancerV2 = abi.decode(
|
|
76
70
|
data,
|
|
77
|
-
(
|
|
71
|
+
(IExecutorHelper.BalancerV2)
|
|
78
72
|
);
|
|
79
73
|
balancerV2.amount = (balancerV2.amount * newAmount) / oldAmount;
|
|
80
74
|
return abi.encode(balancerV2);
|
|
@@ -85,7 +79,7 @@ library ScaleDataHelperArbitrum {
|
|
|
85
79
|
uint256 oldAmount,
|
|
86
80
|
uint256 newAmount
|
|
87
81
|
) internal pure returns (bytes memory) {
|
|
88
|
-
|
|
82
|
+
IExecutorHelper.DODO memory dodo = abi.decode(data, (IExecutorHelper.DODO));
|
|
89
83
|
dodo.amount = (dodo.amount * newAmount) / oldAmount;
|
|
90
84
|
return abi.encode(dodo);
|
|
91
85
|
}
|
|
@@ -95,7 +89,7 @@ library ScaleDataHelperArbitrum {
|
|
|
95
89
|
uint256 oldAmount,
|
|
96
90
|
uint256 newAmount
|
|
97
91
|
) internal pure returns (bytes memory) {
|
|
98
|
-
|
|
92
|
+
IExecutorHelper.UniSwap memory velodrome = abi.decode(data, (IExecutorHelper.UniSwap));
|
|
99
93
|
velodrome.collectAmount = (velodrome.collectAmount * newAmount) / oldAmount;
|
|
100
94
|
return abi.encode(velodrome);
|
|
101
95
|
}
|
|
@@ -105,7 +99,7 @@ library ScaleDataHelperArbitrum {
|
|
|
105
99
|
uint256 oldAmount,
|
|
106
100
|
uint256 newAmount
|
|
107
101
|
) internal pure returns (bytes memory) {
|
|
108
|
-
|
|
102
|
+
IExecutorHelper.GMX memory gmx = abi.decode(data, (IExecutorHelper.GMX));
|
|
109
103
|
gmx.amount = (gmx.amount * newAmount) / oldAmount;
|
|
110
104
|
return abi.encode(gmx);
|
|
111
105
|
}
|
|
@@ -115,10 +109,7 @@ library ScaleDataHelperArbitrum {
|
|
|
115
109
|
uint256 oldAmount,
|
|
116
110
|
uint256 newAmount
|
|
117
111
|
) internal pure returns (bytes memory) {
|
|
118
|
-
|
|
119
|
-
data,
|
|
120
|
-
(IExecutorHelper1.Synthetix)
|
|
121
|
-
);
|
|
112
|
+
IExecutorHelper.Synthetix memory synthetix = abi.decode(data, (IExecutorHelper.Synthetix));
|
|
122
113
|
synthetix.sourceAmount = (synthetix.sourceAmount * newAmount) / oldAmount;
|
|
123
114
|
return abi.encode(synthetix);
|
|
124
115
|
}
|
|
@@ -128,8 +119,48 @@ library ScaleDataHelperArbitrum {
|
|
|
128
119
|
uint256 oldAmount,
|
|
129
120
|
uint256 newAmount
|
|
130
121
|
) internal pure returns (bytes memory) {
|
|
131
|
-
|
|
122
|
+
IExecutorHelper.UniSwap memory camelot = abi.decode(data, (IExecutorHelper.UniSwap));
|
|
132
123
|
camelot.collectAmount = (camelot.collectAmount * newAmount) / oldAmount;
|
|
133
124
|
return abi.encode(camelot);
|
|
134
125
|
}
|
|
126
|
+
|
|
127
|
+
function newPlatypus(
|
|
128
|
+
bytes memory data,
|
|
129
|
+
uint256 oldAmount,
|
|
130
|
+
uint256 newAmount
|
|
131
|
+
) internal pure returns (bytes memory) {
|
|
132
|
+
IExecutorHelper.Platypus memory platypus = abi.decode(data, (IExecutorHelper.Platypus));
|
|
133
|
+
platypus.collectAmount = (platypus.collectAmount * newAmount) / oldAmount;
|
|
134
|
+
return abi.encode(platypus);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function newWrappedstETHSwap(
|
|
138
|
+
bytes memory data,
|
|
139
|
+
uint256 oldAmount,
|
|
140
|
+
uint256 newAmount
|
|
141
|
+
) internal pure returns (bytes memory) {
|
|
142
|
+
IExecutorHelper.WSTETH memory wstEthData = abi.decode(data, (IExecutorHelper.WSTETH));
|
|
143
|
+
wstEthData.amount = (wstEthData.amount * newAmount) / oldAmount;
|
|
144
|
+
return abi.encode(wstEthData);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function newPSM(
|
|
148
|
+
bytes memory data,
|
|
149
|
+
uint256 oldAmount,
|
|
150
|
+
uint256 newAmount
|
|
151
|
+
) internal pure returns (bytes memory) {
|
|
152
|
+
IExecutorHelper.PSM memory psm = abi.decode(data, (IExecutorHelper.PSM));
|
|
153
|
+
psm.amountIn = (psm.amountIn * newAmount) / oldAmount;
|
|
154
|
+
return abi.encode(psm);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function newFrax(
|
|
158
|
+
bytes memory data,
|
|
159
|
+
uint256 oldAmount,
|
|
160
|
+
uint256 newAmount
|
|
161
|
+
) internal pure returns (bytes memory) {
|
|
162
|
+
IExecutorHelper.UniSwap memory frax = abi.decode(data, (IExecutorHelper.UniSwap));
|
|
163
|
+
frax.collectAmount = (frax.collectAmount * newAmount) / oldAmount;
|
|
164
|
+
return abi.encode(frax);
|
|
165
|
+
}
|
|
135
166
|
}
|
package/deployments/1-core.json
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"bulkSellerOffchain": "0x9ACc60F915dFcd190D270fc92567aE71776bd320",
|
|
23
23
|
"router": "0x0000000001e4ef00d069e71d6ba041b0a16f7ea0",
|
|
24
24
|
"routerStatic": "0x263833d47eA3fA4a30f269323aba6a107f9eB14C",
|
|
25
|
-
"pendleSwap": "
|
|
25
|
+
"pendleSwap": "0x5719AcDB9ABBBC6Ba414C9DBFf5B2967342f465d",
|
|
26
26
|
"routerHelper": "0x462206b11d185ef6F64B41D344325401C37EC335",
|
|
27
27
|
"ptOracle": "0x414d3C8A26157085f286abE3BC6E1bb010733602",
|
|
28
28
|
"vePendle": "0x4f30A9D41B80ecC5B94306AB4364951AE3170210",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"marketFactory": "0xf5a7De2D276dbda3EEf1b62A9E718EFf4d29dDC8",
|
|
20
20
|
"router": "0x0000000001e4ef00d069e71d6ba041b0a16f7ea0",
|
|
21
21
|
"routerStatic": "0xAdB09F65bd90d19e3148D9ccb693F3161C6DB3E8",
|
|
22
|
-
"pendleSwap": "
|
|
22
|
+
"pendleSwap": "0x150DD76FAd24C0715dB375d06f1C2C1d917D7d93",
|
|
23
23
|
"routerHelper": "0x462206b11d185ef6F64B41D344325401C37EC335",
|
|
24
24
|
"ptOracle": "0x428f2f93afAc3F96B0DE59854038c585e06165C8",
|
|
25
25
|
"receiverEndpoint": "0xC9215ae9EC67385F38C755D862C8eE3702B5793A",
|