Skip to content

Commit

Permalink
copy the account_sdk folder over
Browse files Browse the repository at this point in the history
  • Loading branch information
piniom committed Jun 7, 2024
1 parent 52cdb73 commit daef796
Show file tree
Hide file tree
Showing 35 changed files with 66,093 additions and 18,834 deletions.
4,197 changes: 0 additions & 4,197 deletions packages/account_sdk/Cargo.lock

This file was deleted.

Large diffs are not rendered by default.

41,031 changes: 41,031 additions & 0 deletions packages/account_sdk/compiled/argent_account.contract_class.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

32,244 changes: 18,834 additions & 13,410 deletions packages/account_sdk/compiled/cartridge_account.contract_class.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion packages/account_sdk/parser_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"contract_aliases": {},
"type_aliases": {
"argent::session::session::session_component::Event": "SessionComponentEvent",
"argent::outside_execution::outside_execution::outside_execution_component::Event": "OEvent",
"argent::outside_execution::outside_execution::outside_execution_component::Event": "OutsideExecutionEvent",
"argent::upgrade::upgrade::upgrade_component::Event": "UpgradeComponentEvent",
"argent::introspection::src5::src5_component::Event": "Src5ComponentEvent",
"cartridge_account::CartridgeAccount::Event": "CartridgeAccountEvent",
"cartridge_account::outside_execution::outside_execution::outside_execution_component::Event": "OutsideExecutionEvent",
"cartridge_account::src5::src5_component::Event": "Src5ComponentEvent",
"openzeppelin::token::erc20::erc20::ERC20Component::Event": "ERC20ComponentEvent",
"openzeppelin::access::ownable::ownable::OwnableComponent::Event": "OwnableComponentEvent",
"webauthn_session::session_component::Event": "SessionComponentEvent",
Expand Down
4,026 changes: 4,026 additions & 0 deletions packages/account_sdk/src/abigen/argent_account.rs

Large diffs are not rendered by default.

1,361 changes: 756 additions & 605 deletions packages/account_sdk/src/abigen/cartridge_account.rs

Large diffs are not rendered by default.

272 changes: 136 additions & 136 deletions packages/account_sdk/src/abigen/erc_20.rs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions packages/account_sdk/src/abigen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#[allow(non_snake_case)]
pub mod cartridge_account;

#[allow(warnings)]
#[allow(non_snake_case)]
pub mod argent_account;

#[allow(warnings)]
#[allow(non_snake_case)]
pub mod erc_20;
101 changes: 21 additions & 80 deletions packages/account_sdk/src/account/cartridge.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
use async_trait::async_trait;
use cainome::cairo_serde::{CairoSerde, ContractAddress};
use cainome::cairo_serde::CairoSerde;
use starknet::{
accounts::{
Account, Call, ConnectedAccount, Declaration, Execution, ExecutionEncoder,
LegacyDeclaration, RawDeclaration, RawExecution, RawLegacyDeclaration,
},
core::types::{
contract::legacy::LegacyContractClass, BlockId, BlockTag, FieldElement,
FlattenedSierraClass,
},
accounts::{Account, Call, ConnectedAccount, ExecutionEncoder},
core::types::{BlockId, BlockTag, FieldElement},
providers::Provider,
};
use std::sync::Arc;

use crate::{
abigen::cartridge_account::{Call as AbigenCall, SignerSignature},
abigen::cartridge_account::SignerSignature,
impl_account, impl_execution_encoder,
signers::{HashSigner, SignError},
};

use super::{AccountHashAndCallsSigner, AccountHashSigner, SpecificAccount};

#[derive(Clone, Debug)]
pub struct CartridgeAccount<P, S>
where
Expand Down Expand Up @@ -46,91 +42,36 @@ where
}
}

impl<P, S> ExecutionEncoder for CartridgeAccount<P, S>
where
P: Provider + Send,
S: HashSigner + Send,
{
fn encode_calls(&self, calls: &[Call]) -> Vec<FieldElement> {
<Vec<AbigenCall> as CairoSerde>::cairo_serialize(
&calls
.iter()
.map(
|Call {
to,
selector,
calldata,
}| AbigenCall {
to: ContractAddress(*to),
selector: *selector,
calldata: calldata.clone(),
},
)
.collect(),
)
}
}

#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
impl<P, S> Account for CartridgeAccount<P, S>
impl<P, S> AccountHashSigner for CartridgeAccount<P, S>
where
P: Provider + Send + Sync,
S: HashSigner + Send + Sync,
{
type SignError = SignError;
async fn sign_hash(&self, hash: FieldElement) -> Result<Vec<FieldElement>, SignError> {
let result = self.signer.sign(&hash).await.ok().unwrap();
Ok(Vec::<SignerSignature>::cairo_serialize(&vec![result]))
}
}

impl<P, S> SpecificAccount for CartridgeAccount<P, S>
where
P: Provider + Send,
S: HashSigner + Send,
{
fn address(&self) -> FieldElement {
self.address
}

fn chain_id(&self) -> FieldElement {
self.chain_id
}

async fn sign_execution(
&self,
execution: &RawExecution,
query_only: bool,
) -> Result<Vec<FieldElement>, Self::SignError> {
let tx_hash = execution.transaction_hash(self.chain_id, self.address, query_only, self);
let result = self.signer.sign(&tx_hash).await.ok().unwrap();
Ok(Vec::<SignerSignature>::cairo_serialize(&vec![result]))
}

async fn sign_declaration(
&self,
_declaration: &RawDeclaration,
_query_only: bool,
) -> Result<Vec<FieldElement>, Self::SignError> {
unimplemented!("sign_declaration")
}

async fn sign_legacy_declaration(
&self,
_legacy_declaration: &RawLegacyDeclaration,
_query_only: bool,
) -> Result<Vec<FieldElement>, Self::SignError> {
unimplemented!("sign_legacy_declaration")
}

fn execute(&self, calls: Vec<Call>) -> Execution<Self> {
Execution::new(calls, self)
}

fn declare(
&self,
contract_class: Arc<FlattenedSierraClass>,
compiled_class_hash: FieldElement,
) -> Declaration<Self> {
Declaration::new(contract_class, compiled_class_hash, self)
}

fn declare_legacy(&self, contract_class: Arc<LegacyContractClass>) -> LegacyDeclaration<Self> {
LegacyDeclaration::new(contract_class, self)
}
}

impl_account!(CartridgeAccount<P: Provider, S: HashSigner>);
impl_execution_encoder!(CartridgeAccount<P: Provider, S: HashSigner>);

impl<P, S> ConnectedAccount for CartridgeAccount<P, S>
where
P: Provider + Send + Sync,
Expand Down
92 changes: 23 additions & 69 deletions packages/account_sdk/src/account/guardian.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
use async_trait::async_trait;
use cainome::cairo_serde::CairoSerde;
use starknet::{
accounts::{
Account, Call, ConnectedAccount, Declaration, Execution, ExecutionEncoder,
LegacyDeclaration, RawDeclaration, RawExecution, RawLegacyDeclaration,
},
core::types::{
contract::legacy::LegacyContractClass, BlockId, FieldElement, FlattenedSierraClass,
},
accounts::{Account, Call, ConnectedAccount, ExecutionEncoder},
core::types::{BlockId, FieldElement},
providers::Provider,
};
use std::sync::Arc;

use crate::{
abigen::cartridge_account::SignerSignature,
impl_account, impl_execution_encoder,
signers::{HashSigner, SignError},
};

use super::cartridge::CartridgeAccount;
use super::{
cartridge::CartridgeAccount, AccountHashAndCallsSigner, AccountHashSigner, SpecificAccount,
};

#[derive(Clone, Debug)]
pub struct CartridgeGuardianAccount<P, S, G>
Expand Down Expand Up @@ -51,7 +48,17 @@ where
pub fn from_account(account: CartridgeAccount<P, S>, guardian: G) -> Self {
Self { account, guardian }
}
pub async fn sign_hash(&self, hash: FieldElement) -> Result<Vec<FieldElement>, SignError> {
}

#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
impl<P, S, G> AccountHashSigner for CartridgeGuardianAccount<P, S, G>
where
P: Provider + Send + Sync,
S: HashSigner + Send + Sync,
G: HashSigner + Send + Sync,
{
async fn sign_hash(&self, hash: FieldElement) -> Result<Vec<FieldElement>, SignError> {
let owner_signature = self.account.signer.sign(&hash).await?;
let guardian_signature = self.guardian.sign(&hash).await?;
Ok(Vec::<SignerSignature>::cairo_serialize(&vec![
Expand All @@ -61,77 +68,24 @@ where
}
}

impl<P, S, G> ExecutionEncoder for CartridgeGuardianAccount<P, S, G>
where
P: Provider + Send,
S: HashSigner + Send,
G: HashSigner + Send,
{
fn encode_calls(&self, calls: &[Call]) -> Vec<FieldElement> {
self.account.encode_calls(calls)
}
}

#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
impl<P, S, G> Account for CartridgeGuardianAccount<P, S, G>
impl<P, S, G> SpecificAccount for CartridgeGuardianAccount<P, S, G>
where
P: Provider + Send + Sync,
S: HashSigner + Send + Sync,
G: HashSigner + Send + Sync,
{
type SignError = SignError;

fn address(&self) -> FieldElement {
self.account.address()
self.account.address
}

fn chain_id(&self) -> FieldElement {
self.account.chain_id()
}

async fn sign_execution(
&self,
execution: &RawExecution,
query_only: bool,
) -> Result<Vec<FieldElement>, Self::SignError> {
let tx_hash = execution.transaction_hash(self.chain_id(), self.address(), query_only, self);
self.sign_hash(tx_hash).await
}

async fn sign_declaration(
&self,
_declaration: &RawDeclaration,
_query_only: bool,
) -> Result<Vec<FieldElement>, Self::SignError> {
unimplemented!("sign_declaration")
}

async fn sign_legacy_declaration(
&self,
_legacy_declaration: &RawLegacyDeclaration,
_query_only: bool,
) -> Result<Vec<FieldElement>, Self::SignError> {
unimplemented!("sign_legacy_declaration")
}

fn execute(&self, calls: Vec<Call>) -> Execution<Self> {
Execution::new(calls, self)
}

fn declare(
&self,
contract_class: Arc<FlattenedSierraClass>,
compiled_class_hash: FieldElement,
) -> Declaration<Self> {
Declaration::new(contract_class, compiled_class_hash, self)
}

fn declare_legacy(&self, contract_class: Arc<LegacyContractClass>) -> LegacyDeclaration<Self> {
LegacyDeclaration::new(contract_class, self)
self.account.chain_id
}
}

impl_account!(CartridgeGuardianAccount<P: Provider, S: HashSigner, G: HashSigner>);
impl_execution_encoder!(CartridgeGuardianAccount<P: Provider, S: HashSigner, G: HashSigner>);

impl<P, S, G> ConnectedAccount for CartridgeGuardianAccount<P, S, G>
where
P: Provider + Send + Sync,
Expand Down
Loading

0 comments on commit daef796

Please sign in to comment.