0.0.4 • Published 2 years ago

@mimic-fi/v1-uniswap-connector v0.0.4

Weekly downloads
-
License
GPL-3.0
Repository
-
Last release
2 years ago

Uniswap Connector

CI npm version

This repository contains an implementation of the Vault's SwapConnector. The SwapConnector is part of the core architecture and is in charge of providing an interface to swap tokens to the Vault. This can be achieved using any type of on-chain exchange, then this repo provides a simple implementation using Uniswap V2.

Deployment

In order to deploy this smart contract locally you can simply do:

import { deploy } from "@mimic-fi/v1-helpers";

const uniswapV2Router = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D";
const connector = await deploy(
  "@mimic-fi/v1-uniswap-connector/artifacts/contracts/UniswapConnector.sol/UniswapConnector",
  [uniswapV2Router]
);

Development

In order to use a SwapConnector you can simply do:

import "@mimic-fi/v1-vault/contracts/interfaces/ISwapConnector.sol";

contract MyContract {
  ISwapConnector connector;

  function getAmountOut(address tokenIn, address tokenOut, uint256 amountIn)
    external
    returns (uint256)
  {
    return connector.getAmountOut(tokenIn, tokenOut, amountIn);
  }

  function swap(
    address tokenIn,
    address tokenOut,
    uint256 amountIn,
    uint256 minAmountOut,
    uint256 deadline,
    bytes memory data
  ) external {
    return
      connector.swap(tokenIn, tokenOut, amountIn, minAmountOut, deadline, data);
  }
}