Skip to content

Instantly share code, notes, and snippets.

@gallynaut
Created March 2, 2023 14:51
Show Gist options
  • Save gallynaut/f960caffd71b4c3818d285497f74fc18 to your computer and use it in GitHub Desktop.
Save gallynaut/f960caffd71b4c3818d285497f74fc18 to your computer and use it in GitHub Desktop.
Fetch Aggregator Balance
import { clusterApiUrl, Connection } from '@solana/web3.js';
import {
AccountNotFoundError,
AggregatorAccount,
LeaseAccount,
SwitchboardProgram,
} from '@switchboard-xyz/solana.js';
async function main() {
const program = await SwitchboardProgram.load(
'mainnet-beta',
new Connection(clusterApiUrl('mainnet-beta'))
);
const [aggregatorAccount, aggregatorState] = await AggregatorAccount.load(
program,
'GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR'
);
const [leaseAccount] = LeaseAccount.fromSeed(
program,
aggregatorState.queuePubkey,
aggregatorAccount.publicKey
);
const leaseEscrow = program.mint.getAssociatedAddress(leaseAccount.publicKey);
const balance = await program.mint.fetchBalance(leaseEscrow);
if (balance === null) {
throw new AccountNotFoundError('Lease Escrow', leaseEscrow);
}
console.log(`Lease Balance: ${balance}`);
}
main()
.then()
.catch(error => {
console.error(error);
});
@gallynaut
Copy link
Author

you can also use

  const [aggregatorAccount, aggregatorState] = new AggregatorAccount.load(
    program,
    'GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR'
  );

  const balance = await aggregatorAccount.fetchBalance();
  if (balance === null) {
    throw new AccountNotFoundError('Lease Escrow', leaseEscrow);
  }

  console.log(`Lease Balance: ${balance}`);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment