npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chfry-dsa

v2.0.14

Published

JS SDK to interact with Chfry DSA contracts

Downloads

25

Readme

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