Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use multicall getEthBalance #46

Merged
merged 5 commits into from
Aug 12, 2024
Merged

feat: use multicall getEthBalance #46

merged 5 commits into from
Aug 12, 2024

Conversation

0xnigir1
Copy link
Collaborator

@0xnigir1 0xnigir1 commented Aug 9, 2024

🤖 Linear

Closes ZKS-147

Description

Use Multicall getEthBalance function to fetch Shared Bridge eth balance in the same multicall call

Copy link

linear bot commented Aug 9, 2024

ZKS-147 Promises optimizations

Check places where Promise.all or Multicall might be beneficial to reduce the delay of performing sequential requests/multiple RPC calls

  • libs/metrics/src/l1/l1MetricsService.ts

@0xnigir1 0xnigir1 requested review from 0xkenj1 and 0xyaco August 9, 2024 17:43
@@ -144,14 +149,19 @@ export class L1MetricsService {
args: [this.sharedBridge.address],
} as const;
}),
{
address: multicall3EthereumAddress,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets extract this value from chain, lets make sure that exist also

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

💯

@0xnigir1 0xnigir1 requested a review from 0xkenj1 August 9, 2024 20:23
} as const);
} else {
const [erc20Balances, ethBalance] = await Promise.all([
this.evmProviderService.multicall({
Copy link
Collaborator

@0xkenj1 0xkenj1 Aug 9, 2024

Choose a reason for hiding this comment

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

dont understand this ser, correct me if iam wrong but if you dont have multicall3Address u cant call .multical({...})

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah you're right

Copy link
Collaborator

@0xyaco 0xyaco left a comment

Choose a reason for hiding this comment

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

Same doubt as @0xkenj1, after that seems good to go 👌 👌

@0xnigir1 0xnigir1 requested review from 0xkenj1 and 0xyaco August 12, 2024 13:00
Comment on lines 166 to 171
balances = await Promise.all([
...addresses.map((tokenAddress) =>
this.evmProviderService.readContract(tokenAddress, erc20Abi, "balanceOf", [
this.sharedBridge.address,
]),
),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any possibility to have one of these calls being throttled by the RPC node err'ing with a 429?

Copy link
Collaborator Author

@0xnigir1 0xnigir1 Aug 12, 2024

Choose a reason for hiding this comment

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

it could but the current amount of tokens is not an issue from what i tested with llama rpc, there's the fine line between adding the pagination overhead when making multiple RPC requests too

Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a very edgy case that practically wont exist, however we are gona be having 429 when calling multiple methods, but we expect to tackle that issue with caching and viem fallback client

0xkenj1
0xkenj1 previously approved these changes Aug 12, 2024
Comment on lines 166 to 171
balances = await Promise.all([
...addresses.map((tokenAddress) =>
this.evmProviderService.readContract(tokenAddress, erc20Abi, "balanceOf", [
this.sharedBridge.address,
]),
),
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a very edgy case that practically wont exist, however we are gona be having 429 when calling multiple methods, but we expect to tackle that issue with caching and viem fallback client

@0xnigir1 0xnigir1 merged commit 30ca7ec into dev Aug 12, 2024
6 checks passed
@0xnigir1 0xnigir1 deleted the feat/l1-tvl-optimization branch August 12, 2024 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants