Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift committed Nov 11, 2023
1 parent 36dff4b commit 6cc7dc4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
13 changes: 11 additions & 2 deletions src/state/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import type { BigNumber } from 'ethers';
import { produce, type Draft } from 'immer';

import type { Config } from '../config/schema';
import type { DapiName, PrivateKey, DecodedDataFeed, ChainId, SignedData, DataFeedId, ProviderName } from '../types';
import type {
DapiName,
PrivateKey,
DecodedDataFeed,
ChainId,
SignedData,
DataFeedId,
ProviderName,
SignedApiUrl,
} from '../types';

interface GasState {
gasPrices: { price: BigNumber; timestampMs: number }[];
Expand Down Expand Up @@ -32,7 +41,7 @@ export interface State {
gasPriceStore: Record<string, Record<string, GasState>>;
derivedSponsorWallets: Record<DapiName, PrivateKey>;
signedApiStore: Record<DataFeedId, SignedData>;
signedApiUrlStore: Record<ChainId, Record<ProviderName, string[]>>;
signedApiUrlStore: Record<ChainId, Record<ProviderName, SignedApiUrl[]>>;
dapis: Record<DapiName, DapiState>;
}

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type PrivateKey = string;
export type DataFeedId = EvmId;
export type ChainId = string;
export type ProviderName = string;
export type SignedApiUrl = string;

// Taken from https://github.com/api3dao/signed-api/blob/main/packages/api/src/schema.ts
export const signedDataSchema = z.object({
Expand Down
20 changes: 12 additions & 8 deletions src/update-feeds/update-feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ export const getFeedsToUpdate = (batch: ReadDapiWithIndexResponse[]): Updateable
})
.filter((updateableDapi): updateableDapi is UpdateableDapi => updateableDapi !== null);

export const processBatch = async (batch: ReadDapiWithIndexResponse[], providerName: ProviderName, chainId: string) => {
export const processBatch = async (
batch: ReadDapiWithIndexResponse[],
providerName: ProviderName,
chainId: ChainId
) => {
logger.debug('Processing batch of active dAPIs', { batch });
const {
config: { sponsorWalletMnemonic, chains },
Expand Down Expand Up @@ -221,13 +225,13 @@ export const processBatch = async (batch: ReadDapiWithIndexResponse[], providerN

// Clear last update timestamps for feeds that don't need an update
for (const feed of batch) {
if (dapiNamesToUpdate.has(feed.dapiName)) continue;

clearSponsorLastUpdateTimestampMs(
chainId,
providerName,
getDerivedSponsorWallet(sponsorWalletMnemonic, feed.dapiName).address
);
if (!dapiNamesToUpdate.has(feed.dapiName)) {
clearSponsorLastUpdateTimestampMs(
chainId,
providerName,
getDerivedSponsorWallet(sponsorWalletMnemonic, feed.dapiName).address
);
}
}

const updatedFeeds = await updateFeeds(
Expand Down

0 comments on commit 6cc7dc4

Please sign in to comment.