Skip to content

Commit

Permalink
dev functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ermvrs committed Oct 16, 2024
1 parent 5f3e890 commit 9d4f334
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
target
dev_signer
dev_account
dev_account
sepolia
sepolia_account
26 changes: 22 additions & 4 deletions src/factory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,31 @@ pub trait IFactory<TContractState> {
fn current_account_class(self: @TContractState) -> ClassHash;
fn precalculate_starknet_address(self: @TContractState, address: EthAddress) -> ContractAddress;
fn deploy_account(self: @TContractState, address: EthAddress) -> ContractAddress;
fn upgrade_contract(self: @TContractState, new_class: ClassHash);
fn change_account_class(ref self: TContractState, new_class: ClassHash);
}

#[starknet::contract]
pub mod Factory {
use core::option::OptionTrait;
use starknet::{ContractAddress, ClassHash, EthAddress};
use starknet::syscalls::{deploy_syscall};
use starknet::{ContractAddress, ClassHash, EthAddress, get_caller_address};
use starknet::syscalls::{deploy_syscall, replace_class_syscall};
use core::traits::{Into, TryInto};
use openzeppelin::utils::deployments::{calculate_contract_address_from_deploy_syscall};
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};

#[storage]
struct Storage {
account_class: ClassHash,
lens: ContractAddress
lens: ContractAddress,
dev: ContractAddress
}

#[constructor]
fn constructor(ref self: ContractState, lens: ContractAddress, account_class: ClassHash) {
fn constructor(ref self: ContractState, lens: ContractAddress, account_class: ClassHash, dev: ContractAddress) {
self.account_class.write(account_class);
self.lens.write(lens);
self.dev.write(dev);
}

#[abi(embed_v0)]
Expand Down Expand Up @@ -79,5 +83,19 @@ pub mod Factory {
// Todo: register lens if needed ?? Or we can use precalculate
account
}

// REMOVE THIS FUNCTION AFTER DEVELOPMENT
fn upgrade_contract(self: @ContractState, new_class: ClassHash) {
assert(get_caller_address() == self.dev.read(), 'only dev');

replace_class_syscall(new_class).unwrap();
}

// REMOVE THIS FUNCTION AFTER DEVELOPMENT
fn change_account_class(ref self: ContractState, new_class: ClassHash) {
assert(get_caller_address() == self.dev.read(), 'only dev');

self.account_class.write(new_class);
}
}
}

0 comments on commit 9d4f334

Please sign in to comment.