import { AccountMeta } from "@solana/web3.js"; import cloneDeep from "deep-clone"; import { AccountsArray } from "../index"; // TODO: there is probably a faster way to do this export const deepCloneObject = (obj: T): T => { return cloneDeep(obj); }; export const findAllIndexes = ( arr: T[], discriminator: (T) => boolean ): number[] => { var indexes = []; for (let i = 0; i < arr.length; i++) { if (discriminator(arr[i])) indexes.push(i); } return indexes; }; export const flattenArrObject = (arr: T[]): T => arr.reduce((prev, item) => { return { ...item, ...prev }; }, {} as T); export const removeDuplicates = ( items: T[], toStringFn: (e: T) => string, fromStringFn: (s: string) => T ): T[] => { return [...new Set(items.map(toStringFn))].map(fromStringFn); }; export const actionMetasToAccountsArray = ( actionMetas: AccountMeta[] ): AccountsArray => actionMetas.map((a) => { return { isSigner: a.isSigner, isWriteable: a.isWritable, address: a.pubkey, }; });