New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@saberhq/solana-contrib

Package Overview
Dependencies
Maintainers
2
Versions
181
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@saberhq/solana-contrib - npm Package Compare versions

Comparing version 1.12.20 to 1.12.21

29

dist/cjs/broadcaster.d.ts

@@ -38,2 +38,31 @@ import type { Blockhash, Commitment, ConfirmOptions, Connection, RpcResponseAndContext, SimulatedTransactionResponse, Transaction } from "@solana/web3.js";

}
/**
* Broadcasts transactions to multiple connections simultaneously.
*/
export declare class MultipleConnectionBroadcaster implements Broadcaster {
readonly connections: readonly Connection[];
readonly opts: ConfirmOptions;
constructor(connections: readonly Connection[], opts?: ConfirmOptions);
getRecentBlockhash(commitment?: Commitment): Promise<Blockhash>;
private _sendRawTransaction;
/**
* Broadcasts a signed transaction.
*
* @param tx
* @param confirm
* @param opts
* @returns
*/
broadcast(tx: Transaction, { printLogs, ...opts }?: BroadcastOptions): Promise<PendingTransaction>;
/**
* Simulates a transaction with a commitment.
* @param tx
* @param commitment
* @returns
*/
simulate(tx: Transaction, { commitment, verifySigners, }?: {
commitment?: Commitment;
verifySigners?: boolean;
}): Promise<RpcResponseAndContext<SimulatedTransactionResponse>>;
}
//# sourceMappingURL=broadcaster.d.ts.map

76

dist/cjs/broadcaster.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SingleConnectionBroadcaster = void 0;
exports.MultipleConnectionBroadcaster = exports.SingleConnectionBroadcaster = void 0;
const tslib_1 = require("tslib");

@@ -15,3 +15,3 @@ const _1 = require(".");

}
getRecentBlockhash(commitment = "recent") {
getRecentBlockhash(commitment = "processed") {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {

@@ -52,4 +52,4 @@ const result = yield this.sendConnection.getRecentBlockhash(commitment);

*/
simulate(tx, { commitment = "recent", verifySigners = true, } = {
commitment: "recent",
simulate(tx, { commitment = "processed", verifySigners = true, } = {
commitment: "processed",
verifySigners: true,

@@ -66,2 +66,70 @@ }) {

exports.SingleConnectionBroadcaster = SingleConnectionBroadcaster;
/**
* Broadcasts transactions to multiple connections simultaneously.
*/
class MultipleConnectionBroadcaster {
constructor(connections, opts = _1.DEFAULT_PROVIDER_OPTIONS) {
this.connections = connections;
this.opts = opts;
}
getRecentBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.commitment) !== null && _a !== void 0 ? _a : "processed"; }
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
const result = yield Promise.any(this.connections.map((conn) => conn.getRecentBlockhash(commitment)));
return result.blockhash;
});
}
_sendRawTransaction(encoded, options) {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
return yield Promise.any(this.connections.map((connection) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
return new _1.PendingTransaction(connection, yield connection.sendRawTransaction(encoded, options));
})));
});
}
/**
* Broadcasts a signed transaction.
*
* @param tx
* @param confirm
* @param opts
* @returns
*/
broadcast(tx, _a = this.opts) {
var { printLogs = true } = _a, opts = (0, tslib_1.__rest)(_a, ["printLogs"]);
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
if (tx.signatures.length === 0) {
throw new Error("Transaction must be signed before broadcasting.");
}
const rawTx = tx.serialize();
if (printLogs) {
return yield this._sendRawTransaction(rawTx, opts);
}
return yield (0, _1.suppressConsoleErrorAsync)(() => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
// hide the logs of TX errors if printLogs = false
return yield this._sendRawTransaction(rawTx, opts);
}));
});
}
/**
* Simulates a transaction with a commitment.
* @param tx
* @param commitment
* @returns
*/
simulate(tx, { commitment = "processed", verifySigners = true, } = {
commitment: "processed",
verifySigners: true,
}) {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
if (verifySigners && tx.signatures.length === 0) {
throw new Error("Transaction must be signed before simulating.");
}
return yield Promise.any(this.connections.map((connection) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
return yield (0, simulateTransactionWithCommitment_1.simulateTransactionWithCommitment)(connection, tx, commitment);
})));
});
}
}
exports.MultipleConnectionBroadcaster = MultipleConnectionBroadcaster;
//# sourceMappingURL=broadcaster.js.map

@@ -71,2 +71,3 @@ import type { Commitment, ConfirmOptions, Connection, KeyedAccountInfo, PublicKey, RpcResponseAndContext, Signer, SimulatedTransactionResponse, Transaction, TransactionInstruction } from "@solana/web3.js";

* Creates a new SolanaProvider.
* @deprecated use {@link SolanaProvider.init}
*/

@@ -92,2 +93,23 @@ static load({ connection, sendConnection, wallet, opts, }: {

/**
* Initializes a new SolanaProvider.
*/
static init({ connection, broadcastConnections, wallet, opts, }: {
/**
* Connection used for general reads
*/
readonly connection: Connection;
/**
* Connections used for broadcasting transactions. Defaults to the read connection.
*/
readonly broadcastConnections?: readonly Connection[];
/**
* Wallet used for signing transactions
*/
readonly wallet: Wallet;
/**
* Confirmation options
*/
readonly opts?: ConfirmOptions;
}): SolanaProvider;
/**
* Sends the given transaction, paid for and signed by the provider's wallet.

@@ -94,0 +116,0 @@ *

13

dist/cjs/provider.js

@@ -9,4 +9,4 @@ "use strict";

exports.DEFAULT_PROVIDER_OPTIONS = {
preflightCommitment: "recent",
commitment: "recent",
preflightCommitment: "processed",
commitment: "processed",
};

@@ -50,3 +50,3 @@ /**

class SolanaTransactionSigner {
constructor(wallet, broadcaster, preflightCommitment = "recent") {
constructor(wallet, broadcaster, preflightCommitment = "processed") {
this.wallet = wallet;

@@ -134,2 +134,3 @@ this.broadcaster = broadcaster;

* Creates a new SolanaProvider.
* @deprecated use {@link SolanaProvider.init}
*/

@@ -140,2 +141,8 @@ static load({ connection, sendConnection = connection, wallet, opts, }) {

/**
* Initializes a new SolanaProvider.
*/
static init({ connection, broadcastConnections = [connection], wallet, opts = exports.DEFAULT_PROVIDER_OPTIONS, }) {
return new SolanaProvider(connection, new _1.MultipleConnectionBroadcaster(broadcastConnections, opts), wallet, opts);
}
/**
* Sends the given transaction, paid for and signed by the provider's wallet.

@@ -142,0 +149,0 @@ *

@@ -85,2 +85,21 @@ import type { Cluster, ConfirmOptions, PublicKey, RpcResponseAndContext, Signer, SimulatedTransactionResponse, TransactionInstruction } from "@solana/web3.js";

* Simulates the transaction and prints a fancy table in the console.
* ```
* ┌─────┬───┬───┬───┬───────────┬──────┬─────┬──────┬───┐
* │index│iso│mar│cum│ programId │quota │used │ left │CPI│
* ├─────┼───┼───┼───┼───────────┼──────┼─────┼──────┼───┤
* │ 0 │298│281│464│'ATokenG..'│200000│24270│175730│ 1 │
* │ 1 │298│ 74│538│'ATokenG..'│178730│21270│157460│ 1 │
* │ 2 │298│ 74│612│'ATokenG..'│157460│27277│130183│ 1 │
* │ 3 │298│ 42│686│'ATokenG..'│130183│21270│108913│ 1 │
* │ 4 │338│265│951│'qExampL..'│108913│76289│ 32624│ 3 │
* └─────┴───┴───┴───┴───────────┴──────┴─────┴──────┴───┘
* ```
*
* - **index**: the array index of the instruction within the transaction
* - **iso**: the isolated size of the instruction (marginal cost of only the instruction)
* - **mar**: the marginal size cost of the instruction (when added to previous)
* - **cum**: the cumulative size of the instructions up until that instruction
* - **quota/used/left**: [BPF instruction compute unit info](https://docs.solana.com/developing/programming-model/runtime)
* - **CPI**: [the maximum depth of CPI](https://docs.solana.com/developing/programming-model/calling-between-programs) (current limit in Solana is 4)
*
* @param opts

@@ -87,0 +106,0 @@ * @returns

@@ -89,2 +89,21 @@ "use strict";

* Simulates the transaction and prints a fancy table in the console.
* ```
* ┌─────┬───┬───┬───┬───────────┬──────┬─────┬──────┬───┐
* │index│iso│mar│cum│ programId │quota │used │ left │CPI│
* ├─────┼───┼───┼───┼───────────┼──────┼─────┼──────┼───┤
* │ 0 │298│281│464│'ATokenG..'│200000│24270│175730│ 1 │
* │ 1 │298│ 74│538│'ATokenG..'│178730│21270│157460│ 1 │
* │ 2 │298│ 74│612│'ATokenG..'│157460│27277│130183│ 1 │
* │ 3 │298│ 42│686│'ATokenG..'│130183│21270│108913│ 1 │
* │ 4 │338│265│951│'qExampL..'│108913│76289│ 32624│ 3 │
* └─────┴───┴───┴───┴───────────┴──────┴─────┴──────┴───┘
* ```
*
* - **index**: the array index of the instruction within the transaction
* - **iso**: the isolated size of the instruction (marginal cost of only the instruction)
* - **mar**: the marginal size cost of the instruction (when added to previous)
* - **cum**: the cumulative size of the instructions up until that instruction
* - **quota/used/left**: [BPF instruction compute unit info](https://docs.solana.com/developing/programming-model/runtime)
* - **CPI**: [the maximum depth of CPI](https://docs.solana.com/developing/programming-model/calling-between-programs) (current limit in Solana is 4)
*
* @param opts

@@ -91,0 +110,0 @@ * @returns

import { TransactionEnvelope } from "..";
/**
* Takes in a simulation result of a transaction and prints it in a cool table.
* ```
* ┌─────┬───┬───┬───┬───────────┬──────┬─────┬──────┬───┐
* │index│iso│mar│cum│ programId │quota │used │ left │CPI│
* ├─────┼───┼───┼───┼───────────┼──────┼─────┼──────┼───┤
* │ 0 │298│281│464│'ATokenG..'│200000│24270│175730│ 1 │
* │ 1 │298│ 74│538│'ATokenG..'│178730│21270│157460│ 1 │
* │ 2 │298│ 74│612│'ATokenG..'│157460│27277│130183│ 1 │
* │ 3 │298│ 42│686│'ATokenG..'│130183│21270│108913│ 1 │
* │ 4 │338│265│951│'qExampL..'│108913│76289│ 32624│ 3 │
* └─────┴───┴───┴───┴───────────┴──────┴─────┴──────┴───┘
* ```
*
* For details about how the table works, see documentation for expectTXTable
* in @saberhq/chai-solana.
* - **index**: the array index of the instruction within the transaction
* - **iso**: the isolated size of the instruction (marginal cost of only the instruction)
* - **mar**: the marginal size cost of the instruction (when added to previous)
* - **cum**: the cumulative size of the instructions up until that instruction
* - **quota/used/left**: [BPF instruction compute unit info](https://docs.solana.com/developing/programming-model/runtime)
* - **CPI**: [the maximum depth of CPI](https://docs.solana.com/developing/programming-model/calling-between-programs) (current limit in Solana is 4)
*
* This can be safely used in a browser since it is only parsing logs.
* For usage, see expectTXTable.
* Safe for browser usage. Can be conveniently run with txEnvelope.simulateTable()
*/

@@ -11,0 +25,0 @@ export declare const printTXTable: (tx: TransactionEnvelope, transactionLogs: string[], message: string) => void;

@@ -8,14 +8,30 @@ "use strict";

* Takes in a simulation result of a transaction and prints it in a cool table.
* ```
* ┌─────┬───┬───┬───┬───────────┬──────┬─────┬──────┬───┐
* │index│iso│mar│cum│ programId │quota │used │ left │CPI│
* ├─────┼───┼───┼───┼───────────┼──────┼─────┼──────┼───┤
* │ 0 │298│281│464│'ATokenG..'│200000│24270│175730│ 1 │
* │ 1 │298│ 74│538│'ATokenG..'│178730│21270│157460│ 1 │
* │ 2 │298│ 74│612│'ATokenG..'│157460│27277│130183│ 1 │
* │ 3 │298│ 42│686│'ATokenG..'│130183│21270│108913│ 1 │
* │ 4 │338│265│951│'qExampL..'│108913│76289│ 32624│ 3 │
* └─────┴───┴───┴───┴───────────┴──────┴─────┴──────┴───┘
* ```
*
* For details about how the table works, see documentation for expectTXTable
* in @saberhq/chai-solana.
* - **index**: the array index of the instruction within the transaction
* - **iso**: the isolated size of the instruction (marginal cost of only the instruction)
* - **mar**: the marginal size cost of the instruction (when added to previous)
* - **cum**: the cumulative size of the instructions up until that instruction
* - **quota/used/left**: [BPF instruction compute unit info](https://docs.solana.com/developing/programming-model/runtime)
* - **CPI**: [the maximum depth of CPI](https://docs.solana.com/developing/programming-model/calling-between-programs) (current limit in Solana is 4)
*
* This can be safely used in a browser since it is only parsing logs.
* For usage, see expectTXTable.
* Safe for browser usage. Can be conveniently run with txEnvelope.simulateTable()
*/
const printTXTable = (tx, transactionLogs, message) => {
if (message) {
console.log();
if (message && message !== "") {
console.log((0, exports.estimateTransactionSize)(tx), message);
}
else {
console.log("Transaction size:", (0, exports.estimateTransactionSize)(tx));
}
const computeUnitLogStack = [];

@@ -22,0 +38,0 @@ const cpiLogStack = [];

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

*/
function simulateTransactionWithCommitment(connection, transaction, commitment = "recent") {
function simulateTransactionWithCommitment(connection, transaction, commitment = "processed") {
var _a;

@@ -12,0 +12,0 @@ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {

@@ -38,2 +38,31 @@ import type { Blockhash, Commitment, ConfirmOptions, Connection, RpcResponseAndContext, SimulatedTransactionResponse, Transaction } from "@solana/web3.js";

}
/**
* Broadcasts transactions to multiple connections simultaneously.
*/
export declare class MultipleConnectionBroadcaster implements Broadcaster {
readonly connections: readonly Connection[];
readonly opts: ConfirmOptions;
constructor(connections: readonly Connection[], opts?: ConfirmOptions);
getRecentBlockhash(commitment?: Commitment): Promise<Blockhash>;
private _sendRawTransaction;
/**
* Broadcasts a signed transaction.
*
* @param tx
* @param confirm
* @param opts
* @returns
*/
broadcast(tx: Transaction, { printLogs, ...opts }?: BroadcastOptions): Promise<PendingTransaction>;
/**
* Simulates a transaction with a commitment.
* @param tx
* @param commitment
* @returns
*/
simulate(tx: Transaction, { commitment, verifySigners, }?: {
commitment?: Commitment;
verifySigners?: boolean;
}): Promise<RpcResponseAndContext<SimulatedTransactionResponse>>;
}
//# sourceMappingURL=broadcaster.d.ts.map

@@ -12,3 +12,3 @@ import { __awaiter, __rest } from "tslib";

}
getRecentBlockhash(commitment = "recent") {
getRecentBlockhash(commitment = "processed") {
return __awaiter(this, void 0, void 0, function* () {

@@ -49,4 +49,4 @@ const result = yield this.sendConnection.getRecentBlockhash(commitment);

*/
simulate(tx, { commitment = "recent", verifySigners = true, } = {
commitment: "recent",
simulate(tx, { commitment = "processed", verifySigners = true, } = {
commitment: "processed",
verifySigners: true,

@@ -62,2 +62,69 @@ }) {

}
/**
* Broadcasts transactions to multiple connections simultaneously.
*/
export class MultipleConnectionBroadcaster {
constructor(connections, opts = DEFAULT_PROVIDER_OPTIONS) {
this.connections = connections;
this.opts = opts;
}
getRecentBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.commitment) !== null && _a !== void 0 ? _a : "processed"; }
return __awaiter(this, void 0, void 0, function* () {
const result = yield Promise.any(this.connections.map((conn) => conn.getRecentBlockhash(commitment)));
return result.blockhash;
});
}
_sendRawTransaction(encoded, options) {
return __awaiter(this, void 0, void 0, function* () {
return yield Promise.any(this.connections.map((connection) => __awaiter(this, void 0, void 0, function* () {
return new PendingTransaction(connection, yield connection.sendRawTransaction(encoded, options));
})));
});
}
/**
* Broadcasts a signed transaction.
*
* @param tx
* @param confirm
* @param opts
* @returns
*/
broadcast(tx, _a = this.opts) {
var { printLogs = true } = _a, opts = __rest(_a, ["printLogs"]);
return __awaiter(this, void 0, void 0, function* () {
if (tx.signatures.length === 0) {
throw new Error("Transaction must be signed before broadcasting.");
}
const rawTx = tx.serialize();
if (printLogs) {
return yield this._sendRawTransaction(rawTx, opts);
}
return yield suppressConsoleErrorAsync(() => __awaiter(this, void 0, void 0, function* () {
// hide the logs of TX errors if printLogs = false
return yield this._sendRawTransaction(rawTx, opts);
}));
});
}
/**
* Simulates a transaction with a commitment.
* @param tx
* @param commitment
* @returns
*/
simulate(tx, { commitment = "processed", verifySigners = true, } = {
commitment: "processed",
verifySigners: true,
}) {
return __awaiter(this, void 0, void 0, function* () {
if (verifySigners && tx.signatures.length === 0) {
throw new Error("Transaction must be signed before simulating.");
}
return yield Promise.any(this.connections.map((connection) => __awaiter(this, void 0, void 0, function* () {
return yield simulateTransactionWithCommitment(connection, tx, commitment);
})));
});
}
}
//# sourceMappingURL=broadcaster.js.map

@@ -71,2 +71,3 @@ import type { Commitment, ConfirmOptions, Connection, KeyedAccountInfo, PublicKey, RpcResponseAndContext, Signer, SimulatedTransactionResponse, Transaction, TransactionInstruction } from "@solana/web3.js";

* Creates a new SolanaProvider.
* @deprecated use {@link SolanaProvider.init}
*/

@@ -92,2 +93,23 @@ static load({ connection, sendConnection, wallet, opts, }: {

/**
* Initializes a new SolanaProvider.
*/
static init({ connection, broadcastConnections, wallet, opts, }: {
/**
* Connection used for general reads
*/
readonly connection: Connection;
/**
* Connections used for broadcasting transactions. Defaults to the read connection.
*/
readonly broadcastConnections?: readonly Connection[];
/**
* Wallet used for signing transactions
*/
readonly wallet: Wallet;
/**
* Confirmation options
*/
readonly opts?: ConfirmOptions;
}): SolanaProvider;
/**
* Sends the given transaction, paid for and signed by the provider's wallet.

@@ -94,0 +116,0 @@ *

import { __awaiter } from "tslib";
import { PendingTransaction, SignerWallet } from ".";
import { MultipleConnectionBroadcaster, PendingTransaction, SignerWallet, } from ".";
import { SingleConnectionBroadcaster } from "./broadcaster";
import { TransactionEnvelope } from "./transaction/TransactionEnvelope";
export const DEFAULT_PROVIDER_OPTIONS = {
preflightCommitment: "recent",
commitment: "recent",
preflightCommitment: "processed",
commitment: "processed",
};

@@ -45,3 +45,3 @@ /**

export class SolanaTransactionSigner {
constructor(wallet, broadcaster, preflightCommitment = "recent") {
constructor(wallet, broadcaster, preflightCommitment = "processed") {
this.wallet = wallet;

@@ -128,2 +128,3 @@ this.broadcaster = broadcaster;

* Creates a new SolanaProvider.
* @deprecated use {@link SolanaProvider.init}
*/

@@ -134,2 +135,8 @@ static load({ connection, sendConnection = connection, wallet, opts, }) {

/**
* Initializes a new SolanaProvider.
*/
static init({ connection, broadcastConnections = [connection], wallet, opts = DEFAULT_PROVIDER_OPTIONS, }) {
return new SolanaProvider(connection, new MultipleConnectionBroadcaster(broadcastConnections, opts), wallet, opts);
}
/**
* Sends the given transaction, paid for and signed by the provider's wallet.

@@ -136,0 +143,0 @@ *

@@ -85,2 +85,21 @@ import type { Cluster, ConfirmOptions, PublicKey, RpcResponseAndContext, Signer, SimulatedTransactionResponse, TransactionInstruction } from "@solana/web3.js";

* Simulates the transaction and prints a fancy table in the console.
* ```
* ┌─────┬───┬───┬───┬───────────┬──────┬─────┬──────┬───┐
* │index│iso│mar│cum│ programId │quota │used │ left │CPI│
* ├─────┼───┼───┼───┼───────────┼──────┼─────┼──────┼───┤
* │ 0 │298│281│464│'ATokenG..'│200000│24270│175730│ 1 │
* │ 1 │298│ 74│538│'ATokenG..'│178730│21270│157460│ 1 │
* │ 2 │298│ 74│612│'ATokenG..'│157460│27277│130183│ 1 │
* │ 3 │298│ 42│686│'ATokenG..'│130183│21270│108913│ 1 │
* │ 4 │338│265│951│'qExampL..'│108913│76289│ 32624│ 3 │
* └─────┴───┴───┴───┴───────────┴──────┴─────┴──────┴───┘
* ```
*
* - **index**: the array index of the instruction within the transaction
* - **iso**: the isolated size of the instruction (marginal cost of only the instruction)
* - **mar**: the marginal size cost of the instruction (when added to previous)
* - **cum**: the cumulative size of the instructions up until that instruction
* - **quota/used/left**: [BPF instruction compute unit info](https://docs.solana.com/developing/programming-model/runtime)
* - **CPI**: [the maximum depth of CPI](https://docs.solana.com/developing/programming-model/calling-between-programs) (current limit in Solana is 4)
*
* @param opts

@@ -87,0 +106,0 @@ * @returns

@@ -86,2 +86,21 @@ import { __awaiter } from "tslib";

* Simulates the transaction and prints a fancy table in the console.
* ```
* ┌─────┬───┬───┬───┬───────────┬──────┬─────┬──────┬───┐
* │index│iso│mar│cum│ programId │quota │used │ left │CPI│
* ├─────┼───┼───┼───┼───────────┼──────┼─────┼──────┼───┤
* │ 0 │298│281│464│'ATokenG..'│200000│24270│175730│ 1 │
* │ 1 │298│ 74│538│'ATokenG..'│178730│21270│157460│ 1 │
* │ 2 │298│ 74│612│'ATokenG..'│157460│27277│130183│ 1 │
* │ 3 │298│ 42│686│'ATokenG..'│130183│21270│108913│ 1 │
* │ 4 │338│265│951│'qExampL..'│108913│76289│ 32624│ 3 │
* └─────┴───┴───┴───┴───────────┴──────┴─────┴──────┴───┘
* ```
*
* - **index**: the array index of the instruction within the transaction
* - **iso**: the isolated size of the instruction (marginal cost of only the instruction)
* - **mar**: the marginal size cost of the instruction (when added to previous)
* - **cum**: the cumulative size of the instructions up until that instruction
* - **quota/used/left**: [BPF instruction compute unit info](https://docs.solana.com/developing/programming-model/runtime)
* - **CPI**: [the maximum depth of CPI](https://docs.solana.com/developing/programming-model/calling-between-programs) (current limit in Solana is 4)
*
* @param opts

@@ -88,0 +107,0 @@ * @returns

import { TransactionEnvelope } from "..";
/**
* Takes in a simulation result of a transaction and prints it in a cool table.
* ```
* ┌─────┬───┬───┬───┬───────────┬──────┬─────┬──────┬───┐
* │index│iso│mar│cum│ programId │quota │used │ left │CPI│
* ├─────┼───┼───┼───┼───────────┼──────┼─────┼──────┼───┤
* │ 0 │298│281│464│'ATokenG..'│200000│24270│175730│ 1 │
* │ 1 │298│ 74│538│'ATokenG..'│178730│21270│157460│ 1 │
* │ 2 │298│ 74│612│'ATokenG..'│157460│27277│130183│ 1 │
* │ 3 │298│ 42│686│'ATokenG..'│130183│21270│108913│ 1 │
* │ 4 │338│265│951│'qExampL..'│108913│76289│ 32624│ 3 │
* └─────┴───┴───┴───┴───────────┴──────┴─────┴──────┴───┘
* ```
*
* For details about how the table works, see documentation for expectTXTable
* in @saberhq/chai-solana.
* - **index**: the array index of the instruction within the transaction
* - **iso**: the isolated size of the instruction (marginal cost of only the instruction)
* - **mar**: the marginal size cost of the instruction (when added to previous)
* - **cum**: the cumulative size of the instructions up until that instruction
* - **quota/used/left**: [BPF instruction compute unit info](https://docs.solana.com/developing/programming-model/runtime)
* - **CPI**: [the maximum depth of CPI](https://docs.solana.com/developing/programming-model/calling-between-programs) (current limit in Solana is 4)
*
* This can be safely used in a browser since it is only parsing logs.
* For usage, see expectTXTable.
* Safe for browser usage. Can be conveniently run with txEnvelope.simulateTable()
*/

@@ -11,0 +25,0 @@ export declare const printTXTable: (tx: TransactionEnvelope, transactionLogs: string[], message: string) => void;

@@ -5,14 +5,30 @@ import { Keypair, SystemProgram } from "@solana/web3.js";

* Takes in a simulation result of a transaction and prints it in a cool table.
* ```
* ┌─────┬───┬───┬───┬───────────┬──────┬─────┬──────┬───┐
* │index│iso│mar│cum│ programId │quota │used │ left │CPI│
* ├─────┼───┼───┼───┼───────────┼──────┼─────┼──────┼───┤
* │ 0 │298│281│464│'ATokenG..'│200000│24270│175730│ 1 │
* │ 1 │298│ 74│538│'ATokenG..'│178730│21270│157460│ 1 │
* │ 2 │298│ 74│612│'ATokenG..'│157460│27277│130183│ 1 │
* │ 3 │298│ 42│686│'ATokenG..'│130183│21270│108913│ 1 │
* │ 4 │338│265│951│'qExampL..'│108913│76289│ 32624│ 3 │
* └─────┴───┴───┴───┴───────────┴──────┴─────┴──────┴───┘
* ```
*
* For details about how the table works, see documentation for expectTXTable
* in @saberhq/chai-solana.
* - **index**: the array index of the instruction within the transaction
* - **iso**: the isolated size of the instruction (marginal cost of only the instruction)
* - **mar**: the marginal size cost of the instruction (when added to previous)
* - **cum**: the cumulative size of the instructions up until that instruction
* - **quota/used/left**: [BPF instruction compute unit info](https://docs.solana.com/developing/programming-model/runtime)
* - **CPI**: [the maximum depth of CPI](https://docs.solana.com/developing/programming-model/calling-between-programs) (current limit in Solana is 4)
*
* This can be safely used in a browser since it is only parsing logs.
* For usage, see expectTXTable.
* Safe for browser usage. Can be conveniently run with txEnvelope.simulateTable()
*/
export const printTXTable = (tx, transactionLogs, message) => {
if (message) {
console.log();
if (message && message !== "") {
console.log(estimateTransactionSize(tx), message);
}
else {
console.log("Transaction size:", estimateTransactionSize(tx));
}
const computeUnitLogStack = [];

@@ -19,0 +35,0 @@ const cpiLogStack = [];

@@ -6,3 +6,3 @@ import { __awaiter } from "tslib";

*/
export function simulateTransactionWithCommitment(connection, transaction, commitment = "recent") {
export function simulateTransactionWithCommitment(connection, transaction, commitment = "processed") {
var _a;

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

{
"name": "@saberhq/solana-contrib",
"version": "1.12.20",
"version": "1.12.21",
"description": "Common types and libraries for Solana",

@@ -37,3 +37,3 @@ "author": "Ian Macalinao <ian@saber.so>",

"@types/jest": "^27.4.0",
"@types/node": "^16.11.17"
"@types/node": "^16.11.19"
},

@@ -43,3 +43,3 @@ "peerDependencies": {

},
"gitHead": "aae8250df060191e4d7a0a0b7a7d228f76f454b8",
"gitHead": "2aff86d221c17e46d6d5285a966eb8989f804c40",
"publishConfig": {

@@ -46,0 +46,0 @@ "access": "public"

@@ -7,2 +7,3 @@ import type {

RpcResponseAndContext,
SendOptions,
SimulatedTransactionResponse,

@@ -37,3 +38,3 @@ Transaction,

async getRecentBlockhash(
commitment: Commitment = "recent"
commitment: Commitment = "processed"
): Promise<Blockhash> {

@@ -86,3 +87,3 @@ const result = await this.sendConnection.getRecentBlockhash(commitment);

{
commitment = "recent",
commitment = "processed",
verifySigners = true,

@@ -93,3 +94,3 @@ }: {

} = {
commitment: "recent",
commitment: "processed",
verifySigners: true,

@@ -108,1 +109,94 @@ }

}
/**
* Broadcasts transactions to multiple connections simultaneously.
*/
export class MultipleConnectionBroadcaster implements Broadcaster {
constructor(
readonly connections: readonly Connection[],
readonly opts: ConfirmOptions = DEFAULT_PROVIDER_OPTIONS
) {}
async getRecentBlockhash(
commitment: Commitment = this.opts.commitment ?? "processed"
): Promise<Blockhash> {
const result = await Promise.any(
this.connections.map((conn) => conn.getRecentBlockhash(commitment))
);
return result.blockhash;
}
private async _sendRawTransaction(
encoded: Buffer,
options?: SendOptions
): Promise<PendingTransaction> {
return await Promise.any(
this.connections.map(async (connection) => {
return new PendingTransaction(
connection,
await connection.sendRawTransaction(encoded, options)
);
})
);
}
/**
* Broadcasts a signed transaction.
*
* @param tx
* @param confirm
* @param opts
* @returns
*/
async broadcast(
tx: Transaction,
{ printLogs = true, ...opts }: BroadcastOptions = this.opts
): Promise<PendingTransaction> {
if (tx.signatures.length === 0) {
throw new Error("Transaction must be signed before broadcasting.");
}
const rawTx = tx.serialize();
if (printLogs) {
return await this._sendRawTransaction(rawTx, opts);
}
return await suppressConsoleErrorAsync(async () => {
// hide the logs of TX errors if printLogs = false
return await this._sendRawTransaction(rawTx, opts);
});
}
/**
* Simulates a transaction with a commitment.
* @param tx
* @param commitment
* @returns
*/
async simulate(
tx: Transaction,
{
commitment = "processed",
verifySigners = true,
}: {
commitment?: Commitment;
verifySigners?: boolean;
} = {
commitment: "processed",
verifySigners: true,
}
): Promise<RpcResponseAndContext<SimulatedTransactionResponse>> {
if (verifySigners && tx.signatures.length === 0) {
throw new Error("Transaction must be signed before simulating.");
}
return await Promise.any(
this.connections.map(async (connection) => {
return await simulateTransactionWithCommitment(
connection,
tx,
commitment
);
})
);
}
}

@@ -15,3 +15,7 @@ import type {

import type { Broadcaster, ReadonlyProvider } from ".";
import { PendingTransaction, SignerWallet } from ".";
import {
MultipleConnectionBroadcaster,
PendingTransaction,
SignerWallet,
} from ".";
import { SingleConnectionBroadcaster } from "./broadcaster";

@@ -27,4 +31,4 @@ import type {

export const DEFAULT_PROVIDER_OPTIONS: ConfirmOptions = {
preflightCommitment: "recent",
commitment: "recent",
preflightCommitment: "processed",
commitment: "processed",
};

@@ -74,3 +78,3 @@

readonly broadcaster: Broadcaster,
readonly preflightCommitment: Commitment = "recent"
readonly preflightCommitment: Commitment = "processed"
) {}

@@ -181,2 +185,3 @@

* Creates a new SolanaProvider.
* @deprecated use {@link SolanaProvider.init}
*/

@@ -215,2 +220,36 @@ static load({

/**
* Initializes a new SolanaProvider.
*/
static init({
connection,
broadcastConnections = [connection],
wallet,
opts = DEFAULT_PROVIDER_OPTIONS,
}: {
/**
* Connection used for general reads
*/
readonly connection: Connection;
/**
* Connections used for broadcasting transactions. Defaults to the read connection.
*/
readonly broadcastConnections?: readonly Connection[];
/**
* Wallet used for signing transactions
*/
readonly wallet: Wallet;
/**
* Confirmation options
*/
readonly opts?: ConfirmOptions;
}): SolanaProvider {
return new SolanaProvider(
connection,
new MultipleConnectionBroadcaster(broadcastConnections, opts),
wallet,
opts
);
}
/**
* Sends the given transaction, paid for and signed by the provider's wallet.

@@ -217,0 +256,0 @@ *

@@ -127,2 +127,21 @@ import type {

* Simulates the transaction and prints a fancy table in the console.
* ```
* ┌─────┬───┬───┬───┬───────────┬──────┬─────┬──────┬───┐
* │index│iso│mar│cum│ programId │quota │used │ left │CPI│
* ├─────┼───┼───┼───┼───────────┼──────┼─────┼──────┼───┤
* │ 0 │298│281│464│'ATokenG..'│200000│24270│175730│ 1 │
* │ 1 │298│ 74│538│'ATokenG..'│178730│21270│157460│ 1 │
* │ 2 │298│ 74│612│'ATokenG..'│157460│27277│130183│ 1 │
* │ 3 │298│ 42│686│'ATokenG..'│130183│21270│108913│ 1 │
* │ 4 │338│265│951│'qExampL..'│108913│76289│ 32624│ 3 │
* └─────┴───┴───┴───┴───────────┴──────┴─────┴──────┴───┘
* ```
*
* - **index**: the array index of the instruction within the transaction
* - **iso**: the isolated size of the instruction (marginal cost of only the instruction)
* - **mar**: the marginal size cost of the instruction (when added to previous)
* - **cum**: the cumulative size of the instructions up until that instruction
* - **quota/used/left**: [BPF instruction compute unit info](https://docs.solana.com/developing/programming-model/runtime)
* - **CPI**: [the maximum depth of CPI](https://docs.solana.com/developing/programming-model/calling-between-programs) (current limit in Solana is 4)
*
* @param opts

@@ -129,0 +148,0 @@ * @returns

@@ -9,8 +9,22 @@ import type { Signer, TransactionInstruction } from "@solana/web3.js";

* Takes in a simulation result of a transaction and prints it in a cool table.
* ```
* ┌─────┬───┬───┬───┬───────────┬──────┬─────┬──────┬───┐
* │index│iso│mar│cum│ programId │quota │used │ left │CPI│
* ├─────┼───┼───┼───┼───────────┼──────┼─────┼──────┼───┤
* │ 0 │298│281│464│'ATokenG..'│200000│24270│175730│ 1 │
* │ 1 │298│ 74│538│'ATokenG..'│178730│21270│157460│ 1 │
* │ 2 │298│ 74│612│'ATokenG..'│157460│27277│130183│ 1 │
* │ 3 │298│ 42│686│'ATokenG..'│130183│21270│108913│ 1 │
* │ 4 │338│265│951│'qExampL..'│108913│76289│ 32624│ 3 │
* └─────┴───┴───┴───┴───────────┴──────┴─────┴──────┴───┘
* ```
*
* For details about how the table works, see documentation for expectTXTable
* in @saberhq/chai-solana.
* - **index**: the array index of the instruction within the transaction
* - **iso**: the isolated size of the instruction (marginal cost of only the instruction)
* - **mar**: the marginal size cost of the instruction (when added to previous)
* - **cum**: the cumulative size of the instructions up until that instruction
* - **quota/used/left**: [BPF instruction compute unit info](https://docs.solana.com/developing/programming-model/runtime)
* - **CPI**: [the maximum depth of CPI](https://docs.solana.com/developing/programming-model/calling-between-programs) (current limit in Solana is 4)
*
* This can be safely used in a browser since it is only parsing logs.
* For usage, see expectTXTable.
* Safe for browser usage. Can be conveniently run with txEnvelope.simulateTable()
*/

@@ -22,5 +36,6 @@ export const printTXTable = (

) => {
if (message) {
console.log();
if (message && message !== "") {
console.log(estimateTransactionSize(tx), message);
} else {
console.log("Transaction size:", estimateTransactionSize(tx));
}

@@ -27,0 +42,0 @@

@@ -16,3 +16,3 @@ import type {

transaction: Transaction,
commitment: Commitment = "recent"
commitment: Commitment = "processed"
): Promise<RpcResponseAndContext<SimulatedTransactionResponse>> {

@@ -19,0 +19,0 @@ const connectionInner = connection as 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

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

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc