Protest.

Protest your worst qualities.. “Protest.” is published by goodxwolf.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Colony sale contract and the CLNY Token

We wanted to create a sale which was simple to understand, did not require pre-registration, and would not result in selling out rapidly to just a few accounts. At the same time, we didn’t want the amount it was possible to raise to be totally unbounded.

We chose to go with a simple soft cap: if the soft cap is hit, then the sale closes after the greater of either three hours, or the time taken to hit the soft cap, up to a maximum of 24 hours.

The core principles followed in the design were: security, simplicity and upgradability. Additionally, we strove to minimise network impact and gas costs for buyers.

The Ethereum development community is based on an ethos of collaboration. Credit goes out to the people and organisations responsible for the contracts we reused and the ideas that influenced this implementation.

Token sales done better — by Nick Johnson
This article kicked off a very productive internal discussion that led to the focus on lowering the overall network impact. See “Gas cost optimisation and the phantom finney” section below.

In line with our main principles, the main ColonyTokenSale.sol contract inherits nothing more than the DS-Math contract for safe arithmetics and has just 4 core functions in addition to the fallback and emergency-only start/stop sale functions.

Note that the single transaction which crosses the softCap value will execute additional logic to determine whether the sale endBlock will change.

The stop() and start() functions are switching a boolean flag to indicate whether the sale is stopped in case of an emergency. This safety switch is a common pattern in ICOs guarding against attacks.

In earlier versions of the sale contract, gas prices for buy transactions were at around ~120,000 gas which was far too high.

The first way to reduce cost for CLNY purchasers was by refactoring out token issuance from the buy() function. Now, the claimPurchase() function is run once for every buyer after the sale concludes, and that gas is paid by Colony, saving ~185,252 gas for each buyer.

After that reduction, we noticed another discrepancy:

Changing a value from zero to non-zero SSTORE operation incurs an additional 20,000 gas. In the sale contract, the first time the buy()function is called, the totalRaised value needed to be changed from 0to some value — this meant that the first buy() transaction ended up with a gas cost of around 35,000 more than all subsequent buy() calls.

It seemed like bad luck to pass this cost onto the most eager and luckiest of CLNY buyers, and also would have required us to advise buyers to set their gas limits higher than expected. So, a workaround was devised:

The totalRaised value is set initially to 1 finney, eliminating the extra cost from the first buyer. The ‘phantom finney’ is then subtracted from totalRaised when the finalize() function is called.

The buy() transaction now consumes at most 56,944 gas.

Note that all but two buy() transactions actually cost just 41,994 gas. The two that differ are the very first buy() transaction (56,994 gas) and the one that executes the endBlock update logic (53,618).

Assume that there are 10,000 buy transactions in queue, and that each of them sends 20K more gas than their actual cost. Because gas is used by miners to fill blocks, about 21 fewer buy transactions would make it in to each block.

That would mean that for every 10,000 buy transactions, the network would use ~42 extra blocks to process.

Colony Token call flow

In addition the MultiSigWallet.sol provides the control over the Token upgrade.

Code has been audited by DappHub:

Elena is a Solidity developer.

She was a corporate warrior in a previous life, but left her high heels and life in London to go backpacking for a year before falling in love with Ethereum and joining Colony.

She now lives in Bulgaria where, while not writing smarter contracts or helping in the Truffle Gitter channel, she goes off-roading in her Jeep.

Colony is a platform for open organisations.

Add a comment

Related posts:

How I dabbled into world of crypto currency

Like every other person, I wanted to save money hence I spoke to people around me who were working in banks, investment management firms and realised they gave me a next to nothing return of around…

Bitcoin Red Diamond Will Become Global Payment.

Bitcoin Red Diamond is a peer-to-peer crypto currency and can be termed as a modified version of the technology on which bitcoin was built. BRD Specifics Acceleration: With BRD’s proprietary 3SPoS…

The musician Mufaro Mafunga

Did we say we will share amazing stories from young people across the world?! Yes we did! Do you ever have a moment where the world becomes too unbearable that only music can heal you!? We all have…