import { PublicKey } from ".."; export type FetchPDAsOption = { id?: { from: number; to: number; }; }; export const defaultOption: FetchPDAsOption = { id: { from: 0, to: 0, }, }; const textEncoder = new TextEncoder(); async function fetchPDAs( seeds: string, programId: PublicKey, options: FetchPDAsOption = {} ): Promise { options = { ...defaultOption, ...options, }; const { id: { from, to } = {} } = options; const result: PublicKey[] = []; if (from && to) { for (let id = from; id < to; id++) { const [pda, _] = await PublicKey.findProgramAddress( [textEncoder.encode(`${seeds} ${id}`)], programId ); result.push(pda); } } else { result.push( ( await PublicKey.findProgramAddress( [textEncoder.encode(seeds)], programId ) )[0] ); } return result; } export default fetchPDAs;