Skip to content

Commit 1d6a534

Browse files
authored
Merge pull request #27 from OpenZeppelin/feat/cairo-contracts-fixes
Fixes for contracts-cairo
2 parents 92f0f6b + b8c16d4 commit 1d6a534

Some content is hidden

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

72 files changed

+6453
-2993
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v4
16+
uses: actions/checkout@v5
1717

1818
- name: Setup pnpm
1919
uses: pnpm/action-setup@v4
@@ -27,4 +27,4 @@ jobs:
2727
run: pnpm run check
2828

2929
- name: Build check
30-
run: pnpm run build
30+
run: pnpm run build

content/contracts-cairo/1.0.0/accounts.mdx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ interoperability with the ecosystem.
8080
The Starknet protocol uses a few entrypoints for abstracting the accounts. We already mentioned the first two
8181
as part of the ISRC6 interface, and both are required for enabling accounts to be used for executing transactions. The rest are optional:
8282

83-
1. `\\__validate__` verifies the validity of the transaction to be executed. This is usually used to validate signatures,
83+
1. `__validate__` verifies the validity of the transaction to be executed. This is usually used to validate signatures,
8484
but the entrypoint implementation can be customized to feature any validation mechanism [with some limitations](https://docs.starknet.io/architecture-and-concepts/accounts/account-functions/#limitations_of_validation).
85-
2. `\\__execute__` executes the transaction if the validation is successful.
86-
3. `\\__validate_declare__` optional entrypoint similar to `\\__validate__` but for transactions
85+
2. `__execute__` executes the transaction if the validation is successful.
86+
3. `__validate_declare__` optional entrypoint similar to `__validate__` but for transactions
8787
meant to declare other contracts.
88-
4. `\\__validate_deploy__` optional entrypoint similar to `\\__validate__` but meant for [counterfactual deployments](/guides/deployment).
88+
4. `__validate_deploy__` optional entrypoint similar to `__validate__` but meant for [counterfactual deployments](/guides/deployment).
8989

9090
<Callout>
9191
Although these entrypoints are available to the protocol for its regular transaction flow, they can also be called like any other method.
@@ -275,7 +275,7 @@ wraps and exposes the `deploy_syscall` to provide arbitrary deployments through
275275
But if you don’t have an account to invoke it, you will probably want to use the latter.
276276

277277
To do counterfactual deployments, you need to implement another protocol-level entrypoint named
278-
`\\__validate_deploy__`. Check the [counterfactual deployments](/guides/deployment) guide to learn how.
278+
`__validate_deploy__`. Check the [counterfactual deployments](/guides/deployment) guide to learn how.
279279

280280
## Sending transactions
281281

@@ -285,7 +285,7 @@ Let’s now explore how to send transactions through these accounts.
285285

286286
First, let’s take the example account we created before and deploy it:
287287

288-
```[,cairo]
288+
```rust
289289
#[starknet::contract(account)]
290290
mod MyAccount {
291291
use openzeppelin_account::AccountComponent;
@@ -333,7 +333,7 @@ The flag enables custom account variants.
333333
The following examples use `sncast` [v0.23.0](https://github.com/foundry-rs/starknet-foundry/releases/tag/v0.23.0).
334334
</Callout>
335335

336-
```[,bash]
336+
```bash
337337
$ sncast \
338338
--url http://127.0.0.1:5050 \
339339
account create \
@@ -344,7 +344,7 @@ $ sncast \
344344
This command will output the precomputed contract address and the recommended `max-fee`.
345345
To counterfactually deploy the account, send funds to the address and then deploy the custom account.
346346

347-
```[,bash]
347+
```bash
348348
$ sncast \
349349
--url http://127.0.0.1:5050 \
350350
account deploy \
@@ -353,7 +353,7 @@ $ sncast \
353353

354354
Once the account is deployed, set the `--account` flag with the custom account name to send transactions from that account.
355355

356-
```[,bash]
356+
```bash
357357
$ sncast \
358358
--account my-custom-account \
359359
--url http://127.0.0.1:5050 \
@@ -367,7 +367,7 @@ $ sncast \
367367

368368
First, let’s take the example account we created before and deploy it:
369369

370-
```[,cairo]
370+
```rust
371371
#[starknet::contract(account)]
372372
mod MyEthAccount {
373373
use openzeppelin_account::EthAccountComponent;
@@ -417,7 +417,7 @@ Next, precompute the EthAccount contract address using the declared class hash.
417417
The following examples use unreleased features from StarknetJS (`starknetjs@next`) at commit [d002baea0abc1de3ac6e87a671f3dec3757437b3](https://github.com/starknet-io/starknet.js/commit/d002baea0abc1de3ac6e87a671f3dec3757437b3).
418418
</Callout>
419419

420-
```[,javascript]
420+
```javascript
421421
import * as dotenv from 'dotenv';
422422
import { CallData, EthSigner, hash } from 'starknet';
423423
import { ABI as ETH_ABI } from '../abis/eth_account.js';
@@ -443,7 +443,7 @@ console.log('Pre-calculated EthAccount address: ', ethContractAddress);
443443

444444
Send funds to the pre-calculated EthAccount address and deploy the contract.
445445

446-
```[,javascript]
446+
```javascript
447447
import * as dotenv from 'dotenv';
448448
import { Account, CallData, EthSigner, RpcProvider, stark } from 'starknet';
449449
import { ABI as ETH_ABI } from '../abis/eth_account.js';
@@ -479,7 +479,7 @@ console.log('EthAccount deployed at: ', contract_address);
479479
Once deployed, connect the EthAccount instance to the target contract which enables calls to come from the EthAccount.
480480
Here’s what an ERC20 transfer from an EthAccount looks like.
481481

482-
```[,javascript]
482+
```javascript
483483
import * as dotenv from 'dotenv';
484484
import { Account, RpcProvider, Contract, EthSigner } from 'starknet';
485485
dotenv.config();

content/contracts-cairo/1.0.0/erc1155.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ mod MyERC1155 {
7979
The following interface represents the full ABI of the Contracts for Cairo [ERC1155Component](/api/erc1155#ERC1155Component).
8080
The interface includes the [IERC1155](/api/erc1155#IERC1155) standard interface and the optional [IERC1155MetadataURI](/api/erc1155#IERC1155MetadataURI) interface together with [ISRC5](/api/introspection#ISRC5).
8181

82-
To support older token deployments, as mentioned in [Dual interfaces](interfaces#dual_interfaces), the component also includes implementations of the interface written in camelCase.
82+
To support older token deployments, as mentioned in [Dual interfaces](guides/interfaces-and-dispatchers#dual-interfaces), the component also includes implementations of the interface written in camelCase.
8383

8484
```cairo
8585
#[starknet::interface]
@@ -156,7 +156,7 @@ In the spirit of the standard, we’ve also included batch operations in the non
156156
<Callout type='warn'>
157157
While [safe_transfer_from](/api/erc1155#IERC1155-safe_transfer_from) and [safe_batch_transfer_from](/api/erc1155#IERC1155-safe_batch_transfer_from) prevent loss by checking the receiver can handle the
158158
</Callout>
159-
tokens, this yields execution to the receiver which can result in a [reentrant call](security#reentrancy_guard).
159+
tokens, this yields execution to the receiver which can result in a [reentrant call](security#reentrancy-guard).
160160

161161
## Receiving tokens
162162

@@ -190,7 +190,7 @@ When [safe_transfer_from](/api/erc1155#IERC1155-safe_transfer_from) and [safe_ba
190190
Otherwise, the transaction will fail.
191191

192192
<Callout>
193-
For information on how to calculate interface IDs, see [Computing the interface ID](introspection#computing_the_interface_id).
193+
For information on how to calculate interface IDs, see [Computing the interface ID](introspection#computing-the-interface-id).
194194
</Callout>
195195

196196
### Creating a token receiver contract

content/contracts-cairo/1.0.0/erc20.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ For a more complete guide on ERC20 token mechanisms, see [Creating ERC20 Supply]
7171
The following interface represents the full ABI of the Contracts for Cairo [ERC20Component](/api/erc20#ERC20Component).
7272
The interface includes the [IERC20](/api/erc20#IERC20) standard interface as well as the optional [IERC20Metadata](/api/erc20#IERC20Metadata).
7373

74-
To support older token deployments, as mentioned in [Dual interfaces](/interfaces#dual_interfaces), the component also includes an implementation of the interface written in camelCase.
74+
To support older token deployments, as mentioned in [Dual interfaces](/guides/interfaces-and-dispatchers#dual-interfaces), the component also includes an implementation of the interface written in camelCase.
7575

7676
```cairo
7777
#[starknet::interface]
@@ -106,7 +106,7 @@ Although Starknet is not EVM compatible, this component aims to be as close as p
106106
Some notable differences, however, can still be found, such as:
107107

108108
* The `ByteArray` type is used to represent strings in Cairo.
109-
* The component offers a [dual interface](/interfaces#dual_interfaces) which supports both snake_case and camelCase methods, as opposed to just camelCase in Solidity.
109+
* The component offers a [dual interface](/guides/interfaces-and-dispatchers#dual-interfaces) which supports both snake_case and camelCase methods, as opposed to just camelCase in Solidity.
110110
* `transfer`, `transfer_from` and `approve` will never return anything different from `true` because they will revert on any error.
111111
* Function selectors are calculated differently between [Cairo](https://github.com/starkware-libs/cairo/blob/7dd34f6c57b7baf5cd5a30c15e00af39cb26f7e1/crates/cairo-lang-starknet/src/contract.rs#L39-L48) and [Solidity](https://solidity-by-example.org/function-selector/).
112112

content/contracts-cairo/1.0.0/erc721.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ mod MyNFT {
6464
The following interface represents the full ABI of the Contracts for Cairo [ERC721Component](/api/erc721#ERC721Component).
6565
The interface includes the [IERC721](/api/erc721#IERC721) standard interface and the optional [IERC721Metadata](/api/erc721#IERC721Metadata) interface.
6666

67-
To support older token deployments, as mentioned in [Dual interfaces](interfaces#dual_interfaces), the component also includes implementations of the interface written in camelCase.
67+
To support older token deployments, as mentioned in [Dual interfaces](guides/interfaces-and-dispatchers#dual-interfaces), the component also includes implementations of the interface written in camelCase.
6868

6969
```cairo
7070
#[starknet::interface]
@@ -158,7 +158,7 @@ When safe methods such as [safe_transfer_from](api/erc721#IERC721-safe_transfer_
158158
Otherwise, the transaction will fail.
159159

160160
<Callout>
161-
For information on how to calculate interface IDs, see [Computing the interface ID](introspection#computing_the_interface_id).
161+
For information on how to calculate interface IDs, see [Computing the interface ID](introspection#computing-the-interface-id).
162162
</Callout>
163163

164164
### Creating a token receiver contract

content/contracts-cairo/1.0.0/guides/deployment.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Note that the `class_hash` must be previously declared for the deployment to suc
1818
2. Send funds to the `contract_address`. Usually you will estimate the fee of the transaction first. Existing
1919
tools usually do this for you.
2020
3. Send a `DeployAccount` type transaction to the network.
21-
4. The protocol will then validate the transaction with the `\\__validate_deploy__` entrypoint of the contract to be deployed.
21+
4. The protocol will then validate the transaction with the `__validate_deploy__` entrypoint of the contract to be deployed.
2222
5. If the validation succeeds, the protocol will charge the fee and then register the contract as deployed.
2323

2424
<Callout>
@@ -27,7 +27,7 @@ Although this method is very popular to deploy accounts, this works for any kind
2727

2828
## Deployment validation
2929

30-
To be counterfactually deployed, the deploying contract must implement the `\\__validate_deploy__` entrypoint,
30+
To be counterfactually deployed, the deploying contract must implement the `__validate_deploy__` entrypoint,
3131
called by the protocol when a `DeployAccount` transaction is sent to the network.
3232

3333
```cairo

content/contracts-cairo/1.0.0/upgrades.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Upgrades
44

55
In different blockchains, multiple patterns have been developed for making a contract upgradeable including the widely adopted proxy patterns.
66

7-
Starknet has native upgradeability through a syscall that updates the contract source code, removing [the need for proxies](#proxies_in_starknet).
7+
Starknet has native upgradeability through a syscall that updates the contract source code, removing [the need for proxies](#proxies-in-starknet).
88

99
<Callout type='warn'>
1010
Make sure you follow [our security recommendations](#security) before upgrading.
@@ -39,7 +39,7 @@ OpenZeppelin Contracts for Cairo provides [Upgradeable](https://github.com/OpenZ
3939
### Usage
4040

4141
Upgrades are often very sensitive operations, and some form of access control is usually required to
42-
avoid unauthorized upgrades. The [Ownable](access#ownership_and_ownable) module is used in this example.
42+
avoid unauthorized upgrades. The [Ownable](access#ownership-and-ownable) module is used in this example.
4343

4444
<Callout>
4545
We will be using the following module to implement the [IUpgradeable](api/upgrades#IUpgradeable) interface described in the API Reference section.

content/contracts-cairo/1.0.0/utils/_class_hashes.mdx

Lines changed: 0 additions & 4 deletions
This file was deleted.

content/contracts-cairo/1.0.0/utils/_common.mdx

Lines changed: 0 additions & 4 deletions
This file was deleted.

content/contracts-cairo/2.0.0/accounts.mdx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ interoperability with the ecosystem.
8080
The Starknet protocol uses a few entrypoints for abstracting the accounts. We already mentioned the first two
8181
as part of the ISRC6 interface, and both are required for enabling accounts to be used for executing transactions. The rest are optional:
8282

83-
1. `\\__validate__` verifies the validity of the transaction to be executed. This is usually used to validate signatures,
83+
1. `__validate__` verifies the validity of the transaction to be executed. This is usually used to validate signatures,
8484
but the entrypoint implementation can be customized to feature any validation mechanism [with some limitations](https://docs.starknet.io/architecture-and-concepts/accounts/account-functions/#limitations_of_validation).
85-
2. `\\__execute__` executes the transaction if the validation is successful.
86-
3. `\\__validate_declare__` optional entrypoint similar to `\\__validate__` but for transactions
85+
2. `__execute__` executes the transaction if the validation is successful.
86+
3. `__validate_declare__` optional entrypoint similar to `__validate__` but for transactions
8787
meant to declare other contracts.
88-
4. `\\__validate_deploy__` optional entrypoint similar to `\\__validate__` but meant for [counterfactual deployments](/guides/deployment).
88+
4. `__validate_deploy__` optional entrypoint similar to `__validate__` but meant for [counterfactual deployments](/guides/deployment).
8989

9090
<Callout>
9191
Although these entrypoints are available to the protocol for its regular transaction flow, they can also be called like any other method.
@@ -275,7 +275,7 @@ wraps and exposes the `deploy_syscall` to provide arbitrary deployments through
275275
But if you don’t have an account to invoke it, you will probably want to use the latter.
276276

277277
To do counterfactual deployments, you need to implement another protocol-level entrypoint named
278-
`\\__validate_deploy__`. Check the [counterfactual deployments](/guides/deployment) guide to learn how.
278+
`__validate_deploy__`. Check the [counterfactual deployments](/guides/deployment) guide to learn how.
279279

280280
## Sending transactions
281281

@@ -285,7 +285,7 @@ Let’s now explore how to send transactions through these accounts.
285285

286286
First, let’s take the example account we created before and deploy it:
287287

288-
```[,cairo]
288+
```rust
289289
#[starknet::contract(account)]
290290
mod MyAccount {
291291
use openzeppelin_account::AccountComponent;
@@ -333,7 +333,7 @@ The flag enables custom account variants.
333333
The following examples use `sncast` [v0.23.0](https://github.com/foundry-rs/starknet-foundry/releases/tag/v0.23.0).
334334
</Callout>
335335

336-
```[,bash]
336+
```bash
337337
$ sncast \
338338
--url http://127.0.0.1:5050 \
339339
account create \
@@ -344,7 +344,7 @@ $ sncast \
344344
This command will output the precomputed contract address and the recommended `max-fee`.
345345
To counterfactually deploy the account, send funds to the address and then deploy the custom account.
346346

347-
```[,bash]
347+
```bash
348348
$ sncast \
349349
--url http://127.0.0.1:5050 \
350350
account deploy \
@@ -353,7 +353,7 @@ $ sncast \
353353

354354
Once the account is deployed, set the `--account` flag with the custom account name to send transactions from that account.
355355

356-
```[,bash]
356+
```bash
357357
$ sncast \
358358
--account my-custom-account \
359359
--url http://127.0.0.1:5050 \
@@ -367,7 +367,7 @@ $ sncast \
367367

368368
First, let’s take the example account we created before and deploy it:
369369

370-
```[,cairo]
370+
```rust
371371
#[starknet::contract(account)]
372372
mod MyEthAccount {
373373
use openzeppelin_account::EthAccountComponent;
@@ -417,7 +417,7 @@ Next, precompute the EthAccount contract address using the declared class hash.
417417
The following examples use unreleased features from StarknetJS (`starknetjs@next`) at commit [d002baea0abc1de3ac6e87a671f3dec3757437b3](https://github.com/starknet-io/starknet.js/commit/d002baea0abc1de3ac6e87a671f3dec3757437b3).
418418
</Callout>
419419

420-
```[,javascript]
420+
```javascript
421421
import * as dotenv from 'dotenv';
422422
import { CallData, EthSigner, hash } from 'starknet';
423423
import { ABI as ETH_ABI } from '../abis/eth_account.js';
@@ -443,7 +443,7 @@ console.log('Pre-calculated EthAccount address: ', ethContractAddress);
443443

444444
Send funds to the pre-calculated EthAccount address and deploy the contract.
445445

446-
```[,javascript]
446+
```javascript
447447
import * as dotenv from 'dotenv';
448448
import { Account, CallData, EthSigner, RpcProvider, stark } from 'starknet';
449449
import { ABI as ETH_ABI } from '../abis/eth_account.js';
@@ -479,7 +479,7 @@ console.log('EthAccount deployed at: ', contract_address);
479479
Once deployed, connect the EthAccount instance to the target contract which enables calls to come from the EthAccount.
480480
Here’s what an ERC20 transfer from an EthAccount looks like.
481481

482-
```[,javascript]
482+
```javascript
483483
import * as dotenv from 'dotenv';
484484
import { Account, RpcProvider, Contract, EthSigner } from 'starknet';
485485
dotenv.config();

0 commit comments

Comments
 (0)