Huge News!Announcing our $40M Series B led by Abstract Ventures.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 2.0.0 to 3.0.0

46

dist/cjs/broadcaster/index.js

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

retryTimes: 3,
retryInterval: 1000,
retryInterval: 1_000,
};

@@ -31,2 +31,4 @@ /**

class SingleConnectionBroadcaster {
sendConnection;
opts;
constructor(sendConnection, opts = provider_js_1.DEFAULT_PROVIDER_OPTIONS) {

@@ -39,5 +41,3 @@ this.sendConnection = sendConnection;

*/
async getLatestBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.commitment) !== null && _a !== void 0 ? _a : "confirmed"; }
async getLatestBlockhash(commitment = this.opts.commitment ?? "confirmed") {
return await this.sendConnection.getLatestBlockhash(commitment);

@@ -48,5 +48,3 @@ }

*/
async getRecentBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.commitment) !== null && _a !== void 0 ? _a : "confirmed"; }
async getRecentBlockhash(commitment = this.opts.commitment ?? "confirmed") {
const result = await this.sendConnection.getLatestBlockhash(commitment);

@@ -74,8 +72,6 @@ return result.blockhash;

*/
async simulate(tx, _a) {
var _b, _c;
var { commitment = (_b = this.opts.preflightCommitment) !== null && _b !== void 0 ? _b : "confirmed", verifySigners = true, } = _a === void 0 ? {
commitment: (_c = this.opts.preflightCommitment) !== null && _c !== void 0 ? _c : "confirmed",
verifySigners: true,
} : _a;
async simulate(tx, { commitment = this.opts.preflightCommitment ?? "confirmed", verifySigners = true, } = {
commitment: this.opts.preflightCommitment ?? "confirmed",
verifySigners: true,
}) {
if (verifySigners && tx.signatures.length === 0) {

@@ -92,2 +88,4 @@ throw new Error("Transaction must be signed before simulating.");

class MultipleConnectionBroadcaster {
connections;
opts;
constructor(connections, opts = provider_js_1.DEFAULT_PROVIDER_OPTIONS) {

@@ -97,5 +95,3 @@ this.connections = connections;

}
async getLatestBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.preflightCommitment) !== null && _a !== void 0 ? _a : "confirmed"; }
async getLatestBlockhash(commitment = this.opts.preflightCommitment ?? "confirmed") {
try {

@@ -114,5 +110,3 @@ const result = await Promise.any(this.connections.map((conn) => conn.getLatestBlockhash(commitment)));

}
async getRecentBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.preflightCommitment) !== null && _a !== void 0 ? _a : "confirmed"; }
async getRecentBlockhash(commitment = this.opts.preflightCommitment ?? "confirmed") {
try {

@@ -134,3 +128,3 @@ const result = await Promise.any(this.connections.map((conn) => conn.getLatestBlockhash(commitment)));

return await Promise.any(this.connections.map(async (connection) => {
return new index_js_1.PendingTransaction(connection, await (0, sendAndSpamRawTx_js_1.sendAndSpamRawTx)(connection, encoded, options !== null && options !== void 0 ? options : this.opts));
return new index_js_1.PendingTransaction(connection, await (0, sendAndSpamRawTx_js_1.sendAndSpamRawTx)(connection, encoded, options ?? this.opts));
}));

@@ -174,8 +168,8 @@ }

*/
async simulate(tx, _a) {
var _b, _c, _d, _e;
var { commitment = (_c = (_b = this.opts.preflightCommitment) !== null && _b !== void 0 ? _b : this.opts.commitment) !== null && _c !== void 0 ? _c : "confirmed", verifySigners = true, } = _a === void 0 ? {
commitment: (_e = (_d = this.opts.preflightCommitment) !== null && _d !== void 0 ? _d : this.opts.commitment) !== null && _e !== void 0 ? _e : "confirmed",
verifySigners: true,
} : _a;
async simulate(tx, { commitment = this.opts.preflightCommitment ??
this.opts.commitment ??
"confirmed", verifySigners = true, } = {
commitment: this.opts.preflightCommitment ?? this.opts.commitment ?? "confirmed",
verifySigners: true,
}) {
if (verifySigners && tx.signatures.length === 0) {

@@ -182,0 +176,0 @@ throw new Error("Transaction must be signed before simulating.");

@@ -13,2 +13,6 @@ "use strict";

class TieredBroadcaster {
primaryConnection;
fallbackConnections;
opts;
premiumBroadcaster;
constructor(primaryConnection,

@@ -24,19 +28,14 @@ /**

}
async getLatestBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.preflightCommitment) !== null && _a !== void 0 ? _a : "confirmed"; }
async getLatestBlockhash(commitment = this.opts.preflightCommitment ?? "confirmed") {
return await this.premiumBroadcaster.getLatestBlockhash(commitment);
}
async getRecentBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.preflightCommitment) !== null && _a !== void 0 ? _a : "confirmed"; }
async getRecentBlockhash(commitment = this.opts.preflightCommitment ?? "confirmed") {
return await this.premiumBroadcaster.getRecentBlockhash(commitment);
}
async _sendRawTransaction(encoded, options) {
const pending = new index_js_1.PendingTransaction(this.primaryConnection, await (0, sendAndSpamRawTx_js_1.sendAndSpamRawTx)(this.primaryConnection, encoded, options !== null && options !== void 0 ? options : this.opts, options !== null && options !== void 0 ? options : index_js_3.DEFAULT_RETRY_OPTIONS));
const pending = new index_js_1.PendingTransaction(this.primaryConnection, await (0, sendAndSpamRawTx_js_1.sendAndSpamRawTx)(this.primaryConnection, encoded, options ?? this.opts, options ?? index_js_3.DEFAULT_RETRY_OPTIONS));
void (async () => {
await Promise.all(this.fallbackConnections.map(async (fc) => {
var _a;
try {
await (0, sendAndSpamRawTx_js_1.sendAndSpamRawTx)(fc, encoded, options !== null && options !== void 0 ? options : this.opts, (_a = options === null || options === void 0 ? void 0 : options.fallbackRetryOptions) !== null && _a !== void 0 ? _a : index_js_3.DEFAULT_FALLBACK_RETRY_OPTIONS);
await (0, sendAndSpamRawTx_js_1.sendAndSpamRawTx)(fc, encoded, options ?? this.opts, options?.fallbackRetryOptions ?? index_js_3.DEFAULT_FALLBACK_RETRY_OPTIONS);
}

@@ -77,8 +76,6 @@ catch (e) {

*/
async simulate(tx, _a) {
var _b, _c;
var { commitment = (_b = this.opts.preflightCommitment) !== null && _b !== void 0 ? _b : "confirmed", verifySigners = true, } = _a === void 0 ? {
commitment: (_c = this.opts.preflightCommitment) !== null && _c !== void 0 ? _c : "confirmed",
verifySigners: true,
} : _a;
async simulate(tx, { commitment = this.opts.preflightCommitment ?? "confirmed", verifySigners = true, } = {
commitment: this.opts.preflightCommitment ?? "confirmed",
verifySigners: true,
}) {
if (verifySigners && tx.signatures.length === 0) {

@@ -85,0 +82,0 @@ throw new Error("Transaction must be signed before simulating.");

@@ -19,2 +19,5 @@ "use strict";

class SolanaReadonlyProvider {
connection;
opts;
publicKey;
/**

@@ -30,7 +33,2 @@ * @param connection The cluster connection where the program is deployed.

this.wallet = {
signTransaction: Promise.resolve.bind(Promise),
signAllTransactions: Promise.resolve.bind(Promise),
publicKey: exports.DEFAULT_READONLY_PUBLIC_KEY,
};
this.wallet = {
...this.wallet,

@@ -40,2 +38,7 @@ publicKey,

}
wallet = {
signTransaction: Promise.resolve.bind(Promise),
signAllTransactions: Promise.resolve.bind(Promise),
publicKey: exports.DEFAULT_READONLY_PUBLIC_KEY,
};
/**

@@ -60,3 +63,3 @@ * Gets

const tx = await wallet.signTransaction(transaction);
if ((opts === null || opts === void 0 ? void 0 : opts.signers) && opts.signers.length > 0) {
if (opts?.signers && opts.signers.length > 0) {
tx.sign(...opts.signers);

@@ -71,2 +74,5 @@ }

class SolanaTransactionSigner {
wallet;
broadcaster;
preflightCommitment;
constructor(wallet, broadcaster, preflightCommitment = "confirmed") {

@@ -136,2 +142,7 @@ this.wallet = wallet;

class SolanaProvider extends SolanaReadonlyProvider {
connection;
broadcaster;
wallet;
opts;
signer;
/**

@@ -221,2 +232,3 @@ * @param connection The cluster connection where the program is deployed.

class SolanaAugmentedProvider {
provider;
constructor(provider) {

@@ -223,0 +235,0 @@ this.provider = provider;

@@ -29,5 +29,4 @@ "use strict";

logs.forEach((log) => {
var _a, _b, _c, _d, _e;
if (log.startsWith("Program log:")) {
(_a = prettyLogs[prettyLogs.length - 1]) === null || _a === void 0 ? void 0 : _a.logs.push({
prettyLogs[prettyLogs.length - 1]?.logs.push({
type: "text",

@@ -42,3 +41,3 @@ depth,

if (matches.length > 0) {
const programAddress = (_b = matches[0]) === null || _b === void 0 ? void 0 : _b[1];
const programAddress = matches[0]?.[1];
(0, tiny_invariant_1.default)(programAddress, "program address");

@@ -53,6 +52,6 @@ if (depth === 0) {

else {
(_c = prettyLogs[prettyLogs.length - 1]) === null || _c === void 0 ? void 0 : _c.logs.push({
prettyLogs[prettyLogs.length - 1]?.logs.push({
type: "cpi",
depth,
programAddress: programAddress !== null && programAddress !== void 0 ? programAddress : null,
programAddress: programAddress ?? null,
});

@@ -63,3 +62,3 @@ }

else if (log.includes("success")) {
(_d = prettyLogs[prettyLogs.length - 1]) === null || _d === void 0 ? void 0 : _d.logs.push({
prettyLogs[prettyLogs.length - 1]?.logs.push({
type: "success",

@@ -91,3 +90,3 @@ depth,

// system transactions don't start with "Program log:"
(_e = prettyLogs[prettyLogs.length - 1]) === null || _e === void 0 ? void 0 : _e.logs.push({
prettyLogs[prettyLogs.length - 1]?.logs.push({
type: "system",

@@ -94,0 +93,0 @@ depth,

@@ -12,6 +12,8 @@ "use strict";

class PendingTransaction {
connection;
signature;
_receipt = null;
constructor(connection, signature) {
this.connection = connection;
this.signature = signature;
this._receipt = null;
}

@@ -18,0 +20,0 @@ /**

@@ -27,2 +27,5 @@ "use strict";

class TransactionEnvelope {
provider;
instructions;
signers;
constructor(

@@ -247,4 +250,3 @@ /**

return this.simulate(opts).then((simulation) => {
var _a;
if ((_a = simulation === null || simulation === void 0 ? void 0 : simulation.value) === null || _a === void 0 ? void 0 : _a.logs) {
if (simulation?.value?.logs) {
(0, index_js_2.printTXTable)(this, simulation.value.logs, "");

@@ -420,6 +422,5 @@ }

.map((ix) => {
var _a;
const programId = ix.programId;
if (programId.equals(ASSOCIATED_TOKEN_PROGRAM_ID)) {
const ataKey = (_a = ix.keys[1]) === null || _a === void 0 ? void 0 : _a.pubkey.toString();
const ataKey = ix.keys[1]?.pubkey.toString();
if (!ataKey) {

@@ -426,0 +427,0 @@ throw new Error("ATA key does not exist on ATA instruction");

@@ -36,2 +36,4 @@ "use strict";

class TransactionReceipt {
signature;
response;
constructor(

@@ -53,4 +55,3 @@ /**

getEvents(eventParser) {
var _a;
const logs = (_a = this.response.meta) === null || _a === void 0 ? void 0 : _a.logMessages;
const logs = this.response.meta?.logMessages;
if (logs && logs.length > 0) {

@@ -65,4 +66,3 @@ return eventParser(logs);

printLogs() {
var _a, _b;
console.log((_b = (_a = this.response.meta) === null || _a === void 0 ? void 0 : _a.logMessages) === null || _b === void 0 ? void 0 : _b.join("\n"));
console.log(this.response.meta?.logMessages?.join("\n"));
}

@@ -74,4 +74,3 @@ /**

get computeUnits() {
var _a;
const logs = (_a = this.response.meta) === null || _a === void 0 ? void 0 : _a.logMessages;
const logs = this.response.meta?.logMessages;
(0, tiny_invariant_1.default)(logs, "no logs");

@@ -78,0 +77,0 @@ const consumeLog = logs[logs.length - 2];

@@ -39,3 +39,2 @@ "use strict";

async function printAccountOwners(connection, plainObj) {
var _a, _b;
try {

@@ -47,3 +46,3 @@ if (typeof plainObj !== "object") {

let relativePath;
const callStack = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n");
const callStack = new Error().stack?.split("\n");
if (callStack) {

@@ -65,3 +64,3 @@ let expectIndex = callStack.findIndex((l) => l.includes(`at ${printAccountOwners.name}`));

if (targetLine) {
const cwd = ((_b = maybeProcess.cwd) === null || _b === void 0 ? void 0 : _b.call(maybeProcess)) || "/";
const cwd = maybeProcess.cwd?.() || "/";
// get the part of targetLine after cwd

@@ -101,3 +100,2 @@ const targetLineAfterCwd = targetLine.substring(targetLine.indexOf(cwd) + cwd.length);

async function gracefulGetMultipleAccountsInfo(connection, publicKeys) {
var _a;
try {

@@ -116,3 +114,3 @@ // To be honest, the web3 internals aren't going to change that much. And if

]);
const value = (_a = unsafeRes === null || unsafeRes === void 0 ? void 0 : unsafeRes.result) === null || _a === void 0 ? void 0 : _a.value;
const value = unsafeRes?.result?.value;
if (value) {

@@ -172,3 +170,3 @@ return value;

const accountInfo = accountInfos[lookupIndex];
const owner = accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.owner;
const owner = accountInfo?.owner;
if (owner) {

@@ -175,0 +173,0 @@ result[resultKey] = `${base58} (${owner})`;

@@ -60,4 +60,6 @@ "use strict";

const computeUnitLog = computeUnitLogStack[i];
const computeUnitMatch = computeUnitLog === null || computeUnitLog === void 0 ? void 0 : computeUnitLog.match(/consumed (\d*) of (\d*)/);
const [consumed, quota] = (computeUnitMatch === null || computeUnitMatch === void 0 ? void 0 : computeUnitMatch.slice(1, 3).map((num) => parseInt(num, 10))) || [undefined, undefined];
const computeUnitMatch = computeUnitLog?.match(/consumed (\d*) of (\d*)/);
const [consumed, quota] = computeUnitMatch
?.slice(1, 3)
.map((num) => parseInt(num, 10)) || [undefined, undefined];
instructionTable.push({

@@ -78,2 +80,3 @@ iso: isolatedInstructionSize(tx.provider, instruction),

class TXSizeEstimationError extends Error {
underlyingError;
constructor(underlyingError) {

@@ -87,2 +90,4 @@ super(`could not estimate transaction size`);

class EstimatedTXTooBigError extends Error {
tx;
size;
constructor(tx, size) {

@@ -89,0 +94,0 @@ super(`Transaction too large`);

@@ -10,2 +10,3 @@ "use strict";

class CachedPublicKey extends web3_js_1.PublicKey {
_base58;
constructor(value) {

@@ -12,0 +13,0 @@ super(value);

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

async function simulateTransactionWithCommitment(connection, transaction, commitment = "confirmed") {
var _a;
const connectionInner = connection;

@@ -27,3 +26,3 @@ // only populate recent blockhash if it isn't on the tx

if (res.error) {
throw new web3_js_1.SendTransactionError("failed to simulate transaction: " + res.error.message, (_a = res.result.value.logs) !== null && _a !== void 0 ? _a : undefined);
throw new web3_js_1.SendTransactionError("failed to simulate transaction: " + res.error.message, res.result.value.logs ?? undefined);
}

@@ -30,0 +29,0 @@ return res.result;

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

*/
const dateToTs = (date) => new bn_js_1.default(Math.floor(date.getTime() / 1000));
const dateToTs = (date) => new bn_js_1.default(Math.floor(date.getTime() / 1_000));
exports.dateToTs = dateToTs;

@@ -19,4 +19,4 @@ /**

*/
const tsToDate = (ts) => new Date(ts.toNumber() * 1000);
const tsToDate = (ts) => new Date(ts.toNumber() * 1_000);
exports.tsToDate = tsToDate;
//# sourceMappingURL=time.js.map

@@ -10,2 +10,3 @@ "use strict";

class SignerWallet {
signer;
constructor(signer) {

@@ -12,0 +13,0 @@ this.signer = signer;

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

retryTimes: 3,
retryInterval: 1000,
retryInterval: 1_000,
};

@@ -31,2 +31,4 @@ /**

class SingleConnectionBroadcaster {
sendConnection;
opts;
constructor(sendConnection, opts = provider_js_1.DEFAULT_PROVIDER_OPTIONS) {

@@ -39,5 +41,3 @@ this.sendConnection = sendConnection;

*/
async getLatestBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.commitment) !== null && _a !== void 0 ? _a : "confirmed"; }
async getLatestBlockhash(commitment = this.opts.commitment ?? "confirmed") {
return await this.sendConnection.getLatestBlockhash(commitment);

@@ -48,5 +48,3 @@ }

*/
async getRecentBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.commitment) !== null && _a !== void 0 ? _a : "confirmed"; }
async getRecentBlockhash(commitment = this.opts.commitment ?? "confirmed") {
const result = await this.sendConnection.getLatestBlockhash(commitment);

@@ -74,8 +72,6 @@ return result.blockhash;

*/
async simulate(tx, _a) {
var _b, _c;
var { commitment = (_b = this.opts.preflightCommitment) !== null && _b !== void 0 ? _b : "confirmed", verifySigners = true, } = _a === void 0 ? {
commitment: (_c = this.opts.preflightCommitment) !== null && _c !== void 0 ? _c : "confirmed",
verifySigners: true,
} : _a;
async simulate(tx, { commitment = this.opts.preflightCommitment ?? "confirmed", verifySigners = true, } = {
commitment: this.opts.preflightCommitment ?? "confirmed",
verifySigners: true,
}) {
if (verifySigners && tx.signatures.length === 0) {

@@ -92,2 +88,4 @@ throw new Error("Transaction must be signed before simulating.");

class MultipleConnectionBroadcaster {
connections;
opts;
constructor(connections, opts = provider_js_1.DEFAULT_PROVIDER_OPTIONS) {

@@ -97,5 +95,3 @@ this.connections = connections;

}
async getLatestBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.preflightCommitment) !== null && _a !== void 0 ? _a : "confirmed"; }
async getLatestBlockhash(commitment = this.opts.preflightCommitment ?? "confirmed") {
try {

@@ -114,5 +110,3 @@ const result = await Promise.any(this.connections.map((conn) => conn.getLatestBlockhash(commitment)));

}
async getRecentBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.preflightCommitment) !== null && _a !== void 0 ? _a : "confirmed"; }
async getRecentBlockhash(commitment = this.opts.preflightCommitment ?? "confirmed") {
try {

@@ -134,3 +128,3 @@ const result = await Promise.any(this.connections.map((conn) => conn.getLatestBlockhash(commitment)));

return await Promise.any(this.connections.map(async (connection) => {
return new index_js_1.PendingTransaction(connection, await (0, sendAndSpamRawTx_js_1.sendAndSpamRawTx)(connection, encoded, options !== null && options !== void 0 ? options : this.opts));
return new index_js_1.PendingTransaction(connection, await (0, sendAndSpamRawTx_js_1.sendAndSpamRawTx)(connection, encoded, options ?? this.opts));
}));

@@ -174,8 +168,8 @@ }

*/
async simulate(tx, _a) {
var _b, _c, _d, _e;
var { commitment = (_c = (_b = this.opts.preflightCommitment) !== null && _b !== void 0 ? _b : this.opts.commitment) !== null && _c !== void 0 ? _c : "confirmed", verifySigners = true, } = _a === void 0 ? {
commitment: (_e = (_d = this.opts.preflightCommitment) !== null && _d !== void 0 ? _d : this.opts.commitment) !== null && _e !== void 0 ? _e : "confirmed",
verifySigners: true,
} : _a;
async simulate(tx, { commitment = this.opts.preflightCommitment ??
this.opts.commitment ??
"confirmed", verifySigners = true, } = {
commitment: this.opts.preflightCommitment ?? this.opts.commitment ?? "confirmed",
verifySigners: true,
}) {
if (verifySigners && tx.signatures.length === 0) {

@@ -182,0 +176,0 @@ throw new Error("Transaction must be signed before simulating.");

@@ -13,2 +13,6 @@ "use strict";

class TieredBroadcaster {
primaryConnection;
fallbackConnections;
opts;
premiumBroadcaster;
constructor(primaryConnection,

@@ -24,19 +28,14 @@ /**

}
async getLatestBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.preflightCommitment) !== null && _a !== void 0 ? _a : "confirmed"; }
async getLatestBlockhash(commitment = this.opts.preflightCommitment ?? "confirmed") {
return await this.premiumBroadcaster.getLatestBlockhash(commitment);
}
async getRecentBlockhash(commitment) {
var _a;
if (commitment === void 0) { commitment = (_a = this.opts.preflightCommitment) !== null && _a !== void 0 ? _a : "confirmed"; }
async getRecentBlockhash(commitment = this.opts.preflightCommitment ?? "confirmed") {
return await this.premiumBroadcaster.getRecentBlockhash(commitment);
}
async _sendRawTransaction(encoded, options) {
const pending = new index_js_1.PendingTransaction(this.primaryConnection, await (0, sendAndSpamRawTx_js_1.sendAndSpamRawTx)(this.primaryConnection, encoded, options !== null && options !== void 0 ? options : this.opts, options !== null && options !== void 0 ? options : index_js_3.DEFAULT_RETRY_OPTIONS));
const pending = new index_js_1.PendingTransaction(this.primaryConnection, await (0, sendAndSpamRawTx_js_1.sendAndSpamRawTx)(this.primaryConnection, encoded, options ?? this.opts, options ?? index_js_3.DEFAULT_RETRY_OPTIONS));
void (async () => {
await Promise.all(this.fallbackConnections.map(async (fc) => {
var _a;
try {
await (0, sendAndSpamRawTx_js_1.sendAndSpamRawTx)(fc, encoded, options !== null && options !== void 0 ? options : this.opts, (_a = options === null || options === void 0 ? void 0 : options.fallbackRetryOptions) !== null && _a !== void 0 ? _a : index_js_3.DEFAULT_FALLBACK_RETRY_OPTIONS);
await (0, sendAndSpamRawTx_js_1.sendAndSpamRawTx)(fc, encoded, options ?? this.opts, options?.fallbackRetryOptions ?? index_js_3.DEFAULT_FALLBACK_RETRY_OPTIONS);
}

@@ -77,8 +76,6 @@ catch (e) {

*/
async simulate(tx, _a) {
var _b, _c;
var { commitment = (_b = this.opts.preflightCommitment) !== null && _b !== void 0 ? _b : "confirmed", verifySigners = true, } = _a === void 0 ? {
commitment: (_c = this.opts.preflightCommitment) !== null && _c !== void 0 ? _c : "confirmed",
verifySigners: true,
} : _a;
async simulate(tx, { commitment = this.opts.preflightCommitment ?? "confirmed", verifySigners = true, } = {
commitment: this.opts.preflightCommitment ?? "confirmed",
verifySigners: true,
}) {
if (verifySigners && tx.signatures.length === 0) {

@@ -85,0 +82,0 @@ throw new Error("Transaction must be signed before simulating.");

@@ -19,2 +19,5 @@ "use strict";

class SolanaReadonlyProvider {
connection;
opts;
publicKey;
/**

@@ -30,7 +33,2 @@ * @param connection The cluster connection where the program is deployed.

this.wallet = {
signTransaction: Promise.resolve.bind(Promise),
signAllTransactions: Promise.resolve.bind(Promise),
publicKey: exports.DEFAULT_READONLY_PUBLIC_KEY,
};
this.wallet = {
...this.wallet,

@@ -40,2 +38,7 @@ publicKey,

}
wallet = {
signTransaction: Promise.resolve.bind(Promise),
signAllTransactions: Promise.resolve.bind(Promise),
publicKey: exports.DEFAULT_READONLY_PUBLIC_KEY,
};
/**

@@ -60,3 +63,3 @@ * Gets

const tx = await wallet.signTransaction(transaction);
if ((opts === null || opts === void 0 ? void 0 : opts.signers) && opts.signers.length > 0) {
if (opts?.signers && opts.signers.length > 0) {
tx.sign(...opts.signers);

@@ -71,2 +74,5 @@ }

class SolanaTransactionSigner {
wallet;
broadcaster;
preflightCommitment;
constructor(wallet, broadcaster, preflightCommitment = "confirmed") {

@@ -136,2 +142,7 @@ this.wallet = wallet;

class SolanaProvider extends SolanaReadonlyProvider {
connection;
broadcaster;
wallet;
opts;
signer;
/**

@@ -221,2 +232,3 @@ * @param connection The cluster connection where the program is deployed.

class SolanaAugmentedProvider {
provider;
constructor(provider) {

@@ -223,0 +235,0 @@ this.provider = provider;

@@ -29,5 +29,4 @@ "use strict";

logs.forEach((log) => {
var _a, _b, _c, _d, _e;
if (log.startsWith("Program log:")) {
(_a = prettyLogs[prettyLogs.length - 1]) === null || _a === void 0 ? void 0 : _a.logs.push({
prettyLogs[prettyLogs.length - 1]?.logs.push({
type: "text",

@@ -42,3 +41,3 @@ depth,

if (matches.length > 0) {
const programAddress = (_b = matches[0]) === null || _b === void 0 ? void 0 : _b[1];
const programAddress = matches[0]?.[1];
(0, tiny_invariant_1.default)(programAddress, "program address");

@@ -53,6 +52,6 @@ if (depth === 0) {

else {
(_c = prettyLogs[prettyLogs.length - 1]) === null || _c === void 0 ? void 0 : _c.logs.push({
prettyLogs[prettyLogs.length - 1]?.logs.push({
type: "cpi",
depth,
programAddress: programAddress !== null && programAddress !== void 0 ? programAddress : null,
programAddress: programAddress ?? null,
});

@@ -63,3 +62,3 @@ }

else if (log.includes("success")) {
(_d = prettyLogs[prettyLogs.length - 1]) === null || _d === void 0 ? void 0 : _d.logs.push({
prettyLogs[prettyLogs.length - 1]?.logs.push({
type: "success",

@@ -91,3 +90,3 @@ depth,

// system transactions don't start with "Program log:"
(_e = prettyLogs[prettyLogs.length - 1]) === null || _e === void 0 ? void 0 : _e.logs.push({
prettyLogs[prettyLogs.length - 1]?.logs.push({
type: "system",

@@ -94,0 +93,0 @@ depth,

@@ -12,6 +12,8 @@ "use strict";

class PendingTransaction {
connection;
signature;
_receipt = null;
constructor(connection, signature) {
this.connection = connection;
this.signature = signature;
this._receipt = null;
}

@@ -18,0 +20,0 @@ /**

@@ -27,2 +27,5 @@ "use strict";

class TransactionEnvelope {
provider;
instructions;
signers;
constructor(

@@ -247,4 +250,3 @@ /**

return this.simulate(opts).then((simulation) => {
var _a;
if ((_a = simulation === null || simulation === void 0 ? void 0 : simulation.value) === null || _a === void 0 ? void 0 : _a.logs) {
if (simulation?.value?.logs) {
(0, index_js_2.printTXTable)(this, simulation.value.logs, "");

@@ -420,6 +422,5 @@ }

.map((ix) => {
var _a;
const programId = ix.programId;
if (programId.equals(ASSOCIATED_TOKEN_PROGRAM_ID)) {
const ataKey = (_a = ix.keys[1]) === null || _a === void 0 ? void 0 : _a.pubkey.toString();
const ataKey = ix.keys[1]?.pubkey.toString();
if (!ataKey) {

@@ -426,0 +427,0 @@ throw new Error("ATA key does not exist on ATA instruction");

@@ -36,2 +36,4 @@ "use strict";

class TransactionReceipt {
signature;
response;
constructor(

@@ -53,4 +55,3 @@ /**

getEvents(eventParser) {
var _a;
const logs = (_a = this.response.meta) === null || _a === void 0 ? void 0 : _a.logMessages;
const logs = this.response.meta?.logMessages;
if (logs && logs.length > 0) {

@@ -65,4 +66,3 @@ return eventParser(logs);

printLogs() {
var _a, _b;
console.log((_b = (_a = this.response.meta) === null || _a === void 0 ? void 0 : _a.logMessages) === null || _b === void 0 ? void 0 : _b.join("\n"));
console.log(this.response.meta?.logMessages?.join("\n"));
}

@@ -74,4 +74,3 @@ /**

get computeUnits() {
var _a;
const logs = (_a = this.response.meta) === null || _a === void 0 ? void 0 : _a.logMessages;
const logs = this.response.meta?.logMessages;
(0, tiny_invariant_1.default)(logs, "no logs");

@@ -78,0 +77,0 @@ const consumeLog = logs[logs.length - 2];

@@ -39,3 +39,2 @@ "use strict";

async function printAccountOwners(connection, plainObj) {
var _a, _b;
try {

@@ -47,3 +46,3 @@ if (typeof plainObj !== "object") {

let relativePath;
const callStack = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n");
const callStack = new Error().stack?.split("\n");
if (callStack) {

@@ -65,3 +64,3 @@ let expectIndex = callStack.findIndex((l) => l.includes(`at ${printAccountOwners.name}`));

if (targetLine) {
const cwd = ((_b = maybeProcess.cwd) === null || _b === void 0 ? void 0 : _b.call(maybeProcess)) || "/";
const cwd = maybeProcess.cwd?.() || "/";
// get the part of targetLine after cwd

@@ -101,3 +100,2 @@ const targetLineAfterCwd = targetLine.substring(targetLine.indexOf(cwd) + cwd.length);

async function gracefulGetMultipleAccountsInfo(connection, publicKeys) {
var _a;
try {

@@ -116,3 +114,3 @@ // To be honest, the web3 internals aren't going to change that much. And if

]);
const value = (_a = unsafeRes === null || unsafeRes === void 0 ? void 0 : unsafeRes.result) === null || _a === void 0 ? void 0 : _a.value;
const value = unsafeRes?.result?.value;
if (value) {

@@ -172,3 +170,3 @@ return value;

const accountInfo = accountInfos[lookupIndex];
const owner = accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.owner;
const owner = accountInfo?.owner;
if (owner) {

@@ -175,0 +173,0 @@ result[resultKey] = `${base58} (${owner})`;

@@ -60,4 +60,6 @@ "use strict";

const computeUnitLog = computeUnitLogStack[i];
const computeUnitMatch = computeUnitLog === null || computeUnitLog === void 0 ? void 0 : computeUnitLog.match(/consumed (\d*) of (\d*)/);
const [consumed, quota] = (computeUnitMatch === null || computeUnitMatch === void 0 ? void 0 : computeUnitMatch.slice(1, 3).map((num) => parseInt(num, 10))) || [undefined, undefined];
const computeUnitMatch = computeUnitLog?.match(/consumed (\d*) of (\d*)/);
const [consumed, quota] = computeUnitMatch
?.slice(1, 3)
.map((num) => parseInt(num, 10)) || [undefined, undefined];
instructionTable.push({

@@ -78,2 +80,3 @@ iso: isolatedInstructionSize(tx.provider, instruction),

class TXSizeEstimationError extends Error {
underlyingError;
constructor(underlyingError) {

@@ -87,2 +90,4 @@ super(`could not estimate transaction size`);

class EstimatedTXTooBigError extends Error {
tx;
size;
constructor(tx, size) {

@@ -89,0 +94,0 @@ super(`Transaction too large`);

@@ -10,2 +10,3 @@ "use strict";

class CachedPublicKey extends web3_js_1.PublicKey {
_base58;
constructor(value) {

@@ -12,0 +13,0 @@ super(value);

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

async function simulateTransactionWithCommitment(connection, transaction, commitment = "confirmed") {
var _a;
const connectionInner = connection;

@@ -27,3 +26,3 @@ // only populate recent blockhash if it isn't on the tx

if (res.error) {
throw new web3_js_1.SendTransactionError("failed to simulate transaction: " + res.error.message, (_a = res.result.value.logs) !== null && _a !== void 0 ? _a : undefined);
throw new web3_js_1.SendTransactionError("failed to simulate transaction: " + res.error.message, res.result.value.logs ?? undefined);
}

@@ -30,0 +29,0 @@ return res.result;

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

*/
const dateToTs = (date) => new bn_js_1.default(Math.floor(date.getTime() / 1000));
const dateToTs = (date) => new bn_js_1.default(Math.floor(date.getTime() / 1_000));
exports.dateToTs = dateToTs;

@@ -19,4 +19,4 @@ /**

*/
const tsToDate = (ts) => new Date(ts.toNumber() * 1000);
const tsToDate = (ts) => new Date(ts.toNumber() * 1_000);
exports.tsToDate = tsToDate;
//# sourceMappingURL=time.js.map

@@ -10,2 +10,3 @@ "use strict";

class SignerWallet {
signer;
constructor(signer) {

@@ -12,0 +13,0 @@ this.signer = signer;

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

@@ -29,4 +29,4 @@ "homepage": "https://github.com/saber-hq/saber-common/tree/master/packages/solana-contrib#readme",

"dependencies": {
"@saberhq/option-utils": "^2.0.0",
"@solana/buffer-layout": "^4.0.0",
"@saberhq/option-utils": "^3.0.0",
"@solana/buffer-layout": "^4.0.1",
"@types/promise-retry": "^1.1.6",

@@ -36,13 +36,13 @@ "@types/retry": "^0.12.5",

"retry": "^0.13.1",
"tiny-invariant": "^1.3.1",
"tiny-invariant": "^1.3.3",
"tslib": "^2.6.2"
},
"devDependencies": {
"@saberhq/tsconfig": "^3.2.1",
"@saberhq/tsconfig": "^3.3.1",
"@solana/web3.js": "^1.91.1",
"@types/bn.js": "^5.1.5",
"@types/jest": "^29.5.10",
"@types/node": "^18.18.14",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.7",
"bn.js": "^5.2.1",
"typescript": "^5.3.2"
"typescript": "^5.4.5"
},

@@ -49,0 +49,0 @@ "peerDependencies": {

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

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