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: tvl by chain #39

Merged
merged 4 commits into from
Aug 7, 2024
Merged

feat: tvl by chain #39

merged 4 commits into from
Aug 7, 2024

Conversation

0xnigir1
Copy link
Collaborator

@0xnigir1 0xnigir1 commented Aug 7, 2024

🤖 Linear

Closes ZKS-76

Description

Retrieve TVL by Chain ID of Shared Bridge from static token list:

tvl(chainId: number) method implemented
added multicall method to EvmProviderService
uses multicall for fetching token balances
uses Pricing Service for fetching prices

Copy link

linear bot commented Aug 7, 2024

ZKS-76 TVL by chainId

Create a Batch contract to query token balances from specific chainId using the method chainBalance from theSharedBridge

Use same token list as for L1 TVL breakdown.

BridgeHub address: 0x303a465B659cBB0ab36eE643eA362c509EEb5213

SharedBridge address: 0xD7f9f54194C633F36CCD5F3da84ad4a1c38cB2cB

AC:

  • Batch contract implemented
  • unit tests for batch contract
  • EvmProvider batchRequest() method used
  • Unit tests for L1MetricsService

Copy link
Collaborator

@0xkenj1 0xkenj1 left a comment

Choose a reason for hiding this comment

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

looks good ser, just some comments

*/
private async fetchTokenBalancesByChain(chainId: number, addresses: Address[]) {
const chainIdBn = BigInt(chainId);
const balances = await this.evmProviderService.multicall({
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we also use multicall to fetchTokenBalances of the SharedBridge ??? I mean, watching this now, makes me wonder that we are adding some overhead by using a batching contract for just iterating over multiple calls and having no computation on it.

Let me know if you agree and i will added to tech debt

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 I thought it too jaja, sure add it to tech debt ser 🫡

>(
args: MulticallParameters<contracts, allowFailure>,
): Promise<MulticallReturnType<contracts, allowFailure>> {
if (!this.chain.contracts?.multicall3?.address) throw new MulticallNotFound();
Copy link
Collaborator

Choose a reason for hiding this comment

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

good catch here

@@ -269,4 +269,91 @@ describe("EvmProviderService", () => {
expect(returnValue).toEqual(arrayAbiFixture.args[0]);
});
});
describe("multicall", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets also add a test for the happy path

});
});

describe("EvmProviderService (with mocked chain)", () => {
Copy link
Collaborator

@0xkenj1 0xkenj1 Aug 7, 2024

Choose a reason for hiding this comment

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

may we just mock the chain instead of splitting the tests into 2 describes ?

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, in spanish criollo: "flashie"

@0xnigir1 0xnigir1 requested a review from 0xyaco August 7, 2024 13:05
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.

Good to go for me after addressing @0xkenj1's comments ✅

Comment on lines +3 to +4
// This is the address given to native ETH on L2 chains.
// See: https://github.com/matter-labs/era-contracts/blob/8a70bbbc48125f5bde6189b4e3c6a3ee79631678/l1-contracts/contracts/common/Config.sol#L105
Copy link
Collaborator

Choose a reason for hiding this comment

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

💯

@0xnigir1 0xnigir1 requested review from 0xkenj1 and 0xyaco August 7, 2024 15:13
@0xnigir1 0xnigir1 merged commit 9238bcc into dev Aug 7, 2024
6 checks passed
@0xnigir1 0xnigir1 deleted the feat/tvl-by-chain branch August 7, 2024 19:12
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