-
Notifications
You must be signed in to change notification settings - Fork 24
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
refactor(getPools): use multicall3 #164
Conversation
WalkthroughWalkthroughThe updates enhance the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant getPools
participant multicallContract
participant systemContract
participant uniswapInterface
User->>getPools: Request pool data
getPools->>multicallContract: Aggregate calls for unique pairs
multicallContract->>systemContract: Fetch pairs data
systemContract-->>multicallContract: Return pairs data
multicallContract-->>getPools: Return aggregated data
getPools->>uniswapInterface: Decode token addresses and reserves
getPools-->>User: Return formatted pools data
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- packages/client/src/getPools.ts (5 hunks)
- packages/client/src/multicall3.json (1 hunks)
Additional comments not posted (11)
packages/client/src/multicall3.json (1)
1-38
: LGTM! Ensure the ABI structure is correct.The ABI structure for the
aggregate
function looks correct. It includes inputs forcalls
and outputs forblockNumber
andreturnData
. Ensure that this ABI matches the actual contract's ABI to avoid runtime errors.packages/client/src/getPools.ts (10)
8-8
: New import for MULTICALL3_ABI.The new import for
MULTICALL3_ABI
is necessary for the multicall functionality.
10-14
: New type definition for Pair.The new
Pair
type definition improves type safety and clarity in the code.
48-52
: Improved logic for generating unique pairs.The new logic for generating unique pairs using the
Pair
type is clear and efficient.
61-66
: Integration of multicall functionality.The integration of the multicall contract using
MULTICALL3_ABI
is well-implemented and improves efficiency.
68-75
: Encoding function data for multicall.The encoding of function data for the multicall contract is correct and ensures that the correct data is passed to the contract.
77-91
: Handling return data from multicall.The logic for handling return data from the multicall contract is robust, with appropriate error handling for invalid data.
93-114
: Generating calls for token data and reserves.The generation of calls for token data and reserves using the multicall contract is efficient and well-structured.
116-118
: Fetching data using multicall.The fetching of data using the multicall contract is correctly implemented.
120-166
: Processing and decoding return data.The processing and decoding of return data is thorough, with appropriate error handling for missing or invalid data.
Line range hint
176-195
:
Formatting the return value.The formatting of the return value into
formattedPools
ensures consistency and clarity in the output.
@andresaiello please, review. |
@zeta-chain/fullstack please, review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
Left a small comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (2)
packages/client/src/getPools.ts (2)
48-50
: Ensure proper error handling ingetForeignCoins
method.The
getForeignCoins
method inpackages/client/src/getForeignCoins.ts
fetches data from an endpoint but lacks explicit error handling. To ensure robustness, consider adding error handling mechanisms such as try-catch blocks and response status checks.
- File:
packages/client/src/getForeignCoins.ts
- Lines to update:
export const getForeignCoins = async function (this: ZetaChainClient) { try { const api = await this.getEndpoint("cosmos-http", `zeta_${this.network}`); const endpoint = `${api}/zeta-chain/fungible/foreign_coins`; const response = await fetch(endpoint); if (!response.ok) { throw new Error(`Failed to fetch foreign coins: ${response.statusText}`); } const data = await response.json(); return data.foreignCoins; } catch (error) { console.error("Error retrieving foreign coins:", error); throw error; } };Analysis chain
Verify the correctness of foreign coin retrieval.
Ensure that the
getForeignCoins
method correctly retrieves foreign coins and handles potential errors.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness of foreign coin retrieval. # Test: Search for the `getForeignCoins` method implementation. Expect: Proper error handling. rg --type python -A 5 $'getForeignCoins'Length of output: 70
Script:
#!/bin/bash # Description: Verify the correctness of foreign coin retrieval. # Test: Search for the `getForeignCoins` method implementation. Expect: Proper error handling. ast-grep --lang typescript --pattern $'function getForeignCoins($_) { $$$ }'Length of output: 79
Script:
#!/bin/bash # Description: Broaden the search to find any method related to foreign coin retrieval. # Test: Search for any occurrence of "foreign" within function definitions or bodies in TypeScript files. rg 'foreign' --type ts -A 10Length of output: 10365
Script:
#!/bin/bash # Description: Extract the full implementation of the getForeignCoins method to examine its error handling. # Test: Extract the implementation of the getForeignCoins method from packages/client/src/getForeignCoins.ts. rg 'function getForeignCoins' -A 20 packages/client/src/getForeignCoins.tsLength of output: 76
Script:
#!/bin/bash # Description: Display the entire content of packages/client/src/getForeignCoins.ts to inspect the getForeignCoins method. # Test: Output the content of packages/client/src/getForeignCoins.ts. cat packages/client/src/getForeignCoins.tsLength of output: 412
93-113
: Issue Found: MissingUniswapV2Pair.json
The
UniswapV2Pair.json
file referenced inpackages/client/src/getPools.ts
is not present in the repository. This could lead to errors in ABI usage. Please verify and correct the reference to ensure the ABI is accurate and up-to-date.
- File:
packages/client/src/getPools.ts
- Lines: 93-113
Analysis chain
LGTM! Verify the
UniswapV2Pair
ABI.The logic for generating calls and processing return data is correct. Ensure the
UniswapV2Pair
ABI is accurate and up-to-date.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the `UniswapV2Pair` ABI. # Test: Search for the `UniswapV2Pair` ABI usage. Expect: Accurate and up-to-date ABI. rg --type python -A 5 $'UniswapV2Pair.abi'Length of output: 72
Script:
#!/bin/bash # Description: Verify the `UniswapV2Pair` ABI. # Test: Search for the `UniswapV2Pair` ABI usage. Expect: Accurate and up-to-date ABI. rg --type js -A 5 $'UniswapV2Pair.abi'Length of output: 37
Script:
#!/bin/bash # Description: Locate the `UniswapV2Pair` definition or usage. # Test: Search for the term "UniswapV2Pair" across all files. rg 'UniswapV2Pair'Length of output: 6880
Script:
#!/bin/bash # Description: Inspect the contents of `UniswapV2Pair.json` to verify the ABI. # Test: Display the contents of `UniswapV2Pair.json`. cat $(fd UniswapV2Pair.json)Length of output: 30
Script:
#!/bin/bash # Description: Locate the `UniswapV2Pair.json` file. # Test: Search for all JSON files to locate `UniswapV2Pair.json`. fd --type f --extension jsonLength of output: 122
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- packages/client/src/getPools.ts (5 hunks)
Additional comments not posted (6)
packages/client/src/getPools.ts (6)
10-14
: LGTM! ThePair
type enhances type safety and code clarity.The introduction of the
Pair
type is a positive change, providing a clear structure for token pairs.
8-9
: LGTM! The new import is necessary for multicall functionality.The import of
MULTICALL3_ABI
is appropriate and required for the multicall contract integration.
Line range hint
48-56
:
LGTM! The uniquePairs generation logic is sound.The use of the
Pair
type ensures unique token pairs and enhances code clarity.
77-92
: LGTM! The return data processing is appropriate.The error handling and filtering logic for the return data are correct and robust.
Line range hint
120-186
:
LGTM! The final data formatting is correct.The data formatting logic enhances the utility of the returned data and is correctly implemented.
61-75
: LGTM! Verify the multicall contract address.The multicall contract setup and call generation are correct. Ensure the multicall contract address is accurate and consistent across environments.
Verification successful
The multicall contract address is consistent across the codebase.
The address "0xca11bde05977b3631167028862be2a173976ca11" is used consistently in both
packages/client/src/getPools.ts
andpackages/client/src/getBalances.ts
.
packages/client/src/getPools.ts
packages/client/src/getBalances.ts
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the multicall contract address. # Test: Search for the multicall contract address usage. Expect: Consistent address across environments. rg --type python -A 5 $'0xca11bde05977b3631167028862be2a173976ca11'Length of output: 97
Script:
#!/bin/bash # Description: Verify the multicall contract address. # Test: Search for the multicall contract address usage. Expect: Consistent address across environments. rg --type js -A 5 $'0xca11bde05977b3631167028862be2a173976ca11'Length of output: 62
Script:
#!/bin/bash # Description: Verify the multicall contract address. # Test: Search for the multicall contract address usage. Expect: Consistent address across environments. rg -A 5 $'0xca11bde05977b3631167028862be2a173976ca11'Length of output: 874
Summary by CodeRabbit
New Features
aggregate
function to streamline contract interactions.Bug Fixes