solana.js: cleaned up SwitchboardEvents

This commit is contained in:
Conner Gallagher 2022-12-22 11:27:30 -07:00
parent 5e1334f6bd
commit f331b88fb7
3 changed files with 198 additions and 145 deletions

View File

@ -1,76 +1,89 @@
import * as anchor from '@project-serum/anchor';
import * as types from './generated';
export type SwitchboardEvents = {
AggregatorAddJobEvent: {
export type AggregatorAddJobEvent = {
feedPubkey: anchor.web3.PublicKey;
jobPubkey: anchor.web3.PublicKey;
};
AggregatorRemoveJobEvent: {
};
export type AggregatorRemoveJobEvent = {
feedPubkey: anchor.web3.PublicKey;
jobPubkey: anchor.web3.PublicKey;
};
AggregatorLockEvent: {
};
export type AggregatorLockEvent = {
feedPubkey: anchor.web3.PublicKey;
};
AggregatorInitEvent: {
};
export type AggregatorInitEvent = {
feedPubkey: anchor.web3.PublicKey;
};
AggregatorSetAuthorityEvent: {
};
export type AggregatorSetAuthorityEvent = {
feedPubkey: anchor.web3.PublicKey;
oldAuthority: anchor.web3.PublicKey;
newAuthority: anchor.web3.PublicKey;
};
AggregatorSetConfigsEvent: {
};
export type AggregatorSetConfigsEvent = {
feedPubkey: anchor.web3.PublicKey;
};
PermissionSetEvent: {
};
export type PermissionSetEvent = {
permissionKey: anchor.web3.PublicKey;
permission: types.SwitchboardPermissionKind;
enable: boolean;
};
VrfRequestRandomnessEvent: {
};
export type VrfRequestRandomnessEvent = {
vrfPubkey: anchor.web3.PublicKey;
oraclePubkeys: anchor.web3.PublicKey[];
loadAmount: anchor.BN;
existingAmount: anchor.BN;
};
VrfRequestEvent: {
};
export type VrfRequestEvent = {
vrfPubkey: anchor.web3.PublicKey;
oraclePubkeys: anchor.web3.PublicKey[];
};
VrfProveEvent: {
};
export type VrfProveEvent = {
vrfPubkey: anchor.web3.PublicKey;
oraclePubkey: anchor.web3.PublicKey;
authorityPubkey: anchor.web3.PublicKey;
};
VrfVerifyEvent: {
};
export type VrfVerifyEvent = {
vrfPubkey: anchor.web3.PublicKey;
oraclePubkey: anchor.web3.PublicKey;
authorityPubkey: anchor.web3.PublicKey;
amount: anchor.BN;
};
VrfCallbackPerformedEvent: {
};
export type VrfCallbackPerformedEvent = {
vrfPubkey: anchor.web3.PublicKey;
oraclePubkey: anchor.web3.PublicKey;
amount: anchor.BN;
};
AggregatorOpenRoundEvent: {
};
export type AggregatorOpenRoundEvent = {
feedPubkey: anchor.web3.PublicKey;
oraclePubkeys: anchor.web3.PublicKey[];
jobPubkeys: anchor.web3.PublicKey[];
remainingFunds: anchor.BN;
queueAuthority: anchor.web3.PublicKey;
};
AggregatorValueUpdateEvent: {
};
export type AggregatorValueUpdateEvent = {
feedPubkey: anchor.web3.PublicKey;
value: types.SwitchboardDecimalFields;
slot: anchor.BN;
timestamp: anchor.BN;
oraclePubkeys: anchor.web3.PublicKey[];
oracleValues: types.SwitchboardDecimalFields[];
};
OracleRewardEvent: {
};
export type OracleRewardEvent = {
feedPubkey: anchor.web3.PublicKey;
leasePubkey: anchor.web3.PublicKey;
oraclePubkey: anchor.web3.PublicKey;
@ -78,23 +91,26 @@ export type SwitchboardEvents = {
amount: anchor.BN;
roundSlot: anchor.BN;
timestamp: anchor.BN;
};
OracleWithdrawEvent: {
};
export type OracleWithdrawEvent = {
oraclePubkey: anchor.web3.PublicKey;
walletPubkey: anchor.web3.PublicKey;
destinationWallet: anchor.web3.PublicKey;
previousAmount: anchor.BN;
newAmount: anchor.BN;
timestamp: anchor.BN;
};
LeaseWithdrawEvent: {
};
export type LeaseWithdrawEvent = {
leasePubkey: anchor.web3.PublicKey;
walletPubkey: anchor.web3.PublicKey;
previousAmount: anchor.BN;
newAmount: anchor.BN;
timestamp: anchor.BN;
};
OracleSlashEvent: {
};
export type OracleSlashEvent = {
feedPubkey: anchor.web3.PublicKey;
leasePubkey: anchor.web3.PublicKey;
oraclePubkey: anchor.web3.PublicKey;
@ -102,43 +118,79 @@ export type SwitchboardEvents = {
amount: anchor.BN;
roundSlot: anchor.BN;
timestamp: anchor.BN;
};
LeaseFundEvent: {
};
export type LeaseFundEvent = {
leasePubkey: anchor.web3.PublicKey;
funder: anchor.web3.PublicKey;
amount: anchor.BN;
timestamp: anchor.BN;
};
ProbationBrokenEvent: {
};
export type ProbationBrokenEvent = {
feedPubkey: anchor.web3.PublicKey;
queuePubkey: anchor.web3.PublicKey;
timestamp: anchor.BN;
};
FeedPermissionRevokedEvent: {
};
export type FeedPermissionRevokedEvent = {
feedPubkey: anchor.web3.PublicKey;
timestamp: anchor.BN;
};
GarbageCollectFailureEvent: {
};
export type GarbageCollectFailureEvent = {
queuePubkey: anchor.web3.PublicKey;
};
OracleBootedEvent: {
};
export type OracleBootedEvent = {
queuePubkey: anchor.web3.PublicKey;
oraclePubkey: anchor.web3.PublicKey;
};
AggregatorCrankEvictionEvent: {};
CrankLeaseInsufficientFundsEvent: {
};
export type CrankLeaseInsufficientFundsEvent = {
feedPubkey: anchor.web3.PublicKey;
leasePubkey: anchor.web3.PublicKey;
};
CrankPopExpectedFailureEvent: {
};
export type CrankPopExpectedFailureEvent = {
feedPubkey: anchor.web3.PublicKey;
leasePubkey: anchor.web3.PublicKey;
};
BufferRelayerOpenRoundEvent: {
};
export type BufferRelayerOpenRoundEvent = {
relayerPubkey: anchor.web3.PublicKey;
jobPubkey: anchor.web3.PublicKey;
oraclePubkeys: anchor.web3.PublicKey[];
remainingFunds: anchor.BN;
queue: anchor.web3.PublicKey;
};
};
export type SwitchboardEvents = {
AggregatorAddJobEvent: AggregatorAddJobEvent;
AggregatorRemoveJobEvent: AggregatorRemoveJobEvent;
AggregatorLockEvent: AggregatorLockEvent;
AggregatorInitEvent: AggregatorInitEvent;
AggregatorSetAuthorityEvent: AggregatorSetAuthorityEvent;
AggregatorSetConfigsEvent: AggregatorSetConfigsEvent;
PermissionSetEvent: PermissionSetEvent;
VrfRequestRandomnessEvent: VrfRequestRandomnessEvent;
VrfRequestEvent: VrfRequestEvent;
VrfProveEvent: VrfProveEvent;
VrfVerifyEvent: VrfVerifyEvent;
VrfCallbackPerformedEvent: VrfCallbackPerformedEvent;
AggregatorOpenRoundEvent: AggregatorOpenRoundEvent;
AggregatorValueUpdateEvent: AggregatorValueUpdateEvent;
OracleRewardEvent: OracleRewardEvent;
OracleWithdrawEvent: OracleWithdrawEvent;
LeaseWithdrawEvent: LeaseWithdrawEvent;
OracleSlashEvent: OracleSlashEvent;
LeaseFundEvent: LeaseFundEvent;
ProbationBrokenEvent: ProbationBrokenEvent;
FeedPermissionRevokedEvent: FeedPermissionRevokedEvent;
GarbageCollectFailureEvent: GarbageCollectFailureEvent;
OracleBootedEvent: OracleBootedEvent;
AggregatorCrankEvictionEvent: {};
CrankLeaseInsufficientFundsEvent: CrankLeaseInsufficientFundsEvent;
CrankPopExpectedFailureEvent: CrankPopExpectedFailureEvent;
BufferRelayerOpenRoundEvent: BufferRelayerOpenRoundEvent;
};

View File

@ -459,7 +459,7 @@ export class SwitchboardProgram {
data: SwitchboardEvents[EventName],
slot: number,
signature: string
) => void
) => void | Promise<void>
): number {
return this._program.addEventListener(eventName as string, callback);
}

View File

@ -486,16 +486,17 @@ export class CrankAccount extends Account<types.CrankAccountData> {
if (numReady < 6) {
// send as-is
return Array.from(Array(numReady).keys()).map(() =>
this.popSync(
return Array.from(Array(numReady).keys()).map(() => {
return this.popSync(
payer,
{
...params,
readyAggregators: params.readyAggregators,
nonce: Math.random(),
},
options
)
);
});
} else {
// stagger the ready accounts
return Array.from(Array(numReady).keys()).map(n => {