@pythnetwork/express-relay-evm-js
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -16,8 +16,13 @@ "use strict"; | ||
privateKey; | ||
apiKey; | ||
client; | ||
constructor(endpoint, chainId, privateKey) { | ||
constructor(endpoint, chainId, privateKey, apiKey) { | ||
this.endpoint = endpoint; | ||
this.chainId = chainId; | ||
this.privateKey = privateKey; | ||
this.client = new index_1.Client({ baseUrl: endpoint }, undefined, this.opportunityHandler.bind(this), this.bidStatusHandler.bind(this)); | ||
this.apiKey = apiKey; | ||
this.client = new index_1.Client({ | ||
baseUrl: endpoint, | ||
apiKey, | ||
}, undefined, this.opportunityHandler.bind(this), this.bidStatusHandler.bind(this)); | ||
} | ||
@@ -88,2 +93,7 @@ async bidStatusHandler(bidStatus) { | ||
}) | ||
.option("api-key", { | ||
description: "The API key of the searcher to authenticate with the server for fetching and submitting bids", | ||
type: "string", | ||
demandOption: false, | ||
}) | ||
.help() | ||
@@ -100,5 +110,5 @@ .alias("help", "h") | ||
} | ||
const searcher = new SimpleSearcher(argv.endpoint, argv.chainId, argv.privateKey); | ||
const searcher = new SimpleSearcher(argv.endpoint, argv.chainId, argv.privateKey, argv.apiKey); | ||
await searcher.start(); | ||
} | ||
run(); |
@@ -5,3 +5,3 @@ import type { components } from "./serverTypes"; | ||
import WebSocket from "isomorphic-ws"; | ||
import { Bid, BidId, BidParams, BidStatusUpdate, Opportunity, OpportunityBid, OpportunityParams, TokenAmount } from "./types"; | ||
import { Bid, BidId, BidParams, BidStatusUpdate, Opportunity, OpportunityBid, OpportunityParams, TokenAmount, BidsResponse } from "./types"; | ||
export * from "./types"; | ||
@@ -12,2 +12,3 @@ export declare class ClientError extends Error { | ||
baseUrl: string; | ||
apiKey?: string; | ||
}; | ||
@@ -34,2 +35,3 @@ export interface WsOptions { | ||
private websocketBidStatusCallback?; | ||
private getAuthorization; | ||
constructor(clientOptions: ClientOptions, wsOptions?: WsOptions, opportunityCallback?: (opportunity: Opportunity) => Promise<void>, bidStatusCallback?: (statusUpdate: BidStatusUpdate) => Promise<void>); | ||
@@ -93,3 +95,9 @@ private connectWebsocket; | ||
submitBid(bid: Bid, subscribeToUpdates?: boolean): Promise<BidId>; | ||
/** | ||
* Get bids for an api key | ||
* @param fromTime The datetime to fetch bids from. If undefined or null, fetches from the beginning of time. | ||
* @returns The paginated bids response | ||
*/ | ||
getBids(fromTime?: Date): Promise<BidsResponse>; | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
@@ -61,4 +61,15 @@ "use strict"; | ||
websocketBidStatusCallback; | ||
getAuthorization() { | ||
return this.clientOptions.apiKey | ||
? { | ||
Authorization: `Bearer ${this.clientOptions.apiKey}`, | ||
} | ||
: {}; | ||
} | ||
constructor(clientOptions, wsOptions, opportunityCallback, bidStatusCallback) { | ||
this.clientOptions = clientOptions; | ||
this.clientOptions.headers = { | ||
...(this.clientOptions.headers ?? {}), | ||
...this.getAuthorization(), | ||
}; | ||
this.wsOptions = { ...DEFAULT_WS_OPTIONS, ...wsOptions }; | ||
@@ -73,3 +84,5 @@ this.websocketOpportunityCallback = opportunityCallback; | ||
websocketEndpoint.pathname = "/v1/ws"; | ||
this.websocket = new isomorphic_ws_1.default(websocketEndpoint.toString()); | ||
this.websocket = new isomorphic_ws_1.default(websocketEndpoint.toString(), { | ||
headers: this.getAuthorization(), | ||
}); | ||
this.websocket.on("message", async (data) => { | ||
@@ -396,3 +409,23 @@ const message = JSON.parse(data.toString()); | ||
} | ||
/** | ||
* Get bids for an api key | ||
* @param fromTime The datetime to fetch bids from. If undefined or null, fetches from the beginning of time. | ||
* @returns The paginated bids response | ||
*/ | ||
async getBids(fromTime) { | ||
const client = (0, openapi_fetch_1.default)(this.clientOptions); | ||
const response = await client.GET("/v1/bids", { | ||
params: { query: { from_time: fromTime?.toISOString() } }, | ||
}); | ||
if (response.error) { | ||
throw new ClientError(response.error.error); | ||
} | ||
else if (response.data === undefined) { | ||
throw new ClientError("No data returned"); | ||
} | ||
else { | ||
return response.data; | ||
} | ||
} | ||
} | ||
exports.Client = Client; |
@@ -147,2 +147,6 @@ import { Address, Hex } from "viem"; | ||
} & components["schemas"]["BidStatus"]; | ||
export type BidResponse = components["schemas"]["SimulatedBid"]; | ||
export type BidsResponse = { | ||
items: BidResponse[]; | ||
}; | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "@pythnetwork/express-relay-evm-js", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "Utilities for interacting with the express relay protocol", | ||
@@ -57,3 +57,3 @@ "homepage": "https://github.com/pyth-network/pyth-crosschain/tree/main/express_relay/sdk/js", | ||
"license": "Apache-2.0", | ||
"gitHead": "954fea65d6bcfaafc6817835209134e0c0099aa0" | ||
"gitHead": "f8ed6ddb220b816b00097a6a798efe262a6acc67" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37168
790