Coder Social home page Coder Social logo

pinkdiamond1 / synthswap Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kwenta/synthswap

0.0 1.0 0.0 610 KB

SynthSwap is a simple utlity contract that combines a 1Inch swap with the Synthetix exchanger enabling low slippage swaps into and out of synths

JavaScript 8.63% TypeScript 32.36% Nix 0.03% Makefile 0.10% Solidity 58.87%

synthswap's Introduction

SynthSwap

Synthswap is a simple utlity contract that combines a 1Inch swap with the Synthetix exchanger enabling low slippage swaps into and out of synths.

See ISynthSwap.sol for the current interface.

Rationale

At the time of writing this there are no single step methods for swapping from any ERC20 to any synth on Optimistic layer 2. The best way for a trader to begin trading on Kwenta is to swap their tokens for sUSD on Uniswap (or 1inch) and then swap their sUSD for their desired synth on Kwenta.

Effectively, Synthswap combines the above process into a singular zap. This enables Kwenta to provide liquidity for swaps like USDT -> sTSLA or sETH -> ETH all within one transaction (excluding approvals) and eventually one interface.

Documentation

In Synthswap.sol there are two core functions: swapInto and swapOutOf. Both these functions take in a data payload that is returned from the 1inch API. This method leverages 1inch's off-chain routing functionality. For swapInto, delegatecall is used to execute the 1inch swap in the context of the EOA.* And for swapOutOf, call is used to execute the 1inch swap in the context of the contract.*

It is also important to note that under the hood 1inch relies on two entrypoint functions in AggregationRouterV3.sol, unoswap for Uniswap like swaps, and swap for everything else. You will see these function selectors in our test payloads as 0x2e95b6c8 and 0x7c025200, respectively.

The remaining parameters are dedicated to routing the Synthetix leg of the swap. The two Synthetix functions used are exchangeWithTrackingForInitiator (see SIP-140 for details) and exchangeWithTracking. The former is used to settle funds with the EOA caller and the latter is used to settle funds within the contract.

*Subject to change with testing.

Prepping Local Development

Install local dependencies:

npm install

Provide ARCHIVE_NODE_URL in .env. Alchemy has free archive nodes:

ARCHIVE_NODE_URL=<YOUR_ARCHIVE_NODE_PROVIDER_HERE>

Deploy to Mainnet Fork

Run a forked network locally:

npm run fork

Deploy Synthswap onto local forked network:

npm run deploy:fork

Running Tests

To run all tests (unit and integration) under /test

npx hardhat test

To run integration tests:

npm run test:integration

To run utils tests:

npm run test:utils

synthswap's People

Contributors

jaredborders avatar jcmonte avatar avclarke avatar kmeraz 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.