Skip to content

Commit

Permalink
improve: Remove incentiveBalance from type (#888)
Browse files Browse the repository at this point in the history
Leftover type from UBA work, we should remove.
  • Loading branch information
nicholaspai authored Feb 13, 2025
1 parent cd8f57e commit b22331b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 31 deletions.
6 changes: 1 addition & 5 deletions src/clients/HubPoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -793,16 +793,14 @@ export class HubPoolClient extends BaseAbstractClient {

public getRunningBalanceForToken(l1Token: string, executedRootBundle: ExecutedRootBundle): TokenRunningBalance {
let runningBalance = toBN(0);
let incentiveBalance = toBN(0);
if (executedRootBundle) {
const indexOfL1Token = executedRootBundle.l1Tokens
.map((l1Token) => l1Token.toLowerCase())
.indexOf(l1Token.toLowerCase());
runningBalance = executedRootBundle.runningBalances[indexOfL1Token];
incentiveBalance = executedRootBundle.incentiveBalances[indexOfL1Token];
}

return { runningBalance, incentiveBalance };
return { runningBalance };
}

async _update(eventNames: HubPoolEvent[]): Promise<HubPoolUpdate> {
Expand Down Expand Up @@ -1007,8 +1005,6 @@ export class HubPoolClient extends BaseAbstractClient {
);
}
executedRootBundle.runningBalances = runningBalances.slice(0, nTokens);
executedRootBundle.incentiveBalances =
runningBalances.length > nTokens ? runningBalances.slice(nTokens) : runningBalances.map(() => toBN(0));
this.executedRootBundles.push(executedRootBundle);
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/interfaces/HubPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,22 @@ export interface ExecutedRootBundle extends SortableEvent {
bundleLpFees: BigNumber[];
netSendAmounts: BigNumber[];
runningBalances: BigNumber[];
incentiveBalances: BigNumber[];
leafId: number;
l1Tokens: string[];
proof: string[];
}

export type ExecutedRootBundleStringified = Omit<
ExecutedRootBundle,
"bundleLpFees" | "netSendAmounts" | "runningBalances" | "incentiveBalances"
"bundleLpFees" | "netSendAmounts" | "runningBalances"
> & {
bundleLpFees: string[];
netSendAmounts: string[];
runningBalances: string[];
incentiveBalances: string[];
};

export type TokenRunningBalance = {
runningBalance: BigNumber;
incentiveBalance: BigNumber;
};

export interface RelayerRefundLeafWithGroup extends RelayerRefundLeaf {
Expand Down
26 changes: 9 additions & 17 deletions test/HubPoolClient.RootBundleEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe("HubPoolClient: RootBundle Events", function () {
it("gets most recent RootBundleExecuted event for chainID and L1 token", async function () {
const { tree: tree1, leaves: leaves1 } = await constructSimpleTree(toBNWei(100));
const { tree: tree2, leaves: leaves2 } = await constructSimpleTree(toBNWei(200));
let runningBalance: BigNumber, incentiveBalance: BigNumber;
let runningBalance: BigNumber;

await configStoreClient.update();
await hubPoolClient.update();
Expand All @@ -196,58 +196,52 @@ describe("HubPoolClient: RootBundle Events", function () {
await hubPool.connect(dataworker).executeRootBundle(...Object.values(leaves1[1]), tree1.getHexProof(leaves1[1]));
const firstRootBundleBlockNumber = await hubPool.provider.getBlockNumber();

({ runningBalance, incentiveBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
({ runningBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
firstRootBundleBlockNumber,
constants.originChainId,
l1Token_1.address
));
expect(runningBalance.eq(0)).to.be.true;
expect(incentiveBalance.eq(0)).to.be.true;
await hubPoolClient.update();

// Happy case where client returns most recent running balance for chain ID and l1 token.
({ runningBalance, incentiveBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
({ runningBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
firstRootBundleBlockNumber,
constants.originChainId,
l1Token_1.address
));
expect(runningBalance.eq(toBNWei(100))).to.be.true;
expect(incentiveBalance.eq(0)).to.be.true;

// Target block is before event.
({ runningBalance, incentiveBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
({ runningBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
0,
constants.originChainId,
l1Token_1.address
));
expect(runningBalance.eq(0)).to.be.true;
expect(incentiveBalance.eq(0)).to.be.true;

// chain ID and L1 token combination not found.
({ runningBalance, incentiveBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
({ runningBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
firstRootBundleBlockNumber,
constants.destinationChainId,
l1Token_1.address
));
expect(runningBalance.eq(0)).to.be.true;
expect(incentiveBalance.eq(0)).to.be.true;

({ runningBalance, incentiveBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
({ runningBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
firstRootBundleBlockNumber,
constants.originChainId,
timer.address
));
expect(runningBalance.eq(0)).to.be.true;
expect(incentiveBalance.eq(0)).to.be.true;

// Running balance at index of L1 token returned:
({ runningBalance, incentiveBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
({ runningBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
firstRootBundleBlockNumber,
constants.originChainId,
l1Token_2.address
));
expect(runningBalance.eq(toBNWei(200))).to.be.true;
expect(incentiveBalance.eq(0)).to.be.true;

// Propose and execute another root bundle:
await hubPool
Expand All @@ -260,21 +254,19 @@ describe("HubPoolClient: RootBundle Events", function () {
await hubPoolClient.update();

// Grabs most up to date running balance for block:
({ runningBalance, incentiveBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
({ runningBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
secondRootBundleBlockNumber,
constants.originChainId,
l1Token_1.address
));
expect(runningBalance.eq(toBNWei(200))).to.be.true; // Grabs second running balance
expect(incentiveBalance.eq(0)).to.be.true;

({ runningBalance, incentiveBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
({ runningBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
firstRootBundleBlockNumber,
constants.originChainId,
l1Token_1.address
));
expect(runningBalance.eq(toBNWei(100))).to.be.true; // Grabs first running balance
expect(incentiveBalance.eq(0)).to.be.true;
});

it("returns proposed and disputed bundles", async function () {
Expand Down
7 changes: 2 additions & 5 deletions test/utils/HubPoolUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export async function publishValidatedBundles(
hubPoolClient: MockHubPoolClient,
spokePoolClients: SpokePoolClientsByChain,
numberOfBundles: number,
_runningBalances?: BigNumber[],
_incentiveBalances?: BigNumber[]
_runningBalances?: BigNumber[]
): Promise<Record<number, { start: number; end: number }[]>> {
// Create a sets of unique block ranges per chain so that we have a lower chance of false positives
// when fetching the block ranges for a specific chain.
Expand All @@ -28,7 +27,6 @@ export async function publishValidatedBundles(
);

const runningBalances = _runningBalances ?? chainIds.map(() => toBN(0));
const incentiveBalances = _incentiveBalances ?? chainIds.map(() => toBN(0));
for (let i = 0; i < numberOfBundles; i++) {
const bundleEvaluationBlockNumbers = chainIds.map((chainId) => {
if (!expectedBlockRanges[chainId]) {
Expand Down Expand Up @@ -56,8 +54,7 @@ export async function publishValidatedBundles(
toBN(chainId),
l1Tokens, // l1Tokens
runningBalances, // bundleLpFees
runningBalances, // netSendAmounts
runningBalances.concat(incentiveBalances) // runningBalances
runningBalances // netSendAmounts
);
});

Expand Down

0 comments on commit b22331b

Please sign in to comment.