Skip to content

Commit 38fee16

Browse files
committed
feat: added alto transport
1 parent 7fc3f63 commit 38fee16

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

packages/common/src/exports/internal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export * from "../deploy/ensureDeployer";
55
export * from "../deploy/getContractAddress";
66
export * from "../deploy/getDeployer";
77
export * from "../transports/wiresaw";
8+
export * from "../transports/alto";
89
export * from "../transports/methods/getUserOperationReceipt";
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Chain, EIP1193RequestFn, Hex, http, Transport } from "viem";
2+
import { chainTransport } from "./chainTransport";
3+
4+
type AltoSendUserOperationResultuest = {
5+
txHash: Hex;
6+
userOpHash: Hex;
7+
};
8+
9+
type AltoOptions<transport extends Transport> = {
10+
/** alto-compatible transport */
11+
altoTransport: transport;
12+
/** fallback transport for all other RPC methods */
13+
fallbackDefaultTransport?: Transport;
14+
};
15+
16+
export function alto<const altoTransport extends Transport>(transports?: AltoOptions<altoTransport>): altoTransport {
17+
return ((opts) => {
18+
const { altoTransport } = transports ?? getDefaultTransports(opts.chain);
19+
20+
const { request: altoRequest, ...rest } = altoTransport(opts);
21+
22+
return {
23+
...rest,
24+
// TODO: type `request` so we don't have to cast
25+
async request(req): ReturnType<EIP1193RequestFn> {
26+
if (req.method === "eth_sendUserOperation") {
27+
console.log("sending user operation via pimlico_sendUserOperationNow", req);
28+
const result = (await altoRequest({
29+
...req,
30+
method: "pimlico_sendUserOperationNow",
31+
})) as AltoSendUserOperationResultuest;
32+
console.log("pimlico_sendUserOperationNow", result);
33+
return result;
34+
}
35+
36+
return await altoRequest(req);
37+
},
38+
};
39+
}) as altoTransport;
40+
}
41+
42+
function getDefaultTransports(chain?: Chain): AltoOptions<Transport> {
43+
if (!chain) {
44+
throw new Error("No chain or transports provided");
45+
}
46+
47+
const altoTransport = chainTransport(chain.rpcUrls.alto);
48+
if (!altoTransport) {
49+
throw new Error("Provided chain does not support alto");
50+
}
51+
52+
return {
53+
altoTransport,
54+
fallbackDefaultTransport: http(),
55+
};
56+
}

packages/entrykit/src/getBundlerTransport.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import { transactionQueue } from "@latticexyz/common/actions";
22
import { Chain, createClient, fallback, http, keccak256, stringToHex, webSocket } from "viem";
33
import { privateKeyToAccount } from "viem/accounts";
44
import { userOpExecutor } from "./quarry/transports/userOpExecutor";
5-
import { wiresaw } from "@latticexyz/common/internal";
5+
import { wiresaw, alto } from "@latticexyz/common/internal";
66

77
export function getBundlerTransport(chain: Chain) {
88
if ("wiresaw" in chain.rpcUrls) {
99
return wiresaw();
1010
}
11+
if ("alto" in chain.rpcUrls) {
12+
return alto();
13+
}
1114

1215
// TODO: bundler websocket
1316
const bundlerHttpUrl = chain.rpcUrls.bundler?.http[0];

0 commit comments

Comments
 (0)