Skip to content

Commit

Permalink
Merge pull request #32 from ermvrs/main
Browse files Browse the repository at this point in the history
predeployed account registration & deployer
  • Loading branch information
ermvrs authored Dec 13, 2024
2 parents 377b6c5 + bc8f1b1 commit cf075b3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ dev_signer
dev_account
sepolia
sepolia_account
deployment
deployment
deployment.md
14 changes: 14 additions & 0 deletions deployer
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": 1,
"variant": {
"type": "open_zeppelin",
"version": 1,
"public_key": "0x24b3df5592dd01a339e109d3f80b6285d6b9456b896d851f056ec6bbc0fcf5b",
"legacy": false
},
"deployment": {
"status": "deployed",
"class_hash": "0xe2eb8f5672af4e6a4e8a8f1b44989685e668489b0a25437733756c5a34a1d6",
"address": "0x72ecd1c5e0da14c6da18b3e0f370602e5a10b91ad5bbef94931610672c30501"
}
}
8 changes: 3 additions & 5 deletions src/accounts/base.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@ pub mod RosettaAccount {
#[storage]
struct Storage {
ethereum_address: EthAddress,
registry: ContractAddress,
strk_address: ContractAddress
registry: ContractAddress
}

#[constructor]
fn constructor(ref self: ContractState, eth_address: EthAddress, registry: ContractAddress) {
self.ethereum_address.write(eth_address);
self.registry.write(registry);
self.strk_address.write(IRosettanetDispatcher { contract_address: registry }.native_currency());
}
#[abi(embed_v0)]
impl AccountImpl of super::IRosettaAccount<ContractState> {
Expand Down Expand Up @@ -162,7 +160,7 @@ pub mod RosettaAccount {
}

fn native_currency(self: @ContractState) -> ContractAddress {
self.strk_address.read()
IRosettanetDispatcher { contract_address: self.registry.read() }.native_currency()
}

fn isValidSignature(
Expand Down Expand Up @@ -278,7 +276,7 @@ pub mod RosettaAccount {

let calldata: Span<felt252> = array![sn_address.into(), value.low.into(), value.high.into()].span();
// tx has to be reverted if not enough balance
call_contract_syscall(self.strk_address.read(), TRANSFER_ENTRYPOINT, calldata).expect('native transfer fails')
call_contract_syscall(self.native_currency(), TRANSFER_ENTRYPOINT, calldata).expect('native transfer fails')
}

fn execute_multicall(self: @ContractState, calls: Span<RosettanetMulticall>) -> Array<Span<felt252>> {
Expand Down
24 changes: 23 additions & 1 deletion src/rosettanet.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub trait IRosettanet<TState> {
// Write methods
fn register_contract(ref self: TState, address: ContractAddress); // Registers existing starknet contract to registry
fn deploy_account(ref self: TState, eth_address: EthAddress) -> ContractAddress; // Deploys starknet account and returns address
fn register_deployed_account(ref self: TState, eth_address: EthAddress); // Registers account deployed not from this contract
fn set_account_class(ref self: TState, class: ClassHash); // Sets account class, this function will be removed after stable account
fn register_matched_addresses(ref self: TState, sn_address: ContractAddress, eth_address: EthAddress); // Will be used during alpha
fn upgrade(ref self: TState, class: ClassHash); // Upgrades contract
Expand All @@ -23,14 +24,16 @@ pub mod Rosettanet {
use starknet::syscalls::{deploy_syscall, replace_class_syscall};
use starknet::{ContractAddress, EthAddress, ClassHash, get_contract_address, get_caller_address};
use openzeppelin::utils::deployments::{calculate_contract_address_from_deploy_syscall};
use rosettacontracts::accounts::base::{IRosettaAccountDispatcher, IRosettaAccountDispatcherTrait};

#[event]
#[derive(Drop, starknet::Event)]
pub enum Event {
AddressRegistered: AddressRegistered,
AccountDeployed: AccountDeployed,
AccountClassChanged: AccountClassChanged,
Upgraded: Upgraded
Upgraded: Upgraded,
PredeployedAccountRegistered: PredeployedAccountRegistered
}

#[derive(Drop, starknet::Event)]
Expand All @@ -47,6 +50,13 @@ pub mod Rosettanet {
pub eth_address: EthAddress,
}

#[derive(Drop, starknet::Event)]
pub struct PredeployedAccountRegistered {
#[key]
pub account: ContractAddress,
pub eth_address: EthAddress,
}

#[derive(Drop, starknet::Event)]
pub struct AccountClassChanged {
pub changer: ContractAddress,
Expand Down Expand Up @@ -107,6 +117,18 @@ pub mod Rosettanet {
account
}

/// Registers pre deployed rosetta account to the registry
/// # Arguments
/// * `eth_address` - Ethereum Address for already deployed account
fn register_deployed_account(ref self: ContractState, eth_address: EthAddress) {
let precalculated_address: ContractAddress = self.precalculate_starknet_account(eth_address);
assert(IRosettaAccountDispatcher { contract_address: precalculated_address}.rosettanet() == get_contract_address(), 'wrong deployment');
// TODO: Add tests for this function
self.update_registry(precalculated_address, eth_address);

self.emit(PredeployedAccountRegistered {account: precalculated_address, eth_address });
}

/// Updates account class
/// # Arguments
/// * `class` - New Rosettanet account class hash
Expand Down

0 comments on commit cf075b3

Please sign in to comment.