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,144 +1,196 @@
import * as anchor from '@project-serum/anchor'; import * as anchor from '@project-serum/anchor';
import * as types from './generated'; import * as types from './generated';
export type SwitchboardEvents = { export type AggregatorAddJobEvent = {
AggregatorAddJobEvent: { feedPubkey: anchor.web3.PublicKey;
feedPubkey: anchor.web3.PublicKey; jobPubkey: anchor.web3.PublicKey;
jobPubkey: anchor.web3.PublicKey; };
};
AggregatorRemoveJobEvent: { export type AggregatorRemoveJobEvent = {
feedPubkey: anchor.web3.PublicKey; feedPubkey: anchor.web3.PublicKey;
jobPubkey: anchor.web3.PublicKey; jobPubkey: anchor.web3.PublicKey;
}; };
AggregatorLockEvent: {
feedPubkey: anchor.web3.PublicKey; export type AggregatorLockEvent = {
}; feedPubkey: anchor.web3.PublicKey;
AggregatorInitEvent: { };
feedPubkey: anchor.web3.PublicKey;
}; export type AggregatorInitEvent = {
AggregatorSetAuthorityEvent: { feedPubkey: anchor.web3.PublicKey;
feedPubkey: anchor.web3.PublicKey; };
oldAuthority: anchor.web3.PublicKey;
newAuthority: anchor.web3.PublicKey; export type AggregatorSetAuthorityEvent = {
}; feedPubkey: anchor.web3.PublicKey;
AggregatorSetConfigsEvent: { oldAuthority: anchor.web3.PublicKey;
feedPubkey: anchor.web3.PublicKey; newAuthority: anchor.web3.PublicKey;
}; };
PermissionSetEvent: {
permissionKey: anchor.web3.PublicKey; export type AggregatorSetConfigsEvent = {
permission: types.SwitchboardPermissionKind; feedPubkey: anchor.web3.PublicKey;
enable: boolean; };
};
VrfRequestRandomnessEvent: { export type PermissionSetEvent = {
vrfPubkey: anchor.web3.PublicKey; permissionKey: anchor.web3.PublicKey;
oraclePubkeys: anchor.web3.PublicKey[]; permission: types.SwitchboardPermissionKind;
loadAmount: anchor.BN; enable: boolean;
existingAmount: anchor.BN; };
};
VrfRequestEvent: { export type VrfRequestRandomnessEvent = {
vrfPubkey: anchor.web3.PublicKey; vrfPubkey: anchor.web3.PublicKey;
oraclePubkeys: anchor.web3.PublicKey[]; oraclePubkeys: anchor.web3.PublicKey[];
}; loadAmount: anchor.BN;
VrfProveEvent: { existingAmount: anchor.BN;
vrfPubkey: anchor.web3.PublicKey; };
oraclePubkey: anchor.web3.PublicKey;
authorityPubkey: anchor.web3.PublicKey; export type VrfRequestEvent = {
}; vrfPubkey: anchor.web3.PublicKey;
VrfVerifyEvent: { oraclePubkeys: anchor.web3.PublicKey[];
vrfPubkey: anchor.web3.PublicKey; };
oraclePubkey: anchor.web3.PublicKey;
authorityPubkey: anchor.web3.PublicKey; export type VrfProveEvent = {
amount: anchor.BN; vrfPubkey: anchor.web3.PublicKey;
}; oraclePubkey: anchor.web3.PublicKey;
VrfCallbackPerformedEvent: { authorityPubkey: anchor.web3.PublicKey;
vrfPubkey: anchor.web3.PublicKey; };
oraclePubkey: anchor.web3.PublicKey;
amount: anchor.BN; export type VrfVerifyEvent = {
}; vrfPubkey: anchor.web3.PublicKey;
AggregatorOpenRoundEvent: { oraclePubkey: anchor.web3.PublicKey;
feedPubkey: anchor.web3.PublicKey; authorityPubkey: anchor.web3.PublicKey;
oraclePubkeys: anchor.web3.PublicKey[]; amount: anchor.BN;
jobPubkeys: anchor.web3.PublicKey[]; };
remainingFunds: anchor.BN;
queueAuthority: anchor.web3.PublicKey; export type VrfCallbackPerformedEvent = {
}; vrfPubkey: anchor.web3.PublicKey;
AggregatorValueUpdateEvent: { oraclePubkey: anchor.web3.PublicKey;
feedPubkey: anchor.web3.PublicKey; amount: anchor.BN;
value: types.SwitchboardDecimalFields; };
slot: anchor.BN;
timestamp: anchor.BN; export type AggregatorOpenRoundEvent = {
oraclePubkeys: anchor.web3.PublicKey[]; feedPubkey: anchor.web3.PublicKey;
oracleValues: types.SwitchboardDecimalFields[]; oraclePubkeys: anchor.web3.PublicKey[];
}; jobPubkeys: anchor.web3.PublicKey[];
OracleRewardEvent: { remainingFunds: anchor.BN;
feedPubkey: anchor.web3.PublicKey; queueAuthority: anchor.web3.PublicKey;
leasePubkey: anchor.web3.PublicKey; };
oraclePubkey: anchor.web3.PublicKey;
walletPubkey: anchor.web3.PublicKey; export type AggregatorValueUpdateEvent = {
amount: anchor.BN; feedPubkey: anchor.web3.PublicKey;
roundSlot: anchor.BN; value: types.SwitchboardDecimalFields;
timestamp: anchor.BN; slot: anchor.BN;
}; timestamp: anchor.BN;
OracleWithdrawEvent: { oraclePubkeys: anchor.web3.PublicKey[];
oraclePubkey: anchor.web3.PublicKey; oracleValues: types.SwitchboardDecimalFields[];
walletPubkey: anchor.web3.PublicKey; };
destinationWallet: anchor.web3.PublicKey;
previousAmount: anchor.BN; export type OracleRewardEvent = {
newAmount: anchor.BN; feedPubkey: anchor.web3.PublicKey;
timestamp: anchor.BN; leasePubkey: anchor.web3.PublicKey;
}; oraclePubkey: anchor.web3.PublicKey;
LeaseWithdrawEvent: { walletPubkey: anchor.web3.PublicKey;
leasePubkey: anchor.web3.PublicKey; amount: anchor.BN;
walletPubkey: anchor.web3.PublicKey; roundSlot: anchor.BN;
previousAmount: anchor.BN; timestamp: anchor.BN;
newAmount: anchor.BN; };
timestamp: anchor.BN;
}; export type OracleWithdrawEvent = {
OracleSlashEvent: { oraclePubkey: anchor.web3.PublicKey;
feedPubkey: anchor.web3.PublicKey; walletPubkey: anchor.web3.PublicKey;
leasePubkey: anchor.web3.PublicKey; destinationWallet: anchor.web3.PublicKey;
oraclePubkey: anchor.web3.PublicKey; previousAmount: anchor.BN;
walletPubkey: anchor.web3.PublicKey; newAmount: anchor.BN;
amount: anchor.BN; timestamp: anchor.BN;
roundSlot: anchor.BN; };
timestamp: anchor.BN;
}; export type LeaseWithdrawEvent = {
LeaseFundEvent: { leasePubkey: anchor.web3.PublicKey;
leasePubkey: anchor.web3.PublicKey; walletPubkey: anchor.web3.PublicKey;
funder: anchor.web3.PublicKey; previousAmount: anchor.BN;
amount: anchor.BN; newAmount: anchor.BN;
timestamp: anchor.BN; timestamp: anchor.BN;
}; };
ProbationBrokenEvent: {
feedPubkey: anchor.web3.PublicKey; export type OracleSlashEvent = {
queuePubkey: anchor.web3.PublicKey; feedPubkey: anchor.web3.PublicKey;
timestamp: anchor.BN; leasePubkey: anchor.web3.PublicKey;
}; oraclePubkey: anchor.web3.PublicKey;
FeedPermissionRevokedEvent: { walletPubkey: anchor.web3.PublicKey;
feedPubkey: anchor.web3.PublicKey; amount: anchor.BN;
timestamp: anchor.BN; roundSlot: anchor.BN;
}; timestamp: anchor.BN;
GarbageCollectFailureEvent: { };
queuePubkey: anchor.web3.PublicKey;
}; export type LeaseFundEvent = {
OracleBootedEvent: { leasePubkey: anchor.web3.PublicKey;
queuePubkey: anchor.web3.PublicKey; funder: anchor.web3.PublicKey;
oraclePubkey: anchor.web3.PublicKey; amount: anchor.BN;
}; timestamp: anchor.BN;
AggregatorCrankEvictionEvent: {}; };
CrankLeaseInsufficientFundsEvent: {
feedPubkey: anchor.web3.PublicKey; export type ProbationBrokenEvent = {
leasePubkey: anchor.web3.PublicKey; feedPubkey: anchor.web3.PublicKey;
}; queuePubkey: anchor.web3.PublicKey;
CrankPopExpectedFailureEvent: { timestamp: anchor.BN;
feedPubkey: anchor.web3.PublicKey; };
leasePubkey: anchor.web3.PublicKey;
}; export type FeedPermissionRevokedEvent = {
BufferRelayerOpenRoundEvent: { feedPubkey: anchor.web3.PublicKey;
relayerPubkey: anchor.web3.PublicKey; timestamp: anchor.BN;
jobPubkey: anchor.web3.PublicKey; };
oraclePubkeys: anchor.web3.PublicKey[];
remainingFunds: anchor.BN; export type GarbageCollectFailureEvent = {
queue: anchor.web3.PublicKey; queuePubkey: anchor.web3.PublicKey;
}; };
export type OracleBootedEvent = {
queuePubkey: anchor.web3.PublicKey;
oraclePubkey: anchor.web3.PublicKey;
};
export type CrankLeaseInsufficientFundsEvent = {
feedPubkey: anchor.web3.PublicKey;
leasePubkey: anchor.web3.PublicKey;
};
export type CrankPopExpectedFailureEvent = {
feedPubkey: anchor.web3.PublicKey;
leasePubkey: anchor.web3.PublicKey;
};
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], data: SwitchboardEvents[EventName],
slot: number, slot: number,
signature: string signature: string
) => void ) => void | Promise<void>
): number { ): number {
return this._program.addEventListener(eventName as string, callback); return this._program.addEventListener(eventName as string, callback);
} }

View File

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