RewardModule

Git Source

Inherits: ContextUpgradeable, AccessControlDefaultAdminRulesUpgradeable

The supply-side reward accounting portion of the protocol. A lender's balance is measured in two parts: a static balance and a dynamic "supply factor". Their true balance is the product of the two values. The dynamic portion is then able to be used to distribute interest accrued to the lender.

State Variables

ION

bytes32 public constant ION = keccak256("ION");

RewardModuleStorageLocation

bytes32 private constant RewardModuleStorageLocation =
    0xdb3a0d63a7808d7d0422c40bb62354f42bff7602a547c329c1453dbcbeef4900;

Functions

_getRewardModuleStorage

function _getRewardModuleStorage() private pure returns (RewardModuleStorage storage $);

_initialize

function _initialize(
    address _underlying,
    address _treasury,
    uint8 decimals_,
    string memory name_,
    string memory symbol_
)
    internal
    onlyInitializing;

_burn

function _burn(address user, address receiverOfUnderlying, uint256 amount) internal returns (uint256);

Parameters

NameTypeDescription

user

address

to burn tokens from

receiverOfUnderlying

address

to send underlying tokens to

amount

uint256

to burn

_burnNormalized

function _burnNormalized(address account, uint256 amount) private;

Parameters

NameTypeDescription

account

address

to decrease balance of

amount

uint256

of normalized tokens to burn

_mint

function _mint(address user, address senderOfUnderlying, uint256 amount) internal returns (uint256);

Parameters

NameTypeDescription

user

address

to mint tokens to

senderOfUnderlying

address

address to transfer underlying tokens from

amount

uint256

of reward tokens to mint

_mintNormalized

function _mintNormalized(address account, uint256 amount) private;

Parameters

NameTypeDescription

account

address

to increase balance of

amount

uint256

of normalized tokens to mint

_mintToTreasury

This function does not perform any rounding checks.

function _mintToTreasury(uint256 amount) internal;

Parameters

NameTypeDescription

amount

uint256

of tokens to mint to treasury

_setSupplyFactor

function _setSupplyFactor(uint256 newSupplyFactor) internal;

updateTreasury

Updates the treasury address

function updateTreasury(address newTreasury) external onlyRole(ION);

Parameters

NameTypeDescription

newTreasury

address

address of new treasury

underlying

Address of underlying asset

function underlying() public view returns (IERC20);

decimals

Decimals of the position asset

function decimals() public view returns (uint8);

balanceOf

Current token balance

function balanceOf(address user) public view returns (uint256);

Parameters

NameTypeDescription

user

address

to get balance of

normalizedBalanceOf

Accounting is done in normalized balances

function normalizedBalanceOf(address user) external view returns (uint256);

Parameters

NameTypeDescription

user

address

to get normalized balance of

name

Name of the position asset

function name() public view returns (string memory);

symbol

Symbol of the position asset

function symbol() public view returns (string memory);

treasury

Current treasury address

function treasury() public view returns (address);

totalSupplyUnaccrued

function totalSupplyUnaccrued() public view returns (uint256);

totalSupply

Current total supply

function totalSupply() public view returns (uint256);

normalizedTotalSupplyUnaccrued

function normalizedTotalSupplyUnaccrued() public view returns (uint256);

normalizedTotalSupply

Current normalized total supply

function normalizedTotalSupply() public view returns (uint256);

supplyFactorUnaccrued

function supplyFactorUnaccrued() public view returns (uint256);

supplyFactor

Current supply factor

function supplyFactor() public view returns (uint256);

calculateRewardAndDebtDistribution

function calculateRewardAndDebtDistribution()
    public
    view
    virtual
    returns (
        uint256 totalSupplyFactorIncrease,
        uint256 totalTreasuryMintAmount,
        uint104[] memory rateIncreases,
        uint256 totalDebtIncrease,
        uint48[] memory timestampIncreases
    );

Events

Transfer

Emitted when value tokens are moved from one account (from) to another (to). Note that value may be zero.

event Transfer(address indexed from, address indexed to, uint256 value);

MintToTreasury

event MintToTreasury(address indexed treasury, uint256 amount, uint256 supplyFactor);

TreasuryUpdate

event TreasuryUpdate(address treasury);

Errors

InvalidBurnAmount

Cannot burn amount whose normalized value is less than zero.

error InvalidBurnAmount();

InvalidMintAmount

Cannot mint amount whose normalized value is less than zero.

error InvalidMintAmount();

InvalidUnderlyingAddress

error InvalidUnderlyingAddress();

InvalidTreasuryAddress

error InvalidTreasuryAddress();

InvalidSender

Indicates a failure with the token sender. Used in transfers.

error InvalidSender(address sender);

Parameters

NameTypeDescription

sender

address

Address whose tokens are being transferred.

InvalidReceiver

Indicates a failure with the token receiver. Used in transfers.

error InvalidReceiver(address receiver);

Parameters

NameTypeDescription

receiver

address

Address to which tokens are being transferred.

InsufficientBalance

Indicates an error related to the current balance of a sender. Used in transfers.

error InsufficientBalance(address account, uint256 balance, uint256 needed);

Parameters

NameTypeDescription

account

address

Address whose token balance is insufficient.

balance

uint256

Current balance for the interacting account.

needed

uint256

Minimum amount required to perform a transfer.

Structs

RewardModuleStorage

struct RewardModuleStorage {
    IERC20 underlying;
    uint8 decimals;
    string name;
    string symbol;
    address treasury;
    uint256 normalizedTotalSupply;
    uint256 supplyFactor;
    mapping(address account => uint256) _normalizedBalances;
}