@recta/client 0.1.10 → 0.1.11
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/README.md +5 -0
- package/dist/constants.d.ts +2 -2
- package/dist/constants.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/preflight.d.ts +28 -5
- package/dist/preflight.js +91 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,6 +64,11 @@ arrival time, and whether Recta proves a cheaper route (for example Base → Arb
|
|
|
64
64
|
LI.FI, measured on 2026-11-19). By default the bridge always runs, with the same arguments and the same result; a
|
|
65
65
|
failed or slow preflight (10 s at most) never blocks it. A transfer outside Recta's corridors is not checked.
|
|
66
66
|
|
|
67
|
+
A transfer you build yourself needs `source_network`, `source_asset`, `destination_network`, `destination_asset` and
|
|
68
|
+
`amount` (whole tokens; a string, a positive number or a bigint). From 0.1.11 a missing or unusable field throws
|
|
69
|
+
`PreflightInputError` before any request instead of sending an incomplete body, and without `onPreflight` the first
|
|
70
|
+
failed or refused preflight of each wrapped call is reported once with `console.warn` (`quiet: true` hides it).
|
|
71
|
+
|
|
67
72
|
LI.FI SDK:
|
|
68
73
|
|
|
69
74
|
```ts
|
package/dist/constants.d.ts
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const RECTA_ORIGIN = "https://api.recta.build";
|
|
9
9
|
/** This package's version (equal to package.json, checked in CI). */
|
|
10
|
-
export declare const CLIENT_VERSION = "0.1.
|
|
10
|
+
export declare const CLIENT_VERSION = "0.1.11";
|
|
11
11
|
/** Sent on every request so Recta can count real use of this package apart from other clients (no address, no key). */
|
|
12
|
-
export declare const USER_AGENT = "recta-client/0.1.
|
|
12
|
+
export declare const USER_AGENT = "recta-client/0.1.11";
|
|
13
13
|
/** The fee: x402 `upto` on Base, a Permit2 `permitWitnessTransferFrom`. All lowercase. */
|
|
14
14
|
export declare const FEE_CHAIN_ID = 8453;
|
|
15
15
|
export declare const PERMIT2 = "0x000000000022d473030f116ddee9f6b43ac78ba3";
|
package/dist/constants.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export const RECTA_ORIGIN = "https://api.recta.build";
|
|
9
9
|
/** This package's version (equal to package.json, checked in CI). */
|
|
10
|
-
export const CLIENT_VERSION = "0.1.
|
|
10
|
+
export const CLIENT_VERSION = "0.1.11";
|
|
11
11
|
/** Sent on every request so Recta can count real use of this package apart from other clients (no address, no key). */
|
|
12
12
|
export const USER_AGENT = `recta-client/${CLIENT_VERSION}`;
|
|
13
13
|
/** The fee: x402 `upto` on Base, a Permit2 `permitWitnessTransferFrom`. All lowercase. */
|
package/dist/index.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export { parseWalletPolicy, type WalletPolicy, type WalletPolicyNetwork } from "
|
|
|
7
7
|
export { viemSigner, viemChainReader, cdpSigner, smartAccountSigner, DEFAULT_USER_OPERATION_OVERHEAD_GAS, CDP_SEND_NETWORKS, type CdpEvmAccountLike, type CdpSendNetwork, type RectaSigner, type RectaChainReader, type RectaTransaction, type RectaTypedData } from "./signer.js";
|
|
8
8
|
export { RectaCheckError, RectaHttpError, RectaDebtError, RectaSendUnknownError } from "./errors.js";
|
|
9
9
|
export * as pins from "./constants.js";
|
|
10
|
-
export { preflight, withPreflight, withPreflightTool, preflightSummary, lifiTransfer, transferFromChainTokens, decimalAmount, RectaSavingFoundError, PREFLIGHT_PATH, PREFLIGHT_USER_AGENT, type PreflightTransfer, type PreflightAnswer, type PreflightOptions, type PreflightRouteEstimate, type WithPreflightOptions, type ChainTokenTransfer } from "./preflight.js";
|
|
10
|
+
export { preflight, withPreflight, withPreflightTool, preflightSummary, lifiTransfer, transferFromChainTokens, decimalAmount, RectaSavingFoundError, PreflightInputError, preflightBody, PREFLIGHT_PATH, PREFLIGHT_USER_AGENT, type PreflightTransfer, type PreflightAnswer, type PreflightOptions, type PreflightRouteEstimate, type WithPreflightOptions, type ChainTokenTransfer } from "./preflight.js";
|
package/dist/index.js
CHANGED
|
@@ -7,4 +7,4 @@ export { parseWalletPolicy } from "./policy.js";
|
|
|
7
7
|
export { viemSigner, viemChainReader, cdpSigner, smartAccountSigner, DEFAULT_USER_OPERATION_OVERHEAD_GAS, CDP_SEND_NETWORKS } from "./signer.js";
|
|
8
8
|
export { RectaCheckError, RectaHttpError, RectaDebtError, RectaSendUnknownError } from "./errors.js";
|
|
9
9
|
export * as pins from "./constants.js";
|
|
10
|
-
export { preflight, withPreflight, withPreflightTool, preflightSummary, lifiTransfer, transferFromChainTokens, decimalAmount, RectaSavingFoundError, PREFLIGHT_PATH, PREFLIGHT_USER_AGENT } from "./preflight.js";
|
|
10
|
+
export { preflight, withPreflight, withPreflightTool, preflightSummary, lifiTransfer, transferFromChainTokens, decimalAmount, RectaSavingFoundError, PreflightInputError, preflightBody, PREFLIGHT_PATH, PREFLIGHT_USER_AGENT } from "./preflight.js";
|
package/dist/preflight.d.ts
CHANGED
|
@@ -6,16 +6,17 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const PREFLIGHT_PATH = "/v1/preflight";
|
|
8
8
|
/** Sent on every preflight this package makes, so Recta can count use of the wrapper apart from other clients. */
|
|
9
|
-
export declare const PREFLIGHT_USER_AGENT = "recta-client/0.1.
|
|
9
|
+
export declare const PREFLIGHT_USER_AGENT = "recta-client/0.1.11 (preflight)";
|
|
10
10
|
export interface PreflightTransfer {
|
|
11
11
|
/** Network keys as Recta names them: base, arbitrum, ethereum, optimism, polygon… */
|
|
12
12
|
readonly source_network: string;
|
|
13
13
|
/** USDC, USDT… */
|
|
14
14
|
readonly source_asset: string;
|
|
15
15
|
readonly destination_network: string;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
/** USDC, USDT… (required by the preflight, even when it is the source asset). */
|
|
17
|
+
readonly destination_asset: string;
|
|
18
|
+
/** Whole tokens: "1000" (or 1000) with USDC is 1,000 USDC. */
|
|
19
|
+
readonly amount: string | number | bigint;
|
|
19
20
|
/** The route you would use (lifi, across, stargate_v2, cctp_v2_standard…). Absent: LI.FI, or Across where LI.FI does not apply. */
|
|
20
21
|
readonly baseline_provider?: string;
|
|
21
22
|
/** Your sending address, for the most exact figure. */
|
|
@@ -46,7 +47,27 @@ export interface PreflightOptions {
|
|
|
46
47
|
/** Give up after this long (default 10 000 ms). The bridge is never held longer than this. */
|
|
47
48
|
readonly timeoutMs?: number;
|
|
48
49
|
}
|
|
49
|
-
/**
|
|
50
|
+
/** Thrown by `preflight` before any request when the transfer lacks a needed field or holds a value it cannot send as given. */
|
|
51
|
+
export declare class PreflightInputError extends Error {
|
|
52
|
+
readonly missing: readonly string[];
|
|
53
|
+
readonly invalid: readonly string[];
|
|
54
|
+
constructor(missing: readonly string[], invalid?: readonly string[]);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* What one transfer becomes on the wire: strings as given (trimmed), positive finite numbers and bigints as their exact
|
|
58
|
+
* decimal text (amount: 1000 → "1000"), camelCase names under Recta's (sourceNetwork → source_network). `missing` and
|
|
59
|
+
* `invalid` say what keeps it from being sent; no value is ever replaced by a default or an example.
|
|
60
|
+
*/
|
|
61
|
+
export declare function preflightBody(transfer: PreflightTransfer | Readonly<Record<string, unknown>>): {
|
|
62
|
+
readonly body: Record<string, string>;
|
|
63
|
+
readonly missing: readonly string[];
|
|
64
|
+
readonly invalid: readonly string[];
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* One preflight. A transfer without the fields the preflight needs, or with a value it cannot send as given, throws
|
|
68
|
+
* PreflightInputError before any request; network failures, timeouts and non-JSON replies throw; a refusal
|
|
69
|
+
* (4xx/5xx JSON) is returned as is.
|
|
70
|
+
*/
|
|
50
71
|
export declare function preflight(transfer: PreflightTransfer, options?: PreflightOptions): Promise<PreflightAnswer>;
|
|
51
72
|
/** A decimal string of whole tokens from an atomic amount: ("1000000000", 6) → "1000". */
|
|
52
73
|
export declare function decimalAmount(atomic: string | bigint, decimals: number): string;
|
|
@@ -104,6 +125,8 @@ export interface WithPreflightOptions extends PreflightOptions {
|
|
|
104
125
|
* RectaSavingFoundError before the bridge is called, so the agent can choose Recta's route.
|
|
105
126
|
*/
|
|
106
127
|
readonly stopOnSaving?: boolean;
|
|
128
|
+
/** Without onPreflight, the first refused or failed preflight is reported once with console.warn; true hides it. */
|
|
129
|
+
readonly quiet?: boolean;
|
|
107
130
|
}
|
|
108
131
|
/**
|
|
109
132
|
* `bridge` with Recta Preflight in front: each call first asks the preflight about the transfer `toTransfer` reads
|
package/dist/preflight.js
CHANGED
|
@@ -9,12 +9,83 @@ import { PINNED_ROUTES } from "./pinned-routes.js";
|
|
|
9
9
|
export const PREFLIGHT_PATH = "/v1/preflight";
|
|
10
10
|
/** Sent on every preflight this package makes, so Recta can count use of the wrapper apart from other clients. */
|
|
11
11
|
export const PREFLIGHT_USER_AGENT = `recta-client/${CLIENT_VERSION} (preflight)`;
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const REQUIRED_FIELDS = ["source_network", "source_asset", "destination_network", "destination_asset", "amount"];
|
|
13
|
+
const FIELD_ALIASES = {
|
|
14
|
+
sourceNetwork: "source_network",
|
|
15
|
+
sourceAsset: "source_asset",
|
|
16
|
+
destinationNetwork: "destination_network",
|
|
17
|
+
destinationAsset: "destination_asset",
|
|
18
|
+
baselineProvider: "baseline_provider",
|
|
19
|
+
};
|
|
20
|
+
/** Thrown by `preflight` before any request when the transfer lacks a needed field or holds a value it cannot send as given. */
|
|
21
|
+
export class PreflightInputError extends Error {
|
|
22
|
+
missing;
|
|
23
|
+
invalid;
|
|
24
|
+
constructor(missing, invalid = []) {
|
|
25
|
+
const parts = [
|
|
26
|
+
...(missing.length > 0 ? [`needs ${missing.join(", ")}`] : []),
|
|
27
|
+
...(invalid.length > 0 ? [`cannot send ${invalid.join("; ")}`] : []),
|
|
28
|
+
];
|
|
29
|
+
super(`Recta Preflight ${parts.join(" and ")}. Pass { source_network: "base", source_asset: "USDC", destination_network: "arbitrum", destination_asset: "USDC", amount: "1000" } ` +
|
|
30
|
+
`(whole tokens; a positive number or bigint is accepted), or build it with lifiTransfer() / transferFromChainTokens().`);
|
|
31
|
+
this.missing = missing;
|
|
32
|
+
this.invalid = invalid;
|
|
33
|
+
this.name = "PreflightInputError";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** A value as the preflight reads it, or a reason it cannot be sent as given. Nothing is ever filled in or guessed. */
|
|
37
|
+
function wireValue(key, v) {
|
|
38
|
+
if (v === undefined || v === null)
|
|
39
|
+
return {};
|
|
40
|
+
if (typeof v === "string")
|
|
41
|
+
return v.trim() === "" ? {} : { value: v.trim() };
|
|
42
|
+
if (typeof v === "bigint")
|
|
43
|
+
return v > 0n ? { value: v.toString() } : { invalid: `${key} = ${v.toString()} (must be positive)` };
|
|
44
|
+
if (typeof v === "number") {
|
|
45
|
+
// String(n) is the shortest decimal that is exactly this number; an exponent form (1e21, 1e-7) is not a plain decimal.
|
|
46
|
+
const text = String(v);
|
|
47
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
48
|
+
return { invalid: `${key} = ${text} (must be a positive finite number)` };
|
|
49
|
+
if (/e/i.test(text))
|
|
50
|
+
return { invalid: `${key} = ${text} (pass it as a decimal string)` };
|
|
51
|
+
if (key === "amount" && Number.isInteger(v) && !Number.isSafeInteger(v))
|
|
52
|
+
return { invalid: `${key} = ${text} (beyond exact number precision: pass a string or bigint)` };
|
|
53
|
+
return { value: text };
|
|
54
|
+
}
|
|
55
|
+
return { invalid: `${key} (a ${typeof v}, not a string or number)` };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* What one transfer becomes on the wire: strings as given (trimmed), positive finite numbers and bigints as their exact
|
|
59
|
+
* decimal text (amount: 1000 → "1000"), camelCase names under Recta's (sourceNetwork → source_network). `missing` and
|
|
60
|
+
* `invalid` say what keeps it from being sent; no value is ever replaced by a default or an example.
|
|
61
|
+
*/
|
|
62
|
+
export function preflightBody(transfer) {
|
|
14
63
|
const body = {};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
64
|
+
const invalid = [];
|
|
65
|
+
for (const [k, v] of Object.entries(transfer)) {
|
|
66
|
+
const key = FIELD_ALIASES[k] ?? k;
|
|
67
|
+
const read = wireValue(key, v);
|
|
68
|
+
if (read.invalid !== undefined)
|
|
69
|
+
invalid.push(read.invalid);
|
|
70
|
+
if (read.value === undefined)
|
|
71
|
+
continue;
|
|
72
|
+
if (body[key] !== undefined && body[key] !== read.value)
|
|
73
|
+
invalid.push(`${key} given twice with different values (${body[key]}, ${read.value})`);
|
|
74
|
+
else
|
|
75
|
+
body[key] = read.value;
|
|
76
|
+
}
|
|
77
|
+
const missing = REQUIRED_FIELDS.filter((k) => body[k] === undefined && !invalid.some((i) => i.startsWith(`${k} `)));
|
|
78
|
+
return { body, missing, invalid };
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* One preflight. A transfer without the fields the preflight needs, or with a value it cannot send as given, throws
|
|
82
|
+
* PreflightInputError before any request; network failures, timeouts and non-JSON replies throw; a refusal
|
|
83
|
+
* (4xx/5xx JSON) is returned as is.
|
|
84
|
+
*/
|
|
85
|
+
export async function preflight(transfer, options = {}) {
|
|
86
|
+
const { body, missing, invalid } = preflightBody(transfer);
|
|
87
|
+
if (missing.length > 0 || invalid.length > 0)
|
|
88
|
+
throw new PreflightInputError(missing, invalid);
|
|
18
89
|
const f = options.fetch ?? fetch;
|
|
19
90
|
const response = await f(`${RECTA_ORIGIN}${PREFLIGHT_PATH}`, {
|
|
20
91
|
method: "POST",
|
|
@@ -115,17 +186,27 @@ export class RectaSavingFoundError extends Error {
|
|
|
115
186
|
this.name = "RectaSavingFoundError";
|
|
116
187
|
}
|
|
117
188
|
}
|
|
189
|
+
/** Without onPreflight a refused or failed preflight would go unseen: say so once per wrapped call, on the console. */
|
|
190
|
+
function warnOnce(options, state, problem) {
|
|
191
|
+
if (options.onPreflight !== undefined || options.quiet === true || state.warned)
|
|
192
|
+
return;
|
|
193
|
+
state.warned = true;
|
|
194
|
+
console.warn(`[@recta/client] Recta Preflight did not run: ${problem} The bridge still ran. Pass onPreflight to see every answer, or quiet: true to hide this.`);
|
|
195
|
+
}
|
|
118
196
|
/** The preflight for one call, or undefined; never throws (a failed preflight never blocks the bridge). */
|
|
119
|
-
async function check(transfer, options) {
|
|
197
|
+
async function check(transfer, options, state) {
|
|
120
198
|
if (transfer === undefined)
|
|
121
199
|
return undefined;
|
|
122
200
|
try {
|
|
123
201
|
const answer = await preflight(transfer, options);
|
|
124
202
|
options.onPreflight?.({ transfer, answer });
|
|
203
|
+
if (answer.outcome === undefined && answer.http_status >= 400)
|
|
204
|
+
warnOnce(options, state, `HTTP ${answer.http_status}${typeof answer["reason_code"] === "string" ? ` ${answer["reason_code"]}` : ""}${typeof answer.message === "string" ? `: ${answer.message}` : "."}`);
|
|
125
205
|
return answer;
|
|
126
206
|
}
|
|
127
207
|
catch (error) {
|
|
128
208
|
options.onPreflight?.({ transfer, error });
|
|
209
|
+
warnOnce(options, state, error instanceof Error ? error.message : String(error));
|
|
129
210
|
return undefined;
|
|
130
211
|
}
|
|
131
212
|
}
|
|
@@ -137,8 +218,9 @@ async function check(transfer, options) {
|
|
|
137
218
|
* const executeRoute = withPreflight(lifi.executeRoute, (route) => lifiTransfer(route));
|
|
138
219
|
*/
|
|
139
220
|
export function withPreflight(bridge, toTransfer, options = {}) {
|
|
221
|
+
const state = { warned: false };
|
|
140
222
|
return async (...args) => {
|
|
141
|
-
const answer = await check(toTransfer(...args), options);
|
|
223
|
+
const answer = await check(toTransfer(...args), options, state);
|
|
142
224
|
if (options.stopOnSaving === true && answer?.outcome === "SAVING_FOUND")
|
|
143
225
|
throw new RectaSavingFoundError(answer);
|
|
144
226
|
return bridge(...args);
|
|
@@ -166,10 +248,11 @@ export function withPreflightTool(tool, toTransfer, options = {}) {
|
|
|
166
248
|
const execute = tool.execute;
|
|
167
249
|
if (execute === undefined)
|
|
168
250
|
return tool;
|
|
251
|
+
const state = { warned: false };
|
|
169
252
|
const wrapped = async (input, ...rest) => {
|
|
170
253
|
const skip = typeof input === "object" && input !== null && input["skip_preflight"] === true;
|
|
171
254
|
const clean = skip ? Object.fromEntries(Object.entries(input).filter(([k]) => k !== "skip_preflight")) : input;
|
|
172
|
-
const answer = skip ? undefined : await check(toTransfer(clean), options);
|
|
255
|
+
const answer = skip ? undefined : await check(toTransfer(clean), options, state);
|
|
173
256
|
if (answer !== undefined && options.stopOnSaving === true && answer.outcome === "SAVING_FOUND") {
|
|
174
257
|
return { status: "RECTA_SAVING_FOUND", recta_preflight: preflightSummary(answer), note: "Recta proved a cheaper route; the bridge was not called. Sign recta_preflight.execute_via_recta.body_to_sign to get it, or call this tool again with skip_preflight: true to bridge anyway." };
|
|
175
258
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@recta/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "Client for Recta (api.recta.build): evaluate a cross-chain stablecoin transfer, authorize Recta's 5 %-of-verified-saving fee, execute the committed route and report it, with local checks before every signature.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Recta (https://recta.build)",
|