DAICO Open-source Framework, Part 5: DaicoPool.sol

DAICO Open-source Framework, Part 5: DaicoPool.sol

In this part 5 of a series, we will cover the DaicoPool contract that manages the funds raised.

 

Each TokenSale contract sends the funds to the DaicoPool contract when it is finalized. Thus, all the funds raised through the token sales will be pooled in this contract, and then it starts to release the funds by following the tap amount you set up before the sale.

 

Here is the constructor:

 

You literally give the tap amount[wei/sec] to tap_amount. The project owner should give the same amount they specified in their white paper. Since the tap amount is in public, you could lose the trust from investors if you give the different value to it.

 

By the same token, you specify the amount of wei for your initial release for your_initialRelease.

Inside the constructor, the Voting contract will be deployed and the tap amount and the self-destruction will be managed by the Voting contract.

 

State Transition

The DaicoPool contract has three states.

  • Initializing(before the project is in progress)

The funds won’t be released yet. It receives the funds from the TokenSalecontract.

  • ProjectInProgress(the project is in progress)

The funds release depending on the tap amount.

  • Destructed(after the self-destruction)

This is the self-destructed state after the proposal of the self-destruction is passed. The funds won’t be released anymore, and token holders can get a refund.

 

Variables

These are variables in this contract.

 

The Association with the TokenSaleManager

The DaicoPool contract associates itself with the TokenSaleManager with the setTokenSaleContract() function in the DaicoPool contract when the TokenSaleManager contract is deployed. This setTokenSaleContract()function cannot be executed more than once.

 

The TokenSaleManager will be able to trigger the release of the funds with the startProject() function.

 

 

Start The Release of The Funds

The TokenSaleManager contract executes the startProject() function in the DaicoPool when it is finalized after the token sale.

This changes the state from Initializing to ProjectInProgress, which release the initial funds and start to release the tap depending on the amount you have set up.

 

 

Withdrawal of The Funds

The project owner(the owner of the DaicoPool contract) can withdraw the funds released with the withdraw() function as time passes.

 

The execution of the withdraw() function will call updateReleasedBalance(), which checks the balance of the funds that have been released already. Then the amount of funds available for your withdrawal(the amount that has been released – the amount that has been withdrawn) will be calculated with getAvailableBalance() and you can withdraw up to that amount. You can withdraw from whichever the smaller amount of either the value in _amountargument or maximum withdrawal amount.

 

 

There are three functions to check/update the balance.

 

 

Update The Tap Amount

The DaicoPool could update the tap amount via the Voting contract. When the tap raising proposal is passed, the raiseTap() function below is executed, and the tap amount will be updated.

 

 

In the raiseTap() function of the DaicoPool, you can either increase or decrease, but there is a limit in the variation in the Voting contract(101〜200%). This prevents the project owner from maliciously raising the tap and running away with the funds.

 

SelfDestruction

When the self-destruction proposal is passed, the Voting contract execute the selfDestruction() function in DaicoPool, and self-destruct the pool. After the self-destruction, it releases the 30 days worth of the funds depending on the tap amount, and then close the tap. The token holders can get a refund after this.

 

We release the 30 days worth of the funds for project owners to cover the cost of closing or shrinking the business. It requires some money to change the office, and other costs such as labor costs are not easy to cancel immediately.

 

Refund

If the pool were self-destructed, the token holders can get a refund in exchange with their tokens. The amount of refund follows the equation below:

 

The funds left in DaicoPool * the number of tokens you exchange / total supply

 

Before the refund, you need to give permission to the DaicoPool contract to spend on behalf of you with the approve() function in the token contract.

 

 

When you execute refund() and return your tokens, you can get the refund depending on the amount of tokens you have sent.

 

 

That was how the DaicoPool works 🙂 Thanks for reading!

 

 

Profile

Takuya Obata

Chief Operating Officer at ICOVO AG. And a blockchain engineer at the same time. He got MVP in Blockchain Hackathon Tokyo 2016. He is also experienced in natural language processing and chess like game programming.