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

@dripfi/drip-sdk

v1.1.16

Published

Drip SDK

Downloads

649

Readme

Drip SDK

Introduction

The Drip SDK is a TypeScript library designed to interact with the Drip protocol. It provides methods to retrieve information about Drip Vaults, manage user authentication, and fetch user balances.

Table of Contents

Installation

To use the Drip SDK in your project, you can install it via npm or yarn:

npm i @dripfi/drip-sdk

Usage

import DripSdk from '@drip/sdk'

Initialize the SDK with your Drip configuration and an optional signer:

const dripConfig = new DripConfig(
    subgraphUrl: string,
    priceFeedApiUrl: string,
    rewardsUrl: string,
    fastRedeemApi: string,
    contracts: Record<number, ContractAddresses>,
    dripRoute: string);
const signer: ethers.Signer = /* your Signer instance */;
const dripSdk = new DripSdk(dripConfig, signer);

Methods

| Name | Requires authentication | Description | | ------ | ------ | ----------- | | getAllVaults(): Promise<Vault[]>| NO | Fetches details of all Drip Vaults. | | getVaultDetails(vaultAddress: string): Promise<Vault> | NO | Fetches details of a specific Drip Vault identified by its address. | | getVaultStats(): Promise<VaultStats>| NO | Returns some overall drip stats | | getTokenPrice(tokenName: string): Promise<number>| NO | Returns the price for the given token (only works for weth at the moment) | | updateSigner(newSigner: Signer): Promise<void>| NO | Updates the signer for the SDK instance. | | isUserAuthenticated(): Promise<AuthenticationStatus> | NO | Checks if the user is authenticated and returns authentication status along with relevant information. | | authenticate(): Promise<boolean> | NO | Initiates the user authentication process and returns a boolean indicating success. | | deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string> | NO | The deposit function allows you to deposit tokens into a specific vault. Returns txHash. | | getExpectedSwapResult(fromTokenAddress: string, toTokenAddress: string, amount: string, decimals: number): Promise<string>| YES | Returns the expected amount of tokens to get from a swap | | getUserBalance(): Promise<UserBalance> | YES | Returns overall user balance information | | getUserBoostedNfts(vaultAddress: string): Promise<string[]> | YES | Returns an array of boosted nfts addresses owned by the user | | getRewardsPerHour(vaultAddress: string): Promise<string[]> | YES | Returns an estimated amount of tokens the user will receive in 1 hour as reward. It considers boost nfts the user owns for the estimation. | | getRewards(): Promise<UserRewards> | YES | Fetches the current user's rewards points for each vault. | | getUserVaultBalance(): Promise<UserVaultBalance> | YES | Fetches the user's balance for a specific Drip Vault. | | fastWithdraw(vault: Vault, amountToWithdraw?: string): Promise<string> | YES | For users who prefer not to wait for withdrawals to be processed, there is a Fast Withdrawal method. While this approach is more gas-intensive, as users bear the cost of executing the withdrawal process themselves, it allows for instant access to the withdrawn tokens. When utilizing Fast Withdrawal, users immediately receive the tokens, eliminating the need to initiate the 'claimWithdrawal' process separately. Returns txHash. | | swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<string> | YES | The swapAndDeposit function allows you to deposit a different token or ether and it will take care of swapping to the correct token before making the deposit. Returns txHash. | | withdraw(vault: Vault, amountToWithdraw?: string): Promise<string> | YES | Withdraws tokens from a vault. After withdrawing, you must wait for the withdrawal to be processed by the 'DoHardWork' function, and then you can claim those tokens using claimWithdraws(). Returns txHash. | | claimWithdraws(vaultAddress: string): Promise<string> | YES | After the withdrawal has been processed by the 'DoHardWork' function, the 'claimWithdraws' function transfers the withdrawn tokens to their personal account. Returns txHash. |

[!IMPORTANT] You must authenticate once for every wallet you want to use


Examples

deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>

I want to deposit 100 USDC in a USDC vault:

USDC_TOKEN_ADDRESS = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"    --> USDC contract address in tenderly environment

you can get vault token address from the vault.depositToken.tokenAddress

VAULT_ADDRESS = "0x...c167" --> Check vaults returned by getAllVaults() and get vault address like: vault.vaultAddress

const txHash = await deposit(USDC_TOKEN_ADDRESS, VAULT_ADDRESS, '100')

[!NOTE] User will be prompted with 2 tx: 1st to approve token usage 2nd to deposit the funds in the vault

[!NOTE] Allowance is calculated by the deposit method, based on the current allowance and the required

[!IMPORTANT] Amount should be formatted, not parsed. In the example we want to deposit 100 USDC so we just input that value instead of adding 6 decimals (100000000)


swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<string>

I want to deposit 1.5ETH in a WETH vault:

WETH_TOKEN_ADDRESS = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"    --> WETH contract address in tenderly environment

const txHash = await swapAndDeposit(WETH_TOKEN_ADDRESS, WETH_TOKEN_ADDRESS, '0', vaultAddress, '1.5')

you can get vault token address from the vault.depositToken.tokenAddress

[!IMPORTANT] ethAmount and fromTokenAmount should be formatted, not parsed. In the example we want to deposit 1.5 WETH so we just input that value instead of adding 18 decimals (1500000000000000000)


withdraw(vault: Vault, amountToWithdraw?: string): Promise<string>

 const userBalanceObject = await getUserBalance()
 const balance = userBalanceObject.userbalance

[!NOTE] If i check balance, that is the max amount I can withdraw

I want to withdraw 100 USDC from the 1st vault fetched. ---> Let's assume the first vault is a USDC vault for simplicity Fetch vaults returned by getAllVault() and pass the vault you want to withdraw from, and the amount to withdraw (100 in this example)

const vaults = await getAllVaults()
const vaultToWithdrawFrom = vaults[0]

const txHash = await withdraw(vaultToWithdrawFrom, '100')

if you want to withdraw all funds in the vault, don't specify the amountToWithdraw:

const txHash = await withdraw(vaultToWithdrawFrom)

[!IMPORTANT] you will have to claim your withdraws after DHW is processed to transfer the withdrawn funds to your wallet


claimWithdraws(vaultAddress: string): Promise<string>

 const userBalanceObject = await getUserBalance()
 const hasWithdrawsToClaim = userBalanceObject.hasWithdrawsToClaim

if hasWithdrawsToClaim is true you have available funds to transfer to your address

 const txHash = await claimWithdraws()

It will transfer all available funds withdrawn with withdraw() function, to your address


fastWithdraw(vault: Vault, amountToWithdraw?: string): Promise<string>

 const userBalanceObject = await getUserBalance()
 const balance = userBalanceObject.userbalance

[!NOTE] If i check balance, that is the max amount I can withdraw

I want to withdraw 3.55 WETH from the 1st vault fetched. ---> Let's assume the first vault is a WETH vault for simplicity Fetch vaults returned by getAllVault() and pass the vault you want to withdraw from, and the amount to withdraw (3.55 in this example)

const vaults = await getAllVaults()
const vaultToWithdrawFrom = vaults[0]

const txHash = await fastWithdraw(vaultToWithdrawFrom, '3.55')

if you want to withdraw all funds in the vault, don't specify the amountToWithdraw, like:

const txHash = await fastWithdraw(vaultToWithdrawFrom)

Types

type Vault = {
  vaultName: string
  vaultAddress: string
  apy: number
  tvr: number
  protocols: string[]
  depositToken: VaultDepositToken
  type: VaultType
  rewards: VaultReward[]
  rewardType: RewardType 
  liveUntil: string
  liveFrom: string
  liveUntilFormatted: string
  hasPoolEnded: boolean
  boosters: NFTBoost[]
  strategies: Strategy[]
  tgePrice?: number
  maxAmountOfTokens?: number
  project: DeployedProject
  projectId: number
  coingeckoId?: string
  depositTokenId: string
  expectedTge?: string
  tokenPrice: number,
  change24h: number,
  volume24h: number,
};

type VaultType = 'launch' | 'earn' | 'airdrop'

type VaultDepositToken = {
  name: string
  symbol: string
  roundingDecimals: number
  precisionDecimals: number
  tokenAddress: string
}

type VaultReward = {
  type: 'token' | 'points';
  name: string;
  symbol: string;
  decimals: number;
  tokenAddress: string;
  monthlyEmissionRate: number;
  blockNumber: number;
  rewardRate: number;
  timestamp: number;
  endTime: number;
};

type NFTBoost = {
  url: string
  tokenAddress: string
  multiplier: number
  nftAddress: string
  network: string
  initialBlock: number
  imagePath: string
}

interface StretchGoal {
  threshhold: number
  threshholdDescription: string
  rewardTooltip: string
  rewardDescription: string
  amountOfTokens: number
}

type Strategy = {
  address: string
  lastDoHardWorkTime: number | null
  lastDoHardWorkBlock: number | null
}

type AuthenticationStatus = {
  isAuthenticated: boolean
  address?: string
  token?: string
  message?: string
}

interface QLFastRedeem {
  assetsWithdrawn: {
    asset: {
      decimals: number
      id: string
      name: string
      symbol: string
    }
    claimed: string
    id: string
  }[]
  blockNumber: number
  id: string
  svtWithdrawn: string
}

type SwapInfo = {
  swapTarget: any
  token: string
  swapCallData: any
}

type UserBalance = {
    assets: {
            asset: string,
            dripping: string,
            deposits: number,
            depositsUSD: number,
            tvr: number,
            apy: number,
            decimals: number,
            reward: number
    }[],
    available: { [symbol: string] : number},
    claimed: { [symbol: string] : number},
};


type UserVaultBalance = {
  hasWithdrawsToClaim: boolean
  userBalance: string
  pendingUserBalance: string
  pendingWithdrawalBalance: string
  withdrawableBalance: string
};


type UserRewards = {
   [vaultAddress: string]: { [rewardPointsName: string]: number } 
};

type VaultStats = {
    totalTVL: number
    totalUsers: number
    activeVaults: number
  };