Deposit

This guide will go over deposit and depositWithMetadata.

The full example can be found on github here.

Setup

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';

async function main() {
    // export your wallet as such
    // export EXAMPLE_WALLET="[92,116,...,245,129]"
    const keypairData = process.env.EXAMPLE_WALLET;
    const programID = Uint8Array.from(JSON.parse(keypairData));
    const walletKeypair = Keypair.fromSecretKey(programID);
    console.log('connected wallet', walletKeypair.publicKey.toString());
    
    // Setup
    const programId = 'dripTrkvSyQKvkyWg7oi4jmeEGMA5scSYowHArJ9Vwk';
    const network = Network.Devnet;
    const clientEnv = ClientEnv.Production;
    const provider = new AnchorProvider(
        new Connection('https://api.devnet.solana.com', 'confirmed'),
        new NodeWallet(walletKeypair),
        AnchorProvider.defaultOptions()
    );
    const drip = Drip.fromNetworkClient(network, provider, programId, clientEnv);
    
    // Devnet Drip USDT
    const tokenA = new PublicKey('H9gBUJs5Kc5zyiKRTzZcYom4Hpj9VPHLy4VzExTVPgxa');
    
    // Given a tokenA, get valid tokenBs
    const tokenBs = await drip.config.getAllTokenBs(tokenA);
    // For the example's sake, lets pick the first token available
    const tokenB = tokenBs[Object.keys(tokenBs)[0]].mint;
    console.log('tokenA', tokenA.toString(), 'tokenB', tokenB.toString());
    
    const vaultProtoConfigs = await drip.config.getSupportedVaultProtoConfigsForPair(
        tokenA,
        tokenB
    );
    // For the example's sake, lets pick the first proto config
    const vaultProtoConfig = vaultProtoConfigs[0];
    console.log(
        'vaultProtoConfig',
        vaultProtoConfig.pubkey.toString(),
        'granularity',
        vaultProtoConfig.granularity.toString()
    );
    
    const vaultPubkey = findVaultPubkey(drip.programId, {
        protoConfig: vaultProtoConfig.pubkey,
        tokenAMint: tokenA,
        tokenBMint: tokenB
    });
    console.log('vault', vaultPubkey.toString());
    
    const dripVault = await drip.getVault(vaultPubkey);
    // ...
}

Deposit Without Token Metadata

This example creates a user position without creating the metaplex token metadata account. The position created by this instruction has no limitations, but the NFT image will not be viewable in your wallet provider (such as phantom). The instruction it is calling under the hood is deposit.

console.log('\n\n\nDeposit Without TokenMetadata');

const res = await dripVault.deposit({
    // units are base units
    amount: new BN(100),
    dripParams: {
        numberOfSwaps: 10
    }
});

console.log('position', res.metadata.position.toString());

Deposit With Token Metadata

This function does the same as Deposit Without Token Metadata, but it does create the token metadata account, thus making the NFT image viewable in most wallet providers. The instruction it is calling under the hood is depositWithMetadata.

console.log('\n\n\nDeposit With TokenMetadata');

const res = await dripVault.depositWithMetadata({
    // units are base units
    amount: new BN(100),
    dripParams: {
        numberOfSwaps: 10
    }
});
console.log('position', res.metadata.position.toString());
console.log('positionMetadataAccount', res.metadata.positionMetadataAccount.toString());

Deposit With Referrer

Both Deposit With Token Metadata and Deposit Without Token Metadata take an optional parameter of referrer. This parameter represents the Token B token account that will receive the referral fees on a withdrawal instruction (withdrawB, closePosition), see Fee Structure for more details. If this parameter is not provided, the vault's treasuryTokenBAccount will be used as the default value.

There is no restriction on the referrer so long that it is a token account for the vaults tokenBMint.

Last updated