diff --git a/libs/tx-builder/src/utils/constants.ts b/libs/tx-builder/src/utils/constants.ts index c73cf36a..2d07f88e 100644 --- a/libs/tx-builder/src/utils/constants.ts +++ b/libs/tx-builder/src/utils/constants.ts @@ -4,7 +4,7 @@ import { LOCAL_ABI } from '@daohaus/abis'; export const EXPIRY = '.proposalExpiry'; export const FORM = '.formValues'; export const CURRENT_DAO = '.daoId'; -export const gasBufferMultiplier = 5; +export const gasBufferMultiplier = 1.2; // buffers baalgas estimate export const BaalContractBase = { type: 'local', contractName: 'Baal', diff --git a/libs/tx-builder/src/utils/multicall.ts b/libs/tx-builder/src/utils/multicall.ts index e0cfc4b7..850894ae 100644 --- a/libs/tx-builder/src/utils/multicall.ts +++ b/libs/tx-builder/src/utils/multicall.ts @@ -14,6 +14,7 @@ import { MulticallArg, StringSearch, TXLego, + ACTION_GAS_LIMIT_ADDITION, } from '@daohaus/utils'; import { CONTRACT_KEYCHAINS, @@ -39,14 +40,14 @@ import { createViemClient } from '@daohaus/utils'; export const estimateFunctionalGas = async ({ chainId, - constractAddress, + contractAddress, from, value, data, rpcs = HAUS_RPC, }: { chainId: ValidNetwork; - constractAddress: string; + contractAddress: string; from: string; value: bigint; data: string; @@ -59,11 +60,13 @@ export const estimateFunctionalGas = async ({ const functionGasFees = await client.estimateGas({ account: from as EthAddress, - to: constractAddress as EthAddress, + to: contractAddress as EthAddress, value, data: data as `0x${string}`, }); + console.log('functionGasFees', functionGasFees); + return Number(functionGasFees); }; @@ -284,10 +287,12 @@ export const handleMulticallArg = async ({ export const gasEstimateFromActions = async ({ actions, + actionsCount, chainId, daoId, }: { actions: MetaTransaction[]; + actionsCount: number; chainId: ValidNetwork; daoId: string; safeId: string; // not used at the moment @@ -297,7 +302,7 @@ export const gasEstimateFromActions = async ({ async (action) => await estimateFunctionalGas({ chainId: chainId, - constractAddress: action.to, + contractAddress: action.to, from: daoId, // from value needs to be the safe module (baal) to estimate without revert value: BigInt(Number(action.value)), data: action.data, @@ -310,9 +315,13 @@ export const gasEstimateFromActions = async ({ (a, b) => (a || 0) + (b || 0), 0 ); + + // extra gas overhead when calling the dao from the baal safe + const baalOnlyGas = actionsCount * ACTION_GAS_LIMIT_ADDITION; + console.log('baalOnlyGas addtition', baalOnlyGas); console.log('totalGasEstimate', totalGasEstimate); - return totalGasEstimate; + return (totalGasEstimate || 0) + baalOnlyGas; }; export const handleEncodeMulticallArg = async ({ @@ -386,12 +395,14 @@ export const handleGasEstimate = async ({ } as MetaTransaction; const gasEstimate = await gasEstimateFromActions({ actions: encodeExecFromModule({ safeId, metaTx }), + actionsCount: actions.length, chainId, daoId, safeId, }); if (gasEstimate) { + // adds buffer to baalgas estimate const buffer = arg.bufferPercentage || gasBufferMultiplier; return Math.round(Number(gasEstimate) * Number(buffer)); } else { diff --git a/libs/utils/src/constants/proposals.ts b/libs/utils/src/constants/proposals.ts index 21c578b1..6f025533 100644 --- a/libs/utils/src/constants/proposals.ts +++ b/libs/utils/src/constants/proposals.ts @@ -105,8 +105,11 @@ export const PROPOSAL_FILTERS: Record = { failed: 'Defeated', expired: 'Expired', }; - -export const GAS_BUFFER_MULTIPLIER = 5; +// Processing gas estimate buffer +export const GAS_BUFFER_MULTIPLIER = 2; // Adding to the gas limit to account for cost of processProposal export const PROCESS_PROPOSAL_GAS_LIMIT_ADDITION = 150000; +// Adding to the gas limit to account for cost of each action +export const ACTION_GAS_LIMIT_ADDITION = 150000; + export const L2_ADDITIONAL_GAS = 5000000; diff --git a/libs/utils/src/utils/gas.ts b/libs/utils/src/utils/gas.ts index 8cfd470e..75094790 100644 --- a/libs/utils/src/utils/gas.ts +++ b/libs/utils/src/utils/gas.ts @@ -16,7 +16,6 @@ export const getGasCostEstimate = async ( ): Promise => { const feeDataNew = await fetchFeeData({ chainId: chainId as ValidNetwork }); - console.log('feeDataNew', feeDataNew); return ( Number(getProcessingGasLimit(gasLimit, chainId)) * Number(feeDataNew.maxFeePerGas || 0)