Created
March 2, 2023 14:51
-
-
Save gallynaut/f960caffd71b4c3818d285497f74fc18 to your computer and use it in GitHub Desktop.
Fetch Aggregator Balance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can also use