UNPKG

@drift-labs/sdk

Version:
61 lines (60 loc) 3.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fetchAccounts = exports.fetchAccount = exports.fetchRevenueShareEscrowAccount = exports.fetchRevenueShareAccount = exports.fetchUserStatsAccount = exports.fetchUserAccountsUsingKeys = exports.fetchUserAccounts = void 0; const pda_1 = require("../addresses/pda"); async function fetchUserAccounts(connection, program, authority, limit = 8) { const userAccountPublicKeys = new Array(); for (let i = 0; i < limit; i++) { userAccountPublicKeys.push(await (0, pda_1.getUserAccountPublicKey)(program.programId, authority, i)); } return fetchUserAccountsUsingKeys(connection, program, userAccountPublicKeys); } exports.fetchUserAccounts = fetchUserAccounts; async function fetchUserAccountsUsingKeys(connection, program, userAccountPublicKeys) { const accountInfos = await connection.getMultipleAccountsInfo(userAccountPublicKeys, 'confirmed'); return accountInfos.map((accountInfo) => { if (!accountInfo) { return undefined; } return program.account.user.coder.accounts.decodeUnchecked('user', accountInfo.data); }); } exports.fetchUserAccountsUsingKeys = fetchUserAccountsUsingKeys; async function fetchUserStatsAccount(connection, program, authority) { const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(program.programId, authority); const accountInfo = await connection.getAccountInfo(userStatsPublicKey, 'confirmed'); return accountInfo ? program.account.user.coder.accounts.decodeUnchecked('userStats', accountInfo.data) : undefined; } exports.fetchUserStatsAccount = fetchUserStatsAccount; async function fetchRevenueShareAccount(connection, program, authority) { const revenueShareAccountPublicKey = (0, pda_1.getRevenueShareAccountPublicKey)(program.programId, authority); const accountInfo = await connection.getAccountInfo(revenueShareAccountPublicKey); if (!accountInfo) return null; return program.account.revenueShare.coder.accounts.decode('revenueShare', accountInfo.data); } exports.fetchRevenueShareAccount = fetchRevenueShareAccount; async function fetchRevenueShareEscrowAccount(connection, program, authority) { const revenueShareEscrowPubKey = (0, pda_1.getRevenueShareEscrowAccountPublicKey)(program.programId, authority); const escrow = await connection.getAccountInfo(revenueShareEscrowPubKey); if (!escrow) return null; const escrowAccount = program.account.revenueShareEscrow.coder.accounts.decode('revenueShareEscrow', escrow.data); return escrowAccount; } exports.fetchRevenueShareEscrowAccount = fetchRevenueShareEscrowAccount; /** Raw account data buffer (no Anchor decode). */ async function fetchAccount(connection, publicKey, opts) { var _a; const info = await connection.getAccountInfo(publicKey, opts === null || opts === void 0 ? void 0 : opts.commitment); return (_a = info === null || info === void 0 ? void 0 : info.data) !== null && _a !== void 0 ? _a : null; } exports.fetchAccount = fetchAccount; /** Batch variant of {@link fetchAccount}. */ async function fetchAccounts(connection, publicKeys, opts) { const infos = await connection.getMultipleAccountsInfo(publicKeys, opts === null || opts === void 0 ? void 0 : opts.commitment); return infos.map((info) => { var _a; return (_a = info === null || info === void 0 ? void 0 : info.data) !== null && _a !== void 0 ? _a : null; }); } exports.fetchAccounts = fetchAccounts;