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: add an example to deploy an ArgentX 0.4.0 account on devnet #471

Merged

Conversation

ptisserand
Copy link
Collaborator

@ptisserand ptisserand commented Feb 24, 2025

Add an example to deply an ArgentX 0.4.0 with a local cosigner on devnet

Summary by CodeRabbit

  • New Features
    • Added a Dart-based script that enables deployment and management of an ArgentX account on the StarkNet blockchain. This update automates account funding, balance verification, and transaction processing, providing clear feedback for each operation.

Copy link

docs-page bot commented Feb 24, 2025

To view this pull requests documentation preview, visit the following URL:

docs.page/focustree/starknet.dart~471

Documentation is deployed and generated using docs.page.

Copy link
Contributor

coderabbitai bot commented Feb 24, 2025

Walkthrough

A new Dart file has been added that implements a script to deploy an ArgentX account on the StarkNet blockchain. The script initializes the necessary signers, establishes a connection to a JSON-RPC provider, computes the account address using calldata and public keys, and handles minting and deployment transactions. It also verifies the account balance and sends a transfer, printing transaction details and handling potential errors during deployment.

Changes

File Change Summary
packages/starknet/.../deploy_argent_account.dart New Dart script for deploying an ArgentX account. It establishes a JSON-RPC connection, initializes guardian and owner signers, constructs calldata, computes the account address, mints funds, deploys the account if needed, and sends a transfer while handling errors.

Sequence Diagram(s)

sequenceDiagram
    participant Main
    participant RPC
    participant Contract

    Main ->> RPC: Connect (using node URI)
    Main ->> RPC: Request Chain ID
    RPC -->> Main: Return Chain ID

    Main ->> Main: Initialize Guardian & Owner signers
    Main ->> Main: Compute Account Address (calldata + public key)
    Main ->> RPC: Mint funds (initiate mint transaction)
    Main ->> RPC: Check account balance (balanceOf call)
    
    alt Account not deployed
      Main ->> Contract: Deploy account via Account.deployAccount
      Contract -->> Main: Return Transaction Hash
      Main ->> RPC: Await transaction confirmation
    end

    Main ->> Contract: Send funds to recipient
    Contract -->> Main: Return Transaction Hash
Loading

Poem

I'm a rabbit hopping through lines of code anew,
With ArgentX dreams and transactions in view.
I nibble on deploys and crunch each byte,
Leaping through JSON-RPC with all my might.
Oh, how sweet the success when the code runs right!
🥕🐇 Happy hops in deployment delight!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 73ade5d and e4d4bc1.

📒 Files selected for processing (1)
  • packages/starknet/example/examples/deploy_argent_account.dart (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/starknet/example/examples/deploy_argent_account.dart
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test-integration
  • GitHub Check: analyze
  • GitHub Check: lint

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
packages/starknet/example/examples/deploy_argent_account.dart (4)

8-10: Consider making the ArgentX class hash configurable.

The hardcoded class hash might need updates when ArgentX releases new versions. Consider making it configurable through environment variables or constructor parameters.

-final argentClassHash = Felt.fromHexString(
-  '0x036078334509b514626504edc9fb252328d1a240e4e948bef8d0c08dff45927f',
-);
+// Read from environment variable or configuration
+final argentClassHash = Felt.fromHexString(
+  Platform.environment['ARGENT_CLASS_HASH'] ?? 
+  '0x036078334509b514626504edc9fb252328d1a240e4e948bef8d0c08dff45927f',
+);

36-43: Make the devnet URL configurable and improve WEI calculation.

The hardcoded localhost URL should be configurable, and the WEI calculation can be improved for clarity.

+const oneEther = BigInt.from(10).pow(18);
+final devnetUrl = Platform.environment['DEVNET_URL'] ?? 'http://localhost:5050';

 await Devnet.mintTransaction(
-    Uri.parse('http://localhost:5050'),
+    Uri.parse(devnetUrl),
     MintRequest(
       address: accountAddress.toHexString(),
-      amount: pow(10, 18) as int,
+      amount: oneEther.toInt(),
       unit: 'WEI',
     ),
   );

69-70: Document the commented fee configuration options.

The commented fee configuration options might be useful for users. Consider adding documentation about when and why to use these options.

Add a comment explaining the fee configuration:

+      // Optional: Use STRK for fee payment instead of ETH
       // useSTRKFee: true,
+      // Optional: Set maximum fee for deployment (in WEI)
       // max_fee: Felt.fromInt(20000000000000),

96-99: Make transfer parameters configurable.

The recipient address and transfer amount are hardcoded. Consider making these configurable to make the example more flexible.

+  final recipient = Platform.environment['RECIPIENT_ADDRESS'] ?? 
+    '0x44554d4d59'; // Example recipient
+  final amount = BigInt.parse(
+    Platform.environment['TRANSFER_AMOUNT'] ?? '10'
+  );

   final txHash = await account.send(
-    recipient: Felt.fromHexString('0x44554d4d59'),
+    recipient: Felt.fromHexString(recipient),
     amount: Uint256(
-      low: Felt.fromInt(10),
+      low: Felt.fromInt(amount.toInt()),
       high: Felt.zero
     ),
   );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between efce379 and 73ade5d.

📒 Files selected for processing (1)
  • packages/starknet/example/examples/deploy_argent_account.dart (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint
  • GitHub Check: analyze
  • GitHub Check: test-integration
🔇 Additional comments (1)
packages/starknet/example/examples/deploy_argent_account.dart (1)

28-34: LGTM! Clean implementation of account address computation.

The code correctly follows StarkNet's account deployment pattern by computing the account address using the class hash, constructor calldata, and signer's public key.

@ptisserand ptisserand merged commit d2ca640 into focustree:main Feb 24, 2025
10 checks passed
@ptisserand ptisserand deleted the feat/add-deploy-argent-account-example branch February 24, 2025 10:59
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.

1 participant