@capxul/mcp 1.2.3 → 2.0.0
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 +3 -5
- package/dist/{_esm-CC5QpzeQ.mjs → _esm-BJMBPEEJ.mjs} +113 -113
- package/dist/{chunk-B5meny8j.mjs → chunk-2rV9d50f.mjs} +1 -2
- package/dist/{eventemitter3-D-pLUuAN.mjs → eventemitter3-BAR9woZ4.mjs} +1 -1
- package/dist/{lib-Dn7-RQTV.mjs → lib-6VZsqqnl.mjs} +3 -3
- package/dist/{lib-CifIgXqP.mjs → lib-BPNIfCSS.mjs} +5 -5
- package/dist/{lib-BRkcywUv.mjs → lib-BuBlVXhu.mjs} +1 -1
- package/dist/lib-CMLhJW3x.mjs +3 -0
- package/dist/{lib-CnLS6gjn.mjs → lib-CQ44Cugp.mjs} +4 -4
- package/dist/lib-CQVjg2KA.mjs +3 -0
- package/dist/{lib-hCYuvdcy.mjs → lib-CQ_IHsde.mjs} +4 -4
- package/dist/lib-Cs29vVRx.mjs +3 -0
- package/dist/{lib-cc_08w0f.mjs → lib-DY_aksO0.mjs} +5 -5
- package/dist/{lib-B8hqwgiz.mjs → lib-DYnihSM4.mjs} +2 -2
- package/dist/lib-S7tWZSeq.mjs +3 -0
- package/dist/main.mjs +3296 -3689
- package/package.json +9 -11
- package/dist/alchemy-rpc-BuobS4-x.mjs +0 -2
- package/dist/alchemy-rpc-vGO5qErZ.mjs +0 -343
- package/dist/lib-BGlYlc2Y.mjs +0 -3
- package/dist/lib-BSq2-y-R.mjs +0 -3
- package/dist/lib-YbuuWTqT.mjs +0 -3
- package/dist/lib-yehPdjuB.mjs +0 -3
- package/dist/src-2B8HO-zu.mjs +0 -2244
- package/dist/src-HgvNZjX7.mjs +0 -2
- package/dist/src-Iv70gRG_.mjs +0 -10639
package/package.json
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capxul/mcp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"private": false,
|
|
5
|
-
"description": "Capxul MCP server
|
|
5
|
+
"description": "Capxul MCP server for auth, Account readiness, identity, Organizations, relationships, requests, destinations, and testnet funding over Streamable HTTP.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"ai-agents",
|
|
8
8
|
"capxul",
|
|
9
9
|
"cli",
|
|
10
10
|
"mcp",
|
|
11
11
|
"model-context-protocol",
|
|
12
|
-
"payments",
|
|
13
12
|
"stablecoin",
|
|
14
13
|
"web3"
|
|
15
14
|
],
|
|
@@ -45,22 +44,21 @@
|
|
|
45
44
|
"devDependencies": {
|
|
46
45
|
"@types/node": "^22.15.3",
|
|
47
46
|
"tsx": "^4.19.0",
|
|
48
|
-
"typescript": "
|
|
47
|
+
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
49
48
|
"vite": "npm:@voidzero-dev/vite-plus-core@0.1.23",
|
|
50
49
|
"vite-plus": "0.1.23",
|
|
51
|
-
"@capxul/backend": "0.1.
|
|
52
|
-
"@capxul/config": "0.1.
|
|
53
|
-
"@capxul/sdk": "
|
|
50
|
+
"@capxul/backend": "0.1.6",
|
|
51
|
+
"@capxul/config": "0.1.1",
|
|
52
|
+
"@capxul/sdk": "2.0.0",
|
|
54
53
|
"@capxul/types": "0.1.0",
|
|
54
|
+
"@capxul/typescript-config": "0.0.0",
|
|
55
55
|
"@capxul/wire": "0.1.0"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"dev": "vp exec tsx src/main.ts serve",
|
|
59
|
-
"check-types": "vp exec tsc -p tsconfig.json --noEmit",
|
|
59
|
+
"check-types": "vp exec ../../node_modules/@typescript/native/bin/tsc -p tsconfig.json --noEmit",
|
|
60
60
|
"lint": "vp lint --deny-warnings",
|
|
61
61
|
"build": "NODE_OPTIONS=--max-old-space-size=12288 vp pack",
|
|
62
|
-
"
|
|
63
|
-
"_vp-tasks-allowed": "vp-allowed: `test` + `test:coverage` are defined as cache-augmented tasks in vite.config.ts so vitest's self-writes don't bust input fingerprinting (#205).",
|
|
64
|
-
"grade": "vp exec tsx scripts/grade-run.ts"
|
|
62
|
+
"_vp-tasks-allowed": "vp-allowed: `test` + `test:coverage` are defined as cache-augmented tasks in vite.config.ts so vitest's self-writes don't bust input fingerprinting (#205)."
|
|
65
63
|
}
|
|
66
64
|
}
|
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
import { E as ENTRY_POINT_07_ADDRESS, U as CAPXUL_PAYMENTS_ADDRESS, W as CAPXUL_PAYMENTS_COMMITMENT_ABI, ft as Errors } from "./src-2B8HO-zu.mjs";
|
|
2
|
-
import { decodeFunctionResult, encodeFunctionData, isHex, toHex } from "viem";
|
|
3
|
-
//#region ../../packages/backend/convex/_shared/env.ts
|
|
4
|
-
function requireEnvOrThrow(name) {
|
|
5
|
-
const value = process.env[name];
|
|
6
|
-
if (!value || value.length === 0) throw Errors.envMissing(name);
|
|
7
|
-
return value;
|
|
8
|
-
}
|
|
9
|
-
function optionalEnv(name) {
|
|
10
|
-
const value = process.env[name];
|
|
11
|
-
return value && value.length > 0 ? value : void 0;
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region ../../packages/backend/convex/_shared/alchemyRpc.ts
|
|
15
|
-
const TX_HASH_HEX = /^0x[0-9a-fA-F]{64}$/;
|
|
16
|
-
function rethrowProvider(method) {
|
|
17
|
-
return (e) => {
|
|
18
|
-
throw Errors.providerError("alchemy", method, e);
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function parseAlchemyQuantity(value, operation, field) {
|
|
22
|
-
try {
|
|
23
|
-
return BigInt(value);
|
|
24
|
-
} catch (cause) {
|
|
25
|
-
throw Errors.providerError("alchemy", `${operation} ${field}`, `invalid ${field} ${value} (${String(cause)})`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Construct the Alchemy URL for a given chain. Single endpoint for both
|
|
30
|
-
* node (eth_*) and bundler (eth_getUserOperationReceipt) RPCs — Alchemy
|
|
31
|
-
* routes by method.
|
|
32
|
-
*/
|
|
33
|
-
function alchemyUrl(chainId) {
|
|
34
|
-
switch (chainId) {
|
|
35
|
-
case 84532: {
|
|
36
|
-
const baseSepoliaRpcUrl = optionalEnv("BASE_SEPOLIA_RPC_URL");
|
|
37
|
-
if (baseSepoliaRpcUrl !== void 0) return baseSepoliaRpcUrl.replace(/\/+$/, "");
|
|
38
|
-
return `https://base-sepolia.g.alchemy.com/v2/${requireEnvOrThrow("ALCHEMY_API_KEY")}`;
|
|
39
|
-
}
|
|
40
|
-
case 8453: return `https://base-mainnet.g.alchemy.com/v2/${requireEnvOrThrow("ALCHEMY_API_KEY")}`;
|
|
41
|
-
default: throw Errors.invalidInput("chainId", `unsupported chainId ${String(chainId)}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function isRecord(value) {
|
|
45
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
46
|
-
}
|
|
47
|
-
function isValidJsonRpcEnvelope(value) {
|
|
48
|
-
if (!isRecord(value) || value.jsonrpc !== "2.0" || value.id !== 1) return false;
|
|
49
|
-
return Object.hasOwn(value, "result") !== Object.hasOwn(value, "error");
|
|
50
|
-
}
|
|
51
|
-
function isValidJsonRpcError(value) {
|
|
52
|
-
return isRecord(value) && typeof value.code === "number" && Number.isInteger(value.code) && typeof value.message === "string";
|
|
53
|
-
}
|
|
54
|
-
var DefinitiveAlchemyJsonRpcRejection = class extends Error {
|
|
55
|
-
constructor() {
|
|
56
|
-
super("Alchemy returned an explicit JSON-RPC rejection");
|
|
57
|
-
this.name = "DefinitiveAlchemyJsonRpcRejection";
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
async function alchemyRpc(chainId, method, params) {
|
|
61
|
-
const url = alchemyUrl(chainId);
|
|
62
|
-
const res = await fetch(url, {
|
|
63
|
-
method: "POST",
|
|
64
|
-
headers: { "Content-Type": "application/json" },
|
|
65
|
-
body: JSON.stringify({
|
|
66
|
-
jsonrpc: "2.0",
|
|
67
|
-
id: 1,
|
|
68
|
-
method,
|
|
69
|
-
params
|
|
70
|
-
})
|
|
71
|
-
}).catch(rethrowProvider(method));
|
|
72
|
-
if (!res.ok) {
|
|
73
|
-
const body = await res.text().catch(() => "<no body>");
|
|
74
|
-
throw Errors.providerError("alchemy", `${method} ${res.status}`, body);
|
|
75
|
-
}
|
|
76
|
-
let json;
|
|
77
|
-
try {
|
|
78
|
-
json = await res.json();
|
|
79
|
-
} catch (cause) {
|
|
80
|
-
throw Errors.providerError("alchemy", `${method} json`, cause);
|
|
81
|
-
}
|
|
82
|
-
if (!isValidJsonRpcEnvelope(json)) throw Errors.providerError("alchemy", method, "malformed JSON-RPC envelope");
|
|
83
|
-
if (json.error !== void 0) {
|
|
84
|
-
if (!isValidJsonRpcError(json.error)) throw Errors.providerError("alchemy", method, "malformed JSON-RPC error");
|
|
85
|
-
throw Errors.providerError("alchemy", method, method === "eth_sendUserOperation" ? new DefinitiveAlchemyJsonRpcRejection() : json.error.message);
|
|
86
|
-
}
|
|
87
|
-
if (json.result === void 0) throw Errors.providerError("alchemy", method, "missing result");
|
|
88
|
-
return json.result;
|
|
89
|
-
}
|
|
90
|
-
function parseReceiptLogs(raw) {
|
|
91
|
-
if (raw === void 0 || raw === null) return [];
|
|
92
|
-
if (!Array.isArray(raw)) throw Errors.providerError("alchemy", "eth_getUserOperationReceipt", "logs is not an array");
|
|
93
|
-
return raw.map((entry) => {
|
|
94
|
-
if (typeof entry !== "object" || entry === null || typeof entry.address !== "string" || !Array.isArray(entry.topics) || typeof entry.data !== "string") throw Errors.providerError("alchemy", "eth_getUserOperationReceipt", `malformed receipt log: ${JSON.stringify(entry)}`);
|
|
95
|
-
const log = entry;
|
|
96
|
-
return {
|
|
97
|
-
address: log.address,
|
|
98
|
-
topics: log.topics.map((t) => {
|
|
99
|
-
if (typeof t !== "string") throw Errors.providerError("alchemy", "eth_getUserOperationReceipt", "non-string log topic");
|
|
100
|
-
return t;
|
|
101
|
-
}),
|
|
102
|
-
data: log.data,
|
|
103
|
-
...typeof log.logIndex === "string" ? { logIndex: hexToSafeInteger(log.logIndex, "eth_getUserOperationReceipt") } : {}
|
|
104
|
-
};
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
async function fetchUserOperationReceipt(args) {
|
|
108
|
-
const raw = await alchemyRpc(args.chainId, "eth_getUserOperationReceipt", [args.userOpHash]);
|
|
109
|
-
if (raw === null) return null;
|
|
110
|
-
if (typeof raw !== "object" || typeof raw.userOpHash !== "string" || typeof raw.sender !== "string" || typeof raw.success !== "boolean" || typeof raw.receipt !== "object" || typeof raw.receipt.blockNumber !== "string" || typeof raw.receipt.transactionHash !== "string") throw Errors.providerError("alchemy", "eth_getUserOperationReceipt", `unexpected shape: ${JSON.stringify(raw)}`);
|
|
111
|
-
return {
|
|
112
|
-
userOpHash: raw.userOpHash,
|
|
113
|
-
sender: raw.sender,
|
|
114
|
-
success: raw.success,
|
|
115
|
-
receipt: {
|
|
116
|
-
blockNumber: hexToSafeInteger(raw.receipt.blockNumber, "eth_getUserOperationReceipt"),
|
|
117
|
-
transactionHash: raw.receipt.transactionHash,
|
|
118
|
-
logs: parseReceiptLogs(raw.logs)
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Parse a hex-encoded JSON-RPC integer into a safe JS number. Throws
|
|
124
|
-
* `Errors.providerError` if the value exceeds `Number.MAX_SAFE_INTEGER`
|
|
125
|
-
* (would silently round under `parseInt` per `.claude/rules/numeric-parsing.md`).
|
|
126
|
-
*/
|
|
127
|
-
function hexToSafeInteger(hex, op) {
|
|
128
|
-
if (typeof hex !== "string" || !hex.startsWith("0x")) throw Errors.providerError("alchemy", op, `expected 0x-prefixed hex, got ${String(hex)}`);
|
|
129
|
-
let big;
|
|
130
|
-
try {
|
|
131
|
-
big = BigInt(hex);
|
|
132
|
-
} catch (cause) {
|
|
133
|
-
throw Errors.providerError("alchemy", op, `invalid hex integer: ${hex} (${String(cause)})`);
|
|
134
|
-
}
|
|
135
|
-
const n = Number(big);
|
|
136
|
-
if (!Number.isSafeInteger(n)) throw Errors.providerError("alchemy", op, `hex value ${hex} exceeds MAX_SAFE_INTEGER`);
|
|
137
|
-
return n;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Read an ERC-20 `balanceOf(holder)` via `eth_call` (canon §2 — RPC pull, no
|
|
141
|
-
* indexer). Returns the raw on-chain integer as a base-10 string so the SDK
|
|
142
|
-
* boundary owns the `fromWei` lift into a `Money` (canon §10). A `bigint`-safe
|
|
143
|
-
* string is returned rather than a `number` because token balances routinely
|
|
144
|
-
* exceed `Number.MAX_SAFE_INTEGER`.
|
|
145
|
-
*/
|
|
146
|
-
async function fetchErc20Balance(args) {
|
|
147
|
-
const BALANCE_OF_SELECTOR = "0x70a08231";
|
|
148
|
-
const holderHex = args.holderAddress.toLowerCase().replace(/^0x/, "");
|
|
149
|
-
if (!/^[0-9a-f]{40}$/.test(holderHex)) throw Errors.invalidInput("holderAddress", "must be 0x + 40 hex chars");
|
|
150
|
-
const calldata = `${BALANCE_OF_SELECTOR}${"0".repeat(24)}${holderHex}`;
|
|
151
|
-
const raw = await alchemyRpc(args.chainId, "eth_call", [{
|
|
152
|
-
to: args.tokenAddress,
|
|
153
|
-
data: calldata
|
|
154
|
-
}, "latest"]);
|
|
155
|
-
if (typeof raw !== "string" || !raw.startsWith("0x")) throw Errors.providerError("alchemy", "eth_call", `unexpected shape: ${String(raw)}`);
|
|
156
|
-
if (raw === "0x") throw Errors.providerError("alchemy", "eth_call", "empty balanceOf return (0x)");
|
|
157
|
-
let big;
|
|
158
|
-
try {
|
|
159
|
-
big = BigInt(raw);
|
|
160
|
-
} catch (cause) {
|
|
161
|
-
throw Errors.providerError("alchemy", "eth_call", `invalid balanceOf hex: ${raw} (${String(cause)})`);
|
|
162
|
-
}
|
|
163
|
-
return { rawBalance: big.toString(10) };
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Look up the first `CapxulPayments.CommitmentCreated` log emitted by a given
|
|
167
|
-
* creator at/after `fromBlock` (G3 · #546). The event is:
|
|
168
|
-
*
|
|
169
|
-
* event CommitmentCreated(uint256 indexed id, address indexed creator,
|
|
170
|
-
* address indexed recipient, address token, uint256 totalAmount,
|
|
171
|
-
* uint48 startTime, uint48 cliffTime, uint48 endTime, bytes32 documentHash,
|
|
172
|
-
* uint8 paymentType);
|
|
173
|
-
*
|
|
174
|
-
* `id` is the indexed first topic (`topics[1]`); `creator` is `topics[2]`.
|
|
175
|
-
* Filtering by `[topic0, null, paddedCreator]` narrows to this creator's
|
|
176
|
-
* commitments — the caller decodes `topics[1]` as the commitment id.
|
|
177
|
-
*/
|
|
178
|
-
async function fetchCommitmentCreatedLog(args) {
|
|
179
|
-
const creatorHex = args.creatorAddress.toLowerCase().replace(/^0x/, "");
|
|
180
|
-
if (!/^[0-9a-f]{40}$/.test(creatorHex)) throw Errors.invalidInput("creatorAddress", "must be 0x + 40 hex chars");
|
|
181
|
-
const paddedCreatorTopic = `0x${"0".repeat(24)}${creatorHex}`;
|
|
182
|
-
const logs = await alchemyRpc(args.chainId, "eth_getLogs", [{
|
|
183
|
-
address: args.contractAddress,
|
|
184
|
-
topics: [
|
|
185
|
-
args.topic0,
|
|
186
|
-
null,
|
|
187
|
-
paddedCreatorTopic
|
|
188
|
-
],
|
|
189
|
-
fromBlock: `0x${args.fromBlock.toString(16)}`,
|
|
190
|
-
toBlock: "latest"
|
|
191
|
-
}]);
|
|
192
|
-
if (!Array.isArray(logs)) throw Errors.providerError("alchemy", "eth_getLogs", "expected array");
|
|
193
|
-
for (const log of logs) {
|
|
194
|
-
if (typeof log.blockNumber !== "string" || typeof log.transactionHash !== "string") throw Errors.providerError("alchemy", "eth_getLogs", `malformed log entry: ${JSON.stringify(log)}`);
|
|
195
|
-
return {
|
|
196
|
-
address: log.address,
|
|
197
|
-
topics: log.topics,
|
|
198
|
-
data: log.data,
|
|
199
|
-
blockNumber: hexToSafeInteger(log.blockNumber, "eth_getLogs"),
|
|
200
|
-
transactionHash: log.transactionHash
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Read the on-chain `commitments(id)` struct from CapxulPayments via `eth_call`.
|
|
207
|
-
* Used to bind lifecycle evidence (claim/cancel/redirect) to the actual on-chain
|
|
208
|
-
* STATE — `requireSuccessfulUserOp` proves a UserOp succeeded from the expected
|
|
209
|
-
* Safe, but only this state read proves the UserOp performed the expected op on
|
|
210
|
-
* THIS commitment id. A never-created id reads back as the zero struct (creator
|
|
211
|
-
* == address(0)), so callers must treat a zero `creator` as "not found".
|
|
212
|
-
*/
|
|
213
|
-
async function fetchCommitmentState(args) {
|
|
214
|
-
const data = encodeFunctionData({
|
|
215
|
-
abi: CAPXUL_PAYMENTS_COMMITMENT_ABI,
|
|
216
|
-
functionName: "commitments",
|
|
217
|
-
args: [args.onchainCommitmentId]
|
|
218
|
-
});
|
|
219
|
-
const raw = await alchemyRpc(args.chainId, "eth_call", [{
|
|
220
|
-
to: CAPXUL_PAYMENTS_ADDRESS,
|
|
221
|
-
data
|
|
222
|
-
}, "latest"]);
|
|
223
|
-
if (typeof raw !== "string" || !raw.startsWith("0x")) throw Errors.providerError("alchemy", "eth_call commitments", `unexpected shape: ${String(raw)}`);
|
|
224
|
-
if (raw === "0x") throw Errors.providerError("alchemy", "eth_call commitments", "empty commitments() return (0x)");
|
|
225
|
-
let decoded;
|
|
226
|
-
try {
|
|
227
|
-
decoded = decodeFunctionResult({
|
|
228
|
-
abi: CAPXUL_PAYMENTS_COMMITMENT_ABI,
|
|
229
|
-
functionName: "commitments",
|
|
230
|
-
data: raw
|
|
231
|
-
});
|
|
232
|
-
} catch (cause) {
|
|
233
|
-
throw Errors.providerError("alchemy", "eth_call commitments", `decode failed: ${String(cause)}`);
|
|
234
|
-
}
|
|
235
|
-
const [creator, token, recipient, totalAmount, claimed, startTime, cliffTime, endTime, documentHash, paymentType, cancelled] = decoded;
|
|
236
|
-
return {
|
|
237
|
-
creator,
|
|
238
|
-
token,
|
|
239
|
-
recipient,
|
|
240
|
-
totalAmount,
|
|
241
|
-
claimed,
|
|
242
|
-
startTime: Number(startTime),
|
|
243
|
-
cliffTime: Number(cliffTime),
|
|
244
|
-
endTime: Number(endTime),
|
|
245
|
-
documentHash,
|
|
246
|
-
paymentType: Number(paymentType),
|
|
247
|
-
cancelled
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
const getNonceAbi = [{
|
|
251
|
-
type: "function",
|
|
252
|
-
name: "getNonce",
|
|
253
|
-
stateMutability: "view",
|
|
254
|
-
inputs: [{
|
|
255
|
-
name: "sender",
|
|
256
|
-
type: "address"
|
|
257
|
-
}, {
|
|
258
|
-
name: "key",
|
|
259
|
-
type: "uint192"
|
|
260
|
-
}],
|
|
261
|
-
outputs: [{
|
|
262
|
-
name: "nonce",
|
|
263
|
-
type: "uint256"
|
|
264
|
-
}]
|
|
265
|
-
}];
|
|
266
|
-
const EIP1559_BASE_FEE_BUFFER_MULTIPLIER = 2n;
|
|
267
|
-
/** Read the EntryPoint v0.7 nonce (key 0) for a sender — 0 for a fresh account. */
|
|
268
|
-
async function fetchEntryPointNonce(args) {
|
|
269
|
-
const data = encodeFunctionData({
|
|
270
|
-
abi: getNonceAbi,
|
|
271
|
-
functionName: "getNonce",
|
|
272
|
-
args: [args.sender, 0n]
|
|
273
|
-
});
|
|
274
|
-
const result = await alchemyRpc(args.chainId, "eth_call", [{
|
|
275
|
-
to: ENTRY_POINT_07_ADDRESS,
|
|
276
|
-
data
|
|
277
|
-
}, "latest"]);
|
|
278
|
-
try {
|
|
279
|
-
return BigInt(result);
|
|
280
|
-
} catch (cause) {
|
|
281
|
-
throw Errors.providerError("alchemy", "eth_call getNonce", `invalid nonce ${result} (${String(cause)})`);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
/** EIP-1559 max + priority fees with a 2x base-fee inclusion buffer. */
|
|
285
|
-
async function fetchUserOperationFees(args) {
|
|
286
|
-
const priority = parseAlchemyQuantity(await alchemyRpc(args.chainId, "eth_maxPriorityFeePerGas", []), "eth_maxPriorityFeePerGas", "maxPriorityFeePerGas");
|
|
287
|
-
const block = await alchemyRpc(args.chainId, "eth_getBlockByNumber", ["latest", false]);
|
|
288
|
-
if (block.baseFeePerGas === void 0) {
|
|
289
|
-
const blockRef = block.number ?? block.hash ?? "<unknown>";
|
|
290
|
-
throw Errors.providerError("alchemy", "eth_getBlockByNumber baseFeePerGas", `missing baseFeePerGas in latest block ${blockRef}: ${JSON.stringify(block)}`);
|
|
291
|
-
}
|
|
292
|
-
return {
|
|
293
|
-
maxFeePerGas: parseAlchemyQuantity(block.baseFeePerGas, "eth_getBlockByNumber", "baseFeePerGas") * EIP1559_BASE_FEE_BUFFER_MULTIPLIER + priority,
|
|
294
|
-
maxPriorityFeePerGas: priority
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
async function estimateUserOperationGas(args) {
|
|
298
|
-
const raw = await alchemyRpc(args.chainId, "eth_estimateUserOperationGas", [args.userOp, ENTRY_POINT_07_ADDRESS]);
|
|
299
|
-
if (typeof raw !== "object" || typeof raw.preVerificationGas !== "string" || typeof raw.verificationGasLimit !== "string" || typeof raw.callGasLimit !== "string") throw Errors.providerError("alchemy", "eth_estimateUserOperationGas", `unexpected shape: ${JSON.stringify(raw)}`);
|
|
300
|
-
return raw;
|
|
301
|
-
}
|
|
302
|
-
function optionalPaymasterHex(raw, method, field) {
|
|
303
|
-
const value = raw[field];
|
|
304
|
-
if (value === void 0) return void 0;
|
|
305
|
-
if (typeof value !== "string" || !isHex(value)) throw Errors.providerError("alchemy", method, `unexpected ${field}: expected hex string`);
|
|
306
|
-
return value;
|
|
307
|
-
}
|
|
308
|
-
async function paymasterRpc(method, args) {
|
|
309
|
-
const raw = await alchemyRpc(args.chainId, method, [
|
|
310
|
-
args.userOp,
|
|
311
|
-
ENTRY_POINT_07_ADDRESS,
|
|
312
|
-
toHex(args.chainId),
|
|
313
|
-
{ policyId: args.policyId }
|
|
314
|
-
]);
|
|
315
|
-
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw Errors.providerError("alchemy", method, `unexpected shape: ${JSON.stringify(raw)}`);
|
|
316
|
-
const result = raw;
|
|
317
|
-
const paymaster = optionalPaymasterHex(result, method, "paymaster");
|
|
318
|
-
const paymasterData = optionalPaymasterHex(result, method, "paymasterData");
|
|
319
|
-
const paymasterVerificationGasLimit = optionalPaymasterHex(result, method, "paymasterVerificationGasLimit");
|
|
320
|
-
const paymasterPostOpGasLimit = optionalPaymasterHex(result, method, "paymasterPostOpGasLimit");
|
|
321
|
-
return {
|
|
322
|
-
...paymaster === void 0 ? {} : { paymaster },
|
|
323
|
-
...paymasterData === void 0 ? {} : { paymasterData },
|
|
324
|
-
...paymasterVerificationGasLimit === void 0 ? {} : { paymasterVerificationGasLimit },
|
|
325
|
-
...paymasterPostOpGasLimit === void 0 ? {} : { paymasterPostOpGasLimit }
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
/** ERC-7677 stub paymaster data (for gas estimation). */
|
|
329
|
-
function getPaymasterStubData(args) {
|
|
330
|
-
return paymasterRpc("pm_getPaymasterStubData", args);
|
|
331
|
-
}
|
|
332
|
-
/** ERC-7677 final paymaster data (after gas estimation). */
|
|
333
|
-
function getPaymasterData(args) {
|
|
334
|
-
return paymasterRpc("pm_getPaymasterData", args);
|
|
335
|
-
}
|
|
336
|
-
/** Submit the signed UserOperation through the bundler — returns the userOpHash. */
|
|
337
|
-
async function sendUserOperation(args) {
|
|
338
|
-
const hash = await alchemyRpc(args.chainId, "eth_sendUserOperation", [args.userOp, ENTRY_POINT_07_ADDRESS]);
|
|
339
|
-
if (typeof hash !== "string" || !TX_HASH_HEX.test(hash)) throw Errors.providerError("alchemy", "eth_sendUserOperation", `unexpected hash: ${String(hash)}; expected 0x-prefixed 32-byte hex`);
|
|
340
|
-
return hash;
|
|
341
|
-
}
|
|
342
|
-
//#endregion
|
|
343
|
-
export { fetchEntryPointNonce as a, fetchUserOperationReceipt as c, sendUserOperation as d, fetchCommitmentState as i, getPaymasterData as l, estimateUserOperationGas as n, fetchErc20Balance as o, fetchCommitmentCreatedLog as r, fetchUserOperationFees as s, alchemyUrl as t, getPaymasterStubData as u };
|
package/dist/lib-BGlYlc2Y.mjs
DELETED
package/dist/lib-BSq2-y-R.mjs
DELETED
package/dist/lib-YbuuWTqT.mjs
DELETED
package/dist/lib-yehPdjuB.mjs
DELETED