Token
contract inherits from OpenZeppelin’s ERC20 standard implementationToken
can only be transferred after a particular_startTime
and before a particular_endTime
, provided in the constructor- Unit tests to account for the
_startTime
and_endTime
constraints Contribution
contract that users can donate ETH to. For their ETH-based contributions,Contribution
issues tokens from theToken
contract in returnContribution
contract stores addresses of users that donate as well as the amount of ETH they’ve donatedContribution
contract has a function that accepts a wallet address, and returns the amount of ETH that a wallet address has contributed to theContribution
contract- Unit tests for the
Contribution
contract - Use OpenZeppelin’s
SafeMath
library in theContribution
contract
- Events that emit when functions in
Token
andContribution
contracts execute - Unit tests for the events
- Emergency stop pattern implemented via inheriting OpenZeppelin's
Pausable
contract. This allows theowner
(address that deployed the contract) topause
andunpause
certain functionalities. In this case, thecontribution
function in theContribution
contract reverts if the contract is paused. - Access control is implemented via inheriting OpenZeppelin's
Ownable
contract. This identifies the deployer address as theowner
and gives the address access to callpause
/unpause
andwithdraw
functions in theContribution
contract.Token
also inherits fromOwnable
to allow the contract deployer to set the address of theContribution
contract that is permitted to mint and issue tokens - Owner must call
setContributionContract
from theToken
contract before the Contribution contract is "allowed" to mint and issue new tokens. This way, there is a separation of concerns between Token logic and Contribution logic. Should there be a bug in the Contribution contract, the owner canpause
contributions so no more money comes in and set a new Contribution contract without having to redeploy the Token contract. - To prevent integer underflow/overflow, both
Contribution
andToken
utilizes theSafeMath
library to perform arithmatics.Contribution
uses the library to update theamountContributed
by a user should they make additional contributions.Token
uses the library to calculate the number of tokens to issue to a user relative to their contribution amount (this multipler is a hypothetical constant) - Both
transfer
andtransferFrom
functions of the ERC20 are restricted bystartTime
andendTime
. Token owners canapprove
tokens outside this window, buttransferFrom
will not work - Time constraints are only implemented on the
transfer
andtransferFrom
functions. This means that users can still contribute ETH to the Contribution contract and be issued new tokens outside of thestartTime
andendTime
window because thecontribution
function callsmint
and nottransfer
- Truffle suite for contract migration setup and testing
- Ganache v4.2.0 as a development blockchain
@openzeppelin/test-helpers
was used along with truffle for testing utils@openzeppelin/contracts
used for theERC20
implementation,SafeMath
,Pausable
, andOwnable
contracts
- Truffle v5.1.9 (core: 5.1.9)
- Solidity - ^0.6.0 (solc-js)
- Node v11.1.0
- Web3.js v1.2.1
- Clone the repository using
git clone https://github.com/nichanank/ui-ethereum-challenge.git
- Navigate to the project repo
cd ui-ethereum-challenge
- Install dependencies
npm i
- Have a development blockchain running (e.g. Ganache) on port 7545 and run
truffle test