stealth-defi-swap
TypeScript icon, indicating that this package has built-in type declarations

1.1.161 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i stealth-defi-swap

Weekly Downloads

0

Version

1.1.161

License

ISC

Unpacked Size

161 kB

Total Files

71

Last publish

Collaborators

  • francis-npx
  • henri-cs
  • abalayre