Be In On The Deal: A Smart Contract that Automates Token Pre-Sales
Tags: Cryptocurrency, Smart Contracts, Bitcoin, Ethereum, Venture Capital

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. OTONOMOS.COM Jun 17·4 min read

The launchpool idea

In our February , we talked about “launchpools” and their potential to turn capital formation on its head by letting the community stake in a refundable pool which turns into committed capital at the end of a pre-sale period.

We have now turned this idea into a smart contract which, in its first deployment, will be used to build a book of prospective token buyers for our own OtoCo token pre-sale starting 24 June.

We designed it such that, in a next release, it can be used by OtoCo users and other issuers who want to automate their token pre-sale the same way.

Objective

The objective is for project Sponsor to initialize a smart contract that lets prospective token buyers stake crypto assets (in our case, DAI, USDC and USDT).

The contract then calculates the number of tokens corresponding to the amount staked, using a price per token that programmatically increases under a bonding curve in function of staker’s place in the queue at the moment of staking.

The slope of the bonding curve is set by Sponsor together with the token’s initial price when the contract is initialized, and cannot be changed once the smart contract is activated.

The end result is a transparent process that gives investors a better price the earlier they reserve tokens, but does not commit their capital until the contract goes is Finalized mode (see below).

Up to that point, they can unstake. Unstaking causes them to lose their place in the queue and forfeit the token price of the place they vacated.

If they want to rejoin the pre-sale process, they’ll have to join at the tail of the queue and pay a higher price.

Design and specifications

The product consists of a Factory Contract that deploys customized launchpools with different attributes.

Each launchpool is controlled by its Sponsor, who is responsible for setting its attributes and who takes decisions during the lifetime of the pool.

The Sponsor is likely to be the issuer of the tokens.

The main specifications are as follows 1:

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.

— 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.

— Right after a Launchpool is initialized the / is defined by values and . If isn't reached, no action can be taken by stakers. Once is reached, stakers could and freely. Once is reached, 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.

— Paused stage has to be triggered by the Sponsor in case any problem occurs. Once a launchpool is in , is no longer allowed but, following our code audit, 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.

— Once is reached, the Sponsor needs to call function. Once called, function will lead to Calculation stage. In this stage, Sponsor is allowed to trigger to calculate how much shares each staker will receive in return for the amount staked. The tokens are calculated as long has > 100000 on the transaction. Once 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.

— Once all tokens are calculated, the contract automatically triggers the stage Distributing. At this stage, Sponsor should trigger on the smart contract, which transfers all calculated tokens to the respective stakers. The process is identical to the 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.

— 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 . 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

The smart contract was audited by Coinspect LLC and a copy of the audit will be made available in our OtoCo Pre-Order Guide and FAQs to be released 24 June.

GitHub

All our code is freely available on OtoCo’s GitHub.

Join our official OtoCo Telegram group for all announcements related to our forthcoming token pre-sale!