@debridge-finance/solana-utils 5.4.2 → 5.5.1
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 +54 -11
- package/dist/browser/index.js.map +1 -1
- package/dist/cjs/spl.js +53 -11
- package/dist/cjs/spl.js.map +1 -1
- package/dist/esm/spl.js +54 -11
- package/dist/esm/spl.js.map +1 -1
- package/dist/types/spl.d.ts +5 -1
- package/dist/types/spl.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -11468,13 +11468,15 @@ function getTokenInfo(connection, tokenAddress) {
|
|
|
11468
11468
|
* @param associatedAccount associated account address
|
|
11469
11469
|
* @param owner owner of the associated account
|
|
11470
11470
|
* @param payer who pays for account creation
|
|
11471
|
+
* @param isToken2022
|
|
11472
|
+
* @param associatedTokenProgramId
|
|
11471
11473
|
*/
|
|
11472
|
-
function createAssociatedWalletInstruction(tokenMint, associatedAccount, owner, payer,
|
|
11474
|
+
function createAssociatedWalletInstruction(tokenMint, associatedAccount, owner, payer, isToken2022, associatedTokenProgramId) {
|
|
11473
11475
|
tokenMint = new PublicKey(tokenMint);
|
|
11474
11476
|
payer = new PublicKey(payer);
|
|
11475
11477
|
owner = new PublicKey(owner);
|
|
11476
11478
|
return new TransactionInstruction({
|
|
11477
|
-
programId:
|
|
11479
|
+
programId: associatedTokenProgramId !== null && associatedTokenProgramId !== void 0 ? associatedTokenProgramId : ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
11478
11480
|
data: buffer.Buffer.from([1]),
|
|
11479
11481
|
keys: [
|
|
11480
11482
|
{
|
|
@@ -11503,7 +11505,7 @@ function createAssociatedWalletInstruction(tokenMint, associatedAccount, owner,
|
|
|
11503
11505
|
isWritable: false,
|
|
11504
11506
|
},
|
|
11505
11507
|
{
|
|
11506
|
-
pubkey: TOKEN_PROGRAM_ID$1,
|
|
11508
|
+
pubkey: isToken2022 ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID$1,
|
|
11507
11509
|
isSigner: false,
|
|
11508
11510
|
isWritable: false,
|
|
11509
11511
|
},
|
|
@@ -11571,11 +11573,27 @@ function getNativeWalletBalance(connection, wallet) {
|
|
|
11571
11573
|
*/
|
|
11572
11574
|
function getAssocSPLWalletBalance(connection, originalWallet, tokenMint) {
|
|
11573
11575
|
return __awaiter(this, void 0, void 0, function* () {
|
|
11576
|
+
var _a, _b, _c, _d;
|
|
11574
11577
|
originalWallet = new PublicKey(originalWallet);
|
|
11575
11578
|
tokenMint = new PublicKey(tokenMint);
|
|
11576
11579
|
const [wallet] = findAssociatedTokenAddress(originalWallet, tokenMint);
|
|
11577
|
-
const
|
|
11578
|
-
|
|
11580
|
+
const [wallet22] = findAssociatedTokenAddress(originalWallet, tokenMint, TOKEN_2022_PROGRAM_ID);
|
|
11581
|
+
const [tokenMintInfo, walletInfo, wallet22Info] = yield connection.getMultipleAccountsInfo([tokenMint, wallet, wallet22]);
|
|
11582
|
+
if (!tokenMintInfo) {
|
|
11583
|
+
throw new Error("Mint doesn't exist");
|
|
11584
|
+
}
|
|
11585
|
+
const owner = tokenMintInfo.owner.toBase58();
|
|
11586
|
+
switch (owner) {
|
|
11587
|
+
case TOKEN_PROGRAM_ID$1.toBase58(): {
|
|
11588
|
+
return new BN((_b = (_a = parseSplAccount(walletInfo !== null && walletInfo !== void 0 ? walletInfo : null)) === null || _a === void 0 ? void 0 : _a.amount.toString()) !== null && _b !== void 0 ? _b : 0);
|
|
11589
|
+
}
|
|
11590
|
+
case TOKEN_2022_PROGRAM_ID.toBase58(): {
|
|
11591
|
+
return new BN((_d = (_c = parseSplAccount(wallet22Info !== null && wallet22Info !== void 0 ? wallet22Info : null)) === null || _c === void 0 ? void 0 : _c.amount.toString()) !== null && _d !== void 0 ? _d : 0);
|
|
11592
|
+
}
|
|
11593
|
+
default: {
|
|
11594
|
+
throw new Error(`Unexpected tokenMint owner: ${owner}`);
|
|
11595
|
+
}
|
|
11596
|
+
}
|
|
11579
11597
|
});
|
|
11580
11598
|
}
|
|
11581
11599
|
/**
|
|
@@ -11585,8 +11603,15 @@ function getAssocSPLWalletBalance(connection, originalWallet, tokenMint) {
|
|
|
11585
11603
|
function getSPLWalletBalance(connection, wallet) {
|
|
11586
11604
|
return __awaiter(this, void 0, void 0, function* () {
|
|
11587
11605
|
wallet = new PublicKey(wallet);
|
|
11588
|
-
const
|
|
11589
|
-
|
|
11606
|
+
const info = yield getAccountInfo(connection, wallet, "finalized");
|
|
11607
|
+
if (!info) {
|
|
11608
|
+
return new BN(0);
|
|
11609
|
+
}
|
|
11610
|
+
const parsed = parseSplAccount(info.data);
|
|
11611
|
+
if (!parsed) {
|
|
11612
|
+
return new BN(0);
|
|
11613
|
+
}
|
|
11614
|
+
return new BN(parsed.amount.toString());
|
|
11590
11615
|
});
|
|
11591
11616
|
}
|
|
11592
11617
|
/**
|
|
@@ -11596,9 +11621,17 @@ function getSPLWalletBalance(connection, wallet) {
|
|
|
11596
11621
|
*/
|
|
11597
11622
|
function getAllTokenAccountsWithBalances(connection, owner) {
|
|
11598
11623
|
return __awaiter(this, void 0, void 0, function* () {
|
|
11599
|
-
const walletsData = yield
|
|
11624
|
+
const [walletsData, walletsDataToken22] = yield Promise.all([
|
|
11625
|
+
connection.getParsedTokenAccountsByOwner(new PublicKey(owner), {
|
|
11626
|
+
programId: TOKEN_PROGRAM_ID$1,
|
|
11627
|
+
}),
|
|
11628
|
+
connection.getParsedTokenAccountsByOwner(new PublicKey(owner), {
|
|
11629
|
+
programId: TOKEN_2022_PROGRAM_ID,
|
|
11630
|
+
}),
|
|
11631
|
+
]);
|
|
11600
11632
|
const wallets = walletsData.value;
|
|
11601
|
-
|
|
11633
|
+
const walletsToken22 = walletsDataToken22.value;
|
|
11634
|
+
const parseTokenAccount = (isToken22) => (wallet) => {
|
|
11602
11635
|
const tokenInfo = wallet.account.data.parsed;
|
|
11603
11636
|
return {
|
|
11604
11637
|
address: wallet.pubkey,
|
|
@@ -11608,8 +11641,13 @@ function getAllTokenAccountsWithBalances(connection, owner) {
|
|
|
11608
11641
|
isInitialized: true,
|
|
11609
11642
|
isNative: tokenInfo.info.isNative,
|
|
11610
11643
|
owner: new PublicKey(tokenInfo.info.owner),
|
|
11644
|
+
isToken22,
|
|
11611
11645
|
};
|
|
11612
|
-
}
|
|
11646
|
+
};
|
|
11647
|
+
return [
|
|
11648
|
+
...wallets.map(parseTokenAccount(false)),
|
|
11649
|
+
...walletsToken22.map(parseTokenAccount(true)),
|
|
11650
|
+
];
|
|
11613
11651
|
});
|
|
11614
11652
|
}
|
|
11615
11653
|
/**
|
|
@@ -11620,7 +11658,11 @@ function getAllTokenAccountsWithBalances(connection, owner) {
|
|
|
11620
11658
|
*/
|
|
11621
11659
|
function getTokenAccountsWithBalance(connection, tokenMint, owner) {
|
|
11622
11660
|
return __awaiter(this, void 0, void 0, function* () {
|
|
11623
|
-
const
|
|
11661
|
+
const mint = new PublicKey(tokenMint);
|
|
11662
|
+
const [walletsData, accountInfo] = yield Promise.all([
|
|
11663
|
+
connection.getParsedTokenAccountsByOwner(new PublicKey(owner), { mint }),
|
|
11664
|
+
connection.getAccountInfo(mint),
|
|
11665
|
+
]);
|
|
11624
11666
|
const wallets = walletsData.value;
|
|
11625
11667
|
return wallets.map((wallet) => {
|
|
11626
11668
|
const tokenInfo = wallet.account.data.parsed;
|
|
@@ -11632,6 +11674,7 @@ function getTokenAccountsWithBalance(connection, tokenMint, owner) {
|
|
|
11632
11674
|
isInitialized: true,
|
|
11633
11675
|
isNative: tokenInfo.info.isNative,
|
|
11634
11676
|
owner: new PublicKey(tokenInfo.info.owner),
|
|
11677
|
+
isToken22: accountInfo.owner.equals(TOKEN_2022_PROGRAM_ID),
|
|
11635
11678
|
};
|
|
11636
11679
|
});
|
|
11637
11680
|
});
|