@dripfi/drip-sdk
v1.2.17
Published
Drip SDK
Downloads
1,057
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'
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
| 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>
| NO | 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. |
| getTokenAllowanceForCurrency(tokenAddress: string): Promise<string>
| NO | This function retrieves the token allowance for a specific currency. |
| getTokenAllowanceForRecycler(tokenAddress: string): Promise<BigNumber>
| NO | This function retrieves the token allowance for the recycler contract. |
| getTokenAllowanceForSwapAndRecycler(tokenAddress: string): Promise<BigNumber>
| NO | This function retrieves the token allowance for the swap and recycler contract. |
| getUserBoostedNfts(vaultAddress: string, headers?: Headers): Promise<string[]>
| YES | This function retrieves an array of boosted NFT addresses owned by the user. |
| getRewardsPerHour(vaultAddress: string): Promise<number>
| YES | This function returns an estimated amount of tokens the user will receive in one hour as a reward for the given vault |
| newDeposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>
| YES | This function allows for a new deposit without checking for allowance.
| newSwapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<string>
| YES | This function allows for a new swap and deposit without checking for allowance. |
| getAllVestingInfo(beneficiaryAddress: string): Promise<VestingInfo>
| YES | This function retrieves all vesting information for a specified beneficiary. |
| getVestingStart(): Promise<string>
| YES | This function retrieves the start time of the vesting period. |
| getVestingEnd(): Promise<string>
| YES | This function retrieves the end time of the vesting period.
| getBeansHistory(): Promise<BeanEntry[]>
| YES | This function retrieves the user's beans history of tx
| getBeansBalance(headers?: Headers): Promise<BeansBalance>
| YES | This function retrieves the user's beans balance.
| getMyPerqBalance(headers?: Headers): Promise<MyPerqData>
| YES | This function retrieves the user's Perq balance data.
| getVaultsClaimableData(headers?: Headers): Promise<VaultClaimData>
| YES | This function fetches claimable data for the user's vaults.
| upgradeLoyaltyCard(): Promise<LoyaltyCard>
| YES | This function upgrades the user's loyalty card.
| getNextLoyaltyCard(headers?: Headers): Promise<LoyaltyCard>
| YES | This function fetches the next loyalty card for the authenticated user based on the currently owned one
| getOwnedLoyaltyCards(headers?: Headers): Promise<LoyaltyCard>
| YES | This function fetches the next loyalty card for the authenticated user based on the currently owned one
| getAllLoyaltyCards(): Promise<LoyaltyCard[]>
| YES | This function fetches all available loyalty cards.
| getLoyaltyCardBoost(rewardId: string, headers?: Headers): Promise<number>
| YES | This function retrieves the boost value for a specific loyalty card.
[!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
};
type BeanEntry = {
address: string
reason: string
recycledAmount: string
beansAmount: string
beansSum: string
amountDepositedInUsd: string
createdAt: string
chainId: number
nonce: number
};
export type BeansBalance = {
balance: string
bonusesClaimed: string[]
};
enum Chain {
MAINNET = 'mainnet',
SEPOLIA = 'sepolia'
}
enum ELoyaltyCardTier {
White = 'White',
Ivory = 'Ivory',
Dune = 'Dune',
Amber = 'Amber',
Sienna = 'Sienna',
Umber = 'Umber',
Black = 'Black'
}
export type MyPerqData = {
[key: string]: {
vaultAddress: string,
projectName: string,
projectType: string,
projectFeatured: boolean,
liveUntil: string,
coingeckoId?: string,
depositTokenId: 'WETH' | 'USDC' | 'DAI',
type: 'earn' | 'launch' | 'airdrop',
rewardType: 'points' | 'token' | 'pnode shards',
amountOfTokens?: number
vaultName: string,
protocols: string[],
apy: number,
tvr: number,
tokenPrice: number,
change24h: number,
volume24h: number,
rewards: CacheVaultRewards[]
strategies: Strategy[],
boosters: NFTBoost[],
depositToken: DepositToken
avgTvl: string
peakTvl: string
pendingDeposits: number;
currentlyDeposited: number;
pendingWithdraws: number;
claimable: number;
ethPrice: number;
tokenRewards: {[token_address: string]: Asset & { amount: number, rewardsPerHour: number }};
}
};