-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathArrayCastLib.sol
54 lines (43 loc) · 1.68 KB
/
ArrayCastLib.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.23;
import { InitSingleVaultData, InitMultiVaultData, LiqRequest } from "src/types/DataTypes.sol";
/// @dev library to cast single values into array for streamlining helper functions
/// @notice not gas optimized, suggested for usage only in view/pure functions
library ArrayCastLib {
function castLiqRequestToArray(LiqRequest memory value_) internal pure returns (LiqRequest[] memory values) {
values = new LiqRequest[](1);
values[0] = value_;
}
function castBoolToArray(bool value_) internal pure returns (bool[] memory values) {
values = new bool[](1);
values[0] = value_;
}
function castToMultiVaultData(InitSingleVaultData memory data_)
internal
pure
returns (InitMultiVaultData memory castedData_)
{
uint256[] memory superformIds = new uint256[](1);
superformIds[0] = data_.superformId;
uint256[] memory amounts = new uint256[](1);
amounts[0] = data_.amount;
uint256[] memory outputAmounts = new uint256[](1);
outputAmounts[0] = data_.outputAmount;
uint256[] memory maxSlippage = new uint256[](1);
maxSlippage[0] = data_.maxSlippage;
LiqRequest[] memory liqData = new LiqRequest[](1);
liqData[0] = data_.liqData;
castedData_ = InitMultiVaultData(
data_.payloadId,
superformIds,
amounts,
outputAmounts,
maxSlippage,
liqData,
castBoolToArray(data_.hasDstSwap),
castBoolToArray(data_.retain4626),
data_.receiverAddress,
data_.extraFormData
);
}
}