Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add src9 component to account presets #1201

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions docs/modules/ROOT/pages/api/account.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@ Initializes the account by registering the `ISRC9_V2` interface Id.
use openzeppelin_presets::AccountUpgradeable;
```

Upgradeable account contract leveraging xref:#AccountComponent[AccountComponent].
Upgradeable account which can change its public key and declare, deploy, or call
contracts. Supports outside execution by implementing xref:#SRC9Component[SRC9].

include::../utils/_class_hashes.adoc[]

Expand All @@ -726,6 +727,7 @@ include::../utils/_class_hashes.adoc[]
.AccountComponent

* xref:#AccountComponent-Embeddable-Mixin-Impl[`++AccountMixinImpl++`]
* xref:#SRC9Component-Embeddable-Impls-OutsideExecutionV2Impl[`++OutsideExecutionV2Impl++`]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* xref:#SRC9Component-Embeddable-Impls-OutsideExecutionV2Impl[`++OutsideExecutionV2Impl++`]
.SRC9Component
* xref:#SRC9Component-Embeddable-Impls-OutsideExecutionV2Impl[`++OutsideExecutionV2Impl++`]

We should have SRC9Component on the right side of OutsideExecutionV2Impl, no?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with eth account if we agree

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

--

[.contract-index]
Expand Down Expand Up @@ -765,7 +767,8 @@ Requirements:
use openzeppelin_presets::EthAccountUpgradeable;
```

Upgradeable account contract leveraging xref:#EthAccountComponent[EthAccountComponent].
Upgradeable account which can change its public key and declare, deploy, or call contracts, using Ethereum
signing keys. Supports outside execution by implementing xref:#SRC9Component[SRC9].

NOTE: The `EthPublicKey` type is an alias for `starknet::secp256k1::Secp256k1Point`.

Expand All @@ -789,6 +792,7 @@ include::../utils/_class_hashes.adoc[]
.EthAccountComponent

* xref:#EthAccountComponent-Embeddable-Mixin-Impl[`++EthAccountMixinImpl++`]
* xref:#SRC9Component-Embeddable-Impls-OutsideExecutionV2Impl[`++OutsideExecutionV2Impl++`]
--

[.contract-index]
Expand Down
1 change: 1 addition & 0 deletions packages/presets/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ build-external-contracts = [
"openzeppelin_test_common::mocks::account::DualCaseAccountMock",
"openzeppelin_test_common::mocks::account::SnakeAccountMock",
"openzeppelin_test_common::mocks::account::SnakeEthAccountMock",
"openzeppelin_test_common::mocks::simple::SimpleMock",
"openzeppelin_test_common::mocks::erc20::DualCaseERC20Mock",
"openzeppelin_test_common::mocks::erc20::SnakeERC20Mock",
"openzeppelin_test_common::mocks::erc721::SnakeERC721Mock",
Expand Down
15 changes: 14 additions & 1 deletion packages/presets/src/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
/// # Account Preset
///
/// OpenZeppelin's upgradeable account which can change its public key and declare, deploy, or call
/// contracts.
/// contracts. Supports outside execution by implementing SRC9.
#[starknet::contract(account)]
pub mod AccountUpgradeable {
use openzeppelin_account::AccountComponent;
use openzeppelin_account::extensions::SRC9Component;
use openzeppelin_introspection::src5::SRC5Component;
use openzeppelin_upgrades::UpgradeableComponent;
use openzeppelin_upgrades::interface::IUpgradeable;
use starknet::ClassHash;

component!(path: AccountComponent, storage: account, event: AccountEvent);
component!(path: SRC5Component, storage: src5, event: SRC5Event);
component!(path: SRC9Component, storage: src9, event: SRC9Event);
component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);

// Account Mixin
Expand All @@ -23,6 +25,12 @@ pub mod AccountUpgradeable {
AccountComponent::AccountMixinImpl<ContractState>;
impl AccountInternalImpl = AccountComponent::InternalImpl<ContractState>;

// SRC9
#[abi(embed_v0)]
impl OutsideExecutionV2Impl =
SRC9Component::OutsideExecutionV2Impl<ContractState>;
impl OutsideExecutionInternalImpl = SRC9Component::InternalImpl<ContractState>;

// Upgradeable
impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl<ContractState>;

Expand All @@ -33,6 +41,8 @@ pub mod AccountUpgradeable {
#[substorage(v0)]
pub src5: SRC5Component::Storage,
#[substorage(v0)]
pub src9: SRC9Component::Storage,
#[substorage(v0)]
pub upgradeable: UpgradeableComponent::Storage
}

Expand All @@ -44,12 +54,15 @@ pub mod AccountUpgradeable {
#[flat]
SRC5Event: SRC5Component::Event,
#[flat]
SRC9Event: SRC9Component::Event,
#[flat]
UpgradeableEvent: UpgradeableComponent::Event
}

#[constructor]
pub fn constructor(ref self: ContractState, public_key: felt252) {
self.account.initializer(public_key);
self.src9.initializer();
}

#[abi(embed_v0)]
Expand Down
16 changes: 15 additions & 1 deletion packages/presets/src/eth_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
/// # EthAccount Preset
///
/// OpenZeppelin's upgradeable account which can change its public key and declare,
/// deploy, or call contracts, using Ethereum signing keys.
/// deploy, or call contracts, using Ethereum signing keys. Supports outside execution by
/// implementing SRC9.
#[starknet::contract(account)]
pub(crate) mod EthAccountUpgradeable {
use openzeppelin_account::EthAccountComponent;
use openzeppelin_account::extensions::SRC9Component;
use openzeppelin_account::interface::EthPublicKey;
use openzeppelin_introspection::src5::SRC5Component;
use openzeppelin_upgrades::UpgradeableComponent;
Expand All @@ -16,6 +18,7 @@ pub(crate) mod EthAccountUpgradeable {

component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent);
component!(path: SRC5Component, storage: src5, event: SRC5Event);
component!(path: SRC9Component, storage: src9, event: SRC9Event);
component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);

// EthAccount Mixin
Expand All @@ -24,6 +27,12 @@ pub(crate) mod EthAccountUpgradeable {
EthAccountComponent::EthAccountMixinImpl<ContractState>;
impl EthAccountInternalImpl = EthAccountComponent::InternalImpl<ContractState>;

// SRC9
#[abi(embed_v0)]
impl OutsideExecutionV2Impl =
SRC9Component::OutsideExecutionV2Impl<ContractState>;
impl OutsideExecutionInternalImpl = SRC9Component::InternalImpl<ContractState>;

// Upgradeable
impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl<ContractState>;

Expand All @@ -34,6 +43,8 @@ pub(crate) mod EthAccountUpgradeable {
#[substorage(v0)]
pub src5: SRC5Component::Storage,
#[substorage(v0)]
pub src9: SRC9Component::Storage,
#[substorage(v0)]
pub upgradeable: UpgradeableComponent::Storage
}

Expand All @@ -45,12 +56,15 @@ pub(crate) mod EthAccountUpgradeable {
#[flat]
SRC5Event: SRC5Component::Event,
#[flat]
SRC9Event: SRC9Component::Event,
#[flat]
UpgradeableEvent: UpgradeableComponent::Event
}

#[constructor]
pub(crate) fn constructor(ref self: ContractState, public_key: EthPublicKey) {
self.eth_account.initializer(public_key);
self.src9.initializer();
}

#[abi(embed_v0)]
Expand Down
7 changes: 7 additions & 0 deletions packages/presets/src/interfaces/account.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use openzeppelin_account::extensions::src9::interface::OutsideExecution;
use starknet::ClassHash;
use starknet::account::Call;

Expand All @@ -11,6 +12,12 @@ pub trait AccountUpgradeableABI<TState> {
// ISRC5
fn supports_interface(self: @TState, interface_id: felt252) -> bool;

// ISRC9
fn execute_from_outside_v2(
ref self: TState, outside_execution: OutsideExecution, signature: Span<felt252>,
) -> Array<Span<felt252>>;
fn is_valid_outside_execution_nonce(self: @TState, nonce: felt252) -> bool;

// IDeclarer
fn __validate_declare__(self: @TState, class_hash: felt252) -> felt252;

Expand Down
7 changes: 7 additions & 0 deletions packages/presets/src/interfaces/eth_account.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use openzeppelin_account::extensions::src9::interface::OutsideExecution;
use openzeppelin_account::interface::EthPublicKey;
use starknet::ClassHash;
use starknet::account::Call;
Expand All @@ -12,6 +13,12 @@ pub trait EthAccountUpgradeableABI<TState> {
// ISRC5
fn supports_interface(self: @TState, interface_id: felt252) -> bool;

// ISRC9
fn execute_from_outside_v2(
ref self: TState, outside_execution: OutsideExecution, signature: Span<felt252>,
) -> Array<Span<felt252>>;
fn is_valid_outside_execution_nonce(self: @TState, nonce: felt252) -> bool;

// IDeclarer
fn __validate_declare__(self: @TState, class_hash: felt252) -> felt252;

Expand Down
Loading