Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspai committed Mar 26, 2024
1 parent 6343e22 commit aed29be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
26 changes: 13 additions & 13 deletions src/dataworker/PoolRebalanceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function updateRunningBalanceForDeposit(
updateAmount: BigNumber
): void {
const l1TokenCounterpart = hubPoolClient.getL1TokenForL2TokenAtBlock(
sdkUtils.getDepositInputToken(deposit),
deposit.inputToken,
deposit.originChainId,
deposit.quoteBlockNumber
);
Expand Down Expand Up @@ -395,6 +395,16 @@ export function generateMarkdownForRootBundle(
const outputTokenDecimals = hubPoolClient.getTokenInfo(destinationChainId, outputToken).decimals;
const lpFeePct = sdkUtils.getSlowFillLeafLpFeePct(leaf);

// Scale amounts to 18 decimals for realizedLpFeePct computation.
const scaleBy = toBN(10).pow(18 - outputTokenDecimals);
const inputAmount = leaf.relayData.inputAmount.mul(scaleBy);
const updatedOutputAmount = leaf.updatedOutputAmount.mul(scaleBy);
assert(
inputAmount.gte(updatedOutputAmount),
"Unexpected output amount for slow fill on" +
` ${getNetworkName(leaf.relayData.originChainId)} depositId ${leaf.relayData.depositId}`
);

// @todo: When v2 types are removed, update the slowFill definition to be more precise about the memebr fields.
const slowFill: Record<string, string> = {
// Shorten select keys for ease of reading from Slack.
Expand All @@ -406,20 +416,10 @@ export function generateMarkdownForRootBundle(
message: leaf.relayData.message,
// Fee decimals is always 18. 1e18 = 100% so 1e16 = 1%.
realizedLpFeePct: `${formatFeePct(lpFeePct)}%`,
outputToken,
outputAmount: convertFromWei(updatedOutputAmount.toString(), 18), // tokens were scaled to 18 decimals.
};

// Scale amounts to 18 decimals for realizedLpFeePct computation.
const scaleBy = toBN(10).pow(18 - outputTokenDecimals);
const inputAmount = leaf.relayData.inputAmount.mul(scaleBy);
const updatedOutputAmount = leaf.updatedOutputAmount.mul(scaleBy);
assert(
inputAmount.gte(updatedOutputAmount),
"Unexpected output amount for slow fill on" +
` ${getNetworkName(leaf.relayData.originChainId)} depositId ${leaf.relayData.depositId}`
);

slowFill.outputToken = outputToken;
slowFill.outputAmount = convertFromWei(updatedOutputAmount.toString(), 18); // tokens were scaled to 18 decimals.
slowRelayLeavesPretty += `\n\t\t\t${index}: ${JSON.stringify(slowFill)}`;
});

Expand Down
1 change: 0 additions & 1 deletion test/Dataworker.buildRoots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ describe("Dataworker: Build merkle roots", async function () {
updateAllClients,
} = fastDataworkerResult);
await updateAllClients();
await updateAllClients();
const poolRebalanceRoot = await dataworkerInstance.buildPoolRebalanceRoot(
getDefaultBlockRange(1),
spokePoolClients
Expand Down

0 comments on commit aed29be

Please sign in to comment.