From 9223942f5513681ea45792946037615d8f228da6 Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Mon, 2 Dec 2024 04:38:20 +0800 Subject: [PATCH] feat: support Argent account v0.4.0 --- examples/deploy_argent_account.rs | 11 ++++--- starknet-accounts/src/factory/argent.rs | 39 +++++++++++++++++++++---- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/examples/deploy_argent_account.rs b/examples/deploy_argent_account.rs index acd559c7..b296c645 100644 --- a/examples/deploy_argent_account.rs +++ b/examples/deploy_argent_account.rs @@ -11,8 +11,8 @@ use starknet::{ #[tokio::main] async fn main() { - // Latest hash as of 2023-09-15. For demo only. - let class_hash = felt!("0x01a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003"); + // Latest hash as of 2024-12-01. For demo only. + let class_hash = felt!("0x036078334509b514626504edc9fb252328d1a240e4e948bef8d0c08dff45927f"); // Anything you like here as salt let salt = felt!("12345678"); @@ -25,10 +25,9 @@ async fn main() { Felt::from_hex("YOUR_PRIVATE_KEY_IN_HEX_HERE").unwrap(), )); - let factory = - ArgentAccountFactory::new(class_hash, chain_id::SEPOLIA, Felt::ZERO, signer, provider) - .await - .unwrap(); + let factory = ArgentAccountFactory::new(class_hash, chain_id::SEPOLIA, None, signer, provider) + .await + .unwrap(); let deployment = factory.deploy_v1(salt); diff --git a/starknet-accounts/src/factory/argent.rs b/starknet-accounts/src/factory/argent.rs index 0a3b3a6c..f6677ec5 100644 --- a/starknet-accounts/src/factory/argent.rs +++ b/starknet-accounts/src/factory/argent.rs @@ -4,22 +4,41 @@ use crate::{ }; use async_trait::async_trait; -use starknet_core::types::{BlockId, BlockTag, Felt}; +use starknet_core::{ + codec::Encode, + types::{BlockId, BlockTag, Felt}, +}; use starknet_providers::Provider; use starknet_signers::{Signer, SignerInteractivityContext}; -/// [`AccountFactory`] implementation for deploying `Argent X` account contracts. +/// [`AccountFactory`] implementation for deploying `Argent X` account contracts (v0.4.0). #[derive(Debug)] pub struct ArgentAccountFactory { class_hash: Felt, chain_id: Felt, owner_public_key: Felt, - guardian_public_key: Felt, + guardian_public_key: Option, signer: S, provider: P, block_id: BlockId, } +/// Constructor parameters for Argent account v0.4.0. +#[derive(Encode)] +#[starknet(core = "starknet_core")] +struct ArgentAccountConstructorParams { + owner: ArgentSigner, + guardian: Option, +} + +/// A simplified version of `argent::signer::signer_signature::Signer` that only supports the simple +/// Starknet signer. +#[derive(Encode)] +#[starknet(core = "starknet_core")] +enum ArgentSigner { + Starknet(Felt), +} + impl ArgentAccountFactory where S: Signer, @@ -28,7 +47,7 @@ where pub async fn new( class_hash: Felt, chain_id: Felt, - guardian_public_key: Felt, + guardian_public_key: Option, signer: S, provider: P, ) -> Result { @@ -66,7 +85,17 @@ where } fn calldata(&self) -> Vec { - vec![self.owner_public_key, self.guardian_public_key] + let mut calldata = vec![]; + + // Encoding this sturct never fails + ArgentAccountConstructorParams { + owner: ArgentSigner::Starknet(self.owner_public_key), + guardian: self.guardian_public_key.map(ArgentSigner::Starknet), + } + .encode(&mut calldata) + .unwrap(); + + calldata } fn chain_id(&self) -> Felt {