@pendle/core-v2 4.0.5 → 4.1.0
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/core/StandardizedYield/implementations/AaveV3/PendleAaveV3SY.sol/PendleAaveV3SY.dbg.json +1 -1
- package/build/artifacts/contracts/core/StandardizedYield/implementations/AaveV3/PendleAaveV3SY.sol/PendleAaveV3SY.json +2 -2
- package/build/artifacts/contracts/core/StandardizedYield/implementations/EtherFi/PendleWEEthSY.sol/PendleWEEthSY.dbg.json +1 -1
- package/build/artifacts/contracts/core/StandardizedYield/implementations/EtherFi/PendleWEEthSY.sol/PendleWEEthSY.json +2 -2
- package/build/artifacts/contracts/core/StandardizedYield/implementations/KelpDAO/PendleRsETHSY.sol/PendleRsETHSY.dbg.json +1 -1
- package/build/artifacts/contracts/core/StandardizedYield/implementations/KelpDAO/PendleRsETHSY.sol/PendleRsETHSY.json +20 -2
- package/build/artifacts/contracts/core/StandardizedYield/implementations/PendleL2LRTSY.sol/PendleL2LRTSY.dbg.json +4 -0
- package/build/artifacts/contracts/core/StandardizedYield/implementations/PendleL2LRTSY.sol/PendleL2LRTSY.json +1054 -0
- package/build/artifacts/contracts/core/StandardizedYield/implementations/Renzo/PendleEzETHSY.sol/PendleEzETHSY.dbg.json +4 -0
- package/build/artifacts/contracts/core/StandardizedYield/implementations/Renzo/PendleEzETHSY.sol/PendleEzETHSY.json +1141 -0
- package/build/artifacts/contracts/core/StandardizedYield/implementations/Swell/PendleRswETHSY.sol/PendleRswETHSY.dbg.json +4 -0
- package/build/artifacts/contracts/core/StandardizedYield/implementations/Swell/PendleRswETHSY.sol/PendleRswETHSY.json +1044 -0
- package/build/artifacts/contracts/core/StandardizedYield/implementations/Swell/PendleSwETH.sol/SwETHSY.dbg.json +1 -1
- package/build/artifacts/contracts/core/StandardizedYield/implementations/Swell/PendleSwETH.sol/SwETHSY.json +2 -2
- package/build/artifacts/contracts/interfaces/IPActionMarketCoreStatic.sol/IPActionMarketCoreStatic.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPActionMarketCoreStatic.sol/IPActionMarketCoreStatic.json +0 -45
- package/build/artifacts/contracts/interfaces/IPActionMintRedeemStatic.sol/IPActionMintRedeemStatic.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPActionMintRedeemStatic.sol/IPActionMintRedeemStatic.json +0 -69
- package/build/artifacts/contracts/interfaces/IPActionStorageStatic.sol/IPActionStorageStatic.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPActionStorageStatic.sol/IPActionStorageStatic.json +0 -26
- package/build/artifacts/contracts/interfaces/IPRouterStatic.sol/IPRouterStatic.dbg.json +1 -1
- package/build/artifacts/contracts/interfaces/IPRouterStatic.sol/IPRouterStatic.json +0 -140
- package/build/artifacts/contracts/interfaces/Renzo/IRenzoOracle.sol/IRenzoOracle.dbg.json +4 -0
- package/build/artifacts/contracts/interfaces/Renzo/IRenzoOracle.sol/IRenzoOracle.json +64 -0
- package/build/artifacts/contracts/interfaces/Renzo/IRenzoRestakeManager.sol/IRenzoRestakeManager.dbg.json +4 -0
- package/build/artifacts/contracts/interfaces/Renzo/IRenzoRestakeManager.sol/IRenzoRestakeManager.json +102 -0
- package/build/artifacts/contracts/interfaces/Swell/IRswETH.sol/IRswETH.dbg.json +4 -0
- package/build/artifacts/contracts/interfaces/Swell/IRswETH.sol/IRswETH.json +44 -0
- package/build/artifacts/contracts/interfaces/Swell/ISwETH.sol/ISwETH.dbg.json +4 -0
- package/build/artifacts/contracts/interfaces/{ISwETH.sol → Swell/ISwETH.sol}/ISwETH.json +8 -8
- package/build/artifacts/contracts/offchain-helpers/router-static/PendleRouterStatic.sol/PendleRouterStatic.dbg.json +4 -0
- package/build/artifacts/contracts/offchain-helpers/router-static/PendleRouterStatic.sol/PendleRouterStatic.json +30 -0
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionInfoStatic.sol/ActionInfoStatic.dbg.json +4 -0
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionInfoStatic.sol/ActionInfoStatic.json +307 -0
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMarketAuxStatic.sol/ActionMarketAuxStatic.dbg.json +4 -0
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMarketAuxStatic.sol/ActionMarketAuxStatic.json +409 -0
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMarketCoreStatic.sol/ActionMarketCoreStatic.dbg.json +4 -0
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMarketCoreStatic.sol/ActionMarketCoreStatic.json +1352 -0
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMintRedeemStatic.sol/ActionMintRedeemStatic.dbg.json +4 -0
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMintRedeemStatic.sol/ActionMintRedeemStatic.json +247 -0
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionStorageStatic.sol/ActionStorageStatic.dbg.json +4 -0
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionStorageStatic.sol/ActionStorageStatic.json +202 -0
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionVePendleStatic.sol/ActionVePendleStatic.dbg.json +4 -0
- package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionVePendleStatic.sol/ActionVePendleStatic.json +93 -0
- package/build/artifacts/contracts/offchain-helpers/router-static/base/StorageLayout.sol/StorageLayout.dbg.json +4 -0
- package/build/artifacts/contracts/offchain-helpers/router-static/base/StorageLayout.sol/StorageLayout.json +10 -0
- package/build/artifacts/contracts/oracles/PendleRedStoneRateOracle.sol/PendleRedStoneRateOracle.dbg.json +4 -0
- package/build/artifacts/contracts/oracles/PendleRedStoneRateOracle.sol/PendleRedStoneRateOracle.json +66 -0
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/PendleSwapBase.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/PendleSwapL1.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/PendleSwapL1.json +2 -2
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/PendleSwapL2.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/PendleSwapL2.json +2 -2
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/interfaces/IExecutorHelper.sol/IExecutorHelper.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/interfaces/IExecutorHelper.sol/IExecutorHelper.json +168 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/interfaces/IExecutorHelperL2.sol/IExecutorHelperL2.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/interfaces/IExecutorHelperL2.sol/IExecutorHelperL2.json +378 -0
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l1-contracts/InputScalingHelper.sol/InputScalingHelper.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l1-contracts/InputScalingHelper.sol/InputScalingHelper.json +2 -2
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l1-contracts/ScalingDataLib.sol/ScalingDataLib.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l1-contracts/ScalingDataLib.sol/ScalingDataLib.json +2 -2
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l2-contracts/CalldataReader.sol/CalldataReader.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l2-contracts/CalldataReader.sol/CalldataReader.json +2 -2
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l2-contracts/CalldataWriter.sol/CalldataWriter.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l2-contracts/CalldataWriter.sol/CalldataWriter.json +2 -2
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l2-contracts/Common.sol/Common.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l2-contracts/Common.sol/Common.json +2 -2
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l2-contracts/DexScaler.sol/DexScaler.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l2-contracts/DexScaler.sol/DexScaler.json +2 -2
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l2-contracts/ExecutorReader.sol/ExecutorReader.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l2-contracts/ExecutorReader.sol/ExecutorReader.json +2 -2
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l2-contracts/InputScalingHelperL2.sol/InputScalingHelperL2.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l2-contracts/InputScalingHelperL2.sol/InputScalingHelperL2.json +2 -2
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l2-contracts/ScalingDataL2Lib.sol/ScalingDataL2Lib.dbg.json +1 -1
- package/build/artifacts/contracts/router/swap-aggregator/kyberswap/l2-contracts/ScalingDataL2Lib.sol/ScalingDataL2Lib.json +2 -2
- package/contracts/core/StandardizedYield/implementations/AaveV3/PendleAaveV3SY.sol +1 -1
- package/contracts/core/StandardizedYield/implementations/EtherFi/PendleWEEthSY.sol +1 -1
- package/contracts/core/StandardizedYield/implementations/KelpDAO/PendleRsETHSY.sol +18 -9
- package/contracts/core/StandardizedYield/implementations/PendleL2LRTSY.sol +93 -0
- package/contracts/core/StandardizedYield/implementations/Renzo/PendleEzETHSY.sol +139 -0
- package/contracts/core/StandardizedYield/implementations/Swell/PendleRswETHSY.sol +101 -0
- package/contracts/core/StandardizedYield/implementations/Swell/PendleSwETH.sol +1 -1
- package/contracts/interfaces/IPActionMarketCoreStatic.sol +8 -17
- package/contracts/interfaces/IPActionMintRedeemStatic.sol +4 -16
- package/contracts/interfaces/IPActionStorageStatic.sol +0 -4
- package/contracts/interfaces/Renzo/IRenzoOracle.sol +8 -0
- package/contracts/interfaces/Renzo/IRenzoRestakeManager.sol +14 -0
- package/contracts/interfaces/Swell/IRswETH.sol +10 -0
- package/contracts/interfaces/{ISwETH.sol → Swell/ISwETH.sol} +2 -2
- package/contracts/offchain-helpers/router-static/PendleRouterStatic.sol +19 -0
- package/contracts/offchain-helpers/router-static/base/ActionInfoStatic.sol +109 -0
- package/contracts/offchain-helpers/router-static/base/ActionMarketAuxStatic.sol +182 -0
- package/contracts/offchain-helpers/router-static/base/ActionMarketCoreStatic.sol +672 -0
- package/contracts/offchain-helpers/router-static/base/ActionMintRedeemStatic.sol +116 -0
- package/contracts/offchain-helpers/router-static/base/ActionStorageStatic.sol +64 -0
- package/contracts/offchain-helpers/router-static/base/ActionVePendleStatic.sol +55 -0
- package/contracts/offchain-helpers/router-static/base/StorageLayout.sol +20 -0
- package/contracts/oracles/PendleRedStoneRateOracle.sol +23 -0
- package/contracts/router/swap-aggregator/kyberswap/interfaces/IExecutorHelper.sol +58 -1
- package/contracts/router/swap-aggregator/kyberswap/interfaces/IExecutorHelperL2.sol +107 -1
- package/contracts/router/swap-aggregator/kyberswap/l1-contracts/InputScalingHelper.sol +14 -0
- package/contracts/router/swap-aggregator/kyberswap/l1-contracts/ScalingDataLib.sol +32 -0
- package/contracts/router/swap-aggregator/kyberswap/l2-contracts/CalldataReader.sol +6 -0
- package/contracts/router/swap-aggregator/kyberswap/l2-contracts/DexScaler.sol +59 -2
- package/contracts/router/swap-aggregator/kyberswap/l2-contracts/InputScalingHelperL2.sol +22 -1
- package/contracts/router/swap-aggregator/kyberswap/l2-contracts/ScalingDataL2Lib.sol +24 -0
- package/deployments/1-core.json +1 -1
- package/deployments/1-markets/EZETH-JUNE2024.json +11 -0
- package/deployments/1-markets/RSETH-KELP-JUNE2024.json +11 -0
- package/deployments/10-core.json +1 -1
- package/deployments/42161-core.json +1 -1
- package/deployments/42161-markets/RSETH-APR2024-ARBITRUM.json +11 -0
- package/deployments/42161-markets/WEETH-APR2024.json +11 -0
- package/deployments/56-core.json +1 -1
- package/deployments/merkle-distribution/2024-01-25.json +9615 -0
- package/package.json +1 -1
- package/typechain-types/IExecutorHelper.ts +273 -0
- package/typechain-types/IExecutorHelperL2.ts +455 -0
- package/typechain-types/IPActionMarketCoreStatic.ts +18 -63
- package/typechain-types/IPActionMintRedeemStatic.ts +10 -102
- package/typechain-types/IPActionStorageStatic.ts +0 -55
- package/typechain-types/IPRouterStatic.ts +28 -220
- package/typechain-types/IRenzoOracle.ts +152 -0
- package/typechain-types/IRenzoRestakeManager.ts +219 -0
- package/typechain-types/IRswETH.ts +138 -0
- package/typechain-types/ISwETH.ts +24 -9
- package/typechain-types/PendleEzETHSY.ts +1471 -0
- package/typechain-types/PendleL2LRTSY.ts +1323 -0
- package/typechain-types/PendleRedStoneRateOracle.ts +113 -0
- package/typechain-types/PendleRsETHSY.ts +21 -0
- package/typechain-types/PendleRswETHSY.ts +1294 -0
- 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/ActionStorageStatic__factory.ts +1 -1
- package/typechain-types/factories/ActionVePendleStatic__factory.ts +1 -1
- package/typechain-types/factories/IExecutorHelperL2__factory.ts +378 -0
- package/typechain-types/factories/IExecutorHelper__factory.ts +168 -0
- package/typechain-types/factories/IPActionMarketCoreStatic__factory.ts +0 -45
- package/typechain-types/factories/IPActionMintRedeemStatic__factory.ts +0 -69
- package/typechain-types/factories/IPActionStorageStatic__factory.ts +0 -26
- package/typechain-types/factories/IPRouterStatic__factory.ts +0 -140
- package/typechain-types/factories/IRenzoOracle__factory.ts +76 -0
- package/typechain-types/factories/IRenzoRestakeManager__factory.ts +121 -0
- package/typechain-types/factories/IRswETH__factory.ts +56 -0
- package/typechain-types/factories/ISwETH__factory.ts +7 -7
- package/typechain-types/factories/PendleAaveV3SY__factory.ts +1 -1
- package/typechain-types/factories/PendleEzETHSY__factory.ts +1218 -0
- package/typechain-types/factories/PendleL2LRTSY__factory.ts +1139 -0
- package/typechain-types/factories/PendleRedStoneRateOracle__factory.ts +142 -0
- package/typechain-types/factories/PendleRouterStatic__factory.ts +1 -1
- package/typechain-types/factories/PendleRsETHSY__factory.ts +23 -1
- package/typechain-types/factories/PendleRswETHSY__factory.ts +1117 -0
- package/typechain-types/factories/PendleSwapL1__factory.ts +1 -1
- package/typechain-types/factories/PendleSwapL2__factory.ts +1 -1
- package/typechain-types/factories/PendleWEEthSY__factory.ts +1 -1
- package/typechain-types/factories/SwETHSY__factory.ts +1 -1
- package/typechain-types/hardhat.d.ts +135 -0
- package/typechain-types/index.ts +28 -0
- package/build/artifacts/contracts/interfaces/ISwETH.sol/ISwETH.dbg.json +0 -4
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity ^0.8.17;
|
|
3
|
+
|
|
4
|
+
import "../../../interfaces/IPRouterStatic.sol";
|
|
5
|
+
import "./StorageLayout.sol";
|
|
6
|
+
|
|
7
|
+
contract ActionMintRedeemStatic is StorageLayout, IPActionMintRedeemStatic {
|
|
8
|
+
using PMath for uint256;
|
|
9
|
+
|
|
10
|
+
function mintPyFromSyStatic(address YT, uint256 netSyToMint) public view returns (uint256 netPYOut) {
|
|
11
|
+
if (IPYieldToken(YT).isExpired()) revert Errors.YCExpired();
|
|
12
|
+
return netSyToMint.mulDown(pyIndexCurrentViewYt(YT));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function redeemPyToSyStatic(address YT, uint256 netPYToRedeem) public view returns (uint256 netSyOut) {
|
|
16
|
+
return netPYToRedeem.divDown(pyIndexCurrentViewYt(YT));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function mintPyFromTokenStatic(
|
|
20
|
+
address YT,
|
|
21
|
+
address tokenIn,
|
|
22
|
+
uint256 netTokenIn
|
|
23
|
+
) external view returns (uint256 netPyOut) {
|
|
24
|
+
address SY = IPYieldToken(YT).SY();
|
|
25
|
+
uint256 netSyReceived = mintSyFromTokenStatic(SY, tokenIn, netTokenIn);
|
|
26
|
+
netPyOut = mintPyFromSyStatic(YT, netSyReceived);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function redeemPyToTokenStatic(
|
|
30
|
+
address YT,
|
|
31
|
+
uint256 netPYToRedeem,
|
|
32
|
+
address tokenOut
|
|
33
|
+
) external view returns (uint256 netTokenOut) {
|
|
34
|
+
address SY = IPYieldToken(YT).SY();
|
|
35
|
+
uint256 netSyReceived = redeemPyToSyStatic(YT, netPYToRedeem);
|
|
36
|
+
netTokenOut = redeemSyToTokenStatic(SY, tokenOut, netSyReceived);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function mintSyFromTokenStatic(
|
|
40
|
+
address SY,
|
|
41
|
+
address tokenIn,
|
|
42
|
+
uint256 netTokenIn
|
|
43
|
+
) public view returns (uint256 netSyOut) {
|
|
44
|
+
return IStandardizedYield(SY).previewDeposit(tokenIn, netTokenIn);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function redeemSyToTokenStatic(
|
|
48
|
+
address SY,
|
|
49
|
+
address tokenOut,
|
|
50
|
+
uint256 netSyIn
|
|
51
|
+
) public view returns (uint256 netTokenOut) {
|
|
52
|
+
return IStandardizedYield(SY).previewRedeem(tokenOut, netSyIn);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function getAmountTokenToMintSy(
|
|
56
|
+
address SY,
|
|
57
|
+
address tokenIn,
|
|
58
|
+
uint256 netSyOut
|
|
59
|
+
) external view returns (uint256 netTokenIn) {
|
|
60
|
+
uint256 pivotAmount;
|
|
61
|
+
|
|
62
|
+
if (tokenIn == address(0)) pivotAmount = 1e18;
|
|
63
|
+
else pivotAmount = 10 ** IStandardizedYield(SY).decimals();
|
|
64
|
+
|
|
65
|
+
uint256 low = pivotAmount;
|
|
66
|
+
{
|
|
67
|
+
while (true) {
|
|
68
|
+
uint256 lowSyOut = mintSyFromTokenStatic(SY, tokenIn, low);
|
|
69
|
+
if (lowSyOut >= netSyOut) low /= 10;
|
|
70
|
+
else break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
uint256 high = pivotAmount;
|
|
75
|
+
{
|
|
76
|
+
while (true) {
|
|
77
|
+
uint256 highSyOut = mintSyFromTokenStatic(SY, tokenIn, high);
|
|
78
|
+
if (highSyOut < netSyOut) high *= 10;
|
|
79
|
+
else break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
while (low <= high) {
|
|
84
|
+
uint256 mid = (low + high) / 2;
|
|
85
|
+
uint256 syOut = mintSyFromTokenStatic(SY, tokenIn, mid);
|
|
86
|
+
|
|
87
|
+
if (syOut >= netSyOut) {
|
|
88
|
+
netTokenIn = mid;
|
|
89
|
+
high = mid - 1;
|
|
90
|
+
} else {
|
|
91
|
+
low = mid + 1;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
assert(netTokenIn > 0);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function pyIndexCurrentViewMarket(address market) public view returns (uint256) {
|
|
99
|
+
(, , IPYieldToken YT) = IPMarket(market).readTokens();
|
|
100
|
+
return pyIndexCurrentViewYt(address(YT));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function pyIndexCurrentViewYt(address yt) public view returns (uint256) {
|
|
104
|
+
IPYieldToken YT = IPYieldToken(yt);
|
|
105
|
+
IStandardizedYield SY = IStandardizedYield(YT.SY());
|
|
106
|
+
|
|
107
|
+
uint256 syIndex = SY.exchangeRate();
|
|
108
|
+
uint256 pyIndexStored = YT.pyIndexStored();
|
|
109
|
+
|
|
110
|
+
if (YT.doCacheIndexSameBlock() && YT.pyIndexLastUpdatedBlock() == block.number) {
|
|
111
|
+
return pyIndexStored;
|
|
112
|
+
} else {
|
|
113
|
+
return PMath.max(syIndex, pyIndexStored);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity ^0.8.17;
|
|
3
|
+
|
|
4
|
+
import "./StorageLayout.sol";
|
|
5
|
+
import "../../../interfaces/IPActionStorageStatic.sol";
|
|
6
|
+
import "../../../interfaces/IPMiniDiamond.sol";
|
|
7
|
+
|
|
8
|
+
contract ActionStorageStatic is StorageLayout, IPActionStorageStatic, IPMiniDiamond {
|
|
9
|
+
function setDefaultApproxParams(ApproxParams memory params) external onlyOwner {
|
|
10
|
+
defaultApproxParams = params;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getDefaultApproxParams() external view returns (ApproxParams memory) {
|
|
14
|
+
return defaultApproxParams;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getOwnerAndPendingOwner() external view returns (address _owner, address _pendingOwner) {
|
|
18
|
+
_owner = owner;
|
|
19
|
+
_pendingOwner = pendingOwner;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function setFacetForSelectors(SelectorsToFacet[] calldata arr) external onlyOwner {
|
|
23
|
+
for (uint256 i = 0; i < arr.length; ) {
|
|
24
|
+
SelectorsToFacet memory s = arr[i];
|
|
25
|
+
for (uint256 j = 0; j < s.selectors.length; ) {
|
|
26
|
+
selectorToFacet[s.selectors[j]] = s.facet;
|
|
27
|
+
unchecked {
|
|
28
|
+
j++;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
unchecked {
|
|
32
|
+
i++;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function facetAddress(bytes4 selector) external view returns (address res) {
|
|
38
|
+
res = selectorToFacet[selector];
|
|
39
|
+
require(res != address(0), "selector not found");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Ownable
|
|
43
|
+
function transferOwnership(address newOwner, bool direct, bool renounce) external onlyOwner {
|
|
44
|
+
if (direct) {
|
|
45
|
+
require(newOwner != address(0) || renounce, "Ownable: zero address");
|
|
46
|
+
|
|
47
|
+
emit OwnershipTransferred(owner, newOwner);
|
|
48
|
+
owner = newOwner;
|
|
49
|
+
pendingOwner = address(0);
|
|
50
|
+
} else {
|
|
51
|
+
pendingOwner = newOwner;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function claimOwnership() external {
|
|
56
|
+
address _pendingOwner = pendingOwner;
|
|
57
|
+
|
|
58
|
+
require(msg.sender == _pendingOwner, "Ownable: caller != pending owner");
|
|
59
|
+
|
|
60
|
+
emit OwnershipTransferred(owner, _pendingOwner);
|
|
61
|
+
owner = _pendingOwner;
|
|
62
|
+
pendingOwner = address(0);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity ^0.8.17;
|
|
3
|
+
|
|
4
|
+
import "../../../core/libraries/MiniHelpers.sol";
|
|
5
|
+
import "../../../interfaces/IPRouterStatic.sol";
|
|
6
|
+
import "../../../interfaces/IPVotingEscrowMainchain.sol";
|
|
7
|
+
import "../../../LiquidityMining/libraries/VeBalanceLib.sol";
|
|
8
|
+
|
|
9
|
+
contract ActionVePendleStatic is IPActionVePendleStatic {
|
|
10
|
+
using VeBalanceLib for VeBalance;
|
|
11
|
+
using VeBalanceLib for LockedPosition;
|
|
12
|
+
|
|
13
|
+
uint128 private constant MAX_LOCK_TIME = 104 weeks;
|
|
14
|
+
uint128 private constant MIN_LOCK_TIME = 1 weeks;
|
|
15
|
+
|
|
16
|
+
IPVotingEscrowMainchain private immutable vePENDLE;
|
|
17
|
+
|
|
18
|
+
constructor(IPVotingEscrowMainchain _vePENDLE) {
|
|
19
|
+
vePENDLE = _vePENDLE;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function increaseLockPositionStatic(
|
|
23
|
+
address user,
|
|
24
|
+
uint128 additionalAmountToLock,
|
|
25
|
+
uint128 newExpiry
|
|
26
|
+
) external view returns (uint128 newVeBalance) {
|
|
27
|
+
if (!WeekMath.isValidWTime(newExpiry)) revert Errors.InvalidWTime(newExpiry);
|
|
28
|
+
if (MiniHelpers.isTimeInThePast(newExpiry)) revert Errors.ExpiryInThePast(newExpiry);
|
|
29
|
+
|
|
30
|
+
if (newExpiry > block.timestamp + MAX_LOCK_TIME) revert Errors.VEExceededMaxLockTime();
|
|
31
|
+
if (newExpiry < block.timestamp + MIN_LOCK_TIME) revert Errors.VEInsufficientLockTime();
|
|
32
|
+
|
|
33
|
+
LockedPosition memory oldPosition;
|
|
34
|
+
|
|
35
|
+
{
|
|
36
|
+
(uint128 amount, uint128 expiry) = vePENDLE.positionData(user);
|
|
37
|
+
oldPosition = LockedPosition(amount, expiry);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (newExpiry < oldPosition.expiry) revert Errors.VENotAllowedReduceExpiry();
|
|
41
|
+
|
|
42
|
+
uint128 newTotalAmountLocked = additionalAmountToLock + oldPosition.amount;
|
|
43
|
+
if (newTotalAmountLocked == 0) revert Errors.VEZeroAmountLocked();
|
|
44
|
+
|
|
45
|
+
uint128 additionalDurationToLock = newExpiry - oldPosition.expiry;
|
|
46
|
+
|
|
47
|
+
LockedPosition memory newPosition = LockedPosition(
|
|
48
|
+
oldPosition.amount + additionalAmountToLock,
|
|
49
|
+
oldPosition.expiry + additionalDurationToLock
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
VeBalance memory newBalance = newPosition.convertToVeBalance();
|
|
53
|
+
return newBalance.getCurrentValue();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity ^0.8.17;
|
|
3
|
+
|
|
4
|
+
import "../../../router/base/MarketApproxLib.sol";
|
|
5
|
+
|
|
6
|
+
abstract contract StorageLayout {
|
|
7
|
+
address internal owner;
|
|
8
|
+
address internal pendingOwner;
|
|
9
|
+
|
|
10
|
+
mapping(bytes4 => address) internal selectorToFacet;
|
|
11
|
+
|
|
12
|
+
ApproxParams internal defaultApproxParams;
|
|
13
|
+
|
|
14
|
+
address internal _deprecated_bulkSellerFactory;
|
|
15
|
+
|
|
16
|
+
modifier onlyOwner() {
|
|
17
|
+
require(msg.sender == owner, "Ownable: caller is not the owner");
|
|
18
|
+
_;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.17;
|
|
3
|
+
|
|
4
|
+
import "../core/libraries/math/PMath.sol";
|
|
5
|
+
import "../interfaces/IPExchangeRateOracle.sol";
|
|
6
|
+
import {AggregatorV3Interface as IChainlinkAggregator} from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol";
|
|
7
|
+
|
|
8
|
+
contract PendleRedStoneRateOracle is IPExchangeRateOracle {
|
|
9
|
+
using PMath for int256;
|
|
10
|
+
|
|
11
|
+
address public immutable oracle;
|
|
12
|
+
uint8 public immutable decimals;
|
|
13
|
+
|
|
14
|
+
constructor(address _redStoneOracle, uint8 _decimals) {
|
|
15
|
+
oracle = _redStoneOracle;
|
|
16
|
+
decimals = _decimals;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getExchangeRate() external view returns (uint256) {
|
|
20
|
+
(, int256 answer, , , ) = IChainlinkAggregator(oracle).latestRoundData();
|
|
21
|
+
return (answer.Uint() * 10 ** decimals) / 10 ** IChainlinkAggregator(oracle).decimals();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -212,9 +212,12 @@ interface IExecutorHelper {
|
|
|
212
212
|
|
|
213
213
|
struct VelocoreV2 {
|
|
214
214
|
address vault;
|
|
215
|
+
uint256 amount;
|
|
215
216
|
address tokenIn;
|
|
216
217
|
address tokenOut;
|
|
217
|
-
|
|
218
|
+
address stablePool; // if not empty then use stable pool
|
|
219
|
+
address wrapToken;
|
|
220
|
+
bool isConvertFirst;
|
|
218
221
|
}
|
|
219
222
|
|
|
220
223
|
struct MaticMigrate {
|
|
@@ -232,6 +235,46 @@ interface IExecutorHelper {
|
|
|
232
235
|
address toToken;
|
|
233
236
|
}
|
|
234
237
|
|
|
238
|
+
struct BalancerV1 {
|
|
239
|
+
address pool;
|
|
240
|
+
address tokenIn;
|
|
241
|
+
address tokenOut;
|
|
242
|
+
uint256 amount;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
struct SwaapV2 {
|
|
246
|
+
address router;
|
|
247
|
+
uint256 amount;
|
|
248
|
+
bytes data;
|
|
249
|
+
address tokenIn;
|
|
250
|
+
address tokenOut;
|
|
251
|
+
address recipient;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
struct ArbswapStable {
|
|
255
|
+
address pool;
|
|
256
|
+
uint256 dx;
|
|
257
|
+
uint256 tokenIndexFrom;
|
|
258
|
+
address tokenIn;
|
|
259
|
+
address tokenOut;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
struct BancorV2 {
|
|
263
|
+
address pool;
|
|
264
|
+
address[] swapPath;
|
|
265
|
+
uint256 amount;
|
|
266
|
+
address recipient;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
struct Ambient {
|
|
270
|
+
address pool;
|
|
271
|
+
uint128 qty;
|
|
272
|
+
address base;
|
|
273
|
+
address quote;
|
|
274
|
+
uint256 poolIdx;
|
|
275
|
+
uint8 settleFlags;
|
|
276
|
+
}
|
|
277
|
+
|
|
235
278
|
function executeUniswap(bytes memory data, uint256 flagsAndPrevAmountOut) external payable returns (uint256);
|
|
236
279
|
|
|
237
280
|
function executeStableSwap(bytes memory data, uint256 flagsAndPrevAmountOut) external payable returns (uint256);
|
|
@@ -311,4 +354,18 @@ interface IExecutorHelper {
|
|
|
311
354
|
function executeSolidlyV2(bytes memory data, uint256 flagsAndPrevAmountOut) external payable returns (uint256);
|
|
312
355
|
|
|
313
356
|
function executeKokonut(bytes memory data, uint256 flagsAndPrevAmountOut) external payable returns (uint256);
|
|
357
|
+
|
|
358
|
+
function executeBalancerV1(bytes memory data, uint256 flagsAndPrevAmountOut) external payable returns (uint256);
|
|
359
|
+
|
|
360
|
+
function executeSwaapV2(bytes memory data, uint256 flagsAndPrevAmountOut) external payable returns (uint256);
|
|
361
|
+
|
|
362
|
+
function executeNomiswapStable(bytes memory data, uint256 flagsAndPrevAmountOut) external payable returns (uint256);
|
|
363
|
+
|
|
364
|
+
function executeArbswapStable(bytes memory data, uint256 flagsAndPrevAmountOut) external payable returns (uint256);
|
|
365
|
+
|
|
366
|
+
function executeBancorV2(bytes memory data, uint256 flagsAndPrevAmountOut) external payable returns (uint256);
|
|
367
|
+
|
|
368
|
+
function executeBancorV3(bytes memory data, uint256 flagsAndPrevAmountOut) external payable returns (uint256);
|
|
369
|
+
|
|
370
|
+
function executeAmbient(bytes memory data, uint256 flagsAndPrevAmountOut) external payable returns (uint256);
|
|
314
371
|
}
|
|
@@ -232,9 +232,12 @@ interface IExecutorHelperL2 {
|
|
|
232
232
|
|
|
233
233
|
struct VelocoreV2 {
|
|
234
234
|
address vault;
|
|
235
|
+
uint256 amount;
|
|
235
236
|
address tokenIn;
|
|
236
237
|
address tokenOut;
|
|
237
|
-
|
|
238
|
+
address stablePool; // if not empty then use stable pool
|
|
239
|
+
address wrapToken;
|
|
240
|
+
bool isConvertFirst;
|
|
238
241
|
}
|
|
239
242
|
|
|
240
243
|
struct MaticMigrate {
|
|
@@ -252,6 +255,46 @@ interface IExecutorHelperL2 {
|
|
|
252
255
|
address toToken;
|
|
253
256
|
}
|
|
254
257
|
|
|
258
|
+
struct BalancerV1 {
|
|
259
|
+
address pool;
|
|
260
|
+
uint256 amount;
|
|
261
|
+
address tokenIn;
|
|
262
|
+
address tokenOut;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
struct SwaapV2 {
|
|
266
|
+
address router;
|
|
267
|
+
uint256 amount;
|
|
268
|
+
bytes data;
|
|
269
|
+
address tokenIn;
|
|
270
|
+
address tokenOut;
|
|
271
|
+
address recipient;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
struct ArbswapStable {
|
|
275
|
+
address pool;
|
|
276
|
+
uint256 dx;
|
|
277
|
+
uint256 tokenIndexFrom;
|
|
278
|
+
address tokenIn;
|
|
279
|
+
address tokenOut;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
struct BancorV2 {
|
|
283
|
+
address pool;
|
|
284
|
+
address[] swapPath;
|
|
285
|
+
uint256 amount;
|
|
286
|
+
address recipient;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
struct Ambient {
|
|
290
|
+
address pool;
|
|
291
|
+
uint128 qty;
|
|
292
|
+
address base;
|
|
293
|
+
address quote;
|
|
294
|
+
uint256 poolIdx;
|
|
295
|
+
uint8 settleFlags;
|
|
296
|
+
}
|
|
297
|
+
|
|
255
298
|
function executeUniswap(
|
|
256
299
|
uint256 index,
|
|
257
300
|
bytes memory data,
|
|
@@ -557,4 +600,67 @@ interface IExecutorHelperL2 {
|
|
|
557
600
|
bool getPoolOnly,
|
|
558
601
|
address nextPool
|
|
559
602
|
) external payable returns (address tokenOut, uint256 tokenAmountOut, address pool);
|
|
603
|
+
|
|
604
|
+
function executeBalancerV1(
|
|
605
|
+
uint256 index,
|
|
606
|
+
bytes memory data,
|
|
607
|
+
uint256 previousAmountOut,
|
|
608
|
+
address tokenIn,
|
|
609
|
+
bool getPoolOnly,
|
|
610
|
+
address nextPool
|
|
611
|
+
) external payable returns (address tokenOut, uint256 tokenAmountOut, address pool);
|
|
612
|
+
|
|
613
|
+
function executeSwaapV2(
|
|
614
|
+
uint256 index,
|
|
615
|
+
bytes memory data,
|
|
616
|
+
uint256 previousAmountOut,
|
|
617
|
+
address tokenIn,
|
|
618
|
+
bool getPoolOnly,
|
|
619
|
+
address nextPool
|
|
620
|
+
) external payable returns (address tokenOut, uint256 tokenAmountOut, address pool);
|
|
621
|
+
|
|
622
|
+
function executeNomiswapStable(
|
|
623
|
+
uint256 index,
|
|
624
|
+
bytes memory data,
|
|
625
|
+
uint256 previousAmountOut,
|
|
626
|
+
address tokenIn,
|
|
627
|
+
bool getPoolOnly,
|
|
628
|
+
address nextPool
|
|
629
|
+
) external payable returns (address tokenOut, uint256 tokenAmountOut, address pool);
|
|
630
|
+
|
|
631
|
+
function executeArbswapStable(
|
|
632
|
+
uint256 index,
|
|
633
|
+
bytes memory data,
|
|
634
|
+
uint256 previousAmountOut,
|
|
635
|
+
address tokenIn,
|
|
636
|
+
bool getPoolOnly,
|
|
637
|
+
address nextPool
|
|
638
|
+
) external payable returns (address tokenOut, uint256 tokenAmountOut, address pool);
|
|
639
|
+
|
|
640
|
+
function executeBancorV2(
|
|
641
|
+
uint256 index,
|
|
642
|
+
bytes memory data,
|
|
643
|
+
uint256 previousAmountOut,
|
|
644
|
+
address tokenIn,
|
|
645
|
+
bool getPoolOnly,
|
|
646
|
+
address nextPool
|
|
647
|
+
) external payable returns (address tokenOut, uint256 tokenAmountOut, address pool);
|
|
648
|
+
|
|
649
|
+
function executeBancorV3(
|
|
650
|
+
uint256 index,
|
|
651
|
+
bytes memory data,
|
|
652
|
+
uint256 previousAmountOut,
|
|
653
|
+
address tokenIn,
|
|
654
|
+
bool getPoolOnly,
|
|
655
|
+
address nextPool
|
|
656
|
+
) external payable returns (address tokenOut, uint256 tokenAmountOut, address pool);
|
|
657
|
+
|
|
658
|
+
function executeAmbient(
|
|
659
|
+
uint256 index,
|
|
660
|
+
bytes memory data,
|
|
661
|
+
uint256 previousAmountOut,
|
|
662
|
+
address tokenIn,
|
|
663
|
+
bool getPoolOnly,
|
|
664
|
+
address nextPool
|
|
665
|
+
) external payable returns (address tokenOut, uint256 tokenAmountOut, address pool);
|
|
560
666
|
}
|
|
@@ -248,6 +248,20 @@ library InputScalingHelper {
|
|
|
248
248
|
swap.data = ScalingDataLib.newMantis(swap.data, oldAmount, newAmount); // @dev using Mantis struct because Solidly V2 and Mantis have same fields
|
|
249
249
|
} else if (functionSelector == IExecutorHelper.executeKokonut.selector) {
|
|
250
250
|
swap.data = ScalingDataLib.newKokonut(swap.data, oldAmount, newAmount);
|
|
251
|
+
} else if (functionSelector == IExecutorHelper.executeBalancerV1.selector) {
|
|
252
|
+
swap.data = ScalingDataLib.newBalancerV1(swap.data, oldAmount, newAmount);
|
|
253
|
+
} else if (functionSelector == IExecutorHelper.executeSwaapV2.selector) {
|
|
254
|
+
revert("InputScalingHelper: Can not scale SwaapV2 swap");
|
|
255
|
+
} else if (functionSelector == IExecutorHelper.executeNomiswapStable.selector) {
|
|
256
|
+
swap.data = ScalingDataLib.newMantis(swap.data, oldAmount, newAmount); // @dev using Mantis struct because NomiswapV2 and Mantis have same fields
|
|
257
|
+
} else if (functionSelector == IExecutorHelper.executeArbswapStable.selector) {
|
|
258
|
+
swap.data = ScalingDataLib.newArbswapStable(swap.data, oldAmount, newAmount);
|
|
259
|
+
} else if (functionSelector == IExecutorHelper.executeBancorV2.selector) {
|
|
260
|
+
swap.data = ScalingDataLib.newBancorV2(swap.data, oldAmount, newAmount);
|
|
261
|
+
} else if (functionSelector == IExecutorHelper.executeBancorV3.selector) {
|
|
262
|
+
swap.data = ScalingDataLib.newMantis(swap.data, oldAmount, newAmount); // @dev using Mantis struct because Bancor V3 and Mantis have same fields
|
|
263
|
+
} else if (functionSelector == IExecutorHelper.executeAmbient.selector) {
|
|
264
|
+
swap.data = ScalingDataLib.newAmbient(swap.data, oldAmount, newAmount);
|
|
251
265
|
} else {
|
|
252
266
|
revert("AggregationExecutor: Dex type not supported");
|
|
253
267
|
}
|
|
@@ -241,4 +241,36 @@ library ScalingDataLib {
|
|
|
241
241
|
kokonut.dx = (kokonut.dx * newAmount) / oldAmount;
|
|
242
242
|
return abi.encode(kokonut);
|
|
243
243
|
}
|
|
244
|
+
|
|
245
|
+
function newBalancerV1(
|
|
246
|
+
bytes memory data,
|
|
247
|
+
uint256 oldAmount,
|
|
248
|
+
uint256 newAmount
|
|
249
|
+
) internal pure returns (bytes memory) {
|
|
250
|
+
IExecutorHelper.BalancerV1 memory balancerV1 = abi.decode(data, (IExecutorHelper.BalancerV1));
|
|
251
|
+
balancerV1.amount = (balancerV1.amount * newAmount) / oldAmount;
|
|
252
|
+
return abi.encode(balancerV1);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function newArbswapStable(
|
|
256
|
+
bytes memory data,
|
|
257
|
+
uint256 oldAmount,
|
|
258
|
+
uint256 newAmount
|
|
259
|
+
) internal pure returns (bytes memory) {
|
|
260
|
+
IExecutorHelper.ArbswapStable memory arbswapStable = abi.decode(data, (IExecutorHelper.ArbswapStable));
|
|
261
|
+
arbswapStable.dx = (arbswapStable.dx * newAmount) / oldAmount;
|
|
262
|
+
return abi.encode(arbswapStable);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function newBancorV2(bytes memory data, uint256 oldAmount, uint256 newAmount) internal pure returns (bytes memory) {
|
|
266
|
+
IExecutorHelper.BancorV2 memory bancorV2 = abi.decode(data, (IExecutorHelper.BancorV2));
|
|
267
|
+
bancorV2.amount = (bancorV2.amount * newAmount) / oldAmount;
|
|
268
|
+
return abi.encode(bancorV2);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function newAmbient(bytes memory data, uint256 oldAmount, uint256 newAmount) internal pure returns (bytes memory) {
|
|
272
|
+
IExecutorHelper.Ambient memory ambient = abi.decode(data, (IExecutorHelper.Ambient));
|
|
273
|
+
ambient.qty = uint128((uint256(ambient.qty) * newAmount) / oldAmount);
|
|
274
|
+
return abi.encode(ambient);
|
|
275
|
+
}
|
|
244
276
|
}
|
|
@@ -55,6 +55,12 @@ library CalldataReader {
|
|
|
55
55
|
return (uint32(bytes4(ret)), startByte);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
function _readUint128(bytes memory data, uint256 startByte) internal pure returns (uint128, uint256) {
|
|
59
|
+
bytes memory ret;
|
|
60
|
+
(ret, startByte) = _calldataVal(data, startByte, 16);
|
|
61
|
+
return (uint128(bytes16(ret)), startByte);
|
|
62
|
+
}
|
|
63
|
+
|
|
58
64
|
function _readUint160(bytes memory data, uint256 startByte) internal pure returns (uint160, uint256) {
|
|
59
65
|
bytes memory ret;
|
|
60
66
|
(ret, startByte) = _calldataVal(data, startByte, 20);
|
|
@@ -361,9 +361,8 @@ library DexScaler {
|
|
|
361
361
|
|
|
362
362
|
(, startByte) = data._readPool(startByte); // pool
|
|
363
363
|
|
|
364
|
-
(, startByte) = data._readAddress(startByte); // tokenOut
|
|
365
|
-
|
|
366
364
|
(uint256 amount, ) = data._readUint128AsUint256(startByte); // amount
|
|
365
|
+
|
|
367
366
|
return data.write16Bytes(startByte, oldAmount == 0 ? 0 : (amount * newAmount) / oldAmount, "scaleVelocoreV2");
|
|
368
367
|
}
|
|
369
368
|
|
|
@@ -379,4 +378,62 @@ library DexScaler {
|
|
|
379
378
|
(uint256 amount, ) = data._readUint128AsUint256(startByte); // amount
|
|
380
379
|
return data.write16Bytes(startByte, oldAmount == 0 ? 0 : (amount * newAmount) / oldAmount, "scaleKokonut");
|
|
381
380
|
}
|
|
381
|
+
|
|
382
|
+
function scaleBalancerV1(
|
|
383
|
+
bytes memory data,
|
|
384
|
+
uint256 oldAmount,
|
|
385
|
+
uint256 newAmount
|
|
386
|
+
) internal pure returns (bytes memory) {
|
|
387
|
+
uint256 startByte;
|
|
388
|
+
|
|
389
|
+
(, startByte) = data._readPool(startByte); // pool
|
|
390
|
+
|
|
391
|
+
(uint256 amount, ) = data._readUint128AsUint256(startByte); // amount
|
|
392
|
+
|
|
393
|
+
return data.write16Bytes(startByte, oldAmount == 0 ? 0 : (amount * newAmount) / oldAmount, "scaleBalancerV1");
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function scaleArbswapStable(
|
|
397
|
+
bytes memory data,
|
|
398
|
+
uint256 oldAmount,
|
|
399
|
+
uint256 newAmount
|
|
400
|
+
) internal pure returns (bytes memory) {
|
|
401
|
+
uint256 startByte;
|
|
402
|
+
|
|
403
|
+
(, startByte) = data._readPool(startByte); // pool
|
|
404
|
+
|
|
405
|
+
(uint256 dx, ) = data._readUint128AsUint256(startByte); // dx
|
|
406
|
+
|
|
407
|
+
return data.write16Bytes(startByte, oldAmount == 0 ? 0 : (dx * newAmount) / oldAmount, "scaleArbswapStable");
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function scaleBancorV2(
|
|
411
|
+
bytes memory data,
|
|
412
|
+
uint256 oldAmount,
|
|
413
|
+
uint256 newAmount
|
|
414
|
+
) internal pure returns (bytes memory) {
|
|
415
|
+
uint256 startByte;
|
|
416
|
+
|
|
417
|
+
(, startByte) = data._readPool(startByte); // pool
|
|
418
|
+
|
|
419
|
+
(, startByte) = data._readAddressArray(startByte); // swapPath
|
|
420
|
+
|
|
421
|
+
(uint256 amount, ) = data._readUint128AsUint256(startByte); // amount
|
|
422
|
+
|
|
423
|
+
return data.write16Bytes(startByte, oldAmount == 0 ? 0 : (amount * newAmount) / oldAmount, "scaleBancorV2");
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function scaleAmbient(
|
|
427
|
+
bytes memory data,
|
|
428
|
+
uint256 oldAmount,
|
|
429
|
+
uint256 newAmount
|
|
430
|
+
) internal pure returns (bytes memory) {
|
|
431
|
+
uint256 startByte;
|
|
432
|
+
|
|
433
|
+
(, startByte) = data._readPool(startByte); // pool
|
|
434
|
+
|
|
435
|
+
(uint128 qty, ) = data._readUint128(startByte); // amount
|
|
436
|
+
|
|
437
|
+
return data.write16Bytes(startByte, oldAmount == 0 ? 0 : (qty * newAmount) / oldAmount, "scaleAmbient");
|
|
438
|
+
}
|
|
382
439
|
}
|
|
@@ -62,7 +62,14 @@ library InputScalingHelperL2 {
|
|
|
62
62
|
VelocoreV2,
|
|
63
63
|
Smardex,
|
|
64
64
|
SolidlyV2,
|
|
65
|
-
Kokonut
|
|
65
|
+
Kokonut,
|
|
66
|
+
BalancerV1,
|
|
67
|
+
SwaapV2,
|
|
68
|
+
NomiswapStable,
|
|
69
|
+
ArbswapStable,
|
|
70
|
+
BancorV2,
|
|
71
|
+
BancorV3,
|
|
72
|
+
Ambient
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
function _getScaledInputData(bytes calldata inputData, uint256 newAmount) internal pure returns (bytes memory) {
|
|
@@ -317,6 +324,20 @@ library InputScalingHelperL2 {
|
|
|
317
324
|
swap.data = swap.data.newMantis(oldAmount, newAmount); // @dev use identical calldata structure as Mantis
|
|
318
325
|
} else if (DexIndex(functionSelectorIndex) == DexIndex.Kokonut) {
|
|
319
326
|
swap.data = swap.data.newKokonut(oldAmount, newAmount);
|
|
327
|
+
} else if (DexIndex(functionSelectorIndex) == DexIndex.BalancerV1) {
|
|
328
|
+
swap.data = swap.data.newBalancerV1(oldAmount, newAmount);
|
|
329
|
+
} else if (DexIndex(functionSelectorIndex) == DexIndex.SwaapV2) {
|
|
330
|
+
revert("InputScalingHelper: Can not scale SwaapV2 swap");
|
|
331
|
+
} else if (DexIndex(functionSelectorIndex) == DexIndex.NomiswapStable) {
|
|
332
|
+
swap.data = swap.data.newMantis(oldAmount, newAmount); // @dev use identical calldata structure as Mantis
|
|
333
|
+
} else if (DexIndex(functionSelectorIndex) == DexIndex.ArbswapStable) {
|
|
334
|
+
swap.data = swap.data.newArbswapStable(oldAmount, newAmount);
|
|
335
|
+
} else if (DexIndex(functionSelectorIndex) == DexIndex.BancorV2) {
|
|
336
|
+
swap.data = swap.data.newBancorV2(oldAmount, newAmount);
|
|
337
|
+
} else if (DexIndex(functionSelectorIndex) == DexIndex.BancorV3) {
|
|
338
|
+
swap.data = swap.data.newMantis(oldAmount, newAmount); // @dev use identical calldata structure as Mantis
|
|
339
|
+
} else if (DexIndex(functionSelectorIndex) == DexIndex.Ambient) {
|
|
340
|
+
swap.data = swap.data.newAmbient(oldAmount, newAmount);
|
|
320
341
|
} else {
|
|
321
342
|
revert("InputScaleHelper: Dex type not supported");
|
|
322
343
|
}
|