Git Product home page Git Product logo

farmer's Introduction

farmer

Python code for interacting with common Polygon tokens, 1inch, and more...

Installation and running

Setup the environment with pipenv install.

Load the environment with pipenv shell or pipenv run python3

Protecting your private key

It's recommended to install secret-stopper to prevent you from accidently commiting your private key (or doxxing your public address). This will replace any pre or post commits you may have already installed

curl https://raw.githubusercontent.com/dodrian/secret-stopper/master/post-commit > .git/hooks/post-commit
curl https://raw.githubusercontent.com/dodrian/secret-stopper/master/pre-commit > .git/hooks/pre-commit
chmod u+x .git/hooks/*-commit

Usage

Tokens

Common Polygon are defined in the tokens module.

Lookup token balance and helper methods:

>>> tokens.USDC.balanceOf(MY_ADDRESS)
179050000
>>> tokens.USDC.hr_balanceOf(MY_ADDRESS)
179.05
>>> tokens.WETH.to_wei(1.2)
1200000000000000000
>>> tokens.WETH.hr_amount(_)
1.2

The same can be done for MATIC (native currency):

>>> tokens.MATIC.hr_balanceOf(MY_ADDRESS)
30.394

Aave tokens are also provided:

>>> tokens.aave.USDC.balanceOf(MY_ADDRESS)
0

1inch

Support is provided for getting quotes and making swaps via 1inch:

>>> oneinch.quote(tokens.WETH, tokens.USDC, 1000000000000000000)
2339289225
>>> oneinch.hr_quote(tokens.WETH, tokens.USDC)
2338.046491
>>> oneinch.swap(tokens.MATIC, tokens.WETH, tokens.MATIC.to_wei(1.5)) 
[...]

Swaps will block execution until the transaction is confirmed, or raise an exception if too much time passes.

farmer's People

Contributors

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