Skip to content

Commit 53c042a

Browse files
immrsdericglau
andauthored
Cairo: support v3.0.0 (#757)
Co-authored-by: Eric Lau <ericglau@outlook.com>
1 parent c2ef626 commit 53c042a

File tree

186 files changed

+18480
-3465
lines changed

Some content is hidden

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

186 files changed

+18480
-3465
lines changed

.changeset/brown-bugs-start.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@openzeppelin/wizard-cairo': major
3+
'@openzeppelin/contracts-mcp': minor
4+
'@openzeppelin/wizard-common': minor
5+
---
6+
7+
- Add support for `with_components` macro. ([#703](https://github.com/OpenZeppelin/contracts-wizard/pull/703))
8+
- Add AccessControlDefaultAdminRules. ([#698](https://github.com/OpenZeppelin/contracts-wizard/pull/698))
9+
10+
- **Breaking changes**:
11+
- Use OpenZeppelin Contracts for Cairo v3.0.0. ([#757](https://github.com/OpenZeppelin/contracts-wizard/pull/757))
12+
- Use OpenZeppelin Contracts for Cairo v3.0.0-alpha.3. ([#688](https://github.com/OpenZeppelin/contracts-wizard/pull/688))
13+
- Use OpenZeppelin Contracts for Cairo v3.0.0-alpha.2. ([#663](https://github.com/OpenZeppelin/contracts-wizard/pull/663))
14+
- Use OpenZeppelin Contracts for Cairo v3.0.0-alpha.1. ([#638](https://github.com/OpenZeppelin/contracts-wizard/pull/638))
15+
- Use OpenZeppelin Contracts for Cairo v3.0.0-alpha.0. ([#623](https://github.com/OpenZeppelin/contracts-wizard/pull/623))

.github/workflows/compile-cairo-alpha-project.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
yarn run update_scarb_project --kind=$kind --macros=$macros_option --access=$access_option --royalty=$royalty_option
6262
6363
echo "Compiling $proj_name..."
64+
scarb clean
6465
scarb build
6566
6667
echo "✅ Compiled $proj_name!"
@@ -70,24 +71,26 @@ jobs:
7071
7172
elif [[ "$kind" == "ERC20" || "$kind" == "Custom" ]]; then
7273
for access_option in "${all_access_options[@]}"; do
73-
proj_name="'$kind, access: $access_option' test project"
74+
proj_name="'$kind, macros: $macros_option, access: $access_option' test project"
7475
echo "Generating $proj_name..."
75-
yarn run update_scarb_project --kind=$kind --access=$access_option
76+
yarn run update_scarb_project --kind=$kind --macros=$macros_option --access=$access_option
7677
7778
echo "Compiling $proj_name..."
79+
scarb clean
7880
scarb build
7981
8082
echo "✅ Compiled $proj_name!"
8183
echo "---------------------------------"
8284
done
8385
8486
else
85-
proj_name="'$kind' test project"
87+
proj_name="'$kind, macros: $macros_option' test project"
8688
8789
echo "Generating $proj_name..."
88-
yarn run update_scarb_project --kind=$kind
90+
yarn run update_scarb_project --kind=$kind --macros=$macros_option
8991
9092
echo "Compiling $proj_name..."
93+
scarb clean
9194
scarb build
9295
9396
echo "✅ Compiled $proj_name!"

.github/workflows/compile-cairo-project.yml

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,55 @@ jobs:
4747
set -e
4848
4949
declare -a all_kinds=("ERC20" "ERC721" "ERC1155" "Account" "Multisig" "Governor" "Vesting" "Custom")
50-
declare -a all_royalty_info_options=("disabled" "enabled_default" "enabled_custom")
51-
for kind in "${all_kinds[@]}"; do
52-
scarb clean
50+
declare -a all_macros_options=("none" "with_components")
51+
declare -a all_access_options=("disabled" "ownable" "roles" "roles-dar-default" "roles-dar-custom")
52+
declare -a all_royalty_options=("disabled" "enabled-default" "enabled-custom")
53+
54+
for macros_option in "${all_macros_options[@]}"; do
55+
for kind in "${all_kinds[@]}"; do
56+
if [[ "$kind" == "ERC721" || "$kind" == "ERC1155" ]]; then
57+
for access_option in "${all_access_options[@]}"; do
58+
for royalty_option in "${all_royalty_options[@]}"; do
59+
proj_name="'$kind, macros: $macros_option, access: $access_option, royalty: $royalty_option' test project"
60+
echo "Generating $proj_name..."
61+
yarn run update_scarb_project --kind=$kind --macros=$macros_option --access=$access_option --royalty=$royalty_option
62+
63+
echo "Compiling $proj_name..."
64+
scarb clean
65+
scarb build
66+
67+
echo "✅ Compiled $proj_name!"
68+
echo "---------------------------------"
69+
done
70+
done
71+
72+
elif [[ "$kind" == "ERC20" || "$kind" == "Custom" ]]; then
73+
for access_option in "${all_access_options[@]}"; do
74+
proj_name="'$kind, macros: $macros_option, access: $access_option' test project"
75+
echo "Generating $proj_name..."
76+
yarn run update_scarb_project --kind=$kind --macros=$macros_option --access=$access_option
77+
78+
echo "Compiling $proj_name..."
79+
scarb clean
80+
scarb build
81+
82+
echo "✅ Compiled $proj_name!"
83+
echo "---------------------------------"
84+
done
85+
86+
else
87+
proj_name="'$kind, macros: $macros_option' test project"
5388
54-
if [[ "$kind" == "ERC721" || "$kind" == "ERC1155" ]]; then
55-
for royalty_info_option in "${all_royalty_info_options[@]}"; do
56-
proj_name="'$kind (royalty info: $royalty_info_option)'' test project"
5789
echo "Generating $proj_name..."
58-
yarn run update_scarb_project $kind $royalty_info_option
90+
yarn run update_scarb_project --kind=$kind --macros=$macros_option
5991
6092
echo "Compiling $proj_name..."
93+
scarb clean
6194
scarb build
6295
6396
echo "✅ Compiled $proj_name!"
6497
echo "---------------------------------"
65-
done
66-
67-
else
68-
proj_name="'$kind' test project"
69-
70-
echo "Generating $proj_name..."
71-
yarn run update_scarb_project $kind
72-
73-
echo "Compiling $proj_name..."
74-
scarb build
75-
76-
echo "✅ Compiled $proj_name!"
77-
echo "---------------------------------"
78-
fi
98+
fi
99+
done
79100
80101
done

packages/common/src/ai/descriptions/cairo.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ export const cairoPrompts = {
1616
};
1717

1818
export const cairoCommonDescriptions = {
19-
access:
20-
'The type of access control to provision. Ownable is a simple mechanism with a single account authorized for all privileged actions. Roles is a flexible mechanism with a separate role for each privileged action. A role can have many authorized accounts.',
2119
upgradeable: 'Whether the smart contract is upgradeable.',
2220
appName:
2321
'Required when votes is enabled, for hashing and signing typed structured data. Name for domain separator implementing SNIP12Metadata trait. Prevents two applications from producing the same hash.',
@@ -32,12 +30,14 @@ export const cairoMacrosDescriptions = {
3230
withComponents: 'Whether to use the "with_components" macro for simplified contract structure.',
3331
};
3432

35-
export const cairoAlphaAccessDescriptions = {
33+
export const cairoAccessDescriptions = {
3634
accessType:
3735
'The type of access control to provision. Ownable is a simple mechanism with a single account authorized for all privileged actions. Roles is a flexible mechanism with a separate role for each privileged action. A role can have many authorized accounts. Roles (Default Admin Rules) provides additional enforced security measures on top of standard Roles mechanism for managing the most privileged role: default admin.',
3836
darInitialDelay: 'The initial delay for the default admin role (in case Roles (Default Admin Rules) is used).',
3937
darDefaultDelayIncrease:
40-
'The default delay increase for the default admin role (in case Roles (Default Admin Rules) is used).',
38+
'The default delay increase in seconds for the default admin role (in case Roles (Default Admin Rules) is used).',
39+
darMaxTransferDelay:
40+
'The maximum delay in seconds for a default admin transfer (in case Roles (Default Admin Rules) is used).',
4141
};
4242

4343
export const cairoRoyaltyInfoDescriptions = {

packages/core/cairo/CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Changelog
22

3-
43
## 2.1.0 (2025-09-16)
54

65
- Support decimals customization for ERC20 Cairo contracts ([#654](https://github.com/OpenZeppelin/contracts-wizard/pull/654))

packages/core/cairo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ The following contract types are supported:
1717
- `erc721`
1818
- `erc1155`
1919
- `account`
20-
- `governor`
2120
- `multisig`
21+
- `governor`
2222
- `vesting`
2323
- `custom`
2424

packages/core/cairo/ava.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = {
44
watchmode: {
55
ignoreChanges: ['contracts', 'artifacts', 'cache'],
66
},
7+
snapshotDir: '.',
78
timeout: '10m',
89
workerThreads: false,
910
};
-1.99 KB
Binary file not shown.

packages/core/cairo/src/account.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const defaults: Required<AccountOptions> = {
2121
outsideExecution: true,
2222
upgradeable: commonDefaults.upgradeable,
2323
info: commonDefaults.info,
24+
macros: commonDefaults.macros,
2425
} as const;
2526

2627
export function printAccount(opts: AccountOptions = defaults): string {
@@ -49,17 +50,16 @@ function withDefaults(opts: AccountOptions): Required<AccountOptions> {
4950

5051
export function buildAccount(opts: AccountOptions): Contract {
5152
const isAccount = true;
52-
const c = new ContractBuilder(opts.name, isAccount);
53-
5453
const allOpts = withDefaults(opts);
54+
const c = new ContractBuilder(allOpts.name, allOpts.macros, isAccount);
5555

5656
switch (allOpts.type) {
5757
case 'stark':
5858
c.addConstructorArgument({ name: 'public_key', type: 'felt252' });
5959
c.addComponent(components.AccountComponent, [{ lit: 'public_key' }], true);
6060
break;
6161
case 'eth':
62-
c.addUseClause('openzeppelin::account::interface', 'EthPublicKey');
62+
c.addUseClause('openzeppelin_interfaces::accounts', 'EthPublicKey');
6363
c.addConstructorArgument({ name: 'public_key', type: 'EthPublicKey' });
6464
c.addComponent(components.EthAccountComponent, [{ lit: 'public_key' }], true);
6565
break;
@@ -98,10 +98,12 @@ function addSRC6(c: ContractBuilder, accountType: Account) {
9898

9999
c.addImplToComponent(componentType, {
100100
name: 'SRC6Impl',
101+
embed: true,
101102
value: `${baseComponent}::SRC6Impl<ContractState>`,
102103
});
103104
c.addImplToComponent(componentType, {
104105
name: 'SRC6CamelOnlyImpl',
106+
embed: true,
105107
value: `${baseComponent}::SRC6CamelOnlyImpl<ContractState>`,
106108
});
107109

@@ -113,6 +115,7 @@ function addDeclarer(c: ContractBuilder, accountType: Account) {
113115

114116
c.addImplToComponent(componentType, {
115117
name: 'DeclarerImpl',
118+
embed: true,
116119
value: `${baseComponent}::DeclarerImpl<ContractState>`,
117120
});
118121
}
@@ -122,6 +125,7 @@ function addDeployer(c: ContractBuilder, accountType: Account) {
122125

123126
c.addImplToComponent(componentType, {
124127
name: 'DeployableImpl',
128+
embed: true,
125129
value: `${baseComponent}::DeployableImpl<ContractState>`,
126130
});
127131
}
@@ -131,16 +135,17 @@ function addPublicKey(c: ContractBuilder, accountType: Account) {
131135

132136
c.addImplToComponent(componentType, {
133137
name: 'PublicKeyImpl',
138+
embed: true,
134139
value: `${baseComponent}::PublicKeyImpl<ContractState>`,
135140
});
136141
c.addImplToComponent(componentType, {
137142
name: 'PublicKeyCamelImpl',
143+
embed: true,
138144
value: `${baseComponent}::PublicKeyCamelImpl<ContractState>`,
139145
});
140146
}
141147

142148
function addOutsideExecution(c: ContractBuilder) {
143-
c.addUseClause('openzeppelin::account::extensions', 'SRC9Component');
144149
c.addComponent(components.SRC9Component, [], true);
145150
}
146151

@@ -151,6 +156,7 @@ function addAccountMixin(c: ContractBuilder, accountType: Account) {
151156
c.addImplToComponent(componentType, {
152157
name: `${accountMixinImpl}`,
153158
value: `${baseComponent}::${accountMixinImpl}<ContractState>`,
159+
embed: true,
154160
});
155161

156162
c.addInterfaceFlag('ISRC5');
@@ -167,7 +173,7 @@ function getBaseCompAndCompType(accountType: Account): [string, typeof component
167173

168174
const components = defineComponents({
169175
AccountComponent: {
170-
path: 'openzeppelin::account',
176+
path: 'openzeppelin_account',
171177
substorage: {
172178
name: 'account',
173179
type: 'AccountComponent::Storage',
@@ -185,7 +191,7 @@ const components = defineComponents({
185191
],
186192
},
187193
EthAccountComponent: {
188-
path: 'openzeppelin::account::eth_account',
194+
path: 'openzeppelin_account::eth_account',
189195
substorage: {
190196
name: 'eth_account',
191197
type: 'EthAccountComponent::Storage',
@@ -203,7 +209,7 @@ const components = defineComponents({
203209
],
204210
},
205211
SRC9Component: {
206-
path: 'openzeppelin::account::extensions',
212+
path: 'openzeppelin_account::extensions',
207213
substorage: {
208214
name: 'src9',
209215
type: 'SRC9Component::Storage',
@@ -215,6 +221,7 @@ const components = defineComponents({
215221
impls: [
216222
{
217223
name: 'OutsideExecutionV2Impl',
224+
embed: true,
218225
value: 'SRC9Component::OutsideExecutionV2Impl<ContractState>',
219226
},
220227
{

packages/core/cairo/src/add-pausable.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function addPausable(c: ContractBuilder, access: Access) {
1717

1818
const components = defineComponents({
1919
PausableComponent: {
20-
path: 'openzeppelin::security::pausable',
20+
path: 'openzeppelin_security::pausable',
2121
substorage: {
2222
name: 'pausable',
2323
type: 'PausableComponent::Storage',
@@ -29,6 +29,7 @@ const components = defineComponents({
2929
impls: [
3030
{
3131
name: 'PausableImpl',
32+
embed: true,
3233
value: 'PausableComponent::PausableImpl<ContractState>',
3334
},
3435
{

0 commit comments

Comments
 (0)