Skip to content

Commit 8e00eb5

Browse files
authored
only crank used oracles option (#356)
* only crank used oracles option * make pyth requirement a bit more safe
1 parent c6c6429 commit 8e00eb5

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

src/bots/pythCranker.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
DriftClient,
1818
getOracleClient,
1919
getPythPullOraclePublicKey,
20+
getVariant,
2021
isOneOfVariant,
2122
ONE,
2223
OracleClient,
@@ -132,13 +133,25 @@ export class PythCrankerBot implements Bot {
132133
.getPerpMarketAccounts()
133134
.map((market) => market.marketIndex);
134135
const perpMarketConfigs = PerpMarkets[this.globalConfig.driftEnv].filter(
135-
(market) => perpMarketIndexes.includes(market.marketIndex)
136+
(market) => {
137+
const oracleVariant = getVariant(market.oracleSource).toLowerCase();
138+
const useMarket = this.crankConfigs.onlyCrankUsedOracles
139+
? oracleVariant.includes('pyth') && !oracleVariant.includes('pull')
140+
: true;
141+
return perpMarketIndexes.includes(market.marketIndex) && useMarket;
142+
}
136143
);
137144
const spotMarketIndexes = this.driftClient
138145
.getSpotMarketAccounts()
139146
.map((market) => market.marketIndex);
140147
const spotMarketConfigs = SpotMarkets[this.globalConfig.driftEnv].filter(
141-
(market) => spotMarketIndexes.includes(market.marketIndex)
148+
(market) => {
149+
const oracleVariant = getVariant(market.oracleSource).toLowerCase();
150+
const useMarket = this.crankConfigs.onlyCrankUsedOracles
151+
? oracleVariant.includes('pyth') && !oracleVariant.includes('pull')
152+
: true;
153+
return spotMarketIndexes.includes(market.marketIndex) && useMarket;
154+
}
142155
);
143156

144157
for (const marketConfig of perpMarketConfigs) {

src/bots/pythLazerCranker.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
DevnetSpotMarkets,
99
DriftClient,
1010
getPythLazerOraclePublicKey,
11+
getVariant,
1112
MainnetPerpMarkets,
1213
MainnetSpotMarkets,
1314
PriorityFeeSubscriber,
@@ -53,13 +54,6 @@ export class PythLazerCrankerBot implements Bot {
5354
this.name = crankConfigs.botId;
5455
this.dryRun = crankConfigs.dryRun;
5556
this.intervalMs = crankConfigs.intervalMs;
56-
if (!globalConfig.hermesEndpoint) {
57-
throw new Error('Missing hermesEndpoint in global config');
58-
}
59-
60-
if (globalConfig.driftEnv != 'devnet') {
61-
throw new Error('Only devnet drift env is supported');
62-
}
6357

6458
const spotMarkets =
6559
this.globalConfig.driftEnv === 'mainnet-beta'
@@ -70,13 +64,18 @@ export class PythLazerCrankerBot implements Bot {
7064
? MainnetPerpMarkets
7165
: DevnetPerpMarkets;
7266

73-
const allFeedIds = [
74-
...spotMarkets.map((market) => market.pythLazerId),
75-
...perpMarkets.map((market) => market.pythLazerId),
76-
].filter((id) => id !== undefined) as number[];
67+
const allFeedIds: number[] = [];
68+
for (const market of [...spotMarkets, ...perpMarkets]) {
69+
if (
70+
(this.crankConfigs.onlyCrankUsedOracles &&
71+
!getVariant(market.oracleSource).toLowerCase().includes('lazer')) ||
72+
market.pythFeedId == undefined
73+
)
74+
continue;
75+
allFeedIds.push(market.pythLazerId!);
76+
}
7777
const allFeedIdsSet = new Set(allFeedIds);
7878
const feedIdChunks = chunks(Array.from(allFeedIdsSet), 11);
79-
8079
console.log(feedIdChunks);
8180

8281
if (!this.globalConfig.lazerEndpoint || !this.globalConfig.lazerToken) {

src/config.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,14 @@ export type PythCrankerBotConfig = BaseBotConfig & {
106106
earlyUpdate: PythUpdateConfigs;
107107
};
108108
};
109+
onlyCrankUsedOracles?: boolean;
109110
};
110111

111112
export type PythLazerCrankerBotConfig = BaseBotConfig & {
112113
slotStalenessThresholdRestart: number;
113114
txSuccessRateThreshold: number;
114115
intervalMs: number;
115-
updateConfigs: {
116-
[key: string]: {
117-
feedId: number;
118-
};
119-
};
116+
onlyCrankUsedOracles?: boolean;
120117
};
121118

122119
export type SwitchboardCrankerBotConfig = BaseBotConfig & {

0 commit comments

Comments
 (0)