solana.js: create methods return new account as first param
This commit is contained in:
parent
e530a583cb
commit
a8eb9893df
|
@ -125,7 +125,7 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
|||
*
|
||||
* ```ts
|
||||
* import {AggregatorAccount} from '@switchboard-xyz/solana.js';
|
||||
* const [aggregatorInit, aggregatorAccount] = await AggregatorAccount.createInstruction(program, payer, {
|
||||
* const [aggregatorAccount, aggregatorInit ] = await AggregatorAccount.createInstruction(program, payer, {
|
||||
* queueAccount,
|
||||
* queueAuthority,
|
||||
* batchSize: 5,
|
||||
|
@ -140,7 +140,7 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
|||
program: SwitchboardProgram,
|
||||
payer: PublicKey,
|
||||
params: AggregatorInitParams
|
||||
): Promise<[TransactionObject, AggregatorAccount]> {
|
||||
): Promise<[AggregatorAccount, TransactionObject]> {
|
||||
const keypair = params.keypair ?? Keypair.generate();
|
||||
program.verifyNewKeypair(keypair);
|
||||
|
||||
|
@ -194,7 +194,7 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
|||
const aggregatorInit = new TransactionObject(payer, ixns, signers);
|
||||
const aggregatorAccount = new AggregatorAccount(program, keypair.publicKey);
|
||||
|
||||
return [aggregatorInit, aggregatorAccount];
|
||||
return [aggregatorAccount, aggregatorInit];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,7 +207,7 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
|||
*
|
||||
* ```ts
|
||||
* import {AggregatorAccount} from '@switchboard-xyz/solana.js';
|
||||
* const [txnSignature, aggregatorAccount] = await AggregatorAccount.create(program, {
|
||||
* const [aggregatorAccount, txnSignature] = await AggregatorAccount.create(program, {
|
||||
* queueAccount,
|
||||
* queueAuthority,
|
||||
* batchSize: 5,
|
||||
|
@ -221,14 +221,14 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
|||
public static async create(
|
||||
program: SwitchboardProgram,
|
||||
params: AggregatorInitParams
|
||||
): Promise<[TransactionSignature, AggregatorAccount]> {
|
||||
const [transaction, account] = await AggregatorAccount.createInstruction(
|
||||
): Promise<[AggregatorAccount, TransactionSignature]> {
|
||||
const [account, transaction] = await AggregatorAccount.createInstruction(
|
||||
program,
|
||||
program.walletPubkey,
|
||||
params
|
||||
);
|
||||
const txnSignature = await program.signAndSend(transaction);
|
||||
return [txnSignature, account];
|
||||
return [account, txnSignature];
|
||||
}
|
||||
|
||||
public getAccounts(params: {
|
||||
|
|
|
@ -147,10 +147,10 @@ export class AggregatorHistoryBuffer extends Account<
|
|||
* Basic usage example:
|
||||
*
|
||||
* ```ts
|
||||
* import {AggregatorAccount,AggregatorHistoryBuffer} from '@switchboard-xyz/solana.js';
|
||||
* import { AggregatorAccount,AggregatorHistoryBuffer } from '@switchboard-xyz/solana.js';
|
||||
* const aggregatorAccount = new AggregatorAccount(program, aggregatorKey);
|
||||
* const aggregator = await aggregatorAccount.loadData();
|
||||
* const [addHistoryTxn, historyBuffer] = await AggregatorHistoryBuffer.createInstructions(program, payer, {
|
||||
* const [historyBuffer, addHistoryTxn] = await AggregatorHistoryBuffer.createInstructions(program, payer, {
|
||||
* aggregatorAccount,
|
||||
* maxSamples: 10000,
|
||||
* });
|
||||
|
@ -162,7 +162,7 @@ export class AggregatorHistoryBuffer extends Account<
|
|||
program: SwitchboardProgram,
|
||||
payer: PublicKey,
|
||||
params: AggregatorHistoryInit
|
||||
): Promise<[TransactionObject, AggregatorHistoryBuffer]> {
|
||||
): Promise<[AggregatorHistoryBuffer, TransactionObject]> {
|
||||
const buffer = params.keypair ?? Keypair.generate();
|
||||
program.verifyNewKeypair(buffer);
|
||||
|
||||
|
@ -199,8 +199,8 @@ export class AggregatorHistoryBuffer extends Account<
|
|||
);
|
||||
|
||||
return [
|
||||
new TransactionObject(payer, ixns, signers),
|
||||
new AggregatorHistoryBuffer(program, buffer.publicKey),
|
||||
new TransactionObject(payer, ixns, signers),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -214,10 +214,10 @@ export class AggregatorHistoryBuffer extends Account<
|
|||
* Basic usage example:
|
||||
*
|
||||
* ```ts
|
||||
* import {AggregatorAccount,AggregatorHistoryBuffer} from '@switchboard-xyz/solana.js';
|
||||
* import { AggregatorAccount,AggregatorHistoryBuffer } from '@switchboard-xyz/solana.js';
|
||||
* const aggregatorAccount = new AggregatorAccount(program, aggregatorKey);
|
||||
* const aggregator = await aggregatorAccount.loadData();
|
||||
* const [addHistorySignature, historyBuffer] = await AggregatorHistoryBuffer.create(program, {
|
||||
* const [historyBuffer, addHistorySignature] = await AggregatorHistoryBuffer.create(program, {
|
||||
* aggregatorAccount,
|
||||
* maxSamples: 10000,
|
||||
* });
|
||||
|
@ -227,14 +227,14 @@ export class AggregatorHistoryBuffer extends Account<
|
|||
public static async create(
|
||||
program: SwitchboardProgram,
|
||||
params: AggregatorHistoryInit
|
||||
): Promise<[TransactionSignature, AggregatorHistoryBuffer]> {
|
||||
const [transaction, account] =
|
||||
): Promise<[AggregatorHistoryBuffer, TransactionSignature]> {
|
||||
const [account, transaction] =
|
||||
await AggregatorHistoryBuffer.createInstructions(
|
||||
program,
|
||||
program.walletPubkey,
|
||||
params
|
||||
);
|
||||
const txnSignature = await program.signAndSend(transaction);
|
||||
return [txnSignature, account];
|
||||
return [account, txnSignature];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ export class BufferRelayerAccount extends Account<types.BufferRelayerAccountData
|
|||
jobAccount: JobAccount;
|
||||
keypair?: Keypair;
|
||||
}
|
||||
): Promise<[TransactionObject, BufferRelayerAccount]> {
|
||||
): Promise<[BufferRelayerAccount, TransactionObject]> {
|
||||
const keypair = params.keypair ?? Keypair.generate();
|
||||
program.verifyNewKeypair(keypair);
|
||||
|
||||
|
@ -143,8 +143,8 @@ export class BufferRelayerAccount extends Account<types.BufferRelayerAccountData
|
|||
);
|
||||
|
||||
return [
|
||||
new TransactionObject(payer, ixns, [keypair]),
|
||||
new BufferRelayerAccount(program, keypair.publicKey),
|
||||
new TransactionObject(payer, ixns, [keypair]),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -158,15 +158,15 @@ export class BufferRelayerAccount extends Account<types.BufferRelayerAccountData
|
|||
jobAccount: JobAccount;
|
||||
keypair?: Keypair;
|
||||
}
|
||||
): Promise<[TransactionSignature, BufferRelayerAccount]> {
|
||||
const [bufferInit, bufferAccount] =
|
||||
): Promise<[BufferRelayerAccount, TransactionSignature]> {
|
||||
const [bufferAccount, bufferInit] =
|
||||
await BufferRelayerAccount.createInstructions(
|
||||
program,
|
||||
program.walletPubkey,
|
||||
params
|
||||
);
|
||||
const txnSignature = await program.signAndSend(bufferInit);
|
||||
return [txnSignature, bufferAccount];
|
||||
return [bufferAccount, txnSignature];
|
||||
}
|
||||
|
||||
public async openRoundInstructions(
|
||||
|
|
|
@ -72,7 +72,7 @@ export class CrankAccount extends Account<types.CrankAccountData> {
|
|||
program: SwitchboardProgram,
|
||||
payer: PublicKey,
|
||||
params: CrankInitParams
|
||||
): Promise<[TransactionObject, CrankAccount]> {
|
||||
): Promise<[CrankAccount, TransactionObject]> {
|
||||
const crankAccount = params.keypair ?? Keypair.generate();
|
||||
program.verifyNewKeypair(crankAccount);
|
||||
|
||||
|
@ -115,20 +115,20 @@ export class CrankAccount extends Account<types.CrankAccountData> {
|
|||
[crankAccount, buffer]
|
||||
);
|
||||
|
||||
return [crankInit, new CrankAccount(program, crankAccount.publicKey)];
|
||||
return [new CrankAccount(program, crankAccount.publicKey), crankInit];
|
||||
}
|
||||
|
||||
public static async create(
|
||||
program: SwitchboardProgram,
|
||||
params: CrankInitParams
|
||||
): Promise<[TransactionSignature, CrankAccount]> {
|
||||
const [crankInit, crankAccount] = await CrankAccount.createInstructions(
|
||||
): Promise<[CrankAccount, TransactionSignature]> {
|
||||
const [crankAccount, crankInit] = await CrankAccount.createInstructions(
|
||||
program,
|
||||
program.walletPubkey,
|
||||
params
|
||||
);
|
||||
const txnSignature = await program.signAndSend(crankInit);
|
||||
return [txnSignature, crankAccount];
|
||||
return [crankAccount, txnSignature];
|
||||
}
|
||||
|
||||
public async popInstruction(
|
||||
|
|
|
@ -84,7 +84,9 @@ export class CrankDataBuffer extends Account<Array<types.CrankRow>> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return an aggregator's assigned history buffer or undefined if it doesn't exist.
|
||||
* Return a crank's dataBuffer
|
||||
*
|
||||
* @throws {string} if dataBuffer is equal to default publicKey
|
||||
*/
|
||||
static fromCrank(
|
||||
program: SwitchboardProgram,
|
||||
|
|
|
@ -51,7 +51,7 @@ export class JobAccount extends Account<types.JobAccountData> {
|
|||
program: SwitchboardProgram,
|
||||
payer: PublicKey,
|
||||
params: JobInitParams
|
||||
): [Array<TransactionObject>, JobAccount] {
|
||||
): [JobAccount, Array<TransactionObject>] {
|
||||
if (params.data.byteLength > 6400) {
|
||||
throw new Error('Switchboard jobs need to be less than 6400 bytes');
|
||||
}
|
||||
|
@ -138,20 +138,20 @@ export class JobAccount extends Account<types.JobAccountData> {
|
|||
}
|
||||
}
|
||||
|
||||
return [txns, new JobAccount(program, jobKeypair.publicKey)];
|
||||
return [new JobAccount(program, jobKeypair.publicKey), txns];
|
||||
}
|
||||
|
||||
public static async create(
|
||||
program: SwitchboardProgram,
|
||||
params: JobInitParams
|
||||
): Promise<[Array<TransactionSignature>, JobAccount]> {
|
||||
const [transactions, account] = JobAccount.createInstructions(
|
||||
): Promise<[JobAccount, Array<TransactionSignature>]> {
|
||||
const [account, transactions] = JobAccount.createInstructions(
|
||||
program,
|
||||
program.walletPubkey,
|
||||
params
|
||||
);
|
||||
const txSignature = await program.signAndSendAll(transactions);
|
||||
return [txSignature, account];
|
||||
return [account, txSignature];
|
||||
}
|
||||
|
||||
decode(data: Buffer): types.JobAccountData {
|
||||
|
|
|
@ -102,7 +102,7 @@ export class LeaseAccount extends Account<types.LeaseAccountData> {
|
|||
withdrawAuthority?: PublicKey;
|
||||
jobAuthorities: Array<PublicKey>;
|
||||
}
|
||||
): Promise<[TransactionObject, LeaseAccount]> {
|
||||
): Promise<[LeaseAccount, TransactionObject]> {
|
||||
const ixns: TransactionInstruction[] = [];
|
||||
const signers: Keypair[] = [];
|
||||
|
||||
|
@ -183,7 +183,7 @@ export class LeaseAccount extends Account<types.LeaseAccountData> {
|
|||
)
|
||||
);
|
||||
|
||||
return [new TransactionObject(payer, ixns, signers), leaseAccount];
|
||||
return [leaseAccount, new TransactionObject(payer, ixns, signers)];
|
||||
}
|
||||
|
||||
public static async create(
|
||||
|
@ -198,8 +198,8 @@ export class LeaseAccount extends Account<types.LeaseAccountData> {
|
|||
withdrawAuthority?: PublicKey;
|
||||
jobAuthorities: Array<PublicKey>;
|
||||
}
|
||||
): Promise<[TransactionSignature, LeaseAccount]> {
|
||||
const [transaction, leaseAccount] = await LeaseAccount.createInstructions(
|
||||
): Promise<[LeaseAccount, TransactionSignature]> {
|
||||
const [leaseAccount, transaction] = await LeaseAccount.createInstructions(
|
||||
program,
|
||||
program.walletPubkey,
|
||||
{
|
||||
|
@ -211,7 +211,7 @@ export class LeaseAccount extends Account<types.LeaseAccountData> {
|
|||
|
||||
const signature = await program.signAndSend(transaction);
|
||||
|
||||
return [signature, leaseAccount];
|
||||
return [leaseAccount, signature];
|
||||
}
|
||||
|
||||
public async getBalance(): Promise<number> {
|
||||
|
|
|
@ -48,7 +48,7 @@ export class OracleAccount extends Account<types.OracleAccountData> {
|
|||
params: {
|
||||
queueAccount: QueueAccount;
|
||||
} & OracleInitParams
|
||||
): Promise<[TransactionObject, OracleAccount]> {
|
||||
): Promise<[OracleAccount, TransactionObject]> {
|
||||
const tokenWallet = Keypair.generate();
|
||||
// console.log(`tokenWallet`, tokenWallet.publicKey.toBase58());
|
||||
|
||||
|
@ -108,12 +108,12 @@ export class OracleAccount extends Account<types.OracleAccountData> {
|
|||
];
|
||||
|
||||
return [
|
||||
new OracleAccount(program, oracleAccount.publicKey),
|
||||
new TransactionObject(
|
||||
payer,
|
||||
ixns,
|
||||
params.authority ? [tokenWallet, params.authority] : [tokenWallet]
|
||||
),
|
||||
new OracleAccount(program, oracleAccount.publicKey),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -122,8 +122,8 @@ export class OracleAccount extends Account<types.OracleAccountData> {
|
|||
params: {
|
||||
queueAccount: QueueAccount;
|
||||
} & OracleInitParams
|
||||
): Promise<[TransactionSignature, OracleAccount]> {
|
||||
const [txnObject, oracleAccount] = await OracleAccount.createInstructions(
|
||||
): Promise<[OracleAccount, TransactionSignature]> {
|
||||
const [oracleAccount, txnObject] = await OracleAccount.createInstructions(
|
||||
program,
|
||||
program.walletPubkey,
|
||||
params
|
||||
|
@ -131,7 +131,7 @@ export class OracleAccount extends Account<types.OracleAccountData> {
|
|||
|
||||
const txnSignature = await program.signAndSend(txnObject);
|
||||
|
||||
return [txnSignature, oracleAccount];
|
||||
return [oracleAccount, txnSignature];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
import * as anchor from '@project-serum/anchor';
|
||||
import { Keypair, PublicKey, SystemProgram } from '@solana/web3.js';
|
||||
import {
|
||||
Keypair,
|
||||
PublicKey,
|
||||
SystemProgram,
|
||||
TransactionSignature,
|
||||
} from '@solana/web3.js';
|
||||
import * as errors from '../errors';
|
||||
import * as types from '../generated';
|
||||
import { SwitchboardProgram } from '../program';
|
||||
|
@ -60,24 +65,11 @@ export class PermissionAccount extends Account<types.PermissionAccountData> {
|
|||
return [new PermissionAccount(program, publicKey), bump];
|
||||
}
|
||||
|
||||
public static async create(
|
||||
program: SwitchboardProgram,
|
||||
params: PermissionAccountInitParams
|
||||
): Promise<[string, PermissionAccount]> {
|
||||
const [txnObject, account] = this.createInstruction(
|
||||
program,
|
||||
program.walletPubkey,
|
||||
params
|
||||
);
|
||||
const txSignature = await program.signAndSend(txnObject);
|
||||
return [txSignature, account];
|
||||
}
|
||||
|
||||
public static createInstruction(
|
||||
program: SwitchboardProgram,
|
||||
payer: PublicKey,
|
||||
params: PermissionAccountInitParams
|
||||
): [TransactionObject, PermissionAccount] {
|
||||
): [PermissionAccount, TransactionObject] {
|
||||
const [account] = PermissionAccount.fromSeed(
|
||||
program,
|
||||
params.authority,
|
||||
|
@ -96,7 +88,20 @@ export class PermissionAccount extends Account<types.PermissionAccountData> {
|
|||
payer,
|
||||
}
|
||||
);
|
||||
return [new TransactionObject(payer, [instruction], []), account];
|
||||
return [account, new TransactionObject(payer, [instruction], [])];
|
||||
}
|
||||
|
||||
public static async create(
|
||||
program: SwitchboardProgram,
|
||||
params: PermissionAccountInitParams
|
||||
): Promise<[PermissionAccount, TransactionSignature]> {
|
||||
const [account, txnObject] = this.createInstruction(
|
||||
program,
|
||||
program.walletPubkey,
|
||||
params
|
||||
);
|
||||
const txSignature = await program.signAndSend(txnObject);
|
||||
return [account, txSignature];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,7 @@ import { Mint } from '../mint';
|
|||
import {
|
||||
PublicKey,
|
||||
SystemProgram,
|
||||
TransactionInstruction,
|
||||
TransactionSignature,
|
||||
} from '@solana/web3.js';
|
||||
import { TransactionObject } from '../transaction';
|
||||
|
@ -103,7 +104,7 @@ export class ProgramStateAccount extends Account<types.SbState> {
|
|||
program: SwitchboardProgram,
|
||||
mint = Mint.native,
|
||||
daoMint = Mint.native
|
||||
): [ProgramStateAccount, anchor.web3.TransactionInstruction] {
|
||||
): [ProgramStateAccount, TransactionInstruction] {
|
||||
const [programStateAccount, stateBump] =
|
||||
ProgramStateAccount.fromSeed(program);
|
||||
|
||||
|
|
|
@ -113,8 +113,8 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
* Basic usage example:
|
||||
*
|
||||
* ```ts
|
||||
* import {QueueAccount} from '@switchboard-xyz/solana.js';
|
||||
* const [queueInitTxn, queueAccount] = await QueueAccount.createInstructions(program, payer, {
|
||||
* import { QueueAccount } from '@switchboard-xyz/solana.js';
|
||||
* const [queueAccount, queueInitTxn] = await QueueAccount.createInstructions(program, payer, {
|
||||
name: 'My Queue',
|
||||
metadata: 'Top Secret',
|
||||
queueSize: 100,
|
||||
|
@ -134,7 +134,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
program: SwitchboardProgram,
|
||||
payer: PublicKey,
|
||||
params: QueueInitParams
|
||||
): Promise<[TransactionObject, QueueAccount]> {
|
||||
): Promise<[QueueAccount, TransactionObject]> {
|
||||
const queueKeypair = params.keypair ?? Keypair.generate();
|
||||
program.verifyNewKeypair(queueKeypair);
|
||||
|
||||
|
@ -148,16 +148,14 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
const reward = program.mint.toTokenAmountBN(params.reward);
|
||||
const minStake = program.mint.toTokenAmountBN(params.minStake);
|
||||
|
||||
return [
|
||||
new TransactionObject(
|
||||
const txn = new TransactionObject(
|
||||
payer,
|
||||
[
|
||||
SystemProgram.createAccount({
|
||||
fromPubkey: program.wallet.publicKey,
|
||||
newAccountPubkey: dataBuffer.publicKey,
|
||||
space: queueDataSize,
|
||||
lamports:
|
||||
await program.connection.getMinimumBalanceForRentExemption(
|
||||
lamports: await program.connection.getMinimumBalanceForRentExemption(
|
||||
queueDataSize
|
||||
),
|
||||
programId: program.programId,
|
||||
|
@ -205,9 +203,9 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
),
|
||||
],
|
||||
[dataBuffer, queueKeypair]
|
||||
),
|
||||
account,
|
||||
];
|
||||
);
|
||||
|
||||
return [account, txn];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -222,8 +220,8 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
* Basic usage example:
|
||||
*
|
||||
* ```ts
|
||||
* import {QueueAccount} from '@switchboard-xyz/solana.js';
|
||||
* const [txnSignature, queueAccount] = await QueueAccount.create(program, {
|
||||
* import { QueueAccount } from '@switchboard-xyz/solana.js';
|
||||
* const [queueAccount, txnSignature] = await QueueAccount.create(program, {
|
||||
name: 'My Queue',
|
||||
metadata: 'Top Secret',
|
||||
queueSize: 100,
|
||||
|
@ -241,14 +239,14 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
public static async create(
|
||||
program: SwitchboardProgram,
|
||||
params: QueueInitParams
|
||||
): Promise<[string, QueueAccount]> {
|
||||
const [txnObject, account] = await this.createInstructions(
|
||||
): Promise<[QueueAccount, string]> {
|
||||
const [account, txnObject] = await this.createInstructions(
|
||||
program,
|
||||
program.walletPubkey,
|
||||
params
|
||||
);
|
||||
const txnSignature = await program.signAndSend(txnObject);
|
||||
return [txnSignature, account];
|
||||
return [account, txnSignature];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -263,9 +261,9 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
* Basic usage example:
|
||||
*
|
||||
* ```ts
|
||||
* import {QueueAccount} from '@switchboard-xyz/solana.js';
|
||||
* import { QueueAccount } from '@switchboard-xyz/solana.js';
|
||||
* const queueAccount = new QueueAccount(program, queuePubkey);
|
||||
* const [oracleInitTxn, oracleAccount] = await queueAccount.createOracleInstructions(payer, {
|
||||
* const [oracleAccount, oracleInitTxn] = await queueAccount.createOracleInstructions(payer, {
|
||||
* name: "My Oracle",
|
||||
* metadata: "Oracle #1"
|
||||
* });
|
||||
|
@ -277,16 +275,16 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
/** The publicKey of the account that will pay for the new accounts. Will also be used as the account authority if no other authority is provided. */
|
||||
payer: PublicKey,
|
||||
params: OracleInitParams & Partial<Omit<PermissionSetParams, 'permission'>>
|
||||
): Promise<[TransactionObject, OracleAccount]> {
|
||||
): Promise<[OracleAccount, TransactionObject]> {
|
||||
const queue = await this.loadData();
|
||||
|
||||
const [createOracleTxnObject, oracleAccount] =
|
||||
const [oracleAccount, createOracleTxnObject] =
|
||||
await OracleAccount.createInstructions(this.program, payer, {
|
||||
...params,
|
||||
queueAccount: this,
|
||||
});
|
||||
|
||||
const [createPermissionTxnObject, permissionAccount] =
|
||||
const [permissionAccount, createPermissionTxnObject] =
|
||||
PermissionAccount.createInstruction(this.program, payer, {
|
||||
granter: this.publicKey,
|
||||
grantee: oracleAccount.publicKey,
|
||||
|
@ -303,8 +301,8 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
}
|
||||
|
||||
return [
|
||||
createOracleTxnObject.combine(createPermissionTxnObject),
|
||||
oracleAccount,
|
||||
createOracleTxnObject.combine(createPermissionTxnObject),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -318,9 +316,9 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
* Basic usage example:
|
||||
*
|
||||
* ```ts
|
||||
* import {QueueAccount} from '@switchboard-xyz/solana.js';
|
||||
* import { QueueAccount } from '@switchboard-xyz/solana.js';
|
||||
* const queueAccount = new QueueAccount(program, queuePubkey);
|
||||
* const [oracleInitSignature, oracleAccount] = await queueAccount.createOracle({
|
||||
* const [oracleAccount, oracleInitSignature] = await queueAccount.createOracle({
|
||||
* name: "My Oracle",
|
||||
* metadata: "Oracle #1"
|
||||
* });
|
||||
|
@ -329,7 +327,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
*/
|
||||
public async createOracle(
|
||||
params: OracleInitParams & Partial<Omit<PermissionSetParams, 'permission'>>
|
||||
): Promise<[TransactionSignature, OracleAccount]> {
|
||||
): Promise<[OracleAccount, TransactionSignature]> {
|
||||
const signers: Keypair[] = [];
|
||||
|
||||
const queue = await this.loadData();
|
||||
|
@ -341,14 +339,14 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
signers.push(params.queueAuthority);
|
||||
}
|
||||
|
||||
const [txn, oracleAccount] = await this.createOracleInstructions(
|
||||
const [oracleAccount, txn] = await this.createOracleInstructions(
|
||||
this.program.walletPubkey,
|
||||
params
|
||||
);
|
||||
|
||||
const signature = await this.program.signAndSend(txn);
|
||||
|
||||
return [signature, oracleAccount];
|
||||
return [oracleAccount, signature];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -363,9 +361,9 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
* Optionally, enable the permissions by setting a queueAuthority keypair along with the enable boolean set to true.
|
||||
*
|
||||
* ```ts
|
||||
* import {QueueAccount} from '@switchboard-xyz/solana.js';
|
||||
* import { QueueAccount } from '@switchboard-xyz/solana.js';
|
||||
* const queueAccount = new QueueAccount(program, queuePubkey);
|
||||
* const [aggregatorInitTxnObject, aggregatorAccount] =
|
||||
* const [aggregatorAccount, aggregatorInitTxnObject] =
|
||||
await queueAccount.createFeedInstructions({
|
||||
enable: true, // not needed if queue has unpermissionedFeedsEnabled
|
||||
queueAuthority: queueAuthority, // not needed if queue has unpermissionedFeedsEnabled
|
||||
|
@ -413,7 +411,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
// job params
|
||||
jobs?: Array<{ pubkey: PublicKey; weight?: number } | JobInitParams>;
|
||||
}
|
||||
): Promise<[TransactionObject[], AggregatorAccount]> {
|
||||
): Promise<[AggregatorAccount, TransactionObject[]]> {
|
||||
const queue = await this.loadData();
|
||||
|
||||
const pre: TransactionObject[] = [];
|
||||
|
@ -437,7 +435,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
if (params.jobs && Array.isArray(params.jobs)) {
|
||||
for await (const job of params.jobs) {
|
||||
if ('data' in job) {
|
||||
const [jobInit, jobAccount] = JobAccount.createInstructions(
|
||||
const [jobAccount, jobInit] = JobAccount.createInstructions(
|
||||
this.program,
|
||||
payer,
|
||||
{
|
||||
|
@ -461,7 +459,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
}
|
||||
}
|
||||
|
||||
const [aggregatorInit, aggregatorAccount] =
|
||||
const [aggregatorAccount, aggregatorInit] =
|
||||
await AggregatorAccount.createInstruction(this.program, payer, {
|
||||
...params,
|
||||
queueAccount: this,
|
||||
|
@ -472,7 +470,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
|
||||
txns.push(aggregatorInit);
|
||||
|
||||
const [leaseInit] = await LeaseAccount.createInstructions(
|
||||
const [leaseAccount, leaseInit] = await LeaseAccount.createInstructions(
|
||||
this.program,
|
||||
payer,
|
||||
{
|
||||
|
@ -487,7 +485,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
txns.push(leaseInit);
|
||||
|
||||
// create permission account
|
||||
const [permissionInit, permissionAccount] =
|
||||
const [permissionAccount, permissionInit] =
|
||||
PermissionAccount.createInstruction(this.program, payer, {
|
||||
granter: this.publicKey,
|
||||
authority: queue.authority,
|
||||
|
@ -525,7 +523,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
}
|
||||
|
||||
if (params.historyLimit && params.historyLimit > 0) {
|
||||
const [historyBufferInit] =
|
||||
const [historyBuffer, historyBufferInit] =
|
||||
await AggregatorHistoryBuffer.createInstructions(this.program, payer, {
|
||||
aggregatorAccount,
|
||||
maxSamples: params.historyLimit,
|
||||
|
@ -539,7 +537,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
...TransactionObject.pack(post),
|
||||
]);
|
||||
|
||||
return [packed, aggregatorAccount];
|
||||
return [aggregatorAccount, packed];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -550,9 +548,9 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
* Optionally, enable the permissions by setting a queueAuthority keypair along with the enable boolean set to true.
|
||||
*
|
||||
* ```ts
|
||||
* import {QueueAccount} from '@switchboard-xyz/solana.js';
|
||||
* import { QueueAccount } from '@switchboard-xyz/solana.js';
|
||||
* const queueAccount = new QueueAccount(program, queuePubkey);
|
||||
* const [aggregatorInitSignatures, aggregatorAccount] =
|
||||
* const [aggregatorAccount, aggregatorInitSignatures] =
|
||||
await queueAccount.createFeed({
|
||||
enable: true, // not needed if queue has unpermissionedFeedsEnabled
|
||||
queueAuthority: queueAuthority, // not needed if queue has unpermissionedFeedsEnabled
|
||||
|
@ -598,7 +596,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
// job params
|
||||
jobs?: Array<{ pubkey: PublicKey; weight?: number } | JobInitParams>;
|
||||
}
|
||||
): Promise<[Array<TransactionSignature>, AggregatorAccount]> {
|
||||
): Promise<[AggregatorAccount, Array<TransactionSignature>]> {
|
||||
const signers: Keypair[] = [];
|
||||
|
||||
const queue = await this.loadData();
|
||||
|
@ -610,14 +608,14 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
signers.push(params.queueAuthority);
|
||||
}
|
||||
|
||||
const [txns, aggregatorAccount] = await this.createFeedInstructions(
|
||||
const [aggregatorAccount, txns] = await this.createFeedInstructions(
|
||||
this.program.walletPubkey,
|
||||
params
|
||||
);
|
||||
|
||||
const signatures = await this.program.signAndSendAll(txns);
|
||||
|
||||
return [signatures, aggregatorAccount];
|
||||
return [aggregatorAccount, signatures];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -632,9 +630,9 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
* Basic usage example:
|
||||
*
|
||||
* ```ts
|
||||
* import {QueueAccount} from '@switchboard-xyz/solana.js';
|
||||
* import { QueueAccount } from '@switchboard-xyz/solana.js';
|
||||
* const queueAccount = new QueueAccount(program, queuePubkey);
|
||||
* const [crankInitTxn, crankAccount] = await queueAccount.createCrankInstructions(payer, {
|
||||
* const [crankAccount, crankInitTxn] = await queueAccount.createCrankInstructions(payer, {
|
||||
* name: "My Crank",
|
||||
* metadata: "Crank #1",
|
||||
* maxRows: 1000,
|
||||
|
@ -646,7 +644,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
public async createCrankInstructions(
|
||||
payer: PublicKey,
|
||||
params: Omit<CrankInitParams, 'queueAccount'>
|
||||
): Promise<[TransactionObject, CrankAccount]> {
|
||||
): Promise<[CrankAccount, TransactionObject]> {
|
||||
return await CrankAccount.createInstructions(this.program, payer, {
|
||||
...params,
|
||||
queueAccount: this,
|
||||
|
@ -663,9 +661,9 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
* Basic usage example:
|
||||
*
|
||||
* ```ts
|
||||
* import {QueueAccount} from '@switchboard-xyz/solana.js';
|
||||
* import { QueueAccount } from '@switchboard-xyz/solana.js';
|
||||
* const queueAccount = new QueueAccount(program, queuePubkey);
|
||||
* const [crankInitSignature, crankAccount] = await queueAccount.createCrank({
|
||||
* const [crankAccount, crankInitSignature] = await queueAccount.createCrank({
|
||||
* name: "My Crank",
|
||||
* metadata: "Crank #1",
|
||||
* maxRows: 1000,
|
||||
|
@ -675,13 +673,13 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
*/
|
||||
public async createCrank(
|
||||
params: Omit<CrankInitParams, 'queueAccount'>
|
||||
): Promise<[TransactionSignature, CrankAccount]> {
|
||||
const [txn, crankAccount] = await this.createCrankInstructions(
|
||||
): Promise<[CrankAccount, TransactionSignature]> {
|
||||
const [crankAccount, txn] = await this.createCrankInstructions(
|
||||
this.program.walletPubkey,
|
||||
params
|
||||
);
|
||||
const txnSignature = await this.program.signAndSend(txn);
|
||||
return [txnSignature, crankAccount];
|
||||
return [crankAccount, txnSignature];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -696,10 +694,10 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
* Basic usage example:
|
||||
*
|
||||
* ```ts
|
||||
* import {QueueAccount} from '@switchboard-xyz/solana.js';
|
||||
* import { QueueAccount } from '@switchboard-xyz/solana.js';
|
||||
* const queueAccount = new QueueAccount(program, queuePubkey);
|
||||
* const vrfKeypair = Keypair.generate();
|
||||
* const [vrfInitTxn, vrfAccount] = await queueAccount.createVrfInstructions(payer, {
|
||||
* const [vrfAccount, vrfInitTxn] = await queueAccount.createVrfInstructions(payer, {
|
||||
* vrfKeypair: vrfKeypair,
|
||||
* callback: {
|
||||
* programId: "",
|
||||
|
@ -715,10 +713,10 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
payer: PublicKey,
|
||||
params: Omit<VrfInitParams, 'queueAccount'> &
|
||||
Partial<Omit<PermissionSetParams, 'permission'>>
|
||||
): Promise<[TransactionObject, VrfAccount]> {
|
||||
): Promise<[VrfAccount, TransactionObject]> {
|
||||
const queue = await this.loadData();
|
||||
|
||||
const [vrfInit, vrfAccount] = await VrfAccount.createInstructions(
|
||||
const [vrfAccount, vrfInit] = await VrfAccount.createInstructions(
|
||||
this.program,
|
||||
payer,
|
||||
{
|
||||
|
@ -730,7 +728,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
);
|
||||
|
||||
// eslint-disable-next-line prefer-const
|
||||
let [permissionInit, permissionAccount] =
|
||||
let [permissionAccount, permissionInit] =
|
||||
PermissionAccount.createInstruction(this.program, payer, {
|
||||
granter: this.publicKey,
|
||||
grantee: vrfAccount.publicKey,
|
||||
|
@ -748,7 +746,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
}
|
||||
}
|
||||
|
||||
return [vrfInit.combine(permissionInit), vrfAccount];
|
||||
return [vrfAccount, vrfInit.combine(permissionInit)];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -761,10 +759,10 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
* Basic usage example:
|
||||
*
|
||||
* ```ts
|
||||
* import {QueueAccount} from '@switchboard-xyz/solana.js';
|
||||
* import { QueueAccount } from '@switchboard-xyz/solana.js';
|
||||
* const queueAccount = new QueueAccount(program, queuePubkey);
|
||||
* const vrfKeypair = Keypair.generate();
|
||||
* const [vrfInitSignature, vrfAccount] = await queueAccount.createVrf({
|
||||
* const [vrfAccount, vrfInitSignature] = await queueAccount.createVrf({
|
||||
* vrfKeypair: vrfKeypair,
|
||||
* callback: {
|
||||
* programId: "",
|
||||
|
@ -778,13 +776,13 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
public async createVrf(
|
||||
params: Omit<VrfInitParams, 'queueAccount'> &
|
||||
Partial<Omit<PermissionSetParams, 'permission'>>
|
||||
): Promise<[TransactionSignature, VrfAccount]> {
|
||||
const [txn, vrfAccount] = await this.createVrfInstructions(
|
||||
): Promise<[VrfAccount, TransactionSignature]> {
|
||||
const [vrfAccount, txn] = await this.createVrfInstructions(
|
||||
this.program.walletPubkey,
|
||||
params
|
||||
);
|
||||
const txnSignature = await this.program.signAndSend(txn);
|
||||
return [txnSignature, vrfAccount];
|
||||
return [vrfAccount, txnSignature];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -799,9 +797,9 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
* Basic usage example:
|
||||
*
|
||||
* ```ts
|
||||
* import {QueueAccount} from '@switchboard-xyz/solana.js';
|
||||
* import { QueueAccount } from '@switchboard-xyz/solana.js';
|
||||
* const queueAccount = new QueueAccount(program, queuePubkey);
|
||||
* const [bufferRelayerInitTxn, bufferRelayerAccount] = await queueAccount.createBufferRelayerInstructions(payer, {
|
||||
* const [bufferRelayerAccount, bufferRelayerInitTxn] = await queueAccount.createBufferRelayerInstructions(payer, {
|
||||
* name: "My Buffer",
|
||||
* minUpdateDelaySeconds: 30,
|
||||
* job: existingJobPubkey,
|
||||
|
@ -817,14 +815,14 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
// job params
|
||||
job: JobAccount | PublicKey | Omit<JobInitParams, 'weight'>;
|
||||
}
|
||||
): Promise<[TransactionObject, BufferRelayerAccount]> {
|
||||
): Promise<[BufferRelayerAccount, TransactionObject]> {
|
||||
const queue = await this.loadData();
|
||||
|
||||
const txns: TransactionObject[] = [];
|
||||
|
||||
let job: JobAccount;
|
||||
if ('data' in params.job) {
|
||||
const [jobInit, jobAccount] = JobAccount.createInstructions(
|
||||
const [jobAccount, jobInit] = JobAccount.createInstructions(
|
||||
this.program,
|
||||
payer,
|
||||
{
|
||||
|
@ -850,7 +848,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
);
|
||||
}
|
||||
|
||||
const [bufferInit, bufferAccount] =
|
||||
const [bufferAccount, bufferInit] =
|
||||
await BufferRelayerAccount.createInstructions(this.program, payer, {
|
||||
name: params.name,
|
||||
minUpdateDelaySeconds: params.minUpdateDelaySeconds,
|
||||
|
@ -863,7 +861,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
txns.push(bufferInit);
|
||||
|
||||
// eslint-disable-next-line prefer-const
|
||||
let [permissionInit, permissionAccount] =
|
||||
let [permissionAccount, permissionInit] =
|
||||
PermissionAccount.createInstruction(this.program, payer, {
|
||||
granter: this.publicKey,
|
||||
grantee: bufferAccount.publicKey,
|
||||
|
@ -890,7 +888,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
);
|
||||
}
|
||||
|
||||
return [packed[0], bufferAccount];
|
||||
return [bufferAccount, packed[0]];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -903,9 +901,9 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
* Basic usage example:
|
||||
*
|
||||
* ```ts
|
||||
* import {QueueAccount} from '@switchboard-xyz/solana.js';
|
||||
* import { QueueAccount } from '@switchboard-xyz/solana.js';
|
||||
* const queueAccount = new QueueAccount(program, queuePubkey);
|
||||
* const [bufferRelayerInitSignature, bufferRelayerAccount] = await queueAccount.createBufferRelayer({
|
||||
* const [bufferRelayerAccount, bufferRelayerInitSignature] = await queueAccount.createBufferRelayer({
|
||||
* name: "My Buffer",
|
||||
* minUpdateDelaySeconds: 30,
|
||||
* job: existingJobPubkey,
|
||||
|
@ -919,14 +917,14 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
// job params
|
||||
job: JobAccount | PublicKey | Omit<JobInitParams, 'weight'>;
|
||||
}
|
||||
): Promise<[TransactionSignature, BufferRelayerAccount]> {
|
||||
const [txn, bufferRelayerAccount] =
|
||||
): Promise<[BufferRelayerAccount, TransactionSignature]> {
|
||||
const [bufferRelayerAccount, txn] =
|
||||
await this.createBufferRelayerInstructions(
|
||||
this.program.walletPubkey,
|
||||
params
|
||||
);
|
||||
const txnSignature = await this.program.signAndSend(txn);
|
||||
return [txnSignature, bufferRelayerAccount];
|
||||
return [bufferRelayerAccount, txnSignature];
|
||||
}
|
||||
|
||||
/** Load the list of oracles that are currently stored in the buffer */
|
||||
|
|
|
@ -80,16 +80,18 @@ export class QueueDataBuffer extends Account<Array<PublicKey>> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return an aggregator's assigned history buffer or undefined if it doesn't exist.
|
||||
* Return a queues dataBuffer
|
||||
*
|
||||
* @throws {string} if dataBuffer is equal to default publicKey
|
||||
*/
|
||||
static fromCrank(
|
||||
static fromQueue(
|
||||
program: SwitchboardProgram,
|
||||
crank: types.CrankAccountData
|
||||
queue: types.OracleQueueAccountData
|
||||
): QueueDataBuffer {
|
||||
if (crank.dataBuffer.equals(PublicKey.default)) {
|
||||
throw new Error(`Failed to find crank data buffer`);
|
||||
if (queue.dataBuffer.equals(PublicKey.default)) {
|
||||
throw new Error(`Failed to find queue data buffer`);
|
||||
}
|
||||
|
||||
return new QueueDataBuffer(program, crank.dataBuffer);
|
||||
return new QueueDataBuffer(program, queue.dataBuffer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ export class VrfAccount extends Account<types.VrfAccountData> {
|
|||
program: SwitchboardProgram,
|
||||
payer: PublicKey,
|
||||
params: VrfInitParams
|
||||
): Promise<[TransactionObject, VrfAccount]> {
|
||||
): Promise<[VrfAccount, TransactionObject]> {
|
||||
program.verifyNewKeypair(params.vrfKeypair);
|
||||
const vrfAccount = new VrfAccount(program, params.vrfKeypair.publicKey);
|
||||
const size = program.account.vrfAccountData.size;
|
||||
|
@ -121,8 +121,10 @@ export class VrfAccount extends Account<types.VrfAccountData> {
|
|||
),
|
||||
];
|
||||
|
||||
const txn = new TransactionObject(payer, ixns, [params.vrfKeypair]);
|
||||
return [txn, vrfAccount];
|
||||
return [
|
||||
vrfAccount,
|
||||
new TransactionObject(payer, ixns, [params.vrfKeypair]),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,14 +135,14 @@ export class VrfAccount extends Account<types.VrfAccountData> {
|
|||
public static async create(
|
||||
program: SwitchboardProgram,
|
||||
params: VrfInitParams
|
||||
): Promise<[string, VrfAccount]> {
|
||||
const [createTxn, vrfAccount] = await VrfAccount.createInstructions(
|
||||
): Promise<[VrfAccount, string]> {
|
||||
const [vrfAccount, vrfInitTxn] = await VrfAccount.createInstructions(
|
||||
program,
|
||||
program.walletPubkey,
|
||||
params
|
||||
);
|
||||
const txnSignature = await program.signAndSend(createTxn);
|
||||
return [txnSignature, vrfAccount];
|
||||
const txnSignature = await program.signAndSend(vrfInitTxn);
|
||||
return [vrfAccount, txnSignature];
|
||||
}
|
||||
|
||||
public async requestRandomnessInstruction(
|
||||
|
|
|
@ -3,8 +3,6 @@ import 'mocha';
|
|||
import chai, { expect } from 'chai';
|
||||
import assert from 'assert';
|
||||
|
||||
import * as anchor from '@project-serum/anchor';
|
||||
import * as spl from '@solana/spl-token';
|
||||
import * as sbv2 from '../src';
|
||||
import { setupTest, TestContext } from './utilts';
|
||||
import { Keypair } from '@solana/web3.js';
|
||||
|
@ -15,7 +13,6 @@ import {
|
|||
QueueAccount,
|
||||
} from '../src';
|
||||
import { OracleJob } from '@switchboard-xyz/common';
|
||||
import { PermitOracleQueueUsage } from '../src/generated/types/SwitchboardPermission';
|
||||
|
||||
describe('Aggregator Tests', () => {
|
||||
let ctx: TestContext;
|
||||
|
@ -30,9 +27,7 @@ describe('Aggregator Tests', () => {
|
|||
before(async () => {
|
||||
ctx = await setupTest();
|
||||
|
||||
const [createQueueSignature, oracleQueue] = await sbv2.QueueAccount.create(
|
||||
ctx.program,
|
||||
{
|
||||
const [oracleQueue] = await sbv2.QueueAccount.create(ctx.program, {
|
||||
name: 'aggregator-queue',
|
||||
metadata: '',
|
||||
authority: queueAuthority.publicKey,
|
||||
|
@ -44,8 +39,7 @@ describe('Aggregator Tests', () => {
|
|||
unpermissionedFeeds: true,
|
||||
unpermissionedVrf: true,
|
||||
enableBufferRelayers: false,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
queueAccount = oracleQueue;
|
||||
|
||||
|
@ -56,7 +50,7 @@ describe('Aggregator Tests', () => {
|
|||
name: 'oracle-1',
|
||||
});
|
||||
|
||||
const [createJobSigs, jobAccount1] = await JobAccount.create(ctx.program, {
|
||||
const [jobAccount1] = await JobAccount.create(ctx.program, {
|
||||
data: OracleJob.encodeDelimited(
|
||||
OracleJob.fromObject({
|
||||
tasks: [
|
||||
|
@ -77,8 +71,7 @@ describe('Aggregator Tests', () => {
|
|||
const aggregatorKeypair = Keypair.generate();
|
||||
const aggregatorAuthority = Keypair.generate();
|
||||
|
||||
const [createAggregatorSig, aggregatorAccount] =
|
||||
await AggregatorAccount.create(ctx.program, {
|
||||
const [aggregatorAccount] = await AggregatorAccount.create(ctx.program, {
|
||||
queueAccount,
|
||||
queueAuthority: queueAuthority.publicKey,
|
||||
authority: aggregatorAuthority.publicKey,
|
||||
|
@ -88,7 +81,7 @@ describe('Aggregator Tests', () => {
|
|||
minUpdateDelaySeconds: 60,
|
||||
keypair: aggregatorKeypair,
|
||||
});
|
||||
const aggregator = await aggregatorAccount.loadData();
|
||||
await aggregatorAccount.loadData();
|
||||
|
||||
const oracleJob = OracleJob.fromObject({
|
||||
tasks: [
|
||||
|
@ -100,7 +93,7 @@ describe('Aggregator Tests', () => {
|
|||
],
|
||||
});
|
||||
|
||||
const [createJobSigs, jobAccount] = await JobAccount.create(
|
||||
const [jobAccount] = await JobAccount.create(
|
||||
ctx.program,
|
||||
|
||||
{
|
||||
|
@ -109,7 +102,7 @@ describe('Aggregator Tests', () => {
|
|||
}
|
||||
);
|
||||
|
||||
const addSig = await aggregatorAccount.addJob({
|
||||
await aggregatorAccount.addJob({
|
||||
job: jobAccount,
|
||||
weight: 1,
|
||||
authority: aggregatorAuthority,
|
||||
|
@ -123,7 +116,7 @@ describe('Aggregator Tests', () => {
|
|||
throw new Error(`Failed to add job to aggregator`);
|
||||
}
|
||||
|
||||
const removeSig = await aggregatorAccount.removeJob({
|
||||
await aggregatorAccount.removeJob({
|
||||
job: jobAccount,
|
||||
jobIdx: jobIdx,
|
||||
authority: aggregatorAuthority,
|
||||
|
@ -138,8 +131,7 @@ describe('Aggregator Tests', () => {
|
|||
});
|
||||
|
||||
it('Creates and funds aggregator', async () => {
|
||||
const [createAggregatorSig, aggregatorAccount] =
|
||||
await queueAccount.createFeed({
|
||||
const [aggregatorAccount] = await queueAccount.createFeed({
|
||||
queueAuthority: queueAuthority,
|
||||
batchSize: 1,
|
||||
minRequiredOracleResults: 1,
|
||||
|
|
|
@ -22,7 +22,7 @@ describe('Job Tests', () => {
|
|||
});
|
||||
const data = OracleJob.encodeDelimited(oracleJob).finish();
|
||||
|
||||
const [jobInit, jobAccount] = JobAccount.createInstructions(
|
||||
const [jobAccount, jobInit] = JobAccount.createInstructions(
|
||||
ctx.program,
|
||||
ctx.program.walletPubkey,
|
||||
{
|
||||
|
|
|
@ -23,8 +23,10 @@ describe('Mint Tests', () => {
|
|||
);
|
||||
await ctx.program.connection.confirmTransaction(airdropTxn);
|
||||
|
||||
const [tokenAddress, createTokenAccountSig] =
|
||||
await ctx.program.mint.createAssocatedUser(ctx.payer.publicKey, user);
|
||||
const [tokenAddress] = await ctx.program.mint.createAssocatedUser(
|
||||
ctx.payer.publicKey,
|
||||
user
|
||||
);
|
||||
userTokenAddress = tokenAddress;
|
||||
|
||||
const userTokenBalance =
|
||||
|
@ -42,11 +44,7 @@ describe('Mint Tests', () => {
|
|||
throw new Error(`User token address does not exist`);
|
||||
}
|
||||
|
||||
const wrapSignature = await ctx.program.mint.wrap(
|
||||
ctx.payer.publicKey,
|
||||
{ amount: 0.25 },
|
||||
user
|
||||
);
|
||||
await ctx.program.mint.wrap(ctx.payer.publicKey, { amount: 0.25 }, user);
|
||||
|
||||
const userTokenBalance =
|
||||
(await ctx.program.mint.getBalance(user.publicKey)) ?? 0;
|
||||
|
@ -69,11 +67,7 @@ describe('Mint Tests', () => {
|
|||
throw new Error(`Final user token address would be negative`);
|
||||
}
|
||||
|
||||
const unwrapSignature = await ctx.program.mint.unwrap(
|
||||
ctx.payer.publicKey,
|
||||
0.1,
|
||||
user
|
||||
);
|
||||
await ctx.program.mint.unwrap(ctx.payer.publicKey, 0.1, user);
|
||||
|
||||
const userTokenBalance = await ctx.program.mint.getBalance(user.publicKey);
|
||||
if (userTokenBalance !== expectedFinalBalance) {
|
||||
|
@ -88,15 +82,9 @@ describe('Mint Tests', () => {
|
|||
throw new Error(`User token address does not exist`);
|
||||
}
|
||||
|
||||
const initialUserTokenBalance = await ctx.program.mint.getBalance(
|
||||
user.publicKey
|
||||
);
|
||||
await ctx.program.mint.getBalance(user.publicKey);
|
||||
|
||||
const unwrapSignature = await ctx.program.mint.unwrap(
|
||||
ctx.payer.publicKey,
|
||||
undefined,
|
||||
user
|
||||
);
|
||||
await ctx.program.mint.unwrap(ctx.payer.publicKey, undefined, user);
|
||||
|
||||
const userTokenAccount = await ctx.program.connection.getAccountInfo(
|
||||
userTokenAddress
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
import 'mocha';
|
||||
|
||||
import * as sbv2 from '../src';
|
||||
import { setupTest, TestContext } from './utilts';
|
||||
import { Keypair } from '@solana/web3.js';
|
||||
import { AggregatorAccount, OracleAccount, QueueAccount, types } from '../src';
|
||||
import { OracleJob } from '@switchboard-xyz/common';
|
||||
|
||||
describe('Open Round Tests', () => {
|
||||
let ctx: TestContext;
|
||||
|
||||
const queueAuthority = Keypair.generate();
|
||||
|
||||
let createQueueSignature: string;
|
||||
let queueAccount: QueueAccount;
|
||||
let queue: types.OracleQueueAccountData;
|
||||
|
||||
let createOracleSignature1: string;
|
||||
let oracleAccount1: OracleAccount;
|
||||
let oracle1: types.OracleAccountData;
|
||||
|
||||
let createOracleSignature2: string;
|
||||
let oracleAccount2: OracleAccount;
|
||||
let oracle2: types.OracleAccountData;
|
||||
|
||||
let createAggregatorSignatures: string[];
|
||||
let aggregatorAccount: AggregatorAccount;
|
||||
let aggregator: types.AggregatorAccountData;
|
||||
|
||||
before(async () => {
|
||||
ctx = await setupTest();
|
||||
|
||||
[queueAccount, createQueueSignature] = await sbv2.QueueAccount.create(
|
||||
ctx.program,
|
||||
{
|
||||
name: 'q1',
|
||||
metadata: '',
|
||||
queueSize: 2,
|
||||
reward: 0.0025,
|
||||
minStake: 0,
|
||||
oracleTimeout: 60,
|
||||
slashingEnabled: false,
|
||||
unpermissionedFeeds: false,
|
||||
unpermissionedVrf: true,
|
||||
enableBufferRelayers: false,
|
||||
authority: queueAuthority.publicKey,
|
||||
}
|
||||
);
|
||||
queue = await queueAccount.loadData();
|
||||
|
||||
[oracleAccount1, createOracleSignature1] = await queueAccount.createOracle({
|
||||
name: 'oracle-1',
|
||||
metadata: 'oracle-1',
|
||||
queueAuthority,
|
||||
});
|
||||
oracle1 = await oracleAccount1.loadData();
|
||||
|
||||
[oracleAccount2, createOracleSignature2] = await queueAccount.createOracle({
|
||||
name: 'oracle-2',
|
||||
metadata: 'oracle-2',
|
||||
queueAuthority,
|
||||
});
|
||||
oracle2 = await oracleAccount2.loadData();
|
||||
|
||||
[aggregatorAccount, createAggregatorSignatures] =
|
||||
await queueAccount.createFeed({
|
||||
queueAuthority: queueAuthority,
|
||||
batchSize: 1,
|
||||
minRequiredOracleResults: 1,
|
||||
minRequiredJobResults: 1,
|
||||
minUpdateDelaySeconds: 60,
|
||||
fundAmount: 1,
|
||||
enable: true,
|
||||
jobs: [
|
||||
{
|
||||
weight: 2,
|
||||
data: OracleJob.encodeDelimited(
|
||||
OracleJob.fromObject({
|
||||
tasks: [
|
||||
{
|
||||
valueTask: {
|
||||
value: 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
).finish(),
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
|
@ -2,8 +2,6 @@ import 'mocha';
|
|||
import chai, { expect } from 'chai';
|
||||
import assert from 'assert';
|
||||
|
||||
import * as anchor from '@project-serum/anchor';
|
||||
import * as spl from '@solana/spl-token';
|
||||
import * as sbv2 from '../src';
|
||||
import { setupTest, TestContext } from './utilts';
|
||||
import { Keypair } from '@solana/web3.js';
|
||||
|
@ -16,13 +14,11 @@ describe('Queue Tests', () => {
|
|||
ctx = await setupTest();
|
||||
});
|
||||
|
||||
let queueAccount: sbv2.QueueAccount;
|
||||
const queueAuthority = Keypair.generate();
|
||||
let queueAccount: sbv2.QueueAccount;
|
||||
|
||||
it('Creates a Queue', async () => {
|
||||
const [createQueueSignature, oracleQueue] = await sbv2.QueueAccount.create(
|
||||
ctx.program,
|
||||
{
|
||||
[queueAccount] = await sbv2.QueueAccount.create(ctx.program, {
|
||||
name: 'q1',
|
||||
metadata: '',
|
||||
queueSize: 2,
|
||||
|
@ -34,10 +30,8 @@ describe('Queue Tests', () => {
|
|||
unpermissionedVrf: true,
|
||||
enableBufferRelayers: false,
|
||||
authority: queueAuthority.publicKey,
|
||||
}
|
||||
);
|
||||
queueAccount = oracleQueue;
|
||||
const queue = await queueAccount.loadData();
|
||||
});
|
||||
await queueAccount.loadData();
|
||||
});
|
||||
|
||||
it('Adds an oracle to a queue', async () => {
|
||||
|
@ -46,8 +40,7 @@ describe('Queue Tests', () => {
|
|||
}
|
||||
const oracleAuthority = Keypair.generate();
|
||||
// Create a new oracle
|
||||
const [createOracleSignatures, oracleAccount] =
|
||||
await queueAccount.createOracle({
|
||||
const [oracleAccount] = await queueAccount.createOracle({
|
||||
name: 'oracle2',
|
||||
metadata: '',
|
||||
queueAuthority,
|
||||
|
@ -56,14 +49,15 @@ describe('Queue Tests', () => {
|
|||
});
|
||||
|
||||
const oracle = await oracleAccount.loadData();
|
||||
const [permissionAccount, permissionBump] = PermissionAccount.fromSeed(
|
||||
const [permissionAccount] = PermissionAccount.fromSeed(
|
||||
ctx.program,
|
||||
queueAuthority.publicKey,
|
||||
queueAccount.publicKey,
|
||||
oracleAccount.publicKey
|
||||
);
|
||||
await permissionAccount.loadData();
|
||||
|
||||
const heartbeatSignature = await oracleAccount.heartbeat({
|
||||
await oracleAccount.heartbeat({
|
||||
queueAccount,
|
||||
tokenWallet: oracle.tokenAccount,
|
||||
authority: oracleAuthority,
|
||||
|
@ -83,8 +77,7 @@ describe('Queue Tests', () => {
|
|||
const oracleAuthority = Keypair.generate();
|
||||
|
||||
// Create a new oracle
|
||||
const [createOracleSignatures, oracleAccount] =
|
||||
await queueAccount.createOracle({
|
||||
const [oracleAccount] = await queueAccount.createOracle({
|
||||
name: 'oracle2',
|
||||
metadata: '',
|
||||
queueAuthority,
|
||||
|
@ -94,7 +87,7 @@ describe('Queue Tests', () => {
|
|||
|
||||
const oracle = await oracleAccount.loadData();
|
||||
|
||||
const heartbeatSignature = await oracleAccount.heartbeat({
|
||||
await oracleAccount.heartbeat({
|
||||
queueAccount,
|
||||
tokenWallet: oracle.tokenAccount,
|
||||
authority: oracleAuthority,
|
||||
|
@ -116,8 +109,7 @@ describe('Queue Tests', () => {
|
|||
const tokenWallet = Keypair.generate();
|
||||
|
||||
// Create a new oracle
|
||||
const [createOracleSignatures, oracleAccount] =
|
||||
await queueAccount.createOracle({
|
||||
const [oracleAccount] = await queueAccount.createOracle({
|
||||
name: 'oracle3',
|
||||
metadata: '',
|
||||
queueAuthority,
|
||||
|
@ -125,7 +117,7 @@ describe('Queue Tests', () => {
|
|||
authority: oracleAuthority,
|
||||
});
|
||||
|
||||
const oracle = await oracleAccount.loadData();
|
||||
await oracleAccount.loadData();
|
||||
|
||||
assert.rejects(
|
||||
async () => {
|
||||
|
|
Loading…
Reference in New Issue