Skip to content

Commit

Permalink
feat: more accurate fast fill time estimations
Browse files Browse the repository at this point in the history
  • Loading branch information
dohaki committed Mar 26, 2024
1 parent 0cd125b commit c7c60ea
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/utils/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { ERC20__factory } from "./typechain";
import { tagAddress } from "./format";
import { getProvider } from "./providers";
import { getFastFillTimeByRoute } from "./fill-times";
import { getConfig } from "utils";
import getApiEndpoint from "./serverless-api";
import { BridgeLimitInterface } from "./serverless-api/types";
Expand Down Expand Up @@ -105,7 +106,7 @@ export const getConfirmationDepositTime = (
): ConfirmationDepositTimeType => {
const config = getConfig();
const depositDelay = config.depositDelays()[fromChain] || 0;
const getTimeEstimateString = (
const getTimeEstimateRangeString = (
lowEstimate: number,
highEstimate: number
): {
Expand All @@ -123,21 +124,29 @@ export const getConfirmationDepositTime = (
};

if (amount.lte(limits.maxDepositInstant)) {
return getTimeEstimateString(1, 5);
const fastFillTimeInSeconds = getFastFillTimeByRoute(fromChain, toChain);
return {
formattedString:
fastFillTimeInSeconds < 60
? `~${Math.floor(fastFillTimeInSeconds)} seconds`
: `~${Math.floor(fastFillTimeInSeconds / 60)} minutes`,
lowEstimate: fastFillTimeInSeconds,
highEstimate: fastFillTimeInSeconds,
};
} else if (amount.lte(limits.maxDepositShortDelay)) {
// This is just a rough estimate of how long 2 bot runs (1-4 minutes allocated for each) + an arbitrum transfer of 3-10 minutes would take.
if (toChain === ChainId.ARBITRUM) return getTimeEstimateString(5, 15);
if (toChain === ChainId.ARBITRUM) return getTimeEstimateRangeString(5, 15);

// Optimism transfers take about 10-20 minutes anecdotally.
if (toChain === ChainId.OPTIMISM) {
return getTimeEstimateString(12, 25);
return getTimeEstimateRangeString(12, 25);
}

// Polygon transfers take 20-30 minutes anecdotally.
if (toChain === ChainId.POLYGON) return getTimeEstimateString(20, 35);
if (toChain === ChainId.POLYGON) return getTimeEstimateRangeString(20, 35);

// Typical numbers for an arbitrary L2.
return getTimeEstimateString(10, 30);
return getTimeEstimateRangeString(10, 30);
}

// If the deposit size is above those, but is allowed by the app, we assume the pool will slow relay it.
Expand Down
53 changes: 53 additions & 0 deletions src/utils/fill-times.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { ChainId } from "./constants";

// Based on avg. fill times for 75th percentile of past bridge transfers
const fastFillTimesSecondsFromTo = {
[ChainId.MAINNET]: {
[ChainId.OPTIMISM]: 32,
[ChainId.POLYGON]: 322.5,
[ChainId.ZK_SYNC]: 78.75,
[ChainId.BASE]: 174,
[ChainId.ARBITRUM]: 122,
},
[ChainId.OPTIMISM]: {
[ChainId.MAINNET]: 12,
[ChainId.POLYGON]: 388,
[ChainId.ZK_SYNC]: 6,
[ChainId.BASE]: 148,
[ChainId.ARBITRUM]: 9,
},
[ChainId.POLYGON]: {
[ChainId.MAINNET]: 70,
[ChainId.OPTIMISM]: 62,
[ChainId.ZK_SYNC]: 58,
[ChainId.BASE]: 178,
[ChainId.ARBITRUM]: 69,
},
[ChainId.ZK_SYNC]: {
[ChainId.MAINNET]: 12,
[ChainId.OPTIMISM]: 416,
[ChainId.POLYGON]: 20,
[ChainId.BASE]: 149,
[ChainId.ARBITRUM]: 237,
},
[ChainId.BASE]: {
[ChainId.MAINNET]: 12,
[ChainId.OPTIMISM]: 68,
[ChainId.POLYGON]: 144,
[ChainId.ZK_SYNC]: 5,
[ChainId.ARBITRUM]: 7,
},
[ChainId.ARBITRUM]: {
[ChainId.MAINNET]: 12,
[ChainId.OPTIMISM]: 247,
[ChainId.POLYGON]: 111,
[ChainId.ZK_SYNC]: 5,
[ChainId.BASE]: 139,
},
};

export function getFastFillTimeByRoute(fromChainId: number, toChainId: number) {
const fillTimeInSeconds = fastFillTimesSecondsFromTo[fromChainId][toChainId];

return fillTimeInSeconds || 60;
}

0 comments on commit c7c60ea

Please sign in to comment.