@nosana/kit
Version:
Nosana KIT
39 lines • 1.41 kB
JavaScript
/**
* Gets the static accounts, initializing them if needed.
* This function caches the result to avoid redundant PDA lookups.
*
* @param programsConfig - Programs configuration
* @param solana - Solana service for PDA lookups
* @param cache - Optional cache object to store the result (for memoization)
* @returns Promise resolving to static accounts
*/
export async function getStaticAccounts(programsConfig, solana, cache) {
// Return cached value if available
if (cache?.value) {
return cache.value;
}
// If we're already initializing, return the existing promise
if (cache?.promise) {
return cache.promise;
}
// Start initialization and store the promise
const promise = (async () => {
const staticAccounts = {
rewardsReflection: await solana.pda(['reflection'], programsConfig.rewardsAddress),
rewardsVault: await solana.pda([programsConfig.nosTokenAddress], programsConfig.rewardsAddress),
rewardsProgram: programsConfig.rewardsAddress,
jobsProgram: programsConfig.jobsAddress,
};
// Cache the result
if (cache) {
cache.value = staticAccounts;
cache.promise = undefined;
}
return staticAccounts;
})();
if (cache) {
cache.promise = promise;
}
return promise;
}
//# sourceMappingURL=getStaticAccounts.js.map