startBlock- Defines the block number where users are first able to purchase BLU from the contract.
blocksPerPeriod- Defines how long is a single period. Using the value of
43200to represent one day on Polygon chain with ~2 seconds block time.
tokenPerPeriod- Defines how many tokens are up for sale during each period. Using the value of
600E18to sell 600 tokens a day.
targetTokenPeriod- Defines what's the target number of tokens to be sold. It's initiated to exactly half of
tokenPerPeriod. If the target number is sold for the period, the price remains the same for the next period. If the actual token sold is higher or lower than the target, the price is adjusted to be higher or lower respectively for the next period.
sensitivity- Defines the maximum level of change to price between two periods. It's initialized to
2E27to allow the price to double or half between two periods depending if the token sold for the given period is above or under the target.
lastPrice- Stores the price of the token during the current or last period. A number
100E27means that one BLU requires 100 MATIC.
lastTokenSoldInPeriod- Stores the number of tokens sold during the current or last period.
lastTransactionPeriod- Stores the period number where the
lastTokenSoldInPeriodis valid for.
totalTokenSold- Stores the total number of tokens sold by the contract.
buyToken- Payable method to allow anyone to buy BLU from the contract. Excess funds will be refunded to the buyer if there is not enough BLU to be purchased. This method is protected by re-entrancy guard.
updatePrice- Method to update the price between periods. It is called by
buyTokento attempt to update the price whenever purchases are made.
updateSensitivity- Allow admin to update the price sensitivity. It must be greater than
1E27. This should be adjusted to be a lower level once the market has reached a consensus on the initial price. The parameter is set to
updatePriceManually- Emergency method to allow admin to update price should the automatic mechanism does not work (ie unbounded loop in
currentPricemay require more gas than allowed in a block).
emergencyShutdown- Emergency method to allow admin to shut down the sale until a new patch is rolled out.
withdraw- Method to allow admin to withdraw funds from the contract.
upgradeTo- Upgrades the UUPS contract to a new implementation. Requires upgrader role only granted to timelock/governance contract for upgrading functionalities of the token.