2.0.14 • Published 2 years ago

chfry-dsa v2.0.14

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Chfry-DSA

Decentralized on-chain leverage using flash-loans

code style: prettier

Introduction

Chfry DSA introduces pre-defined strategies that can be used to perform complex transactions involving flash-loans across various DeFi protocols. The first supported strategy allows users to take leveraged long/short positions on Aave-v2. NO funding rates. NO fees. NO custody of assets. Just pure 1-click decentralized leverage trading.

How does it work

We use DeFi Smart accounts (DSA) similar to Instadapp. Every wallet address needs to create a new DeFi smart account to interact with the protocol. Users have full custody of all their assests that may be on DSA. The DSA account helps enable us to bundle up several transactions into a single transaction which is sent as a delegate-call. Thus these transactions can also be atomic - a failure at any step would revert the whole transaction, hence preventing any unintended operation.

Architecture

Architecture

Strategy details

This reposistory serves as the data aggregation layer and implements business side logic to calculate the parameters that are sent to the smart contract for executing the leveraged positions. The parameters are dependent on various other DeFi protocol configurations

Calculation logic

Please refer to this document for the detailed calculations : https://www.notion.so/Leverage-by-FL-16390bed4fe74b29949025c1b4fe2a11

Scenarios

Open Long position

Open short position

add-margin

Close long position

Close short position

Data dependencies

There are several external factors that are input parameters to the calculations and can impact the logic. These are :

  1. Token price feeds

On mainnet, we will be using only Chainlink oracle prices for fetching the live market value. Aave also relies on Chainlink indirectly, so it should be the best choice. However on Kovan testnet, the prices are not maintained and very unreliable, so there can be some discrepancy.

  • Chainlink oracle

Used only on the mainnet

  • Aave Oracle

Aave maintains their own oracle service that depends on chainlink. The pricing for all lending/borrowing operations will be based on Aave prices.

For the testnet, we depend on Aave oracle for the market price

  • Uniswap

Since the strategies involve swap operations which are done on Uniswap, and uniswap prices may not be in an ideal state on Kovan testnet and lose sync with the Aave prices, we deployed our own Uniswap pools to reduced the difference in the prices.

It can be accessed here : http://chfry-uniswap.s3-website-ap-southeast-1.amazonaws.com/#/pool

  1. Lending Protocol configurations
  • Loan to Value

The Loan to Value of each asset is fetched live from Aave.

  1. User's position history

The user's previous borrows and deposits history impacts the maximum leverage the user can take. It also imapcts the position parameters as well the the health-factor.

Usage guidelines

Ideally a user would be interacting with this application from the frontend UI. But should someone need to run this as separate Node application, here are the steps :

Pre-requisites
  1. Fund your wallet with test Eth on Kovan. You can use https://faucet.paradigm.xyz/ for this.
  2. Fund your wallet with test DAI on Kovan. Use the faucet from Aave testnet https://staging.aave.com/#/faucet
  3. Create a .env file. You can refer to .env.example for this. Add a alchemy/infura node key and the private key of your wallet(NOTE: ensure there are no mainnet funds just to be safe)

Running the tests
  1. Replace the EOA variable with your own address.
  2. Run npx hardhat test to run all the tests or run a particular test case individually from your IDE
Running on the console

You can execute some selected parts of the strategy from the console. 1. Add your code to the main() function 2. Add these lines before calling your logic await setTestNetwork(true); await initDSANode(); await attachAccount(); 3. Run npm run start

2.0.7

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.0.13

2 years ago

2.0.14

2 years ago

2.0.11

2 years ago

2.0.12

2 years ago

2.0.10

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.5

2 years ago

1.1.21-release

2 years ago

2.0.4

2 years ago

2.0.6

2 years ago

1.1.17-beta

2 years ago

2.0.1

2 years ago

1.1.14-beta

2 years ago

1.1.19-test2

2 years ago

1.1.22-release

2 years ago

1.1.24-dev

2 years ago

1.1.18-release

2 years ago

1.1.23-release

2 years ago

1.1.16-beta

2 years ago

1.1.20-release

2 years ago

1.1.19-release

2 years ago

1.1.24-release

2 years ago

1.1.15-beta

2 years ago

1.1.23-dev

2 years ago

1.1.22-dev

2 years ago

1.1.18-test2

2 years ago

1.1.21-dev

2 years ago

1.1.17-test2

2 years ago

1.1.20-dev

2 years ago

1.1.19-dev

2 years ago

1.1.18-dev

2 years ago

1.1.17-dev

2 years ago

1.1.16-test2

2 years ago

1.1.15-test2

2 years ago

1.1.16-dev

2 years ago

1.1.15-dev

2 years ago

1.1.10-stable

2 years ago

1.1.14-dev

2 years ago

1.1.14

2 years ago

1.1.13

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.47

2 years ago

1.0.46

2 years ago

1.0.45

2 years ago

1.0.44

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.40

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago