@recta/client 0.1.8 → 0.1.9

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 CHANGED
@@ -12,13 +12,16 @@ evaluate → authorizeFee → execute → report
12
12
 
13
13
  It never receives a key. Before it signs or sends anything it checks it locally, and those checks cannot be turned off.
14
14
 
15
+ No code to write? [`@recta/mcp`](https://www.npmjs.com/package/@recta/mcp) runs this same flow as a local MCP server, and
16
+ Recta Preflight (<https://api.recta.build/preflight>) is a free hosted check with no wallet at all.
17
+
15
18
  ## Install
16
19
 
17
20
  ```
18
21
  npm install @recta/client viem
19
22
  ```
20
23
 
21
- `viem` (>= 2.38.3, < 3) is the only dependency, and you choose its version.
24
+ `viem` (>= 2.38.3, < 3) is a peer dependency: you choose and pin its version. The package has no other dependency.
22
25
 
23
26
  ## Use
24
27
 
@@ -36,9 +39,9 @@ const recta = createRectaClient({
36
39
  referrer: "0x…", // optional: the integrator that ships this agent (see "Referral for integrators")
37
40
  });
38
41
 
39
- // Dry run: evaluates and checks, signs no permit, sends no transaction. With Recta's collection on it stops at the
40
- // fee permit, before the transactions exist (Recta hands them out only after the permit is signed): `preview.fee`
41
- // carries the permit it would sign and `funds`, whether this wallet can pay it (see "Paying the fee").
42
+ // Dry run: evaluates and checks, signs no permit, sends no transaction. It stops at the fee permit, before the
43
+ // transactions exist (Recta hands them out only after the permit is signed): `preview.fee` carries the permit it
44
+ // would sign and `funds`, whether this wallet can pay it (see "Paying the fee").
42
45
  const preview = await recta.run(request, { dryRun: true });
43
46
 
44
47
  // The whole flow.
@@ -53,93 +56,18 @@ your signer's address. Each step is also available alone: `evaluate`, `authorize
53
56
  An EOA signs its requests as EIP-191 signatures recovered to the sender's address. A smart account on Base signs
54
57
  through `smartAccountSigner` (see "Smart accounts").
55
58
 
56
- ## Referral for integrators
57
-
58
- If you ship Recta inside a plugin, framework or agent template, set your own EVM address once as the `referrer` and
59
- every agent that runs your integration carries it. Recta fixes it at the agent's first signed evaluation and never
60
- changes it afterwards. You earn 20 % of the fees Recta actually collects from those agents (confirmed on chain) for
61
- 12 months, up to 200 USDC per agent, whether or not you pay fees yourself. One level only. The agent still pays exactly
62
- 5 % of its verified saving: your share comes out of Recta's 5 %, never on top of it.
63
-
64
- The referrer travels in the query of the agent's own signed requests, so nobody relaying them can add, drop or change
65
- it. It is ignored when it is the agent's own address. Terms and your balance: `GET /v1/referrals/balance`, signed by
66
- your address, once Recta's referral program is on (it starts together with fee collection).
67
-
68
- ### Smart accounts
59
+ ## Which route to declare
69
60
 
70
- A smart account on Base works through `smartAccountSigner`: any viem smart account (for example
71
- `toCoinbaseSmartAccount` from `viem/account-abstraction`) and an ERC-4337 bundler client on Base, with a paymaster if
72
- one sponsors your gas:
73
-
74
- ```ts
75
- import { createPublicClient, http } from "viem";
76
- import { base } from "viem/chains";
77
- import { createBundlerClient, toCoinbaseSmartAccount } from "viem/account-abstraction";
78
- import { privateKeyToAccount } from "viem/accounts";
79
- import { createRectaClient, smartAccountSigner, viemChainReader } from "@recta/client";
61
+ `baseline_provider` is the route your agent would use without Recta. Declare the one it really uses: the saving and
62
+ the 5 % are measured against it, so declaring a worse route only makes you pay more. The fit check
63
+ (`GET https://api.recta.build/v1/golden-corridor/fit`) lists the routes you can declare for each corridor in
64
+ `declarable_baselines`.
80
65
 
81
- const client = createPublicClient({ chain: base, transport: http(BASE_RPC) });
82
- const account = await toCoinbaseSmartAccount({ client, owners: [privateKeyToAccount(OWNER_KEY)], version: "1.1" });
83
- const bundlerClient = createBundlerClient({ account, client, transport: http(BUNDLER_URL) });
66
+ If your agent bridges through LI.FI (its public API or an aggregator built on it), declare `lifi` wherever the fit
67
+ check lists it; it is refused with `latency_class` SECONDS or MINUTES. Recta reads LI.FI's own transaction, its fee
68
+ included.
84
69
 
85
- const recta = createRectaClient({
86
- signer: smartAccountSigner({ account, bundlerClient }),
87
- chain: viemChainReader((chainId) => publicClients[chainId]),
88
- limits: { maxPermitUsdcAtomic: 5_000_000n, maxNativeValueWei: 10n ** 15n, minOutputBps: 9900 },
89
- });
90
- ```
91
-
92
- - The account is the `sender`, holds the USDC and pays the fee. Recta accepts a smart account on Base only, so its
93
- transfers must start from Base; any other source is refused before any request.
94
- - Requests carry `x-recta-signer-chain: 8453` and are signed in Recta's v2 text, which also names the account and the
95
- chain. Recta asks the account on Base whether the signature holds (ERC-1271, or ERC-6492 while it is not deployed).
96
- - A fee or debt permit is signed only once the account is deployed on Base (Permit2 cannot deploy it): otherwise
97
- `RectaCheckError` `account_not_deployed`. Its first user operation deploys it, for example the bounded approval from
98
- `feeApproval()`.
99
- - Each checked route transaction is one user operation: the committed call, call gas limited to the committed gas
100
- limit, fees capped by the committed fee caps. The bundler client (and its paymaster) prepares it, and the signer
101
- checks it again before the account signs. Nothing is signed if they changed the call, the sender, the call gas, the
102
- fee caps or the init code, or if verification, pre-verification and paymaster gas exceed `maxOverheadGas` (default
103
- `DEFAULT_USER_OPERATION_OVERHEAD_GAS`, 1 500 000). A failed operation throws even when its bundle transaction
104
- succeeded. A receipt that does not arrive in time throws an error naming the operation: look it up before sending
105
- again.
106
- - Recta recognizes the operation in a bundle sent straight to an ERC-4337 EntryPoint (v0.6, v0.7 or v0.8). A bundler
107
- that relays through another contract first is not recognized.
108
- - `report` never sends a smart account's `approval_tx_hash`: the approval is the account's operation, not the
109
- committed transaction field by field, so Recta counts it at its committed upper bound.
110
-
111
- ### Coinbase CDP accounts
112
-
113
- A [Coinbase CDP](https://docs.cdp.coinbase.com) EVM server account (an EOA whose key stays in CDP) works through
114
- `cdpSigner`. This package does not depend on the CDP SDK:
115
-
116
- ```ts
117
- import { CdpClient } from "@coinbase/cdp-sdk";
118
- import { createRectaClient, cdpSigner, viemChainReader } from "@recta/client";
119
-
120
- const cdp = new CdpClient();
121
- const account = await cdp.evm.getOrCreateAccount({ name: "my-agent" });
122
-
123
- const recta = createRectaClient({
124
- signer: cdpSigner({ account }),
125
- chain: viemChainReader((chainId) => publicClients[chainId]),
126
- limits: { maxPermitUsdcAtomic: 5_000_000n, maxNativeValueWei: 10n ** 15n, minOutputBps: 9900 },
127
- });
128
- ```
129
-
130
- CDP signs Recta's requests and the fee permit. On Ethereum, Base, Arbitrum, Optimism, Polygon and Avalanche, CDP also
131
- sends each route transaction once this package has checked it. On any other chain, pass `walletClientFor` as well:
132
- CDP then signs the transaction and your RPC sends it.
133
-
134
- To limit the account to Recta's contracts at CDP's side too, apply the
135
- [CDP Policy Engine policy Recta serves](https://api.recta.build/v1/golden-corridor/wallet-policy/cdp). CDP refuses
136
- anything that policy does not allow, and it allows sending only on those six chains: with the policy applied, a route
137
- on any other chain is refused by CDP unless you add your own rule for it.
138
-
139
- The saving is measured against `baseline_provider`: the route your agent would use without Recta. Declare the one it
140
- really uses. If your agent bridges through LI.FI (its public API or an aggregator built on it), declare `lifi`
141
- wherever the fit check (`GET /v1/golden-corridor/fit`) lists it in `declarable_baselines`; it is refused with
142
- `latency_class` SECONDS or MINUTES. Recta reads LI.FI's own transaction, its fee included. If that route is already the cheapest, Recta answers with no saving and charges nothing.
70
+ If your route is already the cheapest, Recta answers with no saving and charges nothing: keep your route.
143
71
 
144
72
  ## Paying the fee: USDC and the Permit2 allowance on Base
145
73
 
@@ -229,10 +157,6 @@ the declared messaging fee, within `maxNativeValueWei`.
229
157
  `RectaDebtError` with the offer. The package never signs a debt by itself: call `payDebt(offer)` if you agree (same
230
158
  checks, exact amount).
231
159
 
232
- ## What each request identifies
233
-
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.
235
-
236
160
  ## Safety
237
161
 
238
162
  - **The key.** This package never receives a key: your signer signs and sends. Where the key lives is your choice of
@@ -240,9 +164,9 @@ Every request this package sends carries the User-Agent `recta-client/<version>`
240
164
  - **How much, and to whom.** The amount and the recipient are the ones your request names; the package checks that the
241
165
  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
166
  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`.
167
+ limits contracts and approvals, not the amount or recipient a bridge deposit names). `@recta/mcp`'s local server
168
+ (`npx @recta/mcp`, from 0.1.14) refuses a transfer above `RECTA_MAX_AMOUNT` (default 1000 tokens) or to a recipient
169
+ that is neither the wallet nor in `RECTA_ALLOWED_RECIPIENTS`.
246
170
  - **What Recta can take.** Only the fee permit, within `maxPermitUsdcAtomic`: exactly 5 % of the saving verified on
247
171
  chain, never more than the permit, nothing without a saving.
248
172
  - **Which contracts.** Exact-amount approvals to, and deposits into, the pinned bridge contracts (no message or hook at
@@ -274,6 +198,95 @@ Every request this package sends carries the User-Agent `recta-client/<version>`
274
198
  contract it does not know. A corridor or contract Recta adds later is served by the API at once, but refused by
275
199
  this package until a new release pins it.
276
200
 
201
+ ## Smart accounts
202
+
203
+ A smart account on Base works through `smartAccountSigner`: any viem smart account (for example
204
+ `toCoinbaseSmartAccount` from `viem/account-abstraction`) and an ERC-4337 bundler client on Base, with a paymaster if
205
+ one sponsors your gas:
206
+
207
+ ```ts
208
+ import { createPublicClient, http } from "viem";
209
+ import { base } from "viem/chains";
210
+ import { createBundlerClient, toCoinbaseSmartAccount } from "viem/account-abstraction";
211
+ import { privateKeyToAccount } from "viem/accounts";
212
+ import { createRectaClient, smartAccountSigner, viemChainReader } from "@recta/client";
213
+
214
+ const client = createPublicClient({ chain: base, transport: http(BASE_RPC) });
215
+ const account = await toCoinbaseSmartAccount({ client, owners: [privateKeyToAccount(OWNER_KEY)], version: "1.1" });
216
+ const bundlerClient = createBundlerClient({ account, client, transport: http(BUNDLER_URL) });
217
+
218
+ const recta = createRectaClient({
219
+ signer: smartAccountSigner({ account, bundlerClient }),
220
+ chain: viemChainReader((chainId) => publicClients[chainId]),
221
+ limits: { maxPermitUsdcAtomic: 5_000_000n, maxNativeValueWei: 10n ** 15n, minOutputBps: 9900 },
222
+ });
223
+ ```
224
+
225
+ - The account is the `sender`, holds the USDC and pays the fee. Recta accepts a smart account on Base only, so its
226
+ transfers must start from Base; any other source is refused before any request.
227
+ - Requests carry `x-recta-signer-chain: 8453` and are signed in Recta's v2 text, which also names the account and the
228
+ chain. Recta asks the account on Base whether the signature holds (ERC-1271, or ERC-6492 while it is not deployed).
229
+ - A fee or debt permit is signed only once the account is deployed on Base (Permit2 cannot deploy it): otherwise
230
+ `RectaCheckError` `account_not_deployed`. Its first user operation deploys it, for example the bounded approval from
231
+ `feeApproval()`.
232
+ - Each checked route transaction is one user operation: the committed call, call gas limited to the committed gas
233
+ limit, fees capped by the committed fee caps. The bundler client (and its paymaster) prepares it, and the signer
234
+ checks it again before the account signs. Nothing is signed if they changed the call, the sender, the call gas, the
235
+ fee caps or the init code, or if verification, pre-verification and paymaster gas exceed `maxOverheadGas` (default
236
+ `DEFAULT_USER_OPERATION_OVERHEAD_GAS`, 1 500 000). A failed operation throws even when its bundle transaction
237
+ succeeded. A receipt that does not arrive in time throws an error naming the operation: look it up before sending
238
+ again.
239
+ - Recta recognizes the operation in a bundle sent straight to an ERC-4337 EntryPoint (v0.6, v0.7 or v0.8). A bundler
240
+ that relays through another contract first is not recognized.
241
+ - `report` never sends a smart account's `approval_tx_hash`: the approval is the account's operation, not the
242
+ committed transaction field by field, so Recta counts it at its committed upper bound.
243
+
244
+ ## Coinbase CDP accounts
245
+
246
+ A [Coinbase CDP](https://docs.cdp.coinbase.com) EVM server account (an EOA whose key stays in CDP) works through
247
+ `cdpSigner`. This package does not depend on the CDP SDK:
248
+
249
+ ```ts
250
+ import { CdpClient } from "@coinbase/cdp-sdk";
251
+ import { createRectaClient, cdpSigner, viemChainReader } from "@recta/client";
252
+
253
+ const cdp = new CdpClient();
254
+ const account = await cdp.evm.getOrCreateAccount({ name: "my-agent" });
255
+
256
+ const recta = createRectaClient({
257
+ signer: cdpSigner({ account }),
258
+ chain: viemChainReader((chainId) => publicClients[chainId]),
259
+ limits: { maxPermitUsdcAtomic: 5_000_000n, maxNativeValueWei: 10n ** 15n, minOutputBps: 9900 },
260
+ });
261
+ ```
262
+
263
+ CDP signs Recta's requests and the fee permit. On Ethereum, Base, Arbitrum, Optimism, Polygon and Avalanche, CDP also
264
+ sends each route transaction once this package has checked it. On any other chain, pass `walletClientFor` as well:
265
+ CDP then signs the transaction and your RPC sends it.
266
+
267
+ To limit the account to Recta's contracts at CDP's side too, apply the
268
+ [CDP Policy Engine policy Recta serves](https://api.recta.build/v1/golden-corridor/wallet-policy/cdp). CDP refuses
269
+ anything that policy does not allow, and it allows sending only on those six chains: with the policy applied, a route
270
+ on any other chain is refused by CDP unless you add your own rule for it.
271
+
272
+ ## Referral for integrators
273
+
274
+ If you ship Recta inside a plugin, framework or agent template, set your own EVM address once as the `referrer` and
275
+ every agent that runs your integration carries it. Recta fixes it at the agent's first signed evaluation and never
276
+ changes it afterwards. You earn 20 % of the fees Recta actually collects from those agents (confirmed on chain) for
277
+ 12 months, up to 200 USDC per agent, whether or not you pay fees yourself. One level only. The agent still pays exactly
278
+ 5 % of its verified saving: your share comes out of Recta's 5 %, never on top of it.
279
+
280
+ The referrer travels in the query of the agent's own signed requests, so nobody relaying them can add, drop or change
281
+ it. It is ignored when it is the agent's own address.
282
+
283
+ Your reward is applied as a discount on your own Recta fees, or paid in USDC on Base once it reaches 10 USDC. Terms,
284
+ your balance and the agents you referred: `GET https://api.recta.build/v1/referrals/balance`, signed by your address.
285
+
286
+ ## What each request identifies
287
+
288
+ 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.
289
+
277
290
  ## Provenance
278
291
 
279
292
  Every release is published from [RectaBuild/recta](https://github.com/RectaBuild/recta) by GitHub Actions with npm
package/dist/client.js CHANGED
@@ -156,10 +156,10 @@ export function createRectaClient(options) {
156
156
  return a.body;
157
157
  }
158
158
  /**
159
- * Step 2: the decision's committed transactions. With Recta's collection on, the artifact first asks for the fee
159
+ * Step 2: the decision's committed transactions. The artifact first asks for the fee
160
160
  * permit: it is checked, rebuilt, and signed only if it passes and the payer holds the permit's amount in USDC on
161
161
  * Base with at least that allowance to Permit2 (otherwise RectaCheckError `fee_balance` / `fee_allowance`, nothing
162
- * signed; see `feeApproval`); then it is stored and the answer carries the artifact. With `dryRun` and collection on,
162
+ * signed; see `feeApproval`); then it is stored and the answer carries the artifact. With `dryRun`,
163
163
  * it stops at the permit, before the artifact exists, and returns the typed data it would sign and the payer's funds:
164
164
  * the transactions can only be inspected after the permit is signed. Pass the evaluation's `request` so a route that
165
165
  * starts from USDC on Base reserves its own amount from the balance; `execute` checks the funds again either way.
@@ -351,7 +351,7 @@ export function createRectaClient(options) {
351
351
  }
352
352
  /**
353
353
  * The four steps in a row. With `dryRun`, it evaluates and checks but signs no permit and sends no transaction: it
354
- * stops at the permit (collection on) or after checking the artifact (collection off).
354
+ * stops at the permit (or, on a service that does not collect, after checking the artifact).
355
355
  */
356
356
  async function run(request, opts = {}) {
357
357
  const decision = await evaluate(request, opts.idempotencyKey === undefined ? {} : { idempotencyKey: opts.idempotencyKey });
@@ -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.8";
10
+ export declare const CLIENT_VERSION = "0.1.9";
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.8";
12
+ export declare const USER_AGENT = "recta-client/0.1.9";
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.8";
10
+ export const CLIENT_VERSION = "0.1.9";
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@recta/client",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
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)",