Skip to content

Commit

Permalink
feat: change Argent account factory for Cairo 1
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Sep 15, 2023
1 parent a5e23d0 commit 56a79d0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 31 deletions.
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
4 changes: 2 additions & 2 deletions examples/parse_jsonrpc_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use starknet_providers::jsonrpc::{JsonRpcRequest, JsonRpcRequestData};

fn main() {
// Let's pretend this is the raw request body coming from HTTP
let raw_request = r###"{
let raw_request = r#"{
"id": 1,
"jsonrpc": "2.0",
"method": "starknet_getBlockTransactionCount",
"params": [{ "block_number": 200 }]
}"###;
}"#;

// Your server framework should handle this for you. Here we deserialize manually to see what's
// going on.
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

0 comments on commit 56a79d0

Please sign in to comment.