This is a Solidity coding problem for Nayms tech interviews. It is designed to take no more than a few hours.
Ensure you have installed:
- NodeJS 14+
- Yarn (install using
npm i -g yarn
)
Clone the repo locally and install the NPM dependencies using:
yarn
This part must be completed successfully.
The contracts consist of a mintable ERC-20 Token
(which is similar to a Wrapped ETH token). Callers mint tokens by depositing ETH. They can then burn their token balance to get the equivalent amount of deposited ETH back.
In addition, token holders can receive dividend payments in ETH in proportion to their token balance relative to the total supply. Dividends are assigned by looping through the list of holders.
Dividend payments are assigned to token holders' addresses. This means that even if a token holder were to send their tokens to somebody else later on or burn their tokens, they would still be entitled to the dividends they accrued whilst they were holding the tokens.
You will thus need to efficiently keep track of individual token holder addresses in order to assign dividend payouts to holders with minimal gas cost.
For a clearer understanding of how the code is supposed to work please refer to the tests in the test
folder.
You only need to write code in the Token.sol
file. Please ensure all the unit tests pass to successfully complete this part.
This is for bonus points.
The dividends payment process requires looping through token holders. If the no. of holders is very large (e.g. >1000) it's likely that the recordDividend()
method will fail (due to out-of-gas error). Come up with another way of paying dividends that does not suffer from this issue.
Outline in writing (or code!) how you would do things differently. Create a Token2.sol
file with your new code and add a new token2.test.js
test file if you like.
Please publish your code to a new private Github repository and give us (@hiddentao, @melks, @tgeorgas) read-only permissions to it.
yarn devnet
- run a local ganache instance to deploy the contracts to (we recommend keeping this running form the start in a separate tab)yarn compile
- compile the codeyarn test
- run the testsyarn deploy
- deploy compiled code to local testnet (in case you want to use Remix, etc)
MIT