@recta/client 0.1.7 → 0.1.8
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 +46 -0
- package/dist/client.js +77 -5
- package/dist/constants.d.ts +2 -2
- package/dist/constants.js +1 -1
- package/dist/errors.d.ts +33 -1
- package/dist/errors.js +27 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/signer.d.ts +6 -0
- package/dist/signer.js +20 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -177,6 +177,21 @@ Since 0.1.4 `RectaChainReader` requires `readFeeFunds`; `createRectaClient` refu
|
|
|
177
177
|
A custom `RectaChainReader` must implement `readFeeFunds(owner)`; when it cannot read Base it must throw, and the permit
|
|
178
178
|
is then not signed (a dry run reports `funds: null` and the reason).
|
|
179
179
|
|
|
180
|
+
## When a send goes wrong
|
|
181
|
+
|
|
182
|
+
`execute()` sends the route's transactions in order. With a local key (`viemSigner`), the approval and the transfer
|
|
183
|
+
leave back to back on consecutive nonces, so they fit in Recta's 60-second window even on Ethereum; other wallets wait
|
|
184
|
+
for each receipt. Errors say what happened:
|
|
185
|
+
|
|
186
|
+
- `RectaSendUnknownError` (`check` `transaction_unknown`): a transaction may have been sent and its outcome is not
|
|
187
|
+
known. `sentTxHashes` lists every hash already sent, `resultId` the evaluation, and `transferSent` is `NO` only when the
|
|
188
|
+
transfer was certainly never sent (otherwise `UNKNOWN`). Look them up on chain (with no hash,
|
|
189
|
+
the account's latest transactions) before sending anything again, by Recta or any other route. If the transfer
|
|
190
|
+
succeeded, report it with `report(resultId, originTxHash)`.
|
|
191
|
+
- `RectaCheckError` `transaction_failed`: the named transaction was mined and reverted.
|
|
192
|
+
- `wallet_*` checks (the MetaMask signer): their message says what was sent.
|
|
193
|
+
- Any other `RectaCheckError`: nothing was signed or sent.
|
|
194
|
+
|
|
180
195
|
## What is checked before signing
|
|
181
196
|
|
|
182
197
|
**Pins.** The package carries Recta's fee addresses in its own code: Permit2, x402's `upto` proxy, USDC on Base,
|
|
@@ -218,6 +233,37 @@ checks, exact amount).
|
|
|
218
233
|
|
|
219
234
|
Every request this package sends carries the User-Agent `recta-client/<version>`, so Recta can count real use of the package apart from other clients. It names the package and its version only: never an address, a key or a request body.
|
|
220
235
|
|
|
236
|
+
## Safety
|
|
237
|
+
|
|
238
|
+
- **The key.** This package never receives a key: your signer signs and sends. Where the key lives is your choice of
|
|
239
|
+
signer (`viemSigner` with your own account, `cdpSigner` with the key kept at Coinbase, `smartAccountSigner`).
|
|
240
|
+
- **How much, and to whom.** The amount and the recipient are the ones your request names; the package checks that the
|
|
241
|
+
route delivers exactly there, but it does not cap them. Cap them in your own code, or in your wallet's policy (a rule
|
|
242
|
+
on the deposit call's recipient and amount, if your wallet supports one, and a daily limit; Recta's wallet policy
|
|
243
|
+
limits contracts and approvals, not the amount or recipient a bridge deposit names). `@recta/mcp`'s local server (`npx @recta/mcp`, from 0.1.14) refuses a transfer
|
|
244
|
+
above `RECTA_MAX_AMOUNT` (default 1000 tokens) or to a recipient that is neither the wallet nor in
|
|
245
|
+
`RECTA_ALLOWED_RECIPIENTS`.
|
|
246
|
+
- **What Recta can take.** Only the fee permit, within `maxPermitUsdcAtomic`: exactly 5 % of the saving verified on
|
|
247
|
+
chain, never more than the permit, nothing without a saving.
|
|
248
|
+
- **Which contracts.** Exact-amount approvals to, and deposits into, the pinned bridge contracts (no message or hook at
|
|
249
|
+
the destination), and a bounded USDC approval to Permit2 on Base for the fee (`feeApproval`). The bridges are run by
|
|
250
|
+
third parties and some of their contracts are upgradeable proxies: the package pins their addresses, not their code.
|
|
251
|
+
- **If the price moves.** The route transaction fixes the least the recipient gets (`minOutputBps`) and its gas price
|
|
252
|
+
ceilings; a decision already past its expiry is refused before the first transaction is sent. The fee is computed on
|
|
253
|
+
the saving of the transfer as executed.
|
|
254
|
+
- **Replays.** A signed request carries its time (within 5 minutes of Recta's clock, either way) and its body's hash,
|
|
255
|
+
and an evaluation its idempotency key: a repeat returns the stored decision. A fee permit has a Permit2 nonce and can
|
|
256
|
+
be used once. Route transactions use your wallet's own nonce.
|
|
257
|
+
- **What Recta records.** Each evaluation (sender, recipient, amount, corridor) and its decision; Recta does not delete
|
|
258
|
+
these records today. A verified saving is published in the public savings ledger with both transaction hashes. Recta's
|
|
259
|
+
log lines for evaluations and executions carry no wallet address, transfer amount or transaction hash; Cloudflare, which hosts Recta, sees each request's IP
|
|
260
|
+
address and keeps its request logs, whose URLs can include an address, 7 days.
|
|
261
|
+
- **Review.** Audited adversarially by Recta, with the fee contract simulated against Base's real Permit2; no
|
|
262
|
+
independent external audit yet. Recta's server is not open source; this package is. Start with small amounts.
|
|
263
|
+
- **Changes and supply chain.** Pin the exact version you reviewed and check `npm audit signatures`: Recta's routes,
|
|
264
|
+
contracts and fee addresses are pinned in each release, and a service that no longer matches them is refused, never
|
|
265
|
+
followed. It has no dependency of its own: `viem` is a peer range, so pin it too.
|
|
266
|
+
|
|
221
267
|
## Limits of this version
|
|
222
268
|
|
|
223
269
|
- EVM sources and EVM recipients only. Solana, Tron and Bitcoin routes, Relay and deBridge are refused.
|
package/dist/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { keccak256 } from "viem";
|
|
2
2
|
import { checkExecutionArtifact } from "./artifact.js";
|
|
3
3
|
import { FEE_CHAIN_ID, ISSUED_AT_HEADER, PATHS, RECTA_ORIGIN, SIGNATURE_HEADER, SIGNED_REQUEST_PREFIX, SIGNER_CHAIN_HEADER, SIGNER_HEADER, SMART_ACCOUNT_SIGNED_REQUEST_PREFIX, USER_AGENT } from "./constants.js";
|
|
4
|
-
import { RectaCheckError, RectaDebtError, RectaHttpError } from "./errors.js";
|
|
4
|
+
import { RectaCheckError, RectaDebtError, RectaHttpError, RectaSendUnknownError } from "./errors.js";
|
|
5
5
|
import { checkFeePermit } from "./fee.js";
|
|
6
6
|
import { assertFeeReady, feeReadiness, permit2ApprovalTransaction, routeReserveOf, safeErrorText } from "./funds.js";
|
|
7
7
|
import { parseWalletPolicy } from "./policy.js";
|
|
@@ -55,6 +55,15 @@ const resultIdOf = (v) => {
|
|
|
55
55
|
throw new RectaCheckError("result_id", "not a Recta result id");
|
|
56
56
|
return v;
|
|
57
57
|
};
|
|
58
|
+
/** A send whose outcome is not known (owner rule 2026-11-11): every hash already sent and the result_id, and the
|
|
59
|
+
* instruction to look them up (and the account's nonce) before anything is sent again. */
|
|
60
|
+
function unknownSend(resultId, sent, what, transferSent) {
|
|
61
|
+
const hashes = sent.length === 0 ? "No transaction hash came back" : `${sent.map((s) => `${s.role} ${s.hash}`).join(", ")} sent`;
|
|
62
|
+
// Fable A-1 on #23: whether the transfer was attempted is said by the caller, never deduced from the hashes (a
|
|
63
|
+
// transfer whose send failed has no hash and may still have been broadcast).
|
|
64
|
+
const may = transferSent === "NO" ? "the transfer was not sent, but the approval's outcome is not known" : "the transfer may have moved funds";
|
|
65
|
+
return new RectaSendUnknownError(`${hashes} for ${resultId}, then ${what}: ${may}, so look ${sent.length === 0 ? "the account's latest transactions (its nonce)" : "these hashes"} up on chain (and report the EXECUTION if it succeeded) before sending anything again`, resultId, sent.map((s) => ({ ...s })), transferSent);
|
|
66
|
+
}
|
|
58
67
|
/**
|
|
59
68
|
* Recta's flow for an agent that holds its own EOA or smart account (on Base): evaluate → authorizeFee → execute → report. Every step can be
|
|
60
69
|
* called alone. Nothing is signed or sent before this package's own checks pass (see `checkFeePermit` and
|
|
@@ -215,7 +224,8 @@ export function createRectaClient(options) {
|
|
|
215
224
|
await walletPolicy();
|
|
216
225
|
return checkExecutionArtifact(artifact, { resultId: resultIdOf(resultId), request, limits: { signer: payer, nowUnix: nowUnix(), maxNativeValueWei: limits.maxNativeValueWei, minOutputBps: limits.minOutputBps } });
|
|
217
226
|
}
|
|
218
|
-
/** Step 3: checks, then sends the transactions in order
|
|
227
|
+
/** Step 3: checks, then sends the transactions in order: each mined successfully before the next, or, with a signer
|
|
228
|
+
* that can (`sendInSequence`), all of them back to back and then awaited (`executeInSequence`). */
|
|
219
229
|
async function execute(resultId, artifact, request) {
|
|
220
230
|
// The last moment before anything is sent: with a fee authorized for this decision, the payer must still hold it
|
|
221
231
|
// in USDC on Base (plus the transfer itself when it starts from Base USDC) with the Permit2 allowance for it.
|
|
@@ -223,12 +233,35 @@ export function createRectaClient(options) {
|
|
|
223
233
|
if (fee !== undefined)
|
|
224
234
|
assertFeeReady(feeReadiness(await chain.readFeeFunds(signer.address), fee, routeReserveOf(request)));
|
|
225
235
|
const checked = await check(resultId, artifact, request);
|
|
236
|
+
if (signer.sendInSequence !== undefined && checked.transactions.length > 1)
|
|
237
|
+
return executeInSequence(resultId, checked, signer.sendInSequence.bind(signer));
|
|
226
238
|
let approvalTxHash;
|
|
239
|
+
const sent = [];
|
|
227
240
|
for (const tx of checked.transactions) {
|
|
228
241
|
const { role, ...send } = tx;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
242
|
+
let hash;
|
|
243
|
+
try {
|
|
244
|
+
hash = await signer.sendTransaction(send);
|
|
245
|
+
}
|
|
246
|
+
catch (e) {
|
|
247
|
+
// Fable M-3 on #22 (owner rule 2026-11-11): a send that failed without a hash may still have been broadcast.
|
|
248
|
+
// A wallet's own RectaCheckError (MetaMask's journal and recovery, which key on its own checks) passes as it is:
|
|
249
|
+
// that wallet waits inside its own send, so a hash before this one is already mined and in its journal.
|
|
250
|
+
if (e instanceof RectaCheckError)
|
|
251
|
+
throw e;
|
|
252
|
+
// An APPROVAL send that failed means the transfer was never asked for; anything else may have left.
|
|
253
|
+
throw unknownSend(resultId, sent, `sending the ${role} failed without a hash (${safeErrorText(e).slice(0, 200)})`, role === "APPROVAL" ? "NO" : "UNKNOWN");
|
|
254
|
+
}
|
|
255
|
+
sent.push({ role, chainId: tx.chainId, hash });
|
|
256
|
+
let ok;
|
|
257
|
+
try {
|
|
258
|
+
ok = await chain.waitForSuccess(tx.chainId, hash);
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
throw unknownSend(resultId, sent, `waiting for a receipt failed (${safeErrorText(e).slice(0, 200)})`, role === "APPROVAL" ? "NO" : "UNKNOWN");
|
|
262
|
+
}
|
|
263
|
+
if (!ok)
|
|
264
|
+
throw new RectaCheckError("transaction_failed", `${role} transaction ${hash} reverted${role === "APPROVAL" ? ": nothing else was sent" : ": nothing was moved by it"}`);
|
|
232
265
|
if (role === "APPROVAL")
|
|
233
266
|
approvalTxHash = hash;
|
|
234
267
|
else
|
|
@@ -236,6 +269,45 @@ export function createRectaClient(options) {
|
|
|
236
269
|
}
|
|
237
270
|
throw new RectaCheckError("transaction_order", "the artifact has no execution");
|
|
238
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Recta's saving holds for a short horizon after its anchor block (60 s). On Ethereum, waiting for the approval's
|
|
274
|
+
* receipt before sending the deposit took the deposit past it (Recta BIT-OPS-182: mined 72 s after the anchor, nothing
|
|
275
|
+
* accrued). A signer that can (`sendInSequence`: a local key) sends the approval and the deposit one after another on
|
|
276
|
+
* consecutive nonces, and they are awaited only then. From the first hash on, every failure names every hash sent:
|
|
277
|
+
* whether the deposit moved funds is then UNKNOWN until the chain says so, and nothing may be sent again before.
|
|
278
|
+
*/
|
|
279
|
+
async function executeInSequence(resultId, checked, sendInSequence) {
|
|
280
|
+
const sent = [];
|
|
281
|
+
// In sequence the transfer may have been handed to the node at any point: never "NO".
|
|
282
|
+
const unknown = (what) => unknownSend(resultId, sent, what, "UNKNOWN");
|
|
283
|
+
const roles = checked.transactions.map((t) => t.role);
|
|
284
|
+
try {
|
|
285
|
+
await sendInSequence(checked.transactions.map(({ role: _role, ...send }) => send), (i, hash) => { sent.push({ role: roles[i], chainId: checked.transactions[i].chainId, hash }); });
|
|
286
|
+
}
|
|
287
|
+
catch (e) {
|
|
288
|
+
if (e instanceof RectaCheckError && sent.length === 0)
|
|
289
|
+
throw e;
|
|
290
|
+
throw unknown(`sending ${sent.length === 0 ? "the first" : "the next"} transaction failed without a hash (${safeErrorText(e).slice(0, 200)})`);
|
|
291
|
+
}
|
|
292
|
+
const execution = sent.find((s) => s.role === "EXECUTION");
|
|
293
|
+
if (execution === undefined || sent.length !== checked.transactions.length)
|
|
294
|
+
throw unknown("the signer stopped before the transfer");
|
|
295
|
+
const ok = [];
|
|
296
|
+
try {
|
|
297
|
+
for (const s of sent)
|
|
298
|
+
ok.push(await chain.waitForSuccess(s.chainId, s.hash));
|
|
299
|
+
}
|
|
300
|
+
catch (e) {
|
|
301
|
+
throw unknown(`waiting for a receipt failed (${safeErrorText(e).slice(0, 200)})`);
|
|
302
|
+
}
|
|
303
|
+
if (!ok[sent.indexOf(execution)])
|
|
304
|
+
throw new RectaCheckError("transaction_failed", `EXECUTION transaction ${execution.hash} reverted: nothing was moved by it`);
|
|
305
|
+
// The deposit moved funds even if an approval reverted (an allowance already there): it is reported, the reverted
|
|
306
|
+
// approval is not (Recta then prices the approval at its committed upper bound: the saving can only be understated).
|
|
307
|
+
const approvalsOk = sent.every((s, i) => s.role !== "APPROVAL" || ok[i]);
|
|
308
|
+
const approvalTxHash = approvalsOk ? sent.filter((s) => s.role === "APPROVAL").at(-1)?.hash : undefined;
|
|
309
|
+
return { ...(approvalTxHash === undefined ? {} : { approvalTxHash }), originTxHash: execution.hash };
|
|
310
|
+
}
|
|
239
311
|
/**
|
|
240
312
|
* Step 4: reports the executed route; Recta verifies the delivery on chain and records the saving and its 5 %.
|
|
241
313
|
* `stage`: ACCRUED (verified and recorded), PENDING (not yet verifiable: report again later) or REFUSED (Recta will
|
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.8";
|
|
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.8";
|
|
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.8";
|
|
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/errors.d.ts
CHANGED
|
@@ -1,9 +1,41 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* A local check refused, or a transaction did not end as expected. `check` names it. Read it before acting:
|
|
3
|
+
* - `transaction_unknown` (a RectaSendUnknownError): a transaction may have been sent. Look `sentTxHashes` (or, with
|
|
4
|
+
* none, the account's latest transactions) up on chain before sending anything again, by Recta or any other route.
|
|
5
|
+
* - `transaction_failed`: the named transaction was mined and reverted.
|
|
6
|
+
* - a wallet's own checks (`wallet_*`, from the MetaMask signer) say in their message what was sent.
|
|
7
|
+
* - every other check: nothing was signed or sent.
|
|
8
|
+
*/
|
|
2
9
|
export declare class RectaCheckError extends Error {
|
|
3
10
|
readonly check: string;
|
|
4
11
|
readonly name: string;
|
|
5
12
|
constructor(check: string, message: string);
|
|
6
13
|
}
|
|
14
|
+
/** A send whose outcome is not known (owner rule 2026-11-11: UNKNOWN, never FAILED): what was already sent, as data. */
|
|
15
|
+
export declare class RectaSendUnknownError extends RectaCheckError {
|
|
16
|
+
/** The evaluation this send belongs to, when it belongs to one. */
|
|
17
|
+
readonly resultId: string | undefined;
|
|
18
|
+
/** Every transaction hash already sent, in order; empty when none came back. */
|
|
19
|
+
readonly sentTxHashes: readonly {
|
|
20
|
+
readonly role: string;
|
|
21
|
+
readonly chainId: number;
|
|
22
|
+
readonly hash: `0x${string}`;
|
|
23
|
+
}[];
|
|
24
|
+
/** "NO" only when the transfer was certainly never asked for; "UNKNOWN" when it may have left (no hash for it). */
|
|
25
|
+
readonly transferSent: "NO" | "UNKNOWN";
|
|
26
|
+
readonly name: string;
|
|
27
|
+
constructor(message: string,
|
|
28
|
+
/** The evaluation this send belongs to, when it belongs to one. */
|
|
29
|
+
resultId: string | undefined,
|
|
30
|
+
/** Every transaction hash already sent, in order; empty when none came back. */
|
|
31
|
+
sentTxHashes: readonly {
|
|
32
|
+
readonly role: string;
|
|
33
|
+
readonly chainId: number;
|
|
34
|
+
readonly hash: `0x${string}`;
|
|
35
|
+
}[],
|
|
36
|
+
/** "NO" only when the transfer was certainly never asked for; "UNKNOWN" when it may have left (no hash for it). */
|
|
37
|
+
transferSent?: "NO" | "UNKNOWN");
|
|
38
|
+
}
|
|
7
39
|
/** Recta answered with an error. `body` is Recta's JSON answer when it sent one. */
|
|
8
40
|
export declare class RectaHttpError extends Error {
|
|
9
41
|
readonly status: number;
|
package/dist/errors.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* A local check refused, or a transaction did not end as expected. `check` names it. Read it before acting:
|
|
3
|
+
* - `transaction_unknown` (a RectaSendUnknownError): a transaction may have been sent. Look `sentTxHashes` (or, with
|
|
4
|
+
* none, the account's latest transactions) up on chain before sending anything again, by Recta or any other route.
|
|
5
|
+
* - `transaction_failed`: the named transaction was mined and reverted.
|
|
6
|
+
* - a wallet's own checks (`wallet_*`, from the MetaMask signer) say in their message what was sent.
|
|
7
|
+
* - every other check: nothing was signed or sent.
|
|
8
|
+
*/
|
|
2
9
|
export class RectaCheckError extends Error {
|
|
3
10
|
check;
|
|
4
11
|
name = "RectaCheckError";
|
|
@@ -7,6 +14,25 @@ export class RectaCheckError extends Error {
|
|
|
7
14
|
this.check = check;
|
|
8
15
|
}
|
|
9
16
|
}
|
|
17
|
+
/** A send whose outcome is not known (owner rule 2026-11-11: UNKNOWN, never FAILED): what was already sent, as data. */
|
|
18
|
+
export class RectaSendUnknownError extends RectaCheckError {
|
|
19
|
+
resultId;
|
|
20
|
+
sentTxHashes;
|
|
21
|
+
transferSent;
|
|
22
|
+
name = "RectaSendUnknownError";
|
|
23
|
+
constructor(message,
|
|
24
|
+
/** The evaluation this send belongs to, when it belongs to one. */
|
|
25
|
+
resultId,
|
|
26
|
+
/** Every transaction hash already sent, in order; empty when none came back. */
|
|
27
|
+
sentTxHashes,
|
|
28
|
+
/** "NO" only when the transfer was certainly never asked for; "UNKNOWN" when it may have left (no hash for it). */
|
|
29
|
+
transferSent = "UNKNOWN") {
|
|
30
|
+
super("transaction_unknown", message);
|
|
31
|
+
this.resultId = resultId;
|
|
32
|
+
this.sentTxHashes = sentTxHashes;
|
|
33
|
+
this.transferSent = transferSent;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
10
36
|
/** Recta answered with an error. `body` is Recta's JSON answer when it sent one. */
|
|
11
37
|
export class RectaHttpError extends Error {
|
|
12
38
|
status;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export { checkExecutionArtifact, pinnedRouteOf, type CheckedArtifact, type Evalu
|
|
|
5
5
|
export { PINNED_ROUTES, type PinnedRoute } from "./pinned-routes.js";
|
|
6
6
|
export { parseWalletPolicy, type WalletPolicy, type WalletPolicyNetwork } from "./policy.js";
|
|
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
|
-
export { RectaCheckError, RectaHttpError, RectaDebtError } from "./errors.js";
|
|
8
|
+
export { RectaCheckError, RectaHttpError, RectaDebtError, RectaSendUnknownError } from "./errors.js";
|
|
9
9
|
export * as pins from "./constants.js";
|
package/dist/index.js
CHANGED
|
@@ -5,5 +5,5 @@ export { checkExecutionArtifact, pinnedRouteOf } from "./artifact.js";
|
|
|
5
5
|
export { PINNED_ROUTES } from "./pinned-routes.js";
|
|
6
6
|
export { parseWalletPolicy } from "./policy.js";
|
|
7
7
|
export { viemSigner, viemChainReader, cdpSigner, smartAccountSigner, DEFAULT_USER_OPERATION_OVERHEAD_GAS, CDP_SEND_NETWORKS } from "./signer.js";
|
|
8
|
-
export { RectaCheckError, RectaHttpError, RectaDebtError } from "./errors.js";
|
|
8
|
+
export { RectaCheckError, RectaHttpError, RectaDebtError, RectaSendUnknownError } from "./errors.js";
|
|
9
9
|
export * as pins from "./constants.js";
|
package/dist/signer.d.ts
CHANGED
|
@@ -46,6 +46,12 @@ export interface RectaSigner {
|
|
|
46
46
|
signTypedData(typedData: RectaTypedData): Promise<Hex>;
|
|
47
47
|
/** Sends one transaction on `tx.chainId` and returns its hash. */
|
|
48
48
|
sendTransaction(tx: RectaTransaction): Promise<Hex>;
|
|
49
|
+
/**
|
|
50
|
+
* Optional: sends transactions of one chain one after another without waiting for any receipt, on consecutive nonces
|
|
51
|
+
* read once, calling `onSent(i, hash)` the moment each leaves. Only a signer that does not itself wait for receipts
|
|
52
|
+
* and that picks its own nonces implements it (viemSigner with a local key); without it, execute() waits for each.
|
|
53
|
+
*/
|
|
54
|
+
sendInSequence?(txs: readonly RectaTransaction[], onSent: (index: number, hash: Hex) => void): Promise<void>;
|
|
49
55
|
}
|
|
50
56
|
/** Read access to the chains (the agent's own RPC): receipts, and the payer's USDC on Base before a fee is signed. */
|
|
51
57
|
export interface RectaChainReader {
|
package/dist/signer.js
CHANGED
|
@@ -3,6 +3,7 @@ import { formatUserOperationRequest } from "viem/account-abstraction";
|
|
|
3
3
|
import { toAccount } from "viem/accounts";
|
|
4
4
|
import { FEE_CHAIN_ID, PERMIT2, USDC_BASE } from "./constants.js";
|
|
5
5
|
import { ERC20_READ_ABI, safeErrorText } from "./funds.js";
|
|
6
|
+
import { RectaCheckError } from "./errors.js";
|
|
6
7
|
/** A RectaSigner from a viem account and one wallet client per chain. */
|
|
7
8
|
export function viemSigner(args) {
|
|
8
9
|
const { account } = args;
|
|
@@ -21,9 +22,26 @@ export function viemSigner(args) {
|
|
|
21
22
|
signMessage: (message) => account.signMessage({ message }),
|
|
22
23
|
signTypedData: (td) => account.signTypedData(td),
|
|
23
24
|
sendTransaction: (tx) => sendWith(args.walletClientFor(tx.chainId), account, tx),
|
|
25
|
+
// A local key: the nonce is read once from the node (pending) and the transactions take it and the ones after it,
|
|
26
|
+
// so they never share one. Nothing is remembered between calls.
|
|
27
|
+
sendInSequence: async (txs, onSent) => {
|
|
28
|
+
const chainId = txs[0]?.chainId;
|
|
29
|
+
if (chainId === undefined || txs.some((t) => t.chainId !== chainId))
|
|
30
|
+
throw new Error("sendInSequence sends transactions of one chain");
|
|
31
|
+
const client = args.walletClientFor(chainId);
|
|
32
|
+
let first;
|
|
33
|
+
try {
|
|
34
|
+
first = Number(BigInt((await client.request({ method: "eth_getTransactionCount", params: [account.address, "pending"] }))));
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
throw new RectaCheckError("wallet_nonce", `could not read the nonce of ${account.address} on chain ${chainId} (${safeErrorText(e).slice(0, 200)}): nothing was sent`);
|
|
38
|
+
}
|
|
39
|
+
for (const [i, tx] of txs.entries())
|
|
40
|
+
onSent(i, await sendWith(client, account, tx, first + i));
|
|
41
|
+
},
|
|
24
42
|
};
|
|
25
43
|
}
|
|
26
|
-
async function sendWith(client, account, tx) {
|
|
44
|
+
async function sendWith(client, account, tx, nonce) {
|
|
27
45
|
const chainId = await client.getChainId();
|
|
28
46
|
if (chainId !== tx.chainId)
|
|
29
47
|
throw new Error(`walletClientFor(${tx.chainId}) returned a client on chain ${chainId}`);
|
|
@@ -37,6 +55,7 @@ async function sendWith(client, account, tx) {
|
|
|
37
55
|
maxFeePerGas: tx.maxFeePerGas,
|
|
38
56
|
maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
|
|
39
57
|
type: "eip1559",
|
|
58
|
+
...(nonce === undefined ? {} : { nonce }),
|
|
40
59
|
});
|
|
41
60
|
}
|
|
42
61
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@recta/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
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)",
|