@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.
Files changed (22) hide show
  1. package/contracts/offchain-helpers/MarketExchangeRateLib.sol +43 -0
  2. package/contracts/router/swap-aggregator/{PendleSwapEthereum.sol → PendleSwap.sol} +8 -12
  3. package/contracts/router/swap-aggregator/kyberswap/{arbitrum/IExecutorHelper1.sol → IExecutorHelper.sol} +65 -21
  4. package/contracts/router/swap-aggregator/kyberswap/{arbitrum/IMetaAggregationRouterV2.sol → IMetaAggregationRouterV2.sol} +4 -3
  5. package/contracts/router/swap-aggregator/kyberswap/KyberInputScalingHelper.sol +235 -0
  6. package/contracts/router/swap-aggregator/kyberswap/{arbitrum/ScaleDataHelperArbitrum.sol → ScalingDataLib.sol} +56 -25
  7. package/deployments/1-core.json +1 -1
  8. package/deployments/42161-core.json +1 -1
  9. package/package.json +1 -1
  10. package/contracts/router/swap-aggregator/1inch/I1inchAggregationRouterV5.sol +0 -39
  11. package/contracts/router/swap-aggregator/1inch/OneInchAggregationRouterHelper.sol +0 -68
  12. package/contracts/router/swap-aggregator/PendleSwapArbitrum.sol +0 -45
  13. package/contracts/router/swap-aggregator/kyberswap/arbitrum/IExecutorHelper2.sol +0 -10
  14. package/contracts/router/swap-aggregator/kyberswap/arbitrum/KyberHelperArbitrum.sol +0 -200
  15. package/contracts/router/swap-aggregator/kyberswap/ethereum/IAggregationExecutor.sol +0 -17
  16. package/contracts/router/swap-aggregator/kyberswap/ethereum/IExecutorHelperEthereum1.sol +0 -191
  17. package/contracts/router/swap-aggregator/kyberswap/ethereum/IHashflow.sol +0 -30
  18. package/contracts/router/swap-aggregator/kyberswap/ethereum/IMetaAggregationRouterV2.sol +0 -41
  19. package/contracts/router/swap-aggregator/kyberswap/ethereum/KyberHelperEthereum.sol +0 -201
  20. package/contracts/router/swap-aggregator/kyberswap/ethereum/ScaleDataHelperEthereum.sol +0 -147
  21. /package/contracts/router/swap-aggregator/kyberswap/{arbitrum/IAggregationExecutor.sol → IAggregationExecutor.sol} +0 -0
  22. /package/contracts/router/swap-aggregator/kyberswap/{arbitrum/IHashflow.sol → IHashflow.sol} +0 -0
@@ -1,201 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
-
3
- pragma solidity 0.8.17;
4
- import "./IMetaAggregationRouterV2.sol";
5
- import "./IHashflow.sol";
6
- import "./IExecutorHelperEthereum1.sol";
7
- import "./ScaleDataHelperEthereum.sol";
8
-
9
- abstract contract KyberHelperEthereum {
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
- struct Swap {
18
- bytes data;
19
- bytes4 selector;
20
- }
21
-
22
- struct SimpleSwapData {
23
- address[] firstPools;
24
- uint256[] firstSwapAmounts;
25
- bytes[] swapDatas;
26
- uint256 deadline;
27
- bytes destTokenFeeData;
28
- }
29
-
30
- struct SwapExecutorDescription {
31
- Swap[][] swapSequences;
32
- address tokenIn;
33
- address tokenOut;
34
- uint256 minTotalAmountOut;
35
- address to;
36
- uint256 deadline;
37
- bytes destTokenFeeData;
38
- }
39
-
40
- function _getKyberScaledInputData(
41
- bytes calldata kybercall,
42
- uint256 newAmount
43
- ) internal pure returns (bytes memory) {
44
- bytes4 selector = bytes4(kybercall[:4]);
45
-
46
- if (selector == IMetaAggregationRouterV2.swap.selector) {
47
- IMetaAggregationRouterV2.SwapExecutionParams memory params = abi.decode(
48
- kybercall[4:],
49
- (IMetaAggregationRouterV2.SwapExecutionParams)
50
- );
51
-
52
- (params.desc, params.targetData) = _getScaledInputDataV2(
53
- params.desc,
54
- params.targetData,
55
- newAmount,
56
- _flagsChecked(params.desc.flags, _SIMPLE_SWAP)
57
- );
58
- return abi.encodeWithSelector(selector, params);
59
- }
60
-
61
- if (selector == IMetaAggregationRouterV2.swapSimpleMode.selector) {
62
- (
63
- address callTarget,
64
- IMetaAggregationRouterV2.SwapDescriptionV2 memory desc,
65
- bytes memory targetData,
66
- bytes memory clientData
67
- ) = abi.decode(
68
- kybercall[4:],
69
- (address, IMetaAggregationRouterV2.SwapDescriptionV2, bytes, bytes)
70
- );
71
-
72
- (desc, targetData) = _getScaledInputDataV2(desc, targetData, newAmount, true);
73
- return abi.encodeWithSelector(selector, callTarget, desc, targetData, clientData);
74
- }
75
-
76
- revert("InputScalingHelper: Invalid selector");
77
- }
78
-
79
- function _getScaledInputDataV2(
80
- IMetaAggregationRouterV2.SwapDescriptionV2 memory desc,
81
- bytes memory executorData,
82
- uint256 newAmount,
83
- bool isSimpleMode
84
- ) internal pure returns (IMetaAggregationRouterV2.SwapDescriptionV2 memory, bytes memory) {
85
- uint256 oldAmount = desc.amount;
86
- if (oldAmount == newAmount) {
87
- return (desc, executorData);
88
- }
89
-
90
- // simple mode swap
91
- if (isSimpleMode) {
92
- return (
93
- _scaledSwapDescriptionV2(desc, oldAmount, newAmount),
94
- _scaledSimpleSwapData(executorData, oldAmount, newAmount)
95
- );
96
- }
97
-
98
- //normal mode swap
99
- return (
100
- _scaledSwapDescriptionV2(desc, oldAmount, newAmount),
101
- _scaledExecutorCallBytesData(executorData, oldAmount, newAmount)
102
- );
103
- }
104
-
105
- function _scaledSimpleSwapData(
106
- bytes memory data,
107
- uint256 oldAmount,
108
- uint256 newAmount
109
- ) internal pure returns (bytes memory) {
110
- SimpleSwapData memory swapData = abi.decode(data, (SimpleSwapData));
111
- uint256 numberSeq = swapData.firstPools.length;
112
- uint256 newTotalSwapAmount;
113
- for (uint256 i = 0; i < numberSeq; i++) {
114
- if (i == numberSeq - 1) {
115
- swapData.firstSwapAmounts[i] = newAmount - newTotalSwapAmount;
116
- } else {
117
- swapData.firstSwapAmounts[i] =
118
- (swapData.firstSwapAmounts[i] * newAmount) /
119
- oldAmount;
120
- }
121
- newTotalSwapAmount += swapData.firstSwapAmounts[i];
122
- }
123
- return abi.encode(swapData);
124
- }
125
-
126
- function _scaledExecutorCallBytesData(
127
- bytes memory data,
128
- uint256 oldAmount,
129
- uint256 newAmount
130
- ) internal pure returns (bytes memory) {
131
- SwapExecutorDescription memory executorDesc = abi.decode(data, (SwapExecutorDescription));
132
- executorDesc.minTotalAmountOut = (executorDesc.minTotalAmountOut * newAmount) / oldAmount;
133
- for (uint256 i = 0; i < executorDesc.swapSequences.length; i++) {
134
- Swap memory swap = executorDesc.swapSequences[i][0];
135
- bytes4 selector = swap.selector;
136
-
137
- if (selector == IExecutorHelperEthereum1.executeUniSwap.selector) {
138
- swap.data = ScaleDataHelperEthereum.newUniSwap(swap.data, oldAmount, newAmount);
139
- } else if (selector == IExecutorHelperEthereum1.executeStableSwap.selector) {
140
- swap.data = ScaleDataHelperEthereum.newStableSwap(swap.data, oldAmount, newAmount);
141
- } else if (selector == IExecutorHelperEthereum1.executeCurveSwap.selector) {
142
- swap.data = ScaleDataHelperEthereum.newCurveSwap(swap.data, oldAmount, newAmount);
143
- } else if (selector == IExecutorHelperEthereum1.executeKyberDMMSwap.selector) {
144
- swap.data = ScaleDataHelperEthereum.newKyberDMM(swap.data, oldAmount, newAmount);
145
- } else if (selector == IExecutorHelperEthereum1.executeUniV3ProMMSwap.selector) {
146
- swap.data = ScaleDataHelperEthereum.newUniV3ProMM(swap.data, oldAmount, newAmount);
147
- } else if (selector == IExecutorHelperEthereum1.executeRfqSwap.selector) {
148
- revert("InputScalingHelper: Can not scale RFQ swap");
149
- } else if (selector == IExecutorHelperEthereum1.executeBalV2Swap.selector) {
150
- swap.data = ScaleDataHelperEthereum.newBalancerV2(swap.data, oldAmount, newAmount);
151
- } else if (selector == IExecutorHelperEthereum1.executeDODOSwap.selector) {
152
- swap.data = ScaleDataHelperEthereum.newDODO(swap.data, oldAmount, newAmount);
153
- } else if (selector == IExecutorHelperEthereum1.executeWrappedstETHSwap.selector) {
154
- swap.data = ScaleDataHelperEthereum.newWrappedstETHSwap(
155
- swap.data,
156
- oldAmount,
157
- newAmount
158
- );
159
- } else if (selector == IExecutorHelperEthereum1.executeSynthetixSwap.selector) {
160
- swap.data = ScaleDataHelperEthereum.newSynthetix(swap.data, oldAmount, newAmount);
161
- } else if (selector == IExecutorHelperEthereum1.executePSMSwap.selector) {
162
- swap.data = ScaleDataHelperEthereum.newPSM(swap.data, oldAmount, newAmount);
163
- } else if (selector == IExecutorHelperEthereum1.executeHashflowSwap.selector) {
164
- revert("InputScalingHelper: Can not scale RFQ swap");
165
- } else if (selector == IExecutorHelperEthereum1.executeFraxSwap.selector) {
166
- swap.data = ScaleDataHelperEthereum.newFrax(swap.data, oldAmount, newAmount);
167
- } else revert("AggregationExecutor: Dex type not supported");
168
- }
169
- return abi.encode(executorDesc);
170
- }
171
-
172
- function _scaledSwapDescriptionV2(
173
- IMetaAggregationRouterV2.SwapDescriptionV2 memory desc,
174
- uint256 oldAmount,
175
- uint256 newAmount
176
- ) internal pure returns (IMetaAggregationRouterV2.SwapDescriptionV2 memory) {
177
- uint256 oldMinReturnAmount = desc.minReturnAmount;
178
- desc.minReturnAmount = (desc.minReturnAmount * newAmount) / oldAmount;
179
- //newMinReturnAmount should no be 0 if oldMinReturnAmount > 0
180
- if (oldMinReturnAmount > 0 && desc.minReturnAmount == 0) desc.minReturnAmount = 1;
181
- desc.amount = newAmount;
182
- if (desc.srcReceivers.length == 0) {
183
- return desc;
184
- }
185
-
186
- uint256 newTotal;
187
- for (uint256 i = 0; i < desc.srcReceivers.length; i++) {
188
- if (i == desc.srcReceivers.length - 1) {
189
- desc.srcAmounts[i] = newAmount - newTotal;
190
- } else {
191
- desc.srcAmounts[i] = (desc.srcAmounts[i] * newAmount) / oldAmount;
192
- }
193
- newTotal += desc.srcAmounts[i];
194
- }
195
- return desc;
196
- }
197
-
198
- function _flagsChecked(uint256 number, uint256 flag) internal pure returns (bool) {
199
- return number & flag != 0;
200
- }
201
- }
@@ -1,147 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.17;
3
-
4
- import "./IExecutorHelperEthereum1.sol";
5
-
6
- library ScaleDataHelperEthereum {
7
- function newUniSwap(
8
- bytes memory data,
9
- uint256 oldAmount,
10
- uint256 newAmount
11
- ) internal pure returns (bytes memory) {
12
- IExecutorHelperEthereum1.UniSwap memory uniSwap = abi.decode(
13
- data,
14
- (IExecutorHelperEthereum1.UniSwap)
15
- );
16
- uniSwap.collectAmount = (uniSwap.collectAmount * newAmount) / oldAmount;
17
- return abi.encode(uniSwap);
18
- }
19
-
20
- function newStableSwap(
21
- bytes memory data,
22
- uint256 oldAmount,
23
- uint256 newAmount
24
- ) internal pure returns (bytes memory) {
25
- IExecutorHelperEthereum1.StableSwap memory stableSwap = abi.decode(
26
- data,
27
- (IExecutorHelperEthereum1.StableSwap)
28
- );
29
- stableSwap.dx = (stableSwap.dx * newAmount) / oldAmount;
30
- return abi.encode(stableSwap);
31
- }
32
-
33
- function newCurveSwap(
34
- bytes memory data,
35
- uint256 oldAmount,
36
- uint256 newAmount
37
- ) internal pure returns (bytes memory) {
38
- IExecutorHelperEthereum1.CurveSwap memory curveSwap = abi.decode(
39
- data,
40
- (IExecutorHelperEthereum1.CurveSwap)
41
- );
42
- curveSwap.dx = (curveSwap.dx * newAmount) / oldAmount;
43
- return abi.encode(curveSwap);
44
- }
45
-
46
- function newKyberDMM(
47
- bytes memory data,
48
- uint256 oldAmount,
49
- uint256 newAmount
50
- ) internal pure returns (bytes memory) {
51
- IExecutorHelperEthereum1.UniSwap memory kyberDMMSwap = abi.decode(
52
- data,
53
- (IExecutorHelperEthereum1.UniSwap)
54
- );
55
- kyberDMMSwap.collectAmount = (kyberDMMSwap.collectAmount * newAmount) / oldAmount;
56
- return abi.encode(kyberDMMSwap);
57
- }
58
-
59
- function newUniV3ProMM(
60
- bytes memory data,
61
- uint256 oldAmount,
62
- uint256 newAmount
63
- ) internal pure returns (bytes memory) {
64
- IExecutorHelperEthereum1.UniSwapV3ProMM memory uniSwapV3ProMM = abi.decode(
65
- data,
66
- (IExecutorHelperEthereum1.UniSwapV3ProMM)
67
- );
68
- uniSwapV3ProMM.swapAmount = (uniSwapV3ProMM.swapAmount * newAmount) / oldAmount;
69
-
70
- return abi.encode(uniSwapV3ProMM);
71
- }
72
-
73
- function newBalancerV2(
74
- bytes memory data,
75
- uint256 oldAmount,
76
- uint256 newAmount
77
- ) internal pure returns (bytes memory) {
78
- IExecutorHelperEthereum1.BalancerV2 memory balancerV2 = abi.decode(
79
- data,
80
- (IExecutorHelperEthereum1.BalancerV2)
81
- );
82
- balancerV2.amount = (balancerV2.amount * newAmount) / oldAmount;
83
- return abi.encode(balancerV2);
84
- }
85
-
86
- function newDODO(
87
- bytes memory data,
88
- uint256 oldAmount,
89
- uint256 newAmount
90
- ) internal pure returns (bytes memory) {
91
- IExecutorHelperEthereum1.DODO memory dodo = abi.decode(
92
- data,
93
- (IExecutorHelperEthereum1.DODO)
94
- );
95
- dodo.amount = (dodo.amount * newAmount) / oldAmount;
96
- return abi.encode(dodo);
97
- }
98
-
99
- function newSynthetix(
100
- bytes memory data,
101
- uint256 oldAmount,
102
- uint256 newAmount
103
- ) internal pure returns (bytes memory) {
104
- IExecutorHelperEthereum1.Synthetix memory synthetix = abi.decode(
105
- data,
106
- (IExecutorHelperEthereum1.Synthetix)
107
- );
108
- synthetix.sourceAmount = (synthetix.sourceAmount * newAmount) / oldAmount;
109
- return abi.encode(synthetix);
110
- }
111
-
112
- function newWrappedstETHSwap(
113
- bytes memory data,
114
- uint256 oldAmount,
115
- uint256 newAmount
116
- ) internal pure returns (bytes memory) {
117
- IExecutorHelperEthereum1.WSTETH memory wstEthData = abi.decode(
118
- data,
119
- (IExecutorHelperEthereum1.WSTETH)
120
- );
121
- wstEthData.amount = (wstEthData.amount * newAmount) / oldAmount;
122
- return abi.encode(wstEthData);
123
- }
124
-
125
- function newPSM(
126
- bytes memory data,
127
- uint256 oldAmount,
128
- uint256 newAmount
129
- ) internal pure returns (bytes memory) {
130
- IExecutorHelperEthereum1.PSM memory psm = abi.decode(data, (IExecutorHelperEthereum1.PSM));
131
- psm.amountIn = (psm.amountIn * newAmount) / oldAmount;
132
- return abi.encode(psm);
133
- }
134
-
135
- function newFrax(
136
- bytes memory data,
137
- uint256 oldAmount,
138
- uint256 newAmount
139
- ) internal pure returns (bytes memory) {
140
- IExecutorHelperEthereum1.UniSwap memory frax = abi.decode(
141
- data,
142
- (IExecutorHelperEthereum1.UniSwap)
143
- );
144
- frax.collectAmount = (frax.collectAmount * newAmount) / oldAmount;
145
- return abi.encode(frax);
146
- }
147
- }