BondToken
This contract implements a bond token with upgradeable capabilities, access control, and pausability. It includes functionality for managing indexed user assets and global asset pools.
State Variables
globalPool
The global asset pool
userAssets
Mapping of user addresses to their indexed assets
MINTER_ROLE
Role identifier for accounts with minting privileges
GOV_ROLE
Role identifier for accounts with governance privileges
DISTRIBUTOR_ROLE
Role identifier for the distributor
SHARES_DECIMALS
The number of decimals for shares
Functions
constructor
Note: constructor
initialize
Initializes the contract with a name, symbol, minter, governance address, distributor, and initial shares per token.
Parameters
name
string
The name of the token
symbol
string
The symbol of the token
minter
address
The address that will have minting privileges
governance
address
The address that will have governance privileges
sharesPerToken
uint256
The initial number of shares per token
mint
Can only be called by addresses with the MINTER_ROLE.
Mints new tokens to the specified address.
Parameters
to
address
The address that will receive the minted tokens
amount
uint256
The amount of tokens to mint
burn
Can only be called by addresses with the MINTER_ROLE.
Burns tokens from the specified account.
Parameters
account
address
The account from which tokens will be burned
amount
uint256
The amount of tokens to burn
getPreviousPoolAmounts
Returns the previous pool amounts from the global pool.
Returns
<none>
PoolAmount[]
An array of PoolAmount structs representing the previous pool amounts
_update
This function is called during token transfer and is paused when the contract is paused.
Internal function to update user assets after a transfer.
Parameters
from
address
The address tokens are transferred from
to
address
The address tokens are transferred to
amount
uint256
The amount of tokens transferred
updateIndexedUserAssets
This function updates the number of shares held by the user based on the current period.
Updates the indexed user assets for a specific user.
Parameters
user
address
The address of the user
balance
uint256
The current balance of the user
getIndexedUserAmount
This function calculates the number of shares based on the current period and the previous pool amounts.
Returns the indexed amount of shares for a specific user.
Parameters
user
address
The address of the user
balance
uint256
The current balance of the user
period
uint256
The period to calculate the shares for
Returns
<none>
uint256
The indexed amount of shares for the user
resetIndexedUserAssets
This function resets the last updated period and indexed amount of shares to zero. Can only be called by addresses with the DISTRIBUTOR_ROLE and when the contract is not paused.
Resets the indexed user assets for a specific user.
Parameters
user
address
The address of the user
increaseIndexedAssetPeriod
Can only be called by addresses with the GOV_ROLE and when the contract is not paused.
Increases the current period and updates the shares per token.
Parameters
sharesPerToken
uint256
The new number of shares per token
grantRole
Can only be called by addresses with the GOV_ROLE.
Grants a role to an account.
Parameters
role
bytes32
The role to grant
account
address
The account to grant the role to
revokeRole
Can only be called by addresses with the GOV_ROLE.
Revokes a role from an account.
Parameters
role
bytes32
The role to revoke
account
address
The account to revoke the role from
pause
Can only be called by addresses with the GOV_ROLE.
Pauses all contract functions except for upgrades.
unpause
Can only be called by addresses with the GOV_ROLE.
Unpauses all contract functions.
_authorizeUpgrade
Can only be called by addresses with the GOV_ROLE.
Function that should revert when msg.sender
is not authorized to upgrade the contract. Called by {upgradeTo} and {upgradeToAndCall}.
Parameters
newImplementation
address
Address of the new implementation contract
Events
IncreasedAssetPeriod
Emitted when the asset period is increased
UpdatedUserAssets
Emitted when a user's assets are updated
Structs
PoolAmount
Struct to represent a pool's outstanding shares and shares per bond at a specific period
Properties
period
uint256
The period of the pool amount
amount
uint256
The total amount in the pool
sharesPerToken
uint256
The number of shares per token (base 10000)
IndexedGlobalAssetPool
Struct to represent the global asset pool, including the current period, shares per token, and previous pool amounts.
Properties
currentPeriod
uint256
The current period of the global pool
sharesPerToken
uint256
The current number of shares per token (base 10000)
previousPoolAmounts
PoolAmount[]
An array of previous pool amounts
IndexedUserAssets
Struct to represent a user's indexed assets, which are the user's shares
Properties
lastUpdatedPeriod
uint256
The last period when the user's assets were updated
indexedAmountShares
uint256
The user's indexed amount of shares
Last updated