Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt committed Jan 16, 2025
1 parent 7f3d266 commit 820e507
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export const DefaultArbEvaluable = {
} as const;

export const TakeOrderV2EventAbi = parseAbi([orderbookAbi[13]]);
export const OrderbookQuoteAbi = parseAbi([orderbookAbi[14]]);

/**
* Arbitrum node interface address, used to get L1 gas limit.
Expand Down
12 changes: 7 additions & 5 deletions src/gas.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ChainId } from "sushi";
import { BigNumber } from "ethers";
import { getQuoteConfig } from "./utils";
import { encodeFunctionData, multicall3Abi, toHex } from "viem";
import { publicActionsL2, walletActionsL2 } from "viem/op-stack";
import { encodeFunctionData, multicall3Abi, parseAbi, toHex } from "viem";
import { BotConfig, BundledOrders, OperationState, RawTx, ViemClient } from "./types";
import { ArbitrumNodeInterfaceAbi, ArbitrumNodeInterfaceAddress, orderbookAbi } from "./abis";
import { ArbitrumNodeInterfaceAbi, ArbitrumNodeInterfaceAddress, OrderbookQuoteAbi } from "./abis";

/**
* Estimates gas cost of the given tx, also takes into account L1 gas cost if the chain is a special L2.
Expand Down Expand Up @@ -99,15 +99,16 @@ export async function getQuoteGas(
multicallAddressOverride?: string,
): Promise<bigint> {
if (config.chain.id === ChainId.ARBITRUM) {
// build the calldata of a quote call
const quoteConfig = getQuoteConfig(orderDetails.takeOrders[0]) as any;
quoteConfig.inputIOIndex = BigInt(quoteConfig.inputIOIndex);
quoteConfig.outputIOIndex = BigInt(quoteConfig.outputIOIndex);
quoteConfig.order.evaluable.bytecode = toHex(quoteConfig.order.evaluable.bytecode);
const multicallConfig = {
target: orderDetails.orderbook as `0x${string}`,
allowFailure: false,
allowFailure: true,
callData: encodeFunctionData({
abi: parseAbi([orderbookAbi[14]]),
abi: OrderbookQuoteAbi,
functionName: "quote",
args: [quoteConfig],
}),
Expand All @@ -123,9 +124,10 @@ export async function getQuoteGas(
config.viemClient.chain?.contracts?.multicall3?.address;
if (!multicallAddress) throw "unknown multicall address";

// call Arbitrum Node Interface for the calldata to get L1 gas
const result = await config.viemClient.simulateContract({
address: ArbitrumNodeInterfaceAddress,
abi: ArbitrumNodeInterfaceAbi,
address: ArbitrumNodeInterfaceAddress,
functionName: "gasEstimateL1Component",
args: [multicallAddress, false, calldata],
});
Expand Down

0 comments on commit 820e507

Please sign in to comment.