Skip to content

Commit

Permalink
feat: support Argent account v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Dec 1, 2024
1 parent a09d4d4 commit 9223942
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
11 changes: 5 additions & 6 deletions examples/deploy_argent_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);

Expand Down
39 changes: 34 additions & 5 deletions starknet-accounts/src/factory/argent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S, P> {
class_hash: Felt,
chain_id: Felt,
owner_public_key: Felt,
guardian_public_key: Felt,
guardian_public_key: Option<Felt>,
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<ArgentSigner>,
}

/// 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<S, P> ArgentAccountFactory<S, P>
where
S: Signer,
Expand All @@ -28,7 +47,7 @@ where
pub async fn new(
class_hash: Felt,
chain_id: Felt,
guardian_public_key: Felt,
guardian_public_key: Option<Felt>,
signer: S,
provider: P,
) -> Result<Self, S::GetPublicKeyError> {
Expand Down Expand Up @@ -66,7 +85,17 @@ where
}

fn calldata(&self) -> Vec<Felt> {
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 {
Expand Down

0 comments on commit 9223942

Please sign in to comment.