Zap
async zapOut(params: ZapOutParams): Promise<Transaction>
interface ZapOutParams { userTokenInAccount: PublicKey; zapOutParams: ZapOutParameters; remainingAccounts: AccountMeta[]; ammProgram: PublicKey; preInstructions: TransactionInstruction[]; postInstructions: TransactionInstruction[]; }
const preUserTokenBalance = ( await this.connection.getTokenAccountBalance(userInputMintAta) ).value.amount; const remainingAccounts = await getDammV2RemainingAccounts( this.connection, poolAddress, user, userInputMintAta, outputTokenAccountAta, inputTokenProgram, outputTokenProgram ); const payloadData = createDammV2SwapPayload(amountIn, minimumSwapAmountOut); const transaction = await client.zap.zapOut({ userTokenInAccount: new PublicKey( "userTokenInAccount1234567890abcdefghijklmnopqrstuvwxyz" ), zapOutParams: { percentage: 100, offsetAmountIn: AMOUNT_IN_DAMM_V2_OFFSET, preUserTokenBalance: preUserTokenBalance, maxSwapAmount: new BN(1000000000), payloadData: payloadData, }, remainingAccounts: remainingAccounts, ammProgram: DAMM_V2_PROGRAM_ID, });
async zapOutThroughJupiter(params: ZapOutThroughJupiterParams): Promise<Transaction>
interface ZapOutThroughJupiterParams { user: PublicKey; inputMint: PublicKey; outputMint: PublicKey; inputTokenProgram: PublicKey; outputTokenProgram: PublicKey; jupiterSwapResponse: JupiterSwapInstructionResponse; maxSwapAmount: BN; percentageToZapOut: number; }
const quoteResponse = await getJupiterQuote( inputMint, outputMint, swapAmount, 40, 50, true, true, true, "https://lite-api.jup.ag" ); const swapInstructionResponse = await getJupiterSwapInstruction( wallet.publicKey, quoteResponse ); const inputMint = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"); const zapOutTx = await zap.zapOutThroughJupiter({ user: wallet.publicKey, inputMint, outputMint, inputTokenProgram, outputTokenProgram, jupiterSwapResponse: swapInstructionResponse, maxSwapAmount: new BN(1000000000), percentageToZapOut: 100, });
async zapOutThroughDammV2(params: ZapOutThroughDammV2Params): Promise<Transaction>
interface ZapOutThroughDammV2Params { user: PublicKey; poolAddress: PublicKey; inputMint: PublicKey; outputMint: PublicKey; inputTokenProgram: PublicKey; outputTokenProgram: PublicKey; amountIn: BN; minimumSwapAmountOut: BN; maxSwapAmount: BN; percentageToZapOut: number; }
const inputMint = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"); const outputMint = new PublicKey("So11111111111111111111111111111111111111112"); const zapOutTx = await zap.zapOutThroughDlmm({ user: wallet.publicKey, poolAddress: new PublicKey("CGPxT5d1uf9a8cKVJuZaJAU76t2EfLGbTmRbfvLLZp5j"), inputMint, outputMint, inputTokenProgram, outputTokenProgram, amountIn: new BN(1000000000), minimumSwapAmountOut: new BN(0), maxSwapAmount: new BN(1000000000), percentageToZapOut: 100, });
async zapOutThroughDlmm(params: ZapOutThroughDlmmParams): Promise<Transaction>
interface ZapOutThroughDlmmParams { user: PublicKey; lbPairAddress: PublicKey; inputMint: PublicKey; outputMint: PublicKey; inputTokenProgram: PublicKey; outputTokenProgram: PublicKey; amountIn: BN; minimumSwapAmountOut: BN; maxSwapAmount: BN; percentageToZapOut: number; }
const inputMint = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"); const outputMint = new PublicKey("So11111111111111111111111111111111111111112"); const zapOutTx = await zap.zapOutThroughDlmm({ user: wallet.publicKey, lbPairAddress: new PublicKey("5rCf1DM8LjKTw4YqhnoLcngyZYeNnQqztScTogYHAS6"), inputMint, outputMint, inputTokenProgram, outputTokenProgram, amountIn: new BN(1000000000), minimumSwapAmountOut: new BN(0), maxSwapAmount: new BN(1000000000), percentageToZapOut: 100, });
async getTokenProgramFromMint( connection: Connection, mint: PublicKey ): Promise<PublicKey>
interface GetTokenProgramFromMintParams { connection: Connection; mint: PublicKey; }
const tokenProgram = await getTokenProgramFromMint(connection, inputMint);
async getJupiterQuote( inputMint: PublicKey, outputMint: PublicKey, amount: BN, maxAccounts: number, slippageBps: number, dynamicSlippage: boolean = false, onlyDirectRoutes: boolean, restrictIntermediateTokens: boolean, apiUrl: string = "https://lite-api.jup.ag", apiKey?: string ): Promise<JupiterQuoteResponse>
interface GetJupiterQuoteParams { inputMint: PublicKey; outputMint: PublicKey; amount: BN; maxAccounts: number; slippageBps: number; dynamicSlippage: boolean = false; onlyDirectRoutes: boolean; restrictIntermediateTokens: boolean; apiUrl: string = "https://lite-api.jup.ag"; apiKey?: string; }
const quoteResponse = await getJupiterQuote( new PublicKey("So11111111111111111111111111111111111111112"), new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"), new BN(1000000000), 40, 50, true, true, true, "https://lite-api.jup.ag" );
async getJupiterSwapInstruction( userPublicKey: PublicKey, quoteResponse: JupiterQuoteResponse, apiUrl: string = "https://lite-api.jup.ag", apiKey?: string ): Promise<JupiterSwapInstructionResponse>
interface GetJupiterSwapInstructionParams { inputMint: PublicKey; quoteResponse: JupiterQuoteResponse; apiUrl: string = "https://lite-api.jup.ag"; apiKey?: string; }
const quoteResponse = await getJupiterQuote( new PublicKey("So11111111111111111111111111111111111111112"), new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"), new BN(1000000000), 40, 50, true, true, true, "https://lite-api.jup.ag" ); const swapInstructionResponse = await getJupiterSwapInstruction( wallet.publicKey, quoteResponse apiUrl: "https://lite-api.jup.ag", );
Was this page helpful?