Skip to content

Commit

Permalink
api: send compressed ops to pimlico
Browse files Browse the repository at this point in the history
  • Loading branch information
dcposch committed Jan 22, 2024
1 parent 059e9de commit 90d387e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/daimo-api/src/network/bundleCompression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { NameRegistry } from "../contract/nameRegistry";
export interface CompressionInfo {
inflatorAddr: Address;
inflatorID: number;
opInflatorAddr: Address;
opInflatorID: number;
opInflatorCoinAddr: Address;
opInflatorPaymaster: Address;
Expand Down Expand Up @@ -44,7 +45,7 @@ export function compressBundle(
return concatHex(ret);
}

function compressOp(
export function compressOp(
op: UserOpHex,
info: CompressionInfo,
nameReg: NameRegistry
Expand Down
27 changes: 22 additions & 5 deletions packages/daimo-api/src/network/bundlerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { trace } from "@opentelemetry/api";
import { BundlerJsonRpcProvider, Constants } from "userop";
import { Address, Hex, PublicClient, hexToBigInt, isHex } from "viem";

import { CompressionInfo, compressBundle } from "./bundleCompression";
import { CompressionInfo, compressOp } from "./bundleCompression";
import { ViemClient } from "./viemClient";
import { NameRegistry } from "../contract/nameRegistry";
import { OpIndexer } from "../contract/opIndexer";
Expand Down Expand Up @@ -81,6 +81,7 @@ export class BundlerClient {
this.compressionInfo = {
inflatorAddr: perOpInflatorAddress,
inflatorID,
opInflatorAddr,
opInflatorID,
opInflatorCoinAddr,
opInflatorPaymaster,
Expand All @@ -95,11 +96,11 @@ export class BundlerClient {
console.log(`[BUNDLER] submtting userOp: ${JSON.stringify(op)}`);
try {
assert(nameReg != null, "nameReg required");
const compressed = this.compress(op, nameReg);
const compressed = this.compressOp(op, nameReg);
// Simultanously get the opHash (view function) and submit the bundle
const [opHash] = await Promise.all([
this.getOpHash(op, viemClient.publicClient),
this.sendCompressedBundle(compressed, viemClient),
this.sendCompressedOpToBundler(compressed),
]);

if (this.opIndexer) {
Expand Down Expand Up @@ -139,11 +140,27 @@ export class BundlerClient {
});
}

compress(op: UserOpHex, nameReg: NameRegistry) {
compressOp(op: UserOpHex, nameReg: NameRegistry) {
if (this.compressionInfo == null) {
throw new Error("can't compress, inflator info not loaded");
}
return compressBundle(op, this.compressionInfo, nameReg);
return compressOp(op, this.compressionInfo, nameReg);
}

async sendCompressedOpToBundler(compressed: Hex) {
const { compressionInfo } = this;
assert(compressionInfo != null, "can't send compressed, info not loaded");

const n = compressed.length / 2 - 1;
console.log(`[BUNDLER] sending pimlico_sendCompressedOp, ${n} bytes`);

const method = "pimlico_sendCompressedUserOperation";
const result = await this.provider.send(method, [
compressed,
compressionInfo.opInflatorAddr,
Constants.ERC4337.EntryPoint,
]);
console.log(`[BUNDLER] ${method} result: ${JSON.stringify(result)}`);
}

/// Send compressed userop. This is about 4x cheaper than sending uncompressed
Expand Down

0 comments on commit 90d387e

Please sign in to comment.