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

Update overview docs #735

Merged
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
49baf23
feat: update format and add api
ericnordelo Aug 23, 2023
6ba12a9
fix: typo
ericnordelo Aug 23, 2023
38a7363
feat: add counterfactual deployment doc
ericnordelo Aug 24, 2023
06d3384
feat: add API entries
ericnordelo Aug 24, 2023
48e77cf
feat: add events
ericnordelo Aug 24, 2023
2cce06a
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Aug 25, 2023
71cc37d
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Aug 25, 2023
a34020e
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Aug 25, 2023
60305e7
Update docs/modules/ROOT/pages/guides/deployment.adoc
ericnordelo Aug 25, 2023
2223482
Update docs/modules/ROOT/pages/guides/deployment.adoc
ericnordelo Aug 25, 2023
1ae6d18
feat: update from reviews
ericnordelo Aug 25, 2023
849739d
Merge branch 'feat/update-account-docs-#560' of github.com:ericnordel…
ericnordelo Aug 25, 2023
7a9f38e
feat: apply review updates
ericnordelo Aug 25, 2023
2c3b734
feat: update docs
ericnordelo Aug 30, 2023
fbc18fb
Update docs/modules/ROOT/pages/api/account.adoc
ericnordelo Aug 31, 2023
b235619
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Aug 31, 2023
13248e4
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Aug 31, 2023
cdf7bd2
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Aug 31, 2023
bea7e8d
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Aug 31, 2023
437b196
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Aug 31, 2023
d3ffdf4
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Aug 31, 2023
0d8bdce
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Aug 31, 2023
964e58b
Update docs/modules/ROOT/pages/api/account.adoc
ericnordelo Aug 31, 2023
99fa76f
Update docs/modules/ROOT/pages/api/account.adoc
ericnordelo Aug 31, 2023
e5afaeb
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Aug 31, 2023
56715e7
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Aug 31, 2023
a596957
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Aug 31, 2023
c5d1466
Update docs/modules/ROOT/pages/guides/deployment.adoc
ericnordelo Aug 31, 2023
022d8bd
Update docs/modules/ROOT/pages/guides/deployment.adoc
ericnordelo Aug 31, 2023
4ede5cc
Update docs/modules/ROOT/pages/guides/deployment.adoc
ericnordelo Aug 31, 2023
f007a1f
Update docs/modules/ROOT/pages/guides/deployment.adoc
ericnordelo Aug 31, 2023
76ce366
Update docs/modules/ROOT/pages/api/account.adoc
ericnordelo Aug 31, 2023
207662c
Update docs/modules/ROOT/pages/api/account.adoc
ericnordelo Aug 31, 2023
699a27a
Update docs/modules/ROOT/pages/api/account.adoc
ericnordelo Aug 31, 2023
29b23f4
Update docs/modules/ROOT/pages/api/account.adoc
ericnordelo Aug 31, 2023
19b8372
Update docs/modules/ROOT/pages/api/account.adoc
ericnordelo Aug 31, 2023
d909516
Update docs/modules/ROOT/pages/api/account.adoc
ericnordelo Aug 31, 2023
8c23b4c
feat: apply review updates
ericnordelo Aug 31, 2023
8741eea
Merge branch 'feat/update-account-docs-#560' of github.com:ericnordel…
ericnordelo Aug 31, 2023
501b241
fix: account casing
ericnordelo Aug 31, 2023
5b33694
feat: add headers
ericnordelo Aug 31, 2023
e781bfd
Update docs/modules/ROOT/pages/api/account.adoc
ericnordelo Aug 31, 2023
7fdf47b
feat: add link
ericnordelo Aug 31, 2023
448a015
Merge branch 'feat/update-account-docs-#560' of github.com:ericnordel…
ericnordelo Aug 31, 2023
77da367
feat: move API
ericnordelo Sep 1, 2023
76fd058
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Sep 11, 2023
0342dfc
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Sep 11, 2023
7e5a3ec
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Sep 11, 2023
f3cccac
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Sep 11, 2023
0f4583d
refactor: update wording
ericnordelo Sep 11, 2023
7a2db69
Merge branch 'feat/update-account-docs-#560' of github.com:ericnordel…
ericnordelo Sep 11, 2023
55287f4
Merge branch 'cairo-2' of github.com:OpenZeppelin/cairo-contracts int…
ericnordelo Sep 11, 2023
039fb1f
Update docs/antora.yml
ericnordelo Sep 11, 2023
2f51db7
Update docs/modules/ROOT/pages/api/account.adoc
ericnordelo Sep 11, 2023
bf2543c
Update docs/modules/ROOT/pages/api/account.adoc
ericnordelo Sep 11, 2023
eba2992
feat: apply update reviews
ericnordelo Sep 11, 2023
0fe2d86
Merge branch 'feat/update-account-docs-#560' of github.com:ericnordel…
ericnordelo Sep 11, 2023
694b3a2
Update docs/modules/ROOT/pages/api/account.adoc
ericnordelo Sep 11, 2023
5de23f2
refactor: UI
ericnordelo Sep 11, 2023
717f548
fix: UI
ericnordelo Sep 11, 2023
a5d6f94
feat: focus on SRC6
ericnordelo Sep 11, 2023
184b536
Update docs/modules/ROOT/pages/accounts.adoc
ericnordelo Sep 14, 2023
3755397
Merge branch 'feat/update-account-docs-#560' into feat/update-overvie…
ericnordelo Sep 14, 2023
648f8f0
feat: update overview
ericnordelo Sep 14, 2023
000672a
feat: apply review updates
ericnordelo Sep 15, 2023
caea081
Merge branch 'feat/update-account-docs-#560' of github.com:ericnordel…
ericnordelo Sep 15, 2023
6831345
Merge branch 'feat/update-account-docs-#560' into feat/update-overvie…
ericnordelo Sep 15, 2023
32fe871
Update docs/modules/ROOT/pages/index.adoc
ericnordelo Sep 15, 2023
4260bb6
feat: apply review updates
ericnordelo Sep 15, 2023
a6abfb8
Merge branch 'feat/update-overview-docs-#727' of github.com:ericnorde…
ericnordelo Sep 15, 2023
511c6fd
Update docs/modules/ROOT/pages/index.adoc
ericnordelo Sep 18, 2023
3f36ccd
feat: apply review updates
ericnordelo Sep 18, 2023
9907ecc
Merge branch 'feat/update-overview-docs-#727' of github.com:ericnorde…
ericnordelo Sep 18, 2023
0008cd9
Merge branch 'cairo-2' of github.com:OpenZeppelin/cairo-contracts int…
ericnordelo Sep 18, 2023
92abbc2
Update docs/modules/ROOT/pages/index.adoc
ericnordelo Sep 19, 2023
922ebda
Merge branch 'cairo-2' of github.com:OpenZeppelin/cairo-contracts int…
ericnordelo Sep 20, 2023
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
24 changes: 12 additions & 12 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
* xref:index.adoc[Overview]
* xref:wizard.adoc[Wizard]
* xref:extensibility.adoc[Extensibility]
* xref:proxies.adoc[Proxies and Upgrades]
// * xref:wizard.adoc[Wizard]
// * xref:extensibility.adoc[Extensibility]
// * xref:proxies.adoc[Proxies and Upgrades]

* xref:accounts.adoc[Accounts]
** xref:/guides/deployment.adoc[Counterfactual deployments]
** xref:/api/account.adoc[API Reference]

* xref:access.adoc[Access Control]
// * xref:access.adoc[Access Control]

* Tokens
** xref:erc20.adoc[ERC20]
** xref:erc721.adoc[ERC721]
** xref:erc1155.adoc[ERC1155]
// * Tokens
// ** xref:erc20.adoc[ERC20]
// ** xref:erc721.adoc[ERC721]
// ** xref:erc1155.adoc[ERC1155]

* xref:security.adoc[Security]
* xref:introspection.adoc[Introspection]
* xref:udc.adoc[Universal Deployer Contract]
* xref:utilities.adoc[Utilities]
// * xref:security.adoc[Security]
// * xref:introspection.adoc[Introspection]
// * xref:udc.adoc[Universal Deployer Contract]
// * xref:utilities.adoc[Utilities]

* xref:contracts::index.adoc[Contracts for Solidity]
185 changes: 110 additions & 75 deletions docs/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
@@ -1,115 +1,150 @@
= Contracts for Cairo
:starknet: https://starkware.co/product/starknet/[Starknet]
:scarb: https://docs.swmansion.com/scarb[Scarb]
:installation: https://docs.swmansion.com/scarb/download.html[this guide]

*A library for secure smart contract development* written in Cairo for https://starkware.co/product/starknet/[StarkNet], a decentralized ZK Rollup.
= Contracts for Cairo

== Usage
*A library for secure smart contract development* written in Cairo for {starknet}, a decentralized ZK Rollup.

WARNING: This repo contains highly experimental code. Expect rapid iteration. *Use at your own risk.*

=== First time?
== Installation

Before installing Cairo on your machine, you need to install `gmp`:
The library is available as a {scarb} package. Follow {installation} for installing Cairo and Scarb on your machine
before proceeding, and run the following command to check that the installation was successful:

[,bash]
----
sudo apt install -y libgmp3-dev # linux
brew install gmp # mac
----
$ scarb --version

TIP: If you have any trouble installing gmp on your Apple M1 computer, https://github.com/OpenZeppelin/nile/issues/22[here's a list of potential solutions].
scarb 0.7.0 (58cc88efb 2023-08-23)
cairo: 2.2.0 (https://crates.io/crates/cairo-lang-compiler/2.2.0)
sierra: 1.3.0
----

=== Set up your project

Create a directory for your project, then `cd` into it and create a Python virtual environment.
Create an empty directory, and `cd` into it:

[,bash]
----
mkdir my-project
cd my-project
python3 -m venv env
source env/bin/activate
mkdir my_project/ && cd my_project/
----

Install the https://github.com/OpenZeppelin/nile[Nile] development environment and then run `init` to kickstart a new project.
Nile will create the project directory structure and install https://www.cairo-lang.org/docs/quickstart.html[the Cairo language], a https://github.com/Shard-Labs/starknet-devnet/[local network], and a https://docs.pytest.org/en/6.2.x/[testing framework].
Initialize a new Scarb project:

[,bash]
----
pip install cairo-nile
nile init
scarb init
----

=== Install the library
The contents of `my_project/` should now look like this:

[,bash]
----
pip install openzeppelin-cairo-contracts
----

WARNING: Installing directly through GitHub may contain incomplete or breaking implementations.
While we aim not to introduce such changes, we still strongly recommend installing through https://github.com/OpenZeppelin/cairo-contracts/releases/[official releases].

=== Use a basic preset
$ ls

Presets are ready-to-use contracts that you can deploy right away.
They also serve as examples of how to use library modules.
xref:extensibility.adoc#presets[Read more about presets].

[,cairo]
----
// contracts/MyToken.cairo

%lang starknet

from openzeppelin.token.erc20.presets.ERC20 import (
constructor,
name,
symbol,
totalSupply,
decimals,
balanceOf,
allowance,
transfer,
transferFrom,
approve,
increaseAllowance,
decreaseAllowance
)
Scarb.toml src
----

Compile and deploy it right away:
=== Install the library

[,bash]
----
nile compile
Install the library by declaring it as a dependency in the project's `Scarb.toml` file:

nile deploy MyToken <name> <symbol> <decimals> <initial_supply> <recipient> --alias my_token
[,text]
----
[dependencies]
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.7.0" }
----

NOTE: `<initial_supply>` is expected to be two integers i.e.
`1` `0`.
See xref:utilities.adoc#uint256[uint256] for more information.
WARNING: Make sure the tag matches the target release.

=== Write a custom contract using library modules
== Basic usage

xref:extensibility.adoc#libraries[Read more about libraries].
This is how it looks to build an account contract using the xref:accounts.adoc[account module].
Copy the code into `src/lib.cairo`.

[,cairo]
[,javascript]
----
#[starknet::contract]
mod MyAccount {
use openzeppelin::account::Account;
use openzeppelin::account::account::PublicKeyTrait;
use openzeppelin::account::interface;
use openzeppelin::introspection::interface::ISRC5;
use openzeppelin::introspection::src5::SRC5;
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved
use starknet::account::Call;

// Storage members used by this contract are defined in each imported
// module whose `unsafe_state` is used. This design will be improved
// with the addition of components in the future.
#[storage]
struct Storage {}
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved

#[constructor]
fn constructor(ref self: ContractState, public_key: felt252) {
let mut unsafe_state = _unsafe_state();
Account::InternalImpl::initializer(ref unsafe_state, public_key);
}

#[external(v0)]
impl SRC6Impl of interface::ISRC6<ContractState> {
fn __execute__(self: @ContractState, mut calls: Array<Call>) -> Array<Span<felt252>> {
Account::SRC6Impl::__execute__(@_unsafe_state(), calls)
}

fn __validate__(self: @ContractState, mut calls: Array<Call>) -> felt252 {
Account::SRC6Impl::__validate__(@_unsafe_state(), calls)
}

fn is_valid_signature(
self: @ContractState, hash: felt252, signature: Array<felt252>
) -> felt252 {
Account::SRC6Impl::is_valid_signature(@_unsafe_state(), hash, signature)
}
}

#[external(v0)]
impl SRC5Impl of ISRC5<ContractState> {
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved
fn supports_interface(self: @ContractState, interface_id: felt252) -> bool {
Account::SRC5Impl::supports_interface(@_unsafe_state(), interface_id)
}
}

#[external(v0)]
impl PublicKeyImpl of PublicKeyTrait<ContractState> {
fn get_public_key(self: @ContractState) -> felt252 {
Account::PublicKeyImpl::get_public_key(@_unsafe_state())
}

fn set_public_key(ref self: ContractState, new_public_key: felt252) {
let mut unsafe_state = _unsafe_state();
Account::PublicKeyImpl::set_public_key(ref unsafe_state, new_public_key);
}
}

#[external(v0)]
fn __validate_deploy__(
self: @ContractState,
class_hash: felt252,
contract_address_salt: felt252,
_public_key: felt252
) -> felt252 {
Account::__validate_deploy__(
@_unsafe_state(), class_hash, contract_address_salt, _public_key
)
}

#[inline(always)]
fn _unsafe_state() -> Account::ContractState {
Account::unsafe_new_contract_state()
}
}
----
%lang starknet

from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.cairo.common.uint256 import Uint256
from openzeppelin.security.pausable.library import Pausable
from openzeppelin.token.erc20.library import ERC20

(...)
You can now compile it:

@external
func transfer{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
recipient: felt, amount: Uint256
) -> (success: felt) {
Pausable.assert_not_paused();
return ERC20.transfer(recipient, amount);
}
[,bash]
----
scarb build
----