EccConfig.sol
Overview
The EccConfig.sol file defines the EccConfig smart contract, which manages a set of cryptographic token configurations identified by unique keys. Its primary purpose is to store and maintain EccData entries that represent tokens, facilitate minting of these tokens, and handle token transfers. The contract ensures sufficient balance for minting operations and enforces ownership-based access control for sensitive functions.
Key responsibilities include:
Maintaining a mapping of token keys to their corresponding data (
_data).Managing ownership to restrict certain operations.
Ensuring the contract has enough balance to perform token minting.
Adding new tokens with minting and optional transfer to a recipient.
Contract: EccConfig
State Variables
Variable | Type | Description |
|---|---|---|
|
| Holds the contract version identifier ( |
|
| Stores token data entries indexed by a unique key. |
|
| Address of the contract owner, set to contract itself. |
Inheritance
Inherits from
Modifierscontract, which provides access control utilities such assenderIs.
Constructor
constructor ()
Initializes the contract by setting the
_owneraddress to the contract's own address.
Functions
ensureBalance()
function ensureBalance() private pure
Purpose: Checks if the contract's balance exceeds a minimum threshold (
MIN_BALANCE), and if not, mints additional funds.Visibility:
privateBehavior:
Uses a conditional to verify balance.
Calls
gosh.mintshellq(MIN_BALANCE)if balance is insufficient.
Usage: Invoked internally before minting tokens to guarantee sufficient contract balance.
setNewToken()
function setNewToken(EccToken token, optional(address) to) public internalMsg senderIs(_owner)
Purpose: Registers a new token configuration and mints the specified amount of tokens.
Parameters:
token: AnEccTokenstruct containing the token details including the unique key and amount to mint.to(optional): An address to which the minted tokens should be transferred.
Visibility: Public but restricted by
internalMsgandsenderIs(_owner)modifier, limiting calls to the contract owner.Behavior:
Calls
ensureBalance()to maintain sufficient funds.Validates that the token key does not already exist in
_data.If
baseMinted(amount to mint) is not zero, it requires thetoparameter to be provided.Creates a new
EccDataentry with the token and current block timestamp.Stores this entry in
_data.Calls
gosh.minteccto mint the token amount.If
tois specified, transfers the minted tokens to that address with a small value transfer.
Errors:
Reverts if the token key already exists (
ERR_WRONG_KEY).Reverts if
tois missing when tokens are to be minted (ERR_NO_DATA).
Usage Example:
EccToken memory newToken = EccToken({
key: 1234,
baseMinted: 1000,
// other EccToken fields
});
address recipient = 0xabcdef...;
eccConfig.setNewToken(newToken, recipient);
getDetails()
function getDetails() external view returns(mapping(uint32 => EccData) data)
Purpose: Provides external read-only access to the entire
_datamapping.Visibility:
external viewReturns: The full mapping of token keys to their
EccData.Usage: Allows clients to query all stored token configurations and metadata.
Data Structures and Types
EccData: A struct presumably containing token-related data and a timestamp (not fully defined in this file).EccToken: A struct representing token details, including a unique key and minted amount.varuint32: A variable-sized 32-bit unsigned integer type used during transfer.optional(address): An optional address parameter that may or may not contain a value.
Implementation Details and Algorithms
Balance Management: The contract uses a private
ensureBalancemethod to verify and top up the contract's balance before minting tokens, preventing failed mint operations due to insufficient funds.Access Control: The
setNewTokenfunction is protected by thesenderIs(_owner)modifier ensuring only the owner (contract itself) can invoke it.Token Uniqueness: Before adding a new token, the contract checks if a token with the same key already exists to prevent duplicates.
Conditional Transfer: Tokens minted can optionally be transferred to a recipient address if specified, using the built-in transfer mechanism with a small value and currency data.
Interactions with Other System Components
Modifiers Contract: Inherits from
Modifiers, leveraging access control utilities likesenderIs.gosh Interface: Uses external functions
gosh.mintshellqandgosh.minteccfor minting native tokens and ECC tokens respectively.Token Transfer: Utilizes the
transfermethod on the recipient address with currency data to perform token transfers.Constants and Errors: Relies on constants like
MIN_BALANCEand error codesERR_WRONG_KEY,ERR_NO_DATAdefined elsewhere in the system.
Mermaid Class Diagram
classDiagram
class EccConfig {
-string version = "1.0.0"
-mapping(uint32 => EccData) _data
-address _owner
+constructor()
-ensureBalance()
+setNewToken(token: EccToken, to: optional(address))
+getDetails() returns(mapping)
}
EccConfig --|> Modifiers