@ravnexchange/sdk 0.1.3 → 0.1.5
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 +6 -6
- package/dist/client.js +8 -8
- package/dist/execute-and-track.d.ts +5 -5
- package/dist/execute-and-track.js +4 -4
- package/dist/polling.d.ts +1 -1
- package/dist/polling.js +1 -1
- package/dist/types.d.ts +6 -6
- package/dist/types.js +1 -1
- package/package.json +4 -2
package/dist/client.d.ts
CHANGED
|
@@ -13,18 +13,18 @@ export declare class RavnClient {
|
|
|
13
13
|
private readonly fetchImpl;
|
|
14
14
|
constructor(config?: RavnClientConfig);
|
|
15
15
|
private request;
|
|
16
|
-
/** POST /v1/quote
|
|
16
|
+
/** POST /v1/quote: omitting destinationAddress/refundAddress returns a preview-only quote (see QuoteDTO.executable). */
|
|
17
17
|
getQuote(params: GetQuoteParams): Promise<QuoteDTO>;
|
|
18
|
-
/** POST /v1/execute
|
|
18
|
+
/** POST /v1/execute: branch on the returned executionType (TRANSACTION / SIGNATURE / DEPOSIT). */
|
|
19
19
|
execute(params: ExecuteParams): Promise<ExecutionDTO>;
|
|
20
|
-
/** POST /v1/submit-signature
|
|
20
|
+
/** POST /v1/submit-signature: for SIGNATURE-type executions only. Returns the ref to poll getStatus with. */
|
|
21
21
|
submitSignature(params: SubmitSignatureParams): Promise<{
|
|
22
22
|
statusRef: string;
|
|
23
23
|
}>;
|
|
24
|
-
/** GET /v1/status
|
|
24
|
+
/** GET /v1/status: `ref` is the DEPOSIT address or the statusRef from submitSignature. */
|
|
25
25
|
getStatus(quoteToken: string, ref: string): Promise<StatusDTO>;
|
|
26
|
-
/** GET /v1/tokens
|
|
26
|
+
/** GET /v1/tokens: RAVN's listed token registry for one chain. Not a per-pair routability guarantee. */
|
|
27
27
|
getTokens(chainId: number): Promise<TokenDTO[]>;
|
|
28
|
-
/** GET /v1/chains
|
|
28
|
+
/** GET /v1/chains: every chain RAVN lists tokens for. Static; safe to cache client-side. */
|
|
29
29
|
getChains(): Promise<ChainDTO[]>;
|
|
30
30
|
}
|
package/dist/client.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RavnClient = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
|
-
// ravn.exchange is the marketing site (separate deployment, no /api/* routes at all)
|
|
5
|
+
// ravn.exchange is the marketing site (separate deployment, no /api/* routes at all); the
|
|
6
6
|
// actual app, including this API, is served from the app subdomain. A caller that omits
|
|
7
7
|
// baseUrl entirely was 404ing on every single call until this fix.
|
|
8
8
|
const DEFAULT_BASE_URL = "https://app.ravn.exchange/api/v1";
|
|
@@ -27,7 +27,7 @@ class RavnClient {
|
|
|
27
27
|
}
|
|
28
28
|
catch {
|
|
29
29
|
// A non-JSON body (an intermediary's HTML error page, an empty 204/502/504) must still
|
|
30
|
-
// surface as the one error type this client promises
|
|
30
|
+
// surface as the one error type this client promises, never a raw SyntaxError.
|
|
31
31
|
throw new types_1.RavnApiError("INTERNAL", `HTTP ${res.status}: response was not valid JSON`, undefined, undefined);
|
|
32
32
|
}
|
|
33
33
|
if (!res.ok || body.error) {
|
|
@@ -36,32 +36,32 @@ class RavnClient {
|
|
|
36
36
|
}
|
|
37
37
|
return body.data;
|
|
38
38
|
}
|
|
39
|
-
/** POST /v1/quote
|
|
39
|
+
/** POST /v1/quote: omitting destinationAddress/refundAddress returns a preview-only quote (see QuoteDTO.executable). */
|
|
40
40
|
getQuote(params) {
|
|
41
41
|
return this.request("/quote", { method: "POST", body: JSON.stringify(params) });
|
|
42
42
|
}
|
|
43
|
-
/** POST /v1/execute
|
|
43
|
+
/** POST /v1/execute: branch on the returned executionType (TRANSACTION / SIGNATURE / DEPOSIT). */
|
|
44
44
|
execute(params) {
|
|
45
45
|
return this.request("/execute", { method: "POST", body: JSON.stringify(params) });
|
|
46
46
|
}
|
|
47
|
-
/** POST /v1/submit-signature
|
|
47
|
+
/** POST /v1/submit-signature: for SIGNATURE-type executions only. Returns the ref to poll getStatus with. */
|
|
48
48
|
submitSignature(params) {
|
|
49
49
|
return this.request("/submit-signature", {
|
|
50
50
|
method: "POST",
|
|
51
51
|
body: JSON.stringify(params),
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
|
-
/** GET /v1/status
|
|
54
|
+
/** GET /v1/status: `ref` is the DEPOSIT address or the statusRef from submitSignature. */
|
|
55
55
|
getStatus(quoteToken, ref) {
|
|
56
56
|
const qs = new URLSearchParams({ quoteToken, ref }).toString();
|
|
57
57
|
return this.request(`/status?${qs}`, { method: "GET" });
|
|
58
58
|
}
|
|
59
|
-
/** GET /v1/tokens
|
|
59
|
+
/** GET /v1/tokens: RAVN's listed token registry for one chain. Not a per-pair routability guarantee. */
|
|
60
60
|
getTokens(chainId) {
|
|
61
61
|
const qs = new URLSearchParams({ chainId: String(chainId) }).toString();
|
|
62
62
|
return this.request(`/tokens?${qs}`, { method: "GET" });
|
|
63
63
|
}
|
|
64
|
-
/** GET /v1/chains
|
|
64
|
+
/** GET /v1/chains: every chain RAVN lists tokens for. Static; safe to cache client-side. */
|
|
65
65
|
getChains() {
|
|
66
66
|
return this.request("/chains", { method: "GET" });
|
|
67
67
|
}
|
|
@@ -12,17 +12,17 @@ export interface ExecuteAndTrackHandlers {
|
|
|
12
12
|
sendTransaction(tx: TxLike): Promise<string>;
|
|
13
13
|
/**
|
|
14
14
|
* Wait for a transaction hash to confirm. Called on the approval before the main tx is ever
|
|
15
|
-
* sent
|
|
15
|
+
* sent: sending both back-to-back races the allowance and is the most common integration bug
|
|
16
16
|
* this helper exists to prevent.
|
|
17
17
|
*/
|
|
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
21
|
/**
|
|
22
|
-
* The API sends `approval` whenever the venue generically needs an allowance
|
|
22
|
+
* The API sends `approval` whenever the venue generically needs an allowance: it deliberately
|
|
23
23
|
* never reads the chain to check whether the caller already has one (that's an RPC round-trip
|
|
24
24
|
* on every execute). Without this handler, that approval tx is sent unconditionally, even when
|
|
25
|
-
* unnecessary
|
|
25
|
+
* unnecessary: the caller pays gas for a redundant approve on every swap of the same
|
|
26
26
|
* token/spender. Supply this (an allowance read against your own RPC) to skip it when already
|
|
27
27
|
* sufficient, same as the first-party app's own ensureErc20Allowance does.
|
|
28
28
|
*/
|
|
@@ -37,7 +37,7 @@ export interface ExecuteAndTrackResult {
|
|
|
37
37
|
execution: ExecutionDTO;
|
|
38
38
|
approvalTxHash?: string;
|
|
39
39
|
txHash?: string;
|
|
40
|
-
/** Pass to client.getStatus(quoteToken, ref)
|
|
40
|
+
/** Pass to client.getStatus(quoteToken, ref): same value as txHash for TRANSACTION. */
|
|
41
41
|
statusRef?: string;
|
|
42
42
|
/** Set once pollUntilTerminal reaches a terminal status. Absent for DEPOSIT (see below) or when polling is turned off. */
|
|
43
43
|
finalStatus?: StatusDTO;
|
|
@@ -45,7 +45,7 @@ export interface ExecuteAndTrackResult {
|
|
|
45
45
|
/**
|
|
46
46
|
* Sequences execute() → approval (if any) → wait for its receipt → main tx/signature → status
|
|
47
47
|
* polling, using caller-supplied signing/sending functions. The SDK stays wallet-agnostic (no
|
|
48
|
-
* RPC dependency)
|
|
48
|
+
* RPC dependency); this just gets the ORDER right, which quickstart's own docs flag as the
|
|
49
49
|
* most common integration failure: sending the main tx before the approval has confirmed.
|
|
50
50
|
*/
|
|
51
51
|
export declare function executeAndTrack(client: RavnClient, params: ExecuteParams, handlers: ExecuteAndTrackHandlers, options?: ExecuteAndTrackOptions): Promise<ExecuteAndTrackResult>;
|
|
@@ -5,7 +5,7 @@ const polling_1 = require("./polling");
|
|
|
5
5
|
/**
|
|
6
6
|
* Sequences execute() → approval (if any) → wait for its receipt → main tx/signature → status
|
|
7
7
|
* polling, using caller-supplied signing/sending functions. The SDK stays wallet-agnostic (no
|
|
8
|
-
* RPC dependency)
|
|
8
|
+
* RPC dependency); this just gets the ORDER right, which quickstart's own docs flag as the
|
|
9
9
|
* most common integration failure: sending the main tx before the approval has confirmed.
|
|
10
10
|
*/
|
|
11
11
|
async function executeAndTrack(client, params, handlers, options = {}) {
|
|
@@ -21,7 +21,7 @@ async function executeAndTrack(client, params, handlers, options = {}) {
|
|
|
21
21
|
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
-
// Sends and confirms an approval unless the caller already knows it's covered
|
|
24
|
+
// Sends and confirms an approval unless the caller already knows it's covered; see
|
|
25
25
|
// ExecuteAndTrackHandlers.hasAllowance's doc comment for why the API can't decide this itself.
|
|
26
26
|
const maybeSendApproval = async (approval) => {
|
|
27
27
|
if (!approval)
|
|
@@ -46,7 +46,7 @@ async function executeAndTrack(client, params, handlers, options = {}) {
|
|
|
46
46
|
}
|
|
47
47
|
// A signed order isn't allowance-free: CoW's vault relayer and Bebop/0x's Permit2 still pull
|
|
48
48
|
// the sell token with transferFrom, so this on-chain allowance (separate from approvalData's
|
|
49
|
-
// gasless per-trade signature) must be confirmed before signing
|
|
49
|
+
// gasless per-trade signature) must be confirmed before signing, otherwise the order is
|
|
50
50
|
// accepted and simply never fills, with no error to explain why.
|
|
51
51
|
const approvalTxHash = await maybeSendApproval(execution.approval);
|
|
52
52
|
let approvalSignature;
|
|
@@ -57,7 +57,7 @@ async function executeAndTrack(client, params, handlers, options = {}) {
|
|
|
57
57
|
const { statusRef } = await client.submitSignature({ quoteToken: params.quoteToken, signature, approvalSignature });
|
|
58
58
|
return { execution, approvalTxHash, statusRef, finalStatus: await pollStatus(statusRef) };
|
|
59
59
|
}
|
|
60
|
-
// DEPOSIT: nothing to sign or send from here
|
|
60
|
+
// DEPOSIT: nothing to sign or send from here; the user moves funds to execution.deposit.address
|
|
61
61
|
// out-of-band, and this helper has no way to know when that happens. Returned without polling;
|
|
62
62
|
// start polling yourself (getStatus / useRavnStatus) once the deposit is actually sent.
|
|
63
63
|
return { execution, statusRef: execution.statusRef };
|
package/dist/polling.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SettlementStatus } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Whether a status is done changing. "unknown" counts as terminal even though it isn't a real
|
|
4
|
-
* outcome
|
|
4
|
+
* outcome: it means the venue has no live tracker (see StatusDTO.tracking), so it will never
|
|
5
5
|
* change and polling forever would just spin. Only "pending"/"processing" keep polling.
|
|
6
6
|
*/
|
|
7
7
|
export declare function isPollingTerminal(status: SettlementStatus): boolean;
|
package/dist/polling.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isPollingTerminal = isPollingTerminal;
|
|
4
4
|
/**
|
|
5
5
|
* Whether a status is done changing. "unknown" counts as terminal even though it isn't a real
|
|
6
|
-
* outcome
|
|
6
|
+
* outcome: it means the venue has no live tracker (see StatusDTO.tracking), so it will never
|
|
7
7
|
* change and polling forever would just spin. Only "pending"/"processing" keep polling.
|
|
8
8
|
*/
|
|
9
9
|
function isPollingTerminal(status) {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Wire types for RAVN's public /api/v1 surface. Deliberately a standalone mirror of
|
|
3
|
-
* src/lib/api/v1/dto.ts's public DTOs, not an import from it
|
|
3
|
+
* src/lib/api/v1/dto.ts's public DTOs, not an import from it: this package ships to npm on
|
|
4
4
|
* its own and can't depend on the app's internal source tree. Keep these two in sync by hand
|
|
5
5
|
* when the API's public contract changes; that file's own comment already promises the shape
|
|
6
6
|
* is frozen for third parties, so drift should be rare.
|
|
@@ -15,7 +15,7 @@ export interface TokenDTO {
|
|
|
15
15
|
logoUrl?: string;
|
|
16
16
|
}
|
|
17
17
|
export interface QuoteDTO {
|
|
18
|
-
/** Opaque handle
|
|
18
|
+
/** Opaque handle: pass back to execute() verbatim. Do not parse. */
|
|
19
19
|
quoteToken: string;
|
|
20
20
|
venue: {
|
|
21
21
|
id: string;
|
|
@@ -31,14 +31,14 @@ export interface QuoteDTO {
|
|
|
31
31
|
amount: string;
|
|
32
32
|
};
|
|
33
33
|
/** `supported: false` means the venue has no fee mechanism at all (bps will be 0 either
|
|
34
|
-
* way)
|
|
34
|
+
* way); distinct from `supported: true, bps: 0`, a real, intentional zero fee. */
|
|
35
35
|
fee: {
|
|
36
36
|
bps: number;
|
|
37
37
|
amount: string;
|
|
38
38
|
token: TokenDTO;
|
|
39
39
|
supported: boolean;
|
|
40
40
|
};
|
|
41
|
-
/** False means this is a preview-only price
|
|
41
|
+
/** False means this is a preview-only price; see RavnClient.getQuote's destinationAddress note. */
|
|
42
42
|
executable: boolean;
|
|
43
43
|
slippage: {
|
|
44
44
|
bps: number;
|
|
@@ -146,12 +146,12 @@ export interface GetQuoteParams {
|
|
|
146
146
|
/** Positive integer string, in the token's smallest unit (no decimals). */
|
|
147
147
|
inputAmount: string;
|
|
148
148
|
userAddress: string;
|
|
149
|
-
/** Omitting this yields a preview-only quote
|
|
149
|
+
/** Omitting this yields a preview-only quote; see QuoteDTO.executable. */
|
|
150
150
|
destinationAddress?: string;
|
|
151
151
|
refundAddress?: string;
|
|
152
152
|
slippageBps?: number;
|
|
153
153
|
rankingMode?: "best_output" | "fastest";
|
|
154
|
-
/** Drop specific venues from this race
|
|
154
|
+
/** Drop specific venues from this race, e.g. a risk objection to one of them. */
|
|
155
155
|
excludeVenues?: string[];
|
|
156
156
|
/** Test quote -> execute -> status with no real funds and no live venue settlement. See
|
|
157
157
|
* the API's own sandbox field description for per-venue/per-route exceptions. */
|
package/dist/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Wire types for RAVN's public /api/v1 surface. Deliberately a standalone mirror of
|
|
4
|
-
* src/lib/api/v1/dto.ts's public DTOs, not an import from it
|
|
4
|
+
* src/lib/api/v1/dto.ts's public DTOs, not an import from it: this package ships to npm on
|
|
5
5
|
* its own and can't depend on the app's internal source tree. Keep these two in sync by hand
|
|
6
6
|
* when the API's public contract changes; that file's own comment already promises the shape
|
|
7
7
|
* is frozen for third parties, so drift should be rare.
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ravnexchange/sdk",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Typed client for the RAVN integrator API (/api/v1)
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "Typed client for the RAVN integrator API (/api/v1): quote, execute, submit-signature, status.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"files": ["dist"],
|
|
8
8
|
"license": "MIT",
|
|
9
|
+
"repository": { "type": "git", "url": "git+https://github.com/ravndex/ravn-sdk.git", "directory": "core" },
|
|
10
|
+
"homepage": "https://github.com/ravndex/ravn-sdk#readme",
|
|
9
11
|
"publishConfig": { "access": "public" },
|
|
10
12
|
"scripts": {
|
|
11
13
|
"build": "tsc -p tsconfig.build.json"
|