@one-source/api-mcp 5.3.0 → 5.3.1
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 +8 -5
- package/README.npm.md +8 -5
- package/README.repo.md +8 -5
- package/dist/x402.d.ts.map +1 -1
- package/dist/x402.js +99 -28
- package/dist/x402.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# onesource-api-mcp
|
|
2
2
|
|
|
3
|
-
MCP server for OneSource blockchain data.
|
|
3
|
+
MCP server for OneSource blockchain data. 27 named tools for balances, NFTs, transactions, events, and live chain queries via API key or x402 micropayments.
|
|
4
4
|
|
|
5
5
|
```
|
|
6
6
|
npx onesource-api-mcp
|
|
@@ -23,7 +23,7 @@ claude mcp add onesource-api -- npx onesource-api-mcp
|
|
|
23
23
|
}
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
## Tools (
|
|
26
|
+
## Tools (27)
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
### Live Chain Data (12 tools)
|
|
@@ -62,11 +62,12 @@ claude mcp add onesource-api -- npx onesource-api-mcp
|
|
|
62
62
|
| `1s_storage_read` | Read storage slot |
|
|
63
63
|
| `1s_tx_receipt` | Transaction receipt |
|
|
64
64
|
|
|
65
|
-
###
|
|
65
|
+
### Payments (2 tools)
|
|
66
66
|
|
|
67
67
|
| Tool | Description |
|
|
68
68
|
|------|-------------|
|
|
69
69
|
| `1s_payment_mode` | View or switch the x402 payment scheme (`exact` per-call vs `batch` payment channel) |
|
|
70
|
+
| `1s_refund` | Refund unused `batch` channel balance back to your wallet on demand |
|
|
70
71
|
|
|
71
72
|
|
|
72
73
|
## Networks
|
|
@@ -117,6 +118,8 @@ X402_PRIVATE_KEY=your-private-key-hex npx onesource-api-mcp
|
|
|
117
118
|
|
|
118
119
|
Payments default to the **exact** scheme (one USDC payment per call). For a burst of calls you can switch to **batch** settlement — a payment channel that funds many off-chain calls from a single on-chain deposit, settled with one claim — by calling the `1s_payment_mode` tool with `{ "mode": "batch" }`, or by setting `X402_PAYMENT_MODE=batch`. Both modes use the same wallet.
|
|
119
120
|
|
|
121
|
+
In batch mode the first paid call deposits `price × X402_DEPOSIT_MULTIPLIER` (default 10) up front, so a session typically over-funds the channel. Reclaim the unused balance whenever you're done with the `1s_refund` tool; idle channels are also auto-refunded by the receiver after a few hours. The deposit residual is always recoverable.
|
|
122
|
+
|
|
120
123
|
### No auth
|
|
121
124
|
|
|
122
125
|
Without either variable, tools work for free endpoints. Paid endpoints return 402 errors with a descriptive message.
|
|
@@ -132,8 +135,8 @@ Without either variable, tools work for free endpoints. Paid endpoints return 40
|
|
|
132
135
|
| `X402_PAYMENT_MODE` | `exact` | Initial x402 scheme: `exact` (per-call) or `batch` (payment channel). Switch in-session with the `1s_payment_mode` tool. |
|
|
133
136
|
| `X402_RPC_URL` | Base default | Base RPC endpoint used to submit channel deposits in batch mode |
|
|
134
137
|
| `X402_CHANNEL_DIR` | — | Directory to persist batch channel state across restarts. Unset = in-memory (channel lost on restart). |
|
|
135
|
-
| `X402_DEPOSIT_MULTIPLIER` | `
|
|
136
|
-
| `X402_CHANNEL_SALT` | zero | Batch mode: 32-byte hex salt to derive
|
|
138
|
+
| `X402_DEPOSIT_MULTIPLIER` | `10` | Batch mode: deposit = price × this multiplier, funding that many calls per channel. Unused balance is reclaimable via `1s_refund`. |
|
|
139
|
+
| `X402_CHANNEL_SALT` | zero | Batch mode: 32-byte hex salt to derive the starting channel id. The client auto-rotates to the next salt when a channel is exhausted or refunded. |
|
|
137
140
|
|
|
138
141
|
|
|
139
142
|
## License
|
package/README.npm.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# onesource-api-mcp
|
|
2
2
|
|
|
3
|
-
MCP server for OneSource blockchain data.
|
|
3
|
+
MCP server for OneSource blockchain data. 27 named tools for balances, NFTs, transactions, events, and live chain queries via API key or x402 micropayments.
|
|
4
4
|
|
|
5
5
|
```
|
|
6
6
|
npx onesource-api-mcp
|
|
@@ -23,7 +23,7 @@ claude mcp add onesource-api -- npx onesource-api-mcp
|
|
|
23
23
|
}
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
## Tools (
|
|
26
|
+
## Tools (27)
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
### Live Chain Data (12 tools)
|
|
@@ -62,11 +62,12 @@ claude mcp add onesource-api -- npx onesource-api-mcp
|
|
|
62
62
|
| `1s_storage_read` | Read storage slot |
|
|
63
63
|
| `1s_tx_receipt` | Transaction receipt |
|
|
64
64
|
|
|
65
|
-
###
|
|
65
|
+
### Payments (2 tools)
|
|
66
66
|
|
|
67
67
|
| Tool | Description |
|
|
68
68
|
|------|-------------|
|
|
69
69
|
| `1s_payment_mode` | View or switch the x402 payment scheme (`exact` per-call vs `batch` payment channel) |
|
|
70
|
+
| `1s_refund` | Refund unused `batch` channel balance back to your wallet on demand |
|
|
70
71
|
|
|
71
72
|
|
|
72
73
|
## Networks
|
|
@@ -117,6 +118,8 @@ X402_PRIVATE_KEY=your-private-key-hex npx onesource-api-mcp
|
|
|
117
118
|
|
|
118
119
|
Payments default to the **exact** scheme (one USDC payment per call). For a burst of calls you can switch to **batch** settlement — a payment channel that funds many off-chain calls from a single on-chain deposit, settled with one claim — by calling the `1s_payment_mode` tool with `{ "mode": "batch" }`, or by setting `X402_PAYMENT_MODE=batch`. Both modes use the same wallet.
|
|
119
120
|
|
|
121
|
+
In batch mode the first paid call deposits `price × X402_DEPOSIT_MULTIPLIER` (default 10) up front, so a session typically over-funds the channel. Reclaim the unused balance whenever you're done with the `1s_refund` tool; idle channels are also auto-refunded by the receiver after a few hours. The deposit residual is always recoverable.
|
|
122
|
+
|
|
120
123
|
### No auth
|
|
121
124
|
|
|
122
125
|
Without either variable, tools work for free endpoints. Paid endpoints return 402 errors with a descriptive message.
|
|
@@ -132,8 +135,8 @@ Without either variable, tools work for free endpoints. Paid endpoints return 40
|
|
|
132
135
|
| `X402_PAYMENT_MODE` | `exact` | Initial x402 scheme: `exact` (per-call) or `batch` (payment channel). Switch in-session with the `1s_payment_mode` tool. |
|
|
133
136
|
| `X402_RPC_URL` | Base default | Base RPC endpoint used to submit channel deposits in batch mode |
|
|
134
137
|
| `X402_CHANNEL_DIR` | — | Directory to persist batch channel state across restarts. Unset = in-memory (channel lost on restart). |
|
|
135
|
-
| `X402_DEPOSIT_MULTIPLIER` | `
|
|
136
|
-
| `X402_CHANNEL_SALT` | zero | Batch mode: 32-byte hex salt to derive
|
|
138
|
+
| `X402_DEPOSIT_MULTIPLIER` | `10` | Batch mode: deposit = price × this multiplier, funding that many calls per channel. Unused balance is reclaimable via `1s_refund`. |
|
|
139
|
+
| `X402_CHANNEL_SALT` | zero | Batch mode: 32-byte hex salt to derive the starting channel id. The client auto-rotates to the next salt when a channel is exhausted or refunded. |
|
|
137
140
|
|
|
138
141
|
|
|
139
142
|
## License
|
package/README.repo.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# onesource-api-mcp
|
|
2
2
|
|
|
3
|
-
MCP server for OneSource blockchain data.
|
|
3
|
+
MCP server for OneSource blockchain data. 27 named tools for balances, NFTs, transactions, events, and live chain queries via API key or x402 micropayments.
|
|
4
4
|
|
|
5
5
|
```
|
|
6
6
|
npx onesource-api-mcp
|
|
@@ -23,7 +23,7 @@ claude mcp add onesource-api -- npx onesource-api-mcp
|
|
|
23
23
|
}
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
## Tools (
|
|
26
|
+
## Tools (27)
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
### Live Chain Data (12 tools)
|
|
@@ -62,11 +62,12 @@ claude mcp add onesource-api -- npx onesource-api-mcp
|
|
|
62
62
|
| `1s_storage_read` | Read storage slot |
|
|
63
63
|
| `1s_tx_receipt` | Transaction receipt |
|
|
64
64
|
|
|
65
|
-
###
|
|
65
|
+
### Payments (2 tools)
|
|
66
66
|
|
|
67
67
|
| Tool | Description |
|
|
68
68
|
|------|-------------|
|
|
69
69
|
| `1s_payment_mode` | View or switch the x402 payment scheme (`exact` per-call vs `batch` payment channel) |
|
|
70
|
+
| `1s_refund` | Refund unused `batch` channel balance back to your wallet on demand |
|
|
70
71
|
|
|
71
72
|
|
|
72
73
|
## Networks
|
|
@@ -117,6 +118,8 @@ X402_PRIVATE_KEY=your-private-key-hex npx onesource-api-mcp
|
|
|
117
118
|
|
|
118
119
|
Payments default to the **exact** scheme (one USDC payment per call). For a burst of calls you can switch to **batch** settlement — a payment channel that funds many off-chain calls from a single on-chain deposit, settled with one claim — by calling the `1s_payment_mode` tool with `{ "mode": "batch" }`, or by setting `X402_PAYMENT_MODE=batch`. Both modes use the same wallet.
|
|
119
120
|
|
|
121
|
+
In batch mode the first paid call deposits `price × X402_DEPOSIT_MULTIPLIER` (default 10) up front, so a session typically over-funds the channel. Reclaim the unused balance whenever you're done with the `1s_refund` tool; idle channels are also auto-refunded by the receiver after a few hours. The deposit residual is always recoverable.
|
|
122
|
+
|
|
120
123
|
### No auth
|
|
121
124
|
|
|
122
125
|
Without either variable, tools work for free endpoints. Paid endpoints return 402 errors with a descriptive message.
|
|
@@ -132,8 +135,8 @@ Without either variable, tools work for free endpoints. Paid endpoints return 40
|
|
|
132
135
|
| `X402_PAYMENT_MODE` | `exact` | Initial x402 scheme: `exact` (per-call) or `batch` (payment channel). Switch in-session with the `1s_payment_mode` tool. |
|
|
133
136
|
| `X402_RPC_URL` | Base default | Base RPC endpoint used to submit channel deposits in batch mode |
|
|
134
137
|
| `X402_CHANNEL_DIR` | — | Directory to persist batch channel state across restarts. Unset = in-memory (channel lost on restart). |
|
|
135
|
-
| `X402_DEPOSIT_MULTIPLIER` | `
|
|
136
|
-
| `X402_CHANNEL_SALT` | zero | Batch mode: 32-byte hex salt to derive
|
|
138
|
+
| `X402_DEPOSIT_MULTIPLIER` | `10` | Batch mode: deposit = price × this multiplier, funding that many calls per channel. Unused balance is reclaimable via `1s_refund`. |
|
|
139
|
+
| `X402_CHANNEL_SALT` | zero | Batch mode: 32-byte hex salt to derive the starting channel id. The client auto-rotates to the next salt when a channel is exhausted or refunded. |
|
|
137
140
|
| `ONESOURCE_ANALYTICS` | `true` | Set `false` to disable all analytics |
|
|
138
141
|
| `ONESOURCE_ANALYTICS_URL` | `https://1s-analytics.vercel.app` | Dashboard endpoint for event ingestion (baked in by default) |
|
|
139
142
|
| `X402_ANALYTICS_KEY` | `onesource-api-mcp` | Bearer token for the analytics dashboard (baked in by default) |
|
package/dist/x402.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x402.d.ts","sourceRoot":"","sources":["../src/x402.ts"],"names":[],"mappings":"AA6BA,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"x402.d.ts","sourceRoot":"","sources":["../src/x402.ts"],"names":[],"mappings":"AA6BA,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,OAAO,CAAC;AAkB5C,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,MAAM,WAAW,eAAe;IAC9B,6DAA6D;IAC7D,OAAO,EAAE,OAAO,CAAC;IACjB,8BAA8B;IAC9B,IAAI,EAAE,WAAW,CAAC;IAClB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6EAA6E;IAC7E,cAAc,EAAE,OAAO,CAAC;CACzB;AAiCD,wBAAgB,SAAS,IAAI,eAAe,CAkF3C;AA4BD,8BAA8B;AAC9B,wBAAgB,cAAc,IAAI,WAAW,CAE5C;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAK7D;AAED,8DAA8D;AAC9D,wBAAgB,kBAAkB,IAAI,eAAe,CAEpD;AAuBD,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,OAAO,CAAC;IACZ,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAWD;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,YAAY,CAAC,CAgDhE"}
|
package/dist/x402.js
CHANGED
|
@@ -24,19 +24,22 @@ import { toClientEvmSigner } from '@x402/evm';
|
|
|
24
24
|
import { BatchSettlementEvmScheme } from '@x402/evm/batch-settlement/client';
|
|
25
25
|
import { FileClientChannelStorage } from '@x402/evm/batch-settlement/client/file-storage';
|
|
26
26
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
27
|
-
import { createPublicClient, http } from 'viem';
|
|
27
|
+
import { createPublicClient, http, numberToHex } from 'viem';
|
|
28
28
|
import { base } from 'viem/chains';
|
|
29
29
|
const ZERO_SALT = `0x${'0'.repeat(64)}`;
|
|
30
30
|
// Each channel's first paid call deposits depositMultiplier × the call price,
|
|
31
|
-
// funding that many calls before a top-up
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
// funding that many calls before a top-up is needed. We keep modest headroom
|
|
32
|
+
// (10 calls per deposit; e.g. 0.05 USDC at $0.005/call) rather than a large
|
|
33
|
+
// upfront lockup: top-ups are now safe — the gateway gates on confirmed onchain
|
|
34
|
+
// escrow (after the 2026-06-05 multiplier-5 free-call incident) and the client
|
|
35
|
+
// rotates the channel salt past dead/refunded channels — and any unspent
|
|
36
|
+
// balance is reclaimable via 1s_refund or the gateway's idle auto-refund.
|
|
37
|
+
// Override with X402_DEPOSIT_MULTIPLIER (SDK minimum is 3).
|
|
38
|
+
const DEFAULT_DEPOSIT_MULTIPLIER = 10;
|
|
39
|
+
// How many times one batch request will bump the channel salt to skip a dead
|
|
40
|
+
// channel before giving up (and letting the caller fall back to exact). Each
|
|
41
|
+
// bump is a fresh channelId; the failed verify that triggers it isn't charged.
|
|
42
|
+
const MAX_SALT_BUMPS = 8;
|
|
40
43
|
let _applied = false;
|
|
41
44
|
let _cachedResult;
|
|
42
45
|
// Runtime-mutable mode state. `setupX402` seeds it from X402_PAYMENT_MODE; the
|
|
@@ -48,6 +51,13 @@ let _batchAvailable = false;
|
|
|
48
51
|
// The batch-settlement client scheme, retained at module scope so the
|
|
49
52
|
// `1s_refund` tool can call its cooperative-refund flow after setup.
|
|
50
53
|
let _batchScheme;
|
|
54
|
+
// Batch fetch + the machinery to rebuild it under a new channel salt. The salt
|
|
55
|
+
// is rotated when the current channel is dead (exhausted/refunded), so a refund
|
|
56
|
+
// doesn't permanently strand the wallet's batch path on one channelId.
|
|
57
|
+
let _batchFetch;
|
|
58
|
+
let _buildBatch;
|
|
59
|
+
let _baseSalt = ZERO_SALT;
|
|
60
|
+
let _saltOffset = 0n;
|
|
51
61
|
function initialMode() {
|
|
52
62
|
return process.env.X402_PAYMENT_MODE?.trim().toLowerCase() === 'batch'
|
|
53
63
|
? 'batch'
|
|
@@ -76,7 +86,9 @@ export function setupX402() {
|
|
|
76
86
|
// Built eagerly but lazily funded: no on-chain deposit happens until the
|
|
77
87
|
// first paid request is made while in batch mode. If construction fails
|
|
78
88
|
// (e.g. RPC misconfig), fall back to exact-only rather than crashing the MCP.
|
|
79
|
-
|
|
89
|
+
//
|
|
90
|
+
// _buildBatch (re)constructs the scheme for a given salt so the dispatcher can
|
|
91
|
+
// rotate to a fresh channelId when the current channel is dead — see bumpSalt.
|
|
80
92
|
try {
|
|
81
93
|
const publicClient = createPublicClient({
|
|
82
94
|
chain: base,
|
|
@@ -84,35 +96,84 @@ export function setupX402() {
|
|
|
84
96
|
});
|
|
85
97
|
const batchSigner = toClientEvmSigner(account, publicClient);
|
|
86
98
|
const channelDir = process.env.X402_CHANNEL_DIR?.trim() || undefined;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
99
|
+
_baseSalt = process.env.X402_CHANNEL_SALT?.trim() || ZERO_SALT;
|
|
100
|
+
_saltOffset = 0n;
|
|
101
|
+
_buildBatch = (salt) => {
|
|
102
|
+
const batchScheme = new BatchSettlementEvmScheme(batchSigner, {
|
|
103
|
+
depositPolicy: { depositMultiplier: depositMultiplier() },
|
|
104
|
+
salt,
|
|
105
|
+
...(channelDir ? { storage: new FileClientChannelStorage({ directory: channelDir }) } : {}),
|
|
106
|
+
});
|
|
107
|
+
const batchClient = new x402Client();
|
|
108
|
+
batchClient.register('eip155:*', batchScheme);
|
|
109
|
+
_batchScheme = batchScheme;
|
|
110
|
+
_batchFetch = wrapFetchWithPayment(fetch, batchClient);
|
|
111
|
+
};
|
|
112
|
+
// Initial build uses the base salt verbatim (no numberToHex) — offset 0.
|
|
113
|
+
_buildBatch(_baseSalt);
|
|
96
114
|
_batchAvailable = true;
|
|
97
|
-
_batchScheme = batchScheme;
|
|
98
115
|
}
|
|
99
116
|
catch (err) {
|
|
100
117
|
_batchAvailable = false;
|
|
118
|
+
_batchFetch = undefined;
|
|
119
|
+
_buildBatch = undefined;
|
|
101
120
|
console.error(`[onesource-api] warning: batch payment scheme unavailable (${err instanceof Error ? err.message : String(err)}); falling back to exact-only`);
|
|
102
121
|
}
|
|
103
122
|
_enabled = true;
|
|
104
123
|
_address = account.address;
|
|
105
124
|
_mode = initialMode();
|
|
106
125
|
// If batch was requested but is unavailable, stay on exact.
|
|
107
|
-
if (_mode === 'batch' && !
|
|
126
|
+
if (_mode === 'batch' && !_batchFetch)
|
|
108
127
|
_mode = 'exact';
|
|
109
128
|
// Dispatcher: route each request through the active scheme. Reads `_mode`
|
|
110
|
-
// live so in-session switches
|
|
111
|
-
|
|
129
|
+
// and `_batchFetch` live so in-session mode switches and salt rotations take
|
|
130
|
+
// effect immediately. In batch mode, a "channel exhausted/refunded" 402 means
|
|
131
|
+
// the deterministic channelId is dead; rotate the salt to a fresh channel and
|
|
132
|
+
// retry, bounded by MAX_SALT_BUMPS, so a prior refund can't strand batch.
|
|
133
|
+
const dispatchFetch = async (input, init) => {
|
|
134
|
+
if (!(_mode === 'batch' && _batchFetch))
|
|
135
|
+
return exactFetch(input, init);
|
|
136
|
+
let resp = await _batchFetch(input, init);
|
|
137
|
+
let bumps = 0;
|
|
138
|
+
while (_mode === 'batch' && bumps < MAX_SALT_BUMPS && (await isDeadChannel402(resp))) {
|
|
139
|
+
if (!bumpSalt())
|
|
140
|
+
break;
|
|
141
|
+
bumps += 1;
|
|
142
|
+
resp = await _batchFetch(input, init);
|
|
143
|
+
}
|
|
144
|
+
return resp;
|
|
145
|
+
};
|
|
112
146
|
_applied = true;
|
|
113
147
|
_cachedResult = { enabled: true, address: account.address, fetch: dispatchFetch };
|
|
114
148
|
return _cachedResult;
|
|
115
149
|
}
|
|
150
|
+
// isDeadChannel402 reports whether a response is a "this channel can't be
|
|
151
|
+
// reused" rejection — the deterministic channelId is exhausted or was refunded,
|
|
152
|
+
// so the voucher's cumulative can't be backed. Detected from the gateway's 402
|
|
153
|
+
// body reason (cumulative_exceeds_balance / cumulative_below_claimed). Cloning
|
|
154
|
+
// leaves the original body readable for the caller when we don't retry.
|
|
155
|
+
async function isDeadChannel402(resp) {
|
|
156
|
+
if (!resp || resp.status !== 402)
|
|
157
|
+
return false;
|
|
158
|
+
try {
|
|
159
|
+
const text = await resp.clone().text();
|
|
160
|
+
return /cumulative_exceeds_balance|cumulative_below_claimed/.test(text);
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// bumpSalt advances the channel salt by one and rebuilds the batch scheme/fetch,
|
|
167
|
+
// so the next request opens a fresh channelId instead of the dead one. Returns
|
|
168
|
+
// false when batch isn't built (nothing to rebuild).
|
|
169
|
+
function bumpSalt() {
|
|
170
|
+
if (!_buildBatch)
|
|
171
|
+
return false;
|
|
172
|
+
_saltOffset += 1n;
|
|
173
|
+
const next = numberToHex(BigInt(_baseSalt) + _saltOffset, { size: 32 });
|
|
174
|
+
_buildBatch(next);
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
116
177
|
/** Current payment scheme. */
|
|
117
178
|
export function getPaymentMode() {
|
|
118
179
|
return _mode;
|
|
@@ -142,6 +203,10 @@ export function resetX402() {
|
|
|
142
203
|
_mode = 'exact';
|
|
143
204
|
_batchAvailable = false;
|
|
144
205
|
_batchScheme = undefined;
|
|
206
|
+
_batchFetch = undefined;
|
|
207
|
+
_buildBatch = undefined;
|
|
208
|
+
_baseSalt = ZERO_SALT;
|
|
209
|
+
_saltOffset = 0n;
|
|
145
210
|
}
|
|
146
211
|
// A batch-eligible (/api/chain/*) endpoint the refund flow probes for the
|
|
147
212
|
// channel's payment requirements (receiver, asset, receiverAuthorizer) — it's
|
|
@@ -182,6 +247,9 @@ export async function refundBatchChannel() {
|
|
|
182
247
|
const tx = settle?.transaction;
|
|
183
248
|
const balance = settle?.extra?.channelState?.balance;
|
|
184
249
|
const remaining = typeof balance === 'string' ? ` Remaining channel balance: ${atomicToUsdc(balance)} USDC.` : '';
|
|
250
|
+
// The refunded channel is now closed; advance the salt so the next batch
|
|
251
|
+
// burst opens a fresh channelId rather than re-deriving the dead one.
|
|
252
|
+
bumpSalt();
|
|
185
253
|
return {
|
|
186
254
|
ok: true,
|
|
187
255
|
transaction: tx,
|
|
@@ -190,20 +258,23 @@ export async function refundBatchChannel() {
|
|
|
190
258
|
};
|
|
191
259
|
}
|
|
192
260
|
catch (err) {
|
|
193
|
-
const
|
|
194
|
-
|
|
261
|
+
const raw = err instanceof Error ? err.message : String(err);
|
|
262
|
+
const lower = raw.toLowerCase();
|
|
263
|
+
if (lower.includes('no remaining balance') || lower.includes('amount_too_low')) {
|
|
195
264
|
return {
|
|
196
265
|
ok: false,
|
|
197
266
|
message: 'Nothing to refund — the channel has no unused balance (everything deposited has been spent or already refunded).',
|
|
198
267
|
};
|
|
199
268
|
}
|
|
200
|
-
if (
|
|
269
|
+
if (lower.includes('existing channel record')) {
|
|
201
270
|
return {
|
|
202
271
|
ok: false,
|
|
203
272
|
message: 'No payment channel found for this wallet. Open one by making a call in batch mode first (1s_payment_mode → batch).',
|
|
204
273
|
};
|
|
205
274
|
}
|
|
206
|
-
|
|
275
|
+
// Collapse the SDK's own "Refund failed:" prefix(es) so we don't double it.
|
|
276
|
+
const clean = raw.replace(/^(refund failed:\s*)+/i, '');
|
|
277
|
+
return { ok: false, message: `Refund failed: ${clean}` };
|
|
207
278
|
}
|
|
208
279
|
}
|
|
209
280
|
//# sourceMappingURL=x402.js.map
|
package/dist/x402.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x402.js","sourceRoot":"","sources":["../src/x402.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,wBAAwB,EAAE,MAAM,gDAAgD,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"x402.js","sourceRoot":"","sources":["../src/x402.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EA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|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@one-source/api-mcp",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MCP server for OneSource blockchain data — 27 named tools for balances, NFTs, transactions, events, live chain queries, and x402 payment-mode + refund control via x402",
|
|
6
6
|
"bin": {
|