Giter Club home page Giter Club logo

erc20-102's Introduction

ERC20 102

Introduction

Welcome! This is an automated workshop that will dive deeper into managing ERC20 tokens. Specifically we will look at patterns using approve() and transferFrom(). It is aimed at developers used to interacting with and writing smart contracts.

How to work on this TD

The TD has three components:

  • An ERC20 token, ticker TD-ERC20-102, that is used to keep track of points
  • An evaluator contract, that is able to mint and distribute TD-ERC20-102 points
  • A claimable ERC20 token, that is used to issue tokens and manipulate them

Your objective is to gather as many TD-ERC20-102 points as possible. Please note :

  • The transfer function of TD-ERC20-102 has been disabled to encourage you to finish the TD with only one address
  • In order to receive points, you will have to do execute code in Evaluator.sol such that the function TDERC20.distributeTokens(msg.sender, n); is triggered, and distributes n points.
  • This repo contains an interface IExerciceSolution.sol. Your ERC20 contract will have to conform to this interface in order to validate the exercice; that is, your contract needs to implement all the functions described in IExerciceSolution.sol.
  • A high level description of what is expected for each exercice is in this readme. A low level description of what is expected can be inferred by reading the code in Evaluator.sol.
  • The Evaluator contract sometimes needs to make payments to buy your tokens. Make sure he has enough ETH to do so! If not, you can send ETH directly to the contract.
  • You can use different contracts to validate different exercices. In order to update the evaluated exercice, call submitExercice() in the Evaluator contract.

Getting to work

  • Clone the repo on your machine
  • Install the required packages npm install @openzeppelin/[email protected] and npm install @truffle/hdwallet-provider
  • Copy the content of example-truffle-config.js to your truffle config
  • Configure a seed for deployment of contracts in your truffle config
  • Register for an infura key and set it up in your truffle config
  • Download and launch Ganache
  • Test that you are able to connect to the goerli network with truffle console
  • Test that you are able to connect to the goerli network with truffle console --network goerli
  • To deploy a contract, configure a migration in the migration folder. Look at the way the TD is deploy and try to iterate
  • Test your deployment in Ganache truffle migrate
  • Deploy on goerli truffle migrate --network goerli --skip-dry-run

Points list

Setting up

  • Create a git repository and share it with the teacher
  • Create an Infura account and API Key (1 pts)
  • Install and configure truffle (1 pts) These points will be attributed manually if you do not manage to have your contract interact with the evaluator, or automatically when claiming points.
  • Manually claim tokens on claimable ERC20 (1 pts)
  • Claim your points by calling ex1_claimedPoints() in the evaluator (2 pts)

Calling another contract from your contract

  • Create a contract (ExerciceSolution) that can claim tokens from teacher ERC20. Keep track of addresses who claimed token, and how much in ExerciceSolution.
  • Deploy ExerciceSolution and submit it to the evaluator with submitExercice() (1 pts)
  • Call ex2_claimedFromContract in the evaluator to prove your code work (2 pts)
  • Create a function withdrawTokens() in ExerciceSolution to withdraw the claimableTokens from the ExerciceSolution to the address that initially claimed them
  • Call ex3_withdrawFromContract in the evaluator to prove your code work (2 pts)

Approve and transferFrom

  • Use ERC20 function to allow your contract to manipulate your tokens. Call ex4_approvedExerciceSolution() to claim points (1 pts)
  • Use ERC20 to revoke this authorization. Call ex5_revokedExerciceSolution() to claim points (1 pts)
  • Create a function depositTokens() through which a user can deposit claimableTokens in ExerciceSolution, using transferFrom
  • Call ex6_depositTokens in the evaluator to prove your code work (2 pts)

Tracking user deposits with a deposit wrapper ERC20

  • Create and deploy an ERC20 (ExerciceSolutionToken) to track user deposit. This ERC20 should be mintable and mint autorization given to ExerciceSolution.
  • Call ex7_createERC20 in the evaluator to prove your code work (2 pts)
  • Update the deposit function so that user balance is tokenized. When a deposit is made in ExerciceSolution, tokens are minted in ExerciceSolutionToken and transfered to the address depositing.
  • Call ex8_depositAndMint in the evaluator to prove your code work (2 pts)
  • Update the ExerciceSolution withdraw function so that it uses transferFrom() ExerciceSolutionToken, burns these tokens, and returns the claimable tokens
  • Call ex9_withdrawAndBurn in the evaluator to prove your code work (2 pts)

Extra points

Extra points if you find bugs / corrections this TD can benefit from, and submit a PR to make it better. Ideas:

  • Adding a way to check the code of a specific contract was only used once (no copying)
  • Publish the code of the Evaluator on Etherscan using the "Verify and publish" functionnality

TD addresses

  • TDToken 0xb79a94500EE323f15d76fF963CcE27cA3C9e32DF
  • ClaimableToken 0xE70AE39bDaB3c3Df5225E03032D31301E2E71B6b
  • Evaluator 0x16F3F705825294A55d40D3D34BAF9F91722d6143

erc20-102's People

Contributors

l-henri avatar 0xlucqs avatar lucas-kacz avatar bastienles avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.