//import { Drip, DripVault, findVaultPubkey, Network, VaultAccount } from '@dcaf-labs/drip-sdk';import { Address, AnchorProvider, BN } from'@project-serum/anchor';import NodeWallet from'@project-serum/anchor/dist/cjs/nodewallet';import { Connection, Keypair, PublicKey } from'@solana/web3.js';import { Token, TOKEN_PROGRAM_ID } from'@solana/spl-token';asyncfunctionmain() {// export your wallet as such// export EXAMPLE_WALLET="[92,116,...,245,129]"constkeypairData=process.env.EXAMPLE_WALLET;constprogramID=Uint8Array.from(JSON.parse(keypairData));constwalletKeypair=Keypair.fromSecretKey(programID);console.log('connected wallet',walletKeypair.publicKey.toString());// SetupconstprogramId='dripTrkvSyQKvkyWg7oi4jmeEGMA5scSYowHArJ9Vwk';constnetwork=Network.Devnet;constclientEnv=ClientEnv.Production;constprovider=newAnchorProvider(newConnection('https://api.devnet.solana.com','confirmed'),newNodeWallet(walletKeypair),AnchorProvider.defaultOptions() );constdrip=Drip.fromNetworkClient(network, provider, programId, clientEnv);// Devnet Drip USDTconsttokenA=newPublicKey('H9gBUJs5Kc5zyiKRTzZcYom4Hpj9VPHLy4VzExTVPgxa');// Given a tokenA, get valid tokenBsconsttokenBs=awaitdrip.config.getAllTokenBs(tokenA);// For the example's sake, lets pick the first token availableconsttokenB= tokenBs[Object.keys(tokenBs)[0]].mint;console.log('tokenA',tokenA.toString(),'tokenB',tokenB.toString());constvaultProtoConfigs=awaitdrip.config.getSupportedVaultProtoConfigsForPair( tokenA, tokenB );// For the example's sake, lets pick the first proto configconstvaultProtoConfig= vaultProtoConfigs[0];console.log('vaultProtoConfig',vaultProtoConfig.pubkey.toString(),'granularity',vaultProtoConfig.granularity.toString() );constvaultPubkey=findVaultPubkey(drip.programId, { protoConfig:vaultProtoConfig.pubkey, tokenAMint: tokenA, tokenBMint: tokenB });console.log('vault',vaultPubkey.toString());constdripVault=awaitdrip.getVault(vaultPubkey);// Any function from the deposit guide will work here // the specifc one is not relevant, therefore it is not shownconstpositionPubkey=awaitdeposit(dripVault);constdripPosition=awaitdrip.getPosition(positionPubkey);// ...}
Withdraw
This function will withdraw all the accrued destination token (token B) for a position. Under the hood it calls instruction withdrawB. Note, this function will fail if there is no destination token accrued.
This function will withdraw all accrued destination token (token B) for a position along with all remaining source token (token A), burn the position nft token, and close the position nft token account (refunding the lamports to the user).
constres=awaitdripPosition.closePosition();console.log('close position txId',res.id);