Giter Club home page Giter Club logo

dsa-connectors's Introduction

DSA connectors

Connectors are standard proxy logics contract that let DeFi Smart Account (DSA) interact with various smart contracts, and make the important actions accessible like cross protocol interoperability.

DSAs are powerful because they can easily be extended with connectors. Every new connector that is added is immediately usable by any developer building on top of DSAs. Connectors can either be base connectors to protocols, auth connectors, higher level connectors with more specific use cases like optimized lending, or connectors to native liquidity pools.

You can create a PR to request a support for specific protocol or external contracts. The process to add a new connector is explained below.

List of all the mainnet connector for referrence is here

Usage

Pre Requisites

Before running any command, make sure to install dependencies:

$ npm install

Compile

Compile the smart contracts with Hardhat:

$ npm run compile

TypeChain

Compile the smart contracts and generate TypeChain artifacts:

$ npm run typechain

Test

Run tests using interactive CLI

$ npm run test:runner

Run all the tests:

$ npm run test

(Striclty use this envirnment to test, or otherwise make suitable changes in config file before testing).

Deploy

To deploy a connector using interactive CLI

$ npm run deploy:runner

(To deploy script manually use scripts/deployment/deployManually.ts script)

checks

To check that code is compatible with github actions

$ npm run check

How to add a new connector

You can create a new PR to add a new connector. To get the PR merged, certain requirements needs to be met which will be explained here.

New connector should follow the current directory structure

Common files for all connectors are in contracts/common directory.

  • math.sol has methods for mathematical operations (DSMath)
  • interfaces.sol contains the common interfaces
    • TokenInterface for ERC-20 interface including WETH
  • stores.sol contains the global constants as well as methods getId & setId (Stores)
  • basic.sol inherits DSMath & Stores contracts. This contains few details explained below
    • Wrapping & unwrapping ETH (convertEthToWeth & convertWethToEth)
    • Getting token & ETH balance of DSA

Connectors are under contracts/connectors directory, and should be formatted as follows:

  • Connector events should be in a separate contract: events.sol
  • Interfaces should be defined in a seperate file: interface.sol
  • If the connector has helper methods & constants (including interface instances), this should be defined in a separate file: helpers.sol
    • Helpers contract should inherit Basic contract from common directory
    • If the connector doesn't have any helper methods, the main contract should inherit Basic contract
  • The main logic of the contract should be under main.sol, and the contract should inherit Helpers (if exists, otherwise Basic) & Events

Few things to consider while writing the connector:

  • Connector should have a public constant string declared name, which will be the name of the connector. This will be versioned. Ex: Compound-v1
  • Contract name should start with ConnectV2 appended with protocol name. Eg: ConnectV2Compound
  • User interacting methods (external methods) will not be emitting events, rather the methods will be returning 2 variables:
    • _eventName of string type: This will be the event signture defined in the Events contract. Ex: LogDeposit(address,address,uint256,uint256,uint256)
    • _eventParam of bytes type: This will be the abi encoded event parameters
  • The contracts should not have selfdestruct()
  • The contracts should not have delegatecall()
  • Use uint(-1) of type(uint256).max for maximum amount everywhere
  • Use ethAddr (declared in Stores) to denote Ethereum (non-ERC20)
  • Use address(this) instead of msg.sender for fetching balance on-chain, etc
  • Only approve() (declared in Basic) limited amount while giving ERC20 allowance, which strictly needs to be 0 by the end of the spell.
  • User interacting functions should have natspec comments(@dev, @notice, @param).
  • Use getUint() (declared in Stores) for getting value that saved from previous spell
  • Use setUint() (declared in Stores) for setting value to save for the future spell

Support

If you can't find something you're looking for or have any questions, ask them at our developers community on Discord or simply send an Email.

dsa-connectors's People

Contributors

0xdaksh avatar ardhead avatar babkendev01 avatar bhavik-m avatar carlos53093 avatar chinmay0402 avatar cryptodev222 avatar dimsome avatar eccheung4 avatar edmulraney avatar gauddel avatar guifel avatar ishanjain28 avatar jeffywu avatar kaymasjain avatar mubaris avatar pradyuman-verma avatar richa-iitr avatar rustumatizon avatar sanchaymittal avatar shriyatyagii avatar sowmayjain avatar tbouder avatar thrilok209 avatar universefinance avatar vaibhav20201 avatar wanglonghong avatar weitianjie2000 avatar yaronvel avatar zapaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dsa-connectors's Issues

update 1inch

  • Add multi-sell and multi-swap functionality in 1inch connector.

Currently, the 1inch sell function takes these params:

    function sell(
        address buyAddr,
        address sellAddr,
        unit sellAmt,
        unitunitAmt,
        bytes calldata callData,
        unit setId
    )

Need to create a new function multi-sell which takes this as params:

    function sell(
        address[] memory buyAddr,
        address[] memory sellAddr,
        unit[] memory sellAmt,
        unit[] memory unitAmt,
        bytes[] calldata callData,
        unit[] memory setId
    )

And perform swapping of multiple tokens.

Aave v3 import connector with permit

Current Implementation:

Aave v3 import connector: imports Aave v3 position from the user's EOA address to user's DSA wallet in a single transaction with some allowance transactions.

Issue:

User needs to give allowances of all supplied tokens i.e atokens to user's DSA wallet address before doing import transaction. So, if the user has 5 atokens, then 5 allowance transactions + 1 import transaction => total 6 transactions.

Solution:

Since Aave v3 atokens have permit functionality we can utilize and completely remove the allowance transactions and do permit message signing from the user EOA address and use those signed permits in import transaction

Changes:

Aave v3 import connector on polygon:

We need to create a similar Aave v3 import connector for polygon with permit functionality. So, in the import function, we will be passing extra param signedPermits. we need to add permit function before taking atokens(i.e _TransferAtokens) from user's EOA to DSA wallet

Fix status-checks

Status checks are failing in every commit. there are errors in status-check codebase. we need to fix this.

Curve connector

We need a curve connector - for LP management and trade functions. We need to create a dynamic connector so that it interacts with all the curve pools.

Set mainnet fork block from test cases

Currently, we are setting block number in hardhat.config.js. And not all test cases work with that block number. Instead, let's set blocknumber directly from test using this and we can remove this.

Note: We need to fix all the test cases by adding hardhat_reset logic in each test suit.

Fluidity connectors

  • P1 connector (iTokens)
  • P3 connector (Uniswap borrowings)

Will add more details here

Euler Connector

Create Euler Connector with the following functions -

  1. deposit
  2. withdraw
  3. mint
  4. burn
  5. approve
  6. transfer
  7. mint
  8. burn
  9. enter market
  10. exit market

Add Morpho-Aave-V3 connector

This connector will allow all the core write interactions to Morpho Aave V3.

Morpho Aave V3 repository - https://github.com/morpho-dao/morpho-aave-v3/tree/main/src

For instance: Take reference from Morpho Aave v2 connector

Docs - https://docs.instadapp.io/connectors/mainnet/morpho-aave

Add a global storage variable DEFAULT_ITERATIONS. Don't assign it a constant.

Functions to include -
Pure supply deposit functions -

  • deposit
    -> will take 2 inputs underlying and amount. Set onBehalf as address(this) and maxIterations as default
  • depositWithMaxIterations ->
    -> will take 3 inputs underlying, amount and maxIterations. Set onBehalf as address(this)
  • depositOnBehalf ->
    -> will take 3 inputs underlying, amount and onBehalf. Set maxIterations as default
  • depositOnBehalfWithMaxIterations ->
    -> will take 4 inputs underlying, amount, onBehalf and maxIterations.

Collateral supply deposit functions -

  • depositCollateral
    -> will take 2 inputs underlying and amount. Set onBehalf as address(this)
  • depositCollateralOnBehalf
    -> will take 3 inputs underlying, amount and onBehalf.

Borrow functions -

  • borrow
    -> will take 3 inputs underlying, amount and reciever. Set onBehalf as address(this) and maxIterations as default.
  • borrowOnBehalf
    -> will take 4 inputs underlying, amount, reciever and onBehalf. Set maxIterations as default.
  • borrowWithMaxIterations
    -> will take 4 inputs underlying, amount, receiver, and maxIterations. Set onBehalf as address(this).
  • borrowOnBehalfWithMaxIterations ->
    -> will take 5 inputs underlying, amount, receiver, onBehalf, and maxIterations.

Withdraw pure supply functions -

  • withdraw
    -> will take 3 inputs underlying, amount, and receiver. Set onBehalf as address(this) and maxIterations as default.
  • withdrawOnBehalf
    -> will take 4 inputs underlying, amount, receiver, and onBehalf. Set maxIterations as default.
  • withdrawWithMaxIterations
    -> will take 5 inputs underlying, amount, receiver, onBehalf, and maxIterations.

Withdraw collateral supply functions -

  • withdrawCollateral
    -> will take 3 inputs underlying, amount, and receiver. Set onBehalf as address(this).
  • withdrawCollateralOnBehalf
    -> will take 4 inputs underlying, amount, receiver, and onBehalf.

Repay functions -

  • payback
    -> will take 2 inputs underlying and amount. Set onBehalf as address(this).
  • paybackOnBehalf
    -> will take 3 inputs underlying, amount, and onBehalf.

Set default Iteration function -
-> Add a function to update the default iterations set.

Claim will not be included in this connector, we will be making a separate connector for it.

Move project from JavaScript to TypeScript

  • As other repositories under @Instadapp have already updated their code for typescript support. It will be better to make this repo typescript compatible.

  • Here is what you need to do.

  • change hardhat.config.js -> hardhat.config.ts (Hardhat will automatically enable its typescript support then for more info check here).

  • Change all the scripts in js -> ts

  • change the respective test cases as well.

Other improvements to be done:

  • Standardize test cases folder like - making different folder for different chains.
  • Add global test case runner.
  • For deployment use hardhat-deploy module.

Deploy BASIC-B & BASIC-C for Polygon

We already have them on mainnet - BASIC-B & BASIC-C.

Mainnet doc just fyi

Need to deploy these for Polygon. There shouldn't be any change in the contract code as far as I know. It's the support for ERC-721 & ERC-1155.

  • Deploy connector
  • SDK update
  • Add Gnosis safe transaction

Compound Import connector

Currently, Compound Import connector uses loop to import whale positions from DSA's authority address to the DSA wallet. But now, since we are using FLA we can remove that looping over the position and create a simple flow:

  • Payback DSA's authority address compound position borrowing (We will take flashloan for required tokens)
  • Transfer collateral tokens from DSA's authority address to DSA wallet
  • Borrow tokens from DSA wallet's position along with FLA fee (To return flashloan)

Deploy Uniswap v3 on Polygon

Deploy:

  • Uniswap v3 connector
  • Uniswap v3 staking connector

The connectors will be exactly the same as mainnet or arbitrum as the contract addresses for Uniswap v3 stay the same on all chains. For reference look at the addresses here

Updates

  • Updated hardhat-etherscan latest-version i.e., 3.0.1 in hardhat.config.ts.
  • Fix addLiquidity script. here
  • update readme
  • add basic deploy.ts script.

Create a simple Uniswap v3 swap connector on Arbitrum

Just one function as sell() with params as

        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 sqrtPriceLimitX96;

One thing that we need to figure out is how to calculate sqrtPriceLimitX96. I'll also ask this to some other devs :)

  • Convert the Param into this struct inside the function ExactInputSingleParams. Search struct here
  • Then call this function exactInputSingle for swap here (make sure to approve token before calling this function).
  • Address for the swap here. I think it should be a swap router.

Update: To calculate sqrtPriceLimitX96 this should help - https://docs.uniswap.org/protocol/reference/core/libraries/SqrtPriceMath

Adding support for Paraswap & 0x aggregator

Add connectors for Paraswap & 0x.

Paraswap & 0x are the DEX aggregators just like 1inch. On our UI we'll start to route our trade by comparing prices from all these aggregators.

Support on:-

  • Mainnet
  • Polygon
  • Avalanche
  • Arbitrum

For reference - we already have the support Paraswap connector on Polygon.

TODO: Upgrades after typescript support.

Things to implement after #123 gets merged.

  • Make deployment script interactive, use command line args to pass data to deployment script.
  • Upgrade test:runner script, enable usage of command line args to pass data. #200
  • add other chain support to addLiquidity script.
  • script to Verify contract after deployment, use sourcify and hardhat-etherscan.
  • Upgrade solidity version of contract, maybe to 0.8.6.
  • Explain any one connector test case in detail, as it will be helpful for understanding underlying code.
  • Add SPDX-License-Identifier: in solidity files. #199

Repository name

Repository name is dsl-connectors, but there is no mentions of DSL,
but DSA connectors

So is it typo in repository name?

Add CompoundV3 (USDC) Connector for Polygon

Description:

Create a new connector for CompoundV3 (USDC market) on Polygon. Use the existing CompoundV3Mainnet connector.

Additional things =>

  • Connector name: ConnectV2CompoundV3Polygon
  • Identify and replace market addresses for polygon wherever required.
  • Identify if all functions are supported for polygon and remove if not (Do mention in PR if any function is removed).
  • Add test cases
  • Attach screenshot for test case results in the PR.

Mainnet Connector - https://github.com/Instadapp/dsa-connectors/tree/main/contracts/mainnet/connectors/compound/v3

Compound polygon governance proposal - https://compound.finance/governance/proposals/151

Aave import connector on Avalanche

Create an import connector for Aave position to move Aave position from the user's metamask to Instadapp:

  • Payback debt
  • move aTokens
  • Borrow debt with flashloan fee

Compound V3 Arbitrum

Description:
Create a new connector for CompoundV3 (USDC market) on Arbitrum. Use the existing CompoundV3 Polygon connector.

Additional things =>

  • Connector name: ConnectV2CompoundV3Arbitrum
  • Identify and replace market addresses for arbitrum wherever required.
  • Identify if all functions are supported for arbitrum and remove if not (Do mention in PR if any function is removed).
  • Add test cases
  • Attach screenshot for test case results in the PR.

Polygon Connector - https://github.com/Instadapp/dsa- connectors/tree/main/contracts/polygon/connectors/compound/v3

Compound Arbitrum governance proposal - https://compound.finance/governance/proposals/160

Add importPosition on Lite connector

Lite connector here but we'll create a new connector as LITE-B which will only have importPosition function.

Only iETH vault has an import function, so it'll only work for that, but no need to add any specific condition related to that.

Here's the iETH vault's address.

Below is attached the image for importPosition function. No need to add any particular condition for it. Just basic connector which is giving astETH allowance to iETH vault's DSA address.
image

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.