PowerToken
Inherits: IPowerToken, EpochBasedInflationaryVoteToken
Author: M^0 Labs
State Variables
_AUCTION_PERIODS
The number of auction periods in an epoch.
INITIAL_SUPPLY
Returns the initial supply of the token.
bootstrapToken
Returns the address of the token in which token balances and voting powers are bootstrapped.
standardGovernor
Returns the address of the Standard Governor.
vault
Returns the address of the Vault.
bootstrapEpoch
Returns the epoch from which token balances and voting powers are bootstrapped.
_bootstrapSupply
The total supply of the bootstrap token at the bootstrap epoch.
_nextCashTokenStartingEpoch
The starting epoch of the next cash token.
_cashToken
The address of the cash token required to buy from the token auction.
_nextCashToken
The address of the next cash token.
_nextTargetSupplyStartingEpoch
The starting epoch of the next target supply.
_targetSupply
The current target supply of the token.
_nextTargetSupply
The next target supply of the token.
Functions
onlyStandardGovernor
Reverts if the caller is not the Standard Governor.
constructor
Constructs a new Power Token contract.
Parameters
bootstrapToken_
address
The address of the token to bootstrap balances and voting powers from.
standardGovernor_
address
The address of the Standard Governor contract to delegate control to.
cashToken_
address
The address of the token to auction the unowned inflated supply for.
vault_
address
The address of the vault to transfer cash tokens to.
buy
Allows a caller to buy amount
tokens from the auction.
Parameters
minAmount_
uint256
maxAmount_
uint256
destination_
address
expiryEpoch_
uint16
Returns
amount_
uint240
amount The amount of token bought.
cost_
uint256
cost The total cash token cost of the purchase.
markNextVotingEpochAsActive
Marks the next voting epoch as targeted for inflation.
markParticipation
Marks delegatee
as having participated in the current epoch, thus receiving voting power inflation.
Parameters
delegatee_
address
setNextCashToken
Queues the cash token that will take effect from the next epoch onward.
Parameters
nextCashToken_
address
amountToAuction
Returns the amount of tokens that can be bought in the auction.
cashToken
Returns the address of the cash token required to buy from the token auction.
getCost
Returns the total cost, in cash token, of purchasing amount
tokens from the auction.
Parameters
amount_
uint256
Returns
<none>
uint256
The total cost, in cash token, of amount
tokens.
targetSupply
Returns the target supply, which helps determine the amount of tokens up for auction.
*Auction curve:
During every auction period (1/100th of an epoch) the price starts at some "leftPoint" and decreases linearly, with time, to some "rightPoint" (which is half of that "leftPoint"). This is done by computing the weighted average between the "leftPoint" and "rightPoint" for the time remaining in the auction period.
For the next auction period, the new "leftPoint" is half of the previous period's "leftPoint" (which also equals the previous period's "rightPoint").
Combined, this results in the price decreasing by half every auction period at a macro level, but decreasing linearly at a micro-level during each period, without any jumps. Relative price computation:
Since the parameters of this auction are fixed forever (there are no mutable auction parameters and this is not an upgradeable contract), and the token supply is expected to increase relatively quickly and consistently, the result would be that the price Y for some Z% of the total supply would occur earlier and earlier in the auction.
Instead, the desired behavior is that after X seconds into the auction, there will be a price Y for some Z% of the total supply. In other words, it will always cost 572,662,306,133 cash tokens to buy 1% of the previous epoch's total supply with 5 days left in the auction period.
To achieve this, the price is instead computed per basis point of the last epoch's total supply.*
_bootstrap
Bootstrap the account's balance and voting power from the bootstrap token.
Parameters
account_
address
The account to bootstrap.
_delegate
Delegate voting power from delegator_
to newDelegatee_
.
Parameters
delegator_
address
The address of the account delegating voting power.
newDelegatee_
address
The address of the account receiving voting power.
_sync
Syncs account_
so that its balance Snap array in storage, reflects their unrealized inflation.
Parameters
account_
address
The address of the account to sync.
_getBalance
Returns the balance of account_
plus any inflation that is unrealized before epoch_
.
Parameters
account_
address
The account to get the balance for.
epoch_
uint16
The epoch to get the balance at.
Returns
<none>
uint240
The balance of account_
plus any inflation that is unrealized before epoch_
.
_getBootstrapBalance
This is the portion of the initial supply commensurate with the account's portion of the bootstrap supply.
Parameters
account_
address
The account to get the bootstrap balance for.
epoch_
uint16
The epoch to get the bootstrap balance at.
Returns
<none>
uint240
The bootstrap balance of account_
at epoch_
.
_getTotalSupply
Returns the total supply at epoch_
.
Parameters
epoch_
uint16
The epoch to get the total supply at.
Returns
<none>
uint240
The total supply at epoch_
.
_getVotes
Returns the amount of votes of account_
plus any inflation that should be realized at epoch_
.
Parameters
account_
address
The account to get the votes for.
epoch_
uint16
The epoch to get the votes at.
Returns
<none>
uint240
The votes of account_
at epoch_
.
_getInternalOrBootstrap
Returns the amount of balance/votes for account_
at clock value epoch_
.
Parameters
account_
address
The account to get the balance/votes for.
epoch_
uint16
The epoch to get the balance/votes at.
getter_
function (address, uint16) internal view returns (uint240)
An internal view function that returns the balance/votes that are internally tracked.
Returns
<none>
uint240
The balance/votes of account_
(plus any inflation that should be realized) at epoch_
.
_getLastSync
Returns the epoch of the last sync of account_
at or before epoch_
.
Parameters
account_
address
The account to get the last sync for.
epoch_
uint16
The epoch to get the last sync at or before.
Returns
<none>
uint16
The epoch of the last sync of account_
at or before epoch_
.
_getTargetSupply
Returns the target supply of the token at the current epoch.
_revertIfNotStandardGovernor
Reverts if the caller is not the Standard Governor.
_divideUp
Helper function to calculate x
/ y
, rounded up.
Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol)