Be In On The Deal: A Smart Contract that Automates Token Pre-Sales

In this more technical post, we share how we designed our smart contract that automates the bookbuilding process of our token pre-sale.

The launchpool idea

Objective

Design and specifications

  • NonInitialized — This is the first stage of the launchpool before it is initialized. We use the “initialize” function of the new launchpool to set its parameters.
  • Initialized — Right after a Launchpool is initialized the stake/ unstake is defined by values _startTimestamp and _endTimestamp. If _startTimestamp isn't reached, no action can be taken by stakers. Once _startTimestamp is reached, stakers could stake and unstake freely. Once _endTimestamp is reached, stake could only be called if there is still space for within the defined hard cap.
  • Paused — Paused stage has to be triggered by the Sponsor in case any problem occurs. Once a launchpool is in pause, stake is no longer allowed but, following our code audit, unstake is allowed.
  • Calculating — Once _endTimestamp is reached, the Sponsor needs to call lock function. Once called, lock function will lead to Calculation stage. In this stage, Sponsor is allowed to trigger calculateSharesChunk to calculate how much shares each staker will receive in return for the amount staked. The tokens are calculated as long has gasLeft > 100000 on the transaction. Once gasLeft falls below 100000, the contract stops its calculation on the current index, and the function needs to be called again. This process is repeated until all stakers have their tokens calculated.
  • Distributing — Once all tokens are calculated, the contract automatically triggers the stage Distributing. At this stage, Sponsor should trigger distributeSharesChunk on the smart contract, which transfers all calculated tokens to the respective stakers. The process is identical to the calculateSharesChunk: tokens are distributed as long as gasLeft > 100000 on the transaction. When gasLeft falls below 100000, the contract stops distributing on the current index, and the function needs to be called again. This process is repeated until all stakers receive their tokens.
  • Finalized — Once the last tokens are distributed, the previous function automatically triggers Finalized stage. At this stage, the only function that could be triggered by the Sponsor is withdrawStakes. This will allow Sponsor to withdraw all amounts staked by the investors, whose capital is now committed.
  • Aborted — At any moment during the launch pool phase, Sponsor can call the abort function. When aborted, the only function that stakers can call is the unstake function, which will let each investor retrieve their stakes.

Audit

GitHub

--

--

Otonomos helps doers and investors in the crypto and blockchain community around the world form, fund and govern their legal entities, both offchain and onchain

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
OTONOMOS.COM

Otonomos helps doers and investors in the crypto and blockchain community around the world form, fund and govern their legal entities, both offchain and onchain