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: support Argent account v0.4.0 #680

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading