Giter Site home page Giter Site logo

flashloan-weth10's Introduction

WETH10 Flash Loan Example

Borrow unlimited amount of WETH10 with zero fees!

This project showcases an example of a smart contract capable of using flashloans, i.e. implementing ERC3156FlashBorrower, and corresponding deployment code in python.

The project is build using eth-brownie.

Usage

After installing brownie as described here, git clone the repository and run $ brownie run scripts/run.py.

For a more interactive approach start the brownie console and run the script from there:

$ brownie console
$ run("run")

Note about Brownie networks and Infura

In this project we want to fork the Ethereum mainnet at the current state. Therefore we add following line to the brownie-config.yml configuration file:

networks:
    default: mainnet-fork

For more information see the corresponding brownie docs.

If you do not have an Ethereum node at hand it's propably best to use Infura and specify a Project ID. Brownie reads the Project ID from the environment variable $WEB3_INFURA_PROJECT_ID. For more information see corresponding brownie docs.

Background

WETH10

WETH10 is the updated version of the famous WETH9 contract (mostly known as just WETH). The update includes gas optimizations and flash loan capabilities by implementing ERC3156.

ERC3156

This ERC provides standard interfaces and processes for single-asset flash loans. For more information see EIP3156.

Result

Our FlashBorrower emits a Balance(uint256 balance) event two times. The first time in the flashBorrow function, i.e. before the flash loan, and the second time in the onFlashLoan function, i.e. while the contract has access to the loaned amount.

If everything works fine, the scripts/run.py script prints the two emitted balances to the console. The output should be:

Balance of FlashBorrower before and while flash loan:
0E-18 WETH
5192296858534827.628530496329220095 WETH

flashloan-weth10's People

Contributors

pmerkleplant avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.