Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@helium/spl-utils

Package Overview
Dependencies
Maintainers
5
Versions
232
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@helium/spl-utils - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

41

lib/cjs/token.js

@@ -12,3 +12,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.createNft = exports.createMint = exports.createMintInstructions = exports.createAtaAndMint = exports.createAtaAndMintInstructions = exports.mintTo = void 0;
exports.createNft = exports.createMint = exports.createMintInstructions = exports.createAtaAndMint = exports.createAtaAndMintInstructions = exports.createAtaAndTransfer = exports.createAtaAndTransferInstructions = exports.mintTo = void 0;
const mpl_token_metadata_1 = require("@metaplex-foundation/mpl-token-metadata");

@@ -34,2 +34,41 @@ const spl_token_1 = require("@solana/spl-token");

exports.mintTo = mintTo;
function createAtaAndTransferInstructions(provider, mint, amount, from = provider.wallet.publicKey, to = provider.wallet.publicKey, payer = provider.wallet.publicKey) {
return __awaiter(this, void 0, void 0, function* () {
const toAta = yield (0, spl_token_1.getAssociatedTokenAddress)(mint, to, true);
const instructions = [];
if (!(yield provider.connection.getAccountInfo(toAta))) {
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payer, toAta, to, mint));
}
const fromAta = yield (0, spl_token_1.getAssociatedTokenAddress)(mint, from);
if (amount != 0) {
instructions.push((0, spl_token_1.createTransferInstruction)(fromAta, toAta, from, BigInt(amount.toString())));
}
return {
instructions,
toAta,
};
});
}
exports.createAtaAndTransferInstructions = createAtaAndTransferInstructions;
function createAtaAndTransfer(provider, mint, amount, from = provider.wallet.publicKey, to = provider.wallet.publicKey, authority = provider.wallet.publicKey, payer = provider.wallet.publicKey, confirmOptions) {
return __awaiter(this, void 0, void 0, function* () {
const transferIx = new web3_js_1.Transaction();
const { instructions, toAta } = yield createAtaAndTransferInstructions(provider, mint, amount, from, to, payer);
if (instructions.length > 0)
transferIx.add(...instructions);
try {
if (instructions.length > 0)
yield provider.sendAndConfirm(transferIx, undefined, confirmOptions);
}
catch (e) {
console.log("Error", e, e.logs);
if (e.logs) {
console.error(e.logs.join("\n"));
}
throw e;
}
return toAta;
});
}
exports.createAtaAndTransfer = createAtaAndTransfer;
function createAtaAndMintInstructions(provider, mint, amount, to = provider.wallet.publicKey, authority = provider.wallet.publicKey, payer = provider.wallet.publicKey) {

@@ -36,0 +75,0 @@ return __awaiter(this, void 0, void 0, function* () {

import { createCreateMasterEditionV3Instruction, createCreateMetadataAccountV3Instruction, createVerifyCollectionInstruction, PROGRAM_ID as METADATA_PROGRAM_ID } from "@metaplex-foundation/mpl-token-metadata";
import { createAssociatedTokenAccountInstruction, createInitializeMintInstruction, createMintToInstruction, getAssociatedTokenAddress, TOKEN_PROGRAM_ID } from "@solana/spl-token";
import { createAssociatedTokenAccountInstruction, createInitializeMintInstruction, createMintToInstruction, createTransferInstruction, getAssociatedTokenAddress, TOKEN_PROGRAM_ID } from "@solana/spl-token";
import { Keypair, PublicKey, SystemProgram, Transaction } from "@solana/web3.js";

@@ -18,2 +18,35 @@ export async function mintTo(provider, mint, amount, destination) {

}
export async function createAtaAndTransferInstructions(provider, mint, amount, from = provider.wallet.publicKey, to = provider.wallet.publicKey, payer = provider.wallet.publicKey) {
const toAta = await getAssociatedTokenAddress(mint, to, true);
const instructions = [];
if (!(await provider.connection.getAccountInfo(toAta))) {
instructions.push(createAssociatedTokenAccountInstruction(payer, toAta, to, mint));
}
const fromAta = await getAssociatedTokenAddress(mint, from);
if (amount != 0) {
instructions.push(createTransferInstruction(fromAta, toAta, from, BigInt(amount.toString())));
}
return {
instructions,
toAta,
};
}
export async function createAtaAndTransfer(provider, mint, amount, from = provider.wallet.publicKey, to = provider.wallet.publicKey, authority = provider.wallet.publicKey, payer = provider.wallet.publicKey, confirmOptions) {
const transferIx = new Transaction();
const { instructions, toAta } = await createAtaAndTransferInstructions(provider, mint, amount, from, to, payer);
if (instructions.length > 0)
transferIx.add(...instructions);
try {
if (instructions.length > 0)
await provider.sendAndConfirm(transferIx, undefined, confirmOptions);
}
catch (e) {
console.log("Error", e, e.logs);
if (e.logs) {
console.error(e.logs.join("\n"));
}
throw e;
}
return toAta;
}
export async function createAtaAndMintInstructions(provider, mint, amount, to = provider.wallet.publicKey, authority = provider.wallet.publicKey, payer = provider.wallet.publicKey) {

@@ -20,0 +53,0 @@ const ata = await getAssociatedTokenAddress(mint, to, true);

@@ -5,2 +5,7 @@ /// <reference types="bn.js" />

export declare function mintTo(provider: anchor.AnchorProvider, mint: PublicKey, amount: number | bigint, destination: PublicKey): Promise<void>;
export declare function createAtaAndTransferInstructions(provider: anchor.AnchorProvider, mint: PublicKey, amount: number | anchor.BN, from?: PublicKey, to?: PublicKey, payer?: PublicKey): Promise<{
instructions: TransactionInstruction[];
toAta: PublicKey;
}>;
export declare function createAtaAndTransfer(provider: anchor.AnchorProvider, mint: PublicKey, amount: number | anchor.BN, from?: PublicKey, to?: PublicKey, authority?: PublicKey, payer?: PublicKey, confirmOptions?: ConfirmOptions): Promise<PublicKey>;
export declare function createAtaAndMintInstructions(provider: anchor.AnchorProvider, mint: PublicKey, amount: number | anchor.BN, to?: PublicKey, authority?: PublicKey, payer?: PublicKey): Promise<{

@@ -7,0 +12,0 @@ instructions: TransactionInstruction[];

4

package.json
{
"name": "@helium/spl-utils",
"version": "0.0.9",
"version": "0.0.10",
"description": "Utils shared across spl suite",

@@ -44,3 +44,3 @@ "publishConfig": {

},
"gitHead": "6bb46d62bcd8e72558111e8e6f649d689bd80ff5"
"gitHead": "fede087053d338a16cf5d4d74881af6b1248b37b"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc