Skip to content

Commit 3641624

Browse files
authored
Merge pull request #107 from OpenZeppelin/feat/cairo-fix-base-directory-for-3.0.0-docs
Cairo: fix 3.0.0 base directory
2 parents a45f927 + 3fba2e2 commit 3641624

82 files changed

Lines changed: 1267 additions & 18795 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

content/contracts-cairo/2.x/wizard.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ contract and learn about the components offered in OpenZeppelin Contracts for Ca
99
We strongly recommend checking the [Components](./components) section to understand how to extend from our library.
1010
</Callout>
1111

12-
<OZWizard lang="cairo" version="2.0.0" />
12+
import { UMBRELLA_VERSION } from "./utils/constants.js";
13+
14+
<OZWizard lang="cairo" version={UMBRELLA_VERSION} />

content/contracts-cairo/3.x/access.mdx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ The most common and basic form of access control is the concept of ownership: th
1313
of a contract and can do administrative tasks on it.
1414
This approach is perfectly reasonable for contracts that have a single administrative user.
1515

16-
OpenZeppelin Contracts for Cairo provides [OwnableComponent](/contracts-cairo/2.x/api/access#OwnableComponent) for implementing ownership in your contracts.
16+
OpenZeppelin Contracts for Cairo provides [OwnableComponent](/contracts-cairo/3.x/api/access#OwnableComponent) for implementing ownership in your contracts.
1717

1818
### Usage
1919

2020
Integrating this component into a contract first requires assigning an owner.
2121
The implementing contract’s constructor should set the initial owner by passing the owner’s address to Ownable’s
22-
[`initializer`](/contracts-cairo/2.x/api/access#OwnableComponent-initializer) like this:
22+
[`initializer`](/contracts-cairo/3.x/api/access#OwnableComponent-initializer) like this:
2323

2424
```rust
2525
#[starknet::contract]
@@ -106,7 +106,7 @@ will no longer be callable!
106106
### Two step transfer
107107

108108
The component also offers a more robust way of transferring ownership via the
109-
[OwnableTwoStepImpl](/contracts-cairo/2.x/api/access#OwnableComponent-Embeddable-Impls-OwnableTwoStepImpl) implementation. A two step transfer mechanism helps
109+
[OwnableTwoStepImpl](/contracts-cairo/3.x/api/access#OwnableComponent-Embeddable-Impls-OwnableTwoStepImpl) implementation. A two step transfer mechanism helps
110110
to prevent unintended and irreversible owner transfers. Simply replace the `OwnableMixinImpl`
111111
with its respective two step variant:
112112

@@ -146,7 +146,7 @@ flexibility in this regard.
146146

147147
In essence, we will be defining multiple roles, each allowed to perform different sets of actions.
148148
An account may have, for example, 'moderator', 'minter' or 'admin' roles, which you will then check for
149-
instead of simply using [`assert_only_owner`](/contracts-cairo/2.x/api/access#OwnableComponent-assert_only_owner). This check can be enforced through [`assert_only_role`](/contracts-cairo/2.x/api/access#AccessControlComponent-assert_only_role).
149+
instead of simply using [`assert_only_owner`](/contracts-cairo/3.x/api/access#OwnableComponent-assert_only_owner). This check can be enforced through [`assert_only_role`](/contracts-cairo/3.x/api/access#AccessControlComponent-assert_only_role).
150150
Separately, you will be able to define rules for how accounts can be granted a role, have it revoked, and more.
151151

152152
Most software uses access control systems that are role-based: some users are regular users, some may be supervisors
@@ -158,7 +158,7 @@ For each role that you want to define, you will create a new _role identifier_ t
158158
check if an account has that role. See [Creating role identifiers](#creating-role-identifiers) for information
159159
on creating identifiers.
160160

161-
Here’s a simple example of implementing [AccessControl](/contracts-cairo/2.x/api/access#AccessControlComponent) on a portion of an ERC20 token contract which defines
161+
Here’s a simple example of implementing [AccessControl](/contracts-cairo/3.x/api/access#AccessControlComponent) on a portion of an ERC20 token contract which defines
162162
and sets a 'minter' role:
163163

164164
```rust
@@ -242,12 +242,12 @@ mod MyContract {
242242
```
243243

244244
<Callout type='warn'>
245-
Make sure you fully understand how [AccessControl](/contracts-cairo/2.x/api/access#AccessControlComponent) works before
245+
Make sure you fully understand how [AccessControl](/contracts-cairo/3.x/api/access#AccessControlComponent) works before
246246
using it on your system, or copy-pasting the examples from this guide.
247247
</Callout>
248248

249249
While clear and explicit, this isn’t anything we wouldn’t have been able to achieve with
250-
[Ownable](/contracts-cairo/2.x/api/access#OwnableComponent). Where [AccessControl](/contracts-cairo/2.x/api/access#AccessControlComponent) shines the most is in scenarios where granular
250+
[Ownable](/contracts-cairo/3.x/api/access#OwnableComponent). Where [AccessControl](/contracts-cairo/3.x/api/access#AccessControlComponent) shines the most is in scenarios where granular
251251
permissions are required, which can be implemented by defining _multiple_ roles.
252252

253253
Let’s augment our ERC20 token example by also defining a 'burner' role, which lets accounts destroy tokens:
@@ -350,16 +350,16 @@ security practice. Note that each account may still have more than one role, if
350350

351351
### Granting and revoking roles
352352

353-
The ERC20 token example above uses [`_grant_role`](/contracts-cairo/2.x/api/access#AccessControlComponent-_grant_role),
353+
The ERC20 token example above uses [`_grant_role`](/contracts-cairo/3.x/api/access#AccessControlComponent-_grant_role),
354354
an `internal` function that is useful when programmatically assigning
355355
roles (such as during construction). But what if we later want to grant the 'minter' role to additional accounts?
356356

357357
By default, **accounts with a role cannot grant it or revoke it from other accounts**: all having a role does is making
358-
the [`assert_only_role`](/contracts-cairo/2.x/api/access#AccessControlComponent-assert_only_role) check pass. To grant and revoke roles dynamically, you will need help from the role’s _admin_.
358+
the [`assert_only_role`](/contracts-cairo/3.x/api/access#AccessControlComponent-assert_only_role) check pass. To grant and revoke roles dynamically, you will need help from the role’s _admin_.
359359

360360
Every role has an associated admin role, which grants permission to call the
361-
[`grant_role`](/contracts-cairo/2.x/api/access#AccessControlComponent-grant_role) and
362-
[`revoke_role`](/contracts-cairo/2.x/api/access#AccessControlComponent-revoke_role) functions.
361+
[`grant_role`](/contracts-cairo/3.x/api/access#AccessControlComponent-grant_role) and
362+
[`revoke_role`](/contracts-cairo/3.x/api/access#AccessControlComponent-revoke_role) functions.
363363
A role can be granted or revoked by using these if the calling account has the corresponding admin role.
364364
Multiple roles may have the same admin role to make management easier.
365365
A role’s admin can even be the same role itself, which would cause accounts with that role to be able
@@ -369,7 +369,9 @@ This mechanism can be used to create complex permissioning structures resembling
369369
provides an easy way to manage simpler applications. `AccessControl` includes a special role with the role identifier
370370
of `0`, called `DEFAULT_ADMIN_ROLE`, which acts as the **default admin role for all roles**.
371371
An account with this role will be able to manage any other role, unless
372-
[`set_role_admin`](/contracts-cairo/2.x/api/access#AccessControlComponent-set_role_admin) is used to select a new admin role.
372+
[`set_role_admin`](/contracts-cairo/3.x/api/access#AccessControlComponent-set_role_admin) is used to select a new admin role.
373+
374+
Since it is the admin for all roles by default, and in fact it is also its own admin, this role carries significant risk. To mitigate this risk we provide [AccessControlDefaultAdminRules](/contracts-cairo/3.x/api/access#AccessControlDefaultAdminRulesComponent), a recommended extension of AccessControl that adds a number of enforced security measures for this role: the admin is restricted to a single account, with a 2-step transfer procedure with a delay in between steps.
373375

374376
Let’s take a look at the ERC20 token example, this time taking advantage of the default admin role:
375377

content/contracts-cairo/3.x/accounts.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A more detailed discussion on the topic can be found in
1313
[Starknet Shaman’s forum](https://community.starknet.io/t/starknet-account-abstraction-model-part-1/781).
1414

1515
<Callout>
16-
For detailed information on the usage and implementation check the [API Reference](/contracts-cairo/2.x/api/account) section.
16+
For detailed information on the usage and implementation check the [API Reference](/contracts-cairo/3.x/api/account) section.
1717
</Callout>
1818

1919
## What is an account?
@@ -97,11 +97,11 @@ Starknet native account abstraction pattern allows for the creation of custom ac
9797
usually most account implementations validate transactions using the [Stark curve](https://docs.starknet.io/learn/protocol/cryptography#the-stark-curve) which is the most efficient way
9898
of validating signatures since it is a STARK-friendly curve.
9999

100-
OpenZeppelin Contracts for Cairo provides [AccountComponent](/contracts-cairo/2.x/api/account#AccountComponent) for implementing this validation scheme.
100+
OpenZeppelin Contracts for Cairo provides [AccountComponent](/contracts-cairo/3.x/api/account#AccountComponent) for implementing this validation scheme.
101101

102102
### Usage
103103

104-
Constructing an account contract requires integrating both [AccountComponent](/contracts-cairo/2.x/api/account#AccountComponent) and [SRC5Component](/contracts-cairo/2.x/api/introspection#SRC5Component). The contract should also set up the constructor to initialize the public key that will be used as the account’s signer. Here’s an example of a basic contract:
104+
Constructing an account contract requires integrating both [AccountComponent](/contracts-cairo/3.x/api/account#AccountComponent) and [SRC5Component](/contracts-cairo/3.x/api/introspection#SRC5Component). The contract should also set up the constructor to initialize the public key that will be used as the account’s signer. Here’s an example of a basic contract:
105105

106106
```rust
107107
#[starknet::contract(account)]
@@ -180,19 +180,19 @@ pub trait AccountABI {
180180
## Ethereum Account
181181

182182
Besides the Stark-curve account, OpenZeppelin Contracts for Cairo also offers Ethereum-flavored accounts that use the [secp256k1](https://en.bitcoin.it/wiki/Secp256k1) curve for signature validation.
183-
For this the [EthAccountComponent](/contracts-cairo/2.x/api/account#EthAccountComponent) must be used.
183+
For this the [EthAccountComponent](/contracts-cairo/3.x/api/account#EthAccountComponent) must be used.
184184

185185
### Usage
186186

187-
Constructing a secp256k1 account contract also requires integrating both [EthAccountComponent](/contracts-cairo/2.x/api/account#EthAccountComponent) and [SRC5Component](/contracts-cairo/2.x/api/introspection#SRC5Component).
187+
Constructing a secp256k1 account contract also requires integrating both [EthAccountComponent](/contracts-cairo/3.x/api/account#EthAccountComponent) and [SRC5Component](/contracts-cairo/3.x/api/introspection#SRC5Component).
188188
The contract should also set up the constructor to initialize the public key that will be used as the account’s signer.
189189
Here’s an example of a basic contract:
190190

191191
```rust
192192
#[starknet::contract(account)]
193193
mod MyEthAccount {
194194
use openzeppelin_account::EthAccountComponent;
195-
use openzeppelin_account::interface::EthPublicKey;
195+
use openzeppelin_interfaces::accounts::EthPublicKey;
196196
use openzeppelin_introspection::src5::SRC5Component;
197197
use starknet::ClassHash;
198198

@@ -371,7 +371,7 @@ First, let’s take the example account we created before and deploy it:
371371
#[starknet::contract(account)]
372372
mod MyEthAccount {
373373
use openzeppelin_account::EthAccountComponent;
374-
use openzeppelin_account::interface::EthPublicKey;
374+
use openzeppelin_interfaces::accounts::EthPublicKey;
375375
use openzeppelin_introspection::src5::SRC5Component;
376376

377377
component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent);

0 commit comments

Comments
 (0)