fixed getOrCreateSwitchboardTokenAccount fn

This commit is contained in:
Conner Gallagher 2022-07-05 08:20:09 -06:00
parent 183d9c970c
commit 154c66ff3c
9 changed files with 22 additions and 24 deletions

View File

@ -1,5 +1,5 @@
import { PublicKey } from "@solana/web3.js";
import { getOrCreateSwitchboardMintTokenAccount } from "@switchboard-xyz/sbv2-utils";
import { getOrCreateSwitchboardTokenAccount } from "@switchboard-xyz/sbv2-utils";
import {
AggregatorAccount,
OracleQueueAccount,
@ -44,7 +44,7 @@ export default class AggregatorUpdate extends BaseCommand {
const mint = await oracleQueueAccount.loadMint();
const payoutWallet = await getOrCreateSwitchboardMintTokenAccount(
const payoutWallet = await getOrCreateSwitchboardTokenAccount(
this.program,
mint
);

View File

@ -1,5 +1,5 @@
import { PublicKey } from "@solana/web3.js";
import { getOrCreateSwitchboardMintTokenAccount } from "@switchboard-xyz/sbv2-utils";
import { getOrCreateSwitchboardTokenAccount } from "@switchboard-xyz/sbv2-utils";
import {
CrankAccount,
OracleQueueAccount,
@ -56,7 +56,7 @@ export default class CrankTurn extends BaseCommand {
// get payer payout wallet
const mint = await programStateAccount.getTokenMint();
const payoutTokenAddress = await getOrCreateSwitchboardMintTokenAccount(
const payoutTokenAddress = await getOrCreateSwitchboardTokenAccount(
this.program,
mint,
payer

View File

@ -2,7 +2,7 @@ import { Flags } from "@oclif/core";
import * as anchor from "@project-serum/anchor";
import { PublicKey } from "@solana/web3.js";
import {
getOrCreateSwitchboardMintTokenAccount,
getOrCreateSwitchboardTokenAccount,
prettyPrintLease,
} from "@switchboard-xyz/sbv2-utils";
import {
@ -69,7 +69,7 @@ export default class LeaseCreate extends BaseCommand {
const mint = await oracleQueueAccount.loadMint();
// check funder has enough balance for the request
const funderTokenAddress = await getOrCreateSwitchboardMintTokenAccount(
const funderTokenAddress = await getOrCreateSwitchboardTokenAccount(
this.program,
mint,
payer

View File

@ -3,7 +3,7 @@ import * as anchor from "@project-serum/anchor";
import { PublicKey } from "@solana/web3.js";
import {
chalkString,
getOrCreateSwitchboardMintTokenAccount,
getOrCreateSwitchboardTokenAccount,
verifyProgramHasPayer,
} from "@switchboard-xyz/sbv2-utils";
import {
@ -82,7 +82,7 @@ export default class LeaseExtend extends BaseCommand {
const initialLeaseBalance =
await this.program.provider.connection.getTokenAccountBalance(escrow);
const funderTokenAddress = await getOrCreateSwitchboardMintTokenAccount(
const funderTokenAddress = await getOrCreateSwitchboardTokenAccount(
this.program,
mint
);

View File

@ -3,7 +3,7 @@ import * as anchor from "@project-serum/anchor";
import { PublicKey } from "@solana/web3.js";
import {
chalkString,
getOrCreateSwitchboardMintTokenAccount,
getOrCreateSwitchboardTokenAccount,
verifyProgramHasPayer,
} from "@switchboard-xyz/sbv2-utils";
import {
@ -82,7 +82,7 @@ export default class AggregatorLeaseWithdraw extends BaseCommand {
} catch {
try {
const withdrawKeypair = await loadKeypair(flags.withdrawAddress);
withdrawAddress = await getOrCreateSwitchboardMintTokenAccount(
withdrawAddress = await getOrCreateSwitchboardTokenAccount(
this.program,
mint,
withdrawKeypair
@ -94,7 +94,7 @@ export default class AggregatorLeaseWithdraw extends BaseCommand {
}
}
} else {
withdrawAddress = await getOrCreateSwitchboardMintTokenAccount(
withdrawAddress = await getOrCreateSwitchboardTokenAccount(
this.program,
mint
);

View File

@ -4,7 +4,7 @@ import * as spl from "@solana/spl-token";
import { PublicKey } from "@solana/web3.js";
import {
chalkString,
getOrCreateSwitchboardMintTokenAccount,
getOrCreateSwitchboardTokenAccount,
} from "@switchboard-xyz/sbv2-utils";
import {
OracleAccount,
@ -72,7 +72,7 @@ export default class OracleDeposit extends BaseCommand {
).value.amount
);
const funderTokenAddress = await getOrCreateSwitchboardMintTokenAccount(
const funderTokenAddress = await getOrCreateSwitchboardTokenAccount(
this.program,
mint
);

View File

@ -3,7 +3,7 @@ import * as anchor from "@project-serum/anchor";
import { PublicKey } from "@solana/web3.js";
import {
chalkString,
getOrCreateSwitchboardMintTokenAccount,
getOrCreateSwitchboardTokenAccount,
} from "@switchboard-xyz/sbv2-utils";
import {
OracleAccount,
@ -122,7 +122,7 @@ export default class OracleWithdraw extends BaseCommand {
} catch {
try {
const withdrawKeypair = await loadKeypair(flags.withdrawAccount);
withdrawAccount = await getOrCreateSwitchboardMintTokenAccount(
withdrawAccount = await getOrCreateSwitchboardTokenAccount(
this.program,
mint,
withdrawKeypair
@ -134,7 +134,7 @@ export default class OracleWithdraw extends BaseCommand {
}
}
} else {
withdrawAccount = await getOrCreateSwitchboardMintTokenAccount(
withdrawAccount = await getOrCreateSwitchboardTokenAccount(
this.program,
mint
);

View File

@ -1,7 +1,7 @@
import { Flags } from "@oclif/core";
import * as spl from "@solana/spl-token";
import { PublicKey, SYSVAR_RECENT_BLOCKHASHES_PUBKEY } from "@solana/web3.js";
import { getOrCreateSwitchboardMintTokenAccount } from "@switchboard-xyz/sbv2-utils";
import { getOrCreateSwitchboardTokenAccount } from "@switchboard-xyz/sbv2-utils";
import {
OracleQueueAccount,
PermissionAccount,
@ -67,7 +67,7 @@ export default class VrfRequest extends BaseCommand {
? await loadKeypair(flags.funderAuthority)
: payerKeypair;
const funderTokenWallet = await getOrCreateSwitchboardMintTokenAccount(
const funderTokenWallet = await getOrCreateSwitchboardTokenAccount(
this.program,
mint
);

View File

@ -6,14 +6,12 @@ import {
programWallet,
} from "@switchboard-xyz/switchboard-v2";
export const getOrCreateSwitchboardMintTokenAccount = async (
export const getOrCreateSwitchboardTokenAccount = async (
program: anchor.Program,
switchboardMint?: spl.Mint,
payer = programWallet(program)
): Promise<PublicKey> => {
const returnAssociatedAddress = async (
mint: spl.Mint
): Promise<PublicKey> => {
const getAssociatedAddress = async (mint: spl.Mint): Promise<PublicKey> => {
const tokenAccount = await spl.getOrCreateAssociatedTokenAccount(
program.provider.connection,
payer,
@ -30,12 +28,12 @@ export const getOrCreateSwitchboardMintTokenAccount = async (
let mint = switchboardMint;
if (mint) {
returnAssociatedAddress(mint);
return getAssociatedAddress(mint);
}
const [programState] = ProgramStateAccount.fromSeed(program);
mint = await programState.getTokenMint();
if (mint) {
returnAssociatedAddress(mint);
return getAssociatedAddress(mint);
}
throw new Error(`failed to get associated token account`);