SettlerToken

Git Source

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

NameTypeDescription
_nftAddressaddressThe 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

NameTypeDescription
accountaddressThe 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

NameTypeDescription
accountaddressThe 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

NameTypeDescription
fromaddressThe account to transfer tokens from.
toaddress
valueuint256

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

NameTypeDescription
accountaddressThe account to get the balance of.

Returns

NameTypeDescription
accountBalanceuint256The 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

NameTypeDescription
_mintTimestampuint256The timestamp when the NFT was minted.

Returns

NameTypeDescription
totalLifetimeTokensuint256The 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

NameTypeDescription
accountaddressThe account to calculate the new tokens to mint for.

Returns

NameTypeDescription
nftIduint256The ID of the NFT held by the account.
totalLifetimeTokensFromNftuint256The total lifetime tokens from the NFT.
newTokensToMintuint256The new tokens to mint for the account.