index.d.ts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import type { components } from "./serverTypes";
  2. import { ClientOptions as FetchClientOptions } from "openapi-fetch";
  3. import { Address, Hex } from "viem";
  4. import WebSocket from "isomorphic-ws";
  5. import { Bid, BidId, BidParams, BidsResponse, BidStatusUpdate, BidSvm, ExpressRelaySvmConfig, Opportunity, OpportunityBid, OpportunityEvm, OpportunityCreate, TokenAmount } from "./types";
  6. import { Connection, PublicKey, Transaction, TransactionInstruction } from "@solana/web3.js";
  7. import * as anchor from "@coral-xyz/anchor";
  8. export * from "./types";
  9. export * from "./const";
  10. export declare class ClientError extends Error {
  11. }
  12. type ClientOptions = FetchClientOptions & {
  13. baseUrl: string;
  14. apiKey?: string;
  15. };
  16. export interface WsOptions {
  17. /**
  18. * Max time to wait for a response from the server in milliseconds
  19. */
  20. response_timeout: number;
  21. }
  22. export declare function checkHex(hex: string): Hex;
  23. export declare function checkAddress(address: string): Address;
  24. export declare function checkTokenQty(token: {
  25. token: string;
  26. amount: string;
  27. }): TokenAmount;
  28. export declare class Client {
  29. clientOptions: ClientOptions;
  30. wsOptions: WsOptions;
  31. websocket?: WebSocket;
  32. idCounter: number;
  33. callbackRouter: Record<string, (response: components["schemas"]["ServerResultMessage"]) => void>;
  34. private websocketOpportunityCallback?;
  35. private websocketBidStatusCallback?;
  36. private getAuthorization;
  37. constructor(clientOptions: ClientOptions, wsOptions?: WsOptions, opportunityCallback?: (opportunity: Opportunity) => Promise<void>, bidStatusCallback?: (statusUpdate: BidStatusUpdate) => Promise<void>);
  38. private connectWebsocket;
  39. /**
  40. * Subscribes to the specified chains
  41. *
  42. * The opportunity handler will be called for opportunities on the specified chains
  43. * If the opportunity handler is not set, an error will be thrown
  44. * @param chains
  45. */
  46. subscribeChains(chains: string[]): Promise<void>;
  47. /**
  48. * Unsubscribes from the specified chains
  49. *
  50. * The opportunity handler will no longer be called for opportunities on the specified chains
  51. * @param chains
  52. */
  53. unsubscribeChains(chains: string[]): Promise<void>;
  54. requestViaWebsocket(msg: components["schemas"]["ClientMessage"]): Promise<components["schemas"]["APIResponse"] | null>;
  55. /**
  56. * Fetches opportunities
  57. * @param chainId Chain id to fetch opportunities for. e.g: sepolia
  58. * @returns List of opportunities
  59. */
  60. getOpportunities(chainId?: string): Promise<Opportunity[]>;
  61. /**
  62. * Submits an opportunity to be exposed to searchers
  63. * @param opportunity Opportunity to submit
  64. */
  65. submitOpportunity(opportunity: OpportunityCreate): Promise<void>;
  66. /**
  67. * Submits a raw bid for a permission key
  68. * @param bid
  69. * @param subscribeToUpdates If true, the client will subscribe to bid status updates via websocket and will call the bid status callback if set
  70. * @returns The id of the submitted bid, you can use this id to track the status of the bid
  71. */
  72. submitBid(bid: Bid, subscribeToUpdates?: boolean): Promise<BidId>;
  73. /**
  74. * Get bids for an api key
  75. * @param fromTime The datetime to fetch bids from. If undefined or null, fetches from the beginning of time.
  76. * @returns The paginated bids response
  77. */
  78. getBids(fromTime?: Date): Promise<BidsResponse>;
  79. private toServerBid;
  80. /**
  81. * Converts an opportunity from the server to the client format
  82. * Returns undefined if the opportunity version is not supported
  83. * @param opportunity
  84. * @returns Opportunity in the converted client format
  85. */
  86. convertOpportunity(opportunity: components["schemas"]["Opportunity"]): Opportunity | undefined;
  87. /**
  88. * Creates a signed opportunity bid for an opportunity
  89. * @param opportunity EVM Opportunity to bid on
  90. * @param bidParams Bid amount and valid until timestamp
  91. * @param privateKey Private key to sign the bid with
  92. * @returns Signed opportunity bid
  93. */
  94. signOpportunityBid(opportunity: OpportunityEvm, bidParams: BidParams, privateKey: Hex): Promise<OpportunityBid>;
  95. /**
  96. * Creates a signed bid for an EVM opportunity
  97. * @param opportunity EVM Opportunity to bid on
  98. * @param bidParams Bid amount, nonce, and deadline timestamp
  99. * @param privateKey Private key to sign the bid with
  100. * @returns Signed bid
  101. */
  102. signBid(opportunity: OpportunityEvm, bidParams: BidParams, privateKey: Hex): Promise<Bid>;
  103. /**
  104. * Creates a signature for the bid and opportunity
  105. * @param opportunity EVM Opportunity to bid on
  106. * @param bidParams Bid amount, nonce, and deadline timestamp
  107. * @param privateKey Private key to sign the bid with
  108. * @returns Signature for the bid and opportunity
  109. */
  110. getSignature(opportunity: OpportunityEvm, bidParams: BidParams, privateKey: Hex): Promise<`0x${string}`>;
  111. /**
  112. * Fetches the Express Relay SVM config necessary for bidding
  113. * @param chainId The id for the chain you want to fetch the config for
  114. * @param connection The connection to use for fetching the config
  115. */
  116. getExpressRelaySvmConfig(chainId: string, connection: Connection): Promise<ExpressRelaySvmConfig>;
  117. /**
  118. * Constructs a SubmitBid instruction, which can be added to a transaction to permission it on the given permission key
  119. * @param searcher The address of the searcher that is submitting the bid
  120. * @param router The identifying address of the router that the permission key is for
  121. * @param permissionKey The 32-byte permission key as an SVM PublicKey
  122. * @param bidAmount The amount of the bid in lamports
  123. * @param deadline The deadline for the bid in seconds since Unix epoch
  124. * @param chainId The chain ID as a string, e.g. "solana"
  125. * @param relayerSigner The address of the relayer that is submitting the bid
  126. * @param feeReceiverRelayer The fee collection address of the relayer
  127. * @returns The SubmitBid instruction
  128. */
  129. constructSubmitBidInstruction(searcher: PublicKey, router: PublicKey, permissionKey: PublicKey, bidAmount: anchor.BN, deadline: anchor.BN, chainId: string, relayerSigner: PublicKey, feeReceiverRelayer: PublicKey): Promise<TransactionInstruction>;
  130. /**
  131. * Constructs an SVM bid, by adding a SubmitBid instruction to a transaction
  132. * @param tx The transaction to add a SubmitBid instruction to. This transaction should already check for the appropriate permissions.
  133. * @param searcher The address of the searcher that is submitting the bid
  134. * @param router The identifying address of the router that the permission key is for
  135. * @param permissionKey The 32-byte permission key as an SVM PublicKey
  136. * @param bidAmount The amount of the bid in lamports
  137. * @param deadline The deadline for the bid in seconds since Unix epoch
  138. * @param chainId The chain ID as a string, e.g. "solana"
  139. * @param relayerSigner The address of the relayer that is submitting the bid
  140. * @param feeReceiverRelayer The fee collection address of the relayer
  141. * @returns The constructed SVM bid
  142. */
  143. constructSvmBid(tx: Transaction, searcher: PublicKey, router: PublicKey, permissionKey: PublicKey, bidAmount: anchor.BN, deadline: anchor.BN, chainId: string, relayerSigner: PublicKey, feeReceiverRelayer: PublicKey): Promise<BidSvm>;
  144. }
  145. //# sourceMappingURL=index.d.ts.map