eUSD

Overview

The eUSD contract is an interest-bearing ERC20-like token designed for the Lybra protocol. It represents the holder's share in the total amount of Ether controlled by the protocol. The contract stores the sum of all shares to calculate each account's token balance, which is based on the account's shares and the total supply of eUSD.

Contract Details

  • Name: eUSD

  • Symbol: eUSD

  • Decimals: 18

  • Total Supply: The total supply of eUSD tokens is equal to the total amount of eUSD controlled by the protocol.

  • Balances: Balances are dynamic and are calculated based on the account's shares and the total supply of eUSD.

eUSD balances are dynamic and are calculated based on the accounts' shares and the total supply by the protocol. Account shares aren't normalized, so the contract also stores the sum of all shares to calculate each account's token balance, which equals to:

shares[account] * _getTotalMintedEUSD() / _getTotalShares()

The _getTotalMintedEUSD() function returns the total amount of eUSD tokens minted by the protocol. The _getTotalShares() function returns the total amount of shares in existence.

For example, assume that we have:

  • _getTotalMintedEUSD() -> 1000 eUSD

  • sharesOf(user1) -> 100

  • sharesOf(user2) -> 400

Therefore:

  • balanceOf(user1) -> 2 tokens, which corresponds to 200 eUSD

  • balanceOf(user2) -> 8 tokens, which corresponds to 800 eUSD

Function Documentation

name()

function name() public pure returns (string memory)

Returns the name of the token.

symbol()

function symbol() public pure returns (string memory)

Returns the symbol of the token.

decimals()

function decimals() public pure returns (uint8)

Returns the number of decimals for getting user representation of a token amount.

totalSupply()

function totalSupply() public view returns (uint256)

Returns the total amount of eUSD in existence. This is always equal to the total minted eUSD since the token amount is pegged to the total amount of eUSD controlled by the protocol.

balanceOf(address _account)

function balanceOf(address _account) public view returns (uint256)

Returns the amount of eUSD tokens owned by the _account.

transfer(address _recipient, uint256 _amount)

function transfer(address _recipient, uint256 _amount) public returns (bool)

Transfers _amount eUSD tokens from the caller's account to the _recipient account. Returns a boolean value indicating whether the transfer was successful.

allowance(address _owner, address _spender)

function allowance(address _owner, address _spender) public view returns (uint256)

Returns the remaining number of tokens that _spender is allowed to spend on behalf of _owner through transferFrom.

approve(address _spender, uint256 _amount)

function approve(address _spender, uint256 _amount) public returns (bool)

Sets _amount as the allowance of _spender over the caller's tokens. Returns a boolean value indicating whether the approval was successful.

transferFrom(address _sender, address _recipient, uint256 _amount)

function transferFrom(address _sender, address _recipient, uint256 _amount) public returns (bool)

Moves _amount eUSD tokens from _sender to _recipient using the allowance mechanism. Returns a boolean value indicating whether the transfer was successful.

increaseAllowance(address _spender, uint256 _addedValue)

function increaseAllowance(address _spender, uint256 _addedValue) public returns (bool)

Atomically increases the allowance granted to _spender by the caller by _addedValue. Returns a boolean value indicating whether the operation was successful.

decreaseAllowance(address _spender, uint256 _subtractedValue)

function decreaseAllowance(address _spender, uint256 _subtractedValue) public returns (bool)

Atomically decreases the allowance granted to _spender by the caller by _subtractedValue. Returns a boolean value indicating whether the operation was successful.

getTotalShares()

function getTotalShares() public view returns (uint256)

Returns the total amount of shares in existence.

sharesOf(address _account)

function sharesOf(address _account) public view returns (uint256)

Returns the amount of shares owned by the _account.

getSharesByMintedEUSD(uint256 _EUSDAmount)

function getSharesByMintedEUSD(uint256 _EUSDAmount) public view returns (uint256)

Returns the amount of shares that corresponds to the _EUSDAmount of protocol-supplied eUSD.

getMintedEUSDByShares(uint256 _sharesAmount)

function getMintedEUSDByShares(uint256 _sharesAmount) public view returns (uint256)

Returns the amount of eUSD that corresponds to the _sharesAmount of token shares.

transferShares(address _recipient, uint256 _sharesAmount)

function transferShares(address _recipient, uint256 _sharesAmount) public returns (uint256)

This function allows the caller to transfer a specified amount of token shares (_sharesAmount) from their own account to the _recipient account. It returns the amount of transferred tokens.

Requirements:

  • _recipient cannot be the zero address.

  • The caller must have at least _sharesAmount shares.

This function internally calls the _transferShares function to perform the share transfer and emits the TransferShares event to reflect the share transfer. Additionally, it calculates the corresponding token amount based on the transferred shares and emits a Transfer event to reflect the token transfer.

mint(address _recipient, uint256 _mintAmount)

function mint(address _recipient, uint256 _mintAmount) external onlyMintPool MintPaused returns (uint256 newTotalShares)

This function allows a designated mint pool to create and assign new shares to the specified _recipient address. It increases the total amount of shares and the total supply of tokens.

Requirements:

  • _recipient cannot be the zero address.

  • The caller must be a designated mint pool.

  • Minting must not be paused for the calling pool.

This function internally calls the _totalShares and _transferShares functions to update the share balances and emits a Transfer event to reflect the token transfer.

burn(address _account, uint256 _burnAmount)

function burn(address _account, uint256 _burnAmount) external onlyMintPool BurnPaused returns (uint256 newTotalShares)

This function allows a designated mint pool to destroy a specified amount of eUSD tokens (_burnAmount) held by the _account address. It decreases the total amount of shares and the total supply of tokens.

Requirements:

  • _account cannot be the zero address.

  • The caller must be a designated mint pool.

  • Burning must not be paused for the calling pool.

This function internally calls the _onlyBurnShares function to update the share balances and emits a Transfer event to reflect the token transfer.

burnShares(address _account, uint256 _sharesAmount)

function burnShares(address _account, uint256 _sharesAmount) external onlyMintPool BurnPaused returns (uint256 newTotalShares)

This function allows a designated mint pool to destroy a specified amount of token shares (_sharesAmount) held by the _account address. It decreases the total amount of shares without affecting the total supply of tokens.

Requirements:

  • _account cannot be the zero address.

  • The caller must be a designated mint pool.

  • Burning must not be paused for the calling pool.

This function internally calls the _onlyBurnShares function to update the share balances.

Last updated