Launchpad Sale Contract
IFAllocationSale.sol
This contract is responsible for conducting a token sale based on allocation that is obtained through staking over time via IFAllocationMaster.
Events
Public variables
saleAmount
Amount of sale tokens to sell.
This is updated only by depositing sale tokens into this contract via fund
.
paymentReceived
Tracks amount of payment received by each address.
The amount of tokens a user has purchased can be determined with the following calculation:
paymentReceived[user] / salePrice
hasWithdrawn
Tracks whether user has already successfully withdrawn.
purchaserCount
Counter of unique purchasers.
withdrawerCount
Counter of unique withdrawers (doesn't count casher).
salePrice
Sale price is in units of paymentToken/saleToken with 10^18 decimals (we define this constant as SALE_PRICE_DECIMALS = 10^18).
For example, if selling ABC token for 10 IFUSD each, then sale price will be 10 * 10^18 = 10_000_000_000_000_000_000.
Note: this example assumes that ABC token and IFUSD have the same number of decimals.
If decimals differ, then salePrice must accommodate any differences in decimals between sale and payment tokens. In other words, if payment token has A decimals and sale token has B decimals, then the price must be adjusted by multiplying by 10**(A-B). The following examples illustrates this:
If A was 18 but B was only 12, then the salePrice should be adjusted by multiplying by 1,000,000. If A was 12 and B was 18, then salePrice should be adjusted by dividing by 1,000,000.
funder
The contract funder which adds sale tokens to be sold.
casher (optional)
Optional casher settable by owner.
The owner can cash the sale contract, and if an optional casher is specified, then both owner and casher can cash the sale contract.
whitelistSetter (optional)
Optional whitelist setter settable by owner.
The owner can set the whitelist, and if an optional whitelistSetter is specified, then both owner and whitelistSetter can set the whitelist.
paymentToken
The payment token.
saleToken
The sale token.
allocationMaster
The allocation master.
trackId
The track on which this sale is conducted.
allocSnapshotBlock
The snapshot block to read stake weights from for determining allocations.
startBlock
Start block is when sale is active (inclusive).
endBlock
End block is when sale is active (inclusive).
minTotalPayment (optional)
Min payment for token amount.
maxTotalPayment
Max payment for token amount.
This is an independent constraint from allocation. If a user's allocation determines that they can buy a maximum amount of sale tokens for X payment tokens, then the user's maximum is whichever is smaller, X or maxTotalPayment.
saleTokenAllocationOverride (optional)
Flat allocation override for all participants.
Non Internal Functions
constructor
fund
Function for funding sale with sale token (called by project team).
Note that if sale tokens are sent to this contract outside of calling fund
, they will not be used in the sale. The variable saleAmount
tracks how many sale tokens to sell, and it only increases by calling fund
. The purchase / withdraw functions use saleAmount
in the denominator when computing the appropriate fractions of tokens purchased / withdrawn to participants.
However, if sale tokens are accidentally sent directly to the contract, the project team can withdraw those tokens using cash
at the end of the sale.
Can only be called before sale begins.
setMinTotalPayment
Function for owner to set an optional, minimum total payment.
Can only be called before sale begins.
setSaleTokenAllocationOverride
Function for owner to set an optional, sale token allocation override.
Can only be called before sale begins.
setCasher
Function for owner to set an optional, separate casher.
Can only be called before sale begins.
setWhitelistSetter
Function for owner to set an optional, separate whitelist setter.
Can only be called before sale begins.
setWhitelist
Function for owner or whitelist setter to set the whitelist.
Can be called any time, even during sale.
setWithdrawDelay
Function for owner to set a withdraw delay.
Can be called at any time, even during sale.
checkWhitelist
Function for checking merkle proof against provided user address.
getTotalPaymentAllocation
Function to get the total allocation of a user in allocation sale.
Allocation is calculated via the override if set, and otherwise allocation is calculated by the allocation master data.
getMaxPayment
Function to get the max remaining amount of allocation for a user (in terms of payment token).
It is whichever is smaller:
user's payment allocation, which is determined by:
the allocation master
the allocation override
maxTotalPayment
purchase
Function for making purchase in allocation sale when there is no whitelist set.
Can only be called during sale period.
whitelistedPurchase
Function for making purchase in allocation sale when there is a whitelist set.
Can only be called during sale period.
withdraw
Function for withdrawing purchased sale token.
Can be called only once and only after sale end.
withdrawGiveaway
Function for withdrawing (redeeming) sale tokens from a zero cost "giveaway" sale.
Can be called only once and only after sale end.
cash
Function for funder to cash in payment token and unpurchased sale token.
Can be called only once and only after sale end.
emergencyTokenRetrieve
Retrieve tokens erroneously sent in to this address.
Can withdraw any token EXCEPT for sale or payment token.
Other useful notes
Computing remaining
There isn't a view function that returns the remaining sale amount, but this can be easily calculated:
Get public variable
totalPaymentReceived
.Get public variable
salePrice
.Calculate the current amount of sale tokens purchased (say
saleTokensPurchased
) withpaymentReceived*SALE_PRICE_DECIMALS/salePrice
.Keep in mind that
salePrice
is in units of paymentToken/saleToken with SALE_PRICE_DECIMALS decimals.
Finally, get the amount of remaining sale tokens with
saleAmount-saleTokensPurchased
.
Last updated