Skip to content

Commit f61da35

Browse files
committed
update to latest deployment
1 parent ec3155a commit f61da35

9 files changed

Lines changed: 64 additions & 14 deletions

File tree

e2e/clients/httpx/uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/clients/requests/uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/servers/fastapi/uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/servers/flask/uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/typescript/clients/batch-settlement/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ cd clients/batch-settlement
5858
pnpm start
5959
```
6060

61+
## Concurrent requests
62+
63+
Use the concurrent example to send requests over multiple channels in parallel. Each slot uses a unique salt derived from `CHANNEL_SALT`, so the server can serialize work per channel while still processing channels concurrently.
64+
65+
```bash
66+
CONCURRENCY=3 NUMBER_OF_ROUNDS=3 pnpm dev:concurrent
67+
```
68+
6169
## Environment
6270

6371
| Variable | Required | Description |
@@ -70,5 +78,7 @@ pnpm start
7078
| `DEPOSIT_MULTIPLIER` | no | Per-request deposit is payment amount × this multiplier (must be integer **≥ 3**; default `5`) |
7179
| `STORAGE_DIR` | no | Persist client session state (defaults to in-memory) |
7280
| `NUMBER_OF_REQUESTS` | no | How many paid requests to issue (default 3) |
81+
| `CONCURRENCY` | no | How many channels to run in parallel in `pnpm dev:concurrent` (default 3) |
82+
| `NUMBER_OF_ROUNDS` | no | How many concurrent rounds to run in `pnpm dev:concurrent` (default 3) |
7383
| `REFUND_AFTER_REQUESTS` | no | If `true`, issue a self-contained refund via `scheme.refund(url)` after the request loop |
7484
| `REFUND_AMOUNT` | no | Partial refund amount in base units; omit for a full refund |

examples/typescript/clients/batch-settlement/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"scripts": {
66
"start": "tsx index.ts",
77
"dev": "tsx index.ts",
8+
"dev:concurrent": "tsx concurrent.ts",
89
"format": "prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"",
910
"format:check": "prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\"",
1011
"lint": "eslint . --ext .ts --fix",
@@ -29,4 +30,4 @@
2930
"tsx": "^4.7.0",
3031
"typescript": "^5.3.0"
3132
}
32-
}
33+
}

examples/typescript/servers/batch-settlement/README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ See the [scheme specification](../../../../specs/schemes/batch-settlement/scheme
1010

1111
Every channel commits to a `receiverAuthorizer` — the address whose EIP-712 signatures authorize `claimWithSignature` and `refundWithSignature`. This server lets you choose between two strategies:
1212

13-
### 1. Self-managed
13+
### 1. Self-managed (recommended)
1414

1515
Set `EVM_RECEIVER_AUTHORIZER_PRIVATE_KEY` to an EOA you own. The scheme uses it to sign claims/refunds locally; **any facilitator** can relay the resulting transactions.
1616

@@ -39,7 +39,37 @@ This demo uses local-friendly timing: claim every 1 minute, settle every 2 minut
3939

4040
For production, choose a `withdrawDelay` greater than your claim cadence plus an operational safety margin. A daily claim job pairs well with a `withdrawDelay` longer than one day; settle less frequently when gas savings matter more than receiver cash-flow latency. Idle refunds are usually best on a week-scale cadence unless your product needs faster channel cleanup.
4141

42-
The `ChannelManager` can also be used with one-shot calls such as `claimAndSettle()` and `refundIdleChannels()` from a cron job or external worker.
42+
The `ChannelManager` runs the server-side lifecycle: claim vouchers from stored channels, settle claimed funds to `payTo`, and optionally refund idle channels. `start()` enables each job at the configured interval, while callbacks let you choose channels, gate settlement, and hook logging/metrics:
43+
44+
```typescript
45+
manager.start({
46+
claimIntervalSecs: 60,
47+
settleIntervalSecs: 120,
48+
refundIntervalSecs: 180,
49+
maxClaimsPerBatch: 100,
50+
selectClaimChannels: (channels, { now }) =>
51+
channels.filter(
52+
channel =>
53+
channel.withdrawRequestedAt > 0 ||
54+
now - channel.lastRequestTimestamp >= 60_000,
55+
),
56+
shouldSettle: ({ pendingSettle }) => pendingSettle,
57+
selectRefundChannels: (channels, { now }) =>
58+
channels.filter(channel => now - channel.lastRequestTimestamp >= 180_000),
59+
onClaim: result => console.log(`Claimed ${result.vouchers} vouchers`),
60+
onSettle: result => console.log(`Settled ${result.transaction}`),
61+
onRefund: result => console.log(`Refunded ${result.channel}`),
62+
onError: error => console.error("Settlement error:", error),
63+
});
64+
```
65+
66+
In this example, `selectClaimChannels` prioritizes channels with pending withdrawals and channels idle for at least 1 minute, so their vouchers are claimed before a withdrawal can finalize. The same selection callbacks can be reused with one-shot calls such as `claimAndSettle()` and `refundIdleChannels()` from a cron job or external worker.
67+
68+
## Storage
69+
70+
By default, channel sessions are in memory. Set `STORAGE_DIR` to persist them on disk for local restarts.
71+
72+
For serverless deployments or multi-instance servers, configure the scheme with `RedisChannelStorage`; it stores channel sessions in Redis/Valkey so they survive cold starts and update atomically across processes.
4373

4474
## Prerequisites
4575

typescript/packages/mechanisms/evm/src/batch-settlement/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ import { x402ResourceServer } from "@x402/core/server";
110110
import {
111111
BatchSettlementEvmScheme,
112112
FileChannelStorage,
113+
RedisChannelStorage,
113114
} from "@x402/evm/batch-settlement/server";
114115

115116
const scheme = new BatchSettlementEvmScheme(receiverAddress, {
@@ -131,6 +132,14 @@ manager.start({
131132
});
132133
```
133134

135+
For serverless deployments or multi-instance servers, use Redis/Valkey-backed storage so channel updates survive cold starts and are atomic across processes:
136+
137+
```typescript
138+
const scheme = new BatchSettlementEvmScheme(receiverAddress, {
139+
storage: new RedisChannelStorage({ client: redisClient }),
140+
});
141+
```
142+
134143
Use the same `selectClaimChannels` policy with one-shot cron jobs when you need to claim a specific channel subset:
135144

136145
```typescript

typescript/packages/mechanisms/evm/src/batch-settlement/constants.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { keccak256, toBytes } from "viem";
44
export const BATCH_SETTLEMENT_SCHEME = "batch-settlement" as const;
55

66
/** Deployed address of the x402BatchSettlement contract. */
7-
export const BATCH_SETTLEMENT_ADDRESS = "0x8f79473b50d67733349191d7349FE45977d44AF7" as const;
7+
export const BATCH_SETTLEMENT_ADDRESS = "0x4020074e9dF2ce1deE5A9C1b5c3f541D02a10003" as const;
88

99
/** Deployed address of the ERC3009DepositCollector contract. */
1010
export const ERC3009_DEPOSIT_COLLECTOR_ADDRESS =
11-
"0xE9460Cb807D97325E70e41De191430Bea39497f5" as const;
11+
"0x4020806089470a89826cB9fB1f4059150b550004" as const;
1212

1313
/** Deployed address of the Permit2DepositCollector contract. */
1414
export const PERMIT2_DEPOSIT_COLLECTOR_ADDRESS =
15-
"0x1D859871C289cB1e28DB38077272244C6343F7B9" as const;
15+
"0x4020425FAf3B746C082C2f942b4E5159887B0005" as const;
1616

1717
/** Minimum withdraw delay in seconds (15 minutes), matching the onchain constant. */
1818
export const MIN_WITHDRAW_DELAY = 900;

0 commit comments

Comments
 (0)