diff --git a/.gitignore b/.gitignore index 15e3bec..4bfef09 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ dev_signer dev_account sepolia sepolia_account -deployment \ No newline at end of file +deployment +deployment.md diff --git a/deployer b/deployer new file mode 100644 index 0000000..8e13922 --- /dev/null +++ b/deployer @@ -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" + } +} diff --git a/src/accounts/base.cairo b/src/accounts/base.cairo index ef3ff4e..eaca705 100644 --- a/src/accounts/base.cairo +++ b/src/accounts/base.cairo @@ -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 { @@ -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( @@ -278,7 +276,7 @@ pub mod RosettaAccount { let calldata: Span = 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) -> Array> { diff --git a/src/rosettanet.cairo b/src/rosettanet.cairo index 58985e3..698c723 100644 --- a/src/rosettanet.cairo +++ b/src/rosettanet.cairo @@ -4,6 +4,7 @@ pub trait IRosettanet { // 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 @@ -23,6 +24,7 @@ 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)] @@ -30,7 +32,8 @@ pub mod Rosettanet { AddressRegistered: AddressRegistered, AccountDeployed: AccountDeployed, AccountClassChanged: AccountClassChanged, - Upgraded: Upgraded + Upgraded: Upgraded, + PredeployedAccountRegistered: PredeployedAccountRegistered } #[derive(Drop, starknet::Event)] @@ -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, @@ -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