From 96a8cbd6639e07195e0ee11ee17f43600664043d Mon Sep 17 00:00:00 2001 From: notV4l <122404722+notV4l@users.noreply.github.com> Date: Fri, 9 Aug 2024 00:06:16 +0200 Subject: [PATCH] add menu page (#438) * add menu page * setDelegate page * rebase --- examples/starknet-react-next/src/app/page.tsx | 2 + .../src/components/DelegateAccount.tsx | 5 +- .../src/components/Menu.tsx | 30 + packages/account_sdk/src/abigen/controller.rs | 1666 ++++++++--------- packages/account_sdk/src/abigen/erc_20.rs | 1134 +++++------ packages/connector/src/index.ts | 6 +- packages/controller/src/index.ts | 23 +- packages/controller/src/types.ts | 2 + packages/keychain/.env.development | 2 +- .../keychain/src/components/Menu/index.tsx | 128 ++ .../keychain/src/components/SetDelegate.tsx | 66 + packages/keychain/src/components/index.ts | 1 + .../layout/Container/Header/Banner.tsx | 1 + .../src/components/layout/Container/index.tsx | 2 +- .../src/components/layout/Footer/index.tsx | 7 +- packages/keychain/src/hooks/connection.tsx | 40 +- packages/keychain/src/pages/index.tsx | 60 +- packages/keychain/src/utils/account.ts | 4 + .../keychain/src/utils/connection/delegate.ts | 27 + .../keychain/src/utils/connection/index.ts | 5 + .../keychain/src/utils/connection/menu.ts | 16 + .../keychain/src/utils/connection/types.ts | 20 +- packages/keychain/src/utils/controller.ts | 32 +- 23 files changed, 1861 insertions(+), 1418 deletions(-) create mode 100644 examples/starknet-react-next/src/components/Menu.tsx create mode 100644 packages/keychain/src/components/Menu/index.tsx create mode 100644 packages/keychain/src/components/SetDelegate.tsx create mode 100644 packages/keychain/src/utils/connection/delegate.ts create mode 100644 packages/keychain/src/utils/connection/menu.ts diff --git a/examples/starknet-react-next/src/app/page.tsx b/examples/starknet-react-next/src/app/page.tsx index 38ce5000c..75990312d 100644 --- a/examples/starknet-react-next/src/app/page.tsx +++ b/examples/starknet-react-next/src/app/page.tsx @@ -5,6 +5,7 @@ import { SignMessage } from "components/SignMessage"; import { DojoSpawnAndMove } from "components/DojoSpawnAndMove"; import { DelegateAccount } from "components/DelegateAccount"; import { ColorModeToggle } from "components/ColorModeToggle"; +import { Menu } from "components/Menu"; export default function Home() { return ( @@ -16,6 +17,7 @@ export default function Home() { + diff --git a/examples/starknet-react-next/src/components/DelegateAccount.tsx b/examples/starknet-react-next/src/components/DelegateAccount.tsx index a8a034ee5..8772cac9f 100644 --- a/examples/starknet-react-next/src/components/DelegateAccount.tsx +++ b/examples/starknet-react-next/src/components/DelegateAccount.tsx @@ -29,9 +29,10 @@ export const DelegateAccount = () => { setDelegateAddress(delegate?.toString() || ""); setIsDelegateSupported(true); } catch (e: any) { + console.log(e) // controller doesnt support delegateAccount, ignore } - }, [account, cartridgeConnector]); + }, [account, chainId, cartridgeConnector]); const execute = useCallback(async () => { if (!account) { @@ -75,7 +76,7 @@ export const DelegateAccount = () => { type="text" min-width="420px" value={delegateAddressInput} - onChange={(e) => setDelegateAddressInput(e.target.value)} + onChange={(e:any ) => setDelegateAddressInput(e.target.value)} /> + + ); +} diff --git a/packages/account_sdk/src/abigen/controller.rs b/packages/account_sdk/src/abigen/controller.rs index 411eb76be..6b0f24b4a 100644 --- a/packages/account_sdk/src/abigen/controller.rs +++ b/packages/account_sdk/src/abigen/controller.rs @@ -53,22 +53,22 @@ impl ControllerReader

{ } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct Eip191Signer { - pub eth_address: cainome::cairo_serde::EthAddress, +pub struct ExternalOwnerRegistered { + pub address: cainome::cairo_serde::ContractAddress, } -impl cainome::cairo_serde::CairoSerde for Eip191Signer { +impl cainome::cairo_serde::CairoSerde for ExternalOwnerRegistered { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; - __size += cainome::cairo_serde::EthAddress::cairo_serialized_size(&__rust.eth_address); + __size += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.address); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; - __out.extend(cainome::cairo_serde::EthAddress::cairo_serialize( - &__rust.eth_address, + __out.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( + &__rust.address, )); __out } @@ -77,9 +77,37 @@ impl cainome::cairo_serde::CairoSerde for Eip191Signer { __offset: usize, ) -> cainome::cairo_serde::Result { let mut __offset = __offset; - let eth_address = cainome::cairo_serde::EthAddress::cairo_deserialize(__felts, __offset)?; - __offset += cainome::cairo_serde::EthAddress::cairo_serialized_size(ð_address); - Ok(Eip191Signer { eth_address }) + let address = cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; + __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&address); + Ok(ExternalOwnerRegistered { address }) + } +} +#[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] +pub struct OwnerAdded { + pub owner: Signer, +} +impl cainome::cairo_serde::CairoSerde for OwnerAdded { + type RustType = Self; + const SERIALIZED_SIZE: std::option::Option = None; + #[inline] + fn cairo_serialized_size(__rust: &Self::RustType) -> usize { + let mut __size = 0; + __size += Signer::cairo_serialized_size(&__rust.owner); + __size + } + fn cairo_serialize(__rust: &Self::RustType) -> Vec { + let mut __out: Vec = vec![]; + __out.extend(Signer::cairo_serialize(&__rust.owner)); + __out + } + fn cairo_deserialize( + __felts: &[starknet::core::types::Felt], + __offset: usize, + ) -> cainome::cairo_serde::Result { + let mut __offset = __offset; + let owner = Signer::cairo_deserialize(__felts, __offset)?; + __offset += Signer::cairo_serialized_size(&owner); + Ok(OwnerAdded { owner }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] @@ -119,23 +147,24 @@ impl cainome::cairo_serde::CairoSerde for TransactionExecuted { } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct ExternalOwnerRegistered { - pub address: cainome::cairo_serde::ContractAddress, +pub struct StarknetSignature { + pub r: starknet::core::types::Felt, + pub s: starknet::core::types::Felt, } -impl cainome::cairo_serde::CairoSerde for ExternalOwnerRegistered { +impl cainome::cairo_serde::CairoSerde for StarknetSignature { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; - __size += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.address); + __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.r); + __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.s); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; - __out.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( - &__rust.address, - )); + __out.extend(starknet::core::types::Felt::cairo_serialize(&__rust.r)); + __out.extend(starknet::core::types::Felt::cairo_serialize(&__rust.s)); __out } fn cairo_deserialize( @@ -143,9 +172,11 @@ impl cainome::cairo_serde::CairoSerde for ExternalOwnerRegistered { __offset: usize, ) -> cainome::cairo_serde::Result { let mut __offset = __offset; - let address = cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; - __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&address); - Ok(ExternalOwnerRegistered { address }) + let r = starknet::core::types::Felt::cairo_deserialize(__felts, __offset)?; + __offset += starknet::core::types::Felt::cairo_serialized_size(&r); + let s = starknet::core::types::Felt::cairo_deserialize(__felts, __offset)?; + __offset += starknet::core::types::Felt::cairo_serialized_size(&s); + Ok(StarknetSignature { r, s }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] @@ -205,22 +236,22 @@ impl cainome::cairo_serde::CairoSerde for OutsideExecution { } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct SessionRevoked { - pub session_hash: starknet::core::types::Felt, +pub struct ExternalOwnerRemoved { + pub address: cainome::cairo_serde::ContractAddress, } -impl cainome::cairo_serde::CairoSerde for SessionRevoked { +impl cainome::cairo_serde::CairoSerde for ExternalOwnerRemoved { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; - __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.session_hash); + __size += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.address); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; - __out.extend(starknet::core::types::Felt::cairo_serialize( - &__rust.session_hash, + __out.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( + &__rust.address, )); __out } @@ -229,28 +260,28 @@ impl cainome::cairo_serde::CairoSerde for SessionRevoked { __offset: usize, ) -> cainome::cairo_serde::Result { let mut __offset = __offset; - let session_hash = starknet::core::types::Felt::cairo_deserialize(__felts, __offset)?; - __offset += starknet::core::types::Felt::cairo_serialized_size(&session_hash); - Ok(SessionRevoked { session_hash }) + let address = cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; + __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&address); + Ok(ExternalOwnerRemoved { address }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct SessionRegistered { - pub session_hash: starknet::core::types::Felt, +pub struct Eip191Signer { + pub eth_address: cainome::cairo_serde::EthAddress, } -impl cainome::cairo_serde::CairoSerde for SessionRegistered { +impl cainome::cairo_serde::CairoSerde for Eip191Signer { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; - __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.session_hash); + __size += cainome::cairo_serde::EthAddress::cairo_serialized_size(&__rust.eth_address); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; - __out.extend(starknet::core::types::Felt::cairo_serialize( - &__rust.session_hash, + __out.extend(cainome::cairo_serde::EthAddress::cairo_serialize( + &__rust.eth_address, )); __out } @@ -259,34 +290,29 @@ impl cainome::cairo_serde::CairoSerde for SessionRegistered { __offset: usize, ) -> cainome::cairo_serde::Result { let mut __offset = __offset; - let session_hash = starknet::core::types::Felt::cairo_deserialize(__felts, __offset)?; - __offset += starknet::core::types::Felt::cairo_serialized_size(&session_hash); - Ok(SessionRegistered { session_hash }) + let eth_address = cainome::cairo_serde::EthAddress::cairo_deserialize(__felts, __offset)?; + __offset += cainome::cairo_serde::EthAddress::cairo_serialized_size(ð_address); + Ok(Eip191Signer { eth_address }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct Secp256r1Signer { - pub pubkey: cainome::cairo_serde::NonZero, +pub struct Secp256k1Signer { + pub pubkey_hash: cainome::cairo_serde::EthAddress, } -impl cainome::cairo_serde::CairoSerde for Secp256r1Signer { +impl cainome::cairo_serde::CairoSerde for Secp256k1Signer { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; - __size += - cainome::cairo_serde::NonZero::::cairo_serialized_size( - &__rust.pubkey, - ); + __size += cainome::cairo_serde::EthAddress::cairo_serialized_size(&__rust.pubkey_hash); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; - __out.extend( - cainome::cairo_serde::NonZero::::cairo_serialize( - &__rust.pubkey, - ), - ); + __out.extend(cainome::cairo_serde::EthAddress::cairo_serialize( + &__rust.pubkey_hash, + )); __out } fn cairo_deserialize( @@ -294,34 +320,28 @@ impl cainome::cairo_serde::CairoSerde for Secp256r1Signer { __offset: usize, ) -> cainome::cairo_serde::Result { let mut __offset = __offset; - let pubkey = - cainome::cairo_serde::NonZero::::cairo_deserialize( - __felts, __offset, - )?; - __offset += - cainome::cairo_serde::NonZero::::cairo_serialized_size( - &pubkey, - ); - Ok(Secp256r1Signer { pubkey }) + let pubkey_hash = cainome::cairo_serde::EthAddress::cairo_deserialize(__felts, __offset)?; + __offset += cainome::cairo_serde::EthAddress::cairo_serialized_size(&pubkey_hash); + Ok(Secp256k1Signer { pubkey_hash }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct ExternalOwnerRemoved { - pub address: cainome::cairo_serde::ContractAddress, +pub struct Upgraded { + pub class_hash: cainome::cairo_serde::ClassHash, } -impl cainome::cairo_serde::CairoSerde for ExternalOwnerRemoved { +impl cainome::cairo_serde::CairoSerde for Upgraded { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; - __size += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.address); + __size += cainome::cairo_serde::ClassHash::cairo_serialized_size(&__rust.class_hash); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; - __out.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( - &__rust.address, + __out.extend(cainome::cairo_serde::ClassHash::cairo_serialize( + &__rust.class_hash, )); __out } @@ -330,27 +350,29 @@ impl cainome::cairo_serde::CairoSerde for ExternalOwnerRemoved { __offset: usize, ) -> cainome::cairo_serde::Result { let mut __offset = __offset; - let address = cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; - __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&address); - Ok(ExternalOwnerRemoved { address }) + let class_hash = cainome::cairo_serde::ClassHash::cairo_deserialize(__felts, __offset)?; + __offset += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash); + Ok(Upgraded { class_hash }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct OwnerRemoved { - pub owner: Signer, +pub struct DelegateAccountChanged { + pub address: cainome::cairo_serde::ContractAddress, } -impl cainome::cairo_serde::CairoSerde for OwnerRemoved { +impl cainome::cairo_serde::CairoSerde for DelegateAccountChanged { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; - __size += Signer::cairo_serialized_size(&__rust.owner); + __size += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.address); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; - __out.extend(Signer::cairo_serialize(&__rust.owner)); + __out.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( + &__rust.address, + )); __out } fn cairo_deserialize( @@ -358,28 +380,41 @@ impl cainome::cairo_serde::CairoSerde for OwnerRemoved { __offset: usize, ) -> cainome::cairo_serde::Result { let mut __offset = __offset; - let owner = Signer::cairo_deserialize(__felts, __offset)?; - __offset += Signer::cairo_serialized_size(&owner); - Ok(OwnerRemoved { owner }) + let address = cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; + __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&address); + Ok(DelegateAccountChanged { address }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct DelegateAccountChanged { - pub address: cainome::cairo_serde::ContractAddress, +pub struct Session { + pub expires_at: u64, + pub allowed_methods_root: starknet::core::types::Felt, + pub metadata_hash: starknet::core::types::Felt, + pub session_key_guid: starknet::core::types::Felt, } -impl cainome::cairo_serde::CairoSerde for DelegateAccountChanged { +impl cainome::cairo_serde::CairoSerde for Session { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; - __size += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.address); + __size += u64::cairo_serialized_size(&__rust.expires_at); + __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.allowed_methods_root); + __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.metadata_hash); + __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.session_key_guid); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; - __out.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( - &__rust.address, + __out.extend(u64::cairo_serialize(&__rust.expires_at)); + __out.extend(starknet::core::types::Felt::cairo_serialize( + &__rust.allowed_methods_root, + )); + __out.extend(starknet::core::types::Felt::cairo_serialize( + &__rust.metadata_hash, + )); + __out.extend(starknet::core::types::Felt::cairo_serialize( + &__rust.session_key_guid, )); __out } @@ -388,27 +423,45 @@ impl cainome::cairo_serde::CairoSerde for DelegateAccountChanged { __offset: usize, ) -> cainome::cairo_serde::Result { let mut __offset = __offset; - let address = cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; - __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&address); - Ok(DelegateAccountChanged { address }) + let expires_at = u64::cairo_deserialize(__felts, __offset)?; + __offset += u64::cairo_serialized_size(&expires_at); + let allowed_methods_root = + starknet::core::types::Felt::cairo_deserialize(__felts, __offset)?; + __offset += starknet::core::types::Felt::cairo_serialized_size(&allowed_methods_root); + let metadata_hash = starknet::core::types::Felt::cairo_deserialize(__felts, __offset)?; + __offset += starknet::core::types::Felt::cairo_serialized_size(&metadata_hash); + let session_key_guid = starknet::core::types::Felt::cairo_deserialize(__felts, __offset)?; + __offset += starknet::core::types::Felt::cairo_serialized_size(&session_key_guid); + Ok(Session { + expires_at, + allowed_methods_root, + metadata_hash, + session_key_guid, + }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct OwnerAdded { - pub owner: Signer, +pub struct Signature { + pub r: cainome::cairo_serde::U256, + pub s: cainome::cairo_serde::U256, + pub y_parity: bool, } -impl cainome::cairo_serde::CairoSerde for OwnerAdded { +impl cainome::cairo_serde::CairoSerde for Signature { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; - __size += Signer::cairo_serialized_size(&__rust.owner); + __size += cainome::cairo_serde::U256::cairo_serialized_size(&__rust.r); + __size += cainome::cairo_serde::U256::cairo_serialized_size(&__rust.s); + __size += bool::cairo_serialized_size(&__rust.y_parity); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; - __out.extend(Signer::cairo_serialize(&__rust.owner)); + __out.extend(cainome::cairo_serde::U256::cairo_serialize(&__rust.r)); + __out.extend(cainome::cairo_serde::U256::cairo_serialize(&__rust.s)); + __out.extend(bool::cairo_serialize(&__rust.y_parity)); __out } fn cairo_deserialize( @@ -416,29 +469,31 @@ impl cainome::cairo_serde::CairoSerde for OwnerAdded { __offset: usize, ) -> cainome::cairo_serde::Result { let mut __offset = __offset; - let owner = Signer::cairo_deserialize(__felts, __offset)?; - __offset += Signer::cairo_serialized_size(&owner); - Ok(OwnerAdded { owner }) + let r = cainome::cairo_serde::U256::cairo_deserialize(__felts, __offset)?; + __offset += cainome::cairo_serde::U256::cairo_serialized_size(&r); + let s = cainome::cairo_serde::U256::cairo_deserialize(__felts, __offset)?; + __offset += cainome::cairo_serde::U256::cairo_serialized_size(&s); + let y_parity = bool::cairo_deserialize(__felts, __offset)?; + __offset += bool::cairo_serialized_size(&y_parity); + Ok(Signature { r, s, y_parity }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct Upgraded { - pub class_hash: cainome::cairo_serde::ClassHash, +pub struct OwnerRemoved { + pub owner: Signer, } -impl cainome::cairo_serde::CairoSerde for Upgraded { +impl cainome::cairo_serde::CairoSerde for OwnerRemoved { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; - __size += cainome::cairo_serde::ClassHash::cairo_serialized_size(&__rust.class_hash); + __size += Signer::cairo_serialized_size(&__rust.owner); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; - __out.extend(cainome::cairo_serde::ClassHash::cairo_serialize( - &__rust.class_hash, - )); + __out.extend(Signer::cairo_serialize(&__rust.owner)); __out } fn cairo_deserialize( @@ -446,9 +501,9 @@ impl cainome::cairo_serde::CairoSerde for Upgraded { __offset: usize, ) -> cainome::cairo_serde::Result { let mut __offset = __offset; - let class_hash = cainome::cairo_serde::ClassHash::cairo_deserialize(__felts, __offset)?; - __offset += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash); - Ok(Upgraded { class_hash }) + let owner = Signer::cairo_deserialize(__felts, __offset)?; + __offset += Signer::cairo_serialized_size(&owner); + Ok(OwnerRemoved { owner }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] @@ -500,85 +555,17 @@ impl cainome::cairo_serde::CairoSerde for Call { } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct Secp256k1Signer { - pub pubkey_hash: cainome::cairo_serde::EthAddress, -} -impl cainome::cairo_serde::CairoSerde for Secp256k1Signer { - type RustType = Self; - const SERIALIZED_SIZE: std::option::Option = None; - #[inline] - fn cairo_serialized_size(__rust: &Self::RustType) -> usize { - let mut __size = 0; - __size += cainome::cairo_serde::EthAddress::cairo_serialized_size(&__rust.pubkey_hash); - __size - } - fn cairo_serialize(__rust: &Self::RustType) -> Vec { - let mut __out: Vec = vec![]; - __out.extend(cainome::cairo_serde::EthAddress::cairo_serialize( - &__rust.pubkey_hash, - )); - __out - } - fn cairo_deserialize( - __felts: &[starknet::core::types::Felt], - __offset: usize, - ) -> cainome::cairo_serde::Result { - let mut __offset = __offset; - let pubkey_hash = cainome::cairo_serde::EthAddress::cairo_deserialize(__felts, __offset)?; - __offset += cainome::cairo_serde::EthAddress::cairo_serialized_size(&pubkey_hash); - Ok(Secp256k1Signer { pubkey_hash }) - } -} -#[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct Signature { - pub r: cainome::cairo_serde::U256, - pub s: cainome::cairo_serde::U256, - pub y_parity: bool, -} -impl cainome::cairo_serde::CairoSerde for Signature { - type RustType = Self; - const SERIALIZED_SIZE: std::option::Option = None; - #[inline] - fn cairo_serialized_size(__rust: &Self::RustType) -> usize { - let mut __size = 0; - __size += cainome::cairo_serde::U256::cairo_serialized_size(&__rust.r); - __size += cainome::cairo_serde::U256::cairo_serialized_size(&__rust.s); - __size += bool::cairo_serialized_size(&__rust.y_parity); - __size - } - fn cairo_serialize(__rust: &Self::RustType) -> Vec { - let mut __out: Vec = vec![]; - __out.extend(cainome::cairo_serde::U256::cairo_serialize(&__rust.r)); - __out.extend(cainome::cairo_serde::U256::cairo_serialize(&__rust.s)); - __out.extend(bool::cairo_serialize(&__rust.y_parity)); - __out - } - fn cairo_deserialize( - __felts: &[starknet::core::types::Felt], - __offset: usize, - ) -> cainome::cairo_serde::Result { - let mut __offset = __offset; - let r = cainome::cairo_serde::U256::cairo_deserialize(__felts, __offset)?; - __offset += cainome::cairo_serde::U256::cairo_serialized_size(&r); - let s = cainome::cairo_serde::U256::cairo_deserialize(__felts, __offset)?; - __offset += cainome::cairo_serde::U256::cairo_serialized_size(&s); - let y_parity = bool::cairo_deserialize(__felts, __offset)?; - __offset += bool::cairo_serialized_size(&y_parity); - Ok(Signature { r, s, y_parity }) - } -} -#[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct StarknetSigner { - pub pubkey: cainome::cairo_serde::NonZero, +pub struct Secp256r1Signer { + pub pubkey: cainome::cairo_serde::NonZero, } -impl cainome::cairo_serde::CairoSerde for StarknetSigner { +impl cainome::cairo_serde::CairoSerde for Secp256r1Signer { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; __size += - cainome::cairo_serde::NonZero::::cairo_serialized_size( + cainome::cairo_serde::NonZero::::cairo_serialized_size( &__rust.pubkey, ); __size @@ -586,7 +573,7 @@ impl cainome::cairo_serde::CairoSerde for StarknetSigner { fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; __out.extend( - cainome::cairo_serde::NonZero::::cairo_serialize( + cainome::cairo_serde::NonZero::::cairo_serialize( &__rust.pubkey, ), ); @@ -598,46 +585,33 @@ impl cainome::cairo_serde::CairoSerde for StarknetSigner { ) -> cainome::cairo_serde::Result { let mut __offset = __offset; let pubkey = - cainome::cairo_serde::NonZero::::cairo_deserialize( + cainome::cairo_serde::NonZero::::cairo_deserialize( __felts, __offset, )?; __offset += - cainome::cairo_serde::NonZero::::cairo_serialized_size( + cainome::cairo_serde::NonZero::::cairo_serialized_size( &pubkey, ); - Ok(StarknetSigner { pubkey }) + Ok(Secp256r1Signer { pubkey }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct Session { - pub expires_at: u64, - pub allowed_methods_root: starknet::core::types::Felt, - pub metadata_hash: starknet::core::types::Felt, - pub session_key_guid: starknet::core::types::Felt, +pub struct SessionRevoked { + pub session_hash: starknet::core::types::Felt, } -impl cainome::cairo_serde::CairoSerde for Session { +impl cainome::cairo_serde::CairoSerde for SessionRevoked { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; - __size += u64::cairo_serialized_size(&__rust.expires_at); - __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.allowed_methods_root); - __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.metadata_hash); - __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.session_key_guid); + __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.session_hash); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; - __out.extend(u64::cairo_serialize(&__rust.expires_at)); - __out.extend(starknet::core::types::Felt::cairo_serialize( - &__rust.allowed_methods_root, - )); - __out.extend(starknet::core::types::Felt::cairo_serialize( - &__rust.metadata_hash, - )); __out.extend(starknet::core::types::Felt::cairo_serialize( - &__rust.session_key_guid, + &__rust.session_hash, )); __out } @@ -646,21 +620,9 @@ impl cainome::cairo_serde::CairoSerde for Session { __offset: usize, ) -> cainome::cairo_serde::Result { let mut __offset = __offset; - let expires_at = u64::cairo_deserialize(__felts, __offset)?; - __offset += u64::cairo_serialized_size(&expires_at); - let allowed_methods_root = - starknet::core::types::Felt::cairo_deserialize(__felts, __offset)?; - __offset += starknet::core::types::Felt::cairo_serialized_size(&allowed_methods_root); - let metadata_hash = starknet::core::types::Felt::cairo_deserialize(__felts, __offset)?; - __offset += starknet::core::types::Felt::cairo_serialized_size(&metadata_hash); - let session_key_guid = starknet::core::types::Felt::cairo_deserialize(__felts, __offset)?; - __offset += starknet::core::types::Felt::cairo_serialized_size(&session_key_guid); - Ok(Session { - expires_at, - allowed_methods_root, - metadata_hash, - session_key_guid, - }) + let session_hash = starknet::core::types::Felt::cairo_deserialize(__felts, __offset)?; + __offset += starknet::core::types::Felt::cairo_serialized_size(&session_hash); + Ok(SessionRevoked { session_hash }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] @@ -726,6 +688,36 @@ impl cainome::cairo_serde::CairoSerde for WebauthnSignature { } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] +pub struct SessionRegistered { + pub session_hash: starknet::core::types::Felt, +} +impl cainome::cairo_serde::CairoSerde for SessionRegistered { + type RustType = Self; + const SERIALIZED_SIZE: std::option::Option = None; + #[inline] + fn cairo_serialized_size(__rust: &Self::RustType) -> usize { + let mut __size = 0; + __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.session_hash); + __size + } + fn cairo_serialize(__rust: &Self::RustType) -> Vec { + let mut __out: Vec = vec![]; + __out.extend(starknet::core::types::Felt::cairo_serialize( + &__rust.session_hash, + )); + __out + } + fn cairo_deserialize( + __felts: &[starknet::core::types::Felt], + __offset: usize, + ) -> cainome::cairo_serde::Result { + let mut __offset = __offset; + let session_hash = starknet::core::types::Felt::cairo_deserialize(__felts, __offset)?; + __offset += starknet::core::types::Felt::cairo_serialized_size(&session_hash); + Ok(SessionRegistered { session_hash }) + } +} +#[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] pub struct WebauthnSigner { pub origin: Vec, pub rp_id_hash: cainome::cairo_serde::NonZero, @@ -794,24 +786,28 @@ impl cainome::cairo_serde::CairoSerde for WebauthnSigner { } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct StarknetSignature { - pub r: starknet::core::types::Felt, - pub s: starknet::core::types::Felt, +pub struct StarknetSigner { + pub pubkey: cainome::cairo_serde::NonZero, } -impl cainome::cairo_serde::CairoSerde for StarknetSignature { +impl cainome::cairo_serde::CairoSerde for StarknetSigner { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; - __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.r); - __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.s); + __size += + cainome::cairo_serde::NonZero::::cairo_serialized_size( + &__rust.pubkey, + ); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; - __out.extend(starknet::core::types::Felt::cairo_serialize(&__rust.r)); - __out.extend(starknet::core::types::Felt::cairo_serialize(&__rust.s)); + __out.extend( + cainome::cairo_serde::NonZero::::cairo_serialize( + &__rust.pubkey, + ), + ); __out } fn cairo_deserialize( @@ -819,45 +815,45 @@ impl cainome::cairo_serde::CairoSerde for StarknetSignature { __offset: usize, ) -> cainome::cairo_serde::Result { let mut __offset = __offset; - let r = starknet::core::types::Felt::cairo_deserialize(__felts, __offset)?; - __offset += starknet::core::types::Felt::cairo_serialized_size(&r); - let s = starknet::core::types::Felt::cairo_deserialize(__felts, __offset)?; - __offset += starknet::core::types::Felt::cairo_serialized_size(&s); - Ok(StarknetSignature { r, s }) + let pubkey = + cainome::cairo_serde::NonZero::::cairo_deserialize( + __felts, __offset, + )?; + __offset += + cainome::cairo_serde::NonZero::::cairo_serialized_size( + &pubkey, + ); + Ok(StarknetSigner { pubkey }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub enum ExternalOwnersEvent { - ExternalOwnerRegistered(ExternalOwnerRegistered), - ExternalOwnerRemoved(ExternalOwnerRemoved), +pub enum MultipleOwnersEvent { + OwnerAdded(OwnerAdded), + OwnerRemoved(OwnerRemoved), } -impl cainome::cairo_serde::CairoSerde for ExternalOwnersEvent { +impl cainome::cairo_serde::CairoSerde for MultipleOwnersEvent { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { match __rust { - ExternalOwnersEvent::ExternalOwnerRegistered(val) => { - ExternalOwnerRegistered::cairo_serialized_size(val) + 1 - } - ExternalOwnersEvent::ExternalOwnerRemoved(val) => { - ExternalOwnerRemoved::cairo_serialized_size(val) + 1 - } + MultipleOwnersEvent::OwnerAdded(val) => OwnerAdded::cairo_serialized_size(val) + 1, + MultipleOwnersEvent::OwnerRemoved(val) => OwnerRemoved::cairo_serialized_size(val) + 1, _ => 0, } } fn cairo_serialize(__rust: &Self::RustType) -> Vec { match __rust { - ExternalOwnersEvent::ExternalOwnerRegistered(val) => { + MultipleOwnersEvent::OwnerAdded(val) => { let mut temp = vec![]; temp.extend(usize::cairo_serialize(&0usize)); - temp.extend(ExternalOwnerRegistered::cairo_serialize(val)); + temp.extend(OwnerAdded::cairo_serialize(val)); temp } - ExternalOwnersEvent::ExternalOwnerRemoved(val) => { + MultipleOwnersEvent::OwnerRemoved(val) => { let mut temp = vec![]; temp.extend(usize::cairo_serialize(&1usize)); - temp.extend(ExternalOwnerRemoved::cairo_serialize(val)); + temp.extend(OwnerRemoved::cairo_serialize(val)); temp } _ => vec![], @@ -870,22 +866,22 @@ impl cainome::cairo_serde::CairoSerde for ExternalOwnersEvent { let __f = __felts[__offset]; let __index = u128::from_be_bytes(__f.to_bytes_be()[16..].try_into().unwrap()); match __index as usize { - 0usize => Ok(ExternalOwnersEvent::ExternalOwnerRegistered( - ExternalOwnerRegistered::cairo_deserialize(__felts, __offset + 1)?, + 0usize => Ok(MultipleOwnersEvent::OwnerAdded( + OwnerAdded::cairo_deserialize(__felts, __offset + 1)?, )), - 1usize => Ok(ExternalOwnersEvent::ExternalOwnerRemoved( - ExternalOwnerRemoved::cairo_deserialize(__felts, __offset + 1)?, + 1usize => Ok(MultipleOwnersEvent::OwnerRemoved( + OwnerRemoved::cairo_deserialize(__felts, __offset + 1)?, )), _ => { return Err(cainome::cairo_serde::Error::Deserialize(format!( "Index not handle for enum {}", - "ExternalOwnersEvent" + "MultipleOwnersEvent" ))) } } } } -impl TryFrom for ExternalOwnersEvent { +impl TryFrom for MultipleOwnersEvent { type Error = String; fn try_from(event: starknet::core::types::EmittedEvent) -> Result { use cainome::cairo_serde::CairoSerde; @@ -894,51 +890,41 @@ impl TryFrom for ExternalOwnersEvent { } let selector = event.keys[0]; if selector - == starknet::core::utils::get_selector_from_name("ExternalOwnerRegistered") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "ExternalOwnerRegistered")) + == starknet::core::utils::get_selector_from_name("OwnerAdded") + .unwrap_or_else(|_| panic!("Invalid selector for {}", "OwnerAdded")) { let mut key_offset = 0 + 1; let mut data_offset = 0; - let address = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.data, - data_offset, - ) { + let owner = match Signer::cairo_deserialize(&event.data, data_offset) { Ok(v) => v, Err(e) => { return Err(format!( "Could not deserialize field {} for {}: {:?}", - "address", "ExternalOwnerRegistered", e + "owner", "OwnerAdded", e )) } }; - data_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&address); - return Ok(ExternalOwnersEvent::ExternalOwnerRegistered( - ExternalOwnerRegistered { address }, - )); + data_offset += Signer::cairo_serialized_size(&owner); + return Ok(MultipleOwnersEvent::OwnerAdded(OwnerAdded { owner })); }; let selector = event.keys[0]; if selector - == starknet::core::utils::get_selector_from_name("ExternalOwnerRemoved") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "ExternalOwnerRemoved")) + == starknet::core::utils::get_selector_from_name("OwnerRemoved") + .unwrap_or_else(|_| panic!("Invalid selector for {}", "OwnerRemoved")) { let mut key_offset = 0 + 1; let mut data_offset = 0; - let address = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.data, - data_offset, - ) { + let owner = match Signer::cairo_deserialize(&event.data, data_offset) { Ok(v) => v, Err(e) => { return Err(format!( "Could not deserialize field {} for {}: {:?}", - "address", "ExternalOwnerRemoved", e + "owner", "OwnerRemoved", e )) } }; - data_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&address); - return Ok(ExternalOwnersEvent::ExternalOwnerRemoved( - ExternalOwnerRemoved { address }, - )); + data_offset += Signer::cairo_serialized_size(&owner); + return Ok(MultipleOwnersEvent::OwnerRemoved(OwnerRemoved { owner })); }; Err(format!( "Could not match any event from keys {:?}", @@ -947,6 +933,110 @@ impl TryFrom for ExternalOwnersEvent { } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] +pub enum SignerSignature { + Starknet((StarknetSigner, StarknetSignature)), + Secp256k1((Secp256k1Signer, Signature)), + Secp256r1((Secp256r1Signer, Signature)), + Eip191((Eip191Signer, Signature)), + Webauthn((WebauthnSigner, WebauthnSignature)), +} +impl cainome::cairo_serde::CairoSerde for SignerSignature { + type RustType = Self; + const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; + #[inline] + fn cairo_serialized_size(__rust: &Self::RustType) -> usize { + match __rust { + SignerSignature::Starknet(val) => { + <(StarknetSigner, StarknetSignature)>::cairo_serialized_size(val) + 1 + } + SignerSignature::Secp256k1(val) => { + <(Secp256k1Signer, Signature)>::cairo_serialized_size(val) + 1 + } + SignerSignature::Secp256r1(val) => { + <(Secp256r1Signer, Signature)>::cairo_serialized_size(val) + 1 + } + SignerSignature::Eip191(val) => { + <(Eip191Signer, Signature)>::cairo_serialized_size(val) + 1 + } + SignerSignature::Webauthn(val) => { + <(WebauthnSigner, WebauthnSignature)>::cairo_serialized_size(val) + 1 + } + _ => 0, + } + } + fn cairo_serialize(__rust: &Self::RustType) -> Vec { + match __rust { + SignerSignature::Starknet(val) => { + let mut temp = vec![]; + temp.extend(usize::cairo_serialize(&0usize)); + temp.extend(<(StarknetSigner, StarknetSignature)>::cairo_serialize(val)); + temp + } + SignerSignature::Secp256k1(val) => { + let mut temp = vec![]; + temp.extend(usize::cairo_serialize(&1usize)); + temp.extend(<(Secp256k1Signer, Signature)>::cairo_serialize(val)); + temp + } + SignerSignature::Secp256r1(val) => { + let mut temp = vec![]; + temp.extend(usize::cairo_serialize(&2usize)); + temp.extend(<(Secp256r1Signer, Signature)>::cairo_serialize(val)); + temp + } + SignerSignature::Eip191(val) => { + let mut temp = vec![]; + temp.extend(usize::cairo_serialize(&3usize)); + temp.extend(<(Eip191Signer, Signature)>::cairo_serialize(val)); + temp + } + SignerSignature::Webauthn(val) => { + let mut temp = vec![]; + temp.extend(usize::cairo_serialize(&4usize)); + temp.extend(<(WebauthnSigner, WebauthnSignature)>::cairo_serialize(val)); + temp + } + _ => vec![], + } + } + fn cairo_deserialize( + __felts: &[starknet::core::types::Felt], + __offset: usize, + ) -> cainome::cairo_serde::Result { + let __f = __felts[__offset]; + let __index = u128::from_be_bytes(__f.to_bytes_be()[16..].try_into().unwrap()); + match __index as usize { + 0usize => Ok(SignerSignature::Starknet(<( + StarknetSigner, + StarknetSignature, + )>::cairo_deserialize( + __felts, __offset + 1 + )?)), + 1usize => Ok(SignerSignature::Secp256k1( + <(Secp256k1Signer, Signature)>::cairo_deserialize(__felts, __offset + 1)?, + )), + 2usize => Ok(SignerSignature::Secp256r1( + <(Secp256r1Signer, Signature)>::cairo_deserialize(__felts, __offset + 1)?, + )), + 3usize => Ok(SignerSignature::Eip191( + <(Eip191Signer, Signature)>::cairo_deserialize(__felts, __offset + 1)?, + )), + 4usize => Ok(SignerSignature::Webauthn(<( + WebauthnSigner, + WebauthnSignature, + )>::cairo_deserialize( + __felts, __offset + 1 + )?)), + _ => { + return Err(cainome::cairo_serde::Error::Deserialize(format!( + "Index not handle for enum {}", + "SignerSignature" + ))) + } + } + } +} +#[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] pub enum Event { TransactionExecuted(TransactionExecuted), MultipleOwnersEvent(MultipleOwnersEvent), @@ -1320,57 +1410,35 @@ impl TryFrom for Event { } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub enum Signer { - Starknet(StarknetSigner), - Secp256k1(Secp256k1Signer), - Secp256r1(Secp256r1Signer), - Eip191(Eip191Signer), - Webauthn(WebauthnSigner), +pub enum SessionEvent { + SessionRevoked(SessionRevoked), + SessionRegistered(SessionRegistered), } -impl cainome::cairo_serde::CairoSerde for Signer { +impl cainome::cairo_serde::CairoSerde for SessionEvent { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { match __rust { - Signer::Starknet(val) => StarknetSigner::cairo_serialized_size(val) + 1, - Signer::Secp256k1(val) => Secp256k1Signer::cairo_serialized_size(val) + 1, - Signer::Secp256r1(val) => Secp256r1Signer::cairo_serialized_size(val) + 1, - Signer::Eip191(val) => Eip191Signer::cairo_serialized_size(val) + 1, - Signer::Webauthn(val) => WebauthnSigner::cairo_serialized_size(val) + 1, + SessionEvent::SessionRevoked(val) => SessionRevoked::cairo_serialized_size(val) + 1, + SessionEvent::SessionRegistered(val) => { + SessionRegistered::cairo_serialized_size(val) + 1 + } _ => 0, } } fn cairo_serialize(__rust: &Self::RustType) -> Vec { match __rust { - Signer::Starknet(val) => { + SessionEvent::SessionRevoked(val) => { let mut temp = vec![]; temp.extend(usize::cairo_serialize(&0usize)); - temp.extend(StarknetSigner::cairo_serialize(val)); + temp.extend(SessionRevoked::cairo_serialize(val)); temp } - Signer::Secp256k1(val) => { + SessionEvent::SessionRegistered(val) => { let mut temp = vec![]; temp.extend(usize::cairo_serialize(&1usize)); - temp.extend(Secp256k1Signer::cairo_serialize(val)); - temp - } - Signer::Secp256r1(val) => { - let mut temp = vec![]; - temp.extend(usize::cairo_serialize(&2usize)); - temp.extend(Secp256r1Signer::cairo_serialize(val)); - temp - } - Signer::Eip191(val) => { - let mut temp = vec![]; - temp.extend(usize::cairo_serialize(&3usize)); - temp.extend(Eip191Signer::cairo_serialize(val)); - temp - } - Signer::Webauthn(val) => { - let mut temp = vec![]; - temp.extend(usize::cairo_serialize(&4usize)); - temp.extend(WebauthnSigner::cairo_serialize(val)); + temp.extend(SessionRegistered::cairo_serialize(val)); temp } _ => vec![], @@ -1383,59 +1451,147 @@ impl cainome::cairo_serde::CairoSerde for Signer { let __f = __felts[__offset]; let __index = u128::from_be_bytes(__f.to_bytes_be()[16..].try_into().unwrap()); match __index as usize { - 0usize => Ok(Signer::Starknet(StarknetSigner::cairo_deserialize( - __felts, - __offset + 1, - )?)), - 1usize => Ok(Signer::Secp256k1(Secp256k1Signer::cairo_deserialize( - __felts, - __offset + 1, - )?)), - 2usize => Ok(Signer::Secp256r1(Secp256r1Signer::cairo_deserialize( - __felts, - __offset + 1, - )?)), - 3usize => Ok(Signer::Eip191(Eip191Signer::cairo_deserialize( - __felts, - __offset + 1, - )?)), - 4usize => Ok(Signer::Webauthn(WebauthnSigner::cairo_deserialize( - __felts, - __offset + 1, - )?)), + 0usize => Ok(SessionEvent::SessionRevoked( + SessionRevoked::cairo_deserialize(__felts, __offset + 1)?, + )), + 1usize => Ok(SessionEvent::SessionRegistered( + SessionRegistered::cairo_deserialize(__felts, __offset + 1)?, + )), _ => { return Err(cainome::cairo_serde::Error::Deserialize(format!( "Index not handle for enum {}", - "Signer" + "SessionEvent" ))) } } } } -#[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub enum DelegateAccountEvent { - DelegateAccountChanged(DelegateAccountChanged), +impl TryFrom for SessionEvent { + type Error = String; + fn try_from(event: starknet::core::types::EmittedEvent) -> Result { + use cainome::cairo_serde::CairoSerde; + if event.keys.is_empty() { + return Err("Event has no key".to_string()); + } + let selector = event.keys[0]; + if selector + == starknet::core::utils::get_selector_from_name("SessionRevoked") + .unwrap_or_else(|_| panic!("Invalid selector for {}", "SessionRevoked")) + { + let mut key_offset = 0 + 1; + let mut data_offset = 0; + let session_hash = + match starknet::core::types::Felt::cairo_deserialize(&event.data, data_offset) { + Ok(v) => v, + Err(e) => { + return Err(format!( + "Could not deserialize field {} for {}: {:?}", + "session_hash", "SessionRevoked", e + )) + } + }; + data_offset += starknet::core::types::Felt::cairo_serialized_size(&session_hash); + return Ok(SessionEvent::SessionRevoked(SessionRevoked { + session_hash, + })); + }; + let selector = event.keys[0]; + if selector + == starknet::core::utils::get_selector_from_name("SessionRegistered") + .unwrap_or_else(|_| panic!("Invalid selector for {}", "SessionRegistered")) + { + let mut key_offset = 0 + 1; + let mut data_offset = 0; + let session_hash = + match starknet::core::types::Felt::cairo_deserialize(&event.data, data_offset) { + Ok(v) => v, + Err(e) => { + return Err(format!( + "Could not deserialize field {} for {}: {:?}", + "session_hash", "SessionRegistered", e + )) + } + }; + data_offset += starknet::core::types::Felt::cairo_serialized_size(&session_hash); + return Ok(SessionEvent::SessionRegistered(SessionRegistered { + session_hash, + })); + }; + Err(format!( + "Could not match any event from keys {:?}", + event.keys + )) + } } -impl cainome::cairo_serde::CairoSerde for DelegateAccountEvent { +#[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] +pub enum OutsideExecutionEvent {} +impl cainome::cairo_serde::CairoSerde for OutsideExecutionEvent { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { match __rust { - DelegateAccountEvent::DelegateAccountChanged(val) => { - DelegateAccountChanged::cairo_serialized_size(val) + 1 - } _ => 0, } } fn cairo_serialize(__rust: &Self::RustType) -> Vec { match __rust { - DelegateAccountEvent::DelegateAccountChanged(val) => { - let mut temp = vec![]; - temp.extend(usize::cairo_serialize(&0usize)); - temp.extend(DelegateAccountChanged::cairo_serialize(val)); - temp - } + _ => vec![], + } + } + fn cairo_deserialize( + __felts: &[starknet::core::types::Felt], + __offset: usize, + ) -> cainome::cairo_serde::Result { + let __f = __felts[__offset]; + let __index = u128::from_be_bytes(__f.to_bytes_be()[16..].try_into().unwrap()); + match __index as usize { + _ => { + return Err(cainome::cairo_serde::Error::Deserialize(format!( + "Index not handle for enum {}", + "OutsideExecutionEvent" + ))) + } + } + } +} +impl TryFrom for OutsideExecutionEvent { + type Error = String; + fn try_from(event: starknet::core::types::EmittedEvent) -> Result { + use cainome::cairo_serde::CairoSerde; + if event.keys.is_empty() { + return Err("Event has no key".to_string()); + } + Err(format!( + "Could not match any event from keys {:?}", + event.keys + )) + } +} +#[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] +pub enum DelegateAccountEvent { + DelegateAccountChanged(DelegateAccountChanged), +} +impl cainome::cairo_serde::CairoSerde for DelegateAccountEvent { + type RustType = Self; + const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; + #[inline] + fn cairo_serialized_size(__rust: &Self::RustType) -> usize { + match __rust { + DelegateAccountEvent::DelegateAccountChanged(val) => { + DelegateAccountChanged::cairo_serialized_size(val) + 1 + } + _ => 0, + } + } + fn cairo_serialize(__rust: &Self::RustType) -> Vec { + match __rust { + DelegateAccountEvent::DelegateAccountChanged(val) => { + let mut temp = vec![]; + temp.extend(usize::cairo_serialize(&0usize)); + temp.extend(DelegateAccountChanged::cairo_serialize(val)); + temp + } _ => vec![], } } @@ -1496,18 +1652,59 @@ impl TryFrom for DelegateAccountEvent { } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub enum OutsideExecutionEvent {} -impl cainome::cairo_serde::CairoSerde for OutsideExecutionEvent { +pub enum Signer { + Starknet(StarknetSigner), + Secp256k1(Secp256k1Signer), + Secp256r1(Secp256r1Signer), + Eip191(Eip191Signer), + Webauthn(WebauthnSigner), +} +impl cainome::cairo_serde::CairoSerde for Signer { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { match __rust { + Signer::Starknet(val) => StarknetSigner::cairo_serialized_size(val) + 1, + Signer::Secp256k1(val) => Secp256k1Signer::cairo_serialized_size(val) + 1, + Signer::Secp256r1(val) => Secp256r1Signer::cairo_serialized_size(val) + 1, + Signer::Eip191(val) => Eip191Signer::cairo_serialized_size(val) + 1, + Signer::Webauthn(val) => WebauthnSigner::cairo_serialized_size(val) + 1, _ => 0, } } fn cairo_serialize(__rust: &Self::RustType) -> Vec { match __rust { + Signer::Starknet(val) => { + let mut temp = vec![]; + temp.extend(usize::cairo_serialize(&0usize)); + temp.extend(StarknetSigner::cairo_serialize(val)); + temp + } + Signer::Secp256k1(val) => { + let mut temp = vec![]; + temp.extend(usize::cairo_serialize(&1usize)); + temp.extend(Secp256k1Signer::cairo_serialize(val)); + temp + } + Signer::Secp256r1(val) => { + let mut temp = vec![]; + temp.extend(usize::cairo_serialize(&2usize)); + temp.extend(Secp256r1Signer::cairo_serialize(val)); + temp + } + Signer::Eip191(val) => { + let mut temp = vec![]; + temp.extend(usize::cairo_serialize(&3usize)); + temp.extend(Eip191Signer::cairo_serialize(val)); + temp + } + Signer::Webauthn(val) => { + let mut temp = vec![]; + temp.extend(usize::cairo_serialize(&4usize)); + temp.extend(WebauthnSigner::cairo_serialize(val)); + temp + } _ => vec![], } } @@ -1518,56 +1715,67 @@ impl cainome::cairo_serde::CairoSerde for OutsideExecutionEvent { let __f = __felts[__offset]; let __index = u128::from_be_bytes(__f.to_bytes_be()[16..].try_into().unwrap()); match __index as usize { + 0usize => Ok(Signer::Starknet(StarknetSigner::cairo_deserialize( + __felts, + __offset + 1, + )?)), + 1usize => Ok(Signer::Secp256k1(Secp256k1Signer::cairo_deserialize( + __felts, + __offset + 1, + )?)), + 2usize => Ok(Signer::Secp256r1(Secp256r1Signer::cairo_deserialize( + __felts, + __offset + 1, + )?)), + 3usize => Ok(Signer::Eip191(Eip191Signer::cairo_deserialize( + __felts, + __offset + 1, + )?)), + 4usize => Ok(Signer::Webauthn(WebauthnSigner::cairo_deserialize( + __felts, + __offset + 1, + )?)), _ => { return Err(cainome::cairo_serde::Error::Deserialize(format!( "Index not handle for enum {}", - "OutsideExecutionEvent" + "Signer" ))) } } } } -impl TryFrom for OutsideExecutionEvent { - type Error = String; - fn try_from(event: starknet::core::types::EmittedEvent) -> Result { - use cainome::cairo_serde::CairoSerde; - if event.keys.is_empty() { - return Err("Event has no key".to_string()); - } - Err(format!( - "Could not match any event from keys {:?}", - event.keys - )) - } -} #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub enum MultipleOwnersEvent { - OwnerAdded(OwnerAdded), - OwnerRemoved(OwnerRemoved), +pub enum ExternalOwnersEvent { + ExternalOwnerRegistered(ExternalOwnerRegistered), + ExternalOwnerRemoved(ExternalOwnerRemoved), } -impl cainome::cairo_serde::CairoSerde for MultipleOwnersEvent { +impl cainome::cairo_serde::CairoSerde for ExternalOwnersEvent { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { match __rust { - MultipleOwnersEvent::OwnerAdded(val) => OwnerAdded::cairo_serialized_size(val) + 1, - MultipleOwnersEvent::OwnerRemoved(val) => OwnerRemoved::cairo_serialized_size(val) + 1, + ExternalOwnersEvent::ExternalOwnerRegistered(val) => { + ExternalOwnerRegistered::cairo_serialized_size(val) + 1 + } + ExternalOwnersEvent::ExternalOwnerRemoved(val) => { + ExternalOwnerRemoved::cairo_serialized_size(val) + 1 + } _ => 0, } } fn cairo_serialize(__rust: &Self::RustType) -> Vec { match __rust { - MultipleOwnersEvent::OwnerAdded(val) => { + ExternalOwnersEvent::ExternalOwnerRegistered(val) => { let mut temp = vec![]; temp.extend(usize::cairo_serialize(&0usize)); - temp.extend(OwnerAdded::cairo_serialize(val)); + temp.extend(ExternalOwnerRegistered::cairo_serialize(val)); temp } - MultipleOwnersEvent::OwnerRemoved(val) => { + ExternalOwnersEvent::ExternalOwnerRemoved(val) => { let mut temp = vec![]; temp.extend(usize::cairo_serialize(&1usize)); - temp.extend(OwnerRemoved::cairo_serialize(val)); + temp.extend(ExternalOwnerRemoved::cairo_serialize(val)); temp } _ => vec![], @@ -1580,22 +1788,22 @@ impl cainome::cairo_serde::CairoSerde for MultipleOwnersEvent { let __f = __felts[__offset]; let __index = u128::from_be_bytes(__f.to_bytes_be()[16..].try_into().unwrap()); match __index as usize { - 0usize => Ok(MultipleOwnersEvent::OwnerAdded( - OwnerAdded::cairo_deserialize(__felts, __offset + 1)?, + 0usize => Ok(ExternalOwnersEvent::ExternalOwnerRegistered( + ExternalOwnerRegistered::cairo_deserialize(__felts, __offset + 1)?, )), - 1usize => Ok(MultipleOwnersEvent::OwnerRemoved( - OwnerRemoved::cairo_deserialize(__felts, __offset + 1)?, + 1usize => Ok(ExternalOwnersEvent::ExternalOwnerRemoved( + ExternalOwnerRemoved::cairo_deserialize(__felts, __offset + 1)?, )), _ => { return Err(cainome::cairo_serde::Error::Deserialize(format!( "Index not handle for enum {}", - "MultipleOwnersEvent" + "ExternalOwnersEvent" ))) } } } } -impl TryFrom for MultipleOwnersEvent { +impl TryFrom for ExternalOwnersEvent { type Error = String; fn try_from(event: starknet::core::types::EmittedEvent) -> Result { use cainome::cairo_serde::CairoSerde; @@ -1604,41 +1812,51 @@ impl TryFrom for MultipleOwnersEvent { } let selector = event.keys[0]; if selector - == starknet::core::utils::get_selector_from_name("OwnerAdded") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "OwnerAdded")) + == starknet::core::utils::get_selector_from_name("ExternalOwnerRegistered") + .unwrap_or_else(|_| panic!("Invalid selector for {}", "ExternalOwnerRegistered")) { let mut key_offset = 0 + 1; let mut data_offset = 0; - let owner = match Signer::cairo_deserialize(&event.data, data_offset) { + let address = match cainome::cairo_serde::ContractAddress::cairo_deserialize( + &event.data, + data_offset, + ) { Ok(v) => v, Err(e) => { return Err(format!( "Could not deserialize field {} for {}: {:?}", - "owner", "OwnerAdded", e + "address", "ExternalOwnerRegistered", e )) } }; - data_offset += Signer::cairo_serialized_size(&owner); - return Ok(MultipleOwnersEvent::OwnerAdded(OwnerAdded { owner })); + data_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&address); + return Ok(ExternalOwnersEvent::ExternalOwnerRegistered( + ExternalOwnerRegistered { address }, + )); }; let selector = event.keys[0]; if selector - == starknet::core::utils::get_selector_from_name("OwnerRemoved") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "OwnerRemoved")) + == starknet::core::utils::get_selector_from_name("ExternalOwnerRemoved") + .unwrap_or_else(|_| panic!("Invalid selector for {}", "ExternalOwnerRemoved")) { let mut key_offset = 0 + 1; let mut data_offset = 0; - let owner = match Signer::cairo_deserialize(&event.data, data_offset) { + let address = match cainome::cairo_serde::ContractAddress::cairo_deserialize( + &event.data, + data_offset, + ) { Ok(v) => v, Err(e) => { return Err(format!( "Could not deserialize field {} for {}: {:?}", - "owner", "OwnerRemoved", e + "address", "ExternalOwnerRemoved", e )) } }; - data_offset += Signer::cairo_serialized_size(&owner); - return Ok(MultipleOwnersEvent::OwnerRemoved(OwnerRemoved { owner })); + data_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&address); + return Ok(ExternalOwnersEvent::ExternalOwnerRemoved( + ExternalOwnerRemoved { address }, + )); }; Err(format!( "Could not match any event from keys {:?}", @@ -1688,8 +1906,8 @@ impl cainome::cairo_serde::CairoSerde for Sha256Implementation { } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub enum Src5ComponentEvent {} -impl cainome::cairo_serde::CairoSerde for Src5ComponentEvent { +pub enum ReentrancyGuardEvent {} +impl cainome::cairo_serde::CairoSerde for ReentrancyGuardEvent { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; #[inline] @@ -1713,13 +1931,13 @@ impl cainome::cairo_serde::CairoSerde for Src5ComponentEvent { _ => { return Err(cainome::cairo_serde::Error::Deserialize(format!( "Index not handle for enum {}", - "Src5ComponentEvent" + "ReentrancyGuardEvent" ))) } } } } -impl TryFrom for Src5ComponentEvent { +impl TryFrom for ReentrancyGuardEvent { type Error = String; fn try_from(event: starknet::core::types::EmittedEvent) -> Result { use cainome::cairo_serde::CairoSerde; @@ -1733,35 +1951,25 @@ impl TryFrom for Src5ComponentEvent { } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub enum SessionEvent { - SessionRevoked(SessionRevoked), - SessionRegistered(SessionRegistered), +pub enum UpgradeEvent { + Upgraded(Upgraded), } -impl cainome::cairo_serde::CairoSerde for SessionEvent { +impl cainome::cairo_serde::CairoSerde for UpgradeEvent { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { match __rust { - SessionEvent::SessionRevoked(val) => SessionRevoked::cairo_serialized_size(val) + 1, - SessionEvent::SessionRegistered(val) => { - SessionRegistered::cairo_serialized_size(val) + 1 - } + UpgradeEvent::Upgraded(val) => Upgraded::cairo_serialized_size(val) + 1, _ => 0, } } fn cairo_serialize(__rust: &Self::RustType) -> Vec { match __rust { - SessionEvent::SessionRevoked(val) => { + UpgradeEvent::Upgraded(val) => { let mut temp = vec![]; temp.extend(usize::cairo_serialize(&0usize)); - temp.extend(SessionRevoked::cairo_serialize(val)); - temp - } - SessionEvent::SessionRegistered(val) => { - let mut temp = vec![]; - temp.extend(usize::cairo_serialize(&1usize)); - temp.extend(SessionRegistered::cairo_serialize(val)); + temp.extend(Upgraded::cairo_serialize(val)); temp } _ => vec![], @@ -1774,22 +1982,20 @@ impl cainome::cairo_serde::CairoSerde for SessionEvent { let __f = __felts[__offset]; let __index = u128::from_be_bytes(__f.to_bytes_be()[16..].try_into().unwrap()); match __index as usize { - 0usize => Ok(SessionEvent::SessionRevoked( - SessionRevoked::cairo_deserialize(__felts, __offset + 1)?, - )), - 1usize => Ok(SessionEvent::SessionRegistered( - SessionRegistered::cairo_deserialize(__felts, __offset + 1)?, - )), + 0usize => Ok(UpgradeEvent::Upgraded(Upgraded::cairo_deserialize( + __felts, + __offset + 1, + )?)), _ => { return Err(cainome::cairo_serde::Error::Deserialize(format!( "Index not handle for enum {}", - "SessionEvent" + "UpgradeEvent" ))) } } } } -impl TryFrom for SessionEvent { +impl TryFrom for UpgradeEvent { type Error = String; fn try_from(event: starknet::core::types::EmittedEvent) -> Result { use cainome::cairo_serde::CairoSerde; @@ -1798,110 +2004,8 @@ impl TryFrom for SessionEvent { } let selector = event.keys[0]; if selector - == starknet::core::utils::get_selector_from_name("SessionRevoked") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "SessionRevoked")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let session_hash = - match starknet::core::types::Felt::cairo_deserialize(&event.data, data_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "session_hash", "SessionRevoked", e - )) - } - }; - data_offset += starknet::core::types::Felt::cairo_serialized_size(&session_hash); - return Ok(SessionEvent::SessionRevoked(SessionRevoked { - session_hash, - })); - }; - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("SessionRegistered") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "SessionRegistered")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let session_hash = - match starknet::core::types::Felt::cairo_deserialize(&event.data, data_offset) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "session_hash", "SessionRegistered", e - )) - } - }; - data_offset += starknet::core::types::Felt::cairo_serialized_size(&session_hash); - return Ok(SessionEvent::SessionRegistered(SessionRegistered { - session_hash, - })); - }; - Err(format!( - "Could not match any event from keys {:?}", - event.keys - )) - } -} -#[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub enum UpgradeEvent { - Upgraded(Upgraded), -} -impl cainome::cairo_serde::CairoSerde for UpgradeEvent { - type RustType = Self; - const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; - #[inline] - fn cairo_serialized_size(__rust: &Self::RustType) -> usize { - match __rust { - UpgradeEvent::Upgraded(val) => Upgraded::cairo_serialized_size(val) + 1, - _ => 0, - } - } - fn cairo_serialize(__rust: &Self::RustType) -> Vec { - match __rust { - UpgradeEvent::Upgraded(val) => { - let mut temp = vec![]; - temp.extend(usize::cairo_serialize(&0usize)); - temp.extend(Upgraded::cairo_serialize(val)); - temp - } - _ => vec![], - } - } - fn cairo_deserialize( - __felts: &[starknet::core::types::Felt], - __offset: usize, - ) -> cainome::cairo_serde::Result { - let __f = __felts[__offset]; - let __index = u128::from_be_bytes(__f.to_bytes_be()[16..].try_into().unwrap()); - match __index as usize { - 0usize => Ok(UpgradeEvent::Upgraded(Upgraded::cairo_deserialize( - __felts, - __offset + 1, - )?)), - _ => { - return Err(cainome::cairo_serde::Error::Deserialize(format!( - "Index not handle for enum {}", - "UpgradeEvent" - ))) - } - } - } -} -impl TryFrom for UpgradeEvent { - type Error = String; - fn try_from(event: starknet::core::types::EmittedEvent) -> Result { - use cainome::cairo_serde::CairoSerde; - if event.keys.is_empty() { - return Err("Event has no key".to_string()); - } - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("Upgraded") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "Upgraded")) + == starknet::core::utils::get_selector_from_name("Upgraded") + .unwrap_or_else(|_| panic!("Invalid selector for {}", "Upgraded")) { let mut key_offset = 0 + 1; let mut data_offset = 0; @@ -1927,112 +2031,8 @@ impl TryFrom for UpgradeEvent { } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub enum SignerSignature { - Starknet((StarknetSigner, StarknetSignature)), - Secp256k1((Secp256k1Signer, Signature)), - Secp256r1((Secp256r1Signer, Signature)), - Eip191((Eip191Signer, Signature)), - Webauthn((WebauthnSigner, WebauthnSignature)), -} -impl cainome::cairo_serde::CairoSerde for SignerSignature { - type RustType = Self; - const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; - #[inline] - fn cairo_serialized_size(__rust: &Self::RustType) -> usize { - match __rust { - SignerSignature::Starknet(val) => { - <(StarknetSigner, StarknetSignature)>::cairo_serialized_size(val) + 1 - } - SignerSignature::Secp256k1(val) => { - <(Secp256k1Signer, Signature)>::cairo_serialized_size(val) + 1 - } - SignerSignature::Secp256r1(val) => { - <(Secp256r1Signer, Signature)>::cairo_serialized_size(val) + 1 - } - SignerSignature::Eip191(val) => { - <(Eip191Signer, Signature)>::cairo_serialized_size(val) + 1 - } - SignerSignature::Webauthn(val) => { - <(WebauthnSigner, WebauthnSignature)>::cairo_serialized_size(val) + 1 - } - _ => 0, - } - } - fn cairo_serialize(__rust: &Self::RustType) -> Vec { - match __rust { - SignerSignature::Starknet(val) => { - let mut temp = vec![]; - temp.extend(usize::cairo_serialize(&0usize)); - temp.extend(<(StarknetSigner, StarknetSignature)>::cairo_serialize(val)); - temp - } - SignerSignature::Secp256k1(val) => { - let mut temp = vec![]; - temp.extend(usize::cairo_serialize(&1usize)); - temp.extend(<(Secp256k1Signer, Signature)>::cairo_serialize(val)); - temp - } - SignerSignature::Secp256r1(val) => { - let mut temp = vec![]; - temp.extend(usize::cairo_serialize(&2usize)); - temp.extend(<(Secp256r1Signer, Signature)>::cairo_serialize(val)); - temp - } - SignerSignature::Eip191(val) => { - let mut temp = vec![]; - temp.extend(usize::cairo_serialize(&3usize)); - temp.extend(<(Eip191Signer, Signature)>::cairo_serialize(val)); - temp - } - SignerSignature::Webauthn(val) => { - let mut temp = vec![]; - temp.extend(usize::cairo_serialize(&4usize)); - temp.extend(<(WebauthnSigner, WebauthnSignature)>::cairo_serialize(val)); - temp - } - _ => vec![], - } - } - fn cairo_deserialize( - __felts: &[starknet::core::types::Felt], - __offset: usize, - ) -> cainome::cairo_serde::Result { - let __f = __felts[__offset]; - let __index = u128::from_be_bytes(__f.to_bytes_be()[16..].try_into().unwrap()); - match __index as usize { - 0usize => Ok(SignerSignature::Starknet(<( - StarknetSigner, - StarknetSignature, - )>::cairo_deserialize( - __felts, __offset + 1 - )?)), - 1usize => Ok(SignerSignature::Secp256k1( - <(Secp256k1Signer, Signature)>::cairo_deserialize(__felts, __offset + 1)?, - )), - 2usize => Ok(SignerSignature::Secp256r1( - <(Secp256r1Signer, Signature)>::cairo_deserialize(__felts, __offset + 1)?, - )), - 3usize => Ok(SignerSignature::Eip191( - <(Eip191Signer, Signature)>::cairo_deserialize(__felts, __offset + 1)?, - )), - 4usize => Ok(SignerSignature::Webauthn(<( - WebauthnSigner, - WebauthnSignature, - )>::cairo_deserialize( - __felts, __offset + 1 - )?)), - _ => { - return Err(cainome::cairo_serde::Error::Deserialize(format!( - "Index not handle for enum {}", - "SignerSignature" - ))) - } - } - } -} -#[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub enum ReentrancyGuardEvent {} -impl cainome::cairo_serde::CairoSerde for ReentrancyGuardEvent { +pub enum Src5ComponentEvent {} +impl cainome::cairo_serde::CairoSerde for Src5ComponentEvent { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; #[inline] @@ -2056,13 +2056,13 @@ impl cainome::cairo_serde::CairoSerde for ReentrancyGuardEvent { _ => { return Err(cainome::cairo_serde::Error::Deserialize(format!( "Index not handle for enum {}", - "ReentrancyGuardEvent" + "Src5ComponentEvent" ))) } } } } -impl TryFrom for ReentrancyGuardEvent { +impl TryFrom for Src5ComponentEvent { type Error = String; fn try_from(event: starknet::core::types::EmittedEvent) -> Result { use cainome::cairo_serde::CairoSerde; @@ -2078,80 +2078,66 @@ impl TryFrom for ReentrancyGuardEvent { impl Controller { #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn is_external_owner( + pub fn is_owner( &self, - external_owner_address: &cainome::cairo_serde::ContractAddress, + owner_guid: &starknet::core::types::Felt, ) -> cainome::cairo_serde::call::FCall { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - __calldata.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( - external_owner_address, - )); + __calldata.extend(starknet::core::types::Felt::cairo_serialize(owner_guid)); let __call = starknet::core::types::FunctionCall { contract_address: self.address, - entry_point_selector: starknet::macros::selector!("is_external_owner"), + entry_point_selector: starknet::macros::selector!("is_owner"), calldata: __calldata, }; cainome::cairo_serde::call::FCall::new(__call, self.provider()) } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn is_session_revoked( + pub fn assert_valid_owner_signature( &self, - session_hash: &starknet::core::types::Felt, - ) -> cainome::cairo_serde::call::FCall { + signer_signature: &SignerSignature, + ) -> cainome::cairo_serde::call::FCall { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - __calldata.extend(starknet::core::types::Felt::cairo_serialize(session_hash)); + __calldata.extend(SignerSignature::cairo_serialize(signer_signature)); let __call = starknet::core::types::FunctionCall { contract_address: self.address, - entry_point_selector: starknet::macros::selector!("is_session_revoked"), + entry_point_selector: starknet::macros::selector!("assert_valid_owner_signature"), calldata: __calldata, }; cainome::cairo_serde::call::FCall::new(__call, self.provider()) } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn is_owner( + pub fn is_external_owner( &self, - owner_guid: &starknet::core::types::Felt, + external_owner_address: &cainome::cairo_serde::ContractAddress, ) -> cainome::cairo_serde::call::FCall { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - __calldata.extend(starknet::core::types::Felt::cairo_serialize(owner_guid)); - let __call = starknet::core::types::FunctionCall { - contract_address: self.address, - entry_point_selector: starknet::macros::selector!("is_owner"), - calldata: __calldata, - }; - cainome::cairo_serde::call::FCall::new(__call, self.provider()) - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] - pub fn assert_valid_owner_signature( - &self, - signer_signature: &SignerSignature, - ) -> cainome::cairo_serde::call::FCall { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - __calldata.extend(SignerSignature::cairo_serialize(signer_signature)); + __calldata.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( + external_owner_address, + )); let __call = starknet::core::types::FunctionCall { contract_address: self.address, - entry_point_selector: starknet::macros::selector!("assert_valid_owner_signature"), + entry_point_selector: starknet::macros::selector!("is_external_owner"), calldata: __calldata, }; cainome::cairo_serde::call::FCall::new(__call, self.provider()) } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn delegate_account( + pub fn is_session_revoked( &self, - ) -> cainome::cairo_serde::call::FCall { + session_hash: &starknet::core::types::Felt, + ) -> cainome::cairo_serde::call::FCall { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; + __calldata.extend(starknet::core::types::Felt::cairo_serialize(session_hash)); let __call = starknet::core::types::FunctionCall { contract_address: self.address, - entry_point_selector: starknet::macros::selector!("delegate_account"), + entry_point_selector: starknet::macros::selector!("is_session_revoked"), calldata: __calldata, }; cainome::cairo_serde::call::FCall::new(__call, self.provider()) @@ -2210,6 +2196,36 @@ impl Controller { } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] + pub fn delegate_account( + &self, + ) -> cainome::cairo_serde::call::FCall { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + let __call = starknet::core::types::FunctionCall { + contract_address: self.address, + entry_point_selector: starknet::macros::selector!("delegate_account"), + calldata: __calldata, + }; + cainome::cairo_serde::call::FCall::new(__call, self.provider()) + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn supports_interface( + &self, + interface_id: &starknet::core::types::Felt, + ) -> cainome::cairo_serde::call::FCall { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + __calldata.extend(starknet::core::types::Felt::cairo_serialize(interface_id)); + let __call = starknet::core::types::FunctionCall { + contract_address: self.address, + entry_point_selector: starknet::macros::selector!("supports_interface"), + calldata: __calldata, + }; + cainome::cairo_serde::call::FCall::new(__call, self.provider()) + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] pub fn is_valid_signature( &self, hash: &starknet::core::types::Felt, @@ -2230,19 +2246,98 @@ impl Controller { } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn supports_interface( + pub fn add_owner_getcall( &self, - interface_id: &starknet::core::types::Felt, - ) -> cainome::cairo_serde::call::FCall { + owner: &Signer, + signature: &SignerSignature, + ) -> starknet::accounts::Call { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - __calldata.extend(starknet::core::types::Felt::cairo_serialize(interface_id)); - let __call = starknet::core::types::FunctionCall { - contract_address: self.address, - entry_point_selector: starknet::macros::selector!("supports_interface"), + __calldata.extend(Signer::cairo_serialize(owner)); + __calldata.extend(SignerSignature::cairo_serialize(signature)); + starknet::accounts::Call { + to: self.address, + selector: starknet::macros::selector!("add_owner"), + calldata: __calldata, + } + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn add_owner( + &self, + owner: &Signer, + signature: &SignerSignature, + ) -> starknet::accounts::ExecutionV1 { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + __calldata.extend(Signer::cairo_serialize(owner)); + __calldata.extend(SignerSignature::cairo_serialize(signature)); + let __call = starknet::accounts::Call { + to: self.address, + selector: starknet::macros::selector!("add_owner"), + calldata: __calldata, + }; + self.account.execute_v1(vec![__call]) + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn remove_owner_getcall(&self, owner: &Signer) -> starknet::accounts::Call { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + __calldata.extend(Signer::cairo_serialize(owner)); + starknet::accounts::Call { + to: self.address, + selector: starknet::macros::selector!("remove_owner"), + calldata: __calldata, + } + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn remove_owner(&self, owner: &Signer) -> starknet::accounts::ExecutionV1 { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + __calldata.extend(Signer::cairo_serialize(owner)); + let __call = starknet::accounts::Call { + to: self.address, + selector: starknet::macros::selector!("remove_owner"), + calldata: __calldata, + }; + self.account.execute_v1(vec![__call]) + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn upgrade_getcall( + &self, + new_class_hash: &cainome::cairo_serde::ClassHash, + ) -> starknet::accounts::Call { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + __calldata.extend(cainome::cairo_serde::ClassHash::cairo_serialize( + new_class_hash, + )); + starknet::accounts::Call { + to: self.address, + selector: starknet::macros::selector!("upgrade"), + calldata: __calldata, + } + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn upgrade( + &self, + new_class_hash: &cainome::cairo_serde::ClassHash, + ) -> starknet::accounts::ExecutionV1 { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + __calldata.extend(cainome::cairo_serde::ClassHash::cairo_serialize( + new_class_hash, + )); + let __call = starknet::accounts::Call { + to: self.address, + selector: starknet::macros::selector!("upgrade"), calldata: __calldata, }; - cainome::cairo_serde::call::FCall::new(__call, self.provider()) + self.account.execute_v1(vec![__call]) } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] @@ -2386,60 +2481,78 @@ impl Controller { } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn add_owner_getcall( + pub fn execute_from_outside_getcall( &self, - owner: &Signer, - signature: &SignerSignature, + outside_execution: &OutsideExecution, + signature: &Vec, ) -> starknet::accounts::Call { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - __calldata.extend(Signer::cairo_serialize(owner)); - __calldata.extend(SignerSignature::cairo_serialize(signature)); + __calldata.extend(OutsideExecution::cairo_serialize(outside_execution)); + __calldata.extend(Vec::::cairo_serialize( + signature, + )); starknet::accounts::Call { to: self.address, - selector: starknet::macros::selector!("add_owner"), + selector: starknet::macros::selector!("execute_from_outside"), calldata: __calldata, } } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn add_owner( + pub fn execute_from_outside( &self, - owner: &Signer, - signature: &SignerSignature, + outside_execution: &OutsideExecution, + signature: &Vec, ) -> starknet::accounts::ExecutionV1 { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - __calldata.extend(Signer::cairo_serialize(owner)); - __calldata.extend(SignerSignature::cairo_serialize(signature)); + __calldata.extend(OutsideExecution::cairo_serialize(outside_execution)); + __calldata.extend(Vec::::cairo_serialize( + signature, + )); let __call = starknet::accounts::Call { to: self.address, - selector: starknet::macros::selector!("add_owner"), + selector: starknet::macros::selector!("execute_from_outside"), calldata: __calldata, }; self.account.execute_v1(vec![__call]) } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn remove_owner_getcall(&self, owner: &Signer) -> starknet::accounts::Call { + pub fn execute_from_outside_v2_getcall( + &self, + outside_execution: &OutsideExecution, + signature: &Vec, + ) -> starknet::accounts::Call { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - __calldata.extend(Signer::cairo_serialize(owner)); + __calldata.extend(OutsideExecution::cairo_serialize(outside_execution)); + __calldata.extend(Vec::::cairo_serialize( + signature, + )); starknet::accounts::Call { to: self.address, - selector: starknet::macros::selector!("remove_owner"), + selector: starknet::macros::selector!("execute_from_outside_v2"), calldata: __calldata, } } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn remove_owner(&self, owner: &Signer) -> starknet::accounts::ExecutionV1 { + pub fn execute_from_outside_v2( + &self, + outside_execution: &OutsideExecution, + signature: &Vec, + ) -> starknet::accounts::ExecutionV1 { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - __calldata.extend(Signer::cairo_serialize(owner)); + __calldata.extend(OutsideExecution::cairo_serialize(outside_execution)); + __calldata.extend(Vec::::cairo_serialize( + signature, + )); let __call = starknet::accounts::Call { to: self.address, - selector: starknet::macros::selector!("remove_owner"), + selector: starknet::macros::selector!("execute_from_outside_v2"), calldata: __calldata, }; self.account.execute_v1(vec![__call]) @@ -2559,84 +2672,6 @@ impl Controller { } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn execute_from_outside_getcall( - &self, - outside_execution: &OutsideExecution, - signature: &Vec, - ) -> starknet::accounts::Call { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - __calldata.extend(OutsideExecution::cairo_serialize(outside_execution)); - __calldata.extend(Vec::::cairo_serialize( - signature, - )); - starknet::accounts::Call { - to: self.address, - selector: starknet::macros::selector!("execute_from_outside"), - calldata: __calldata, - } - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] - pub fn execute_from_outside( - &self, - outside_execution: &OutsideExecution, - signature: &Vec, - ) -> starknet::accounts::ExecutionV1 { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - __calldata.extend(OutsideExecution::cairo_serialize(outside_execution)); - __calldata.extend(Vec::::cairo_serialize( - signature, - )); - let __call = starknet::accounts::Call { - to: self.address, - selector: starknet::macros::selector!("execute_from_outside"), - calldata: __calldata, - }; - self.account.execute_v1(vec![__call]) - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] - pub fn execute_from_outside_v2_getcall( - &self, - outside_execution: &OutsideExecution, - signature: &Vec, - ) -> starknet::accounts::Call { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - __calldata.extend(OutsideExecution::cairo_serialize(outside_execution)); - __calldata.extend(Vec::::cairo_serialize( - signature, - )); - starknet::accounts::Call { - to: self.address, - selector: starknet::macros::selector!("execute_from_outside_v2"), - calldata: __calldata, - } - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] - pub fn execute_from_outside_v2( - &self, - outside_execution: &OutsideExecution, - signature: &Vec, - ) -> starknet::accounts::ExecutionV1 { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - __calldata.extend(OutsideExecution::cairo_serialize(outside_execution)); - __calldata.extend(Vec::::cairo_serialize( - signature, - )); - let __call = starknet::accounts::Call { - to: self.address, - selector: starknet::macros::selector!("execute_from_outside_v2"), - calldata: __calldata, - }; - self.account.execute_v1(vec![__call]) - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] pub fn __validate___getcall(&self, calls: &Vec) -> starknet::accounts::Call { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; @@ -2685,43 +2720,40 @@ impl Controller { }; self.account.execute_v1(vec![__call]) } +} +impl ControllerReader

{ #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn upgrade_getcall( + pub fn is_owner( &self, - new_class_hash: &cainome::cairo_serde::ClassHash, - ) -> starknet::accounts::Call { + owner_guid: &starknet::core::types::Felt, + ) -> cainome::cairo_serde::call::FCall { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - __calldata.extend(cainome::cairo_serde::ClassHash::cairo_serialize( - new_class_hash, - )); - starknet::accounts::Call { - to: self.address, - selector: starknet::macros::selector!("upgrade"), + __calldata.extend(starknet::core::types::Felt::cairo_serialize(owner_guid)); + let __call = starknet::core::types::FunctionCall { + contract_address: self.address, + entry_point_selector: starknet::macros::selector!("is_owner"), calldata: __calldata, - } + }; + cainome::cairo_serde::call::FCall::new(__call, self.provider()) } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn upgrade( + pub fn assert_valid_owner_signature( &self, - new_class_hash: &cainome::cairo_serde::ClassHash, - ) -> starknet::accounts::ExecutionV1 { + signer_signature: &SignerSignature, + ) -> cainome::cairo_serde::call::FCall { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - __calldata.extend(cainome::cairo_serde::ClassHash::cairo_serialize( - new_class_hash, - )); - let __call = starknet::accounts::Call { - to: self.address, - selector: starknet::macros::selector!("upgrade"), + __calldata.extend(SignerSignature::cairo_serialize(signer_signature)); + let __call = starknet::core::types::FunctionCall { + contract_address: self.address, + entry_point_selector: starknet::macros::selector!("assert_valid_owner_signature"), calldata: __calldata, }; - self.account.execute_v1(vec![__call]) + cainome::cairo_serde::call::FCall::new(__call, self.provider()) } -} -impl ControllerReader

{ #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] pub fn is_external_owner( @@ -2758,52 +2790,6 @@ impl ControllerReader

{ } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn is_owner( - &self, - owner_guid: &starknet::core::types::Felt, - ) -> cainome::cairo_serde::call::FCall { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - __calldata.extend(starknet::core::types::Felt::cairo_serialize(owner_guid)); - let __call = starknet::core::types::FunctionCall { - contract_address: self.address, - entry_point_selector: starknet::macros::selector!("is_owner"), - calldata: __calldata, - }; - cainome::cairo_serde::call::FCall::new(__call, self.provider()) - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] - pub fn assert_valid_owner_signature( - &self, - signer_signature: &SignerSignature, - ) -> cainome::cairo_serde::call::FCall { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - __calldata.extend(SignerSignature::cairo_serialize(signer_signature)); - let __call = starknet::core::types::FunctionCall { - contract_address: self.address, - entry_point_selector: starknet::macros::selector!("assert_valid_owner_signature"), - calldata: __calldata, - }; - cainome::cairo_serde::call::FCall::new(__call, self.provider()) - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] - pub fn delegate_account( - &self, - ) -> cainome::cairo_serde::call::FCall { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - let __call = starknet::core::types::FunctionCall { - contract_address: self.address, - entry_point_selector: starknet::macros::selector!("delegate_account"), - calldata: __calldata, - }; - cainome::cairo_serde::call::FCall::new(__call, self.provider()) - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] pub fn is_valid_outside_execution_nonce( &self, nonce: &starknet::core::types::Felt, @@ -2856,20 +2842,14 @@ impl ControllerReader

{ } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn is_valid_signature( + pub fn delegate_account( &self, - hash: &starknet::core::types::Felt, - signature: &Vec, - ) -> cainome::cairo_serde::call::FCall { + ) -> cainome::cairo_serde::call::FCall { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - __calldata.extend(starknet::core::types::Felt::cairo_serialize(hash)); - __calldata.extend(Vec::::cairo_serialize( - signature, - )); let __call = starknet::core::types::FunctionCall { contract_address: self.address, - entry_point_selector: starknet::macros::selector!("is_valid_signature"), + entry_point_selector: starknet::macros::selector!("delegate_account"), calldata: __calldata, }; cainome::cairo_serde::call::FCall::new(__call, self.provider()) @@ -2890,4 +2870,24 @@ impl ControllerReader

{ }; cainome::cairo_serde::call::FCall::new(__call, self.provider()) } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn is_valid_signature( + &self, + hash: &starknet::core::types::Felt, + signature: &Vec, + ) -> cainome::cairo_serde::call::FCall { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + __calldata.extend(starknet::core::types::Felt::cairo_serialize(hash)); + __calldata.extend(Vec::::cairo_serialize( + signature, + )); + let __call = starknet::core::types::FunctionCall { + contract_address: self.address, + entry_point_selector: starknet::macros::selector!("is_valid_signature"), + calldata: __calldata, + }; + cainome::cairo_serde::call::FCall::new(__call, self.provider()) + } } diff --git a/packages/account_sdk/src/abigen/erc_20.rs b/packages/account_sdk/src/abigen/erc_20.rs index 42ed6a401..a3da404c2 100644 --- a/packages/account_sdk/src/abigen/erc_20.rs +++ b/packages/account_sdk/src/abigen/erc_20.rs @@ -53,31 +53,29 @@ impl Erc20Reader

{ } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct Transfer { - pub from: cainome::cairo_serde::ContractAddress, - pub to: cainome::cairo_serde::ContractAddress, - pub value: cainome::cairo_serde::U256, +pub struct OwnershipTransferred { + pub previous_owner: cainome::cairo_serde::ContractAddress, + pub new_owner: cainome::cairo_serde::ContractAddress, } -impl cainome::cairo_serde::CairoSerde for Transfer { +impl cainome::cairo_serde::CairoSerde for OwnershipTransferred { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; - __size += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.from); - __size += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.to); - __size += cainome::cairo_serde::U256::cairo_serialized_size(&__rust.value); + __size += + cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.previous_owner); + __size += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.new_owner); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; __out.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( - &__rust.from, + &__rust.previous_owner, )); __out.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( - &__rust.to, + &__rust.new_owner, )); - __out.extend(cainome::cairo_serde::U256::cairo_serialize(&__rust.value)); __out } fn cairo_deserialize( @@ -85,39 +83,42 @@ impl cainome::cairo_serde::CairoSerde for Transfer { __offset: usize, ) -> cainome::cairo_serde::Result { let mut __offset = __offset; - let from = cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; - __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&from); - let to = cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; - __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&to); - let value = cainome::cairo_serde::U256::cairo_deserialize(__felts, __offset)?; - __offset += cainome::cairo_serde::U256::cairo_serialized_size(&value); - Ok(Transfer { from, to, value }) + let previous_owner = + cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; + __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&previous_owner); + let new_owner = + cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; + __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&new_owner); + Ok(OwnershipTransferred { + previous_owner, + new_owner, + }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct Approval { - pub owner: cainome::cairo_serde::ContractAddress, - pub spender: cainome::cairo_serde::ContractAddress, +pub struct Transfer { + pub from: cainome::cairo_serde::ContractAddress, + pub to: cainome::cairo_serde::ContractAddress, pub value: cainome::cairo_serde::U256, } -impl cainome::cairo_serde::CairoSerde for Approval { +impl cainome::cairo_serde::CairoSerde for Transfer { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; - __size += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.owner); - __size += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.spender); + __size += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.from); + __size += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.to); __size += cainome::cairo_serde::U256::cairo_serialized_size(&__rust.value); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; __out.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( - &__rust.owner, + &__rust.from, )); __out.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( - &__rust.spender, + &__rust.to, )); __out.extend(cainome::cairo_serde::U256::cairo_serialize(&__rust.value)); __out @@ -127,25 +128,21 @@ impl cainome::cairo_serde::CairoSerde for Approval { __offset: usize, ) -> cainome::cairo_serde::Result { let mut __offset = __offset; - let owner = cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; - __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&owner); - let spender = cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; - __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&spender); + let from = cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; + __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&from); + let to = cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; + __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&to); let value = cainome::cairo_serde::U256::cairo_deserialize(__felts, __offset)?; __offset += cainome::cairo_serde::U256::cairo_serialized_size(&value); - Ok(Approval { - owner, - spender, - value, - }) + Ok(Transfer { from, to, value }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct OwnershipTransferred { +pub struct OwnershipTransferStarted { pub previous_owner: cainome::cairo_serde::ContractAddress, pub new_owner: cainome::cairo_serde::ContractAddress, } -impl cainome::cairo_serde::CairoSerde for OwnershipTransferred { +impl cainome::cairo_serde::CairoSerde for OwnershipTransferStarted { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] @@ -177,35 +174,29 @@ impl cainome::cairo_serde::CairoSerde for OwnershipTransferred { let new_owner = cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&new_owner); - Ok(OwnershipTransferred { + Ok(OwnershipTransferStarted { previous_owner, new_owner, }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct OwnershipTransferStarted { - pub previous_owner: cainome::cairo_serde::ContractAddress, - pub new_owner: cainome::cairo_serde::ContractAddress, +pub struct Upgraded { + pub class_hash: cainome::cairo_serde::ClassHash, } -impl cainome::cairo_serde::CairoSerde for OwnershipTransferStarted { +impl cainome::cairo_serde::CairoSerde for Upgraded { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; - __size += - cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.previous_owner); - __size += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.new_owner); + __size += cainome::cairo_serde::ClassHash::cairo_serialized_size(&__rust.class_hash); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; - __out.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( - &__rust.previous_owner, - )); - __out.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( - &__rust.new_owner, + __out.extend(cainome::cairo_serde::ClassHash::cairo_serialize( + &__rust.class_hash, )); __out } @@ -214,36 +205,37 @@ impl cainome::cairo_serde::CairoSerde for OwnershipTransferStarted { __offset: usize, ) -> cainome::cairo_serde::Result { let mut __offset = __offset; - let previous_owner = - cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; - __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&previous_owner); - let new_owner = - cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; - __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&new_owner); - Ok(OwnershipTransferStarted { - previous_owner, - new_owner, - }) + let class_hash = cainome::cairo_serde::ClassHash::cairo_deserialize(__felts, __offset)?; + __offset += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash); + Ok(Upgraded { class_hash }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub struct Upgraded { - pub class_hash: cainome::cairo_serde::ClassHash, +pub struct Approval { + pub owner: cainome::cairo_serde::ContractAddress, + pub spender: cainome::cairo_serde::ContractAddress, + pub value: cainome::cairo_serde::U256, } -impl cainome::cairo_serde::CairoSerde for Upgraded { +impl cainome::cairo_serde::CairoSerde for Approval { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; - __size += cainome::cairo_serde::ClassHash::cairo_serialized_size(&__rust.class_hash); + __size += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.owner); + __size += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&__rust.spender); + __size += cainome::cairo_serde::U256::cairo_serialized_size(&__rust.value); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; - __out.extend(cainome::cairo_serde::ClassHash::cairo_serialize( - &__rust.class_hash, + __out.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( + &__rust.owner, )); + __out.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( + &__rust.spender, + )); + __out.extend(cainome::cairo_serde::U256::cairo_serialize(&__rust.value)); __out } fn cairo_deserialize( @@ -251,43 +243,39 @@ impl cainome::cairo_serde::CairoSerde for Upgraded { __offset: usize, ) -> cainome::cairo_serde::Result { let mut __offset = __offset; - let class_hash = cainome::cairo_serde::ClassHash::cairo_deserialize(__felts, __offset)?; - __offset += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash); - Ok(Upgraded { class_hash }) + let owner = cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; + __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&owner); + let spender = cainome::cairo_serde::ContractAddress::cairo_deserialize(__felts, __offset)?; + __offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&spender); + let value = cainome::cairo_serde::U256::cairo_deserialize(__felts, __offset)?; + __offset += cainome::cairo_serde::U256::cairo_serialized_size(&value); + Ok(Approval { + owner, + spender, + value, + }) } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub enum OwnableComponentEvent { - OwnershipTransferred(OwnershipTransferred), - OwnershipTransferStarted(OwnershipTransferStarted), +pub enum UpgradeEvent { + Upgraded(Upgraded), } -impl cainome::cairo_serde::CairoSerde for OwnableComponentEvent { +impl cainome::cairo_serde::CairoSerde for UpgradeEvent { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { match __rust { - OwnableComponentEvent::OwnershipTransferred(val) => { - OwnershipTransferred::cairo_serialized_size(val) + 1 - } - OwnableComponentEvent::OwnershipTransferStarted(val) => { - OwnershipTransferStarted::cairo_serialized_size(val) + 1 - } + UpgradeEvent::Upgraded(val) => Upgraded::cairo_serialized_size(val) + 1, _ => 0, } } fn cairo_serialize(__rust: &Self::RustType) -> Vec { match __rust { - OwnableComponentEvent::OwnershipTransferred(val) => { + UpgradeEvent::Upgraded(val) => { let mut temp = vec![]; temp.extend(usize::cairo_serialize(&0usize)); - temp.extend(OwnershipTransferred::cairo_serialize(val)); - temp - } - OwnableComponentEvent::OwnershipTransferStarted(val) => { - let mut temp = vec![]; - temp.extend(usize::cairo_serialize(&1usize)); - temp.extend(OwnershipTransferStarted::cairo_serialize(val)); + temp.extend(Upgraded::cairo_serialize(val)); temp } _ => vec![], @@ -300,22 +288,20 @@ impl cainome::cairo_serde::CairoSerde for OwnableComponentEvent { let __f = __felts[__offset]; let __index = u128::from_be_bytes(__f.to_bytes_be()[16..].try_into().unwrap()); match __index as usize { - 0usize => Ok(OwnableComponentEvent::OwnershipTransferred( - OwnershipTransferred::cairo_deserialize(__felts, __offset + 1)?, - )), - 1usize => Ok(OwnableComponentEvent::OwnershipTransferStarted( - OwnershipTransferStarted::cairo_deserialize(__felts, __offset + 1)?, - )), + 0usize => Ok(UpgradeEvent::Upgraded(Upgraded::cairo_deserialize( + __felts, + __offset + 1, + )?)), _ => { return Err(cainome::cairo_serde::Error::Deserialize(format!( "Index not handle for enum {}", - "OwnableComponentEvent" + "UpgradeEvent" ))) } } } } -impl TryFrom for OwnableComponentEvent { +impl TryFrom for UpgradeEvent { type Error = String; fn try_from(event: starknet::core::types::EmittedEvent) -> Result { use cainome::cairo_serde::CairoSerde; @@ -324,85 +310,25 @@ impl TryFrom for OwnableComponentEvent { } let selector = event.keys[0]; if selector - == starknet::core::utils::get_selector_from_name("OwnershipTransferred") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "OwnershipTransferred")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let previous_owner = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.keys, - key_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "previous_owner", "OwnershipTransferred", e - )) - } - }; - key_offset += - cainome::cairo_serde::ContractAddress::cairo_serialized_size(&previous_owner); - let new_owner = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.keys, - key_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "new_owner", "OwnershipTransferred", e - )) - } - }; - key_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&new_owner); - return Ok(OwnableComponentEvent::OwnershipTransferred( - OwnershipTransferred { - previous_owner, - new_owner, - }, - )); - }; - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("OwnershipTransferStarted") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "OwnershipTransferStarted")) + == starknet::core::utils::get_selector_from_name("Upgraded") + .unwrap_or_else(|_| panic!("Invalid selector for {}", "Upgraded")) { let mut key_offset = 0 + 1; let mut data_offset = 0; - let previous_owner = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.keys, - key_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "previous_owner", "OwnershipTransferStarted", e - )) - } - }; - key_offset += - cainome::cairo_serde::ContractAddress::cairo_serialized_size(&previous_owner); - let new_owner = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.keys, - key_offset, + let class_hash = match cainome::cairo_serde::ClassHash::cairo_deserialize( + &event.data, + data_offset, ) { Ok(v) => v, Err(e) => { return Err(format!( "Could not deserialize field {} for {}: {:?}", - "new_owner", "OwnershipTransferStarted", e + "class_hash", "Upgraded", e )) } }; - key_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&new_owner); - return Ok(OwnableComponentEvent::OwnershipTransferStarted( - OwnershipTransferStarted { - previous_owner, - new_owner, - }, - )); + data_offset += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash); + return Ok(UpgradeEvent::Upgraded(Upgraded { class_hash })); }; Err(format!( "Could not match any event from keys {:?}", @@ -411,41 +337,33 @@ impl TryFrom for OwnableComponentEvent { } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub enum Event { - OwnableEvent(OwnableComponentEvent), - ERC20Event(ERC20ComponentEvent), - UpgradeableEvent(UpgradeEvent), +pub enum ERC20ComponentEvent { + Transfer(Transfer), + Approval(Approval), } -impl cainome::cairo_serde::CairoSerde for Event { +impl cainome::cairo_serde::CairoSerde for ERC20ComponentEvent { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { match __rust { - Event::OwnableEvent(val) => OwnableComponentEvent::cairo_serialized_size(val) + 1, - Event::ERC20Event(val) => ERC20ComponentEvent::cairo_serialized_size(val) + 1, - Event::UpgradeableEvent(val) => UpgradeEvent::cairo_serialized_size(val) + 1, + ERC20ComponentEvent::Transfer(val) => Transfer::cairo_serialized_size(val) + 1, + ERC20ComponentEvent::Approval(val) => Approval::cairo_serialized_size(val) + 1, _ => 0, } } fn cairo_serialize(__rust: &Self::RustType) -> Vec { match __rust { - Event::OwnableEvent(val) => { + ERC20ComponentEvent::Transfer(val) => { let mut temp = vec![]; temp.extend(usize::cairo_serialize(&0usize)); - temp.extend(OwnableComponentEvent::cairo_serialize(val)); + temp.extend(Transfer::cairo_serialize(val)); temp } - Event::ERC20Event(val) => { + ERC20ComponentEvent::Approval(val) => { let mut temp = vec![]; temp.extend(usize::cairo_serialize(&1usize)); - temp.extend(ERC20ComponentEvent::cairo_serialize(val)); - temp - } - Event::UpgradeableEvent(val) => { - let mut temp = vec![]; - temp.extend(usize::cairo_serialize(&2usize)); - temp.extend(UpgradeEvent::cairo_serialize(val)); + temp.extend(Approval::cairo_serialize(val)); temp } _ => vec![], @@ -458,27 +376,24 @@ impl cainome::cairo_serde::CairoSerde for Event { let __f = __felts[__offset]; let __index = u128::from_be_bytes(__f.to_bytes_be()[16..].try_into().unwrap()); match __index as usize { - 0usize => Ok(Event::OwnableEvent( - OwnableComponentEvent::cairo_deserialize(__felts, __offset + 1)?, - )), - 1usize => Ok(Event::ERC20Event(ERC20ComponentEvent::cairo_deserialize( + 0usize => Ok(ERC20ComponentEvent::Transfer(Transfer::cairo_deserialize( __felts, __offset + 1, )?)), - 2usize => Ok(Event::UpgradeableEvent(UpgradeEvent::cairo_deserialize( + 1usize => Ok(ERC20ComponentEvent::Approval(Approval::cairo_deserialize( __felts, __offset + 1, )?)), _ => { return Err(cainome::cairo_serde::Error::Deserialize(format!( "Index not handle for enum {}", - "Event" + "ERC20ComponentEvent" ))) } } } } -impl TryFrom for Event { +impl TryFrom for ERC20ComponentEvent { type Error = String; fn try_from(event: starknet::core::types::EmittedEvent) -> Result { use cainome::cairo_serde::CairoSerde; @@ -486,88 +401,6 @@ impl TryFrom for Event { return Err("Event has no key".to_string()); } let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("OwnershipTransferred") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "OwnershipTransferred")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let previous_owner = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.keys, - key_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "previous_owner", "OwnershipTransferred", e - )) - } - }; - key_offset += - cainome::cairo_serde::ContractAddress::cairo_serialized_size(&previous_owner); - let new_owner = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.keys, - key_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "new_owner", "OwnershipTransferred", e - )) - } - }; - key_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&new_owner); - return Ok(Event::OwnableEvent( - OwnableComponentEvent::OwnershipTransferred(OwnershipTransferred { - previous_owner, - new_owner, - }), - )); - }; - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("OwnershipTransferStarted") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "OwnershipTransferStarted")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let previous_owner = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.keys, - key_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "previous_owner", "OwnershipTransferStarted", e - )) - } - }; - key_offset += - cainome::cairo_serde::ContractAddress::cairo_serialized_size(&previous_owner); - let new_owner = match cainome::cairo_serde::ContractAddress::cairo_deserialize( - &event.keys, - key_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "new_owner", "OwnershipTransferStarted", e - )) - } - }; - key_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&new_owner); - return Ok(Event::OwnableEvent( - OwnableComponentEvent::OwnershipTransferStarted(OwnershipTransferStarted { - previous_owner, - new_owner, - }), - )); - }; - let selector = event.keys[0]; if selector == starknet::core::utils::get_selector_from_name("Transfer") .unwrap_or_else(|_| panic!("Invalid selector for {}", "Transfer")) @@ -611,11 +444,7 @@ impl TryFrom for Event { } }; data_offset += cainome::cairo_serde::U256::cairo_serialized_size(&value); - return Ok(Event::ERC20Event(ERC20ComponentEvent::Transfer(Transfer { - from, - to, - value, - }))); + return Ok(ERC20ComponentEvent::Transfer(Transfer { from, to, value })); }; let selector = event.keys[0]; if selector @@ -661,35 +490,11 @@ impl TryFrom for Event { } }; data_offset += cainome::cairo_serde::U256::cairo_serialized_size(&value); - return Ok(Event::ERC20Event(ERC20ComponentEvent::Approval(Approval { + return Ok(ERC20ComponentEvent::Approval(Approval { owner, spender, value, - }))); - }; - let selector = event.keys[0]; - if selector - == starknet::core::utils::get_selector_from_name("Upgraded") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "Upgraded")) - { - let mut key_offset = 0 + 1; - let mut data_offset = 0; - let class_hash = match cainome::cairo_serde::ClassHash::cairo_deserialize( - &event.data, - data_offset, - ) { - Ok(v) => v, - Err(e) => { - return Err(format!( - "Could not deserialize field {} for {}: {:?}", - "class_hash", "Upgraded", e - )) - } - }; - data_offset += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash); - return Ok(Event::UpgradeableEvent(UpgradeEvent::Upgraded(Upgraded { - class_hash, - }))); + })); }; Err(format!( "Could not match any event from keys {:?}", @@ -698,25 +503,37 @@ impl TryFrom for Event { } } #[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub enum UpgradeEvent { - Upgraded(Upgraded), +pub enum OwnableComponentEvent { + OwnershipTransferred(OwnershipTransferred), + OwnershipTransferStarted(OwnershipTransferStarted), } -impl cainome::cairo_serde::CairoSerde for UpgradeEvent { +impl cainome::cairo_serde::CairoSerde for OwnableComponentEvent { type RustType = Self; const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; #[inline] fn cairo_serialized_size(__rust: &Self::RustType) -> usize { match __rust { - UpgradeEvent::Upgraded(val) => Upgraded::cairo_serialized_size(val) + 1, + OwnableComponentEvent::OwnershipTransferred(val) => { + OwnershipTransferred::cairo_serialized_size(val) + 1 + } + OwnableComponentEvent::OwnershipTransferStarted(val) => { + OwnershipTransferStarted::cairo_serialized_size(val) + 1 + } _ => 0, } } fn cairo_serialize(__rust: &Self::RustType) -> Vec { match __rust { - UpgradeEvent::Upgraded(val) => { + OwnableComponentEvent::OwnershipTransferred(val) => { let mut temp = vec![]; temp.extend(usize::cairo_serialize(&0usize)); - temp.extend(Upgraded::cairo_serialize(val)); + temp.extend(OwnershipTransferred::cairo_serialize(val)); + temp + } + OwnableComponentEvent::OwnershipTransferStarted(val) => { + let mut temp = vec![]; + temp.extend(usize::cairo_serialize(&1usize)); + temp.extend(OwnershipTransferStarted::cairo_serialize(val)); temp } _ => vec![], @@ -729,20 +546,22 @@ impl cainome::cairo_serde::CairoSerde for UpgradeEvent { let __f = __felts[__offset]; let __index = u128::from_be_bytes(__f.to_bytes_be()[16..].try_into().unwrap()); match __index as usize { - 0usize => Ok(UpgradeEvent::Upgraded(Upgraded::cairo_deserialize( - __felts, - __offset + 1, - )?)), + 0usize => Ok(OwnableComponentEvent::OwnershipTransferred( + OwnershipTransferred::cairo_deserialize(__felts, __offset + 1)?, + )), + 1usize => Ok(OwnableComponentEvent::OwnershipTransferStarted( + OwnershipTransferStarted::cairo_deserialize(__felts, __offset + 1)?, + )), _ => { return Err(cainome::cairo_serde::Error::Deserialize(format!( "Index not handle for enum {}", - "UpgradeEvent" + "OwnableComponentEvent" ))) } } } } -impl TryFrom for UpgradeEvent { +impl TryFrom for OwnableComponentEvent { type Error = String; fn try_from(event: starknet::core::types::EmittedEvent) -> Result { use cainome::cairo_serde::CairoSerde; @@ -751,60 +570,128 @@ impl TryFrom for UpgradeEvent { } let selector = event.keys[0]; if selector - == starknet::core::utils::get_selector_from_name("Upgraded") - .unwrap_or_else(|_| panic!("Invalid selector for {}", "Upgraded")) + == starknet::core::utils::get_selector_from_name("OwnershipTransferred") + .unwrap_or_else(|_| panic!("Invalid selector for {}", "OwnershipTransferred")) { let mut key_offset = 0 + 1; let mut data_offset = 0; - let class_hash = match cainome::cairo_serde::ClassHash::cairo_deserialize( - &event.data, - data_offset, + let previous_owner = match cainome::cairo_serde::ContractAddress::cairo_deserialize( + &event.keys, + key_offset, ) { Ok(v) => v, Err(e) => { return Err(format!( "Could not deserialize field {} for {}: {:?}", - "class_hash", "Upgraded", e + "previous_owner", "OwnershipTransferred", e )) } }; - data_offset += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash); - return Ok(UpgradeEvent::Upgraded(Upgraded { class_hash })); + key_offset += + cainome::cairo_serde::ContractAddress::cairo_serialized_size(&previous_owner); + let new_owner = match cainome::cairo_serde::ContractAddress::cairo_deserialize( + &event.keys, + key_offset, + ) { + Ok(v) => v, + Err(e) => { + return Err(format!( + "Could not deserialize field {} for {}: {:?}", + "new_owner", "OwnershipTransferred", e + )) + } + }; + key_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&new_owner); + return Ok(OwnableComponentEvent::OwnershipTransferred( + OwnershipTransferred { + previous_owner, + new_owner, + }, + )); }; - Err(format!( - "Could not match any event from keys {:?}", - event.keys - )) - } -} -#[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] -pub enum ERC20ComponentEvent { - Transfer(Transfer), - Approval(Approval), -} -impl cainome::cairo_serde::CairoSerde for ERC20ComponentEvent { - type RustType = Self; - const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; - #[inline] - fn cairo_serialized_size(__rust: &Self::RustType) -> usize { - match __rust { - ERC20ComponentEvent::Transfer(val) => Transfer::cairo_serialized_size(val) + 1, - ERC20ComponentEvent::Approval(val) => Approval::cairo_serialized_size(val) + 1, - _ => 0, - } - } - fn cairo_serialize(__rust: &Self::RustType) -> Vec { - match __rust { - ERC20ComponentEvent::Transfer(val) => { - let mut temp = vec![]; - temp.extend(usize::cairo_serialize(&0usize)); - temp.extend(Transfer::cairo_serialize(val)); - temp - } - ERC20ComponentEvent::Approval(val) => { - let mut temp = vec![]; + let selector = event.keys[0]; + if selector + == starknet::core::utils::get_selector_from_name("OwnershipTransferStarted") + .unwrap_or_else(|_| panic!("Invalid selector for {}", "OwnershipTransferStarted")) + { + let mut key_offset = 0 + 1; + let mut data_offset = 0; + let previous_owner = match cainome::cairo_serde::ContractAddress::cairo_deserialize( + &event.keys, + key_offset, + ) { + Ok(v) => v, + Err(e) => { + return Err(format!( + "Could not deserialize field {} for {}: {:?}", + "previous_owner", "OwnershipTransferStarted", e + )) + } + }; + key_offset += + cainome::cairo_serde::ContractAddress::cairo_serialized_size(&previous_owner); + let new_owner = match cainome::cairo_serde::ContractAddress::cairo_deserialize( + &event.keys, + key_offset, + ) { + Ok(v) => v, + Err(e) => { + return Err(format!( + "Could not deserialize field {} for {}: {:?}", + "new_owner", "OwnershipTransferStarted", e + )) + } + }; + key_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&new_owner); + return Ok(OwnableComponentEvent::OwnershipTransferStarted( + OwnershipTransferStarted { + previous_owner, + new_owner, + }, + )); + }; + Err(format!( + "Could not match any event from keys {:?}", + event.keys + )) + } +} +#[derive(Debug, PartialEq, PartialOrd, Clone, serde :: Serialize, serde :: Deserialize)] +pub enum Event { + OwnableEvent(OwnableComponentEvent), + ERC20Event(ERC20ComponentEvent), + UpgradeableEvent(UpgradeEvent), +} +impl cainome::cairo_serde::CairoSerde for Event { + type RustType = Self; + const SERIALIZED_SIZE: std::option::Option = std::option::Option::None; + #[inline] + fn cairo_serialized_size(__rust: &Self::RustType) -> usize { + match __rust { + Event::OwnableEvent(val) => OwnableComponentEvent::cairo_serialized_size(val) + 1, + Event::ERC20Event(val) => ERC20ComponentEvent::cairo_serialized_size(val) + 1, + Event::UpgradeableEvent(val) => UpgradeEvent::cairo_serialized_size(val) + 1, + _ => 0, + } + } + fn cairo_serialize(__rust: &Self::RustType) -> Vec { + match __rust { + Event::OwnableEvent(val) => { + let mut temp = vec![]; + temp.extend(usize::cairo_serialize(&0usize)); + temp.extend(OwnableComponentEvent::cairo_serialize(val)); + temp + } + Event::ERC20Event(val) => { + let mut temp = vec![]; temp.extend(usize::cairo_serialize(&1usize)); - temp.extend(Approval::cairo_serialize(val)); + temp.extend(ERC20ComponentEvent::cairo_serialize(val)); + temp + } + Event::UpgradeableEvent(val) => { + let mut temp = vec![]; + temp.extend(usize::cairo_serialize(&2usize)); + temp.extend(UpgradeEvent::cairo_serialize(val)); temp } _ => vec![], @@ -817,24 +704,27 @@ impl cainome::cairo_serde::CairoSerde for ERC20ComponentEvent { let __f = __felts[__offset]; let __index = u128::from_be_bytes(__f.to_bytes_be()[16..].try_into().unwrap()); match __index as usize { - 0usize => Ok(ERC20ComponentEvent::Transfer(Transfer::cairo_deserialize( + 0usize => Ok(Event::OwnableEvent( + OwnableComponentEvent::cairo_deserialize(__felts, __offset + 1)?, + )), + 1usize => Ok(Event::ERC20Event(ERC20ComponentEvent::cairo_deserialize( __felts, __offset + 1, )?)), - 1usize => Ok(ERC20ComponentEvent::Approval(Approval::cairo_deserialize( + 2usize => Ok(Event::UpgradeableEvent(UpgradeEvent::cairo_deserialize( __felts, __offset + 1, )?)), _ => { return Err(cainome::cairo_serde::Error::Deserialize(format!( "Index not handle for enum {}", - "ERC20ComponentEvent" + "Event" ))) } } } } -impl TryFrom for ERC20ComponentEvent { +impl TryFrom for Event { type Error = String; fn try_from(event: starknet::core::types::EmittedEvent) -> Result { use cainome::cairo_serde::CairoSerde; @@ -842,6 +732,88 @@ impl TryFrom for ERC20ComponentEvent { return Err("Event has no key".to_string()); } let selector = event.keys[0]; + if selector + == starknet::core::utils::get_selector_from_name("OwnershipTransferred") + .unwrap_or_else(|_| panic!("Invalid selector for {}", "OwnershipTransferred")) + { + let mut key_offset = 0 + 1; + let mut data_offset = 0; + let previous_owner = match cainome::cairo_serde::ContractAddress::cairo_deserialize( + &event.keys, + key_offset, + ) { + Ok(v) => v, + Err(e) => { + return Err(format!( + "Could not deserialize field {} for {}: {:?}", + "previous_owner", "OwnershipTransferred", e + )) + } + }; + key_offset += + cainome::cairo_serde::ContractAddress::cairo_serialized_size(&previous_owner); + let new_owner = match cainome::cairo_serde::ContractAddress::cairo_deserialize( + &event.keys, + key_offset, + ) { + Ok(v) => v, + Err(e) => { + return Err(format!( + "Could not deserialize field {} for {}: {:?}", + "new_owner", "OwnershipTransferred", e + )) + } + }; + key_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&new_owner); + return Ok(Event::OwnableEvent( + OwnableComponentEvent::OwnershipTransferred(OwnershipTransferred { + previous_owner, + new_owner, + }), + )); + }; + let selector = event.keys[0]; + if selector + == starknet::core::utils::get_selector_from_name("OwnershipTransferStarted") + .unwrap_or_else(|_| panic!("Invalid selector for {}", "OwnershipTransferStarted")) + { + let mut key_offset = 0 + 1; + let mut data_offset = 0; + let previous_owner = match cainome::cairo_serde::ContractAddress::cairo_deserialize( + &event.keys, + key_offset, + ) { + Ok(v) => v, + Err(e) => { + return Err(format!( + "Could not deserialize field {} for {}: {:?}", + "previous_owner", "OwnershipTransferStarted", e + )) + } + }; + key_offset += + cainome::cairo_serde::ContractAddress::cairo_serialized_size(&previous_owner); + let new_owner = match cainome::cairo_serde::ContractAddress::cairo_deserialize( + &event.keys, + key_offset, + ) { + Ok(v) => v, + Err(e) => { + return Err(format!( + "Could not deserialize field {} for {}: {:?}", + "new_owner", "OwnershipTransferStarted", e + )) + } + }; + key_offset += cainome::cairo_serde::ContractAddress::cairo_serialized_size(&new_owner); + return Ok(Event::OwnableEvent( + OwnableComponentEvent::OwnershipTransferStarted(OwnershipTransferStarted { + previous_owner, + new_owner, + }), + )); + }; + let selector = event.keys[0]; if selector == starknet::core::utils::get_selector_from_name("Transfer") .unwrap_or_else(|_| panic!("Invalid selector for {}", "Transfer")) @@ -885,7 +857,11 @@ impl TryFrom for ERC20ComponentEvent { } }; data_offset += cainome::cairo_serde::U256::cairo_serialized_size(&value); - return Ok(ERC20ComponentEvent::Transfer(Transfer { from, to, value })); + return Ok(Event::ERC20Event(ERC20ComponentEvent::Transfer(Transfer { + from, + to, + value, + }))); }; let selector = event.keys[0]; if selector @@ -931,11 +907,35 @@ impl TryFrom for ERC20ComponentEvent { } }; data_offset += cainome::cairo_serde::U256::cairo_serialized_size(&value); - return Ok(ERC20ComponentEvent::Approval(Approval { + return Ok(Event::ERC20Event(ERC20ComponentEvent::Approval(Approval { owner, spender, value, - })); + }))); + }; + let selector = event.keys[0]; + if selector + == starknet::core::utils::get_selector_from_name("Upgraded") + .unwrap_or_else(|_| panic!("Invalid selector for {}", "Upgraded")) + { + let mut key_offset = 0 + 1; + let mut data_offset = 0; + let class_hash = match cainome::cairo_serde::ClassHash::cairo_deserialize( + &event.data, + data_offset, + ) { + Ok(v) => v, + Err(e) => { + return Err(format!( + "Could not deserialize field {} for {}: {:?}", + "class_hash", "Upgraded", e + )) + } + }; + data_offset += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash); + return Ok(Event::UpgradeableEvent(UpgradeEvent::Upgraded(Upgraded { + class_hash, + }))); }; Err(format!( "Could not match any event from keys {:?}", @@ -944,20 +944,6 @@ impl TryFrom for ERC20ComponentEvent { } } impl Erc20 { - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] - pub fn owner( - &self, - ) -> cainome::cairo_serde::call::FCall { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - let __call = starknet::core::types::FunctionCall { - contract_address: self.address, - entry_point_selector: starknet::macros::selector!("owner"), - calldata: __calldata, - }; - cainome::cairo_serde::call::FCall::new(__call, self.provider()) - } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] pub fn total_supply( @@ -1010,230 +996,93 @@ impl Erc20 { entry_point_selector: starknet::macros::selector!("allowance"), calldata: __calldata, }; - cainome::cairo_serde::call::FCall::new(__call, self.provider()) - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] - pub fn name( - &self, - ) -> cainome::cairo_serde::call::FCall { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - let __call = starknet::core::types::FunctionCall { - contract_address: self.address, - entry_point_selector: starknet::macros::selector!("name"), - calldata: __calldata, - }; - cainome::cairo_serde::call::FCall::new(__call, self.provider()) - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] - pub fn symbol( - &self, - ) -> cainome::cairo_serde::call::FCall { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - let __call = starknet::core::types::FunctionCall { - contract_address: self.address, - entry_point_selector: starknet::macros::selector!("symbol"), - calldata: __calldata, - }; - cainome::cairo_serde::call::FCall::new(__call, self.provider()) - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] - pub fn decimals(&self) -> cainome::cairo_serde::call::FCall { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - let __call = starknet::core::types::FunctionCall { - contract_address: self.address, - entry_point_selector: starknet::macros::selector!("decimals"), - calldata: __calldata, - }; - cainome::cairo_serde::call::FCall::new(__call, self.provider()) - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] - pub fn totalSupply( - &self, - ) -> cainome::cairo_serde::call::FCall { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - let __call = starknet::core::types::FunctionCall { - contract_address: self.address, - entry_point_selector: starknet::macros::selector!("totalSupply"), - calldata: __calldata, - }; - cainome::cairo_serde::call::FCall::new(__call, self.provider()) - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] - pub fn balanceOf( - &self, - account: &cainome::cairo_serde::ContractAddress, - ) -> cainome::cairo_serde::call::FCall { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - __calldata.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( - account, - )); - let __call = starknet::core::types::FunctionCall { - contract_address: self.address, - entry_point_selector: starknet::macros::selector!("balanceOf"), - calldata: __calldata, - }; - cainome::cairo_serde::call::FCall::new(__call, self.provider()) - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] - pub fn upgrade_getcall( - &self, - new_class_hash: &cainome::cairo_serde::ClassHash, - ) -> starknet::accounts::Call { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - __calldata.extend(cainome::cairo_serde::ClassHash::cairo_serialize( - new_class_hash, - )); - starknet::accounts::Call { - to: self.address, - selector: starknet::macros::selector!("upgrade"), - calldata: __calldata, - } - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] - pub fn upgrade( - &self, - new_class_hash: &cainome::cairo_serde::ClassHash, - ) -> starknet::accounts::ExecutionV1 { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - __calldata.extend(cainome::cairo_serde::ClassHash::cairo_serialize( - new_class_hash, - )); - let __call = starknet::accounts::Call { - to: self.address, - selector: starknet::macros::selector!("upgrade"), - calldata: __calldata, - }; - self.account.execute_v1(vec![__call]) - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] - pub fn transfer_ownership_getcall( - &self, - new_owner: &cainome::cairo_serde::ContractAddress, - ) -> starknet::accounts::Call { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - __calldata.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( - new_owner, - )); - starknet::accounts::Call { - to: self.address, - selector: starknet::macros::selector!("transfer_ownership"), - calldata: __calldata, - } - } - #[allow(clippy::ptr_arg)] - #[allow(clippy::too_many_arguments)] - pub fn transfer_ownership( - &self, - new_owner: &cainome::cairo_serde::ContractAddress, - ) -> starknet::accounts::ExecutionV1 { - use cainome::cairo_serde::CairoSerde; - let mut __calldata = vec![]; - __calldata.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( - new_owner, - )); - let __call = starknet::accounts::Call { - to: self.address, - selector: starknet::macros::selector!("transfer_ownership"), - calldata: __calldata, - }; - self.account.execute_v1(vec![__call]) + cainome::cairo_serde::call::FCall::new(__call, self.provider()) } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn renounce_ownership_getcall(&self) -> starknet::accounts::Call { + pub fn name( + &self, + ) -> cainome::cairo_serde::call::FCall { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - starknet::accounts::Call { - to: self.address, - selector: starknet::macros::selector!("renounce_ownership"), + let __call = starknet::core::types::FunctionCall { + contract_address: self.address, + entry_point_selector: starknet::macros::selector!("name"), calldata: __calldata, - } + }; + cainome::cairo_serde::call::FCall::new(__call, self.provider()) } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn renounce_ownership(&self) -> starknet::accounts::ExecutionV1 { + pub fn symbol( + &self, + ) -> cainome::cairo_serde::call::FCall { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - let __call = starknet::accounts::Call { - to: self.address, - selector: starknet::macros::selector!("renounce_ownership"), + let __call = starknet::core::types::FunctionCall { + contract_address: self.address, + entry_point_selector: starknet::macros::selector!("symbol"), calldata: __calldata, }; - self.account.execute_v1(vec![__call]) + cainome::cairo_serde::call::FCall::new(__call, self.provider()) } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn transferOwnership_getcall( - &self, - newOwner: &cainome::cairo_serde::ContractAddress, - ) -> starknet::accounts::Call { + pub fn decimals(&self) -> cainome::cairo_serde::call::FCall { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - __calldata.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( - newOwner, - )); - starknet::accounts::Call { - to: self.address, - selector: starknet::macros::selector!("transferOwnership"), + let __call = starknet::core::types::FunctionCall { + contract_address: self.address, + entry_point_selector: starknet::macros::selector!("decimals"), calldata: __calldata, - } + }; + cainome::cairo_serde::call::FCall::new(__call, self.provider()) } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn transferOwnership( + pub fn totalSupply( &self, - newOwner: &cainome::cairo_serde::ContractAddress, - ) -> starknet::accounts::ExecutionV1 { + ) -> cainome::cairo_serde::call::FCall { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - __calldata.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( - newOwner, - )); - let __call = starknet::accounts::Call { - to: self.address, - selector: starknet::macros::selector!("transferOwnership"), + let __call = starknet::core::types::FunctionCall { + contract_address: self.address, + entry_point_selector: starknet::macros::selector!("totalSupply"), calldata: __calldata, }; - self.account.execute_v1(vec![__call]) + cainome::cairo_serde::call::FCall::new(__call, self.provider()) } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn renounceOwnership_getcall(&self) -> starknet::accounts::Call { + pub fn balanceOf( + &self, + account: &cainome::cairo_serde::ContractAddress, + ) -> cainome::cairo_serde::call::FCall { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - starknet::accounts::Call { - to: self.address, - selector: starknet::macros::selector!("renounceOwnership"), + __calldata.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( + account, + )); + let __call = starknet::core::types::FunctionCall { + contract_address: self.address, + entry_point_selector: starknet::macros::selector!("balanceOf"), calldata: __calldata, - } + }; + cainome::cairo_serde::call::FCall::new(__call, self.provider()) } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn renounceOwnership(&self) -> starknet::accounts::ExecutionV1 { + pub fn owner( + &self, + ) -> cainome::cairo_serde::call::FCall { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - let __call = starknet::accounts::Call { - to: self.address, - selector: starknet::macros::selector!("renounceOwnership"), + let __call = starknet::core::types::FunctionCall { + contract_address: self.address, + entry_point_selector: starknet::macros::selector!("owner"), calldata: __calldata, }; - self.account.execute_v1(vec![__call]) + cainome::cairo_serde::call::FCall::new(__call, self.provider()) } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] @@ -1407,22 +1256,159 @@ impl Erc20 { }; self.account.execute_v1(vec![__call]) } -} -impl Erc20Reader

{ #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] - pub fn owner( + pub fn upgrade_getcall( &self, - ) -> cainome::cairo_serde::call::FCall { + new_class_hash: &cainome::cairo_serde::ClassHash, + ) -> starknet::accounts::Call { use cainome::cairo_serde::CairoSerde; let mut __calldata = vec![]; - let __call = starknet::core::types::FunctionCall { - contract_address: self.address, - entry_point_selector: starknet::macros::selector!("owner"), + __calldata.extend(cainome::cairo_serde::ClassHash::cairo_serialize( + new_class_hash, + )); + starknet::accounts::Call { + to: self.address, + selector: starknet::macros::selector!("upgrade"), + calldata: __calldata, + } + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn upgrade( + &self, + new_class_hash: &cainome::cairo_serde::ClassHash, + ) -> starknet::accounts::ExecutionV1 { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + __calldata.extend(cainome::cairo_serde::ClassHash::cairo_serialize( + new_class_hash, + )); + let __call = starknet::accounts::Call { + to: self.address, + selector: starknet::macros::selector!("upgrade"), calldata: __calldata, }; - cainome::cairo_serde::call::FCall::new(__call, self.provider()) + self.account.execute_v1(vec![__call]) + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn transfer_ownership_getcall( + &self, + new_owner: &cainome::cairo_serde::ContractAddress, + ) -> starknet::accounts::Call { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + __calldata.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( + new_owner, + )); + starknet::accounts::Call { + to: self.address, + selector: starknet::macros::selector!("transfer_ownership"), + calldata: __calldata, + } + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn transfer_ownership( + &self, + new_owner: &cainome::cairo_serde::ContractAddress, + ) -> starknet::accounts::ExecutionV1 { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + __calldata.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( + new_owner, + )); + let __call = starknet::accounts::Call { + to: self.address, + selector: starknet::macros::selector!("transfer_ownership"), + calldata: __calldata, + }; + self.account.execute_v1(vec![__call]) + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn renounce_ownership_getcall(&self) -> starknet::accounts::Call { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + starknet::accounts::Call { + to: self.address, + selector: starknet::macros::selector!("renounce_ownership"), + calldata: __calldata, + } + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn renounce_ownership(&self) -> starknet::accounts::ExecutionV1 { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + let __call = starknet::accounts::Call { + to: self.address, + selector: starknet::macros::selector!("renounce_ownership"), + calldata: __calldata, + }; + self.account.execute_v1(vec![__call]) + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn transferOwnership_getcall( + &self, + newOwner: &cainome::cairo_serde::ContractAddress, + ) -> starknet::accounts::Call { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + __calldata.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( + newOwner, + )); + starknet::accounts::Call { + to: self.address, + selector: starknet::macros::selector!("transferOwnership"), + calldata: __calldata, + } + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn transferOwnership( + &self, + newOwner: &cainome::cairo_serde::ContractAddress, + ) -> starknet::accounts::ExecutionV1 { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + __calldata.extend(cainome::cairo_serde::ContractAddress::cairo_serialize( + newOwner, + )); + let __call = starknet::accounts::Call { + to: self.address, + selector: starknet::macros::selector!("transferOwnership"), + calldata: __calldata, + }; + self.account.execute_v1(vec![__call]) + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn renounceOwnership_getcall(&self) -> starknet::accounts::Call { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + starknet::accounts::Call { + to: self.address, + selector: starknet::macros::selector!("renounceOwnership"), + calldata: __calldata, + } + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn renounceOwnership(&self) -> starknet::accounts::ExecutionV1 { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + let __call = starknet::accounts::Call { + to: self.address, + selector: starknet::macros::selector!("renounceOwnership"), + calldata: __calldata, + }; + self.account.execute_v1(vec![__call]) } +} +impl Erc20Reader

{ #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] pub fn total_supply(&self) -> cainome::cairo_serde::call::FCall { @@ -1541,4 +1527,18 @@ impl Erc20Reader

{ }; cainome::cairo_serde::call::FCall::new(__call, self.provider()) } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] + pub fn owner( + &self, + ) -> cainome::cairo_serde::call::FCall { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + let __call = starknet::core::types::FunctionCall { + contract_address: self.address, + entry_point_selector: starknet::macros::selector!("owner"), + calldata: __calldata, + }; + cainome::cairo_serde::call::FCall::new(__call, self.provider()) + } } diff --git a/packages/connector/src/index.ts b/packages/connector/src/index.ts index 10dc627ee..e0693ea89 100644 --- a/packages/connector/src/index.ts +++ b/packages/connector/src/index.ts @@ -65,7 +65,11 @@ class ControllerConnector extends Connector { } async delegateAccount() { - return this.controller.delegateAccount(); + return await this.controller.delegateAccount(); + } + + async openMenu() { + return await this.controller.openMenu(); } } diff --git a/packages/controller/src/index.ts b/packages/controller/src/index.ts index 2daeb202a..9afc97f27 100644 --- a/packages/controller/src/index.ts +++ b/packages/controller/src/index.ts @@ -21,6 +21,7 @@ import { ColorMode, PaymasterOptions, Prefund, + ConnectError, } from "./types"; import { createModal } from "./modal"; import { defaultPresets } from "./presets"; @@ -57,6 +58,20 @@ class Controller { this.initModal(); } + async openMenu() { + if (!this.keychain || !this.modal) { + console.error(new NotReadyToConnect().message); + return null; + } + this.modal.open(); + const res = await this.keychain.openMenu(); + this.modal.close(); + if (res && (res as ConnectError).code === ResponseCodes.NOT_CONNECTED) { + return false; + } + return true; + } + private initModal() { if (typeof document === "undefined") return; @@ -223,16 +238,12 @@ class Controller { } async delegateAccount() { - if (!this.account) { + if (!this.keychain) { console.error(new NotReadyToConnect().message); return null; } - return this.account.callContract({ - contractAddress: this.account.address, - entrypoint: "delegate_account", - calldata: [], - }); + return await this.keychain.delegateAccount(); } } diff --git a/packages/controller/src/types.ts b/packages/controller/src/types.ts index 57290f968..af13f5d32 100644 --- a/packages/controller/src/types.ts +++ b/packages/controller/src/types.ts @@ -86,6 +86,7 @@ export interface Keychain { paymaster?: PaymasterOptions, ): Promise; logout(): Promise; + openMenu(): Promise; session(): Promise; sessions(): Promise<{ [key: string]: Session; @@ -105,6 +106,7 @@ export interface Keychain { signDeclareTransaction(transaction: DeclareSignerDetails): Promise; username(): string; + delegateAccount(): string; } export interface Modal { diff --git a/packages/keychain/.env.development b/packages/keychain/.env.development index 4619f94d3..cd126d247 100644 --- a/packages/keychain/.env.development +++ b/packages/keychain/.env.development @@ -10,7 +10,7 @@ NEXT_PUBLIC_ETH_RPC_SEPOLIA="https://eth-sepolia.g.alchemy.com/v2/mURnclB5pn5elD NEXT_PUBLIC_ORIGIN="http://localhost:3001" NEXT_PUBLIC_RP_ID="localhost" -NEXT_PUBLIC_ADMIN_URL="http://localhost:3000" +NEXT_PUBLIC_ADMIN_URL="http://localhost:3002" NEXT_PUBLIC_API_BASE_URL="http://localhost:8000" NEXT_PUBLIC_API_URL="http://localhost:8000/query" NEXT_PUBLIC_RPC_MAINNET="http://localhost:8001/x/starknet/mainnet" diff --git a/packages/keychain/src/components/Menu/index.tsx b/packages/keychain/src/components/Menu/index.tsx new file mode 100644 index 000000000..71feab5c3 --- /dev/null +++ b/packages/keychain/src/components/Menu/index.tsx @@ -0,0 +1,128 @@ +import { Button, VStack, Text, HStack, Spacer } from "@chakra-ui/react"; +import { Container, Content, Footer } from "components/layout"; +import { CopyIcon } from "@cartridge/ui"; +import { useConnection } from "hooks/connection"; +import { useEffect, useState } from "react"; + +const shortAddress = (address: string) => { + return `${address.slice(0, 6)}...${address.slice( + address.length - 4, + address.length, + )}`; +}; + +export function Menu({ + onLogout, + onSetDelegate, +}: { + onLogout: () => void; + onSetDelegate: () => void; +}) { + const { controller } = useConnection(); + const [isCopying, setIsCopying] = useState(false); + const [isCopyingDelegate, setIsCopyingDelegate] = useState(false); + const [delegateAccount, setDelegateAccount] = useState(""); + + useEffect(() => { + const init = async () => { + const delegate = await controller.delegateAccount(); + setDelegateAccount(delegate); + }; + init(); + }, [controller]); + + const onCopy = () => { + setIsCopying(true); + navigator.clipboard.writeText(controller.address); + setTimeout(() => { + setIsCopying(false); + }, 1_000); + }; + + const onCopyDelegate = () => { + setIsCopyingDelegate(true); + navigator.clipboard.writeText(delegateAccount); + setTimeout(() => { + setIsCopyingDelegate(false); + }, 1_000); + }; + + return ( + + + + + + + Controller + + + {!isCopying ? ( + + {shortAddress(controller.address)} + + + + ) : ( + Copied to clipboard! + )} + + + {delegateAccount && BigInt(delegateAccount) !== 0n && ( + + + Delegate + + + {!isCopyingDelegate ? ( + + {shortAddress(delegateAccount)} + + + + ) : ( + Copied to clipboard! + )} + + )} + + + + + + + +

+ + ); +} diff --git a/packages/keychain/src/components/SetDelegate.tsx b/packages/keychain/src/components/SetDelegate.tsx new file mode 100644 index 000000000..c1bebd018 --- /dev/null +++ b/packages/keychain/src/components/SetDelegate.tsx @@ -0,0 +1,66 @@ +import { AlertIcon } from "@cartridge/ui"; +import { Button, VStack, Text, HStack, Input } from "@chakra-ui/react"; +import { Container, Content, Footer } from "components/layout"; +import { useEffect, useState } from "react"; +import { CallData, num } from "starknet"; + +export function SetDelegate({ + onClose, + onSetDelegate, +}: { + onClose: () => void; + onSetDelegate: (address: string) => void; +}) { + const [delegateAddress, setDelegateAddress] = useState(""); + const [isValid, setIsValid] = useState(true); + + useEffect(() => { + try { + CallData.compile([delegateAddress]); + setIsValid(num.isHex(delegateAddress)); + } catch (e: any) { + setIsValid(false); + } + }, [delegateAddress]); + + return ( + + + + + Your controller can be owned by an existing Starknet wallet which + can receive the rewards you earn while playing.
+ (This can be updated later) +
+ + setDelegateAddress(e.target.value)} + /> + {!isValid && delegateAddress !== "" && ( + + Invalid address! + + )} + +
+
+
+ + +
+
+ ); +} diff --git a/packages/keychain/src/components/index.ts b/packages/keychain/src/components/index.ts index 556611560..c5a68a779 100644 --- a/packages/keychain/src/components/index.ts +++ b/packages/keychain/src/components/index.ts @@ -2,3 +2,4 @@ export * from "./Animation"; export * from "./DeploymentRequired"; export * from "./Execute"; export * from "./SignMessage"; +export * from "./Menu"; diff --git a/packages/keychain/src/components/layout/Container/Header/Banner.tsx b/packages/keychain/src/components/layout/Container/Header/Banner.tsx index e3407308b..c672ba94b 100644 --- a/packages/keychain/src/components/layout/Container/Header/Banner.tsx +++ b/packages/keychain/src/components/layout/Container/Header/Banner.tsx @@ -34,6 +34,7 @@ export function Banner({ Icon, icon, title, description }: BannerProps) { switch (variant) { case "connect": case "error": + case "menu": return ( - {variant === "connect" && ( + {(variant === "connect" || variant === "menu") && ( Controller by - + )} diff --git a/packages/keychain/src/hooks/connection.tsx b/packages/keychain/src/hooks/connection.tsx index 9fb845fac..40f95e8db 100644 --- a/packages/keychain/src/hooks/connection.tsx +++ b/packages/keychain/src/hooks/connection.tsx @@ -13,8 +13,10 @@ import { connectToController, ConnectionCtx, LogoutCtx, + SetDelegateCtx, + ExecuteCtx, } from "utils/connection"; -import { RpcProvider, constants, shortString } from "starknet"; +import { RpcProvider, CallData, constants, shortString } from "starknet"; import { Policy, Prefund, ResponseCodes } from "@cartridge/controller"; import { mergeDefaultETHPrefund } from "utils/token"; import { isIframe } from "components/connect/utils"; @@ -36,6 +38,11 @@ type ConnectionContextValue = { setController: (controller: Controller) => void; cancel: () => void; logout: (context: ConnectionCtx) => void; + setDelegate: (context: ConnectionCtx) => void; + setDelegateTransaction: ( + context: ConnectionCtx, + delegateAddress: string, + ) => void; }; export function ConnectionProvider({ children }: PropsWithChildren) { @@ -147,6 +154,35 @@ export function ConnectionProvider({ children }: PropsWithChildren) { } as LogoutCtx); }, []); + const setDelegate = useCallback((context: ConnectionCtx) => { + setContext({ + origin: context.origin, + type: "set-delegate", + resolve: context.resolve, + reject: context.reject, + } as SetDelegateCtx); + }, []); + + const setDelegateTransaction = useCallback( + (context: ConnectionCtx, delegateAddress: string) => { + setContext({ + origin: context.origin, + transactions: [ + { + contractAddress: controller.address, + entrypoint: "set_delegate_account", + calldata: CallData.compile([delegateAddress]), + }, + ], + transactionsDetail: {}, + type: "execute", + resolve: context.resolve, + reject: context.reject, + } as ExecuteCtx); + }, + [controller?.address], + ); + return ( {children} diff --git a/packages/keychain/src/pages/index.tsx b/packages/keychain/src/pages/index.tsx index e81275d18..c099cbb60 100644 --- a/packages/keychain/src/pages/index.tsx +++ b/packages/keychain/src/pages/index.tsx @@ -1,22 +1,27 @@ import dynamic from "next/dynamic"; import { Signature } from "starknet"; import { ResponseCodes } from "@cartridge/controller"; -import { DeploymentRequired, Execute, SignMessage } from "components"; +import { DeploymentRequired, Execute, Menu, SignMessage } from "components"; import { CreateController, CreateSession, Logout } from "components/connect"; import { useConnection } from "hooks/connection"; import { ConnectCtx, ExecuteCtx, LogoutCtx, + OpenMenuCtx, + SetDelegateCtx, SignMessageCtx, } from "utils/connection"; import { diff } from "utils/controller"; import { logout } from "utils/connection/logout"; import { LoginMode } from "components/connect/types"; import { ErrorPage } from "components/ErrorBoundary"; +import { SetDelegate } from "components/SetDelegate"; function Home() { - const { context, controller, error } = useConnection(); + const { context, controller, error, setDelegate, setDelegateTransaction } = + useConnection(); + if (window.self === window.top || !context?.origin) { return <>; } @@ -116,6 +121,57 @@ function Home() { ); } + case "open-menu": { + const ctx = context as OpenMenuCtx; + return ( + + ctx.resolve({ + code: ResponseCodes.CANCELED, + message: "Canceled", + }) + } + > + { + logout(ctx.origin)(); + + ctx.resolve({ + code: ResponseCodes.NOT_CONNECTED, + message: "User logged out", + }); + }} + onSetDelegate={() => setDelegate(ctx)} + /> + + ); + } + + case "set-delegate": { + const ctx = context as SetDelegateCtx; + return ( + + ctx.resolve({ + code: ResponseCodes.CANCELED, + message: "Canceled", + }) + } + > + + ctx.resolve({ + code: ResponseCodes.CANCELED, + message: "Canceled", + }) + } + onSetDelegate={(delegateAddress) => { + setDelegateTransaction(ctx, delegateAddress); + }} + /> + + ); + } default: return <>*Waves*; } diff --git a/packages/keychain/src/utils/account.ts b/packages/keychain/src/utils/account.ts index b6e745b20..e9375390a 100644 --- a/packages/keychain/src/utils/account.ts +++ b/packages/keychain/src/utils/account.ts @@ -194,6 +194,10 @@ class Account extends BaseAccount { nonce: undefined, }); } + + async delegateAccount(): Promise { + return this.cartridge.delegateAccount(); + } } export default Account; diff --git a/packages/keychain/src/utils/connection/delegate.ts b/packages/keychain/src/utils/connection/delegate.ts new file mode 100644 index 000000000..58a05eb6b --- /dev/null +++ b/packages/keychain/src/utils/connection/delegate.ts @@ -0,0 +1,27 @@ +import { ConnectionCtx, SetDelegateCtx } from "./types"; +import Controller from "utils/controller"; + +export function setDelegateFactory(setContext: (ctx: ConnectionCtx) => void) { + return (_: Controller, origin: string) => (account: string) => { + return new Promise((resolve, reject) => { + setContext({ + type: "set-delegate", + origin, + account, + resolve, + reject, + } as SetDelegateCtx); + }); + }; +} + +export function delegateAccount() { + return async () => { + const controller = Controller.fromStore(); + if (!controller) { + throw new Error("no controller"); + } + + return await controller.delegateAccount(); + }; +} diff --git a/packages/keychain/src/utils/connection/index.ts b/packages/keychain/src/utils/connection/index.ts index 7cf8e2e8b..152fb6a89 100644 --- a/packages/keychain/src/utils/connection/index.ts +++ b/packages/keychain/src/utils/connection/index.ts @@ -13,6 +13,8 @@ import { revoke, session, sessions } from "./sessions"; import { signMessageFactory } from "./sign"; import { username } from "./username"; import { ConnectionCtx } from "./types"; +import { openMenuFactory } from "./menu"; +import { delegateAccount, setDelegateFactory } from "./delegate"; export function connectToController({ setOrigin, @@ -45,10 +47,13 @@ export function connectToController({ probe: normalize(validate(probeFactory(setController))), revoke: normalize(revoke), signMessage: normalize(validate(signMessageFactory(setContext))), + openMenu: normalize(validate(openMenuFactory(setContext))), session: normalize(session), sessions: normalize(sessions), + setDelegate: normalize(validate(setDelegateFactory(setContext))), reset: normalize(() => () => setContext(undefined)), username: normalize(username), + delegateAccount: normalize(delegateAccount), }, }); } diff --git a/packages/keychain/src/utils/connection/menu.ts b/packages/keychain/src/utils/connection/menu.ts new file mode 100644 index 000000000..ef255dd99 --- /dev/null +++ b/packages/keychain/src/utils/connection/menu.ts @@ -0,0 +1,16 @@ +import { ConnectionCtx, OpenMenuCtx } from "./types"; +import Controller from "utils/controller"; + +export function openMenuFactory(setContext: (ctx: ConnectionCtx) => void) { + return (_: Controller, origin: string) => (account: string) => { + return new Promise((resolve, reject) => { + setContext({ + type: "open-menu", + origin, + account, + resolve, + reject, + } as OpenMenuCtx); + }); + }; +} diff --git a/packages/keychain/src/utils/connection/types.ts b/packages/keychain/src/utils/connection/types.ts index 096d8c8ac..9c5afb4ac 100644 --- a/packages/keychain/src/utils/connection/types.ts +++ b/packages/keychain/src/utils/connection/types.ts @@ -17,7 +17,9 @@ export type ConnectionCtx = | ConnectCtx | LogoutCtx | ExecuteCtx - | SignMessageCtx; + | SignMessageCtx + | OpenMenuCtx + | SetDelegateCtx; export type ConnectCtx = { origin: string; @@ -54,3 +56,19 @@ export type SignMessageCtx = { resolve: (signature: Signature | ConnectError) => void; reject: (reason?: unknown) => void; }; + +export type OpenMenuCtx = { + origin: string; + type: "open-menu"; + account: string; + resolve: (res: ConnectError) => void; + reject: (reason?: unknown) => void; +}; + +export type SetDelegateCtx = { + origin: string; + type: "set-delegate"; + account: string; + resolve: (res: ConnectError) => void; // ? + reject: (reason?: unknown) => void; // ? +}; diff --git a/packages/keychain/src/utils/controller.ts b/packages/keychain/src/utils/controller.ts index 9450eab6f..0c49a936b 100644 --- a/packages/keychain/src/utils/controller.ts +++ b/packages/keychain/src/utils/controller.ts @@ -1,4 +1,9 @@ -import { SignerInterface, BigNumberish, addAddressPadding } from "starknet"; +import { + SignerInterface, + BigNumberish, + addAddressPadding, + num, +} from "starknet"; import { Policy, Session } from "@cartridge/controller"; @@ -7,6 +12,8 @@ import Storage from "utils/storage"; import Account from "./account"; import { selectors, VERSION } from "./selectors"; import migrations from "./migrations"; +import { AccountInfoDocument } from "generated/graphql"; +import { client } from "./graphql"; type SerializedController = { publicKey: string; @@ -60,6 +67,29 @@ export default class Controller { ); } + async getUser() { + const res = await client.request(AccountInfoDocument, { + id: this.address, + }); + + // @ts-expect-error TODO: fix type error + const account = res.accounts?.edges?.[0]?.node; + if (!account) { + throw new Error("User not found"); + } + + return { + address: this.address, + name: account.id, + profileUri: `https://cartridge.gg/profile/${this.address}`, + }; + } + + async delegateAccount() { + const address = await this.account.cartridge.delegateAccount(); + return num.toHexString(address); + } + delete() { return Storage.clear(); }