From 7eb923e6068d9fe36fd585448ff79413edc046c4 Mon Sep 17 00:00:00 2001 From: Paul <108695806+pxrl@users.noreply.github.com> Date: Thu, 6 Feb 2025 15:36:52 +0000 Subject: [PATCH 1/6] fix: Use tsc-friendly assert This helps with tsc type inference. --- src/clients/BundleDataClient/BundleDataClient.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clients/BundleDataClient/BundleDataClient.ts b/src/clients/BundleDataClient/BundleDataClient.ts index 3d266014..ee94d0ed 100644 --- a/src/clients/BundleDataClient/BundleDataClient.ts +++ b/src/clients/BundleDataClient/BundleDataClient.ts @@ -1,3 +1,4 @@ +import assert from "assert"; import _ from "lodash"; import { ProposedRootBundle, @@ -24,7 +25,6 @@ import { bnZero, queryHistoricalDepositForFill, assign, - assert, fixedPointAdjustment, isDefined, toBN, @@ -388,7 +388,7 @@ export class BundleDataClient { const fill = await verifyFillRepayment( _fill, this.spokePoolClients[_fill.destinationChainId].spokePool.provider, - matchingDeposit!, + matchingDeposit, this.clients.hubPoolClient ); if (!isDefined(fill)) { From 099c1858ce6c8a63f5eed28e52accadfaf071ad4 Mon Sep 17 00:00:00 2001 From: nicholaspai Date: Thu, 6 Feb 2025 10:53:20 -0500 Subject: [PATCH 2/6] Clean up more !'s --- .../BundleDataClient/BundleDataClient.ts | 59 +++++++++++-------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/src/clients/BundleDataClient/BundleDataClient.ts b/src/clients/BundleDataClient/BundleDataClient.ts index ee94d0ed..a3f14939 100644 --- a/src/clients/BundleDataClient/BundleDataClient.ts +++ b/src/clients/BundleDataClient/BundleDataClient.ts @@ -399,7 +399,7 @@ export class BundleDataClient { this.clients.hubPoolClient, blockRanges, this.chainIdListForBundleEvaluationBlockNumbers, - matchingDeposit!.fromLiteChain // Use ! because we've already asserted that matchingDeposit is defined. + matchingDeposit.fromLiteChain ); // Assume that lp fees are 0 for the sake of speed. In the future we could batch compute // these or make hardcoded assumptions based on the origin-repayment chain direction. This might result @@ -862,16 +862,21 @@ export class BundleDataClient { slowFillRequest: undefined, }; } else { - v3RelayHashes[relayDataHash].deposits!.push(deposit); + assert(isDefined(v3RelayHashes[relayDataHash].deposits), "Deposit should exist in relay hash dictionary."); + v3RelayHashes[relayDataHash].deposits.push(deposit); } // Account for duplicate deposits by concatenating the relayDataHash with the count of the number of times // we have seen it so far. - const newBundleDepositHash = `${relayDataHash}@${v3RelayHashes[relayDataHash].deposits!.length - 1}`; + assert( + isDefined(v3RelayHashes[relayDataHash].deposits) && v3RelayHashes[relayDataHash].deposits.length > 0, + "Deposit should exist in relay hash dictionary." + ); + const newBundleDepositHash = `${relayDataHash}@${v3RelayHashes[relayDataHash].deposits.length - 1}`; const decodedBundleDepositHash = decodeBundleDepositHash(newBundleDepositHash); assert( decodedBundleDepositHash.relayDataHash === relayDataHash && - decodedBundleDepositHash.index === v3RelayHashes[relayDataHash].deposits!.length - 1, + decodedBundleDepositHash.index === v3RelayHashes[relayDataHash].deposits.length - 1, "Not using correct bundle deposit hash key" ); if (deposit.blockNumber >= originChainBlockRange[0]) { @@ -934,7 +939,7 @@ export class BundleDataClient { if (v3RelayHashes[relayDataHash]) { if (!v3RelayHashes[relayDataHash].fill) { assert( - isDefined(v3RelayHashes[relayDataHash].deposits) && v3RelayHashes[relayDataHash].deposits!.length > 0, + isDefined(v3RelayHashes[relayDataHash].deposits) && v3RelayHashes[relayDataHash].deposits.length > 0, "Deposit should exist in relay hash dictionary." ); v3RelayHashes[relayDataHash].fill = fill; @@ -942,7 +947,7 @@ export class BundleDataClient { const fillToRefund = await verifyFillRepayment( fill, destinationClient.spokePool.provider, - v3RelayHashes[relayDataHash].deposits![0], + v3RelayHashes[relayDataHash].deposits[0], this.clients.hubPoolClient ); if (!isDefined(fillToRefund)) { @@ -953,7 +958,7 @@ export class BundleDataClient { v3RelayHashes[relayDataHash].fill = fillToRefund; validatedBundleV3Fills.push({ ...fillToRefund, - quoteTimestamp: v3RelayHashes[relayDataHash].deposits![0].quoteTimestamp, + quoteTimestamp: v3RelayHashes[relayDataHash].deposits[0].quoteTimestamp, }); // Now that we know this deposit has been filled on-chain, identify any duplicate deposits @@ -964,7 +969,7 @@ export class BundleDataClient { // fill is from a prior bundle. Paying out the filler keeps the behavior consistent for how // we deal with duplicate deposits regardless if the deposit is matched with a pre-fill or // a current bundle fill. - const duplicateDeposits = v3RelayHashes[relayDataHash].deposits!.slice(1); + const duplicateDeposits = v3RelayHashes[relayDataHash].deposits.slice(1); duplicateDeposits.forEach((duplicateDeposit) => { if (isSlowFill(fill)) { updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit); @@ -982,7 +987,7 @@ export class BundleDataClient { // events. if ( fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill && - _canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposits![0]) + _canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposits[0]) ) { fastFillsReplacingSlowFills.push(relayDataHash); } @@ -1098,10 +1103,10 @@ export class BundleDataClient { return; } assert( - isDefined(v3RelayHashes[relayDataHash].deposits) && v3RelayHashes[relayDataHash].deposits!.length > 0, + isDefined(v3RelayHashes[relayDataHash].deposits) && v3RelayHashes[relayDataHash].deposits.length > 0, "Deposit should exist in relay hash dictionary." ); - const matchedDeposit = v3RelayHashes[relayDataHash].deposits![0]; + const matchedDeposit = v3RelayHashes[relayDataHash].deposits[0]; if ( slowFillRequest.blockNumber >= destinationChainBlockRange[0] && @@ -1191,11 +1196,9 @@ export class BundleDataClient { await mapAsync(bundleDepositHashes, async (depositHash) => { const { relayDataHash, index } = decodeBundleDepositHash(depositHash); const { deposits, fill, slowFillRequest } = v3RelayHashes[relayDataHash]; - if (!deposits || deposits.length === 0) { - throw new Error("Deposits should exist in relay hash dictionary."); - } + assert(isDefined(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary."); const deposit = deposits[index]; - if (!deposit) throw new Error("Deposit should exist in relay hash dictionary."); + assert(isDefined(deposit), "Deposit should exist in relay hash dictionary."); if (deposit.originChainId !== originChainId || deposit.destinationChainId !== destinationChainId) { return; } @@ -1207,7 +1210,7 @@ export class BundleDataClient { const fillToRefund = await verifyFillRepayment( fill, destinationClient.spokePool.provider, - v3RelayHashes[relayDataHash].deposits![0], + deposits[0], this.clients.hubPoolClient ); if (!isDefined(fillToRefund)) { @@ -1256,19 +1259,19 @@ export class BundleDataClient { // then we wouldn't be in this branch of the code. const prefill = await this.findMatchingFillEvent(deposit, destinationClient); assert(isDefined(prefill), `findFillEvent# Cannot find prefill: ${relayDataHash}`); - assert(getRelayEventKey(prefill!) === relayDataHash, "Relay hashes should match."); + assert(getRelayEventKey(prefill) === relayDataHash, "Relay hashes should match."); if (canRefundPrefills) { const verifiedFill = await verifyFillRepayment( - prefill!, + prefill, destinationClient.spokePool.provider, deposit, this.clients.hubPoolClient ); if (!isDefined(verifiedFill)) { - bundleUnrepayableFillsV3.push(prefill!); + bundleUnrepayableFillsV3.push(prefill); } else if (!isSlowFill(verifiedFill)) { validatedBundleV3Fills.push({ - ...verifiedFill!, + ...verifiedFill, quoteTimestamp: deposit.quoteTimestamp, }); } else { @@ -1383,14 +1386,19 @@ export class BundleDataClient { validatedBundleV3Fills.length > 0 ? this.clients.hubPoolClient.batchComputeRealizedLpFeePct( validatedBundleV3Fills.map((fill) => { - const matchedDeposit = v3RelayHashes[getRelayEventKey(fill)].deposits![0]; + const relayKey = getRelayEventKey(fill); + assert( + isDefined(v3RelayHashes[relayKey].deposits) && v3RelayHashes[relayKey].deposits.length > 0, + "Deposit should exist in relay hash dictionary." + ); + const matchedDeposit = v3RelayHashes[relayKey].deposits[0]; assert(isDefined(matchedDeposit), "Deposit should exist in relay hash dictionary."); const { chainToSendRefundTo: paymentChainId } = getRefundInformationFromFill( fill, this.clients.hubPoolClient, blockRangesForChains, chainIds, - matchedDeposit!.fromLiteChain + matchedDeposit.fromLiteChain ); return { ...fill, @@ -1427,14 +1435,17 @@ export class BundleDataClient { }); v3FillLpFees.forEach(({ realizedLpFeePct }, idx) => { const fill = validatedBundleV3Fills[idx]; - const associatedDeposit = v3RelayHashes[getRelayEventKey(fill)].deposits![0]; + const relayKey = getRelayEventKey(fill); + const { deposits } = v3RelayHashes[relayKey]; + assert(isDefined(deposits) && deposits.length > 0, "Deposits should exist in relay hash dictionary."); + const associatedDeposit = deposits[0]; assert(isDefined(associatedDeposit), "Deposit should exist in relay hash dictionary."); const { chainToSendRefundTo, repaymentToken } = getRefundInformationFromFill( fill, this.clients.hubPoolClient, blockRangesForChains, chainIds, - associatedDeposit!.fromLiteChain + associatedDeposit.fromLiteChain ); updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken, fill.relayer); }); From eaa2795778ebd871eeab1364e58d854a072baddf Mon Sep 17 00:00:00 2001 From: nicholaspai Date: Thu, 6 Feb 2025 11:14:48 -0500 Subject: [PATCH 3/6] remove local assert --- .../chain-queries/baseQuery.ts | 2 +- src/utils/CachingUtils.ts | 2 +- src/utils/LogUtils.ts | 14 +------------- test/SpokePoolClient.SpeedUp.ts | 2 +- test/SpokePoolClient.ValidateFill.ts | 2 +- test/relayFeeCalculator.test.ts | 2 +- test/utils/utils.ts | 18 +++++++++--------- 7 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/relayFeeCalculator/chain-queries/baseQuery.ts b/src/relayFeeCalculator/chain-queries/baseQuery.ts index 8de1399e..de144a6a 100644 --- a/src/relayFeeCalculator/chain-queries/baseQuery.ts +++ b/src/relayFeeCalculator/chain-queries/baseQuery.ts @@ -13,10 +13,10 @@ import { BigNumber, toBNWei, bnZero, - assert, chainIsOPStack, fixedPointAdjustment, } from "../../utils"; +import assert from "assert"; import { Logger, QueryInterface } from "../relayFeeCalculator"; import { Transport } from "viem"; import { getGasPriceEstimate } from "../../gasPriceOracle/oracle"; diff --git a/src/utils/CachingUtils.ts b/src/utils/CachingUtils.ts index 27c601c2..ec5271ab 100644 --- a/src/utils/CachingUtils.ts +++ b/src/utils/CachingUtils.ts @@ -1,6 +1,6 @@ import { DEFAULT_CACHING_SAFE_LAG, DEFAULT_CACHING_TTL } from "../constants"; import { CachingMechanismInterface, Deposit, Fill, SlowFillRequest } from "../interfaces"; -import { assert } from "./LogUtils"; +import assert from "assert"; import { composeRevivers, objectWithBigNumberReviver } from "./ReviverUtils"; import { getRelayHashFromEvent } from "./SpokeUtils"; import { getCurrentTime } from "./TimeUtils"; diff --git a/src/utils/LogUtils.ts b/src/utils/LogUtils.ts index c9d38e8d..dc88cc14 100644 --- a/src/utils/LogUtils.ts +++ b/src/utils/LogUtils.ts @@ -23,16 +23,4 @@ export function formattedLog( ...data, }); } -} - -/** - * Asserts the truth of a condition. If the condition is false, an error is thrown with the provided message. - * @param condition The condition to assert. - * @param message The message to throw if the condition is false. - * @throws Error if the condition is false. - */ -export function assert(condition: boolean, message: string): void { - if (!condition) { - throw new Error(message); - } -} +} \ No newline at end of file diff --git a/test/SpokePoolClient.SpeedUp.ts b/test/SpokePoolClient.SpeedUp.ts index 4a6fdc01..553614de 100644 --- a/test/SpokePoolClient.SpeedUp.ts +++ b/test/SpokePoolClient.SpeedUp.ts @@ -3,7 +3,6 @@ import { Deposit, SpeedUp } from "../src/interfaces"; import { bnOne, getMessageHash } from "../src/utils"; import { destinationChainId, originChainId } from "./constants"; import { - assert, assertPromiseError, Contract, BigNumber, @@ -18,6 +17,7 @@ import { getUpdatedV3DepositSignature, setupTokensForWallet, } from "./utils"; +import assert from "assert"; describe("SpokePoolClient: SpeedUp", function () { const ignoredFields = [ diff --git a/test/SpokePoolClient.ValidateFill.ts b/test/SpokePoolClient.ValidateFill.ts index 3012045d..c9222da4 100644 --- a/test/SpokePoolClient.ValidateFill.ts +++ b/test/SpokePoolClient.ValidateFill.ts @@ -14,7 +14,6 @@ import { } from "../src/utils"; import { CHAIN_ID_TEST_LIST, originChainId, destinationChainId, repaymentChainId } from "./constants"; import { - assert, expect, BigNumber, toBNWei, @@ -37,6 +36,7 @@ import { winston, lastSpyLogIncludes, } from "./utils"; +import assert from "assert"; import { MockConfigStoreClient, MockHubPoolClient, MockSpokePoolClient } from "./mocks"; let spokePool_1: Contract, erc20_1: Contract, spokePool_2: Contract, erc20_2: Contract, hubPool: Contract; diff --git a/test/relayFeeCalculator.test.ts b/test/relayFeeCalculator.test.ts index 4947de09..320f6781 100644 --- a/test/relayFeeCalculator.test.ts +++ b/test/relayFeeCalculator.test.ts @@ -16,7 +16,6 @@ import { BigNumber, Contract, SignerWithAddress, - assert, assertPromiseError, assertPromisePasses, buildDepositForRelayerFeeTest, @@ -28,6 +27,7 @@ import { setupTokensForWallet, makeCustomTransport, } from "./utils"; +import assert from "assert"; import { TOKEN_SYMBOLS_MAP } from "@across-protocol/constants"; import { EMPTY_MESSAGE, ZERO_ADDRESS } from "../src/constants"; import { SpokePool } from "@across-protocol/contracts"; diff --git a/test/utils/utils.ts b/test/utils/utils.ts index 1ded28ac..c9e7a175 100644 --- a/test/utils/utils.ts +++ b/test/utils/utils.ts @@ -31,7 +31,7 @@ import { EMPTY_MESSAGE, PROTOCOL_DEFAULT_CHAIN_ID_INDICES, ZERO_ADDRESS } from " import { SpyTransport } from "./SpyTransport"; chai.use(chaiExclude); -const assert = chai.assert; +const chaiAssert = chai.assert; export type SignerWithAddress = utils.SignerWithAddress; @@ -49,7 +49,7 @@ export const { zeroAddress, } = utils; -export { assert, BigNumber, expect, chai, Contract, sinon, toBN, toBNWei, toWei, utf8ToHex, winston }; +export { chaiAssert, BigNumber, expect, chai, Contract, sinon, toBN, toBNWei, toWei, utf8ToHex, winston }; const TokenRolesEnum = { OWNER: "0", @@ -71,7 +71,7 @@ export function deepEqualsWithBigNumber(x: unknown, y: unknown, omitKeys: string .sort() .map((key) => [key, y?.[key]]) ); - assert.deepStrictEqual(_.omit(sortedKeysX, omitKeys), _.omit(sortedKeysY, omitKeys)); + chaiAssert.deepStrictEqual(_.omit(sortedKeysX, omitKeys), _.omit(sortedKeysY, omitKeys)); return true; } @@ -86,7 +86,7 @@ export async function assertPromiseError(promise: Promise, errMessage?: st throw err; } if (errMessage) { - assert.isTrue(err.message.includes(errMessage)); + chaiAssert.isTrue(err.message.includes(errMessage)); } } } @@ -314,7 +314,7 @@ export async function depositV3( const lastEvent = events.at(-1); let args = lastEvent?.args; - assert.exists(args); + chaiAssert.exists(args); args = args!; const { blockNumber, transactionHash, transactionIndex, logIndex } = lastEvent!; @@ -351,14 +351,14 @@ export async function requestV3SlowFill( signer: SignerWithAddress ): Promise { const destinationChainId = Number(await spokePool.chainId()); - assert.notEqual(relayData.originChainId, destinationChainId); + chaiAssert.notEqual(relayData.originChainId, destinationChainId); await spokePool.connect(signer).requestV3SlowFill(relayData); const events = await spokePool.queryFilter(spokePool.filters.RequestedV3SlowFill()); const lastEvent = events.at(-1); let args = lastEvent!.args; - assert.exists(args); + chaiAssert.exists(args); args = args!; const { blockNumber, transactionHash, transactionIndex, logIndex } = lastEvent!; @@ -392,14 +392,14 @@ export async function fillV3Relay( repaymentChainId?: number ): Promise { const destinationChainId = Number(await spokePool.chainId()); - assert.notEqual(deposit.originChainId, destinationChainId); + chaiAssert.notEqual(deposit.originChainId, destinationChainId); await spokePool.connect(signer).fillV3Relay(deposit, repaymentChainId ?? destinationChainId); const events = await spokePool.queryFilter(spokePool.filters.FilledV3Relay()); const lastEvent = events.at(-1); let args = lastEvent!.args; - assert.exists(args); + chaiAssert.exists(args); args = args!; const { blockNumber, transactionHash, transactionIndex, logIndex } = lastEvent!; From b4f8fce180a97c1f556ac21484e26f29841d595f Mon Sep 17 00:00:00 2001 From: nicholaspai Date: Thu, 6 Feb 2025 11:25:12 -0500 Subject: [PATCH 4/6] Revert "Clean up more !'s" This reverts commit 099c1858ce6c8a63f5eed28e52accadfaf071ad4. --- .../BundleDataClient/BundleDataClient.ts | 59 ++++++++----------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/src/clients/BundleDataClient/BundleDataClient.ts b/src/clients/BundleDataClient/BundleDataClient.ts index a3f14939..519dc658 100644 --- a/src/clients/BundleDataClient/BundleDataClient.ts +++ b/src/clients/BundleDataClient/BundleDataClient.ts @@ -862,21 +862,20 @@ export class BundleDataClient { slowFillRequest: undefined, }; } else { - assert(isDefined(v3RelayHashes[relayDataHash].deposits), "Deposit should exist in relay hash dictionary."); - v3RelayHashes[relayDataHash].deposits.push(deposit); + const { deposits } = v3RelayHashes[relayDataHash]; + assert(isDefined(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary."); + deposits.push(deposit); } // Account for duplicate deposits by concatenating the relayDataHash with the count of the number of times // we have seen it so far. - assert( - isDefined(v3RelayHashes[relayDataHash].deposits) && v3RelayHashes[relayDataHash].deposits.length > 0, - "Deposit should exist in relay hash dictionary." - ); - const newBundleDepositHash = `${relayDataHash}@${v3RelayHashes[relayDataHash].deposits.length - 1}`; + const { deposits } = v3RelayHashes[relayDataHash]; + assert(isDefined(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary."); + const newBundleDepositHash = `${relayDataHash}@${deposits.length - 1}`; const decodedBundleDepositHash = decodeBundleDepositHash(newBundleDepositHash); assert( decodedBundleDepositHash.relayDataHash === relayDataHash && - decodedBundleDepositHash.index === v3RelayHashes[relayDataHash].deposits.length - 1, + decodedBundleDepositHash.index === deposits.length - 1, "Not using correct bundle deposit hash key" ); if (deposit.blockNumber >= originChainBlockRange[0]) { @@ -938,16 +937,14 @@ export class BundleDataClient { const relayDataHash = getRelayEventKey(fill); if (v3RelayHashes[relayDataHash]) { if (!v3RelayHashes[relayDataHash].fill) { - assert( - isDefined(v3RelayHashes[relayDataHash].deposits) && v3RelayHashes[relayDataHash].deposits.length > 0, - "Deposit should exist in relay hash dictionary." - ); + const { deposits } = v3RelayHashes[relayDataHash]; + assert(isDefined(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary."); v3RelayHashes[relayDataHash].fill = fill; if (fill.blockNumber >= destinationChainBlockRange[0]) { const fillToRefund = await verifyFillRepayment( fill, destinationClient.spokePool.provider, - v3RelayHashes[relayDataHash].deposits[0], + deposits[0], this.clients.hubPoolClient ); if (!isDefined(fillToRefund)) { @@ -958,7 +955,7 @@ export class BundleDataClient { v3RelayHashes[relayDataHash].fill = fillToRefund; validatedBundleV3Fills.push({ ...fillToRefund, - quoteTimestamp: v3RelayHashes[relayDataHash].deposits[0].quoteTimestamp, + quoteTimestamp: deposits[0].quoteTimestamp, }); // Now that we know this deposit has been filled on-chain, identify any duplicate deposits @@ -969,7 +966,7 @@ export class BundleDataClient { // fill is from a prior bundle. Paying out the filler keeps the behavior consistent for how // we deal with duplicate deposits regardless if the deposit is matched with a pre-fill or // a current bundle fill. - const duplicateDeposits = v3RelayHashes[relayDataHash].deposits.slice(1); + const duplicateDeposits = deposits.slice(1); duplicateDeposits.forEach((duplicateDeposit) => { if (isSlowFill(fill)) { updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit); @@ -987,7 +984,7 @@ export class BundleDataClient { // events. if ( fill.relayExecutionInfo.fillType === FillType.ReplacedSlowFill && - _canCreateSlowFillLeaf(v3RelayHashes[relayDataHash].deposits[0]) + _canCreateSlowFillLeaf(deposits[0]) ) { fastFillsReplacingSlowFills.push(relayDataHash); } @@ -1096,17 +1093,15 @@ export class BundleDataClient { if (v3RelayHashes[relayDataHash]) { if (!v3RelayHashes[relayDataHash].slowFillRequest) { v3RelayHashes[relayDataHash].slowFillRequest = slowFillRequest; - if (v3RelayHashes[relayDataHash].fill) { + const { deposits, fill } = v3RelayHashes[relayDataHash]; + if (fill) { // Exiting here assumes that slow fill requests must precede fills, so if there was a fill // following this slow fill request, then we would have already seen it. We don't need to check // for a fill older than this slow fill request. return; } - assert( - isDefined(v3RelayHashes[relayDataHash].deposits) && v3RelayHashes[relayDataHash].deposits.length > 0, - "Deposit should exist in relay hash dictionary." - ); - const matchedDeposit = v3RelayHashes[relayDataHash].deposits[0]; + assert(isDefined(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary."); + const matchedDeposit = deposits[0]; if ( slowFillRequest.blockNumber >= destinationChainBlockRange[0] && @@ -1196,9 +1191,11 @@ export class BundleDataClient { await mapAsync(bundleDepositHashes, async (depositHash) => { const { relayDataHash, index } = decodeBundleDepositHash(depositHash); const { deposits, fill, slowFillRequest } = v3RelayHashes[relayDataHash]; - assert(isDefined(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary."); + if (!deposits || deposits.length === 0) { + throw new Error("Deposits should exist in relay hash dictionary."); + } const deposit = deposits[index]; - assert(isDefined(deposit), "Deposit should exist in relay hash dictionary."); + if (!deposit) throw new Error("Deposit should exist in relay hash dictionary."); if (deposit.originChainId !== originChainId || deposit.destinationChainId !== destinationChainId) { return; } @@ -1386,12 +1383,9 @@ export class BundleDataClient { validatedBundleV3Fills.length > 0 ? this.clients.hubPoolClient.batchComputeRealizedLpFeePct( validatedBundleV3Fills.map((fill) => { - const relayKey = getRelayEventKey(fill); - assert( - isDefined(v3RelayHashes[relayKey].deposits) && v3RelayHashes[relayKey].deposits.length > 0, - "Deposit should exist in relay hash dictionary." - ); - const matchedDeposit = v3RelayHashes[relayKey].deposits[0]; + const { deposits } = v3RelayHashes[getRelayEventKey(fill)]; + assert(isDefined(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary."); + const matchedDeposit = deposits[0]; assert(isDefined(matchedDeposit), "Deposit should exist in relay hash dictionary."); const { chainToSendRefundTo: paymentChainId } = getRefundInformationFromFill( fill, @@ -1435,9 +1429,8 @@ export class BundleDataClient { }); v3FillLpFees.forEach(({ realizedLpFeePct }, idx) => { const fill = validatedBundleV3Fills[idx]; - const relayKey = getRelayEventKey(fill); - const { deposits } = v3RelayHashes[relayKey]; - assert(isDefined(deposits) && deposits.length > 0, "Deposits should exist in relay hash dictionary."); + const { deposits } = v3RelayHashes[getRelayEventKey(fill)]; + assert(isDefined(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary."); const associatedDeposit = deposits[0]; assert(isDefined(associatedDeposit), "Deposit should exist in relay hash dictionary."); const { chainToSendRefundTo, repaymentToken } = getRefundInformationFromFill( From ba0e42b1dfbb92a4597522fd5f0bb22a3196a12b Mon Sep 17 00:00:00 2001 From: nicholaspai Date: Thu, 6 Feb 2025 11:27:03 -0500 Subject: [PATCH 5/6] Update LogUtils.ts --- src/utils/LogUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/LogUtils.ts b/src/utils/LogUtils.ts index dc88cc14..f3c6b041 100644 --- a/src/utils/LogUtils.ts +++ b/src/utils/LogUtils.ts @@ -23,4 +23,4 @@ export function formattedLog( ...data, }); } -} \ No newline at end of file +} From 476e0c53f833b4bbb0a32088b058aa32630d7690 Mon Sep 17 00:00:00 2001 From: Paul <108695806+pxrl@users.noreply.github.com> Date: Thu, 6 Feb 2025 21:41:01 +0000 Subject: [PATCH 6/6] update --- test/SpokePoolClient.SpeedUp.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/SpokePoolClient.SpeedUp.ts b/test/SpokePoolClient.SpeedUp.ts index 553614de..01f2a5d9 100644 --- a/test/SpokePoolClient.SpeedUp.ts +++ b/test/SpokePoolClient.SpeedUp.ts @@ -17,7 +17,6 @@ import { getUpdatedV3DepositSignature, setupTokensForWallet, } from "./utils"; -import assert from "assert"; describe("SpokePoolClient: SpeedUp", function () { const ignoredFields = [ @@ -176,7 +175,7 @@ describe("SpokePoolClient: SpeedUp", function () { let updatedDeposit = spokePoolClient.getDepositsForDestinationChain(deposit.destinationChainId).at(-1); // Convoluted checks to help tsc narrow types. - assert.exists(updatedDeposit); + expect(updatedDeposit).to.exist; updatedDeposit = updatedDeposit!; if (lowestOutputAmount.eq(deposit.outputAmount)) { @@ -217,11 +216,11 @@ describe("SpokePoolClient: SpeedUp", function () { const testOriginChainId = field !== "originChainId" ? originChainId : originChainId + 1; const testDepositId = field !== "depositId" ? depositId : depositId.add(1); const testDepositor = field !== "depositor" ? depositor : (await ethers.getSigners())[0]; - assert.isTrue(field !== "depositor" || testDepositor.address !== depositor.address); // Sanity check + expect(field !== "depositor" || testDepositor.address !== depositor.address).to.be.true; // Sanity check const signature = await getUpdatedV3DepositSignature( testDepositor, - testDepositId.toNumber(), + testDepositId, testOriginChainId, updatedOutputAmount, updatedRecipient,