import { Fill } from "../../../interfaces"; import { getBlockRangeForChain, isSlowFill } from "../../../utils"; import { HubPoolClient } from "../../HubPoolClient"; export function getRefundInformationFromFill( fill: Fill, hubPoolClient: HubPoolClient, blockRangesForChains: number[][], chainIdListForBundleEvaluationBlockNumbers: number[], fromLiteChain: boolean ): { chainToSendRefundTo: number; repaymentToken: string; } { // Handle slow relay where repaymentChainId = 0. Slow relays always pay recipient on destination chain. // So, save the slow fill under the destination chain, and save the fast fill under its repayment chain. let chainToSendRefundTo = isSlowFill(fill) ? fill.destinationChainId : fill.repaymentChainId; // If the fill is for a deposit originating from the lite chain, the repayment chain is the origin chain // regardless of whether it is a slow or fast fill (we ignore slow fills but this is for posterity). if (fromLiteChain) { chainToSendRefundTo = fill.originChainId; } // Save fill data and associate with repayment chain and L2 token refund should be denominated in. const endBlockForMainnet = getBlockRangeForChain( blockRangesForChains, hubPoolClient.chainId, chainIdListForBundleEvaluationBlockNumbers )[1]; const l1TokenCounterpart = hubPoolClient.getL1TokenForL2TokenAtBlock( fill.inputToken, fill.originChainId, endBlockForMainnet ); const repaymentToken = hubPoolClient.getL2TokenForL1TokenAtBlock( l1TokenCounterpart, chainToSendRefundTo, endBlockForMainnet ); return { chainToSendRefundTo, repaymentToken, }; }