@debridge-finance/solana-utils 4.1.0 → 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 +50 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/cjs/spl.js +43 -1
- package/dist/cjs/spl.js.map +1 -1
- package/dist/esm/spl.js +43 -0
- package/dist/esm/spl.js.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;
|
|
@@ -9512,6 +9517,49 @@ var AccountType;
|
|
|
9512
9517
|
AccountType[AccountType["Unknown"] = 3] = "Unknown";
|
|
9513
9518
|
AccountType[AccountType["NotExists"] = 4] = "NotExists";
|
|
9514
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
|
+
}
|
|
9515
9563
|
/**
|
|
9516
9564
|
* Builds instruction for creation of associated wallet for specified token
|
|
9517
9565
|
* @param tokenMint mint account of SPL-token
|
|
@@ -9746,6 +9794,7 @@ function checkIfAssociatedWalletExists(connection, mintAccount, originalWallet)
|
|
|
9746
9794
|
var spl = /*#__PURE__*/Object.freeze({
|
|
9747
9795
|
__proto__: null,
|
|
9748
9796
|
get AccountType () { return AccountType; },
|
|
9797
|
+
getTokenInfo: getTokenInfo,
|
|
9749
9798
|
createAssociatedWalletInstruction: createAssociatedWalletInstruction,
|
|
9750
9799
|
parseSplAccount: parseSplAccount,
|
|
9751
9800
|
isWalletCorrectATA: isWalletCorrectATA,
|