Skip to content

Commit

Permalink
Fetch multiple token managers
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbogle committed Feb 4, 2022
1 parent a40fb3d commit ac0cc2f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/programs/tokenManager/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,36 @@ export const getTokenManager = async (
pubkey: tokenManagerId,
};
};

export const getTokenManagers = async (
connection: Connection,
tokenManagerIds: PublicKey[]
): Promise<AccountData<TokenManagerData[]>> => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const provider = new Provider(connection, null, {});
const tokenManagerProgram = new Program<TOKEN_MANAGER_PROGRAM>(
TOKEN_MANAGER_IDL,
TOKEN_MANAGER_ADDRESS,
provider
);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
let tokenManagers = [];
try {
tokenManagers =
await tokenManagerProgram.account.tokenManager.fetchMultiple(
tokenManagerIds
);
} catch (e) {
console.log(e);
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return tokenManagers.map((tm, i) => ({
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
parsed: tm,
pubkey: tokenManagerIds[i],
}));
};

0 comments on commit ac0cc2f

Please sign in to comment.