@kamino-finance/klend-sdk 7.1.3 → 7.1.4
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/classes/vault.d.ts +1 -1
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +46 -28
- package/dist/classes/vault.js.map +1 -1
- package/dist/manager/client_kamino_manager.js +1 -1
- package/dist/manager/client_kamino_manager.js.map +1 -1
- package/dist/utils/ata.d.ts +10 -1
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +47 -0
- package/dist/utils/ata.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/vault.ts +57 -38
- package/src/manager/client_kamino_manager.ts +1 -2
- package/src/utils/ata.ts +79 -0
package/src/utils/ata.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AccountInfoBase,
|
|
3
|
+
AccountInfoWithJsonData,
|
|
4
|
+
AccountInfoWithPubkey,
|
|
2
5
|
Address,
|
|
6
|
+
Base58EncodedBytes,
|
|
3
7
|
fetchEncodedAccount,
|
|
4
8
|
GetAccountInfoApi,
|
|
5
9
|
GetMultipleAccountsApi,
|
|
@@ -8,6 +12,7 @@ import {
|
|
|
8
12
|
Lamports,
|
|
9
13
|
MaybeAccount,
|
|
10
14
|
Rpc,
|
|
15
|
+
SolanaRpcApi,
|
|
11
16
|
TransactionSigner,
|
|
12
17
|
} from '@solana/kit';
|
|
13
18
|
import Decimal from 'decimal.js';
|
|
@@ -262,3 +267,77 @@ export const createWsolAtaIfMissing = async (
|
|
|
262
267
|
closeAtaIxs: closeIxs,
|
|
263
268
|
};
|
|
264
269
|
};
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Get all standard token accounts for tokens using old Token Program, not Token 2022 for a given wallet
|
|
273
|
+
* @param rpc - Solana RPC rpc (read)
|
|
274
|
+
* @param wallet - wallet to get the token accounts for
|
|
275
|
+
* @returns an array of all token accounts for the given wallet
|
|
276
|
+
*/
|
|
277
|
+
export async function getAllStandardTokenProgramTokenAccounts(
|
|
278
|
+
rpc: Rpc<SolanaRpcApi>,
|
|
279
|
+
wallet: Address
|
|
280
|
+
): Promise<AccountInfoWithPubkey<AccountInfoBase & AccountInfoWithJsonData>[]> {
|
|
281
|
+
return rpc
|
|
282
|
+
.getProgramAccounts(TOKEN_PROGRAM_ADDRESS, {
|
|
283
|
+
filters: [
|
|
284
|
+
{ dataSize: 165n },
|
|
285
|
+
{ memcmp: { offset: 32n, bytes: wallet.toString() as Base58EncodedBytes, encoding: 'base58' } },
|
|
286
|
+
],
|
|
287
|
+
encoding: 'jsonParsed',
|
|
288
|
+
})
|
|
289
|
+
.send();
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Type definitions for parsed token account data
|
|
293
|
+
interface ParsedTokenAccountInfo {
|
|
294
|
+
mint: string;
|
|
295
|
+
owner: string;
|
|
296
|
+
tokenAmount: {
|
|
297
|
+
amount: string;
|
|
298
|
+
decimals: number;
|
|
299
|
+
uiAmount: number | null;
|
|
300
|
+
uiAmountString: string;
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
interface ParsedTokenAccountData {
|
|
305
|
+
parsed: {
|
|
306
|
+
info: ParsedTokenAccountInfo;
|
|
307
|
+
type: string;
|
|
308
|
+
};
|
|
309
|
+
program: string;
|
|
310
|
+
space: bigint;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Type guard to check if account data is parsed
|
|
314
|
+
function isParsedTokenAccountData(data: any): data is ParsedTokenAccountData {
|
|
315
|
+
return (
|
|
316
|
+
data &&
|
|
317
|
+
typeof data === 'object' &&
|
|
318
|
+
'parsed' in data &&
|
|
319
|
+
data.parsed &&
|
|
320
|
+
typeof data.parsed === 'object' &&
|
|
321
|
+
'info' in data.parsed &&
|
|
322
|
+
data.parsed.info &&
|
|
323
|
+
typeof data.parsed.info === 'object' &&
|
|
324
|
+
'mint' in data.parsed.info &&
|
|
325
|
+
'tokenAmount' in data.parsed.info
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Helper function to safely get mint from parsed token account
|
|
330
|
+
export function getTokenAccountMint(accountData: any): string | null {
|
|
331
|
+
if (isParsedTokenAccountData(accountData)) {
|
|
332
|
+
return accountData.parsed.info.mint;
|
|
333
|
+
}
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Helper function to safely get token amount from parsed token account
|
|
338
|
+
export function getTokenAccountAmount(accountData: any): number | null {
|
|
339
|
+
if (isParsedTokenAccountData(accountData)) {
|
|
340
|
+
return accountData.parsed.info.tokenAmount.uiAmount;
|
|
341
|
+
}
|
|
342
|
+
return null;
|
|
343
|
+
}
|