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: change Argent account factory for Cairo 1 #472

Merged
merged 1 commit into from
Sep 15, 2023
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
8 changes: 3 additions & 5 deletions examples/deploy_argent_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ use starknet::{

#[tokio::main]
async fn main() {
// Latest hashes as of 2023-01-21. For demo only.
let proxy_hash = felt!("0x025ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918");
let impl_hash = felt!("0x033434ad846cdd5f23eb73ff09fe6fddd568284a0fb7d1be20ee482f044dabe2");
// Latest hash as of 2023-09-15. For demo only.
let class_hash = felt!("0x01a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003");

// Anything you like here as salt
let salt = felt!("12345678");
Expand All @@ -21,8 +20,7 @@ async fn main() {
));

let factory = ArgentAccountFactory::new(
proxy_hash,
impl_hash,
class_hash,
chain_id::TESTNET,
FieldElement::ZERO,
signer,
Expand Down
31 changes: 7 additions & 24 deletions starknet-accounts/src/factory/argent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,10 @@ use starknet_core::types::FieldElement;
use starknet_providers::Provider;
use starknet_signers::Signer;

/// Selector for "initialize"
const SELECTOR_INITIALIZE: FieldElement = FieldElement::from_mont([
14382173896205878522,
7380089477680411368,
4404362358337226556,
132905214994424316,
]);

pub struct ArgentAccountFactory<S, P> {
proxy_class_hash: FieldElement,
impl_class_hash: FieldElement,
class_hash: FieldElement,
chain_id: FieldElement,
signer_public_key: FieldElement,
owner_public_key: FieldElement,
guardian_public_key: FieldElement,
signer: S,
provider: P,
Expand All @@ -28,19 +19,17 @@ where
S: Signer,
{
pub async fn new(
proxy_class_hash: FieldElement,
impl_class_hash: FieldElement,
class_hash: FieldElement,
chain_id: FieldElement,
guardian_public_key: FieldElement,
signer: S,
provider: P,
) -> Result<Self, S::GetPublicKeyError> {
let signer_public_key = signer.get_public_key().await?;
Ok(Self {
proxy_class_hash,
impl_class_hash,
class_hash,
chain_id,
signer_public_key: signer_public_key.scalar(),
owner_public_key: signer_public_key.scalar(),
guardian_public_key,
signer,
provider,
Expand All @@ -59,17 +48,11 @@ where
type SignError = S::SignError;

fn class_hash(&self) -> FieldElement {
self.proxy_class_hash
self.class_hash
}

fn calldata(&self) -> Vec<FieldElement> {
vec![
self.impl_class_hash,
SELECTOR_INITIALIZE,
FieldElement::TWO,
self.signer_public_key,
self.guardian_public_key,
]
vec![self.owner_public_key, self.guardian_public_key]
}

fn chain_id(&self) -> FieldElement {
Expand Down
Loading