SettlerToken
Inherits: ERC20, ERC20Permit
Author: EridianAlpha
An ERC20 token called Ethereum Settler
(SETTLER).
State Variables
TOKEN_EMISSION_RATE
uint256 public constant TOKEN_EMISSION_RATE = 1e18;
SETTLEMENT_NFT
SettlementNft public immutable SETTLEMENT_NFT;
s_mintedTokensFromNft
mapping(uint256 => uint256) public s_mintedTokensFromNft;
Functions
constructor
Constructor for the Settler Token contract to initialize the Settlement NFT address.
constructor(address _nftAddress) ERC20("Ethereum Settler", "SETTLER") ERC20Permit("Ethereum Settler");
Parameters
Name | Type | Description |
---|---|---|
_nftAddress | address | The address of the Settlement NFT contract. |
mintOutstandingTokensFromNft
Mint outstanding tokens for an account based on the Settler NFT held by that account.
Useful when an NFT is transferred as this function can be called before the NFT is transferred,
function mintOutstandingTokensFromNft(address account) external;
Parameters
Name | Type | Description |
---|---|---|
account | address | The account to mint tokens for. |
_mintOutstandingTokensFromNft
Internal function to mint outstanding tokens for an account based on the Settler NFT held by that account.
This function calculates the new tokens to mint and updates the state to reflect the minted tokens.
If the nftId
is zero, the function does nothing as there is no corresponding NFT for the account.
function _mintOutstandingTokensFromNft(address account) internal;
Parameters
Name | Type | Description |
---|---|---|
account | address | The account for which tokens are minted. |
_update
Override standard ERC20 _update
function.
Mints outstanding SETTLER tokens based on the Settler NFT held by the account,
then calls the parent _update
function to update the account balances.
function _update(address from, address to, uint256 value) internal override;
Parameters
Name | Type | Description |
---|---|---|
from | address | The account to transfer tokens from. |
to | address | |
value | uint256 |
balanceOf
Override standard ERC20 balanceOf
function.
If the account has an NFT, calculate the unminted balance based on the time since the NFT was minted.
function balanceOf(address account) public view override returns (uint256 accountBalance);
Parameters
Name | Type | Description |
---|---|---|
account | address | The account to get the balance of. |
Returns
Name | Type | Description |
---|---|---|
accountBalance | uint256 | The balance of the account as a sum of the minted and unminted tokens. |
_totalLifetimeTokensFromNft
Calculate the total lifetime tokens from an NFT based on the mint timestamp.
function _totalLifetimeTokensFromNft(uint256 _mintTimestamp) internal view returns (uint256 totalLifetimeTokens);
Parameters
Name | Type | Description |
---|---|---|
_mintTimestamp | uint256 | The timestamp when the NFT was minted. |
Returns
Name | Type | Description |
---|---|---|
totalLifetimeTokens | uint256 | The total lifetime tokens from the NFT. |
_calculateNewTokensToMint
Calculate the new tokens to mint for an account based on the Settler NFT held by the account.
function _calculateNewTokensToMint(address account)
internal
view
returns (uint256 nftId, uint256 totalLifetimeTokensFromNft, uint256 newTokensToMint);
Parameters
Name | Type | Description |
---|---|---|
account | address | The account to calculate the new tokens to mint for. |
Returns
Name | Type | Description |
---|---|---|
nftId | uint256 | The ID of the NFT held by the account. |
totalLifetimeTokensFromNft | uint256 | The total lifetime tokens from the NFT. |
newTokensToMint | uint256 | The new tokens to mint for the account. |