Giter Club home page Giter Club logo

1inch-swap's Introduction

1inch ProxySwap

A minimal example showing how to integrate 1inch with your smart contract

image

Dependencies

Installation

git clone https://github.com/smye/1inch-swap.git
cd 1inch-swap
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Usage

  • Add the OpenZeppelin dependencies via Brownies package manager

    brownie pm install OpenZeppelin/[email protected]
  • To add a live network to Brownie

    brownie networks add Ethereum polygon host=https://matic-mainnet.chainstacklabs.com  chainid=137 explorer=https://api.polygonscan.com/api
  • For a development network

    brownie networks add Development polygon-fork host=http://127.0.0.1 cmd=ganache-cli fork=https://matic-mainnet.chainstacklabs.com port=8545
  • Modify brownie-config.yaml

    • router: Address of the 1inch router
    • tokenIn: Input token address
    • tokenOut: Address of token to receive
    • amount: Amount of tokenIn being swapped
    • slippage: Percentage that amount of tokenOut can deviate from the quote by, before reverting
    • chain_id: Chain ID of the current network, used for querying 1inch API
  • Set the PRIVATE_KEY environment variable (for live networks)

    export PRIVATE_KEY=0x....
  • To deploy the SwapProxy contract on a mainnet-fork

    brownie run deploy_swap.py --network polygon-fork --interactive
  • To execute a swap on an already deployed SwapProxy contract on a mainnet-fork

    brownie run swap.py --network polygon-fork --interactive

Notes

  • Deploying on mainnet is exactly the same, but replace polygon-fork with polygon

  • By default the account used in a forked environment is defined in the get_acc() function in swap.py

  • The slippage protection (minOut) isn't strictly required in the contract as it is provided in the swap_req["tx"]["data"] value returned by the 1inch API, however, it is an additional failsafe

1inch-swap's People

Contributors

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