@ravnexchange/sdk 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ChainDTO, ExecuteParams, ExecutionDTO, GetQuoteParams, QuoteDTO, StatusDTO, SubmitSignatureParams, TokenDTO } from "./types";
1
+ import type { ChainDTO, ExecuteParams, ExecutionDTO, GetQuoteParams, QuoteDTO, StatusDTO, SubmitSignatureParams, SubmitTransactionParams, TokenDTO } from "./types";
2
2
  export interface RavnClientConfig {
3
3
  /** Self-serve or enterprise key. Omit for the anonymous tier (works immediately, lower rate limit). */
4
4
  apiKey?: string;
@@ -21,6 +21,12 @@ export declare class RavnClient {
21
21
  submitSignature(params: SubmitSignatureParams): Promise<{
22
22
  statusRef: string;
23
23
  }>;
24
+ /** POST /v1/submit-transaction: only for a TRANSACTION execution carrying `submit`
25
+ * (broadcastViaRavn quotes). RAVN checks the signed transaction, then sends it; refused, nothing
26
+ * is sent. Returns the Solana signature; poll getStatus with the execution's statusRef. */
27
+ submitTransaction(params: SubmitTransactionParams): Promise<{
28
+ txHash: string;
29
+ }>;
24
30
  /** POST /v1/status: pass the quoteToken execute() returned (not the quote's own), and as `ref`
25
31
  * the execution's statusRef, submitSignature's statusRef, or the origin tx hash. POST, not GET:
26
32
  * a 2-hop quoteToken in a query string can exceed header limits and fail with 431. */
package/dist/client.js CHANGED
@@ -51,6 +51,15 @@ class RavnClient {
51
51
  body: JSON.stringify(params),
52
52
  });
53
53
  }
54
+ /** POST /v1/submit-transaction: only for a TRANSACTION execution carrying `submit`
55
+ * (broadcastViaRavn quotes). RAVN checks the signed transaction, then sends it; refused, nothing
56
+ * is sent. Returns the Solana signature; poll getStatus with the execution's statusRef. */
57
+ submitTransaction(params) {
58
+ return this.request("/submit-transaction", {
59
+ method: "POST",
60
+ body: JSON.stringify(params),
61
+ });
62
+ }
54
63
  /** POST /v1/status: pass the quoteToken execute() returned (not the quote's own), and as `ref`
55
64
  * the execution's statusRef, submitSignature's statusRef, or the origin tx hash. POST, not GET:
56
65
  * a 2-hop quoteToken in a query string can exceed header limits and fail with 431. */
@@ -18,6 +18,11 @@ export interface ExecuteAndTrackHandlers {
18
18
  waitForReceipt(hash: string, chainId?: number): Promise<void>;
19
19
  /** Sign an EIP-712 typed-data payload. Only called for SIGNATURE executions. */
20
20
  signTypedData?(typedData: Record<string, unknown>): Promise<`0x${string}`>;
21
+ /**
22
+ * Sign (don't send) a base64 Solana transaction and return it signed, base64. Only called for a
23
+ * TRANSACTION carrying `submit` (broadcastViaRavn quotes), which RAVN checks and sends itself.
24
+ */
25
+ signSolanaTransaction?(serialized: string): Promise<string>;
21
26
  /**
22
27
  * The API sends `approval` whenever the venue generically needs an allowance: it deliberately
23
28
  * never reads the chain to check whether the caller already has one (that's an RPC round-trip
@@ -33,6 +33,20 @@ async function executeAndTrack(client, params, handlers, options = {}) {
33
33
  await handlers.waitForReceipt(hash, approval.chainId);
34
34
  return hash;
35
35
  };
36
+ if (execution.executionType === "TRANSACTION" && execution.submit) {
37
+ // Never broadcast this one ourselves: a payment Layerswap can't match sits at Layerswap, and
38
+ // RAVN's check before sending is what catches it.
39
+ if (!handlers.signSolanaTransaction) {
40
+ throw new Error("executeAndTrack: this execution must be submitted through RAVN and requires signSolanaTransaction, none was provided");
41
+ }
42
+ if (!execution.transaction.serialized) {
43
+ throw new Error("executeAndTrack: TRANSACTION execution with submit is missing transaction.serialized");
44
+ }
45
+ const signedTransaction = await handlers.signSolanaTransaction(execution.transaction.serialized);
46
+ const { txHash } = await client.submitTransaction({ quoteToken, signedTransaction });
47
+ const statusRef = execution.statusRef ?? txHash;
48
+ return { execution, quoteToken, txHash, statusRef, finalStatus: await pollStatus(statusRef) };
49
+ }
36
50
  if (execution.executionType === "TRANSACTION") {
37
51
  const approvalTxHash = await maybeSendApproval(execution.approval);
38
52
  const txHash = await handlers.sendTransaction(execution.transaction);
package/dist/types.d.ts CHANGED
@@ -52,6 +52,12 @@ export interface QuoteDTO {
52
52
  outputUsd: string | null;
53
53
  estimatedTimeSeconds: number;
54
54
  estimatedTimeIsGuess: boolean;
55
+ /** Epoch ms, always a real time: execute() on `quoteToken` before this, re-quote after. Never
56
+ * refused for age before it; past it most routes fail with QUOTE_EXPIRED. Already 5 s ahead of
57
+ * the venue's own deadline, so compare it to the clock as is. 2-hop routes
58
+ * (`venue.id === "compose"`) and venues with no deadline are never refused for age: it's 60 s
59
+ * from the response, when to re-quote. A 2-hop route re-prices at execute (BUILD_FAILED if the
60
+ * minimum shown can no longer be met). */
55
61
  expiresAt: number;
56
62
  /** Present on 2-hop (`venue.id === "compose"`) and Relay dest-call quotes. Sign hop 1; hop 2 is
57
63
  * a unique deposit, not a second wallet tx. */
@@ -82,6 +88,9 @@ export interface AlternativeQuoteDTO {
82
88
  executable: boolean;
83
89
  estimatedTimeSeconds: number;
84
90
  estimatedTimeIsGuess: boolean;
91
+ /** This route's own execute deadline, same meaning as QuoteDTO.expiresAt. Venues differ, so
92
+ * check it before executing an alternative. */
93
+ expiresAt: number;
85
94
  hops?: {
86
95
  id: string;
87
96
  name: string;
@@ -139,6 +148,12 @@ export type ExecutionDTO = {
139
148
  chainId?: number;
140
149
  serialized?: string;
141
150
  };
151
+ /** Only on quotes made with `broadcastViaRavn: true`. Don't broadcast this one: sign
152
+ * `transaction.serialized` and pass it to submitTransaction, which checks the signed
153
+ * transaction still pays Layerswap the way it matches deposits, then sends it. */
154
+ submit?: {
155
+ url: string;
156
+ };
142
157
  } | {
143
158
  executionType: "SIGNATURE";
144
159
  /** Pass this, not the quote's own token, to submitSignature and getStatus. */
@@ -205,6 +220,12 @@ export interface GetQuoteParams {
205
220
  /** Test quote -> execute -> status with no real funds and no live venue settlement. See
206
221
  * the API's own sandbox field description for per-venue/per-route exceptions. */
207
222
  sandbox?: boolean;
223
+ /** Set if you can post a signed Solana transaction back (submitTransaction) instead of
224
+ * broadcasting it yourself. Adds Layerswap's memo routes (Solana tokens into native BTC or
225
+ * Robinhood Chain stocks, no account rent), which only work when RAVN checks the signed
226
+ * transaction first: a TRANSACTION execution carrying `submit` must go through
227
+ * submitTransaction. executeAndTrack does this when given signSolanaTransaction. */
228
+ broadcastViaRavn?: boolean;
208
229
  }
209
230
  export interface ExecuteParams {
210
231
  quoteToken: string;
@@ -220,6 +241,12 @@ export interface SubmitSignatureParams {
220
241
  signature: `0x${string}`;
221
242
  approvalSignature?: `0x${string}`;
222
243
  }
244
+ export interface SubmitTransactionParams {
245
+ /** The quoteToken execute() returned with that transaction, not the quote's own. */
246
+ quoteToken: string;
247
+ /** `transaction.serialized` after your user's wallet signed it, base64. */
248
+ signedTransaction: string;
249
+ }
223
250
  export interface ErrorMeta {
224
251
  requestId: string;
225
252
  version: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ravnexchange/sdk",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Typed client for the RAVN integrator API (/api/v1): quote, execute, submit-signature, status.",
5
5
  "keywords": ["ravn", "cross-chain", "swap", "swap-api", "dex-aggregator", "bitcoin", "native-btc", "solana", "evm", "crypto", "defi", "typescript", "sdk", "api-client"],
6
6
  "main": "./dist/index.js",