SmartPool’s Donation Contract Explained

Victor Tran
SmartPool
Published in
4 min readJan 19, 2017

--

Introduction

In this document, we explain SmartPoolToken contract, its design, architecture, and functionalities. The SmartPoolToken contract is deployed at address 0x98F62d8aD5a884C8bbcf262591DFF55DAb263B80 and its source code can be found here.

Design and architecture

Overview of SmartPoolToken

We deployed 2 contracts: SmartPoolToken and Standard Ethereum Wallet Contract.

SmartPoolToken contract

SmartPoolToken contract is based on Zepplin’s StandardToken (inherent the StandardToken contract without changing it) and has the following properties:

  1. The token name is SPT.
  2. 100 SPTs are given in return to every donated Ether. This exchange rate will be changed in January 27th as described in our call for donation.
  3. 600,000 SPTs were pre-mined and are held by the owner of the contract. The role of the pre-mined tokens is described here.
  4. The owner of the contract can decide to freeze and resume the donation campaign at any point in time, e.g., because enough funding was raised. More formally, the contract can be in either of these two states:
  • Unlocked: When the contract is in this state, it operates normally.
  • Locked: When the contract is in this state, it throws whenever it receives Ethers. In other words, we stop accepting donations.

5. The owner of the contract is Loi Luu via address: 0x98F62d8aD5a884C8bbcf262591DFF55DAb263B80.

6. The beneficiary of the contract balance is a 2–3 multisig wallet 0xa34EDD0E0223C2151b8408E3043b2F6EDC564fcE that is controlled by three of our team members: Loi Luu, Yaron Velner and Victor Tran.

Detailed explanation

In this section, we present the details of our contract. We assume the reader is already familiar with standard token functionality, and describe only the parts that are built on top of Zepplin’s StandardToken.

Contract creation

  1. Our contract is deployed by Loi Luu at this address: 0x98F62d8aD5a884C8bbcf262591DFF55DAb263B80. It’s constructor takes two parameters: the number of pre-mined token hold by the owner (Loi Luu) and an address of the contract’s beneficial. The number of pre-mined tokens is 600,000 and the beneficial address is the address of our 2–3 multisig wallet contract (i.e. 0xa34EDD0E0223C2151b8408E3043b2F6EDC564fcE). Please see more details about the pre-mined tokens here.
  2. Total fund raised is initialized to 0.
  3. Token exchange rate is set as 1 Ether for 100 SPT.
  4. The contract’s owner is the creator of the contract (i.e. Loi Luu).

Accepting donations

SmartPoolToken fallback function accepts donations. It is called (invoked) by sending funds to the contract.

  1. If the contract is in locked state, it throws an exception.
  2. If the transaction amount (msg.value) is 0, it throws.
  3. If the sender had never donated before, the contract increases number of donors and register the address (msg.sender) to donor list.
  4. Total fund is increased by the amount (msg.value) in the transaction.
  5. We calculate the corresponding tokens issued for the donated amount by multiplying the token rate with the donated amount. For example, 1 ETH for 100 tokens, 0.1 ETH for 10 tokens. If the donation is less than the required amount for 1 token, no token will be issued, although the donation is still accepted.
  6. The sender (msg.sender) is credited the new tokens calculated in previous step.
  7. If the number of tokens is greater than 0, TokenMint event will be fired with the sender’s address and the number of tokens passed as parameters.
  8. Donated event is fired with sender’s address, the amount in Wei, the number of tokens gave to sender, and the block number (block.number) passed as parameters.

Donor’s information

  1. getDonationAmount is a public function for a token holder to get his/her total donation in Wei.
  2. getTokenBalance is a public function for a token holder to get his/her number of holding tokens. We note that similar functionally is also implemented in the StandardToken contract.

Get token rate per 1 ETH

  1. tokenRate is a public function for a user to get the current rate for 1 ETH. If the returned rate is 100, it means 100 tokens will be issued for 1 ETH.

Change the token rate

  1. If the sender is not the contract’s owner, it throws.
  2. The rate is changed to the new rate. The new rate will be used to issue tokens for next donations.

Withdraw the contract’s balance

  1. If the sender is not the contract’s owner, it throws.
  2. All available balance of the contract will be sent to the beneficial address. In this case, it’s our multisig wallet contract: 0xa34EDD0E0223C2151b8408E3043b2F6EDC564fcE

Lock/Unlock the contract

  1. stopAcceptingDonation moves the contract into locked state. The function can be called only by its owner, otherwise it will terminate. The function also throw if the contract is already in unlocked state.
  2. startAcceptingDonation is to move the contract into unlocked state. The function can be called by only its owner, otherwise it will terminate. The function also throw if the contract is already locked.

Test result

To test the contract’s correctness, we prepare 26 tests using truffle framework to test the 8 aforementioned features. The tests were run as the following attached screenshot. More information about the tests can be found at this url.

Results of SmartPoolToken contract’s tests

Acknowledgement

We would like to thank the SmartPool donors for their generous donations. Please consider donating to support SmartPool development.

--

--