UNPKG

@kamino-finance/farms-sdk

Version:
54 lines 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createMintInstructions = createMintInstructions; exports.getMintDecimals = getMintDecimals; exports.getAssociatedTokenAddress = getAssociatedTokenAddress; exports.createAssociatedTokenAccountIdempotentInstruction = createAssociatedTokenAccountIdempotentInstruction; const token_2022_1 = require("@solana-program/token-2022"); const system_1 = require("@solana-program/system"); const token_1 = require("@solana-program/token"); async function createMintInstructions(rpc, authority, mint, decimals) { return [ (0, system_1.getCreateAccountInstruction)({ payer: authority, space: 82n, lamports: await rpc.getMinimumBalanceForRentExemption(82n).send(), programAddress: token_1.TOKEN_PROGRAM_ADDRESS, newAccount: mint, }), (0, token_2022_1.getInitializeMint2Instruction)({ mint: mint.address, decimals, mintAuthority: authority.address, freezeAuthority: null, }, { programAddress: token_1.TOKEN_PROGRAM_ADDRESS }), ]; } async function getMintDecimals(rpc, mintAddress) { const mint = await (0, token_2022_1.fetchMint)(rpc, mintAddress); return mint.data.decimals; } async function getAssociatedTokenAddress(owner, tokenMintAddress, tokenProgram) { const [ata] = await (0, token_2022_1.findAssociatedTokenPda)({ mint: tokenMintAddress, owner, tokenProgram, }); return ata; } async function createAssociatedTokenAccountIdempotentInstruction(payer, mint, tokenProgram, owner = payer.address, ata) { let ataAddress = ata; if (!ataAddress) { ataAddress = await getAssociatedTokenAddress(owner, mint, tokenProgram); } const createUserTokenAccountIx = (0, token_2022_1.getCreateAssociatedTokenIdempotentInstruction)({ ata: ataAddress, mint: mint, owner, payer, tokenProgram, systemProgram: system_1.SYSTEM_PROGRAM_ADDRESS, }, { programAddress: token_2022_1.ASSOCIATED_TOKEN_PROGRAM_ADDRESS }); return [ataAddress, createUserTokenAccountIx]; } //# sourceMappingURL=token.js.map