Add SwitchboardError to Solana.js exports
This commit is contained in:
parent
4820baa43a
commit
e0882bfdcb
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@switchboard-xyz/solana.js",
|
||||
"version": "2.0.2",
|
||||
"version": "2.0.4",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@switchboard-xyz/solana.js",
|
||||
"version": "2.0.2",
|
||||
"version": "2.0.4",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@project-serum/anchor": "^0.25.0",
|
||||
|
|
|
@ -183,6 +183,8 @@ export interface AggregatorSaveResultParams {
|
|||
tokenMint: PublicKey;
|
||||
/**
|
||||
* List of parsed oracles.
|
||||
*
|
||||
* TODO: Add better typing to this field type
|
||||
*/
|
||||
oracles: Array<any>;
|
||||
}
|
||||
|
|
|
@ -312,10 +312,6 @@ export class LeaseAccount extends Account<types.LeaseAccountData> {
|
|||
if (!queueAccountInfo) {
|
||||
throw new errors.AccountNotFoundError(lease.queue);
|
||||
}
|
||||
const queue: types.OracleQueueAccountData = coder.decode(
|
||||
QueueAccount.accountName,
|
||||
queueAccountInfo.data
|
||||
);
|
||||
|
||||
const jobWallets: Array<PublicKey> = [];
|
||||
const walletBumps: Array<number> = [];
|
||||
|
@ -436,8 +432,6 @@ export class LeaseAccount extends Account<types.LeaseAccountData> {
|
|||
}
|
||||
|
||||
const lease = await this.loadData();
|
||||
const coder = this.program.coder;
|
||||
|
||||
const accountInfos = await this.program.connection.getMultipleAccountsInfo([
|
||||
lease.aggregator,
|
||||
lease.queue,
|
||||
|
@ -452,20 +446,12 @@ export class LeaseAccount extends Account<types.LeaseAccountData> {
|
|||
if (!aggregatorAccountInfo) {
|
||||
throw new errors.AccountNotFoundError(lease.aggregator);
|
||||
}
|
||||
const aggregator: types.AggregatorAccountData = coder.decode(
|
||||
AggregatorAccount.accountName,
|
||||
aggregatorAccountInfo.data
|
||||
);
|
||||
|
||||
// decode queue
|
||||
const queueAccountInfo = accountInfos.shift();
|
||||
if (!queueAccountInfo) {
|
||||
throw new errors.AccountNotFoundError(lease.queue);
|
||||
}
|
||||
const queue: types.OracleQueueAccountData = coder.decode(
|
||||
QueueAccount.accountName,
|
||||
queueAccountInfo.data
|
||||
);
|
||||
|
||||
const [_, leaseBump] = LeaseAccount.fromSeed(
|
||||
this.program,
|
||||
|
|
|
@ -3,5 +3,7 @@ export * from './clock';
|
|||
export * as types from './generated';
|
||||
export * from './mint';
|
||||
export * from './program';
|
||||
export * from './switchboardError';
|
||||
export * from './switchboardEvents';
|
||||
export * from './transaction';
|
||||
export * from './utils';
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import * as anchor from '@project-serum/anchor';
|
||||
import * as errors from './errors';
|
||||
import * as sbv2 from './accounts';
|
||||
import * as types from './generated';
|
||||
import {
|
||||
Cluster,
|
||||
Connection,
|
||||
|
@ -12,124 +11,8 @@ import {
|
|||
} from '@solana/web3.js';
|
||||
import { Mint } from './mint';
|
||||
import { TransactionObject } from './transaction';
|
||||
import { SwitchboardEvents } from './switchboardEvents';
|
||||
|
||||
export type SwitchboardEvents = {
|
||||
AggregatorInitEvent: {
|
||||
feedPubkey: PublicKey;
|
||||
};
|
||||
VrfRequestRandomnessEvent: {
|
||||
vrfPubkey: PublicKey;
|
||||
oraclePubkeys: PublicKey[];
|
||||
loadAmount: anchor.BN;
|
||||
existingAmount: anchor.BN;
|
||||
};
|
||||
VrfRequestEvent: {
|
||||
vrfPubkey: PublicKey;
|
||||
oraclePubkeys: PublicKey[];
|
||||
};
|
||||
VrfProveEvent: {
|
||||
vrfPubkey: PublicKey;
|
||||
oraclePubkey: PublicKey;
|
||||
authorityPubkey: PublicKey;
|
||||
};
|
||||
VrfVerifyEvent: {
|
||||
vrfPubkey: PublicKey;
|
||||
oraclePubkey: PublicKey;
|
||||
authorityPubkey: PublicKey;
|
||||
amount: anchor.BN;
|
||||
};
|
||||
VrfCallbackPerformedEvent: {
|
||||
vrfPubkey: PublicKey;
|
||||
oraclePubkey: PublicKey;
|
||||
amount: anchor.BN;
|
||||
};
|
||||
AggregatorOpenRoundEvent: {
|
||||
feedPubkey: PublicKey;
|
||||
oraclePubkeys: PublicKey[];
|
||||
jobPubkeys: PublicKey[];
|
||||
remainingFunds: anchor.BN;
|
||||
queueAuthority: PublicKey;
|
||||
};
|
||||
AggregatorValueUpdateEvent: {
|
||||
feedPubkey: PublicKey;
|
||||
value: types.SwitchboardDecimal;
|
||||
slot: anchor.BN;
|
||||
timestamp: anchor.BN;
|
||||
oraclePubkeys: PublicKey[];
|
||||
oracleValues: types.SwitchboardDecimal[];
|
||||
};
|
||||
OracleRewardEvent: {
|
||||
feedPubkey: PublicKey;
|
||||
leasePubkey: PublicKey;
|
||||
oraclePubkey: PublicKey;
|
||||
walletPubkey: PublicKey;
|
||||
amount: anchor.BN;
|
||||
roundSlot: anchor.BN;
|
||||
timestamp: anchor.BN;
|
||||
};
|
||||
OracleWithdrawEvent: {
|
||||
oraclePubkey: PublicKey;
|
||||
walletPubkey: PublicKey;
|
||||
destinationWallet: PublicKey;
|
||||
previousAmount: anchor.BN;
|
||||
newAmount: anchor.BN;
|
||||
timestamp: anchor.BN;
|
||||
};
|
||||
LeaseWithdrawEvent: {
|
||||
leasePubkey: PublicKey;
|
||||
walletPubkey: PublicKey;
|
||||
previousAmount: anchor.BN;
|
||||
newAmount: anchor.BN;
|
||||
timestamp: anchor.BN;
|
||||
};
|
||||
OracleSlashEvent: {
|
||||
feedPubkey: PublicKey;
|
||||
leasePubkey: PublicKey;
|
||||
oraclePubkey: PublicKey;
|
||||
walletPubkey: PublicKey;
|
||||
amount: anchor.BN;
|
||||
roundSlot: anchor.BN;
|
||||
timestamp: anchor.BN;
|
||||
};
|
||||
LeaseFundEvent: {
|
||||
leasePubkey: PublicKey;
|
||||
funder: PublicKey;
|
||||
amount: anchor.BN;
|
||||
timestamp: anchor.BN;
|
||||
};
|
||||
ProbationBrokenEvent: {
|
||||
feedPubkey: PublicKey;
|
||||
queuePubkey: PublicKey;
|
||||
timestamp: anchor.BN;
|
||||
};
|
||||
FeedPermissionRevokedEvent: {
|
||||
feedPubkey: PublicKey;
|
||||
timestamp: anchor.BN;
|
||||
};
|
||||
GarbageCollectFailureEvent: {
|
||||
queuePubkey: PublicKey;
|
||||
};
|
||||
OracleBootedEvent: {
|
||||
queuePubkey: PublicKey;
|
||||
oraclePubkey: PublicKey;
|
||||
};
|
||||
AggregatorCrankEvictionEvent: {};
|
||||
CrankLeaseInsufficientFundsEvent: {
|
||||
feedPubkey: PublicKey;
|
||||
leasePubkey: PublicKey;
|
||||
};
|
||||
CrankPopExpectedFailureEvent: {
|
||||
feedPubkey: PublicKey;
|
||||
leasePubkey: PublicKey;
|
||||
};
|
||||
BufferRelayerOpenRoundEvent: {
|
||||
relayerPubkey: PublicKey;
|
||||
jobPubkey: PublicKey;
|
||||
oraclePubkeys: PublicKey[];
|
||||
remainingFunds: anchor.BN;
|
||||
queue: PublicKey;
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Switchboard Devnet Program ID
|
||||
*/
|
||||
|
@ -142,6 +25,10 @@ export const SBV2_DEVNET_PID = new PublicKey(
|
|||
export const SBV2_MAINNET_PID = new PublicKey(
|
||||
'SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f'
|
||||
);
|
||||
/**
|
||||
* A generated keypair that is assigned as the _payerKeypair_ when in read-only mode.
|
||||
*/
|
||||
export const READ_ONLY_KEYPAIR = Keypair.generate();
|
||||
/**
|
||||
* Returns the Switchboard Program ID for the specified Cluster.
|
||||
*/
|
||||
|
@ -167,12 +54,6 @@ const isBrowser =
|
|||
process.env.ANCHOR_BROWSER ||
|
||||
(typeof window !== 'undefined' && !window.process?.hasOwnProperty('type')); // eslint-disable-line no-prototype-builtins
|
||||
|
||||
// export const READ_ONLY_KEYPAIR = Keypair.fromSecretKey(
|
||||
// new Uint8Array([...(Array(32).fill(255) as number[])])
|
||||
// );
|
||||
export const READ_ONLY_KEYPAIR = Keypair.generate();
|
||||
export const READ_ONLY_PUBKEY = READ_ONLY_KEYPAIR.publicKey;
|
||||
|
||||
/**
|
||||
* Wrapper class for the Switchboard anchor Program.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
import { SwitchboardProgram } from './program';
|
||||
|
||||
/**
|
||||
* Switchboard wrapper for anchor program errors.
|
||||
*/
|
||||
export class SwitchboardError {
|
||||
/**
|
||||
* Converts a numerical error code to a SwitchboardError based on the program
|
||||
* IDL.
|
||||
* @param program the Switchboard program object containing the program IDL.
|
||||
* @param code Error code to convert to a SwitchboardError object.
|
||||
* @return SwitchboardError
|
||||
*/
|
||||
static fromCode(program: SwitchboardProgram, code: number): SwitchboardError {
|
||||
for (const e of program.idl.errors ?? []) {
|
||||
if (code === e.code) {
|
||||
return new SwitchboardError(program, e.name, e.code, e.msg);
|
||||
}
|
||||
}
|
||||
throw new Error(`Could not find SwitchboardError for error code ${code}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* The program containing the Switchboard IDL specifying error codes.
|
||||
*/
|
||||
readonly program: SwitchboardProgram;
|
||||
|
||||
/**
|
||||
* Stringified name of the error type.
|
||||
*/
|
||||
readonly name: string;
|
||||
|
||||
/**
|
||||
* Numerical SwitchboardError representation.
|
||||
*/
|
||||
readonly code: number;
|
||||
|
||||
/**
|
||||
* Message describing this error in detail.
|
||||
*/
|
||||
readonly msg?: string;
|
||||
|
||||
private constructor(
|
||||
program: SwitchboardProgram,
|
||||
name: string,
|
||||
code: number,
|
||||
msg?: string
|
||||
) {
|
||||
this.program = program;
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
import * as anchor from '@project-serum/anchor';
|
||||
import * as types from './generated';
|
||||
|
||||
export type SwitchboardEvents = {
|
||||
AggregatorInitEvent: {
|
||||
feedPubkey: anchor.web3.PublicKey;
|
||||
};
|
||||
VrfRequestRandomnessEvent: {
|
||||
vrfPubkey: anchor.web3.PublicKey;
|
||||
oraclePubkeys: anchor.web3.PublicKey[];
|
||||
loadAmount: anchor.BN;
|
||||
existingAmount: anchor.BN;
|
||||
};
|
||||
VrfRequestEvent: {
|
||||
vrfPubkey: anchor.web3.PublicKey;
|
||||
oraclePubkeys: anchor.web3.PublicKey[];
|
||||
};
|
||||
VrfProveEvent: {
|
||||
vrfPubkey: anchor.web3.PublicKey;
|
||||
oraclePubkey: anchor.web3.PublicKey;
|
||||
authorityPubkey: anchor.web3.PublicKey;
|
||||
};
|
||||
VrfVerifyEvent: {
|
||||
vrfPubkey: anchor.web3.PublicKey;
|
||||
oraclePubkey: anchor.web3.PublicKey;
|
||||
authorityPubkey: anchor.web3.PublicKey;
|
||||
amount: anchor.BN;
|
||||
};
|
||||
VrfCallbackPerformedEvent: {
|
||||
vrfPubkey: anchor.web3.PublicKey;
|
||||
oraclePubkey: anchor.web3.PublicKey;
|
||||
amount: anchor.BN;
|
||||
};
|
||||
AggregatorOpenRoundEvent: {
|
||||
feedPubkey: anchor.web3.PublicKey;
|
||||
oraclePubkeys: anchor.web3.PublicKey[];
|
||||
jobPubkeys: anchor.web3.PublicKey[];
|
||||
remainingFunds: anchor.BN;
|
||||
queueAuthority: anchor.web3.PublicKey;
|
||||
};
|
||||
AggregatorValueUpdateEvent: {
|
||||
feedPubkey: anchor.web3.PublicKey;
|
||||
value: types.SwitchboardDecimal;
|
||||
slot: anchor.BN;
|
||||
timestamp: anchor.BN;
|
||||
oraclePubkeys: anchor.web3.PublicKey[];
|
||||
oracleValues: types.SwitchboardDecimal[];
|
||||
};
|
||||
OracleRewardEvent: {
|
||||
feedPubkey: anchor.web3.PublicKey;
|
||||
leasePubkey: anchor.web3.PublicKey;
|
||||
oraclePubkey: anchor.web3.PublicKey;
|
||||
walletPubkey: anchor.web3.PublicKey;
|
||||
amount: anchor.BN;
|
||||
roundSlot: anchor.BN;
|
||||
timestamp: anchor.BN;
|
||||
};
|
||||
OracleWithdrawEvent: {
|
||||
oraclePubkey: anchor.web3.PublicKey;
|
||||
walletPubkey: anchor.web3.PublicKey;
|
||||
destinationWallet: anchor.web3.PublicKey;
|
||||
previousAmount: anchor.BN;
|
||||
newAmount: anchor.BN;
|
||||
timestamp: anchor.BN;
|
||||
};
|
||||
LeaseWithdrawEvent: {
|
||||
leasePubkey: anchor.web3.PublicKey;
|
||||
walletPubkey: anchor.web3.PublicKey;
|
||||
previousAmount: anchor.BN;
|
||||
newAmount: anchor.BN;
|
||||
timestamp: anchor.BN;
|
||||
};
|
||||
OracleSlashEvent: {
|
||||
feedPubkey: anchor.web3.PublicKey;
|
||||
leasePubkey: anchor.web3.PublicKey;
|
||||
oraclePubkey: anchor.web3.PublicKey;
|
||||
walletPubkey: anchor.web3.PublicKey;
|
||||
amount: anchor.BN;
|
||||
roundSlot: anchor.BN;
|
||||
timestamp: anchor.BN;
|
||||
};
|
||||
LeaseFundEvent: {
|
||||
leasePubkey: anchor.web3.PublicKey;
|
||||
funder: anchor.web3.PublicKey;
|
||||
amount: anchor.BN;
|
||||
timestamp: anchor.BN;
|
||||
};
|
||||
ProbationBrokenEvent: {
|
||||
feedPubkey: anchor.web3.PublicKey;
|
||||
queuePubkey: anchor.web3.PublicKey;
|
||||
timestamp: anchor.BN;
|
||||
};
|
||||
FeedPermissionRevokedEvent: {
|
||||
feedPubkey: anchor.web3.PublicKey;
|
||||
timestamp: anchor.BN;
|
||||
};
|
||||
GarbageCollectFailureEvent: {
|
||||
queuePubkey: anchor.web3.PublicKey;
|
||||
};
|
||||
OracleBootedEvent: {
|
||||
queuePubkey: anchor.web3.PublicKey;
|
||||
oraclePubkey: anchor.web3.PublicKey;
|
||||
};
|
||||
AggregatorCrankEvictionEvent: {};
|
||||
CrankLeaseInsufficientFundsEvent: {
|
||||
feedPubkey: anchor.web3.PublicKey;
|
||||
leasePubkey: anchor.web3.PublicKey;
|
||||
};
|
||||
CrankPopExpectedFailureEvent: {
|
||||
feedPubkey: anchor.web3.PublicKey;
|
||||
leasePubkey: anchor.web3.PublicKey;
|
||||
};
|
||||
BufferRelayerOpenRoundEvent: {
|
||||
relayerPubkey: anchor.web3.PublicKey;
|
||||
jobPubkey: anchor.web3.PublicKey;
|
||||
oraclePubkeys: anchor.web3.PublicKey[];
|
||||
remainingFunds: anchor.BN;
|
||||
queue: anchor.web3.PublicKey;
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue