Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions contracts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["yield_vault", "zap", "options", "aa_recovery", "aa_factory", "settlement", "intent_swap", "dutch_auction", "liquid_staking", "emission_controller", "strategies/delta_neutral", "stableswap", "stealth_addresses", "merkle_distributor"]
members = ["yield_vault", "yield_tranches", "zap", "options", "aa_recovery", "aa_factory", "settlement", "intent_swap", "dutch_auction", "liquid_staking", "emission_controller", "optimistic_governance", "streaming_payments"]

[profile.release]
opt-level = "z"
Expand Down
75 changes: 43 additions & 32 deletions contracts/aa_factory/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ use crate::proxy_wallet::ProxyWalletClient;
#[derive(Clone)]
pub enum StorageKey {
Initialized,
Admin, // Factory admin address
ProxyCodeHash, // Hash of the proxy contract code
DeployedProxies, // Vec<Address> - All deployed proxy addresses
UserToProxy, // Map<Address, Address> - User address to proxy mapping
Relayer, // Trusted relayer for gas sponsorship
Nonce, // Nonce for deterministic address generation
Admin, // Factory admin address
ProxyCodeHash, // Hash of the proxy contract code
DeployedProxies, // Vec<Address> - All deployed proxy addresses
UserToProxy, // Map<Address, Address> - User address to proxy mapping
Relayer, // Trusted relayer for gas sponsorship
Nonce, // Nonce for deterministic address generation
}

// ── Data Structures ─────────────────────────────────────────────────────
Expand All @@ -37,9 +37,9 @@ pub enum StorageKey {
#[contracttype]
#[derive(Clone, Debug)]
pub struct DeploymentConfig {
pub owner: Address, // The wallet owner's address
pub owner: Address, // The wallet owner's address
pub relayer: Option<Address>, // Optional trusted relayer
pub salt: u64, // Salt for deterministic address generation
pub salt: u64, // Salt for deterministic address generation
}

/// Proxy wallet information
Expand Down Expand Up @@ -115,13 +115,19 @@ impl WalletFactory {
}

env.storage().instance().set(&StorageKey::Admin, &admin);
env.storage().instance().set(&StorageKey::ProxyCodeHash, &proxy_code_hash);
env.storage()
.instance()
.set(&StorageKey::ProxyCodeHash, &proxy_code_hash);
env.storage().instance().set(&StorageKey::Nonce, &0u64);
env.storage().instance().set(&StorageKey::Initialized, &true);
env.storage()
.instance()
.set(&StorageKey::Initialized, &true);

// Initialize storage collections
let deployed_proxies: Vec<Address> = Vec::new(&env);
env.storage().instance().set(&StorageKey::DeployedProxies, &deployed_proxies);
env.storage()
.instance()
.set(&StorageKey::DeployedProxies, &deployed_proxies);

// Emit event
env.events().publish((symbol_short!("init"),), (admin,));
Expand Down Expand Up @@ -155,10 +161,7 @@ impl WalletFactory {
///
/// - Each user can only have one proxy wallet
/// - The proxy is initialized with the owner and factory addresses
pub fn deploy_proxy(
env: Env,
config: DeploymentConfig,
) -> Result<Address, FactoryError> {
pub fn deploy_proxy(env: Env, config: DeploymentConfig) -> Result<Address, FactoryError> {
Self::require_initialized(&env)?;
config.owner.require_auth();

Expand All @@ -183,18 +186,20 @@ impl WalletFactory {
// &proxy_code_hash,
// (config.owner.clone(), env.current_contract_address(), config.relayer.clone()),
// );

// For this implementation, we return the computed address as a placeholder
// The actual deployment would happen through the Soroban CLI or SDK
let proxy_id = config.owner.clone(); // Placeholder - in production this would be the deployed contract address

// Initialize the proxy
// In production: proxy_client.initialize(...)

// Update storage
let mut updated_mapping = user_to_proxy;
updated_mapping.set(config.owner.clone(), proxy_id.clone());
env.storage().instance().set(&StorageKey::UserToProxy, &updated_mapping);
env.storage()
.instance()
.set(&StorageKey::UserToProxy, &updated_mapping);

// Add to deployed proxies list
let mut deployed: Vec<Address> = env
Expand All @@ -203,11 +208,19 @@ impl WalletFactory {
.get(&StorageKey::DeployedProxies)
.unwrap_or(Vec::new(&env));
deployed.push_back(proxy_id.clone());
env.storage().instance().set(&StorageKey::DeployedProxies, &deployed);
env.storage()
.instance()
.set(&StorageKey::DeployedProxies, &deployed);

// Update nonce
let nonce: u64 = env.storage().instance().get(&StorageKey::Nonce).unwrap_or(0);
env.storage().instance().set(&StorageKey::Nonce, &(nonce + 1));
let nonce: u64 = env
.storage()
.instance()
.get(&StorageKey::Nonce)
.unwrap_or(0);
env.storage()
.instance()
.set(&StorageKey::Nonce, &(nonce + 1));

// Emit event
env.events().publish(
Expand Down Expand Up @@ -266,18 +279,15 @@ impl WalletFactory {
/// # Returns
///
/// Returns `Ok(())` on success
pub fn set_relayer(
env: Env,
admin: Address,
relayer: Address,
) -> Result<(), FactoryError> {
pub fn set_relayer(env: Env, admin: Address, relayer: Address) -> Result<(), FactoryError> {
Self::require_initialized(&env)?;
Self::require_admin(&env, &admin)?;

env.storage().instance().set(&StorageKey::Relayer, &relayer);

// Emit event
env.events().publish((symbol_short!("set_rel"),), (relayer,));
env.events()
.publish((symbol_short!("set_rel"),), (relayer,));

Ok(())
}
Expand Down Expand Up @@ -372,10 +382,7 @@ impl WalletFactory {
/// # Returns
///
/// Returns ProxyInfo if the proxy exists
pub fn get_proxy_info(
env: Env,
proxy_address: Address,
) -> Result<ProxyInfo, FactoryError> {
pub fn get_proxy_info(env: Env, proxy_address: Address) -> Result<ProxyInfo, FactoryError> {
Self::require_initialized(&env)?;

// Search through user mappings to find owner
Expand Down Expand Up @@ -410,7 +417,11 @@ impl WalletFactory {
/// Returns the stored proxy code hash
pub fn get_proxy_code_hash(env: Env) -> Result<Bytes, FactoryError> {
Self::require_initialized(&env)?;
Ok(env.storage().instance().get(&StorageKey::ProxyCodeHash).unwrap())
Ok(env
.storage()
.instance()
.get(&StorageKey::ProxyCodeHash)
.unwrap())
}

/// Get the factory admin address.
Expand Down
7 changes: 2 additions & 5 deletions contracts/aa_factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@
mod factory;
mod proxy_wallet;

pub use factory::{
DeploymentConfig, FactoryError, ProxyInfo, WalletFactory, WalletFactoryClient,
};
pub use factory::{DeploymentConfig, FactoryError, ProxyInfo, WalletFactory, WalletFactoryClient};
pub use proxy_wallet::{
ExecutionResult, ProxyError, ProxyWallet, ProxyWalletClient, UserOperation,
WebAuthnSignature,
ExecutionResult, ProxyError, ProxyWallet, ProxyWalletClient, UserOperation, WebAuthnSignature,
};
Loading
Loading