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

stealth-defi-swap

v1.1.161

Published

stealth-defi-swap is a TypeScript library for getting the swaps from the Paraswap API in order to interact with a vault.

Downloads

261

Readme

stealth-defi-swap

stealth-defi-swap is a TypeScript library for getting the swaps from the Paraswap API in order to interact with a vault.

Installation

Using npm:

npm i stealth-defi-swap

Using yarn:

yarn add stealth-defi-swap

Exemple

import { sdswap } from "stealth-defi-swap";
import { BigNumber } from "ethers";

const opti: sdswap.Interfaces.SwapOptimisation = {
  slippage: "10000",
  maxImpact: "10000",
};

const swapConfig: sdswap.Interfaces.SwapConfig = {
  networkID: 56,
  signerAddress: "0x4b16c5de96eb2117bbe5fd171e4d203624b014aa",
  recipientAddress: "0x4b16c5de96eb2117bbe5fd171e4d203624b014aa",
};

const swapDeposit: sdswap.Interfaces.SwapDeposit = {
  amountIn: BigNumber.from(10).pow(18).mul(1000),
  baseToken: "0xe9e7cea3dedca5984780bafc599bd69add087d56",
  baseTokenDecimals: 18,
  tokensDecimals: [18, 18],
  tokensAddresses: [
    "0x2170Ed0880ac9A755fd29B2688956BD959F933F8",
    "0xe9e7cea3dedca5984780bafc599bd69add087d56",
  ],
  optimisation: opti,
  positions: [BigNumber.from(5000), BigNumber.from(5000)],
};

/// Getting the swaps for a deposit
const swaps = await sdswap.Actions.deposit(swapDeposit, swapConfig);

Interfaces

The list of all interfaces needed to interact with the functions. They are accessible from the following command : sdswap.Interfaces.

SwapConfig {
    networkID: number; // chainID
    signerAddress: string; // The address who execute the swap (in every case it's the vault for now)
    recipientAddress: string; // The beneficiary of the swap (in every case it's the vault for now)
}

/// We don't use a JSON RPC Provider in this package, so we cannot know ERC20 decimals
/// So we need to pass them as an arguments
SwapDeposit {
    baseToken: string; /// Equivalent to tokenFrom because we swap from baseToken to vault assets
    baseTokenDecimals: number; //
    amountIn: BigNumber; /// Amount of token at tokenFrom
    tokensAddresses: string[]; /// Self-explanatory
    tokensDecimals: number[]; /// Self-explanatory
    optimisation: SwapOptimisation; /// See SwapOptimisation
    positions: BigNumber[]; /// Current positons of the vault returned via getVaultStatus[0] (fetch it before submitting the swap)
}

SwapRedeem {
    shareAmount: BigNumber; /// Share redeemed
    shareSupply: BigNumber; /// Share global supply
    baseToken: string; /// Equivalent to tokenTo because we swap to baseToken and then send the remain part to user
    baseTokenDecimals: number; /// Self-explanatory
    tokensAddresses: string[]; /// Addresses of the vault tokens
    tokensDecimals: number[]; /// Array of decimals for vault token (in the good order always !)
    tokensBalances: BigNumber[]; /// Balance of the vault for each token (of course, including the baseToken)
    optimisation: SwapOptimisation; /// See SwapOptimisation
}

SwapRebalance {
    tokensAddresses: string[]; /// See above
    tokensBalances: BigNumber[]; /// See above
    tokensDecimals: number[]; /// See above
    positions: BigNumber[]; /// Vault current positions (from getVaultStatus[0])
    desiredPositions: BigNumber[]; /// Desired positions
    vaultValueUSD: BigNumber; /// Vault USD value (from getVaultStatus[1])
    optimisation: SwapOptimisation; /// See SwapOptimisation
}

/// If the swap tx reverts, try a higher slippage or price impact
/// Verify the deepth of liquidity on the swap
SwapOptimisation {
    slippage: string; /// default: 1000 so 10% in Basis Point (<10,000) : Amount of losses tolerated due to slippage
    maxImpact: string; /// default: 1000 so 10% in Basis Point (<10,000) : Amount of losses tolerated due to price impact
}

Functions

The list of all functions needed to interact with the Paraswap API. They are accessible from the following command : sdswap.Actions.

  • sdswap.Actions.Deposit(swapDeposit, swapConfig)
  • sdswap.Actions.Redeem(swapRedeem, swapConfig)
  • sdswap.Actions.rebalanceByMinDebitPriority(SwapRebalance, Swapconfig)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT