UNPKG

@renec-foundation/redex-sdk

Version:

Typescript SDK to interact with Orca's Whirlpool program.

40 lines (39 loc) 2.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createWSOLAccountInstructions = exports.getAssociatedTokenAddressSync = exports.isNativeMint = void 0; const spl_token_1 = require("@solana/spl-token"); const web3_js_1 = require("@solana/web3.js"); function isNativeMint(mint) { return mint.equals(spl_token_1.NATIVE_MINT); } exports.isNativeMint = isNativeMint; // TODO: Update spl-token so we get this method function getAssociatedTokenAddressSync(mint, owner, programId = spl_token_1.TOKEN_PROGRAM_ID, associatedTokenProgramId = spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID) { const [address] = web3_js_1.PublicKey.findProgramAddressSync([new web3_js_1.PublicKey(owner).toBuffer(), programId.toBuffer(), new web3_js_1.PublicKey(mint).toBuffer()], associatedTokenProgramId); return address; } exports.getAssociatedTokenAddressSync = getAssociatedTokenAddressSync; // TODO: This is a temp fn to help add payer / differing destination params to the original method // Deprecate this as soon as we move to sync-native. Can consider moving to common-sdk for posterity. function createWSOLAccountInstructions(owner, amountToWrap, accountExemption, payer, unwrapDestination) { var _a; const payerKey = payer !== null && payer !== void 0 ? payer : owner; const unwrapDestinationKey = (_a = unwrapDestination !== null && unwrapDestination !== void 0 ? unwrapDestination : payer) !== null && _a !== void 0 ? _a : owner; const tempAccount = new web3_js_1.Keypair(); const createIx = web3_js_1.SystemProgram.createAccount({ fromPubkey: payerKey, newAccountPubkey: tempAccount.publicKey, lamports: amountToWrap.toNumber() + accountExemption, space: spl_token_1.AccountLayout.span, programId: spl_token_1.TOKEN_PROGRAM_ID, }); const initIx = spl_token_1.Token.createInitAccountInstruction(spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.NATIVE_MINT, tempAccount.publicKey, owner); const closeIx = spl_token_1.Token.createCloseAccountInstruction(spl_token_1.TOKEN_PROGRAM_ID, tempAccount.publicKey, unwrapDestinationKey, owner, []); return { address: tempAccount.publicKey, instructions: [createIx, initIx], cleanupInstructions: [closeIx], signers: [tempAccount], }; } exports.createWSOLAccountInstructions = createWSOLAccountInstructions;