@pendle/core-v2 2.3.0-mainnet → 2.3.2-mainnet
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/router/ActionAddRemoveLiq.sol/ActionAddRemoveLiq.dbg.json +1 -1
- package/build/artifacts/contracts/router/ActionAddRemoveLiq.sol/ActionAddRemoveLiq.json +2 -2
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwapArbitrum.sol/PendleSwapArbitrum.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwapArbitrum.sol/PendleSwapArbitrum.json +76 -0
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwapEthereum.sol/PendleSwapEthereum.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwapEthereum.sol/PendleSwapEthereum.json +76 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/arbitrum/IAggregationExecutor.sol/IAggregationExecutor.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/{interfaces → arbitrum}/IAggregationExecutor.sol/IAggregationExecutor.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/arbitrum/IExecutorHelper1.sol/IExecutorHelper1.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/arbitrum/IExecutorHelper1.sol/IExecutorHelper1.json +388 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/arbitrum/IExecutorHelper2.sol/IExecutorHelper2.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/arbitrum/IExecutorHelper2.sol/IExecutorHelper2.json +40 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/arbitrum/IHashflow.sol/IHashflow.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/{interfaces → arbitrum}/IHashflow.sol/IHashflow.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/arbitrum/IMetaAggregationRouterV2.sol/IMetaAggregationRouterV2.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/{interfaces → arbitrum}/IMetaAggregationRouterV2.sol/IMetaAggregationRouterV2.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/arbitrum/KyberHelperArbitrum.sol/KyberHelperArbitrum.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/{KyberAggregationRouterHelper.sol/KyberAggregationRouterHelper.json → arbitrum/KyberHelperArbitrum.sol/KyberHelperArbitrum.json} +2 -2
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/arbitrum/ScaleDataHelperArbitrum.sol/ScaleDataHelperArbitrum.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/arbitrum/ScaleDataHelperArbitrum.sol/ScaleDataHelperArbitrum.json +10 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/ethereum/IAggregationExecutor.sol/IAggregationExecutor.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/ethereum/IAggregationExecutor.sol/IAggregationExecutor.json +65 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/ethereum/IExecutorHelperEthereum1.sol/IExecutorHelperEthereum1.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/{interfaces → ethereum}/IExecutorHelperEthereum1.sol/IExecutorHelperEthereum1.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/ethereum/IHashflow.sol/IHashflow.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/ethereum/IHashflow.sol/IHashflow.json +101 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/ethereum/IMetaAggregationRouterV2.sol/IMetaAggregationRouterV2.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/ethereum/IMetaAggregationRouterV2.sol/IMetaAggregationRouterV2.json +215 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/ethereum/KyberHelperEthereum.sol/KyberHelperEthereum.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/ethereum/KyberHelperEthereum.sol/KyberHelperEthereum.json +10 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/ethereum/ScaleDataHelperEthereum.sol/ScaleDataHelperEthereum.dbg.json +4 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/ethereum/ScaleDataHelperEthereum.sol/ScaleDataHelperEthereum.json +10 -0
- package/contracts/router/ActionAddRemoveLiq.sol +0 -1
- package/contracts/router/swap-aggregator/PendleSwapArbitrum.sol +45 -0
- package/contracts/router/swap-aggregator/{PendleSwapAggregator.sol → PendleSwapEthereum.sol} +5 -3
- package/contracts/router/swap-aggregator/kyberswap/arbitrum/IExecutorHelper1.sol +195 -0
- package/contracts/router/swap-aggregator/kyberswap/arbitrum/IExecutorHelper2.sol +10 -0
- package/contracts/router/swap-aggregator/kyberswap/arbitrum/IMetaAggregationRouterV2.sol +41 -0
- package/contracts/router/swap-aggregator/kyberswap/arbitrum/KyberHelperArbitrum.sol +200 -0
- package/contracts/router/swap-aggregator/kyberswap/arbitrum/ScaleDataHelperArbitrum.sol +135 -0
- package/contracts/router/swap-aggregator/kyberswap/ethereum/IAggregationExecutor.sol +17 -0
- package/contracts/router/swap-aggregator/kyberswap/ethereum/IHashflow.sol +30 -0
- package/contracts/router/swap-aggregator/kyberswap/{KyberAggregationRouterHelper.sol → ethereum/KyberHelperEthereum.sol} +16 -28
- package/contracts/router/swap-aggregator/kyberswap/{ScaleDataHelperEthereum1.sol → ethereum/ScaleDataHelperEthereum.sol} +2 -2
- package/deployments/1-core.json +1 -1
- package/deployments/42161-core.json +1 -1
- package/package.json +1 -1
- package/typechain-types/IExecutorHelper1.ts +643 -0
- package/typechain-types/IExecutorHelper2.ts +115 -0
- package/typechain-types/InputScalingHelper.ts +108 -0
- package/typechain-types/PendleSwapArbitrum.ts +126 -0
- package/typechain-types/PendleSwapEthereum.ts +126 -0
- package/typechain-types/factories/ActionAddRemoveLiq__factory.ts +1 -1
- package/typechain-types/factories/IExecutorHelper1__factory.ts +403 -0
- package/typechain-types/factories/IExecutorHelper2__factory.ts +55 -0
- package/typechain-types/factories/InputScalingHelper__factory.ts +88 -0
- package/typechain-types/factories/PendleSwapAggregator__factory.ts +1 -1
- package/typechain-types/factories/PendleSwapArbitrum__factory.ts +129 -0
- package/typechain-types/factories/PendleSwapEthereum__factory.ts +129 -0
- package/typechain-types/hardhat.d.ts +58 -184
- package/typechain-types/index.ts +10 -44
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwapAggregator.sol/PendleSwapAggregator.dbg.json +0 -4
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwapAggregator.sol/PendleSwapAggregator.json +0 -72
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/KyberAggregationRouterHelper.sol/KyberAggregationRouterHelper.dbg.json +0 -4
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/ScaleDataHelperEthereum1.sol/ScaleDataHelperEthereum1.dbg.json +0 -4
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/ScaleDataHelperEthereum1.sol/ScaleDataHelperEthereum1.json +0 -10
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/interfaces/IAggregationExecutor.sol/IAggregationExecutor.dbg.json +0 -4
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/interfaces/IExecutorHelperEthereum1.sol/IExecutorHelperEthereum1.dbg.json +0 -4
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/interfaces/IHashflow.sol/IHashflow.dbg.json +0 -4
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/interfaces/IMetaAggregationRouterV2.sol/IMetaAggregationRouterV2.dbg.json +0 -4
- /package/contracts/router/swap-aggregator/kyberswap/{interfaces → arbitrum}/IAggregationExecutor.sol +0 -0
- /package/contracts/router/swap-aggregator/kyberswap/{interfaces → arbitrum}/IHashflow.sol +0 -0
- /package/contracts/router/swap-aggregator/kyberswap/{interfaces → ethereum}/IExecutorHelperEthereum1.sol +0 -0
- /package/contracts/router/swap-aggregator/kyberswap/{interfaces → ethereum}/IMetaAggregationRouterV2.sol +0 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.17;
|
|
3
|
+
|
|
4
|
+
import "./IHashflow.sol";
|
|
5
|
+
|
|
6
|
+
interface IExecutorHelper1 {
|
|
7
|
+
struct UniSwap {
|
|
8
|
+
address pool;
|
|
9
|
+
address tokenIn;
|
|
10
|
+
address tokenOut;
|
|
11
|
+
address recipient;
|
|
12
|
+
uint256 collectAmount; // amount that should be transferred to the pool
|
|
13
|
+
uint256 limitReturnAmount;
|
|
14
|
+
uint32 swapFee;
|
|
15
|
+
uint32 feePrecision;
|
|
16
|
+
uint32 tokenWeightInput;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
struct StableSwap {
|
|
20
|
+
address pool;
|
|
21
|
+
address tokenFrom;
|
|
22
|
+
address tokenTo;
|
|
23
|
+
uint8 tokenIndexFrom;
|
|
24
|
+
uint8 tokenIndexTo;
|
|
25
|
+
uint256 dx;
|
|
26
|
+
uint256 minDy;
|
|
27
|
+
uint256 poolLength;
|
|
28
|
+
address poolLp;
|
|
29
|
+
bool isSaddle; // true: saddle, false: stable
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
struct CurveSwap {
|
|
33
|
+
address pool;
|
|
34
|
+
address tokenFrom;
|
|
35
|
+
address tokenTo;
|
|
36
|
+
int128 tokenIndexFrom;
|
|
37
|
+
int128 tokenIndexTo;
|
|
38
|
+
uint256 dx;
|
|
39
|
+
uint256 minDy;
|
|
40
|
+
bool usePoolUnderlying;
|
|
41
|
+
bool useTriCrypto;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
struct UniSwapV3ProMM {
|
|
45
|
+
address recipient;
|
|
46
|
+
address pool;
|
|
47
|
+
address tokenIn;
|
|
48
|
+
address tokenOut;
|
|
49
|
+
uint256 swapAmount;
|
|
50
|
+
uint256 limitReturnAmount;
|
|
51
|
+
uint160 sqrtPriceLimitX96;
|
|
52
|
+
bool isUniV3; // true = UniV3, false = ProMM
|
|
53
|
+
}
|
|
54
|
+
struct SwapCallbackData {
|
|
55
|
+
bytes path;
|
|
56
|
+
address payer;
|
|
57
|
+
}
|
|
58
|
+
struct SwapCallbackDataPath {
|
|
59
|
+
address pool;
|
|
60
|
+
address tokenIn;
|
|
61
|
+
address tokenOut;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
struct BalancerV2 {
|
|
65
|
+
address vault;
|
|
66
|
+
bytes32 poolId;
|
|
67
|
+
address assetIn;
|
|
68
|
+
address assetOut;
|
|
69
|
+
uint256 amount;
|
|
70
|
+
uint256 limit;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
struct KyberRFQ {
|
|
74
|
+
address rfq;
|
|
75
|
+
bytes order;
|
|
76
|
+
bytes signature;
|
|
77
|
+
uint256 amount;
|
|
78
|
+
address payable target;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
struct DODO {
|
|
82
|
+
address recipient;
|
|
83
|
+
address pool;
|
|
84
|
+
address tokenFrom;
|
|
85
|
+
address tokenTo;
|
|
86
|
+
uint256 amount;
|
|
87
|
+
uint256 minReceiveQuote;
|
|
88
|
+
address sellHelper;
|
|
89
|
+
bool isSellBase;
|
|
90
|
+
bool isVersion2;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
struct GMX {
|
|
94
|
+
address vault;
|
|
95
|
+
address tokenIn;
|
|
96
|
+
address tokenOut;
|
|
97
|
+
uint256 amount;
|
|
98
|
+
uint256 minOut;
|
|
99
|
+
address receiver;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
struct Synthetix {
|
|
103
|
+
address synthetixProxy;
|
|
104
|
+
address tokenIn;
|
|
105
|
+
address tokenOut;
|
|
106
|
+
bytes32 sourceCurrencyKey;
|
|
107
|
+
uint256 sourceAmount;
|
|
108
|
+
bytes32 destinationCurrencyKey;
|
|
109
|
+
uint256 minAmount;
|
|
110
|
+
bool useAtomicExchange;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
struct Hashflow {
|
|
114
|
+
address router;
|
|
115
|
+
IHashflow.Quote quote;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function executeUniSwap(
|
|
119
|
+
uint256 index,
|
|
120
|
+
bytes memory data,
|
|
121
|
+
uint256 previousAmountOut
|
|
122
|
+
) external payable returns (uint256);
|
|
123
|
+
|
|
124
|
+
function executeStableSwap(
|
|
125
|
+
uint256 index,
|
|
126
|
+
bytes memory data,
|
|
127
|
+
uint256 previousAmountOut
|
|
128
|
+
) external payable returns (uint256);
|
|
129
|
+
|
|
130
|
+
function executeCurveSwap(
|
|
131
|
+
uint256 index,
|
|
132
|
+
bytes memory data,
|
|
133
|
+
uint256 previousAmountOut
|
|
134
|
+
) external payable returns (uint256);
|
|
135
|
+
|
|
136
|
+
function executeKyberDMMSwap(
|
|
137
|
+
uint256 index,
|
|
138
|
+
bytes memory data,
|
|
139
|
+
uint256 previousAmountOut
|
|
140
|
+
) external payable returns (uint256);
|
|
141
|
+
|
|
142
|
+
function executeUniV3ProMMSwap(
|
|
143
|
+
uint256 index,
|
|
144
|
+
bytes memory data,
|
|
145
|
+
uint256 previousAmountOut
|
|
146
|
+
) external payable returns (uint256);
|
|
147
|
+
|
|
148
|
+
function executeRfqSwap(
|
|
149
|
+
uint256 index,
|
|
150
|
+
bytes memory data,
|
|
151
|
+
uint256 previousAmountOut
|
|
152
|
+
) external payable returns (uint256);
|
|
153
|
+
|
|
154
|
+
function executeBalV2Swap(
|
|
155
|
+
uint256 index,
|
|
156
|
+
bytes memory data,
|
|
157
|
+
uint256 previousAmountOut
|
|
158
|
+
) external payable returns (uint256);
|
|
159
|
+
|
|
160
|
+
function executeDODOSwap(
|
|
161
|
+
uint256 index,
|
|
162
|
+
bytes memory data,
|
|
163
|
+
uint256 previousAmountOut
|
|
164
|
+
) external payable returns (uint256);
|
|
165
|
+
|
|
166
|
+
function executeVelodromeSwap(
|
|
167
|
+
uint256 index,
|
|
168
|
+
bytes memory data,
|
|
169
|
+
uint256 previousAmountOut
|
|
170
|
+
) external payable returns (uint256);
|
|
171
|
+
|
|
172
|
+
function executeGMXSwap(
|
|
173
|
+
uint256 index,
|
|
174
|
+
bytes memory data,
|
|
175
|
+
uint256 previousAmountOut
|
|
176
|
+
) external payable returns (uint256);
|
|
177
|
+
|
|
178
|
+
function executeSynthetixSwap(
|
|
179
|
+
uint256 index,
|
|
180
|
+
bytes memory data,
|
|
181
|
+
uint256 previousAmountOut
|
|
182
|
+
) external payable returns (uint256);
|
|
183
|
+
|
|
184
|
+
function executeHashflowSwap(
|
|
185
|
+
uint256 index,
|
|
186
|
+
bytes memory data,
|
|
187
|
+
uint256 previousAmountOut
|
|
188
|
+
) external payable returns (uint256);
|
|
189
|
+
|
|
190
|
+
function executeCamelotSwap(
|
|
191
|
+
uint256 index,
|
|
192
|
+
bytes memory data,
|
|
193
|
+
uint256 previousAmountOut
|
|
194
|
+
) external payable returns (uint256);
|
|
195
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.17;
|
|
3
|
+
|
|
4
|
+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
5
|
+
import { IAggregationExecutor } from "./IAggregationExecutor.sol";
|
|
6
|
+
|
|
7
|
+
interface IMetaAggregationRouterV2 {
|
|
8
|
+
struct SwapDescriptionV2 {
|
|
9
|
+
IERC20 srcToken;
|
|
10
|
+
IERC20 dstToken;
|
|
11
|
+
address[] srcReceivers; // transfer src token to these addresses, default
|
|
12
|
+
uint256[] srcAmounts;
|
|
13
|
+
address[] feeReceivers;
|
|
14
|
+
uint256[] feeAmounts;
|
|
15
|
+
address dstReceiver;
|
|
16
|
+
uint256 amount;
|
|
17
|
+
uint256 minReturnAmount;
|
|
18
|
+
uint256 flags;
|
|
19
|
+
bytes permit;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/// @dev use for swapGeneric and swap to avoid stack too deep
|
|
23
|
+
struct SwapExecutionParams {
|
|
24
|
+
address callTarget; // call this address
|
|
25
|
+
address approveTarget; // approve this address if _APPROVE_FUND set
|
|
26
|
+
bytes targetData;
|
|
27
|
+
SwapDescriptionV2 desc;
|
|
28
|
+
bytes clientData;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function swap(
|
|
32
|
+
SwapExecutionParams calldata execution
|
|
33
|
+
) external payable returns (uint256, uint256);
|
|
34
|
+
|
|
35
|
+
function swapSimpleMode(
|
|
36
|
+
IAggregationExecutor caller,
|
|
37
|
+
SwapDescriptionV2 memory desc,
|
|
38
|
+
bytes calldata executorData,
|
|
39
|
+
bytes calldata clientData
|
|
40
|
+
) external returns (uint256, uint256);
|
|
41
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.17;
|
|
3
|
+
|
|
4
|
+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
5
|
+
import { IExecutorHelper1 } from "./IExecutorHelper1.sol";
|
|
6
|
+
import { IExecutorHelper2 } from "./IExecutorHelper2.sol";
|
|
7
|
+
import { IMetaAggregationRouterV2 } from "./IMetaAggregationRouterV2.sol";
|
|
8
|
+
import { ScaleDataHelperArbitrum } from "./ScaleDataHelperArbitrum.sol";
|
|
9
|
+
|
|
10
|
+
abstract contract KyberHelperArbitrum {
|
|
11
|
+
uint256 private constant _PARTIAL_FILL = 0x01;
|
|
12
|
+
uint256 private constant _REQUIRES_EXTRA_ETH = 0x02;
|
|
13
|
+
uint256 private constant _SHOULD_CLAIM = 0x04;
|
|
14
|
+
uint256 private constant _BURN_FROM_MSG_SENDER = 0x08;
|
|
15
|
+
uint256 private constant _BURN_FROM_TX_ORIGIN = 0x10;
|
|
16
|
+
uint256 private constant _SIMPLE_SWAP = 0x20;
|
|
17
|
+
|
|
18
|
+
struct Swap {
|
|
19
|
+
bytes data;
|
|
20
|
+
bytes4 selector;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
struct SimpleSwapData {
|
|
24
|
+
address[] firstPools;
|
|
25
|
+
uint256[] firstSwapAmounts;
|
|
26
|
+
bytes[] swapDatas;
|
|
27
|
+
uint256 deadline;
|
|
28
|
+
bytes destTokenFeeData;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
struct SwapExecutorDescription {
|
|
32
|
+
Swap[][] swapSequences;
|
|
33
|
+
address tokenIn;
|
|
34
|
+
address tokenOut;
|
|
35
|
+
uint256 minTotalAmountOut;
|
|
36
|
+
address to;
|
|
37
|
+
uint256 deadline;
|
|
38
|
+
bytes destTokenFeeData;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function _getKyberScaledInputData(
|
|
42
|
+
bytes calldata kybercall,
|
|
43
|
+
uint256 newAmount
|
|
44
|
+
) internal pure returns (bytes memory) {
|
|
45
|
+
bytes4 selector = bytes4(kybercall[:4]);
|
|
46
|
+
|
|
47
|
+
if (selector == IMetaAggregationRouterV2.swap.selector) {
|
|
48
|
+
IMetaAggregationRouterV2.SwapExecutionParams memory params = abi.decode(
|
|
49
|
+
kybercall[4:],
|
|
50
|
+
(IMetaAggregationRouterV2.SwapExecutionParams)
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
(params.desc, params.targetData) = _getScaledInputDataV2(
|
|
54
|
+
params.desc,
|
|
55
|
+
params.targetData,
|
|
56
|
+
newAmount,
|
|
57
|
+
_flagsChecked(params.desc.flags, _SIMPLE_SWAP)
|
|
58
|
+
);
|
|
59
|
+
return abi.encodeWithSelector(selector, params);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (selector == IMetaAggregationRouterV2.swapSimpleMode.selector) {
|
|
63
|
+
(
|
|
64
|
+
address callTarget,
|
|
65
|
+
IMetaAggregationRouterV2.SwapDescriptionV2 memory desc,
|
|
66
|
+
bytes memory targetData,
|
|
67
|
+
bytes memory clientData
|
|
68
|
+
) = abi.decode(
|
|
69
|
+
kybercall[4:],
|
|
70
|
+
(address, IMetaAggregationRouterV2.SwapDescriptionV2, bytes, bytes)
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
(desc, targetData) = _getScaledInputDataV2(desc, targetData, newAmount, true);
|
|
74
|
+
return abi.encodeWithSelector(selector, callTarget, desc, targetData, clientData);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
revert("InputScalingHelper: Invalid selector");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function _getScaledInputDataV2(
|
|
81
|
+
IMetaAggregationRouterV2.SwapDescriptionV2 memory desc,
|
|
82
|
+
bytes memory executorData,
|
|
83
|
+
uint256 newAmount,
|
|
84
|
+
bool isSimpleMode
|
|
85
|
+
) internal pure returns (IMetaAggregationRouterV2.SwapDescriptionV2 memory, bytes memory) {
|
|
86
|
+
uint256 oldAmount = desc.amount;
|
|
87
|
+
if (oldAmount == newAmount) {
|
|
88
|
+
return (desc, executorData);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// simple mode swap
|
|
92
|
+
if (isSimpleMode) {
|
|
93
|
+
return (
|
|
94
|
+
_scaledSwapDescriptionV2(desc, oldAmount, newAmount),
|
|
95
|
+
_scaledSimpleSwapData(executorData, oldAmount, newAmount)
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
//normal mode swap
|
|
100
|
+
return (
|
|
101
|
+
_scaledSwapDescriptionV2(desc, oldAmount, newAmount),
|
|
102
|
+
_scaledExecutorCallBytesData(executorData, oldAmount, newAmount)
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function _scaledSimpleSwapData(
|
|
107
|
+
bytes memory data,
|
|
108
|
+
uint256 oldAmount,
|
|
109
|
+
uint256 newAmount
|
|
110
|
+
) internal pure returns (bytes memory) {
|
|
111
|
+
SimpleSwapData memory swapData = abi.decode(data, (SimpleSwapData));
|
|
112
|
+
uint256 numberSeq = swapData.firstPools.length;
|
|
113
|
+
uint256 newTotalSwapAmount;
|
|
114
|
+
for (uint256 i = 0; i < numberSeq; i++) {
|
|
115
|
+
if (i == numberSeq - 1) {
|
|
116
|
+
swapData.firstSwapAmounts[i] = newAmount - newTotalSwapAmount;
|
|
117
|
+
} else {
|
|
118
|
+
swapData.firstSwapAmounts[i] =
|
|
119
|
+
(swapData.firstSwapAmounts[i] * newAmount) /
|
|
120
|
+
oldAmount;
|
|
121
|
+
}
|
|
122
|
+
newTotalSwapAmount += swapData.firstSwapAmounts[i];
|
|
123
|
+
}
|
|
124
|
+
return abi.encode(swapData);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function _scaledExecutorCallBytesData(
|
|
128
|
+
bytes memory data,
|
|
129
|
+
uint256 oldAmount,
|
|
130
|
+
uint256 newAmount
|
|
131
|
+
) internal pure returns (bytes memory) {
|
|
132
|
+
SwapExecutorDescription memory executorDesc = abi.decode(data, (SwapExecutorDescription));
|
|
133
|
+
executorDesc.minTotalAmountOut = (executorDesc.minTotalAmountOut * newAmount) / oldAmount;
|
|
134
|
+
for (uint256 i = 0; i < executorDesc.swapSequences.length; i++) {
|
|
135
|
+
Swap memory swap = executorDesc.swapSequences[i][0];
|
|
136
|
+
bytes4 selector = swap.selector;
|
|
137
|
+
|
|
138
|
+
if (selector == IExecutorHelper1.executeUniSwap.selector) {
|
|
139
|
+
swap.data = ScaleDataHelperArbitrum.newUniSwap(swap.data, oldAmount, newAmount);
|
|
140
|
+
} else if (selector == IExecutorHelper1.executeStableSwap.selector) {
|
|
141
|
+
swap.data = ScaleDataHelperArbitrum.newStableSwap(swap.data, oldAmount, newAmount);
|
|
142
|
+
} else if (selector == IExecutorHelper1.executeCurveSwap.selector) {
|
|
143
|
+
swap.data = ScaleDataHelperArbitrum.newCurveSwap(swap.data, oldAmount, newAmount);
|
|
144
|
+
} else if (selector == IExecutorHelper1.executeKyberDMMSwap.selector) {
|
|
145
|
+
swap.data = ScaleDataHelperArbitrum.newKyberDMM(swap.data, oldAmount, newAmount);
|
|
146
|
+
} else if (selector == IExecutorHelper1.executeUniV3ProMMSwap.selector) {
|
|
147
|
+
swap.data = ScaleDataHelperArbitrum.newUniV3ProMM(swap.data, oldAmount, newAmount);
|
|
148
|
+
} else if (selector == IExecutorHelper1.executeRfqSwap.selector) {
|
|
149
|
+
revert("InputScalingHelper: Can not scale RFQ swap");
|
|
150
|
+
} else if (selector == IExecutorHelper1.executeBalV2Swap.selector) {
|
|
151
|
+
swap.data = ScaleDataHelperArbitrum.newBalancerV2(swap.data, oldAmount, newAmount);
|
|
152
|
+
} else if (selector == IExecutorHelper1.executeDODOSwap.selector) {
|
|
153
|
+
swap.data = ScaleDataHelperArbitrum.newDODO(swap.data, oldAmount, newAmount);
|
|
154
|
+
} else if (selector == IExecutorHelper1.executeVelodromeSwap.selector) {
|
|
155
|
+
swap.data = ScaleDataHelperArbitrum.newVelodrome(swap.data, oldAmount, newAmount);
|
|
156
|
+
} else if (selector == IExecutorHelper1.executeGMXSwap.selector) {
|
|
157
|
+
swap.data = ScaleDataHelperArbitrum.newGMX(swap.data, oldAmount, newAmount);
|
|
158
|
+
} else if (selector == IExecutorHelper1.executeSynthetixSwap.selector) {
|
|
159
|
+
swap.data = ScaleDataHelperArbitrum.newSynthetix(swap.data, oldAmount, newAmount);
|
|
160
|
+
} else if (selector == IExecutorHelper1.executeHashflowSwap.selector) {
|
|
161
|
+
revert("InputScalingHelper: Can not scale RFQ swap");
|
|
162
|
+
} else if (selector == IExecutorHelper1.executeCamelotSwap.selector) {
|
|
163
|
+
swap.data = ScaleDataHelperArbitrum.newCamelot(swap.data, oldAmount, newAmount);
|
|
164
|
+
} else if (selector == IExecutorHelper2.executeKyberLimitOrder.selector) {
|
|
165
|
+
revert("InputScalingHelper: Can not scale RFQ swap");
|
|
166
|
+
} else revert("AggregationExecutor: Dex type not supported");
|
|
167
|
+
}
|
|
168
|
+
return abi.encode(executorDesc);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function _scaledSwapDescriptionV2(
|
|
172
|
+
IMetaAggregationRouterV2.SwapDescriptionV2 memory desc,
|
|
173
|
+
uint256 oldAmount,
|
|
174
|
+
uint256 newAmount
|
|
175
|
+
) internal pure returns (IMetaAggregationRouterV2.SwapDescriptionV2 memory) {
|
|
176
|
+
uint256 oldMinReturnAmount = desc.minReturnAmount;
|
|
177
|
+
desc.minReturnAmount = (desc.minReturnAmount * newAmount) / oldAmount;
|
|
178
|
+
//newMinReturnAmount should no be 0 if oldMinReturnAmount > 0
|
|
179
|
+
if (oldMinReturnAmount > 0 && desc.minReturnAmount == 0) desc.minReturnAmount = 1;
|
|
180
|
+
desc.amount = newAmount;
|
|
181
|
+
if (desc.srcReceivers.length == 0) {
|
|
182
|
+
return desc;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
uint256 newTotal;
|
|
186
|
+
for (uint256 i = 0; i < desc.srcReceivers.length; i++) {
|
|
187
|
+
if (i == desc.srcReceivers.length - 1) {
|
|
188
|
+
desc.srcAmounts[i] = newAmount - newTotal;
|
|
189
|
+
} else {
|
|
190
|
+
desc.srcAmounts[i] = (desc.srcAmounts[i] * newAmount) / oldAmount;
|
|
191
|
+
}
|
|
192
|
+
newTotal += desc.srcAmounts[i];
|
|
193
|
+
}
|
|
194
|
+
return desc;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function _flagsChecked(uint256 number, uint256 flag) internal pure returns (bool) {
|
|
198
|
+
return number & flag != 0;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.17;
|
|
3
|
+
|
|
4
|
+
import { IExecutorHelper1 } from "./IExecutorHelper1.sol";
|
|
5
|
+
|
|
6
|
+
library ScaleDataHelperArbitrum {
|
|
7
|
+
function newUniSwap(
|
|
8
|
+
bytes memory data,
|
|
9
|
+
uint256 oldAmount,
|
|
10
|
+
uint256 newAmount
|
|
11
|
+
) internal pure returns (bytes memory) {
|
|
12
|
+
IExecutorHelper1.UniSwap memory uniSwap = abi.decode(data, (IExecutorHelper1.UniSwap));
|
|
13
|
+
uniSwap.collectAmount = (uniSwap.collectAmount * newAmount) / oldAmount;
|
|
14
|
+
return abi.encode(uniSwap);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function newStableSwap(
|
|
18
|
+
bytes memory data,
|
|
19
|
+
uint256 oldAmount,
|
|
20
|
+
uint256 newAmount
|
|
21
|
+
) internal pure returns (bytes memory) {
|
|
22
|
+
IExecutorHelper1.StableSwap memory stableSwap = abi.decode(
|
|
23
|
+
data,
|
|
24
|
+
(IExecutorHelper1.StableSwap)
|
|
25
|
+
);
|
|
26
|
+
stableSwap.dx = (stableSwap.dx * newAmount) / oldAmount;
|
|
27
|
+
return abi.encode(stableSwap);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function newCurveSwap(
|
|
31
|
+
bytes memory data,
|
|
32
|
+
uint256 oldAmount,
|
|
33
|
+
uint256 newAmount
|
|
34
|
+
) internal pure returns (bytes memory) {
|
|
35
|
+
IExecutorHelper1.CurveSwap memory curveSwap = abi.decode(
|
|
36
|
+
data,
|
|
37
|
+
(IExecutorHelper1.CurveSwap)
|
|
38
|
+
);
|
|
39
|
+
curveSwap.dx = (curveSwap.dx * newAmount) / oldAmount;
|
|
40
|
+
return abi.encode(curveSwap);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function newKyberDMM(
|
|
44
|
+
bytes memory data,
|
|
45
|
+
uint256 oldAmount,
|
|
46
|
+
uint256 newAmount
|
|
47
|
+
) internal pure returns (bytes memory) {
|
|
48
|
+
IExecutorHelper1.UniSwap memory kyberDMMSwap = abi.decode(
|
|
49
|
+
data,
|
|
50
|
+
(IExecutorHelper1.UniSwap)
|
|
51
|
+
);
|
|
52
|
+
kyberDMMSwap.collectAmount = (kyberDMMSwap.collectAmount * newAmount) / oldAmount;
|
|
53
|
+
return abi.encode(kyberDMMSwap);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function newUniV3ProMM(
|
|
57
|
+
bytes memory data,
|
|
58
|
+
uint256 oldAmount,
|
|
59
|
+
uint256 newAmount
|
|
60
|
+
) internal pure returns (bytes memory) {
|
|
61
|
+
IExecutorHelper1.UniSwapV3ProMM memory uniSwapV3ProMM = abi.decode(
|
|
62
|
+
data,
|
|
63
|
+
(IExecutorHelper1.UniSwapV3ProMM)
|
|
64
|
+
);
|
|
65
|
+
uniSwapV3ProMM.swapAmount = (uniSwapV3ProMM.swapAmount * newAmount) / oldAmount;
|
|
66
|
+
|
|
67
|
+
return abi.encode(uniSwapV3ProMM);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function newBalancerV2(
|
|
71
|
+
bytes memory data,
|
|
72
|
+
uint256 oldAmount,
|
|
73
|
+
uint256 newAmount
|
|
74
|
+
) internal pure returns (bytes memory) {
|
|
75
|
+
IExecutorHelper1.BalancerV2 memory balancerV2 = abi.decode(
|
|
76
|
+
data,
|
|
77
|
+
(IExecutorHelper1.BalancerV2)
|
|
78
|
+
);
|
|
79
|
+
balancerV2.amount = (balancerV2.amount * newAmount) / oldAmount;
|
|
80
|
+
return abi.encode(balancerV2);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function newDODO(
|
|
84
|
+
bytes memory data,
|
|
85
|
+
uint256 oldAmount,
|
|
86
|
+
uint256 newAmount
|
|
87
|
+
) internal pure returns (bytes memory) {
|
|
88
|
+
IExecutorHelper1.DODO memory dodo = abi.decode(data, (IExecutorHelper1.DODO));
|
|
89
|
+
dodo.amount = (dodo.amount * newAmount) / oldAmount;
|
|
90
|
+
return abi.encode(dodo);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function newVelodrome(
|
|
94
|
+
bytes memory data,
|
|
95
|
+
uint256 oldAmount,
|
|
96
|
+
uint256 newAmount
|
|
97
|
+
) internal pure returns (bytes memory) {
|
|
98
|
+
IExecutorHelper1.UniSwap memory velodrome = abi.decode(data, (IExecutorHelper1.UniSwap));
|
|
99
|
+
velodrome.collectAmount = (velodrome.collectAmount * newAmount) / oldAmount;
|
|
100
|
+
return abi.encode(velodrome);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function newGMX(
|
|
104
|
+
bytes memory data,
|
|
105
|
+
uint256 oldAmount,
|
|
106
|
+
uint256 newAmount
|
|
107
|
+
) internal pure returns (bytes memory) {
|
|
108
|
+
IExecutorHelper1.GMX memory gmx = abi.decode(data, (IExecutorHelper1.GMX));
|
|
109
|
+
gmx.amount = (gmx.amount * newAmount) / oldAmount;
|
|
110
|
+
return abi.encode(gmx);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function newSynthetix(
|
|
114
|
+
bytes memory data,
|
|
115
|
+
uint256 oldAmount,
|
|
116
|
+
uint256 newAmount
|
|
117
|
+
) internal pure returns (bytes memory) {
|
|
118
|
+
IExecutorHelper1.Synthetix memory synthetix = abi.decode(
|
|
119
|
+
data,
|
|
120
|
+
(IExecutorHelper1.Synthetix)
|
|
121
|
+
);
|
|
122
|
+
synthetix.sourceAmount = (synthetix.sourceAmount * newAmount) / oldAmount;
|
|
123
|
+
return abi.encode(synthetix);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function newCamelot(
|
|
127
|
+
bytes memory data,
|
|
128
|
+
uint256 oldAmount,
|
|
129
|
+
uint256 newAmount
|
|
130
|
+
) internal pure returns (bytes memory) {
|
|
131
|
+
IExecutorHelper1.UniSwap memory camelot = abi.decode(data, (IExecutorHelper1.UniSwap));
|
|
132
|
+
camelot.collectAmount = (camelot.collectAmount * newAmount) / oldAmount;
|
|
133
|
+
return abi.encode(camelot);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity >=0.6.12;
|
|
4
|
+
|
|
5
|
+
interface IAggregationExecutor {
|
|
6
|
+
function callBytes(bytes calldata data) external payable; // 0xd9c45357
|
|
7
|
+
|
|
8
|
+
// callbytes per swap sequence
|
|
9
|
+
function swapSingleSequence(bytes calldata data) external;
|
|
10
|
+
|
|
11
|
+
function finalTransactionProcessing(
|
|
12
|
+
address tokenIn,
|
|
13
|
+
address tokenOut,
|
|
14
|
+
address to,
|
|
15
|
+
bytes calldata destTokenFeeData
|
|
16
|
+
) external;
|
|
17
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity 0.8.17;
|
|
4
|
+
|
|
5
|
+
interface IHashflow {
|
|
6
|
+
enum RFQType {
|
|
7
|
+
TAKER,
|
|
8
|
+
MAKER
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
struct Quote {
|
|
12
|
+
RFQType rfqType;
|
|
13
|
+
address pool;
|
|
14
|
+
address eoa;
|
|
15
|
+
address trader;
|
|
16
|
+
address effectiveTrader;
|
|
17
|
+
address baseToken;
|
|
18
|
+
address quoteToken;
|
|
19
|
+
uint256 effectiveBaseTokenAmount;
|
|
20
|
+
uint256 maxBaseTokenAmount;
|
|
21
|
+
uint256 maxQuoteTokenAmount;
|
|
22
|
+
uint256 fees;
|
|
23
|
+
uint256 quoteExpiry;
|
|
24
|
+
uint256 nonce;
|
|
25
|
+
bytes32 txid;
|
|
26
|
+
bytes signedQuote;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function tradeSingleHop(Quote memory quote) external payable;
|
|
30
|
+
}
|