zeta-chain / toolkit

A library of ZetaChain helper utilities, contracts, and Hardhat tasks for smart-contract development
MIT License
43 stars 22 forks source link

Support query solana balances #185

Closed lukema95 closed 1 month ago

lukema95 commented 2 months ago

Relevant issue: #180

Summary by CodeRabbit

coderabbitai[bot] commented 2 months ago
📝 Walkthrough
📝 Walkthrough ## Walkthrough The changes primarily involve updates to the `package.json`, `getBalances.ts`, and `balances.ts` files. The `package.json` file sees a version change for the `@zetachain/networks` package and the addition of the `bs58` package. The `getBalances.ts` function is modified to accept an additional `solanaAddress` parameter, enhancing its capability to handle multiple blockchain addresses. The `balances.ts` file is updated to support multiple blockchain addresses through new command-line flags and improved private key handling. ## Changes | File | Change Summary | |--------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `package.json` | - Updated `@zetachain/networks` version from `^10.0.0` to `10.0.0-rc1`.
- Added new dependency `bs58` with version `^6.0.0`. | | `packages/client/src/getBalances.ts` | - Modified `getBalances` function to accept `solanaAddress` in addition to `btcAddress` and `evmAddress`.
- Adjusted logic for handling token balances to include checks for `evmAddress` and `solanaAddress`.
- Updated API calls for fetching balances based on chain type, including changes for Bitcoin and Solana balance retrieval. | | `packages/tasks/src/balances.ts` | - Enhanced support for multiple blockchain addresses by modifying private key handling.
- Updated error messages for missing private keys to include new environment variables.
- Refactored command-line interface to accept specific flags for `--evm`, `--solana`, and `--bitcoin`.
- Modified output format to include Solana address if available. | ## Possibly related PRs - #172: This PR updates the `@zetachain/networks` package version in `package.json`, which is directly related to the change in the main PR that also modifies the version of `@zetachain/networks` from `^10.0.0` to `10.0.0-rc1`. ## Suggested labels `dependencies`

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?

❤️ Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
🪧 Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` 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 using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
fadeev commented 2 months ago

Solana CLI stores keys in ~/.config/solana/id.json. Please, suggest how we can modify the task to optionally use a key from there (and whether this is a good idea). Maybe we check if this file exists, use it, if not default to the private key in env.

fadeev commented 2 months ago

Also, please, add a way to specify a custom Solana address to query. If address is provided, don't derive it from private key.

Maybe,

npx hardhat balances --evm 0x*** --solana *** --bitcoin ***
lukema95 commented 1 month ago

Also, please, add a way to specify a custom Solana address to query. If address is provided, don't derive it from private key.

Maybe,

npx hardhat balances --evm 0x*** --solana *** --bitcoin ***

Given that we currently have tokens on three heterogeneous chains, and may expand to more in the future, I'd like to clarify a few points:

    1. Is an EVM address (--evm or private key) mandatory?
    1. If we provide one of the three parameters --evm, --solana, or --bitcoin, can we ignore the private key?
    1. Would it be better to uniformly place all required private keys in the .env file? Currently, there's only one PRIVATE_KEY, but Solana needs to read from ~/.config/solana/id.json. This can cause some confusion in decision-making. Can we expand the variables to EVM_PRIVATE_KEY, SOLANA_PRIVATE_KEY, and BTC_PRIVATE_KEY? This would provide greater flexibility.
    1. For the above, we only need to first determine whether condition 2 is provided, if not, then directly read the private key in condition 3. This makes the code judgment simpler.
fadeev commented 1 month ago

Is an EVM address (--evm or private key) mandatory?

No, I don't think it's mandatory.

fadeev commented 1 month ago

If we provide one of the three parameters --evm, --solana, or --bitcoin, can we ignore the private key?

I think we can. This is basically "watch mode" in a wallet, where you provide an address, can view balances, but of course can't sign txs.

fadeev commented 1 month ago

Would it be better to uniformly place all required private keys in the .env file? Currently, there's only one PRIVATE_KEY, but Solana needs to read from ~/.config/solana/id.json. This can cause some confusion in decision-making. Can we expand the variables to EVM_PRIVATE_KEY, SOLANA_PRIVATE_KEY, and BTC_PRIVATE_KEY? This would provide greater flexibility.

Yes, I think it's a good decision!

lukema95 commented 1 month ago
npx hardhat balances --solana HEgoKVmb6yohTatYM3D7nXFojo7uYEmitz2qj1255KL2 --evm 0x6093537Aa6C8C8bf4705bda40aC9193977208B39 --bitcoin tb1quy77dhfutn7dndevv7vff5he7g0d2j2hj2jwrv

    EVM: 0x6093537Aa6C8C8bf4705bda40aC9193977208B39 
Bitcoin: tb1quy77dhfutn7dndevv7vff5he7g0d2j2hj2jwrv 
 Solana: HEgoKVmb6yohTatYM3D7nXFojo7uYEmitz2qj1255KL2

┌─────────┬───────────────────┬───────────────────────────────────┬─────────┬─────────────┐
│ (index) │ Chain             │ Token                             │ Type    │ Amount      │
├─────────┼───────────────────┼───────────────────────────────────┼─────────┼─────────────┤
│ 0       │ 'amoy_testnet'    │ 'WZETA'                           │ 'ERC20' │ '0.000000'  │
│ 1       │ 'amoy_testnet'    │ 'MATIC.AMOY'                      │ 'Gas'   │ '0.650769'  │
│ 2       │ 'base_sepolia'    │ 'ETH.BASESEPOLIA'                 │ 'Gas'   │ '0.000000'  │
│ 3       │ 'bsc_testnet'     │ 'USDC'                            │ 'ERC20' │ '0.001689'  │
│ 4       │ 'bsc_testnet'     │ 'WZETA'                           │ 'ERC20' │ '0.000000'  │
│ 5       │ 'bsc_testnet'     │ 'tBNB'                            │ 'Gas'   │ '0.795821'  │
│ 6       │ 'btc_testnet'     │ 'tBTC'                            │ 'Gas'   │ '0.000112'  │
│ 7       │ 'sepolia_testnet' │ 'USDC.SEPOLIA'                    │ 'ERC20' │ '0.000000'  │
│ 8       │ 'sepolia_testnet' │ 'WZETA'                           │ 'ERC20' │ '0.000000'  │
│ 9       │ 'sepolia_testnet' │ 'sETH.SEPOLIA'                    │ 'Gas'   │ '0.241025'  │
│ 10      │ 'solana_devnet'   │ 'SOL.SOLANA'                      │ 'Gas'   │ '3.189423'  │
│ 11      │ 'zeta_testnet'    │ 'sETH.SEPOLIA'                    │ 'ZRC20' │ '0.031614'  │
│ 12      │ 'zeta_testnet'    │ 'USDC-goerli_testnet'             │ 'ZRC20' │ '0.000000'  │
│ 13      │ 'zeta_testnet'    │ 'gETH'                            │ 'ZRC20' │ '0.000000'  │
│ 14      │ 'zeta_testnet'    │ 'ETH.BASESEPOLIA'                 │ 'ZRC20' │ '0.000000'  │
│ 15      │ 'zeta_testnet'    │ 'tMATIC'                          │ 'ZRC20' │ '0.000000'  │
│ 16      │ 'zeta_testnet'    │ 'tBTC'                            │ 'ZRC20' │ '0.000022'  │
│ 17      │ 'zeta_testnet'    │ 'MATIC.AMOY'                      │ 'ZRC20' │ '0.108915'  │
│ 18      │ 'zeta_testnet'    │ 'USDC-bsc_testnet'                │ 'ZRC20' │ '0.000000'  │
│ 19      │ 'zeta_testnet'    │ 'USDC-mumbai_testnet'             │ 'ZRC20' │ '0.000000'  │
│ 20      │ 'zeta_testnet'    │ 'SOL.SOLANA'                      │ 'ZRC20' │ '0.000000'  │
│ 21      │ 'zeta_testnet'    │ 'ZetaChain ZRC20 USDC on SEPOLIA' │ 'ZRC20' │ '0.116826'  │
│ 22      │ 'zeta_testnet'    │ 'tBNB'                            │ 'ZRC20' │ '0.000000'  │
│ 23      │ 'zeta_testnet'    │ 'WZETA'                           │ 'ERC20' │ '0.042220'  │
│ 24      │ 'zeta_testnet'    │ 'ZETA'                            │ 'Gas'   │ '70.274601' │
└─────────┴───────────────────┴───────────────────────────────────┴─────────┴─────────────┘
npx hardhat balances 
      EVM: 0x6093537Aa6C8C8bf4705bda40aC9193977208B39 
Bitcoin: tb1quy77dhfutn7dndevv7vff5he7g0d2j2hj2jwrv 
Solana: HEgoKVmb6yohTatYM3D7nXFojo7uYEmitz2qj1255KL2
┌─────────┬───────────────────┬───────────────────────────────────┬─────────┬─────────────┐
│ (index) │ Chain             │ Token                             │ Type    │ Amount      │
├─────────┼───────────────────┼───────────────────────────────────┼─────────┼─────────────┤
│ 0       │ 'amoy_testnet'    │ 'WZETA'                           │ 'ERC20' │ '0.000000'  │
│ 1       │ 'amoy_testnet'    │ 'MATIC.AMOY'                      │ 'Gas'   │ '0.650769'  │
│ 2       │ 'base_sepolia'    │ 'ETH.BASESEPOLIA'                 │ 'Gas'   │ '0.000000'  │
│ 3       │ 'bsc_testnet'     │ 'USDC'                            │ 'ERC20' │ '0.001689'  │
│ 4       │ 'bsc_testnet'     │ 'WZETA'                           │ 'ERC20' │ '0.000000'  │
│ 5       │ 'bsc_testnet'     │ 'tBNB'                            │ 'Gas'   │ '0.795821'  │
│ 6       │ 'btc_testnet'     │ 'tBTC'                            │ 'Gas'   │ '0.000112'  │
│ 7       │ 'sepolia_testnet' │ 'USDC.SEPOLIA'                    │ 'ERC20' │ '0.000000'  │
│ 8       │ 'sepolia_testnet' │ 'WZETA'                           │ 'ERC20' │ '0.000000'  │
│ 9       │ 'sepolia_testnet' │ 'sETH.SEPOLIA'                    │ 'Gas'   │ '0.241025'  │
│ 10      │ 'solana_devnet'   │ 'SOL.SOLANA'                      │ 'Gas'   │ '3.189423'  │
│ 11      │ 'zeta_testnet'    │ 'sETH.SEPOLIA'                    │ 'ZRC20' │ '0.031614'  │
│ 12      │ 'zeta_testnet'    │ 'USDC-goerli_testnet'             │ 'ZRC20' │ '0.000000'  │
│ 13      │ 'zeta_testnet'    │ 'gETH'                            │ 'ZRC20' │ '0.000000'  │
│ 14      │ 'zeta_testnet'    │ 'ETH.BASESEPOLIA'                 │ 'ZRC20' │ '0.000000'  │
│ 15      │ 'zeta_testnet'    │ 'tMATIC'                          │ 'ZRC20' │ '0.000000'  │
│ 16      │ 'zeta_testnet'    │ 'tBTC'                            │ 'ZRC20' │ '0.000022'  │
│ 17      │ 'zeta_testnet'    │ 'MATIC.AMOY'                      │ 'ZRC20' │ '0.108915'  │
│ 18      │ 'zeta_testnet'    │ 'USDC-bsc_testnet'                │ 'ZRC20' │ '0.000000'  │
│ 19      │ 'zeta_testnet'    │ 'USDC-mumbai_testnet'             │ 'ZRC20' │ '0.000000'  │
│ 20      │ 'zeta_testnet'    │ 'SOL.SOLANA'                      │ 'ZRC20' │ '0.000000'  │
│ 21      │ 'zeta_testnet'    │ 'ZetaChain ZRC20 USDC on SEPOLIA' │ 'ZRC20' │ '0.116826'  │
│ 22      │ 'zeta_testnet'    │ 'tBNB'                            │ 'ZRC20' │ '0.000000'  │
│ 23      │ 'zeta_testnet'    │ 'WZETA'                           │ 'ERC20' │ '0.042220'  │
│ 24      │ 'zeta_testnet'    │ 'ZETA'                            │ 'Gas'   │ '70.274601' │
└─────────┴───────────────────┴───────────────────────────────────┴─────────┴─────────────┘
lukema95 commented 1 month ago

@fadeev pls review. Looks like we need to update npx hardhat account --save.

fadeev commented 1 month ago

@fadeev pls review. Looks like we need to update npx hardhat account --save.

Yes, I've added an issue: https://github.com/zeta-chain/toolkit/issues/187 (feel free to take it!)

lukema95 commented 1 month ago

Looks good! I think XYZ_PRIVATE_KEY is definitely the way to go, but can you please add PRIVATE_KEY as an alias to EVM_PRIVATE_KEY for backwards compatibility. We don't want to break the experience for no good reason.

So, the logic is for EVM if exists use EVM_PRIVATE_KEY (higher priority), if not use PRIVATE_KEY (lower priority).

Done