Skip to content

Commit

Permalink
fix schema
Browse files Browse the repository at this point in the history
  • Loading branch information
keyvankhademi committed Sep 11, 2024
1 parent 1807030 commit c4d6989
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
9 changes: 7 additions & 2 deletions apps/hermes/client/js/src/HermesClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export type EncodingType = z.infer<typeof schemas.EncodingType>;
export type PriceFeedMetadata = z.infer<typeof schemas.PriceFeedMetadata>;
export type PriceIdInput = z.infer<typeof schemas.PriceIdInput>;
export type PriceUpdate = z.infer<typeof schemas.PriceUpdate>;
export type PublisherCaps = z.infer<typeof schemas.PublisherCaps>;
export type PublisherCaps = z.infer<
typeof schemas.LatestPublisherStakeCapsUpdateDataResponse
>;

const DEFAULT_TIMEOUT: DurationInMs = 5000;
const DEFAULT_HTTP_RETRIES = 3;
Expand Down Expand Up @@ -140,7 +142,10 @@ export class HermesClient {
if (options) {
this.appendUrlSearchParams(url, options);
}
return await this.httpRequest(url.toString(), schemas.PublisherCaps);
return await this.httpRequest(
url.toString(),
schemas.LatestPublisherStakeCapsUpdateDataResponse
);
}

/**
Expand Down
32 changes: 16 additions & 16 deletions apps/hermes/client/js/src/zodSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,18 @@ const PriceUpdate = z
parsed: z.array(ParsedPriceUpdate).nullish(),
})
.passthrough();
const ParsedPublisherCap = z.object({
publisher: z.string(),
cap: z.number().int(),
});

const PublisherCaps = z.object({
binary: BinaryUpdate,
parsed: z
.object({
publisher_stake_caps: z.array(ParsedPublisherCap),
})
.array()
.nullish(),
});
const ParsedPublisherStakeCap = z
.object({ cap: z.number().int().gte(0), publisher: z.string() })
.passthrough();
const ParsedPublisherStakeCapsUpdate = z
.object({ publisher_stake_caps: z.array(ParsedPublisherStakeCap) })
.passthrough();
const LatestPublisherStakeCapsUpdateDataResponse = z
.object({
binary: BinaryUpdate,
parsed: z.array(ParsedPublisherStakeCapsUpdate).nullish(),
})
.passthrough();

export const schemas = {
AssetType,
Expand All @@ -69,7 +67,9 @@ export const schemas = {
RpcPriceFeedMetadataV2,
ParsedPriceUpdate,
PriceUpdate,
PublisherCaps,
ParsedPublisherStakeCap,
ParsedPublisherStakeCapsUpdate,
LatestPublisherStakeCapsUpdateDataResponse,
};

const endpoints = makeApi([
Expand Down Expand Up @@ -229,7 +229,7 @@ Given a collection of price feed ids, retrieve the latest Pyth price for each pr
schema: z.boolean().optional(),
},
],
response: z.array(PublisherCaps),
response: LatestPublisherStakeCapsUpdateDataResponse,
},
]);

Expand Down

0 comments on commit c4d6989

Please sign in to comment.