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

Zero basis fees #5857

Merged
merged 7 commits into from
Mar 19, 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
1 change: 1 addition & 0 deletions ops/mainnet/prod/core/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ locals {
}
]
relayerFeeTolerance = 60
checkOnlyExecuteFee = true
environment = var.stage
database = {
url = local.default_db_url
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
},
"gitHead": "937a7cde93e6ac1e151c6374f48adf83d3fa4ec6",
"stableVersion": "2.0.0"
}
}
5 changes: 5 additions & 0 deletions packages/agents/sequencer/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ export const getEnvConfig = (
: configFile.relayerFeeTolerance
? configFile.relayerFeeTolerance
: DEFAULT_RELAYER_FEE_TOLERANCE,
checkOnlyExecuteFee: configJson.checkOnlyExecuteFee
? configJson.checkOnlyExecuteFee
: configFile.checkOnlyExecuteFee
? configFile.checkOnlyExecuteFee
: true,
};

const defaultConfirmations = chainData && (chainData.get("1")?.confirmations ?? 1 + 3);
Expand Down
1 change: 1 addition & 0 deletions packages/agents/sequencer/src/lib/entities/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const SequencerConfigSchema = Type.Object({
),
database: TDatabaseConfig,
relayerFeeTolerance: Type.Number({ minimum: 0, maximum: 100 }),
checkOnlyExecuteFee: Type.Boolean(),
});

export type SequencerConfig = Static<typeof SequencerConfigSchema>;
Expand Down
2 changes: 2 additions & 0 deletions packages/agents/sequencer/src/lib/helpers/relayerfee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export const canSubmitToRelayer = async (transfer: XTransfer): Promise<{ canSubm
},
chainData,
logger,
requestContext,
config.checkOnlyExecuteFee,
);

let relayerFeePaidUsd = constants.Zero;
Expand Down
1 change: 1 addition & 0 deletions packages/integration/test/constants/testnet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ export const SEQUENCER_CONFIG: Promise<SequencerConfig> = (async (): Promise<Seq
url: "postgres://postgres:qwerty@localhost:5432/connext?sslmode=disable",
},
relayerFeeTolerance: 20,
checkOnlyExecuteFee: false,
};
})();

Expand Down
20 changes: 20 additions & 0 deletions packages/utils/src/constants/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,26 @@ export const NATIVE_TOKEN = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
export const DEFAULT_GAS_ESTIMATES = {
execute: "400000",
executeL1: "20000",
// average gas of reconcile tx to L2 / batch size (n=10)
// - 350,000 for 1 tx batch
// - 1,200,000 for 10 tx batch
proveAndProcess: "120000",
// average gas of reconcile tx L1 costs on op
// - 43,000 1 tx batch
// - 220,000 10 tx batch
proveAndProcessL1: "20000",
// monthly costs in weth / monthly transfer count = weth cost per transfer
// weth. chaindata should be updated when switching between op and slow mode
messaging: "4500",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just wondering why we need messaging item here?

Does this only work in slow mode to go through AMB?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is for the optimistic messaging overhead

gasPriceFactor: "1000000000000000000",
};

export type GasEstimates = {
execute: string;
executeL1: string;
proveAndProcess: string;
proveAndProcessL1: string;
messaging: string;
gasPriceFactor: string;
};

Expand All @@ -23,11 +37,17 @@ export const getHardcodedGasLimits = async (

const execute = chainInfo.gasEstimates?.execute ?? DEFAULT_GAS_ESTIMATES.execute;
const executeL1 = chainInfo.gasEstimates?.executeL1 ?? DEFAULT_GAS_ESTIMATES.executeL1;
const proveAndProcess = chainInfo.gasEstimates?.proveAndProcess ?? DEFAULT_GAS_ESTIMATES.proveAndProcess;
const proveAndProcessL1 = chainInfo.gasEstimates?.proveAndProcessL1 ?? DEFAULT_GAS_ESTIMATES.proveAndProcessL1;
const messaging = chainInfo.gasEstimates?.messaging ?? DEFAULT_GAS_ESTIMATES.messaging;
const gasPriceFactor = chainInfo.gasEstimates?.gasPriceFactor ?? DEFAULT_GAS_ESTIMATES.gasPriceFactor;
const res = {
execute,
executeL1,
gasPriceFactor,
proveAndProcess,
proveAndProcessL1,
messaging,
} as GasEstimates;
return res;
};
3 changes: 3 additions & 0 deletions packages/utils/src/peripherals/chainData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export type ChainData = {
execute: string;
xcallL1: string;
executeL1: string;
proveAndProcess: string;
proveAndProcessL1: string;
messaging: string;
gasPriceFactor?: string;
};
};
Expand Down
23 changes: 19 additions & 4 deletions packages/utils/src/peripherals/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const calculateRelayerFee = async (
chainData: Map<string, ChainData>,
logger?: Logger,
_requestContext?: RequestContext,
onlyExecute = true,
): Promise<BigNumber> => {
const { requestContext, methodContext } = createLoggingContext(calculateRelayerFee.name, _requestContext);

Expand Down Expand Up @@ -57,26 +58,40 @@ export const calculateRelayerFee = async (
const {
execute: executeGasAmount,
executeL1: executeL1GasAmount,
proveAndProcess: proveAndProcessGasAmount,
proveAndProcessL1: proveAndProcessL1GasAmount,
messaging: messagingGasAmount,
gasPriceFactor,
} = await getHardcodedGasLimits(destinationDomain, chainData);
if (logger) {
logger.debug("Hardcoded gasLimits", requestContext, methodContext, {
execute: executeGasAmount,
executeL1: executeL1GasAmount,
proveAndProcess: proveAndProcessGasAmount,
proveAndProcessL1: proveAndProcessL1GasAmount,
messaging: messagingGasAmount,
gasPriceFactor,
});
}

const totalGasAmount = callDataGasAmount
? Number(executeGasAmount) + Number(callDataGasAmount)
: Number(executeGasAmount);
const baseGasFees =
Number(executeGasAmount) +
Number(onlyExecute ? 0 : proveAndProcessGasAmount) +
Number(onlyExecute ? 0 : messagingGasAmount);

const l1GasLimit =
destinationChainId == 10
? Number(executeL1GasAmount) + Number(onlyExecute ? 0 : proveAndProcessL1GasAmount)
: undefined;

const totalGasAmount = callDataGasAmount ? Number(baseGasFees) + Number(callDataGasAmount) : Number(executeGasAmount);
const [estimatedRelayerFee, originTokenPrice, destinationTokenPrice] = await Promise.all([
getGelatoEstimatedFee(
destinationChainId,
constants.AddressZero,
Number(totalGasAmount),
isHighPriority,
destinationChainId == 10 ? Number(executeL1GasAmount) : undefined,
l1GasLimit,
),
originNativeTokenPrice
? Promise.resolve(originNativeTokenPrice)
Expand Down
Loading