@nosana/kit
Version:
Nosana KIT
36 lines (35 loc) • 1.29 kB
JavaScript
export class BaseProgram {
/**
* Gets the static accounts, initializing them if needed.
*/
async getStaticAccounts() {
if (this._staticAccounts) {
return this._staticAccounts;
}
// If we're already initializing, return the existing promise
if (this._initializingAccounts) {
return this._initializingAccounts;
}
// Start initialization and store the promise
this._initializingAccounts = this.initializeStaticAccounts();
// Wait for initialization to complete
this._staticAccounts = await this._initializingAccounts;
this._initializingAccounts = undefined;
return this._staticAccounts;
}
async initializeStaticAccounts() {
return {
rewardsReflection: await this.sdk.solana.pda([
'reflection',
], this.sdk.config.programs.rewardsAddress),
rewardsVault: await this.sdk.solana.pda([
this.sdk.config.programs.nosTokenAddress,
], this.sdk.config.programs.rewardsAddress),
rewardsProgram: this.sdk.config.programs.rewardsAddress,
jobsProgram: this.sdk.config.programs.jobsAddress
};
}
constructor(sdk) {
this.sdk = sdk;
}
}