Code Monkey home page Code Monkey logo

defi321's Introduction

Defi321 is the simplest DeFi

This code is created for study purposes. Please do not use it in a production environment.

It has the following characteristics:

  • It does not communicate with Oracle at all and sets the token price as $1,000.
  • It does not handle decimals.
  • The fee is set at 2%.
  • The reward to liquidity providers is given when the accumulated swap fees in the pool exceed $1,000.

how to intaract

$ truffle console

then

const accounts = await web3.eth.getAccounts();
const me = web3.utils.toChecksumAddress(accounts[0]);
const Defi321 = await Defi321.deployed();
const TokenA = await TokenA.deployed();
const TokenB = await TokenB.deployed();
web3.eth.defaultAccount = accounts[0];

const addressAString = TokenA.address;
const addressA = web3.utils.toChecksumAddress(addressAString);
const addressBString = TokenB.address;
const addressB = web3.utils.toChecksumAddress(addressBString);
const defi = web3.utils.toChecksumAddress(Defi321.address);
const result = await Defi321.createPool(addressA, addressB);

await TokenA.approve(defi, 100000);
await TokenB.approve(defi, 100000);
await TokenA.transfer(me, 10000);
await TokenB.transfer(me, 10000);
await Defi321.provideLiquidity(addressA, addressB, 1000, 1000);
await Defi321.withdrawLiquidity(addressA, addressB, 1, 1);
await TokenA.balanceOf(me)
await TokenB.balanceOf(me)
await Defi321.swap(addressA, addressB, 100);
await TokenA.balanceOf(me)
await TokenB.balanceOf(me)

const pairId = await Defi321.getPairId(addressA, addressB);
await Defi321.getCurrentReward();
await Defi321.getPool(pairId);
await Defi321.claim();

defi321's People

Contributors

s-ekai avatar

Watchers

 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.