@debridge-finance/solana-utils 4.0.1 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.js +57 -9
- package/dist/browser/index.js.map +1 -1
- package/dist/cjs/helpers.js +2 -4
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/spl.js +44 -2
- package/dist/cjs/spl.js.map +1 -1
- package/dist/esm/helpers.js +6 -7
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/spl.js +43 -0
- package/dist/esm/spl.js.map +1 -1
- package/dist/types/helpers.d.ts +5 -0
- package/dist/types/helpers.d.ts.map +1 -1
- package/dist/types/spl.d.ts +13 -0
- package/dist/types/spl.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/browser/index.js
CHANGED
|
@@ -6414,7 +6414,12 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
6414
6414
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
6415
6415
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
6416
6416
|
});
|
|
6417
|
-
}
|
|
6417
|
+
}
|
|
6418
|
+
|
|
6419
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
6420
|
+
var e = new Error(message);
|
|
6421
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
6422
|
+
};
|
|
6418
6423
|
|
|
6419
6424
|
const BPS_DENOMINATOR = 10000;
|
|
6420
6425
|
const SOLANA_CHAIN_ID = 7565164;
|
|
@@ -6632,11 +6637,11 @@ function setBlockhash(transaction, blockhash) {
|
|
|
6632
6637
|
* @returns
|
|
6633
6638
|
*/
|
|
6634
6639
|
function sendAll(connection, wallet, transactions, options) {
|
|
6635
|
-
var _a;
|
|
6640
|
+
var _a, _b;
|
|
6636
6641
|
return __awaiter(this, void 0, void 0, function* () {
|
|
6637
6642
|
const blockhashCommitment = (options === null || options === void 0 ? void 0 : options.blockhashCommitment) === undefined ? "finalized" : options.blockhashCommitment;
|
|
6638
6643
|
const convertIntoTxV0 = (options === null || options === void 0 ? void 0 : options.convertIntoTxV0) === undefined ? true : options.convertIntoTxV0;
|
|
6639
|
-
|
|
6644
|
+
(options === null || options === void 0 ? void 0 : options.debug) === undefined ? false : options.debug;
|
|
6640
6645
|
const skipPreflight = (options === null || options === void 0 ? void 0 : options.skipPreflight) === undefined ? false : options.skipPreflight;
|
|
6641
6646
|
const rpcCalls = (options === null || options === void 0 ? void 0 : options.rpcCalls) === undefined ? 3 : options.rpcCalls;
|
|
6642
6647
|
if (!Array.isArray(transactions))
|
|
@@ -6647,7 +6652,7 @@ function sendAll(connection, wallet, transactions, options) {
|
|
|
6647
6652
|
let txIds = [];
|
|
6648
6653
|
if ((options === null || options === void 0 ? void 0 : options.waitBetweenSend) === undefined || options.waitBetweenSend === 0) {
|
|
6649
6654
|
yield Promise.all(transactions.map((tx) => __awaiter(this, void 0, void 0, function* () {
|
|
6650
|
-
var
|
|
6655
|
+
var _c;
|
|
6651
6656
|
let txV0;
|
|
6652
6657
|
if (isVersionedTx(tx)) {
|
|
6653
6658
|
tx.message.recentBlockhash = FAKE_BLOCKHASH;
|
|
@@ -6670,7 +6675,7 @@ function sendAll(connection, wallet, transactions, options) {
|
|
|
6670
6675
|
commitment: "confirmed",
|
|
6671
6676
|
});
|
|
6672
6677
|
if (simulationResult.value.err !== null) {
|
|
6673
|
-
throw new Error(`Tx simulation Error! Transaction message dump: ${buffer.Buffer.from(txV0.serialize()).toString("base64")}\n Error: ${JSON.stringify(simulationResult.value.err)}, logs:\n ${(
|
|
6678
|
+
throw new Error(`Tx simulation Error! Transaction message dump: ${buffer.Buffer.from(txV0.serialize()).toString("base64")}\n Error: ${JSON.stringify(simulationResult.value.err)}, logs:\n ${(_c = simulationResult.value.logs) === null || _c === void 0 ? void 0 : _c.join("\n")}`);
|
|
6674
6679
|
}
|
|
6675
6680
|
}
|
|
6676
6681
|
})));
|
|
@@ -6680,9 +6685,9 @@ function sendAll(connection, wallet, transactions, options) {
|
|
|
6680
6685
|
// sign after setting correct blockhashes
|
|
6681
6686
|
const signed = yield wallet.signAllTransactions(transactions, options === null || options === void 0 ? void 0 : options.signers);
|
|
6682
6687
|
txIds = yield Promise.all(signed.map((signedTx) => {
|
|
6688
|
+
var _a;
|
|
6683
6689
|
const serialized = buffer.Buffer.from(signedTx.serialize());
|
|
6684
|
-
|
|
6685
|
-
console.debug(serialized.toString("base64"));
|
|
6690
|
+
(_a = options === null || options === void 0 ? void 0 : options.logger) === null || _a === void 0 ? void 0 : _a.call(options, `Sending tx: ${serialized.toString("base64")}`);
|
|
6686
6691
|
return sendWithRetries(connection, serialized, lastValidBlockHeight, rpcCalls, blockhashCommitment);
|
|
6687
6692
|
}));
|
|
6688
6693
|
}
|
|
@@ -6717,8 +6722,7 @@ function sendAll(connection, wallet, transactions, options) {
|
|
|
6717
6722
|
}
|
|
6718
6723
|
}
|
|
6719
6724
|
const serialized = buffer.Buffer.from(signed.serialize());
|
|
6720
|
-
|
|
6721
|
-
console.debug(serialized.toString("base64"));
|
|
6725
|
+
(_b = options === null || options === void 0 ? void 0 : options.logger) === null || _b === void 0 ? void 0 : _b.call(options, `Sending tx: ${serialized.toString("base64")}`);
|
|
6722
6726
|
txIds.push(yield sendWithRetries(connection, serialized, lastValidBlockHeight, rpcCalls, blockhashCommitment));
|
|
6723
6727
|
yield sleep(options.waitBetweenSend);
|
|
6724
6728
|
}
|
|
@@ -9513,6 +9517,49 @@ var AccountType;
|
|
|
9513
9517
|
AccountType[AccountType["Unknown"] = 3] = "Unknown";
|
|
9514
9518
|
AccountType[AccountType["NotExists"] = 4] = "NotExists";
|
|
9515
9519
|
})(AccountType || (AccountType = {}));
|
|
9520
|
+
/**
|
|
9521
|
+
* Get name, symbol and decimals for provided token
|
|
9522
|
+
* @param connection solana web3 connection
|
|
9523
|
+
* @param tokenAddress address to get metaplex info for
|
|
9524
|
+
* @returns
|
|
9525
|
+
*/
|
|
9526
|
+
function getTokenInfo(connection, tokenAddress) {
|
|
9527
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9528
|
+
const tokenMetaProgramId = new PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
|
|
9529
|
+
const findMetaplexMetadataPda = (tokenMint) => PublicKey.findProgramAddressSync([buffer.Buffer.from('metadata', 'utf-8'), tokenMetaProgramId.toBuffer(), tokenMint.toBuffer()], tokenMetaProgramId)[0];
|
|
9530
|
+
const decodeMetaplexMetadataPartial = (data) => {
|
|
9531
|
+
const rawName = data.subarray(65 + 4, 65 + 36); // omit first 4 bytes, size is already hardcoded
|
|
9532
|
+
const rawSymbol = data.subarray(101 + 4, 115); // omit first 4 bytes, size is already hardcoded
|
|
9533
|
+
const rawUri = data.subarray(115 + 4, 204); // omit first 4 bytes, size is already hardcoded
|
|
9534
|
+
return {
|
|
9535
|
+
uri: rawUri.toString("utf-8").replace(/\u0000/g, ""),
|
|
9536
|
+
symbol: rawSymbol.toString("utf-8").replace(/\u0000/g, ""),
|
|
9537
|
+
name: rawName.toString("utf-8").replace(/\u0000/g, ""),
|
|
9538
|
+
};
|
|
9539
|
+
};
|
|
9540
|
+
const pda = findMetaplexMetadataPda(tokenAddress);
|
|
9541
|
+
const [tokenAccount, pdaAccount] = yield connection.getMultipleAccountsInfo([tokenAddress, pda]);
|
|
9542
|
+
if (tokenAccount === null || pdaAccount === null || (pdaAccount === null || pdaAccount === void 0 ? void 0 : pdaAccount.lamports) === 0) {
|
|
9543
|
+
return null;
|
|
9544
|
+
}
|
|
9545
|
+
// parse token account
|
|
9546
|
+
// mint_authority - coption(pubkey) = 4 or 36
|
|
9547
|
+
// supply - u64 = 8
|
|
9548
|
+
// decimals - u8
|
|
9549
|
+
let decimalsOffset = 12;
|
|
9550
|
+
if (tokenAccount.data[0] === 1)
|
|
9551
|
+
decimalsOffset += 32;
|
|
9552
|
+
const decimals = tokenAccount.data[decimalsOffset];
|
|
9553
|
+
const { name, symbol, uri } = decodeMetaplexMetadataPartial(pdaAccount.data);
|
|
9554
|
+
return {
|
|
9555
|
+
address: tokenAddress,
|
|
9556
|
+
decimals,
|
|
9557
|
+
name,
|
|
9558
|
+
symbol,
|
|
9559
|
+
json: uri,
|
|
9560
|
+
};
|
|
9561
|
+
});
|
|
9562
|
+
}
|
|
9516
9563
|
/**
|
|
9517
9564
|
* Builds instruction for creation of associated wallet for specified token
|
|
9518
9565
|
* @param tokenMint mint account of SPL-token
|
|
@@ -9747,6 +9794,7 @@ function checkIfAssociatedWalletExists(connection, mintAccount, originalWallet)
|
|
|
9747
9794
|
var spl = /*#__PURE__*/Object.freeze({
|
|
9748
9795
|
__proto__: null,
|
|
9749
9796
|
get AccountType () { return AccountType; },
|
|
9797
|
+
getTokenInfo: getTokenInfo,
|
|
9750
9798
|
createAssociatedWalletInstruction: createAssociatedWalletInstruction,
|
|
9751
9799
|
parseSplAccount: parseSplAccount,
|
|
9752
9800
|
isWalletCorrectATA: isWalletCorrectATA,
|