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

@saberhq/solana

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@saberhq/solana - npm Package Compare versions

Comparing version 0.1.1-beta.1 to 0.1.1-beta.2

5

dist/constants.js

@@ -0,5 +1,8 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_NETWORK_CONFIG_MAP = void 0;
/**
* Default configuration for all networks.
*/
export var DEFAULT_NETWORK_CONFIG_MAP = {
exports.DEFAULT_NETWORK_CONFIG_MAP = {
"mainnet-beta": {

@@ -6,0 +9,0 @@ name: "Mainnet Beta",

11

dist/index.js

@@ -1,5 +0,8 @@

export * from "./constants";
export * from "./interfaces";
export * from "./provider";
export * from "./transaction";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./constants"), exports);
tslib_1.__exportStar(require("./interfaces"), exports);
tslib_1.__exportStar(require("./provider"), exports);
tslib_1.__exportStar(require("./transaction"), exports);
//# sourceMappingURL=index.js.map

@@ -1,2 +0,3 @@

export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=interfaces.js.map

@@ -1,4 +0,6 @@

import { __awaiter, __generator } from "tslib";
import { sendAndConfirmRawTransaction, } from "@solana/web3.js";
import invariant from "tiny-invariant";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const web3_js_1 = require("@solana/web3.js");
const tiny_invariant_1 = require("tiny-invariant");
/**

@@ -10,3 +12,3 @@ * The network and wallet context used to send transactions paid for and signed

*/
var SolanaProvider = /** @class */ (function () {
class SolanaProvider {
/**

@@ -17,3 +19,3 @@ * @param connection The cluster connection where the program is deployed.

*/
function SolanaProvider(connection, wallet, opts) {
constructor(connection, wallet, opts) {
this.connection = connection;

@@ -23,3 +25,3 @@ this.wallet = wallet;

}
SolanaProvider.defaultOptions = function () {
static defaultOptions() {
return {

@@ -29,3 +31,3 @@ preflightCommitment: "recent",

};
};
}
/**

@@ -39,91 +41,58 @@ * Sends the given transaction, paid for and signed by the provider's wallet.

*/
SolanaProvider.prototype.send = function (tx, signers, opts) {
return __awaiter(this, void 0, void 0, function () {
var _a, rawTx, txId;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (signers === undefined) {
signers = [];
}
if (opts === undefined) {
opts = this.opts;
}
tx.feePayer = this.wallet.publicKey;
_a = tx;
return [4 /*yield*/, this.connection.getRecentBlockhash(opts.preflightCommitment)];
case 1:
_a.recentBlockhash = (_b.sent()).blockhash;
return [4 /*yield*/, this.wallet.signTransaction(tx)];
case 2:
_b.sent();
signers
.filter(function (s) { return s !== undefined; })
.forEach(function (kp) {
tx.partialSign(kp);
});
rawTx = tx.serialize();
return [4 /*yield*/, sendAndConfirmRawTransaction(this.connection, rawTx, opts)];
case 3:
txId = _b.sent();
return [2 /*return*/, txId];
}
send(tx, signers, opts) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (signers === undefined) {
signers = [];
}
if (opts === undefined) {
opts = this.opts;
}
tx.feePayer = this.wallet.publicKey;
tx.recentBlockhash = (yield this.connection.getRecentBlockhash(opts.preflightCommitment)).blockhash;
yield this.wallet.signTransaction(tx);
signers
.filter((s) => s !== undefined)
.forEach((kp) => {
tx.partialSign(kp);
});
const rawTx = tx.serialize();
const txId = yield web3_js_1.sendAndConfirmRawTransaction(this.connection, rawTx, opts);
return txId;
});
};
}
/**
* Similar to `send`, but for an array of transactions and signers.
*/
SolanaProvider.prototype.sendAll = function (reqs, opts) {
return __awaiter(this, void 0, void 0, function () {
var blockhash, txs, signedTxs, sigs, k, tx, rawTx, _a, _b;
var _this = this;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
if (opts === undefined) {
opts = this.opts;
}
return [4 /*yield*/, this.connection.getRecentBlockhash(opts.preflightCommitment)];
case 1:
blockhash = _c.sent();
txs = reqs.map(function (r) {
var tx = r.tx;
var signers = r.signers;
if (signers === undefined) {
signers = [];
}
tx.feePayer = _this.wallet.publicKey;
tx.recentBlockhash = blockhash.blockhash;
signers
.filter(function (s) { return s !== undefined; })
.forEach(function (kp) {
tx.partialSign(kp);
});
return tx;
});
return [4 /*yield*/, this.wallet.signAllTransactions(txs)];
case 2:
signedTxs = _c.sent();
sigs = [];
k = 0;
_c.label = 3;
case 3:
if (!(k < txs.length)) return [3 /*break*/, 6];
tx = signedTxs[k];
invariant(tx, "tx missing");
rawTx = tx.serialize();
_b = (_a = sigs).push;
return [4 /*yield*/, sendAndConfirmRawTransaction(this.connection, rawTx, opts)];
case 4:
_b.apply(_a, [_c.sent()]);
_c.label = 5;
case 5:
k += 1;
return [3 /*break*/, 3];
case 6: return [2 /*return*/, sigs];
sendAll(reqs, opts) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (opts === undefined) {
opts = this.opts;
}
const blockhash = yield this.connection.getRecentBlockhash(opts.preflightCommitment);
const txs = reqs.map((r) => {
const tx = r.tx;
let signers = r.signers;
if (signers === undefined) {
signers = [];
}
tx.feePayer = this.wallet.publicKey;
tx.recentBlockhash = blockhash.blockhash;
signers
.filter((s) => s !== undefined)
.forEach((kp) => {
tx.partialSign(kp);
});
return tx;
});
const signedTxs = yield this.wallet.signAllTransactions(txs);
const sigs = [];
for (let k = 0; k < txs.length; k += 1) {
const tx = signedTxs[k];
tiny_invariant_1.default(tx, "tx missing");
const rawTx = tx.serialize();
sigs.push(yield web3_js_1.sendAndConfirmRawTransaction(this.connection, rawTx, opts));
}
return sigs;
});
};
}
/**

@@ -137,68 +106,44 @@ * Simulates the given transaction, returning emitted logs from execution.

*/
SolanaProvider.prototype.simulate = function (tx, signers, opts) {
simulate(tx, signers, opts) {
var _a, _b, _c;
return __awaiter(this, void 0, void 0, function () {
var _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
if (signers === undefined) {
signers = [];
}
if (opts === undefined) {
opts = this.opts;
}
tx.feePayer = this.wallet.publicKey;
_d = tx;
return [4 /*yield*/, this.connection.getRecentBlockhash((_a = opts.preflightCommitment) !== null && _a !== void 0 ? _a : this.opts.preflightCommitment)];
case 1:
_d.recentBlockhash = (_e.sent()).blockhash;
return [4 /*yield*/, this.wallet.signTransaction(tx)];
case 2:
_e.sent();
signers
.filter(function (s) { return s !== undefined; })
.forEach(function (kp) {
tx.partialSign(kp);
});
return [4 /*yield*/, simulateTransaction(this.connection, tx, (_c = (_b = opts.commitment) !== null && _b !== void 0 ? _b : this.opts.commitment) !== null && _c !== void 0 ? _c : "recent")];
case 3: return [2 /*return*/, _e.sent()];
}
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (signers === undefined) {
signers = [];
}
if (opts === undefined) {
opts = this.opts;
}
tx.feePayer = this.wallet.publicKey;
tx.recentBlockhash = (yield this.connection.getRecentBlockhash((_a = opts.preflightCommitment) !== null && _a !== void 0 ? _a : this.opts.preflightCommitment)).blockhash;
yield this.wallet.signTransaction(tx);
signers
.filter((s) => s !== undefined)
.forEach((kp) => {
tx.partialSign(kp);
});
return yield simulateTransaction(this.connection, tx, (_c = (_b = opts.commitment) !== null && _b !== void 0 ? _b : this.opts.commitment) !== null && _c !== void 0 ? _c : "recent");
});
};
return SolanaProvider;
}());
export default SolanaProvider;
}
}
exports.default = SolanaProvider;
// Copy of Connection.simulateTransaction that takes a commitment parameter.
function simulateTransaction(connection, transaction, commitment) {
return __awaiter(this, void 0, void 0, function () {
var connectionInner, transactionTyped, _a, signData, wireTransaction, encodedTransaction, config, res;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
connectionInner = connection;
transactionTyped = transaction;
_a = transaction;
return [4 /*yield*/, connectionInner._recentBlockhash(connectionInner._disableBlockhashCaching)];
case 1:
_a.recentBlockhash = _b.sent();
signData = transaction.serializeMessage();
wireTransaction = transactionTyped._serialize(signData);
encodedTransaction = wireTransaction.toString("base64");
config = { encoding: "base64", commitment: commitment };
return [4 /*yield*/, connectionInner._rpcRequest("simulateTransaction", [
encodedTransaction,
config,
])];
case 2:
res = _b.sent();
if (res.error) {
throw new Error("failed to simulate transaction: " + res.error.message);
}
return [2 /*return*/, res.result];
}
});
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const connectionInner = connection;
const transactionTyped = transaction;
transaction.recentBlockhash = yield connectionInner._recentBlockhash(connectionInner._disableBlockhashCaching);
const signData = transaction.serializeMessage();
const wireTransaction = transactionTyped._serialize(signData);
const encodedTransaction = wireTransaction.toString("base64");
const config = { encoding: "base64", commitment };
const res = yield connectionInner._rpcRequest("simulateTransaction", [
encodedTransaction,
config,
]);
if (res.error) {
throw new Error("failed to simulate transaction: " + res.error.message);
}
return res.result;
});
}
//# sourceMappingURL=provider.js.map

@@ -1,11 +0,13 @@

import { __awaiter, __generator } from "tslib";
import { Transaction, } from "@solana/web3.js";
import promiseRetry from "promise-retry";
import invariant from "tiny-invariant";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransactionReceipt = exports.PendingTransaction = exports.TransactionEnvelope = void 0;
const tslib_1 = require("tslib");
const web3_js_1 = require("@solana/web3.js");
const promise_retry_1 = require("promise-retry");
const tiny_invariant_1 = require("tiny-invariant");
/**
* Contains a Transaction that is being built.
*/
var TransactionEnvelope = /** @class */ (function () {
function TransactionEnvelope(provider, instructions, signers) {
if (signers === void 0) { signers = []; }
class TransactionEnvelope {
constructor(provider, instructions, signers = []) {
this.provider = provider;

@@ -15,21 +17,15 @@ this.instructions = instructions;

}
TransactionEnvelope.prototype.addSigners = function () {
var _a;
var signers = [];
for (var _i = 0; _i < arguments.length; _i++) {
signers[_i] = arguments[_i];
}
(_a = this.signers).push.apply(_a, signers);
addSigners(...signers) {
this.signers.push(...signers);
return this;
};
}
/**
* Builds a transaction from this envelope.
*/
TransactionEnvelope.prototype.build = function () {
var _a;
return (_a = new Transaction()).add.apply(_a, this.instructions);
};
TransactionEnvelope.prototype.simulate = function (opts) {
build() {
return new web3_js_1.Transaction().add(...this.instructions);
}
simulate(opts) {
return this.provider.simulate(this.build(), this.signers, opts);
};
}
/**

@@ -40,23 +36,15 @@ * Sends the transaction.

*/
TransactionEnvelope.prototype.send = function (opts) {
return __awaiter(this, void 0, void 0, function () {
var sig;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.provider.send(this.build(), this.signers, opts)];
case 1:
sig = _a.sent();
return [2 /*return*/, new PendingTransaction(this.provider, sig)];
}
});
send(opts) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const sig = yield this.provider.send(this.build(), this.signers, opts);
return new PendingTransaction(this.provider, sig);
});
};
return TransactionEnvelope;
}());
export { TransactionEnvelope };
}
}
exports.TransactionEnvelope = TransactionEnvelope;
/**
* Transaction which may or may not be confirmed.
*/
var PendingTransaction = /** @class */ (function () {
function PendingTransaction(provider, signature) {
class PendingTransaction {
constructor(provider, signature) {
this.provider = provider;

@@ -70,45 +58,28 @@ this.signature = signature;

*/
PendingTransaction.prototype.wait = function () {
return __awaiter(this, void 0, void 0, function () {
var receipt;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (this.receipt) {
return [2 /*return*/, this.receipt];
}
return [4 /*yield*/, promiseRetry(function (retry) { return __awaiter(_this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.provider.connection.getTransaction(this.signature, {
commitment: "confirmed",
})];
case 1:
result = _a.sent();
if (!result) {
retry(new Error("error"));
return [2 /*return*/];
}
return [2 /*return*/, new TransactionReceipt(this.provider, this.signature, result)];
}
});
}); }, { retries: 5 })];
case 1:
receipt = _a.sent();
invariant(receipt, "transaction could not be confirmed");
return [2 /*return*/, receipt];
wait() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (this.receipt) {
return this.receipt;
}
const receipt = yield promise_retry_1.default((retry) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const result = yield this.provider.connection.getTransaction(this.signature, {
commitment: "confirmed",
});
if (!result) {
retry(new Error("error"));
return;
}
});
return new TransactionReceipt(this.provider, this.signature, result);
}), { retries: 5 });
tiny_invariant_1.default(receipt, "transaction could not be confirmed");
return receipt;
});
};
return PendingTransaction;
}());
export { PendingTransaction };
}
}
exports.PendingTransaction = PendingTransaction;
/**
* A transaction that has been processed by the cluster.
*/
var TransactionReceipt = /** @class */ (function () {
function TransactionReceipt(
class TransactionReceipt {
constructor(
/**

@@ -133,5 +104,5 @@ * Current provider.

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

@@ -141,31 +112,26 @@ return eventParser(logs);

return [];
};
}
/**
* Prints the logs associated with this transaction.
*/
TransactionReceipt.prototype.printLogs = function () {
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"));
};
Object.defineProperty(TransactionReceipt.prototype, "computeUnits", {
/**
* Gets the compute units used by the transaction.
* @returns
*/
get: function () {
var _a;
var logs = (_a = this.response.meta) === null || _a === void 0 ? void 0 : _a.logMessages;
invariant(logs, "no logs");
var consumeLog = logs[logs.length - 2];
invariant(consumeLog, "no consume log");
var amtStr = consumeLog.split(" ")[3];
invariant(amtStr, "no amount");
return parseInt(amtStr);
},
enumerable: false,
configurable: true
});
return TransactionReceipt;
}());
export { TransactionReceipt };
}
/**
* Gets the compute units used by the transaction.
* @returns
*/
get computeUnits() {
var _a;
const logs = (_a = this.response.meta) === null || _a === void 0 ? void 0 : _a.logMessages;
tiny_invariant_1.default(logs, "no logs");
const consumeLog = logs[logs.length - 2];
tiny_invariant_1.default(consumeLog, "no consume log");
const amtStr = consumeLog.split(" ")[3];
tiny_invariant_1.default(amtStr, "no amount");
return parseInt(amtStr);
}
}
exports.TransactionReceipt = TransactionReceipt;
//# sourceMappingURL=transaction.js.map
{
"name": "@saberhq/solana",
"version": "0.1.1-beta.1",
"version": "0.1.1-beta.2",
"description": "Common types and libraries for Solana",

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

},
"gitHead": "7341e6079710ca881cef8225173920223ab0c265",
"gitHead": "e36fcf5cb872993ddf822c153911f34e1d075f17",
"publishConfig": {

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

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