UNPKG

@orca-so/whirlpool-sdk

Version:

Whirlpool SDK for the Orca protocol.

26 lines (25 loc) 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createWSOLAccountInstructions = void 0; const spl_token_1 = require("@solana/spl-token"); const web3_js_1 = require("@solana/web3.js"); // TODO use native-mint instead function createWSOLAccountInstructions(walletAddress, amountIn, rentExemptLamports) { const tempAccount = new web3_js_1.Keypair(); const createAccountInstruction = web3_js_1.SystemProgram.createAccount({ fromPubkey: walletAddress, newAccountPubkey: tempAccount.publicKey, lamports: amountIn.toNumber() + rentExemptLamports, space: spl_token_1.AccountLayout.span, programId: spl_token_1.TOKEN_PROGRAM_ID, }); const initAccountInstruction = spl_token_1.Token.createInitAccountInstruction(spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.NATIVE_MINT, tempAccount.publicKey, walletAddress); const closeWSOLAccountInstruction = spl_token_1.Token.createCloseAccountInstruction(spl_token_1.TOKEN_PROGRAM_ID, tempAccount.publicKey, walletAddress, walletAddress, []); return { address: tempAccount.publicKey, instructions: [createAccountInstruction, initAccountInstruction], cleanupInstructions: [closeWSOLAccountInstruction], signers: [tempAccount], }; } exports.createWSOLAccountInstructions = createWSOLAccountInstructions;