Skip to content

Commit

Permalink
contracts-bedrock: create StaticConfig lib
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfuturistic committed May 20, 2024
1 parent 30f3027 commit 8a3681a
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions packages/contracts-bedrock/src/libraries/StaticConfig.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,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));
}
}

0 comments on commit 8a3681a

Please sign in to comment.