Socket
Socket
Sign inDemoInstall

@solana/spl-token

Package Overview
Dependencies
Maintainers
0
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/spl-token - npm Package Compare versions

Comparing version 0.4.6 to 0.4.7

25

lib/cjs/extensions/transferFee/actions.js

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.harvestWithheldTokensToMint = exports.withdrawWithheldTokensFromAccounts = exports.withdrawWithheldTokensFromMint = exports.transferCheckedWithFee = void 0;
exports.setTransferFee = exports.harvestWithheldTokensToMint = exports.withdrawWithheldTokensFromAccounts = exports.withdrawWithheldTokensFromMint = exports.transferCheckedWithFee = void 0;
const web3_js_1 = require("@solana/web3.js");

@@ -107,2 +107,25 @@ const internal_js_1 = require("../../actions/internal.js");

exports.harvestWithheldTokensToMint = harvestWithheldTokensToMint;
/**
* Update transfer fee and maximum fee
*
* @param connection Connection to use
* @param payer Payer of the transaction fees
* @param mint The token mint
* @param authority The authority of the transfer fee
* @param multiSigners Signing accounts if `owner` is a multisig
* @param transferFeeBasisPoints Amount of transfer collected as fees, expressed as basis points of the transfer amount
* @param maximumFee Maximum fee assessed on transfers
* @param confirmOptions Options for confirming the transaction
* @param programId SPL Token program account
*
* @return Signature of the confirmed transaction
*/
function setTransferFee(connection_1, payer_1, mint_1, authority_1, multiSigners_1, transferFeeBasisPoints_1, maximumFee_1, confirmOptions_1) {
return __awaiter(this, arguments, void 0, function* (connection, payer, mint, authority, multiSigners, transferFeeBasisPoints, maximumFee, confirmOptions, programId = constants_js_1.TOKEN_2022_PROGRAM_ID) {
const [authorityPublicKey, signers] = (0, internal_js_1.getSigners)(authority, multiSigners);
const transaction = new web3_js_1.Transaction().add((0, instructions_js_1.createSetTransferFeeInstruction)(mint, authorityPublicKey, signers, transferFeeBasisPoints, maximumFee, programId));
return yield (0, web3_js_1.sendAndConfirmTransaction)(connection, transaction, [payer, ...signers], confirmOptions);
});
}
exports.setTransferFee = setTransferFee;
//# sourceMappingURL=actions.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeHarvestWithheldTokensToMintInstructionUnchecked = exports.decodeHarvestWithheldTokensToMintInstruction = exports.createHarvestWithheldTokensToMintInstruction = exports.harvestWithheldTokensToMintInstructionData = exports.decodeWithdrawWithheldTokensFromAccountsInstructionUnchecked = exports.decodeWithdrawWithheldTokensFromAccountsInstruction = exports.createWithdrawWithheldTokensFromAccountsInstruction = exports.withdrawWithheldTokensFromAccountsInstructionData = exports.decodeWithdrawWithheldTokensFromMintInstructionUnchecked = exports.decodeWithdrawWithheldTokensFromMintInstruction = exports.createWithdrawWithheldTokensFromMintInstruction = exports.withdrawWithheldTokensFromMintInstructionData = exports.decodeTransferCheckedWithFeeInstructionUnchecked = exports.decodeTransferCheckedWithFeeInstruction = exports.createTransferCheckedWithFeeInstruction = exports.transferCheckedWithFeeInstructionData = exports.decodeInitializeTransferFeeConfigInstructionUnchecked = exports.decodeInitializeTransferFeeConfigInstruction = exports.createInitializeTransferFeeConfigInstruction = exports.initializeTransferFeeConfigInstructionData = exports.TransferFeeInstruction = void 0;
exports.decodeSetTransferFeeInstructionUnchecked = exports.decodeSetTransferFeeInstruction = exports.createSetTransferFeeInstruction = exports.setTransferFeeInstructionData = exports.decodeHarvestWithheldTokensToMintInstructionUnchecked = exports.decodeHarvestWithheldTokensToMintInstruction = exports.createHarvestWithheldTokensToMintInstruction = exports.harvestWithheldTokensToMintInstructionData = exports.decodeWithdrawWithheldTokensFromAccountsInstructionUnchecked = exports.decodeWithdrawWithheldTokensFromAccountsInstruction = exports.createWithdrawWithheldTokensFromAccountsInstruction = exports.withdrawWithheldTokensFromAccountsInstructionData = exports.decodeWithdrawWithheldTokensFromMintInstructionUnchecked = exports.decodeWithdrawWithheldTokensFromMintInstruction = exports.createWithdrawWithheldTokensFromMintInstruction = exports.withdrawWithheldTokensFromMintInstructionData = exports.decodeTransferCheckedWithFeeInstructionUnchecked = exports.decodeTransferCheckedWithFeeInstruction = exports.createTransferCheckedWithFeeInstruction = exports.transferCheckedWithFeeInstructionData = exports.decodeInitializeTransferFeeConfigInstructionUnchecked = exports.decodeInitializeTransferFeeConfigInstruction = exports.createInitializeTransferFeeConfigInstruction = exports.initializeTransferFeeConfigInstructionData = exports.TransferFeeInstruction = void 0;
const buffer_layout_1 = require("@solana/buffer-layout");

@@ -483,2 +483,90 @@ const buffer_layout_utils_1 = require("@solana/buffer-layout-utils");

exports.decodeHarvestWithheldTokensToMintInstructionUnchecked = decodeHarvestWithheldTokensToMintInstructionUnchecked;
exports.setTransferFeeInstructionData = (0, buffer_layout_1.struct)([
(0, buffer_layout_1.u8)('instruction'),
(0, buffer_layout_1.u8)('transferFeeInstruction'),
(0, buffer_layout_1.u16)('transferFeeBasisPoints'),
(0, buffer_layout_utils_1.u64)('maximumFee'),
]);
/**
* Construct a SetTransferFeeInstruction instruction
*
* @param mint The token mint
* @param authority The authority of the transfer fee
* @param signers The signer account(s)
* @param transferFeeBasisPoints Amount of transfer collected as fees, expressed as basis points of the transfer amount
* @param maximumFee Maximum fee assessed on transfers
* @param programID SPL Token program account
*
* @return Instruction to add to a transaction
*/
function createSetTransferFeeInstruction(mint, authority, signers, transferFeeBasisPoints, maximumFee, programId = constants_js_1.TOKEN_2022_PROGRAM_ID) {
if (!(0, constants_js_1.programSupportsExtensions)(programId)) {
throw new errors_js_1.TokenUnsupportedInstructionError();
}
const data = Buffer.alloc(exports.setTransferFeeInstructionData.span);
exports.setTransferFeeInstructionData.encode({
instruction: types_js_1.TokenInstruction.TransferFeeExtension,
transferFeeInstruction: TransferFeeInstruction.SetTransferFee,
transferFeeBasisPoints: transferFeeBasisPoints,
maximumFee: maximumFee,
}, data);
const keys = (0, internal_js_1.addSigners)([{ pubkey: mint, isSigner: false, isWritable: true }], authority, signers);
return new web3_js_1.TransactionInstruction({ keys, programId, data });
}
exports.createSetTransferFeeInstruction = createSetTransferFeeInstruction;
/**
* Decode an SetTransferFee instruction and validate it
*
* @param instruction Transaction instruction to decode
* @param programId SPL Token program account
*
* @return Decoded, valid instruction
*/
function decodeSetTransferFeeInstruction(instruction, programId) {
if (!instruction.programId.equals(programId))
throw new errors_js_1.TokenInvalidInstructionProgramError();
if (instruction.data.length !== exports.setTransferFeeInstructionData.span)
throw new errors_js_1.TokenInvalidInstructionDataError();
const { keys: { mint, authority, signers }, data, } = decodeSetTransferFeeInstructionUnchecked(instruction);
if (data.instruction !== types_js_1.TokenInstruction.TransferFeeExtension ||
data.transferFeeInstruction !== TransferFeeInstruction.SetTransferFee)
throw new errors_js_1.TokenInvalidInstructionTypeError();
if (!mint)
throw new errors_js_1.TokenInvalidInstructionKeysError();
return {
programId,
keys: {
mint,
authority,
signers: signers ? signers : null,
},
data,
};
}
exports.decodeSetTransferFeeInstruction = decodeSetTransferFeeInstruction;
/**
* Decode a SetTransferFee instruction without validating it
*
* @param instruction Transaction instruction to decode
*
* @return Decoded, non-validated instruction
*/
function decodeSetTransferFeeInstructionUnchecked({ programId, keys: [mint, authority, ...signers], data, }) {
const { instruction, transferFeeInstruction, transferFeeBasisPoints, maximumFee } = exports.setTransferFeeInstructionData.decode(data);
return {
programId,
keys: {
mint,
authority,
signers,
},
data: {
instruction,
transferFeeInstruction,
transferFeeBasisPoints,
maximumFee,
},
};
}
exports.decodeSetTransferFeeInstructionUnchecked = decodeSetTransferFeeInstructionUnchecked;
//# sourceMappingURL=instructions.js.map

2

lib/cjs/extensions/transferHook/state.js

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

exports.getExtraAccountMetas = getExtraAccountMetas;
/** Take an ExtraAccountMeta and construct that into an acutal AccountMeta */
/** Take an ExtraAccountMeta and construct that into an actual AccountMeta */
function resolveExtraAccountMeta(connection, extraMeta, previousMetas, instructionData, transferHookProgramId) {

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

import { sendAndConfirmTransaction, Transaction } from '@solana/web3.js';
import { getSigners } from '../../actions/internal.js';
import { TOKEN_2022_PROGRAM_ID } from '../../constants.js';
import { createHarvestWithheldTokensToMintInstruction, createTransferCheckedWithFeeInstruction, createWithdrawWithheldTokensFromAccountsInstruction, createWithdrawWithheldTokensFromMintInstruction, } from './instructions.js';
import { createHarvestWithheldTokensToMintInstruction, createSetTransferFeeInstruction, createTransferCheckedWithFeeInstruction, createWithdrawWithheldTokensFromAccountsInstruction, createWithdrawWithheldTokensFromMintInstruction, } from './instructions.js';
/**

@@ -82,2 +82,22 @@ * Transfer tokens from one account to another, asserting the transfer fee, token mint, and decimals

}
/**
* Update transfer fee and maximum fee
*
* @param connection Connection to use
* @param payer Payer of the transaction fees
* @param mint The token mint
* @param authority The authority of the transfer fee
* @param multiSigners Signing accounts if `owner` is a multisig
* @param transferFeeBasisPoints Amount of transfer collected as fees, expressed as basis points of the transfer amount
* @param maximumFee Maximum fee assessed on transfers
* @param confirmOptions Options for confirming the transaction
* @param programId SPL Token program account
*
* @return Signature of the confirmed transaction
*/
export async function setTransferFee(connection, payer, mint, authority, multiSigners, transferFeeBasisPoints, maximumFee, confirmOptions, programId = TOKEN_2022_PROGRAM_ID) {
const [authorityPublicKey, signers] = getSigners(authority, multiSigners);
const transaction = new Transaction().add(createSetTransferFeeInstruction(mint, authorityPublicKey, signers, transferFeeBasisPoints, maximumFee, programId));
return await sendAndConfirmTransaction(connection, transaction, [payer, ...signers], confirmOptions);
}
//# sourceMappingURL=actions.js.map

@@ -465,2 +465,87 @@ import { struct, u16, u8 } from '@solana/buffer-layout';

}
export const setTransferFeeInstructionData = struct([
u8('instruction'),
u8('transferFeeInstruction'),
u16('transferFeeBasisPoints'),
u64('maximumFee'),
]);
/**
* Construct a SetTransferFeeInstruction instruction
*
* @param mint The token mint
* @param authority The authority of the transfer fee
* @param signers The signer account(s)
* @param transferFeeBasisPoints Amount of transfer collected as fees, expressed as basis points of the transfer amount
* @param maximumFee Maximum fee assessed on transfers
* @param programID SPL Token program account
*
* @return Instruction to add to a transaction
*/
export function createSetTransferFeeInstruction(mint, authority, signers, transferFeeBasisPoints, maximumFee, programId = TOKEN_2022_PROGRAM_ID) {
if (!programSupportsExtensions(programId)) {
throw new TokenUnsupportedInstructionError();
}
const data = Buffer.alloc(setTransferFeeInstructionData.span);
setTransferFeeInstructionData.encode({
instruction: TokenInstruction.TransferFeeExtension,
transferFeeInstruction: TransferFeeInstruction.SetTransferFee,
transferFeeBasisPoints: transferFeeBasisPoints,
maximumFee: maximumFee,
}, data);
const keys = addSigners([{ pubkey: mint, isSigner: false, isWritable: true }], authority, signers);
return new TransactionInstruction({ keys, programId, data });
}
/**
* Decode an SetTransferFee instruction and validate it
*
* @param instruction Transaction instruction to decode
* @param programId SPL Token program account
*
* @return Decoded, valid instruction
*/
export function decodeSetTransferFeeInstruction(instruction, programId) {
if (!instruction.programId.equals(programId))
throw new TokenInvalidInstructionProgramError();
if (instruction.data.length !== setTransferFeeInstructionData.span)
throw new TokenInvalidInstructionDataError();
const { keys: { mint, authority, signers }, data, } = decodeSetTransferFeeInstructionUnchecked(instruction);
if (data.instruction !== TokenInstruction.TransferFeeExtension ||
data.transferFeeInstruction !== TransferFeeInstruction.SetTransferFee)
throw new TokenInvalidInstructionTypeError();
if (!mint)
throw new TokenInvalidInstructionKeysError();
return {
programId,
keys: {
mint,
authority,
signers: signers ? signers : null,
},
data,
};
}
/**
* Decode a SetTransferFee instruction without validating it
*
* @param instruction Transaction instruction to decode
*
* @return Decoded, non-validated instruction
*/
export function decodeSetTransferFeeInstructionUnchecked({ programId, keys: [mint, authority, ...signers], data, }) {
const { instruction, transferFeeInstruction, transferFeeBasisPoints, maximumFee } = setTransferFeeInstructionData.decode(data);
return {
programId,
keys: {
mint,
authority,
signers,
},
data: {
instruction,
transferFeeInstruction,
transferFeeBasisPoints,
maximumFee,
},
};
}
//# sourceMappingURL=instructions.js.map

@@ -58,3 +58,3 @@ import { blob, greedy, seq, struct, u32, u8 } from '@solana/buffer-layout';

}
/** Take an ExtraAccountMeta and construct that into an acutal AccountMeta */
/** Take an ExtraAccountMeta and construct that into an actual AccountMeta */
export async function resolveExtraAccountMeta(connection, extraMeta, previousMetas, instructionData, transferHookProgramId) {

@@ -61,0 +61,0 @@ if (extraMeta.discriminator === 0) {

@@ -64,2 +64,18 @@ import type { ConfirmOptions, Connection, PublicKey, Signer, TransactionSignature } from '@solana/web3.js';

export declare function harvestWithheldTokensToMint(connection: Connection, payer: Signer, mint: PublicKey, sources: PublicKey[], confirmOptions?: ConfirmOptions, programId?: PublicKey): Promise<TransactionSignature>;
/**
* Update transfer fee and maximum fee
*
* @param connection Connection to use
* @param payer Payer of the transaction fees
* @param mint The token mint
* @param authority The authority of the transfer fee
* @param multiSigners Signing accounts if `owner` is a multisig
* @param transferFeeBasisPoints Amount of transfer collected as fees, expressed as basis points of the transfer amount
* @param maximumFee Maximum fee assessed on transfers
* @param confirmOptions Options for confirming the transaction
* @param programId SPL Token program account
*
* @return Signature of the confirmed transaction
*/
export declare function setTransferFee(connection: Connection, payer: Signer, mint: PublicKey, authority: Signer | PublicKey, multiSigners: Signer[], transferFeeBasisPoints: number, maximumFee: bigint, confirmOptions?: ConfirmOptions, programId?: PublicKey): Promise<TransactionSignature>;
//# sourceMappingURL=actions.d.ts.map

@@ -346,2 +346,69 @@ import type { AccountMeta, Signer, PublicKey } from '@solana/web3.js';

export declare function decodeHarvestWithheldTokensToMintInstructionUnchecked({ programId, keys: [mint, ...sources], data, }: TransactionInstruction): DecodedHarvestWithheldTokensToMintInstructionUnchecked;
export interface SetTransferFeeInstructionData {
instruction: TokenInstruction.TransferFeeExtension;
transferFeeInstruction: TransferFeeInstruction.SetTransferFee;
transferFeeBasisPoints: number;
maximumFee: bigint;
}
export declare const setTransferFeeInstructionData: import("@solana/buffer-layout").Structure<SetTransferFeeInstructionData>;
/**
* Construct a SetTransferFeeInstruction instruction
*
* @param mint The token mint
* @param authority The authority of the transfer fee
* @param signers The signer account(s)
* @param transferFeeBasisPoints Amount of transfer collected as fees, expressed as basis points of the transfer amount
* @param maximumFee Maximum fee assessed on transfers
* @param programID SPL Token program account
*
* @return Instruction to add to a transaction
*/
export declare function createSetTransferFeeInstruction(mint: PublicKey, authority: PublicKey, signers: (Signer | PublicKey)[], transferFeeBasisPoints: number, maximumFee: bigint, programId?: PublicKey): TransactionInstruction;
/** A decoded, valid SetTransferFee instruction */
export interface DecodedSetTransferFeeInstruction {
programId: PublicKey;
keys: {
mint: AccountMeta;
authority: AccountMeta;
signers: AccountMeta[] | null;
};
data: {
instruction: TokenInstruction.TransferFeeExtension;
transferFeeInstruction: TransferFeeInstruction.SetTransferFee;
transferFeeBasisPoints: number;
maximumFee: bigint;
};
}
/**
* Decode an SetTransferFee instruction and validate it
*
* @param instruction Transaction instruction to decode
* @param programId SPL Token program account
*
* @return Decoded, valid instruction
*/
export declare function decodeSetTransferFeeInstruction(instruction: TransactionInstruction, programId: PublicKey): DecodedSetTransferFeeInstruction;
/** A decoded, valid SetTransferFee instruction */
export interface DecodedSetTransferFeeInstructionUnchecked {
programId: PublicKey;
keys: {
mint: AccountMeta;
authority: AccountMeta;
signers: AccountMeta[] | undefined;
};
data: {
instruction: TokenInstruction.TransferFeeExtension;
transferFeeInstruction: TransferFeeInstruction.SetTransferFee;
transferFeeBasisPoints: number;
maximumFee: bigint;
};
}
/**
* Decode a SetTransferFee instruction without validating it
*
* @param instruction Transaction instruction to decode
*
* @return Decoded, non-validated instruction
*/
export declare function decodeSetTransferFeeInstructionUnchecked({ programId, keys: [mint, authority, ...signers], data, }: TransactionInstruction): DecodedSetTransferFeeInstructionUnchecked;
//# sourceMappingURL=instructions.d.ts.map

@@ -8,3 +8,3 @@ /// <reference types="node" />

export interface TransferHook {
/** The transfer hook update authrority */
/** The transfer hook update authority */
authority: PublicKey;

@@ -21,3 +21,3 @@ /** The transfer hook program account */

/**
* Whether or not this account is currently tranferring tokens
* Whether or not this account is currently transferring tokens
* True during the transfer hook cpi, otherwise false

@@ -57,4 +57,4 @@ */

export declare function getExtraAccountMetas(account: AccountInfo<Buffer>): ExtraAccountMeta[];
/** Take an ExtraAccountMeta and construct that into an acutal AccountMeta */
/** Take an ExtraAccountMeta and construct that into an actual AccountMeta */
export declare function resolveExtraAccountMeta(connection: Connection, extraMeta: ExtraAccountMeta, previousMetas: AccountMeta[], instructionData: Buffer, transferHookProgramId: PublicKey): Promise<AccountMeta>;
//# sourceMappingURL=state.d.ts.map
{
"name": "@solana/spl-token",
"description": "SPL Token Program JS API",
"version": "0.4.6",
"author": "Solana Labs Maintainers <maintainers@solanalabs.com>",
"repository": "https://github.com/solana-labs/solana-program-library",
"license": "Apache-2.0",
"type": "module",
"sideEffects": false,
"engines": {
"node": ">=16"
},
"files": [
"lib",
"src",
"LICENSE",
"README.md"
],
"publishConfig": {
"access": "public"
},
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"name": "@solana/spl-token",
"description": "SPL Token Program JS API",
"version": "0.4.7",
"author": "Solana Labs Maintainers <maintainers@solanalabs.com>",
"repository": "https://github.com/solana-labs/solana-program-library",
"license": "Apache-2.0",
"type": "module",
"sideEffects": false,
"engines": {
"node": ">=16"
},
"files": [
"lib",
"src",
"LICENSE",
"README.md"
],
"publishConfig": {
"access": "public"
},
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"types": "./lib/types/index.d.ts",
"exports": {
"types": "./lib/types/index.d.ts",
"exports": {
"types": "./lib/types/index.d.ts",
"require": "./lib/cjs/index.js",
"import": "./lib/esm/index.js"
},
"scripts": {
"nuke": "shx rm -rf node_modules package-lock.json || true",
"reinstall": "npm run nuke && npm install",
"clean": "shx rm -rf lib **/*.tsbuildinfo || true",
"build": "tsc --build --verbose tsconfig.all.json",
"postbuild": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
"build:program": "cargo build-sbf --manifest-path=../program/Cargo.toml && cargo build-sbf --manifest-path=../program-2022/Cargo.toml && cargo build-sbf --manifest-path=../../associated-token-account/program/Cargo.toml && cargo build-sbf --manifest-path=../transfer-hook/example/Cargo.toml",
"watch": "tsc --build --verbose --watch tsconfig.all.json",
"release": "npm run clean && npm run build",
"fmt": "prettier --write '{*,**/*}.{ts,tsx,js,jsx,json}'",
"lint": "prettier --check '{*,**/*}.{ts,tsx,js,jsx,json}' && eslint --max-warnings 0 .",
"lint:fix": "npm run fmt && eslint --fix .",
"example": "node --experimental-specifier-resolution=node --loader ts-node/esm examples/createMintAndTransferTokens.ts",
"test": "npm run test:unit && npm run test:e2e-built && npm run test:e2e-native && npm run test:e2e-2022",
"test:unit": "mocha test/unit",
"test:e2e-built": "start-server-and-test 'solana-test-validator --bpf-program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA ../../target/deploy/spl_token.so --reset --quiet' http://127.0.0.1:8899/health 'mocha test/e2e'",
"test:e2e-2022": "TEST_PROGRAM_ID=TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb start-server-and-test 'solana-test-validator --bpf-program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL ../../target/deploy/spl_associated_token_account.so --bpf-program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb ../../target/deploy/spl_token_2022.so --bpf-program TokenHookExampLe8smaVNrxTBezWTRbEwxwb1Zykrb ../../target/deploy/spl_transfer_hook_example.so --reset --quiet' http://127.0.0.1:8899/health 'mocha test/e2e*'",
"test:e2e-native": "start-server-and-test 'solana-test-validator --reset --quiet' http://127.0.0.1:8899/health 'mocha test/e2e'",
"test:build-programs": "cargo build-sbf --manifest-path ../program/Cargo.toml && cargo build-sbf --manifest-path ../program-2022/Cargo.toml && cargo build-sbf --manifest-path ../../associated-token-account/program/Cargo.toml",
"deploy": "npm run deploy:docs",
"docs": "shx rm -rf docs && typedoc && shx cp .nojekyll docs/",
"deploy:docs": "npm run docs && gh-pages --dest token/js --dist docs --dotfiles"
},
"peerDependencies": {
"@solana/web3.js": "^1.91.6"
},
"dependencies": {
"@solana/buffer-layout": "^4.0.0",
"@solana/buffer-layout-utils": "^0.2.0",
"@solana/spl-token-group": "^0.0.4",
"@solana/spl-token-metadata": "^0.1.4",
"buffer": "^6.0.3"
},
"devDependencies": {
"@solana/codecs-strings": "2.0.0-preview.2",
"@solana/spl-memo": "0.2.4",
"@solana/web3.js": "^1.91.6",
"@types/chai-as-promised": "^7.1.4",
"@types/chai": "^4.3.14",
"@types/mocha": "^10.0.6",
"@types/node": "^20.12.7",
"@types/node-fetch": "^2.6.11",
"@typescript-eslint/eslint-plugin": "^7.7.0",
"@typescript-eslint/parser": "^7.7.0",
"chai": "^5.1.0",
"chai-as-promised": "^7.1.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-require-extensions": "^0.1.1",
"gh-pages": "^6.1.1",
"mocha": "^10.4.0",
"prettier": "^3.2.5",
"process": "^0.11.10",
"shx": "^0.3.4",
"start-server-and-test": "^2.0.3",
"ts-node": "^10.9.2",
"typedoc": "^0.25.13",
"typescript": "^5.4.5"
}
}
"require": "./lib/cjs/index.js",
"import": "./lib/esm/index.js"
},
"peerDependencies": {
"@solana/web3.js": "^1.93.1"
},
"dependencies": {
"@solana/buffer-layout": "^4.0.0",
"@solana/buffer-layout-utils": "^0.2.0",
"@solana/spl-token-group": "^0.0.3",
"@solana/spl-token-metadata": "^0.1.3",
"buffer": "^6.0.3"
},
"devDependencies": {
"@solana/codecs-strings": "2.0.0-preview.3",
"@solana/spl-memo": "0.2.4",
"@solana/web3.js": "^1.93.1",
"@types/chai-as-promised": "^7.1.4",
"@types/chai": "^4.3.16",
"@types/mocha": "^10.0.7",
"@types/node": "^20.14.8",
"@types/node-fetch": "^2.6.11",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"chai": "^5.1.1",
"chai-as-promised": "^8.0.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-require-extensions": "^0.1.1",
"gh-pages": "^6.1.1",
"mocha": "^10.4.0",
"prettier": "^3.3.2",
"process": "^0.11.10",
"shx": "^0.3.4",
"start-server-and-test": "^2.0.4",
"ts-node": "^10.9.2",
"typedoc": "^0.26.2",
"typescript": "^5.5.2"
},
"scripts": {
"nuke": "shx rm -rf node_modules package-lock.json || true",
"reinstall": "npm run nuke && npm install",
"clean": "shx rm -rf lib **/*.tsbuildinfo || true",
"build": "tsc --build --verbose tsconfig.all.json",
"postbuild": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
"build:program": "cargo build-sbf --manifest-path=../program/Cargo.toml && cargo build-sbf --manifest-path=../program-2022/Cargo.toml && cargo build-sbf --manifest-path=../../associated-token-account/program/Cargo.toml && cargo build-sbf --no-default-features --manifest-path=../transfer-hook/example/Cargo.toml",
"watch": "tsc --build --verbose --watch tsconfig.all.json",
"release": "npm run clean && npm run build",
"fmt": "prettier --write '{*,**/*}.{ts,tsx,js,jsx,json}'",
"lint": "prettier --check '{*,**/*}.{ts,tsx,js,jsx,json}' && eslint --max-warnings 0 .",
"lint:fix": "npm run fmt && eslint --fix .",
"example": "node --experimental-specifier-resolution=node --loader ts-node/esm examples/createMintAndTransferTokens.ts",
"test": "npm run test:unit && npm run test:e2e-built && npm run test:e2e-native && npm run test:e2e-2022",
"test:unit": "mocha test/unit",
"test:e2e-built": "start-server-and-test 'solana-test-validator --bpf-program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA ../../target/deploy/spl_token.so --reset --quiet' http://127.0.0.1:8899/health 'mocha test/e2e'",
"test:e2e-2022": "TEST_PROGRAM_ID=TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb start-server-and-test 'solana-test-validator --bpf-program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL ../../target/deploy/spl_associated_token_account.so --bpf-program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb ../../target/deploy/spl_token_2022.so --bpf-program TokenHookExampLe8smaVNrxTBezWTRbEwxwb1Zykrb ../../target/deploy/spl_transfer_hook_example.so --reset --quiet' http://127.0.0.1:8899/health 'mocha test/e2e*'",
"test:e2e-native": "start-server-and-test 'solana-test-validator --reset --quiet' http://127.0.0.1:8899/health 'mocha test/e2e'",
"test:build-programs": "cargo build-sbf --manifest-path ../program/Cargo.toml && cargo build-sbf --manifest-path ../program-2022/Cargo.toml && cargo build-sbf --manifest-path ../../associated-token-account/program/Cargo.toml",
"deploy": "npm run deploy:docs",
"docs": "shx rm -rf docs && typedoc && shx cp .nojekyll docs/",
"deploy:docs": "npm run docs && gh-pages --dest token/js --dist docs --dotfiles"
}
}

@@ -7,2 +7,3 @@ import type { ConfirmOptions, Connection, PublicKey, Signer, TransactionSignature } from '@solana/web3.js';

createHarvestWithheldTokensToMintInstruction,
createSetTransferFeeInstruction,
createTransferCheckedWithFeeInstruction,

@@ -162,1 +163,43 @@ createWithdrawWithheldTokensFromAccountsInstruction,

}
/**
* Update transfer fee and maximum fee
*
* @param connection Connection to use
* @param payer Payer of the transaction fees
* @param mint The token mint
* @param authority The authority of the transfer fee
* @param multiSigners Signing accounts if `owner` is a multisig
* @param transferFeeBasisPoints Amount of transfer collected as fees, expressed as basis points of the transfer amount
* @param maximumFee Maximum fee assessed on transfers
* @param confirmOptions Options for confirming the transaction
* @param programId SPL Token program account
*
* @return Signature of the confirmed transaction
*/
export async function setTransferFee(
connection: Connection,
payer: Signer,
mint: PublicKey,
authority: Signer | PublicKey,
multiSigners: Signer[],
transferFeeBasisPoints: number,
maximumFee: bigint,
confirmOptions?: ConfirmOptions,
programId = TOKEN_2022_PROGRAM_ID
): Promise<TransactionSignature> {
const [authorityPublicKey, signers] = getSigners(authority, multiSigners);
const transaction = new Transaction().add(
createSetTransferFeeInstruction(
mint,
authorityPublicKey,
signers,
transferFeeBasisPoints,
maximumFee,
programId
)
);
return await sendAndConfirmTransaction(connection, transaction, [payer, ...signers], confirmOptions);
}

@@ -829,1 +829,156 @@ import { struct, u16, u8 } from '@solana/buffer-layout';

}
// SetTransferFee
export interface SetTransferFeeInstructionData {
instruction: TokenInstruction.TransferFeeExtension;
transferFeeInstruction: TransferFeeInstruction.SetTransferFee;
transferFeeBasisPoints: number;
maximumFee: bigint;
}
export const setTransferFeeInstructionData = struct<SetTransferFeeInstructionData>([
u8('instruction'),
u8('transferFeeInstruction'),
u16('transferFeeBasisPoints'),
u64('maximumFee'),
]);
/**
* Construct a SetTransferFeeInstruction instruction
*
* @param mint The token mint
* @param authority The authority of the transfer fee
* @param signers The signer account(s)
* @param transferFeeBasisPoints Amount of transfer collected as fees, expressed as basis points of the transfer amount
* @param maximumFee Maximum fee assessed on transfers
* @param programID SPL Token program account
*
* @return Instruction to add to a transaction
*/
export function createSetTransferFeeInstruction(
mint: PublicKey,
authority: PublicKey,
signers: (Signer | PublicKey)[],
transferFeeBasisPoints: number,
maximumFee: bigint,
programId = TOKEN_2022_PROGRAM_ID
): TransactionInstruction {
if (!programSupportsExtensions(programId)) {
throw new TokenUnsupportedInstructionError();
}
const data = Buffer.alloc(setTransferFeeInstructionData.span);
setTransferFeeInstructionData.encode(
{
instruction: TokenInstruction.TransferFeeExtension,
transferFeeInstruction: TransferFeeInstruction.SetTransferFee,
transferFeeBasisPoints: transferFeeBasisPoints,
maximumFee: maximumFee,
},
data
);
const keys = addSigners([{ pubkey: mint, isSigner: false, isWritable: true }], authority, signers);
return new TransactionInstruction({ keys, programId, data });
}
/** A decoded, valid SetTransferFee instruction */
export interface DecodedSetTransferFeeInstruction {
programId: PublicKey;
keys: {
mint: AccountMeta;
authority: AccountMeta;
signers: AccountMeta[] | null;
};
data: {
instruction: TokenInstruction.TransferFeeExtension;
transferFeeInstruction: TransferFeeInstruction.SetTransferFee;
transferFeeBasisPoints: number;
maximumFee: bigint;
};
}
/**
* Decode an SetTransferFee instruction and validate it
*
* @param instruction Transaction instruction to decode
* @param programId SPL Token program account
*
* @return Decoded, valid instruction
*/
export function decodeSetTransferFeeInstruction(
instruction: TransactionInstruction,
programId: PublicKey
): DecodedSetTransferFeeInstruction {
if (!instruction.programId.equals(programId)) throw new TokenInvalidInstructionProgramError();
if (instruction.data.length !== setTransferFeeInstructionData.span) throw new TokenInvalidInstructionDataError();
const {
keys: { mint, authority, signers },
data,
} = decodeSetTransferFeeInstructionUnchecked(instruction);
if (
data.instruction !== TokenInstruction.TransferFeeExtension ||
data.transferFeeInstruction !== TransferFeeInstruction.SetTransferFee
)
throw new TokenInvalidInstructionTypeError();
if (!mint) throw new TokenInvalidInstructionKeysError();
return {
programId,
keys: {
mint,
authority,
signers: signers ? signers : null,
},
data,
};
}
/** A decoded, valid SetTransferFee instruction */
export interface DecodedSetTransferFeeInstructionUnchecked {
programId: PublicKey;
keys: {
mint: AccountMeta;
authority: AccountMeta;
signers: AccountMeta[] | undefined;
};
data: {
instruction: TokenInstruction.TransferFeeExtension;
transferFeeInstruction: TransferFeeInstruction.SetTransferFee;
transferFeeBasisPoints: number;
maximumFee: bigint;
};
}
/**
* Decode a SetTransferFee instruction without validating it
*
* @param instruction Transaction instruction to decode
*
* @return Decoded, non-validated instruction
*/
export function decodeSetTransferFeeInstructionUnchecked({
programId,
keys: [mint, authority, ...signers],
data,
}: TransactionInstruction): DecodedSetTransferFeeInstructionUnchecked {
const { instruction, transferFeeInstruction, transferFeeBasisPoints, maximumFee } =
setTransferFeeInstructionData.decode(data);
return {
programId,
keys: {
mint,
authority,
signers,
},
data: {
instruction,
transferFeeInstruction,
transferFeeBasisPoints,
maximumFee,
},
};
}

@@ -13,3 +13,3 @@ import { blob, greedy, seq, struct, u32, u8 } from '@solana/buffer-layout';

export interface TransferHook {
/** The transfer hook update authrority */
/** The transfer hook update authority */
authority: PublicKey;

@@ -37,3 +37,3 @@ /** The transfer hook program account */

/**
* Whether or not this account is currently tranferring tokens
* Whether or not this account is currently transferring tokens
* True during the transfer hook cpi, otherwise false

@@ -110,3 +110,3 @@ */

/** Take an ExtraAccountMeta and construct that into an acutal AccountMeta */
/** Take an ExtraAccountMeta and construct that into an actual AccountMeta */
export async function resolveExtraAccountMeta(

@@ -113,0 +113,0 @@ connection: Connection,

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

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc