Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve hedera support #318

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/rpc/estimation/gasEstimationHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UserOperation } from "@alto/types"
import type { ChainType, UserOperation } from "@alto/types"
import type { StateOverrides, UserOperationV07 } from "@alto/types"
import type { Hex } from "viem"
import type { SimulateHandleOpResult } from "./types"
Expand Down Expand Up @@ -56,6 +56,7 @@ export class GasEstimationHandler {
chainId: number,
blockTagSupport: boolean,
utilityWalletAddress: Address,
chainType: ChainType,
entryPointSimulationsAddress?: Address,
fixedGasLimitForEstimation?: bigint
) {
Expand All @@ -74,6 +75,7 @@ export class GasEstimationHandler {
entryPointSimulationsAddress,
blockTagSupport,
utilityWalletAddress,
chainType,
fixedGasLimitForEstimation
)
}
Expand Down
43 changes: 34 additions & 9 deletions src/rpc/estimation/gasEstimationsV07.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
ValidationErrors,
ExecutionErrors,
targetCallResultSchema,
RpcError
RpcError,
ChainType
} from "@alto/types"
import { getUserOperationHash, toPackedUserOperation } from "@alto/utils"
import {
Expand All @@ -40,6 +41,7 @@ export class GasEstimatorV07 {
blockTagSupport: boolean
utilityWalletAddress: Address
fixedGasLimitForEstimation?: bigint
chainType: ChainType

constructor(
binarySearchToleranceDelta: bigint,
Expand All @@ -49,6 +51,7 @@ export class GasEstimatorV07 {
entryPointSimulationsAddress: Address | undefined,
blockTagSupport: boolean,
utilityWalletAddress: Address,
chainType: ChainType,
fixedGasLimitForEstimation?: bigint
) {
this.binarySearchToleranceDelta = binarySearchToleranceDelta
Expand All @@ -58,6 +61,7 @@ export class GasEstimatorV07 {
this.entryPointSimulationsAddress = entryPointSimulationsAddress
this.blockTagSupport = blockTagSupport
this.utilityWalletAddress = utilityWalletAddress
this.chainType = chainType
this.fixedGasLimitForEstimation = fixedGasLimitForEstimation
}

Expand Down Expand Up @@ -302,14 +306,35 @@ export class GasEstimatorV07 {
queuedUserOperations
})

let cause = await this.callPimlicoEntryPointSimulations({
entryPoint,
entryPointSimulationsCallData: [
simulateHandleOpLast,
simulateCallData
],
stateOverrides
})
let cause

if (this.chainType === "hedera") {
// due to Hedera specific restrictions, we can't combine these two calls.
const [simulateHandleOpLastCause, simulateCallDataCause] =
await Promise.all([
this.callPimlicoEntryPointSimulations({
entryPoint,
entryPointSimulationsCallData: [simulateHandleOpLast],
stateOverrides
}),
this.callPimlicoEntryPointSimulations({
entryPoint,
entryPointSimulationsCallData: [simulateCallData],
stateOverrides
})
])

cause = [simulateHandleOpLastCause[0], simulateCallDataCause[0]]
} else {
cause = await this.callPimlicoEntryPointSimulations({
entryPoint,
entryPointSimulationsCallData: [
simulateHandleOpLast,
simulateCallData
],
stateOverrides
})
}

cause = cause.map((data: Hex) => {
const decodedDelegateAndError = decodeErrorResult({
Expand Down
8 changes: 7 additions & 1 deletion src/rpc/rpcHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import {
slice,
toFunctionSelector
} from "viem"
import { base, baseSepolia, optimism } from "viem/chains"
import { base, baseSepolia, hedera, optimism } from "viem/chains"
import type { NonceQueuer } from "./nonceQueuer"

export interface IRpcEndpoint {
Expand Down Expand Up @@ -423,6 +423,12 @@ export class RpcHandler implements IRpcEndpoint {
userOperation.verificationGasLimit = 5_000_000n
}

if (this.chainId === hedera.id) {
// The eth_call gasLimit is set to 12_500_000 on Hedera.
userOperation.verificationGasLimit = 5_000_000n
userOperation.callGasLimit = 4_500_000n
}

if (isVersion07(userOperation)) {
userOperation.paymasterPostOpGasLimit = 2_000_000n
userOperation.paymasterVerificationGasLimit = 5_000_000n
Expand Down
1 change: 1 addition & 0 deletions src/rpc/validation/UnsafeValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class UnsafeValidator implements InterfaceValidator {
publicClient.chain.id,
blockTagSupport,
utilityWalletAddress,
chainType,
entryPointSimulationsAddress,
fixedGasLimitForEstimation
)
Expand Down
Loading