From 90d387eb8e57e9c27370959282568c248d2fe8f8 Mon Sep 17 00:00:00 2001 From: DC Date: Mon, 18 Dec 2023 17:38:49 -0800 Subject: [PATCH] api: send compressed ops to pimlico --- .../src/network/bundleCompression.ts | 3 ++- .../daimo-api/src/network/bundlerClient.ts | 27 +++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/packages/daimo-api/src/network/bundleCompression.ts b/packages/daimo-api/src/network/bundleCompression.ts index 06694f368..45800315c 100644 --- a/packages/daimo-api/src/network/bundleCompression.ts +++ b/packages/daimo-api/src/network/bundleCompression.ts @@ -17,6 +17,7 @@ import { NameRegistry } from "../contract/nameRegistry"; export interface CompressionInfo { inflatorAddr: Address; inflatorID: number; + opInflatorAddr: Address; opInflatorID: number; opInflatorCoinAddr: Address; opInflatorPaymaster: Address; @@ -44,7 +45,7 @@ export function compressBundle( return concatHex(ret); } -function compressOp( +export function compressOp( op: UserOpHex, info: CompressionInfo, nameReg: NameRegistry diff --git a/packages/daimo-api/src/network/bundlerClient.ts b/packages/daimo-api/src/network/bundlerClient.ts index 925f0e702..5c2860beb 100644 --- a/packages/daimo-api/src/network/bundlerClient.ts +++ b/packages/daimo-api/src/network/bundlerClient.ts @@ -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"; @@ -81,6 +81,7 @@ export class BundlerClient { this.compressionInfo = { inflatorAddr: perOpInflatorAddress, inflatorID, + opInflatorAddr, opInflatorID, opInflatorCoinAddr, opInflatorPaymaster, @@ -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) { @@ -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