added TransactionObjectOptions to some aggregator methods
This commit is contained in:
parent
98d85c7753
commit
5a663abbf2
|
@ -477,13 +477,11 @@ export class SwitchboardProgram {
|
||||||
if (isBrowser) throw new errors.SwitchboardProgramIsBrowserError();
|
if (isBrowser) throw new errors.SwitchboardProgramIsBrowserError();
|
||||||
if (this.isReadOnly) throw new errors.SwitchboardProgramReadOnlyError();
|
if (this.isReadOnly) throw new errors.SwitchboardProgramReadOnlyError();
|
||||||
|
|
||||||
const packed = TransactionObject.pack(txns);
|
|
||||||
|
|
||||||
const txnSignatures: Array<TransactionSignature> = [];
|
const txnSignatures: Array<TransactionSignature> = [];
|
||||||
for await (const [i, txn] of packed.entries()) {
|
for await (const [i, txn] of txns.entries()) {
|
||||||
txnSignatures.push(await this.signAndSend(txn, opts, txnOptions));
|
txnSignatures.push(await this.signAndSend(txn, opts, txnOptions));
|
||||||
if (
|
if (
|
||||||
i !== packed.length - 1 &&
|
i !== txns.length - 1 &&
|
||||||
delay &&
|
delay &&
|
||||||
typeof delay === 'number' &&
|
typeof delay === 'number' &&
|
||||||
delay > 0
|
delay > 0
|
||||||
|
|
|
@ -931,7 +931,8 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
priorityFeeBumpPeriod: number;
|
priorityFeeBumpPeriod: number;
|
||||||
maxPriorityFeeMultiplier: number;
|
maxPriorityFeeMultiplier: number;
|
||||||
force: boolean;
|
force: boolean;
|
||||||
}>
|
}>,
|
||||||
|
options?: TransactionObjectOptions
|
||||||
): Promise<TransactionObject> {
|
): Promise<TransactionObject> {
|
||||||
if (!(params.force ?? false)) {
|
if (!(params.force ?? false)) {
|
||||||
const aggregator = await this.loadData();
|
const aggregator = await this.loadData();
|
||||||
|
@ -989,7 +990,8 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
return new TransactionObject(
|
return new TransactionObject(
|
||||||
payer,
|
payer,
|
||||||
[setConfigIxn],
|
[setConfigIxn],
|
||||||
params.authority ? [params.authority] : []
|
params.authority ? [params.authority] : [],
|
||||||
|
options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1009,11 +1011,13 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
priorityFeeBumpPeriod?: number;
|
priorityFeeBumpPeriod?: number;
|
||||||
maxPriorityFeeMultiplier?: number;
|
maxPriorityFeeMultiplier?: number;
|
||||||
force: boolean;
|
force: boolean;
|
||||||
}>
|
}>,
|
||||||
|
options?: TransactionObjectOptions
|
||||||
): Promise<TransactionSignature> {
|
): Promise<TransactionSignature> {
|
||||||
const setConfigTxn = await this.setConfigInstruction(
|
const setConfigTxn = await this.setConfigInstruction(
|
||||||
this.program.walletPubkey,
|
this.program.walletPubkey,
|
||||||
params
|
params,
|
||||||
|
options
|
||||||
);
|
);
|
||||||
const txnSignature = await this.program.signAndSend(setConfigTxn);
|
const txnSignature = await this.program.signAndSend(setConfigTxn);
|
||||||
return txnSignature;
|
return txnSignature;
|
||||||
|
@ -1024,7 +1028,8 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
params: {
|
params: {
|
||||||
queueAccount: QueueAccount;
|
queueAccount: QueueAccount;
|
||||||
authority?: Keypair;
|
authority?: Keypair;
|
||||||
}
|
},
|
||||||
|
options?: TransactionObjectOptions
|
||||||
): TransactionObject {
|
): TransactionObject {
|
||||||
const setQueueIxn = types.aggregatorSetQueue(
|
const setQueueIxn = types.aggregatorSetQueue(
|
||||||
this.program,
|
this.program,
|
||||||
|
@ -1040,17 +1045,22 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
return new TransactionObject(
|
return new TransactionObject(
|
||||||
payer,
|
payer,
|
||||||
[setQueueIxn],
|
[setQueueIxn],
|
||||||
params.authority ? [params.authority] : []
|
params.authority ? [params.authority] : [],
|
||||||
|
options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async setQueue(params: {
|
public async setQueue(
|
||||||
|
params: {
|
||||||
queueAccount: QueueAccount;
|
queueAccount: QueueAccount;
|
||||||
authority?: Keypair;
|
authority?: Keypair;
|
||||||
}): Promise<TransactionSignature> {
|
},
|
||||||
|
options?: TransactionObjectOptions
|
||||||
|
): Promise<TransactionSignature> {
|
||||||
const setQueueTxn = this.setQueueInstruction(
|
const setQueueTxn = this.setQueueInstruction(
|
||||||
this.program.walletPubkey,
|
this.program.walletPubkey,
|
||||||
params
|
params,
|
||||||
|
options
|
||||||
);
|
);
|
||||||
const txnSignature = await this.program.signAndSend(setQueueTxn);
|
const txnSignature = await this.program.signAndSend(setQueueTxn);
|
||||||
return txnSignature;
|
return txnSignature;
|
||||||
|
@ -1062,7 +1072,8 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
job: JobAccount;
|
job: JobAccount;
|
||||||
weight?: number;
|
weight?: number;
|
||||||
authority?: Keypair;
|
authority?: Keypair;
|
||||||
}
|
},
|
||||||
|
options?: TransactionObjectOptions
|
||||||
): TransactionObject {
|
): TransactionObject {
|
||||||
const authority = params.authority ? params.authority.publicKey : payer;
|
const authority = params.authority ? params.authority.publicKey : payer;
|
||||||
const addJobIxn = types.aggregatorAddJob(
|
const addJobIxn = types.aggregatorAddJob(
|
||||||
|
@ -1077,16 +1088,24 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
return new TransactionObject(
|
return new TransactionObject(
|
||||||
payer,
|
payer,
|
||||||
[addJobIxn],
|
[addJobIxn],
|
||||||
params.authority ? [params.authority] : []
|
params.authority ? [params.authority] : [],
|
||||||
|
options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async addJob(params: {
|
public async addJob(
|
||||||
|
params: {
|
||||||
job: JobAccount;
|
job: JobAccount;
|
||||||
weight?: number;
|
weight?: number;
|
||||||
authority?: Keypair;
|
authority?: Keypair;
|
||||||
}): Promise<TransactionSignature> {
|
},
|
||||||
const txn = this.addJobInstruction(this.program.walletPubkey, params);
|
options?: TransactionObjectOptions
|
||||||
|
): Promise<TransactionSignature> {
|
||||||
|
const txn = this.addJobInstruction(
|
||||||
|
this.program.walletPubkey,
|
||||||
|
params,
|
||||||
|
options
|
||||||
|
);
|
||||||
const txnSignature = await this.program.signAndSend(txn);
|
const txnSignature = await this.program.signAndSend(txn);
|
||||||
return txnSignature;
|
return txnSignature;
|
||||||
}
|
}
|
||||||
|
@ -1095,7 +1114,8 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
payer: PublicKey,
|
payer: PublicKey,
|
||||||
params: {
|
params: {
|
||||||
authority?: Keypair;
|
authority?: Keypair;
|
||||||
}
|
},
|
||||||
|
options?: TransactionObjectOptions
|
||||||
): TransactionObject {
|
): TransactionObject {
|
||||||
return new TransactionObject(
|
return new TransactionObject(
|
||||||
payer,
|
payer,
|
||||||
|
@ -1109,14 +1129,22 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
params.authority ? [params.authority] : []
|
params.authority ? [params.authority] : [],
|
||||||
|
options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async lock(params: {
|
public async lock(
|
||||||
|
params: {
|
||||||
authority?: Keypair;
|
authority?: Keypair;
|
||||||
}): Promise<TransactionSignature> {
|
},
|
||||||
const lockTxn = this.lockInstruction(this.program.walletPubkey, params);
|
options?: TransactionObjectOptions
|
||||||
|
): Promise<TransactionSignature> {
|
||||||
|
const lockTxn = this.lockInstruction(
|
||||||
|
this.program.walletPubkey,
|
||||||
|
params,
|
||||||
|
options
|
||||||
|
);
|
||||||
const txnSignature = await this.program.signAndSend(lockTxn);
|
const txnSignature = await this.program.signAndSend(lockTxn);
|
||||||
return txnSignature;
|
return txnSignature;
|
||||||
}
|
}
|
||||||
|
@ -1126,7 +1154,8 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
params: {
|
params: {
|
||||||
newAuthority: PublicKey;
|
newAuthority: PublicKey;
|
||||||
authority?: Keypair;
|
authority?: Keypair;
|
||||||
}
|
},
|
||||||
|
options?: TransactionObjectOptions
|
||||||
): TransactionObject {
|
): TransactionObject {
|
||||||
return new TransactionObject(
|
return new TransactionObject(
|
||||||
payer,
|
payer,
|
||||||
|
@ -1141,17 +1170,22 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
params.authority ? [params.authority] : []
|
params.authority ? [params.authority] : [],
|
||||||
|
options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async setAuthority(params: {
|
public async setAuthority(
|
||||||
|
params: {
|
||||||
newAuthority: PublicKey;
|
newAuthority: PublicKey;
|
||||||
authority?: Keypair;
|
authority?: Keypair;
|
||||||
}): Promise<TransactionSignature> {
|
},
|
||||||
|
options?: TransactionObjectOptions
|
||||||
|
): Promise<TransactionSignature> {
|
||||||
const setAuthorityTxn = this.setAuthorityInstruction(
|
const setAuthorityTxn = this.setAuthorityInstruction(
|
||||||
this.program.walletPubkey,
|
this.program.walletPubkey,
|
||||||
params
|
params,
|
||||||
|
options
|
||||||
);
|
);
|
||||||
const txnSignature = await this.program.signAndSend(setAuthorityTxn);
|
const txnSignature = await this.program.signAndSend(setAuthorityTxn);
|
||||||
return txnSignature;
|
return txnSignature;
|
||||||
|
@ -1164,13 +1198,18 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
jobIdx: number;
|
jobIdx: number;
|
||||||
weight: number;
|
weight: number;
|
||||||
authority?: Keypair;
|
authority?: Keypair;
|
||||||
}
|
},
|
||||||
|
options?: TransactionObjectOptions
|
||||||
): TransactionObject {
|
): TransactionObject {
|
||||||
const removeJob = this.removeJobInstruction(payer, {
|
const removeJob = this.removeJobInstruction(
|
||||||
|
payer,
|
||||||
|
{
|
||||||
job: params.job,
|
job: params.job,
|
||||||
jobIdx: params.jobIdx,
|
jobIdx: params.jobIdx,
|
||||||
authority: params.authority,
|
authority: params.authority,
|
||||||
});
|
},
|
||||||
|
options
|
||||||
|
);
|
||||||
const addJob = this.addJobInstruction(payer, {
|
const addJob = this.addJobInstruction(payer, {
|
||||||
job: params.job,
|
job: params.job,
|
||||||
weight: params.weight,
|
weight: params.weight,
|
||||||
|
@ -1179,15 +1218,19 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
return removeJob.combine(addJob);
|
return removeJob.combine(addJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateJobWeight(params: {
|
public async updateJobWeight(
|
||||||
|
params: {
|
||||||
job: JobAccount;
|
job: JobAccount;
|
||||||
jobIdx: number;
|
jobIdx: number;
|
||||||
weight: number;
|
weight: number;
|
||||||
authority?: Keypair;
|
authority?: Keypair;
|
||||||
}): Promise<TransactionSignature> {
|
},
|
||||||
|
options?: TransactionObjectOptions
|
||||||
|
): Promise<TransactionSignature> {
|
||||||
const transaction = this.updateJobWeightInstruction(
|
const transaction = this.updateJobWeightInstruction(
|
||||||
this.program.walletPubkey,
|
this.program.walletPubkey,
|
||||||
params
|
params,
|
||||||
|
options
|
||||||
);
|
);
|
||||||
const signature = await this.program.signAndSend(transaction);
|
const signature = await this.program.signAndSend(transaction);
|
||||||
return signature;
|
return signature;
|
||||||
|
@ -1199,7 +1242,8 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
job: JobAccount;
|
job: JobAccount;
|
||||||
jobIdx: number;
|
jobIdx: number;
|
||||||
authority?: Keypair;
|
authority?: Keypair;
|
||||||
}
|
},
|
||||||
|
options?: TransactionObjectOptions
|
||||||
): TransactionObject {
|
): TransactionObject {
|
||||||
const authority = params.authority ? params.authority.publicKey : payer;
|
const authority = params.authority ? params.authority.publicKey : payer;
|
||||||
const removeJobIxn = types.aggregatorRemoveJob(
|
const removeJobIxn = types.aggregatorRemoveJob(
|
||||||
|
@ -1214,18 +1258,23 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
return new TransactionObject(
|
return new TransactionObject(
|
||||||
payer,
|
payer,
|
||||||
[removeJobIxn],
|
[removeJobIxn],
|
||||||
params.authority ? [params.authority] : []
|
params.authority ? [params.authority] : [],
|
||||||
|
options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async removeJob(params: {
|
public async removeJob(
|
||||||
|
params: {
|
||||||
job: JobAccount;
|
job: JobAccount;
|
||||||
jobIdx: number;
|
jobIdx: number;
|
||||||
authority?: Keypair;
|
authority?: Keypair;
|
||||||
}): Promise<TransactionSignature> {
|
},
|
||||||
|
options?: TransactionObjectOptions
|
||||||
|
): Promise<TransactionSignature> {
|
||||||
const removeJobTxn = this.removeJobInstruction(
|
const removeJobTxn = this.removeJobInstruction(
|
||||||
this.program.walletPubkey,
|
this.program.walletPubkey,
|
||||||
params
|
params,
|
||||||
|
options
|
||||||
);
|
);
|
||||||
const txnSignature = await this.program.signAndSend(removeJobTxn);
|
const txnSignature = await this.program.signAndSend(removeJobTxn);
|
||||||
return txnSignature;
|
return txnSignature;
|
||||||
|
@ -1233,7 +1282,8 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
|
|
||||||
public async openRoundInstruction(
|
public async openRoundInstruction(
|
||||||
payer: PublicKey,
|
payer: PublicKey,
|
||||||
params?: { payoutWallet?: PublicKey }
|
params?: { payoutWallet?: PublicKey },
|
||||||
|
options?: TransactionObjectOptions
|
||||||
): Promise<TransactionObject> {
|
): Promise<TransactionObject> {
|
||||||
const aggregatorData = await this.loadData();
|
const aggregatorData = await this.loadData();
|
||||||
const queueAccount = new QueueAccount(
|
const queueAccount = new QueueAccount(
|
||||||
|
@ -1289,15 +1339,19 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return new TransactionObject(payer, ixns, []);
|
return new TransactionObject(payer, ixns, [], options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async openRound(params?: {
|
public async openRound(
|
||||||
|
params?: {
|
||||||
payoutWallet?: PublicKey;
|
payoutWallet?: PublicKey;
|
||||||
}): Promise<TransactionSignature> {
|
},
|
||||||
|
options?: TransactionObjectOptions
|
||||||
|
): Promise<TransactionSignature> {
|
||||||
const openRoundTxn = await this.openRoundInstruction(
|
const openRoundTxn = await this.openRoundInstruction(
|
||||||
this.program.walletPubkey,
|
this.program.walletPubkey,
|
||||||
params
|
params,
|
||||||
|
options
|
||||||
);
|
);
|
||||||
const txnSignature = await this.program.signAndSend(openRoundTxn);
|
const txnSignature = await this.program.signAndSend(openRoundTxn);
|
||||||
return txnSignature;
|
return txnSignature;
|
||||||
|
@ -1604,7 +1658,8 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
params: {
|
params: {
|
||||||
authority?: Keypair;
|
authority?: Keypair;
|
||||||
mode: types.AggregatorResolutionModeKind;
|
mode: types.AggregatorResolutionModeKind;
|
||||||
}
|
},
|
||||||
|
options?: TransactionObjectOptions
|
||||||
): TransactionObject {
|
): TransactionObject {
|
||||||
return new TransactionObject(
|
return new TransactionObject(
|
||||||
payer,
|
payer,
|
||||||
|
@ -1623,17 +1678,22 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
params.authority ? [params.authority] : []
|
params.authority ? [params.authority] : [],
|
||||||
|
options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setSlidingWindow(params: {
|
async setSlidingWindow(
|
||||||
|
params: {
|
||||||
authority?: Keypair;
|
authority?: Keypair;
|
||||||
mode: types.AggregatorResolutionModeKind;
|
mode: types.AggregatorResolutionModeKind;
|
||||||
}): Promise<TransactionSignature> {
|
},
|
||||||
|
options?: TransactionObjectOptions
|
||||||
|
): Promise<TransactionSignature> {
|
||||||
const setSlidingWindowTxn = this.setSlidingWindowInstruction(
|
const setSlidingWindowTxn = this.setSlidingWindowInstruction(
|
||||||
this.program.walletPubkey,
|
this.program.walletPubkey,
|
||||||
params
|
params,
|
||||||
|
options
|
||||||
);
|
);
|
||||||
const txnSignature = await this.program.signAndSend(setSlidingWindowTxn);
|
const txnSignature = await this.program.signAndSend(setSlidingWindowTxn);
|
||||||
return txnSignature;
|
return txnSignature;
|
||||||
|
@ -1643,7 +1703,8 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
params?: { payoutWallet?: PublicKey } & {
|
params?: { payoutWallet?: PublicKey } & {
|
||||||
aggregator?: types.AggregatorAccountData;
|
aggregator?: types.AggregatorAccountData;
|
||||||
},
|
},
|
||||||
timeout = 30000
|
timeout = 30000,
|
||||||
|
options?: TransactionObjectOptions
|
||||||
): Promise<[types.AggregatorAccountData, TransactionSignature | undefined]> {
|
): Promise<[types.AggregatorAccountData, TransactionSignature | undefined]> {
|
||||||
const aggregator = params?.aggregator ?? (await this.loadData());
|
const aggregator = params?.aggregator ?? (await this.loadData());
|
||||||
const currentRoundOpenSlot = aggregator.latestConfirmedRound.roundOpenSlot;
|
const currentRoundOpenSlot = aggregator.latestConfirmedRound.roundOpenSlot;
|
||||||
|
@ -1683,7 +1744,7 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
|
||||||
await closeWebsocket();
|
await closeWebsocket();
|
||||||
});
|
});
|
||||||
|
|
||||||
const openRoundSignature = await this.openRound(params).catch(
|
const openRoundSignature = await this.openRound(params, options).catch(
|
||||||
async error => {
|
async error => {
|
||||||
await closeWebsocket();
|
await closeWebsocket();
|
||||||
throw new Error(`Failed to call openRound, ${error}`);
|
throw new Error(`Failed to call openRound, ${error}`);
|
||||||
|
|
|
@ -13,7 +13,10 @@ import * as errors from '../errors';
|
||||||
import * as types from '../generated';
|
import * as types from '../generated';
|
||||||
import { SwitchboardProgram } from '../SwitchboardProgram';
|
import { SwitchboardProgram } from '../SwitchboardProgram';
|
||||||
import { Account } from './account';
|
import { Account } from './account';
|
||||||
import { TransactionObject } from '../TransactionObject';
|
import {
|
||||||
|
TransactionObject,
|
||||||
|
TransactionObjectOptions,
|
||||||
|
} from '../TransactionObject';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Account type storing a list of SwitchboardTasks {@linkcode OracleJob.Task} dictating how to source data off-chain.
|
* Account type storing a list of SwitchboardTasks {@linkcode OracleJob.Task} dictating how to source data off-chain.
|
||||||
|
@ -129,7 +132,8 @@ export class JobAccount extends Account<types.JobAccountData> {
|
||||||
public static createInstructions(
|
public static createInstructions(
|
||||||
program: SwitchboardProgram,
|
program: SwitchboardProgram,
|
||||||
payer: PublicKey,
|
payer: PublicKey,
|
||||||
params: JobInitParams
|
params: JobInitParams,
|
||||||
|
options?: TransactionObjectOptions
|
||||||
): [JobAccount, Array<TransactionObject>] {
|
): [JobAccount, Array<TransactionObject>] {
|
||||||
if (params.data.byteLength > 6400) {
|
if (params.data.byteLength > 6400) {
|
||||||
throw new Error('Switchboard jobs need to be less than 6400 bytes');
|
throw new Error('Switchboard jobs need to be less than 6400 bytes');
|
||||||
|
@ -168,7 +172,8 @@ export class JobAccount extends Account<types.JobAccountData> {
|
||||||
new TransactionObject(
|
new TransactionObject(
|
||||||
payer,
|
payer,
|
||||||
[jobInitIxn],
|
[jobInitIxn],
|
||||||
params.authority ? [jobKeypair, params.authority] : [jobKeypair]
|
params.authority ? [jobKeypair, params.authority] : [jobKeypair],
|
||||||
|
options
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -207,7 +212,8 @@ export class JobAccount extends Account<types.JobAccountData> {
|
||||||
new TransactionObject(
|
new TransactionObject(
|
||||||
payer,
|
payer,
|
||||||
[jobInitIxn],
|
[jobInitIxn],
|
||||||
params.authority ? [jobKeypair, params.authority] : [jobKeypair]
|
params.authority ? [jobKeypair, params.authority] : [jobKeypair],
|
||||||
|
options
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -229,7 +235,8 @@ export class JobAccount extends Account<types.JobAccountData> {
|
||||||
new TransactionObject(
|
new TransactionObject(
|
||||||
payer,
|
payer,
|
||||||
[jobSetDataIxn],
|
[jobSetDataIxn],
|
||||||
params.authority ? [params.authority] : []
|
params.authority ? [params.authority] : [],
|
||||||
|
options
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -240,12 +247,14 @@ export class JobAccount extends Account<types.JobAccountData> {
|
||||||
|
|
||||||
public static async create(
|
public static async create(
|
||||||
program: SwitchboardProgram,
|
program: SwitchboardProgram,
|
||||||
params: JobInitParams
|
params: JobInitParams,
|
||||||
|
options?: TransactionObjectOptions
|
||||||
): Promise<[JobAccount, Array<TransactionSignature>]> {
|
): Promise<[JobAccount, Array<TransactionSignature>]> {
|
||||||
const [account, transactions] = JobAccount.createInstructions(
|
const [account, transactions] = JobAccount.createInstructions(
|
||||||
program,
|
program,
|
||||||
program.walletPubkey,
|
program.walletPubkey,
|
||||||
params
|
params,
|
||||||
|
options
|
||||||
);
|
);
|
||||||
const txSignature = await program.signAndSendAll(transactions);
|
const txSignature = await program.signAndSendAll(transactions);
|
||||||
return [account, txSignature];
|
return [account, txSignature];
|
||||||
|
|
|
@ -16,7 +16,10 @@ import { promiseWithTimeout } from '@switchboard-xyz/common';
|
||||||
import * as errors from '../errors';
|
import * as errors from '../errors';
|
||||||
import * as types from '../generated';
|
import * as types from '../generated';
|
||||||
import { SwitchboardProgram } from '../SwitchboardProgram';
|
import { SwitchboardProgram } from '../SwitchboardProgram';
|
||||||
import { TransactionObject } from '../TransactionObject';
|
import {
|
||||||
|
TransactionObject,
|
||||||
|
TransactionObjectOptions,
|
||||||
|
} from '../TransactionObject';
|
||||||
import { Account, OnAccountChangeCallback } from './account';
|
import { Account, OnAccountChangeCallback } from './account';
|
||||||
import { OracleAccount } from './oracleAccount';
|
import { OracleAccount } from './oracleAccount';
|
||||||
import { PermissionAccount } from './permissionAccount';
|
import { PermissionAccount } from './permissionAccount';
|
||||||
|
@ -229,51 +232,23 @@ export class VrfAccount extends Account<types.VrfAccountData> {
|
||||||
|
|
||||||
public proveAndVerifyInstructions(
|
public proveAndVerifyInstructions(
|
||||||
params: VrfProveAndVerifyParams,
|
params: VrfProveAndVerifyParams,
|
||||||
tryCount = 278
|
options?: TransactionObjectOptions,
|
||||||
): TransactionInstruction[] {
|
numTxns = 40
|
||||||
const ixns: TransactionInstruction[] = [];
|
): Array<TransactionObject> {
|
||||||
|
const idx = params.vrf.builders.findIndex(builder =>
|
||||||
const vrf = params.vrf;
|
|
||||||
|
|
||||||
const idx = vrf.builders.findIndex(builder =>
|
|
||||||
params.oraclePubkey.equals(builder.producer)
|
params.oraclePubkey.equals(builder.producer)
|
||||||
);
|
);
|
||||||
if (idx === -1) {
|
if (idx === -1) {
|
||||||
throw new Error('OracleNotFoundError');
|
throw new Error('OracleNotFoundError');
|
||||||
}
|
}
|
||||||
|
|
||||||
// only add proof in first ixn to optimally pack
|
const remainingAccounts = params.vrf.callback.accounts.slice(
|
||||||
ixns.push(
|
0,
|
||||||
types.vrfProveAndVerify(
|
params.vrf.callback.accountsLen
|
||||||
this.program,
|
|
||||||
{
|
|
||||||
params: {
|
|
||||||
nonce: 1,
|
|
||||||
stateBump: this.program.programState.bump,
|
|
||||||
idx: idx,
|
|
||||||
proof: new Uint8Array(),
|
|
||||||
proofEncoded: params.proof,
|
|
||||||
counter: vrf.counter,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
vrf: this.publicKey,
|
|
||||||
callbackPid: vrf.callback.programId,
|
|
||||||
tokenProgram: TOKEN_PROGRAM_ID,
|
|
||||||
escrow: vrf.escrow,
|
|
||||||
programState: this.program.programState.publicKey,
|
|
||||||
oracle: params.oraclePubkey,
|
|
||||||
oracleAuthority: params.oracleAuthority,
|
|
||||||
oracleWallet: params.oracleTokenWallet,
|
|
||||||
instructionsSysvar: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// add verify ixns
|
const txns = Array.from(Array(numTxns).keys()).map(i => {
|
||||||
for (let i = 0; i < tryCount; ++i) {
|
const proveIxn = types.vrfProveAndVerify(
|
||||||
ixns.push(
|
|
||||||
types.vrfProveAndVerify(
|
|
||||||
this.program,
|
this.program,
|
||||||
{
|
{
|
||||||
params: {
|
params: {
|
||||||
|
@ -281,36 +256,45 @@ export class VrfAccount extends Account<types.VrfAccountData> {
|
||||||
stateBump: this.program.programState.bump,
|
stateBump: this.program.programState.bump,
|
||||||
idx: idx,
|
idx: idx,
|
||||||
proof: new Uint8Array(),
|
proof: new Uint8Array(),
|
||||||
proofEncoded: '',
|
proofEncoded: params.proof,
|
||||||
counter: vrf.counter,
|
counter: params.vrf.counter,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
vrf: this.publicKey,
|
vrf: this.publicKey,
|
||||||
callbackPid: vrf.callback.programId,
|
callbackPid: params.vrf.callback.programId,
|
||||||
tokenProgram: TOKEN_PROGRAM_ID,
|
tokenProgram: TOKEN_PROGRAM_ID,
|
||||||
escrow: vrf.escrow,
|
escrow: params.vrf.escrow,
|
||||||
programState: this.program.programState.publicKey,
|
programState: this.program.programState.publicKey,
|
||||||
oracle: params.oraclePubkey,
|
oracle: params.oraclePubkey,
|
||||||
oracleAuthority: params.oracleAuthority,
|
oracleAuthority: params.oracleAuthority,
|
||||||
oracleWallet: params.oracleTokenWallet,
|
oracleWallet: params.oracleTokenWallet,
|
||||||
instructionsSysvar: SYSVAR_INSTRUCTIONS_PUBKEY,
|
instructionsSysvar: SYSVAR_INSTRUCTIONS_PUBKEY,
|
||||||
}
|
}
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
proveIxn.keys = proveIxn.keys.concat(remainingAccounts);
|
||||||
|
|
||||||
|
return new TransactionObject(this.program.walletPubkey, [proveIxn], [], {
|
||||||
|
computeUnitLimit: 1_400_000, // allow user to override
|
||||||
|
...options,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return txns;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ixns;
|
public async proveAndVerify(
|
||||||
}
|
params: {
|
||||||
|
|
||||||
public async proveAndVerify(params: {
|
|
||||||
vrf?: types.VrfAccountData;
|
vrf?: types.VrfAccountData;
|
||||||
proof?: string;
|
proof?: string;
|
||||||
oraclePubkey?: PublicKey;
|
oraclePubkey?: PublicKey;
|
||||||
oracleTokenWallet?: PublicKey;
|
oracleTokenWallet?: PublicKey;
|
||||||
oracleAuthority?: PublicKey;
|
oracleAuthority?: PublicKey;
|
||||||
skipPreflight?: boolean;
|
skipPreflight?: boolean;
|
||||||
}): Promise<Array<TransactionSignature>> {
|
},
|
||||||
|
options?: TransactionObjectOptions,
|
||||||
|
numTxns = 40
|
||||||
|
): Promise<Array<TransactionSignature>> {
|
||||||
const vrf = params.vrf ?? (await this.loadData());
|
const vrf = params.vrf ?? (await this.loadData());
|
||||||
const oraclePubkey = params.oraclePubkey ?? vrf.builders[0].producer;
|
const oraclePubkey = params.oraclePubkey ?? vrf.builders[0].producer;
|
||||||
|
|
||||||
|
@ -323,15 +307,18 @@ export class VrfAccount extends Account<types.VrfAccountData> {
|
||||||
oracleAuthority = oracle.oracleAuthority;
|
oracleAuthority = oracle.oracleAuthority;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ixns = this.proveAndVerifyInstructions({
|
const txns = this.proveAndVerifyInstructions(
|
||||||
|
{
|
||||||
vrf,
|
vrf,
|
||||||
proof: params.proof ?? '',
|
proof: params.proof ?? '',
|
||||||
oraclePubkey,
|
oraclePubkey,
|
||||||
oracleTokenWallet,
|
oracleTokenWallet,
|
||||||
oracleAuthority,
|
oracleAuthority,
|
||||||
});
|
},
|
||||||
|
options,
|
||||||
|
numTxns
|
||||||
|
);
|
||||||
|
|
||||||
const txns = TransactionObject.packIxns(this.program.walletPubkey, ixns);
|
|
||||||
const txnSignatures = await this.program.signAndSendAll(txns, {
|
const txnSignatures = await this.program.signAndSendAll(txns, {
|
||||||
skipPreflight: params.skipPreflight ?? true,
|
skipPreflight: params.skipPreflight ?? true,
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,7 +15,7 @@ anchor_vrf_parser = "4wTeTACfwiXqqvy44bNBB3V2rFjmSTXVoEr4ZAYamJEN"
|
||||||
url = "https://anchor.projectserum.com"
|
url = "https://anchor.projectserum.com"
|
||||||
|
|
||||||
[scripts]
|
[scripts]
|
||||||
test = "yarn run ts-mocha -p ./tsconfig.json -t 30000 ./tests/*.test.ts"
|
test = "yarn run ts-mocha -p ./tsconfig.json -t 60000 ./tests/*.test.ts"
|
||||||
|
|
||||||
[test.validator]
|
[test.validator]
|
||||||
url="https://api.devnet.solana.com"
|
url="https://api.devnet.solana.com"
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
"@solana/spl-token": "^0.3.6",
|
"@solana/spl-token": "^0.3.6",
|
||||||
"@solana/web3.js": "^1.67.0",
|
"@solana/web3.js": "^1.67.0",
|
||||||
"@switchboard-xyz/common": "^2.1.8",
|
"@switchboard-xyz/common": "^2.1.8",
|
||||||
"@switchboard-xyz/solana.js": "^2.0.52",
|
"@switchboard-xyz/solana.js": "^2.0.79",
|
||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
"dotenv": "^16.0.1",
|
"dotenv": "^16.0.1",
|
||||||
"yargs": "^17.5.1"
|
"yargs": "^17.5.1"
|
||||||
|
@ -275,6 +275,36 @@
|
||||||
"node": ">= 8"
|
"node": ">= 8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@project-serum/anchor": {
|
||||||
|
"version": "0.26.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@project-serum/anchor/-/anchor-0.26.0.tgz",
|
||||||
|
"integrity": "sha512-Nq+COIjE1135T7qfnOHEn7E0q39bQTgXLFk837/rgFe6Hkew9WML7eHsS+lSYD2p3OJaTiUOHTAq1lHy36oIqQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"@coral-xyz/borsh": "^0.26.0",
|
||||||
|
"@solana/web3.js": "^1.68.0",
|
||||||
|
"base64-js": "^1.5.1",
|
||||||
|
"bn.js": "^5.1.2",
|
||||||
|
"bs58": "^4.0.1",
|
||||||
|
"buffer-layout": "^1.2.2",
|
||||||
|
"camelcase": "^6.3.0",
|
||||||
|
"cross-fetch": "^3.1.5",
|
||||||
|
"crypto-hash": "^1.3.0",
|
||||||
|
"eventemitter3": "^4.0.7",
|
||||||
|
"js-sha256": "^0.9.0",
|
||||||
|
"pako": "^2.0.3",
|
||||||
|
"snake-case": "^3.0.4",
|
||||||
|
"superstruct": "^0.15.4",
|
||||||
|
"toml": "^3.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=11"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@project-serum/anchor/node_modules/superstruct": {
|
||||||
|
"version": "0.15.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/superstruct/-/superstruct-0.15.5.tgz",
|
||||||
|
"integrity": "sha512-4AOeU+P5UuE/4nOUkmcQdW5y7i9ndt1cQd/3iUe+LTz3RxESf/W/5lg4B74HbDMMv8PHnPnGCQFH45kBcrQYoQ=="
|
||||||
|
},
|
||||||
"node_modules/@project-serum/borsh": {
|
"node_modules/@project-serum/borsh": {
|
||||||
"version": "0.2.5",
|
"version": "0.2.5",
|
||||||
"resolved": "https://registry.npmjs.org/@project-serum/borsh/-/borsh-0.2.5.tgz",
|
"resolved": "https://registry.npmjs.org/@project-serum/borsh/-/borsh-0.2.5.tgz",
|
||||||
|
@ -386,15 +416,16 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@solana/web3.js": {
|
"node_modules/@solana/web3.js": {
|
||||||
"version": "1.70.1",
|
"version": "1.73.0",
|
||||||
"resolved": "https://registry.npmjs.org/@solana/web3.js/-/web3.js-1.70.1.tgz",
|
"resolved": "https://registry.npmjs.org/@solana/web3.js/-/web3.js-1.73.0.tgz",
|
||||||
"integrity": "sha512-AnaqCF1cJ3w7d0yhvLGAKAcRI+n5o+ursQihhoTe4cUh8/9d4gbT73SoHYElS7e67OtAgLmSfbcC5hcOAgdvnQ==",
|
"integrity": "sha512-YrgX3Py7ylh8NYkbanoINUPCj//bWUjYZ5/WPy9nQ9SK3Cl7QWCR+NmbDjmC/fTspZGR+VO9LTQslM++jr5PRw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.12.5",
|
"@babel/runtime": "^7.12.5",
|
||||||
"@noble/ed25519": "^1.7.0",
|
"@noble/ed25519": "^1.7.0",
|
||||||
"@noble/hashes": "^1.1.2",
|
"@noble/hashes": "^1.1.2",
|
||||||
"@noble/secp256k1": "^1.6.3",
|
"@noble/secp256k1": "^1.6.3",
|
||||||
"@solana/buffer-layout": "^4.0.0",
|
"@solana/buffer-layout": "^4.0.0",
|
||||||
|
"agentkeepalive": "^4.2.1",
|
||||||
"bigint-buffer": "^1.1.5",
|
"bigint-buffer": "^1.1.5",
|
||||||
"bn.js": "^5.0.0",
|
"bn.js": "^5.0.0",
|
||||||
"borsh": "^0.7.0",
|
"borsh": "^0.7.0",
|
||||||
|
@ -445,61 +476,25 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@switchboard-xyz/solana.js": {
|
"node_modules/@switchboard-xyz/solana.js": {
|
||||||
"version": "2.0.52",
|
"version": "2.0.79",
|
||||||
"resolved": "https://registry.npmjs.org/@switchboard-xyz/solana.js/-/solana.js-2.0.52.tgz",
|
"resolved": "https://registry.npmjs.org/@switchboard-xyz/solana.js/-/solana.js-2.0.79.tgz",
|
||||||
"integrity": "sha512-ppM64vBeR8DZ9RYeVi7mhG4OwwLvBOYAlitaa7v32/43Qlz7rHokdRkyQPYh50mr2rRiebVlpMINh6ZD6tWP6A==",
|
"integrity": "sha512-gQeseWGpzWDcpQEqivRNw+FgjGjV2nxmEXgcZWwRz7SpRYehuhZVBnkueTlQEAdGYmi/oXU32YpERcfm6s2jXg==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@project-serum/anchor": "^0.25.0",
|
"@project-serum/anchor": "^0.26.0",
|
||||||
"@project-serum/borsh": "^0.2.5",
|
"@project-serum/borsh": "^0.2.5",
|
||||||
"@solana/spl-token": "^0.3.5",
|
"@solana/spl-token": "^0.3.6",
|
||||||
"@solana/web3.js": "^1.66.1",
|
"@solana/web3.js": "^1.73.0",
|
||||||
"@switchboard-xyz/common": "^2.1.8",
|
"@switchboard-xyz/common": "^2.1.8",
|
||||||
"big.js": "^6.2.1",
|
"big.js": "^6.2.1",
|
||||||
"bn.js": "^5.2.1"
|
"bn.js": "^5.2.1",
|
||||||
|
"dotenv": "^16.0.3",
|
||||||
|
"lodash": "^4.17.21"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.0.0",
|
"node": ">=16.0.0",
|
||||||
"npm": ">=7.0.0"
|
"npm": ">=7.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@switchboard-xyz/solana.js/node_modules/@project-serum/anchor": {
|
|
||||||
"version": "0.25.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@project-serum/anchor/-/anchor-0.25.0.tgz",
|
|
||||||
"integrity": "sha512-E6A5Y/ijqpfMJ5psJvbw0kVTzLZFUcOFgs6eSM2M2iWE1lVRF18T6hWZVNl6zqZsoz98jgnNHtVGJMs+ds9A7A==",
|
|
||||||
"dependencies": {
|
|
||||||
"@project-serum/borsh": "^0.2.5",
|
|
||||||
"@solana/web3.js": "^1.36.0",
|
|
||||||
"base64-js": "^1.5.1",
|
|
||||||
"bn.js": "^5.1.2",
|
|
||||||
"bs58": "^4.0.1",
|
|
||||||
"buffer-layout": "^1.2.2",
|
|
||||||
"camelcase": "^5.3.1",
|
|
||||||
"cross-fetch": "^3.1.5",
|
|
||||||
"crypto-hash": "^1.3.0",
|
|
||||||
"eventemitter3": "^4.0.7",
|
|
||||||
"js-sha256": "^0.9.0",
|
|
||||||
"pako": "^2.0.3",
|
|
||||||
"snake-case": "^3.0.4",
|
|
||||||
"superstruct": "^0.15.4",
|
|
||||||
"toml": "^3.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=11"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@switchboard-xyz/solana.js/node_modules/camelcase": {
|
|
||||||
"version": "5.3.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz",
|
|
||||||
"integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=6"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@switchboard-xyz/solana.js/node_modules/superstruct": {
|
|
||||||
"version": "0.15.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/superstruct/-/superstruct-0.15.5.tgz",
|
|
||||||
"integrity": "sha512-4AOeU+P5UuE/4nOUkmcQdW5y7i9ndt1cQd/3iUe+LTz3RxESf/W/5lg4B74HbDMMv8PHnPnGCQFH45kBcrQYoQ=="
|
|
||||||
},
|
|
||||||
"node_modules/@tsconfig/node10": {
|
"node_modules/@tsconfig/node10": {
|
||||||
"version": "1.0.9",
|
"version": "1.0.9",
|
||||||
"resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz",
|
"resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz",
|
||||||
|
@ -808,6 +803,19 @@
|
||||||
"node": ">=0.4.0"
|
"node": ">=0.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/agentkeepalive": {
|
||||||
|
"version": "4.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.2.1.tgz",
|
||||||
|
"integrity": "sha512-Zn4cw2NEqd+9fiSVWMscnjyQ1a8Yfoc5oBajLeo5w+YBHgDUcEBY2hS4YpTz6iN5f/2zQiktcuM6tS8x1p9dpA==",
|
||||||
|
"dependencies": {
|
||||||
|
"debug": "^4.1.0",
|
||||||
|
"depd": "^1.1.2",
|
||||||
|
"humanize-ms": "^1.2.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 8.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/ajv": {
|
"node_modules/ajv": {
|
||||||
"version": "6.12.6",
|
"version": "6.12.6",
|
||||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
|
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
|
||||||
|
@ -1262,7 +1270,6 @@
|
||||||
"version": "4.3.4",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ms": "2.1.2"
|
"ms": "2.1.2"
|
||||||
},
|
},
|
||||||
|
@ -1337,6 +1344,14 @@
|
||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/depd": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/diff": {
|
"node_modules/diff": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz",
|
||||||
|
@ -2152,6 +2167,14 @@
|
||||||
"integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==",
|
"integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/humanize-ms": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"ms": "^2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/ieee754": {
|
"node_modules/ieee754": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
|
||||||
|
@ -2930,8 +2953,7 @@
|
||||||
"node_modules/ms": {
|
"node_modules/ms": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"node_modules/nanoid": {
|
"node_modules/nanoid": {
|
||||||
"version": "3.3.1",
|
"version": "3.3.1",
|
||||||
|
@ -4762,6 +4784,35 @@
|
||||||
"fastq": "^1.6.0"
|
"fastq": "^1.6.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@project-serum/anchor": {
|
||||||
|
"version": "0.26.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@project-serum/anchor/-/anchor-0.26.0.tgz",
|
||||||
|
"integrity": "sha512-Nq+COIjE1135T7qfnOHEn7E0q39bQTgXLFk837/rgFe6Hkew9WML7eHsS+lSYD2p3OJaTiUOHTAq1lHy36oIqQ==",
|
||||||
|
"requires": {
|
||||||
|
"@coral-xyz/borsh": "^0.26.0",
|
||||||
|
"@solana/web3.js": "^1.68.0",
|
||||||
|
"base64-js": "^1.5.1",
|
||||||
|
"bn.js": "^5.1.2",
|
||||||
|
"bs58": "^4.0.1",
|
||||||
|
"buffer-layout": "^1.2.2",
|
||||||
|
"camelcase": "^6.3.0",
|
||||||
|
"cross-fetch": "^3.1.5",
|
||||||
|
"crypto-hash": "^1.3.0",
|
||||||
|
"eventemitter3": "^4.0.7",
|
||||||
|
"js-sha256": "^0.9.0",
|
||||||
|
"pako": "^2.0.3",
|
||||||
|
"snake-case": "^3.0.4",
|
||||||
|
"superstruct": "^0.15.4",
|
||||||
|
"toml": "^3.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"superstruct": {
|
||||||
|
"version": "0.15.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/superstruct/-/superstruct-0.15.5.tgz",
|
||||||
|
"integrity": "sha512-4AOeU+P5UuE/4nOUkmcQdW5y7i9ndt1cQd/3iUe+LTz3RxESf/W/5lg4B74HbDMMv8PHnPnGCQFH45kBcrQYoQ=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"@project-serum/borsh": {
|
"@project-serum/borsh": {
|
||||||
"version": "0.2.5",
|
"version": "0.2.5",
|
||||||
"resolved": "https://registry.npmjs.org/@project-serum/borsh/-/borsh-0.2.5.tgz",
|
"resolved": "https://registry.npmjs.org/@project-serum/borsh/-/borsh-0.2.5.tgz",
|
||||||
|
@ -4855,15 +4906,16 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@solana/web3.js": {
|
"@solana/web3.js": {
|
||||||
"version": "1.70.1",
|
"version": "1.73.0",
|
||||||
"resolved": "https://registry.npmjs.org/@solana/web3.js/-/web3.js-1.70.1.tgz",
|
"resolved": "https://registry.npmjs.org/@solana/web3.js/-/web3.js-1.73.0.tgz",
|
||||||
"integrity": "sha512-AnaqCF1cJ3w7d0yhvLGAKAcRI+n5o+ursQihhoTe4cUh8/9d4gbT73SoHYElS7e67OtAgLmSfbcC5hcOAgdvnQ==",
|
"integrity": "sha512-YrgX3Py7ylh8NYkbanoINUPCj//bWUjYZ5/WPy9nQ9SK3Cl7QWCR+NmbDjmC/fTspZGR+VO9LTQslM++jr5PRw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@babel/runtime": "^7.12.5",
|
"@babel/runtime": "^7.12.5",
|
||||||
"@noble/ed25519": "^1.7.0",
|
"@noble/ed25519": "^1.7.0",
|
||||||
"@noble/hashes": "^1.1.2",
|
"@noble/hashes": "^1.1.2",
|
||||||
"@noble/secp256k1": "^1.6.3",
|
"@noble/secp256k1": "^1.6.3",
|
||||||
"@solana/buffer-layout": "^4.0.0",
|
"@solana/buffer-layout": "^4.0.0",
|
||||||
|
"agentkeepalive": "^4.2.1",
|
||||||
"bigint-buffer": "^1.1.5",
|
"bigint-buffer": "^1.1.5",
|
||||||
"bn.js": "^5.0.0",
|
"bn.js": "^5.0.0",
|
||||||
"borsh": "^0.7.0",
|
"borsh": "^0.7.0",
|
||||||
|
@ -4899,51 +4951,19 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@switchboard-xyz/solana.js": {
|
"@switchboard-xyz/solana.js": {
|
||||||
"version": "2.0.52",
|
"version": "2.0.79",
|
||||||
"resolved": "https://registry.npmjs.org/@switchboard-xyz/solana.js/-/solana.js-2.0.52.tgz",
|
"resolved": "https://registry.npmjs.org/@switchboard-xyz/solana.js/-/solana.js-2.0.79.tgz",
|
||||||
"integrity": "sha512-ppM64vBeR8DZ9RYeVi7mhG4OwwLvBOYAlitaa7v32/43Qlz7rHokdRkyQPYh50mr2rRiebVlpMINh6ZD6tWP6A==",
|
"integrity": "sha512-gQeseWGpzWDcpQEqivRNw+FgjGjV2nxmEXgcZWwRz7SpRYehuhZVBnkueTlQEAdGYmi/oXU32YpERcfm6s2jXg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@project-serum/anchor": "^0.25.0",
|
"@project-serum/anchor": "^0.26.0",
|
||||||
"@project-serum/borsh": "^0.2.5",
|
"@project-serum/borsh": "^0.2.5",
|
||||||
"@solana/spl-token": "^0.3.5",
|
"@solana/spl-token": "^0.3.6",
|
||||||
"@solana/web3.js": "^1.66.1",
|
"@solana/web3.js": "^1.73.0",
|
||||||
"@switchboard-xyz/common": "^2.1.8",
|
"@switchboard-xyz/common": "^2.1.8",
|
||||||
"big.js": "^6.2.1",
|
"big.js": "^6.2.1",
|
||||||
"bn.js": "^5.2.1"
|
"bn.js": "^5.2.1",
|
||||||
},
|
"dotenv": "^16.0.3",
|
||||||
"dependencies": {
|
"lodash": "^4.17.21"
|
||||||
"@project-serum/anchor": {
|
|
||||||
"version": "0.25.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@project-serum/anchor/-/anchor-0.25.0.tgz",
|
|
||||||
"integrity": "sha512-E6A5Y/ijqpfMJ5psJvbw0kVTzLZFUcOFgs6eSM2M2iWE1lVRF18T6hWZVNl6zqZsoz98jgnNHtVGJMs+ds9A7A==",
|
|
||||||
"requires": {
|
|
||||||
"@project-serum/borsh": "^0.2.5",
|
|
||||||
"@solana/web3.js": "^1.36.0",
|
|
||||||
"base64-js": "^1.5.1",
|
|
||||||
"bn.js": "^5.1.2",
|
|
||||||
"bs58": "^4.0.1",
|
|
||||||
"buffer-layout": "^1.2.2",
|
|
||||||
"camelcase": "^5.3.1",
|
|
||||||
"cross-fetch": "^3.1.5",
|
|
||||||
"crypto-hash": "^1.3.0",
|
|
||||||
"eventemitter3": "^4.0.7",
|
|
||||||
"js-sha256": "^0.9.0",
|
|
||||||
"pako": "^2.0.3",
|
|
||||||
"snake-case": "^3.0.4",
|
|
||||||
"superstruct": "^0.15.4",
|
|
||||||
"toml": "^3.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"camelcase": {
|
|
||||||
"version": "5.3.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz",
|
|
||||||
"integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg=="
|
|
||||||
},
|
|
||||||
"superstruct": {
|
|
||||||
"version": "0.15.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/superstruct/-/superstruct-0.15.5.tgz",
|
|
||||||
"integrity": "sha512-4AOeU+P5UuE/4nOUkmcQdW5y7i9ndt1cQd/3iUe+LTz3RxESf/W/5lg4B74HbDMMv8PHnPnGCQFH45kBcrQYoQ=="
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@tsconfig/node10": {
|
"@tsconfig/node10": {
|
||||||
|
@ -5153,6 +5173,16 @@
|
||||||
"integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==",
|
"integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"agentkeepalive": {
|
||||||
|
"version": "4.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.2.1.tgz",
|
||||||
|
"integrity": "sha512-Zn4cw2NEqd+9fiSVWMscnjyQ1a8Yfoc5oBajLeo5w+YBHgDUcEBY2hS4YpTz6iN5f/2zQiktcuM6tS8x1p9dpA==",
|
||||||
|
"requires": {
|
||||||
|
"debug": "^4.1.0",
|
||||||
|
"depd": "^1.1.2",
|
||||||
|
"humanize-ms": "^1.2.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"ajv": {
|
"ajv": {
|
||||||
"version": "6.12.6",
|
"version": "6.12.6",
|
||||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
|
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
|
||||||
|
@ -5479,7 +5509,6 @@
|
||||||
"version": "4.3.4",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"ms": "2.1.2"
|
"ms": "2.1.2"
|
||||||
}
|
}
|
||||||
|
@ -5525,6 +5554,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/delay/-/delay-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/delay/-/delay-5.0.0.tgz",
|
||||||
"integrity": "sha512-ReEBKkIfe4ya47wlPYf/gu5ib6yUG0/Aez0JQZQz94kiWtRQvZIQbTiehsnwHvLSWJnQdhVeqYue7Id1dKr0qw=="
|
"integrity": "sha512-ReEBKkIfe4ya47wlPYf/gu5ib6yUG0/Aez0JQZQz94kiWtRQvZIQbTiehsnwHvLSWJnQdhVeqYue7Id1dKr0qw=="
|
||||||
},
|
},
|
||||||
|
"depd": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ=="
|
||||||
|
},
|
||||||
"diff": {
|
"diff": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz",
|
||||||
|
@ -6144,6 +6178,14 @@
|
||||||
"integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==",
|
"integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"humanize-ms": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==",
|
||||||
|
"requires": {
|
||||||
|
"ms": "^2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"ieee754": {
|
"ieee754": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
|
||||||
|
@ -6714,8 +6756,7 @@
|
||||||
"ms": {
|
"ms": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"nanoid": {
|
"nanoid": {
|
||||||
"version": "3.3.1",
|
"version": "3.3.1",
|
||||||
|
|
|
@ -11,8 +11,17 @@
|
||||||
"sbv2-vrf-example": "./sbv2-vrf-example.sh"
|
"sbv2-vrf-example": "./sbv2-vrf-example.sh"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "echo \"For workspace anchor-vrf-parser, run 'anchor build' from the project root\" && exit 0",
|
"lint": "eslint --ext .js,.json,.ts 'src/**' --fix",
|
||||||
"lint": "eslint --ext .js,.json,.ts 'src/**' --fix"
|
"pubkey": "solana-keygen pubkey target/deploy/anchor_vrf_parser-keypair.json",
|
||||||
|
"localnet": "npm run localnet:down || exit 0; solana-test-validator -q -r --ledger .anchor/test-ledger --mint $(solana-keygen pubkey ~/.config/solana/id.json) --bind-address 0.0.0.0 --url https://api.devnet.solana.com --rpc-port 8899 --clone 2TfB33aLaneQb5TNVwyDz3jSZXS6jdW2ARw1Dgf84XCG `# programId` --clone J4CArpsbrZqu1axqQ4AnrqREs3jwoyA1M5LMiQQmAzB9 `# programDataAddress` --clone CKwZcshn4XDvhaWVH9EXnk3iu19t6t5xP2Sy2pD6TRDp `# idlAddress` --clone BYM81n8HvTJuqZU1PmTVcwZ9G8uoji7FKM6EaPkwphPt `# programState` --clone FVLfR6C2ckZhbSwBzZY4CX7YBcddUSge5BNeGQv5eKhy `# switchboardVault` & npm run localnet:wait",
|
||||||
|
"localnet:wait": "for attempt in {1..30}; do sleep 1; if curl -sS http://localhost:8899 -X POST -H 'Content-Type: application/json' -d '{\"jsonrpc\":\"2.0\",\"id\":1, \"method\":\"getBlockHeight\"}'; then echo ready; break; fi; done",
|
||||||
|
"localnet:down": "kill -9 $(pgrep command solana-test-validator) || exit 0",
|
||||||
|
"network:create": "sbv2 solana network create --keypair ~/.config/solana/id.json --configFile .switchboard/networks/default.config.json --schemaFile .switchboard/networks/default.json --cluster localnet --force",
|
||||||
|
"network:start": "sbv2 solana network start --keypair ~/.config/solana/id.json --schemaFile .switchboard/networks/default.json --cluster localnet --nodeImage dev-v2-RC_01_05_23_18_41a-beta",
|
||||||
|
"network:start:dev": "VERBOSE=1 DEBUG=1 CHAIN=solana CLUSTER=localnet TASK_RUNNER_SOLANA_RPC=https://api.mainnet-beta.solana.com FS_PAYER_SECRET_PATH=~/.config/solana/id.json RPC_URL=http://localhost:8899 ORACLE_KEY=Ei4HcqRQtf6TfwbuRXKRwCtt8PDXhmq9NhYLWpoh23xp ts-node ../../../switchboard-oracle-v2/node/src/apps/oracle",
|
||||||
|
"build": "anchor build && npx anchor-client-gen target/idl/lottery.json client/generated --program-id $(solana-keygen pubkey target/deploy/anchor_vrf_parser-keypair.json) && npx prettier client/generated --write",
|
||||||
|
"test": "npm run localnet && npm run network:create && npm run network:start & sleep 60 && anchor test --skip-local-validator",
|
||||||
|
"test:dev": "npm run localnet && npm run network:create && npm run network:start:dev & sleep 15 && anchor test --skip-local-validator"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@coral-xyz/anchor": "^0.26.0",
|
"@coral-xyz/anchor": "^0.26.0",
|
||||||
|
@ -21,7 +30,7 @@
|
||||||
"@solana/spl-token": "^0.3.6",
|
"@solana/spl-token": "^0.3.6",
|
||||||
"@solana/web3.js": "^1.67.0",
|
"@solana/web3.js": "^1.67.0",
|
||||||
"@switchboard-xyz/common": "^2.1.8",
|
"@switchboard-xyz/common": "^2.1.8",
|
||||||
"@switchboard-xyz/solana.js": "^2.0.52",
|
"@switchboard-xyz/solana.js": "^2.0.79",
|
||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
"dotenv": "^16.0.1",
|
"dotenv": "^16.0.1",
|
||||||
"yargs": "^17.5.1"
|
"yargs": "^17.5.1"
|
||||||
|
|
|
@ -14,11 +14,11 @@ import {
|
||||||
AnchorWallet,
|
AnchorWallet,
|
||||||
Callback,
|
Callback,
|
||||||
PermissionAccount,
|
PermissionAccount,
|
||||||
SwitchboardTestContext,
|
|
||||||
types,
|
types,
|
||||||
} from "@switchboard-xyz/solana.js";
|
} from "@switchboard-xyz/solana.js";
|
||||||
import { sleep } from "@switchboard-xyz/common";
|
import { sleep } from "@switchboard-xyz/common";
|
||||||
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||||
|
import { Switchboard } from "./init";
|
||||||
|
|
||||||
describe("anchor-vrf-parser test", () => {
|
describe("anchor-vrf-parser test", () => {
|
||||||
const provider = AnchorProvider.env();
|
const provider = AnchorProvider.env();
|
||||||
|
@ -36,7 +36,7 @@ describe("anchor-vrf-parser test", () => {
|
||||||
|
|
||||||
const payer = (provider.wallet as AnchorWallet).payer;
|
const payer = (provider.wallet as AnchorWallet).payer;
|
||||||
|
|
||||||
let switchboard: SwitchboardTestContext;
|
let switchboard: Switchboard;
|
||||||
|
|
||||||
const vrfSecret = anchor.web3.Keypair.generate();
|
const vrfSecret = anchor.web3.Keypair.generate();
|
||||||
console.log(`VRF Account: ${vrfSecret.publicKey}`);
|
console.log(`VRF Account: ${vrfSecret.publicKey}`);
|
||||||
|
@ -63,40 +63,11 @@ describe("anchor-vrf-parser test", () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
// First, attempt to load the switchboard devnet PID
|
switchboard = await Switchboard.load(provider);
|
||||||
try {
|
|
||||||
switchboard = await SwitchboardTestContext.loadDevnetQueue(
|
|
||||||
provider as anchor.AnchorProvider,
|
|
||||||
"F8ce7MsckeZAbAGmxjJNetxYXQa9mKr9nnrC3qKubyYy",
|
|
||||||
5_000_000 // .005 wSOL
|
|
||||||
);
|
|
||||||
console.log("devnet detected");
|
|
||||||
return;
|
|
||||||
} catch (error: any) {
|
|
||||||
console.log(`Error: SBV2 Devnet - ${error.message}`);
|
|
||||||
// console.error(error);
|
|
||||||
}
|
|
||||||
// If fails, fallback to looking for a local env file
|
|
||||||
try {
|
|
||||||
switchboard = await SwitchboardTestContext.loadFromEnv(
|
|
||||||
provider,
|
|
||||||
undefined,
|
|
||||||
5_000_000 // .005 wSOL
|
|
||||||
);
|
|
||||||
console.log("localnet detected");
|
|
||||||
return;
|
|
||||||
} catch (error: any) {
|
|
||||||
console.log(`Error: SBV2 Localnet - ${error.message}`);
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
// If fails, throw error
|
|
||||||
throw new Error(
|
|
||||||
`Failed to load the SwitchboardTestContext from devnet or from a switchboard.env file`
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Creates a vrfClient account", async () => {
|
it("Creates a vrfClient account", async () => {
|
||||||
const queue = switchboard.queue;
|
const queue = switchboard.queue.account;
|
||||||
const { unpermissionedVrfEnabled, authority, dataBuffer } =
|
const { unpermissionedVrfEnabled, authority, dataBuffer } =
|
||||||
await queue.loadData();
|
await queue.loadData();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
import { AnchorProvider } from "@coral-xyz/anchor";
|
||||||
|
import { Cluster, clusterApiUrl, Keypair } from "@solana/web3.js";
|
||||||
|
import {
|
||||||
|
ISwitchboardNetwork,
|
||||||
|
SwitchboardNetwork,
|
||||||
|
SwitchboardProgram,
|
||||||
|
} from "@switchboard-xyz/solana.js";
|
||||||
|
import os from "os";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
export const DEFAULT_KEYPAIR_PATH = path.join(
|
||||||
|
os.homedir(),
|
||||||
|
".config/solana/id.json"
|
||||||
|
);
|
||||||
|
|
||||||
|
export function getCluster(
|
||||||
|
rpcEndpoint: string
|
||||||
|
): Cluster | "localnet" | undefined {
|
||||||
|
switch (rpcEndpoint) {
|
||||||
|
case "http://localhost:8899":
|
||||||
|
return "localnet";
|
||||||
|
case clusterApiUrl("devnet"):
|
||||||
|
return "devnet";
|
||||||
|
case clusterApiUrl("mainnet-beta"):
|
||||||
|
return "mainnet-beta";
|
||||||
|
default:
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Switchboard extends SwitchboardNetwork {
|
||||||
|
private static _instances: Map<string, Promise<Switchboard>> = new Map();
|
||||||
|
|
||||||
|
private constructor(network: SwitchboardNetwork, readonly name: string) {
|
||||||
|
super(network);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static load(
|
||||||
|
provider: AnchorProvider,
|
||||||
|
name = "default"
|
||||||
|
): Promise<Switchboard> {
|
||||||
|
if (!this._instances.has(name)) {
|
||||||
|
this._instances.set(
|
||||||
|
name,
|
||||||
|
new Promise(async (resolve, reject) => {
|
||||||
|
try {
|
||||||
|
const program = await SwitchboardProgram.fromProvider(provider);
|
||||||
|
const switchboardNetwork = SwitchboardNetwork.find(program, name);
|
||||||
|
const switchboard = new Switchboard(switchboardNetwork, name);
|
||||||
|
resolve(switchboard);
|
||||||
|
} catch (error) {
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._instances.get(name)!;
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,6 +12,7 @@
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"strict": false,
|
"strict": false,
|
||||||
"strictNullChecks": false,
|
"strictNullChecks": false,
|
||||||
|
"target": "es6",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@switchboard-xyz/switchboard-v2": ["../../javascript/switchboard-v2"],
|
"@switchboard-xyz/switchboard-v2": ["../../javascript/switchboard-v2"],
|
||||||
"@switchboard-xyz/sbv2-utils": ["../../javascript/sbv2-utils"],
|
"@switchboard-xyz/sbv2-utils": ["../../javascript/sbv2-utils"],
|
||||||
|
|
Loading…
Reference in New Issue