1.2.2 • Published 9 months ago

@dripfi/drip-sdk v1.2.2

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

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'
import { DripConfig, Chain } from '@dripfi/drip-sdk'

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

const chain: Chain = Chain.MAINNET // if targeting ethereum mainnet

const chain: Chain = Chain.SEPOLIA // if targeting sepolia testnet

const signer: ethers.Signer = /* your Signer instance */;

const dripSdk = new DripSdk(chain, signer);

Methods

NameRequires authenticationDescription
getAllVaults(): Promise<Vault[]>NOFetches details of all Drip Vaults.
getVaultDetails(vaultAddress: string): Promise<Vault>NOFetches details of a specific Drip Vault identified by its address.
getVaultStats(): Promise<VaultStats>NOReturns some overall drip stats
getTokenPrice(tokenName: string): Promise<number>NOReturns the price for the given token (only works for weth at the moment)
updateSigner(newSigner: Signer): Promise<void>NOUpdates the signer for the SDK instance.
isUserAuthenticated(): Promise<AuthenticationStatus>NOChecks if the user is authenticated and returns authentication status along with relevant information.
authenticate(): Promise<boolean>NOInitiates the user authentication process and returns a boolean indicating success.
deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>NOThe deposit function allows you to deposit tokens into a specific vault. Returns txHash.
getExpectedSwapResult(fromTokenAddress: string, toTokenAddress: string, amount: string, decimals: number): Promise<string>YESReturns the expected amount of tokens to get from a swap
getUserBalance(): Promise<UserBalance>YESReturns overall user balance information
getUserBoostedNfts(vaultAddress: string): Promise<string[]>YESReturns an array of boosted nfts addresses owned by the user
getRewardsPerHour(vaultAddress: string): Promise<string[]>YESReturns 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>YESFetches the current user's rewards points for each vault.
getUserVaultBalance(): Promise<UserVaultBalance>YESFetches the user's balance for a specific Drip Vault.
fastWithdraw(vault: Vault, amountToWithdraw?: string): Promise<string>YESFor 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>YESThe 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>YESWithdraws 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>YESAfter 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
  };
  
1.2.2

9 months ago

1.2.0

9 months ago

1.2.1

9 months ago

1.1.28

9 months ago

1.1.27

9 months ago

1.1.26

9 months ago

1.1.25

9 months ago

1.1.24

9 months ago

1.1.23

9 months ago

1.1.22-dev.1

10 months ago

1.1.22

10 months ago

1.1.21-dev.2

10 months ago

1.1.21-dev.1

10 months ago

1.1.21-dev

10 months ago

1.1.21-test

10 months ago

1.1.21

10 months ago

1.1.20

10 months ago

1.1.19

10 months ago

1.1.18

10 months ago

1.1.17

10 months ago

1.1.16

10 months ago

1.1.15

10 months ago

1.1.14

10 months ago

1.1.13

10 months ago

1.1.12

10 months ago

1.1.11

10 months ago

1.1.10

10 months ago

1.1.9

11 months ago

1.1.8

11 months ago

1.1.7

11 months ago

1.1.6

11 months ago

1.0.20

12 months ago

1.1.5

12 months ago

1.0.19

12 months ago

1.1.4

12 months ago

1.1.3

12 months ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago