-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathStaticConfig.sol
60 lines (54 loc) · 2.5 KB
/
StaticConfig.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
55
56
57
58
59
60
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
/// @title StaticConfig
/// @notice Library for encoding and decoding static configuration data.
library StaticConfig {
/// @notice Encodes the static configuration data for a gas paying token.
/// @param _token Address of the gas paying token.
/// @param _decimals Number of decimals for the gas paying token.
/// @param _name Name of the gas paying token.
/// @param _symbol Symbol of the gas paying token.
/// @return Encoded static configuration data.
function encodeGasPayingToken(
address _token,
uint8 _decimals,
bytes32 _name,
bytes32 _symbol
)
internal
pure
returns (bytes memory)
{
return abi.encode(_token, _decimals, name, symbol);
}
/// @notice Decodes the static configuration data for a gas paying token.
/// @param _data Encoded static configuration data.
/// @return Decoded gas paying token data (token address, decimals, name, symbol).
function decodeGasPayingToken(bytes memory _data) internal pure returns (address, uint8, bytes32, bytes32) {
return abi.decode(_data, (address, uint8, bytes32, bytes32));
}
/// @notice Encodes the static configuration data for adding a dependency.
/// @param _chainId Chain ID of the dependency to add.
/// @return Encoded static configuration data.
function encodeAddDependency(uint256 _chainId) internal pure returns (bytes memory) {
return abi.encode(_chainId);
}
/// @notice Decodes the static configuration data for adding a dependency.
/// @param _data Encoded static configuration data.
/// @return Decoded chain ID of the dependency to add.
function decodeAddDependency(bytes memory _data) internal pure returns (uint256) {
return abi.decode(_data, (uint256));
}
/// @notice Encodes the static configuration data for removing a dependency.
/// @param _chainId Chain ID of the dependency to remove.
/// @return Encoded static configuration data.
function encodeRemoveDependency(uint256 _chainId) internal pure returns (bytes memory) {
return abi.encode(_chainId);
}
/// @notice Decodes the static configuration data for removing a dependency.
/// @param _data Encoded static configuration data.
/// @return Decoded chain ID of the dependency to remove.
function decodeRemoveDependency(bytes memory _data) internal pure returns (uint256) {
return abi.decode(_data, (uint256));
}
}