Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/clients/HubPoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,26 +1021,32 @@ export class HubPoolClient extends BaseAbstractClient {
// only run iff a new token has been enabled. Will only append iff the info is not there already.
// Filter out any duplicate addresses. This might happen due to enabling, disabling and re-enabling a token.
if (eventsToQuery.includes("L1TokenEnabledForLiquidityProvision")) {
const uniqueL1Tokens = dedupArray(
const uniqueL1Tokens: string[] = dedupArray(
events["L1TokenEnabledForLiquidityProvision"].map((event) => String(event.args["l1Token"]))
);

const [tokenInfo, lpTokenInfo] = await Promise.all([
const { hubPool } = this;

// Generate multicall input for pooledTokens query.
const pooledTokensFn = "pooledTokens";
const multicall = uniqueL1Tokens.map((token) => hubPool.interface.encodeFunctionData(pooledTokensFn, [token]));

const [tokenInfo, lpTokenMulticall] = await Promise.all([
Promise.all(
uniqueL1Tokens.map(async (l1Token: string) => {
uniqueL1Tokens.map(async (l1Token) => {
const tokenInfo = await fetchTokenInfo(l1Token, this.hubPool.provider);
return {
...tokenInfo,
address: EvmAddress.from(l1Token),
};
})
),
Promise.all(
uniqueL1Tokens.map(
async (l1Token: string) => await this.hubPool.pooledTokens(l1Token, { blockTag: update.searchEndBlock })
)
),
hubPool.callStatic.multicall(multicall, { blockTag: update.searchEndBlock }),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nb. should only multicall if uniqueLpTokens.length > 0. Otherwise the multicall fails. This is currently causing some test failures.

]);
const lpTokenInfo = lpTokenMulticall.map((result: string) =>
hubPool.interface.decodeFunctionResult(pooledTokensFn, result)
);

for (const info of tokenInfo) {
if (!this.l1Tokens.find((token) => token.address.eq(info.address))) {
if (info.decimals > 0 && info.decimals <= 18) {
Expand All @@ -1051,7 +1057,7 @@ export class HubPoolClient extends BaseAbstractClient {
}
}

uniqueL1Tokens.forEach((token: string, i) => {
uniqueL1Tokens.forEach((token, i) => {
this.lpTokens[token] = {
lastLpFeeUpdate: lpTokenInfo[i].lastLpFeeUpdate,
liquidReserves: lpTokenInfo[i].liquidReserves,
Expand Down
Loading