solana.js: added OracleAccount fetchBalanceBN method

This commit is contained in:
Conner Gallagher 2022-12-13 10:27:58 -07:00
parent 809efaa016
commit 13a70f716b
1 changed files with 10 additions and 0 deletions

View File

@ -16,6 +16,7 @@ import { PermissionAccount } from './permissionAccount';
import { QueueAccount } from './queueAccount';
import * as spl from '@solana/spl-token';
import { TransactionObject } from '../transaction';
import BN from 'bn.js';
/**
* Account type holding an oracle's configuration including the authority and the reward/slashing wallet along with a set of metrics tracking its reliability.
@ -118,6 +119,15 @@ export class OracleAccount extends Account<types.OracleAccountData> {
return amount;
}
async fetchBalanceBN(stakingWallet?: PublicKey): Promise<BN> {
const tokenAccount = stakingWallet ?? (await this.loadData()).tokenAccount;
const amount = await this.program.mint.fetchBalanceBN(tokenAccount);
if (amount === null) {
throw new Error(`Failed to fetch oracle staking wallet balance`);
}
return amount;
}
/**
* Retrieve and decode the {@linkcode types.OracleAccountData} stored in this account.
*/