Skip to content
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
175e032
Introduce set-macros module
immrsd Oct 22, 2025
6a8a245
Support with_components macro in contract builder and pring logic
immrsd Oct 22, 2025
36f4ed1
Update contracts generators
immrsd Oct 22, 2025
1a4541d
Support macros in Vesting
immrsd Oct 22, 2025
6b4caed
Support macros in set-upgradeable
immrsd Oct 22, 2025
527ae44
Support macros in set-royalty-info
immrsd Oct 22, 2025
05e440a
Support macros in set-access-control
immrsd Oct 22, 2025
0c2c473
Support macros in Multisig
immrsd Oct 22, 2025
67f64fd
Support macros in Governor
immrsd Oct 22, 2025
e1eb066
Support macros in ERC721
immrsd Oct 22, 2025
df39503
Support macros in ERC20
immrsd Oct 22, 2025
062b79d
Support macros in ERC1155
immrsd Oct 22, 2025
8082ccd
Support macros in Custom contract
immrsd Oct 22, 2025
4df5fa8
Support macros in add-pausable
immrsd Oct 22, 2025
6100d0b
Support macros in common-options
immrsd Oct 22, 2025
88f14bd
Support macros in tests
immrsd Oct 22, 2025
a517606
Migrate Cairo-alpha test project to standalone OZ packages
immrsd Oct 22, 2025
b3dee92
Update Cairo-alpha test project generator script
immrsd Oct 22, 2025
bbb4381
Support macros subset option in Cairo-alpha CI workflow
immrsd Oct 22, 2025
ccbc8fd
Add UI control for macros section
immrsd Oct 22, 2025
a0f6bd0
Intergrate macros UI section into all UI controls
immrsd Oct 22, 2025
c16419c
Support macros in App.svelte
immrsd Oct 22, 2025
2f369ab
Remove explicit copying of macros defaults obj
immrsd Oct 22, 2025
099132d
Add changelog entry
immrsd Oct 22, 2025
ac9523d
Add check to printing logic
immrsd Oct 22, 2025
e9957ff
Add additional alias values for macros CLI params
immrsd Oct 22, 2025
40efd2f
Fix comments in UI controls
immrsd Oct 22, 2025
b230314
Update Cairo-alpha test snapshots
immrsd Oct 22, 2025
a1b5752
Make macros disabled by default
immrsd Oct 22, 2025
686f807
Support passing macros options to contract generators
immrsd Oct 22, 2025
72e01ad
Update vesting test snapshots
immrsd Oct 22, 2025
74d632b
Run formatter
immrsd Oct 22, 2025
69b9eea
Merge master
immrsd Oct 29, 2025
9f3a468
Fix empty enum struct issue
immrsd Oct 29, 2025
aa68391
Add function definitions for macro in Cairo-alpha
immrsd Oct 29, 2025
42ffcbb
Add macros to Cairo-alpha function definitions for AI
immrsd Oct 29, 2025
94decc2
Move Cairo-alpha tests to "with_components_off" folder, put into subf…
immrsd Oct 29, 2025
7934af3
Add ava setting for snapshot files location, remove wrongfully genera…
immrsd Oct 29, 2025
99bd314
Update test file refs for with_components_off tests
immrsd Oct 29, 2025
a025a4e
Add test cases for Account when with_components macro is enabled
immrsd Oct 29, 2025
bc3b0b8
Duplicate tests for when with_components macro is enabled
immrsd Oct 29, 2025
5c9079c
Remove with_components enabled tests for Foo contract & component
immrsd Oct 29, 2025
99af405
Fix issue with empty "with_components"
immrsd Oct 29, 2025
4413f8e
Update ERC20 tests for enabled with_components
immrsd Oct 29, 2025
c06129e
Update ERC721 tests for enabled with_components
immrsd Oct 29, 2025
e47aaf8
Update ERC1155 tests for enabled with_components
immrsd Oct 29, 2025
dc2c78d
Update Governor tests for enabled with_components
immrsd Oct 29, 2025
927ff08
Update Multisig tests for enabled with_components
immrsd Oct 29, 2025
8b33efe
Update Vesting tests for enabled with_components
immrsd Oct 29, 2025
97a6b27
Lint files
immrsd Oct 29, 2025
a567b73
Fix Cairo-alpha test project workflow code
immrsd Oct 29, 2025
756d6bb
Add changeset
immrsd Oct 29, 2025
71842f9
Fix namespace issues after merge
immrsd Oct 29, 2025
5402c8f
Improve tooltip text in MacrosSection component
immrsd Oct 29, 2025
8f323b0
Add help tooltip to macros section
immrsd Oct 29, 2025
6ab91db
Update Cairo-alpha snapshots
immrsd Oct 29, 2025
edcb68e
Fix changelog entry
immrsd Nov 1, 2025
08e8df6
Merge master
immrsd Nov 1, 2025
5fcd5b5
Merge master
immrsd Nov 4, 2025
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
5 changes: 5 additions & 0 deletions .changeset/mean-shoes-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openzeppelin/wizard-common': patch
---

Add macros descriptions for Cairo-alpha
54 changes: 28 additions & 26 deletions .github/workflows/compile-cairo-alpha-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,50 +47,52 @@ jobs:
set -e
declare -a all_kinds=("ERC20" "ERC721" "ERC1155" "Account" "Multisig" "Governor" "Vesting" "Custom")
declare -a all_macros_options=("none" "with_components")
declare -a all_access_options=("disabled" "ownable" "roles" "roles-dar-default" "roles-dar-custom")
declare -a all_royalty_options=("disabled" "enabled-default" "enabled-custom")
for kind in "${all_kinds[@]}"; do
scarb clean
if [[ "$kind" == "ERC721" || "$kind" == "ERC1155" ]]; then
for access_option in "${all_access_options[@]}"; do
for royalty_option in "${all_royalty_options[@]}"; do
proj_name="'$kind, access: $access_option, royalty: $royalty_option' test project"
for macros_option in "${all_macros_options[@]}"; do
for kind in "${all_kinds[@]}"; do
if [[ "$kind" == "ERC721" || "$kind" == "ERC1155" ]]; then
for access_option in "${all_access_options[@]}"; do
for royalty_option in "${all_royalty_options[@]}"; do
proj_name="'$kind, macros: $macros_option, access: $access_option, royalty: $royalty_option' test project"
echo "Generating $proj_name..."
yarn run update_scarb_project --kind=$kind --macros=$macros_option --access=$access_option --royalty=$royalty_option
echo "Compiling $proj_name..."
scarb build
echo "✅ Compiled $proj_name!"
echo "---------------------------------"
done
done
elif [[ "$kind" == "ERC20" || "$kind" == "Custom" ]]; then
for access_option in "${all_access_options[@]}"; do
proj_name="'$kind, access: $access_option' test project"
echo "Generating $proj_name..."
yarn run update_scarb_project --kind=$kind --access=$access_option --royalty=$royalty_option
yarn run update_scarb_project --kind=$kind --access=$access_option
echo "Compiling $proj_name..."
scarb build
echo "✅ Compiled $proj_name!"
echo "---------------------------------"
done
done
elif [[ "$kind" == "ERC20" || "$kind" == "Custom" ]]; then
for access_option in "${all_access_options[@]}"; do
proj_name="'$kind, access: $access_option' test project"
else
proj_name="'$kind' test project"
echo "Generating $proj_name..."
yarn run update_scarb_project --kind=$kind --access=$access_option
yarn run update_scarb_project --kind=$kind
echo "Compiling $proj_name..."
scarb build
echo "✅ Compiled $proj_name!"
echo "---------------------------------"
done
else
proj_name="'$kind' test project"
echo "Generating $proj_name..."
yarn run update_scarb_project --kind=$kind
echo "Compiling $proj_name..."
scarb build
echo "✅ Compiled $proj_name!"
echo "---------------------------------"
fi
fi
done
done
5 changes: 5 additions & 0 deletions packages/common/src/ai/descriptions/cairo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export const cairoCommonDescriptions = {
'Provides information for how much royalty is owed and to whom, based on a sale price. Follows ERC-2981 standard.',
};

export const cairoMacrosDescriptions = {
macros: 'The macros to use for the contract.',
withComponents: 'Whether to use the "with_components" macro for simplified contract structure.',
};

export const cairoAlphaAccessDescriptions = {
accessType:
'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.',
Expand Down
1 change: 1 addition & 0 deletions packages/core/cairo_alpha/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Add support for `with_components` macro. ([#703](https://github.com/OpenZeppelin/contracts-wizard/pull/703))
- Add AccessControlDefaultAdminRules. ([#698](https://github.com/OpenZeppelin/contracts-wizard/pull/698))

- **Breaking changes**:
Expand Down
1 change: 1 addition & 0 deletions packages/core/cairo_alpha/ava.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
watchmode: {
ignoreChanges: ['contracts', 'artifacts', 'cache'],
},
snapshotDir: '.',
timeout: '10m',
workerThreads: false,
};
Binary file removed packages/core/cairo_alpha/src/account.test.ts.snap
Binary file not shown.
21 changes: 14 additions & 7 deletions packages/core/cairo_alpha/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const defaults: Required<AccountOptions> = {
outsideExecution: true,
upgradeable: commonDefaults.upgradeable,
info: commonDefaults.info,
macros: commonDefaults.macros,
} as const;

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

export function buildAccount(opts: AccountOptions): Contract {
const isAccount = true;
const c = new ContractBuilder(opts.name, isAccount);

const allOpts = withDefaults(opts);
const c = new ContractBuilder(allOpts.name, allOpts.macros, isAccount);

switch (allOpts.type) {
case 'stark':
c.addConstructorArgument({ name: 'public_key', type: 'felt252' });
c.addComponent(components.AccountComponent, [{ lit: 'public_key' }], true);
break;
case 'eth':
c.addUseClause('openzeppelin::interfaces::accounts', 'EthPublicKey');
c.addUseClause('openzeppelin_interfaces::accounts', 'EthPublicKey');
c.addConstructorArgument({ name: 'public_key', type: 'EthPublicKey' });
c.addComponent(components.EthAccountComponent, [{ lit: 'public_key' }], true);
break;
Expand Down Expand Up @@ -98,10 +98,12 @@ function addSRC6(c: ContractBuilder, accountType: Account) {

c.addImplToComponent(componentType, {
name: 'SRC6Impl',
embed: true,
value: `${baseComponent}::SRC6Impl<ContractState>`,
});
c.addImplToComponent(componentType, {
name: 'SRC6CamelOnlyImpl',
embed: true,
value: `${baseComponent}::SRC6CamelOnlyImpl<ContractState>`,
});

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

c.addImplToComponent(componentType, {
name: 'DeclarerImpl',
embed: true,
value: `${baseComponent}::DeclarerImpl<ContractState>`,
});
}
Expand All @@ -122,6 +125,7 @@ function addDeployer(c: ContractBuilder, accountType: Account) {

c.addImplToComponent(componentType, {
name: 'DeployableImpl',
embed: true,
value: `${baseComponent}::DeployableImpl<ContractState>`,
});
}
Expand All @@ -131,16 +135,17 @@ function addPublicKey(c: ContractBuilder, accountType: Account) {

c.addImplToComponent(componentType, {
name: 'PublicKeyImpl',
embed: true,
value: `${baseComponent}::PublicKeyImpl<ContractState>`,
});
c.addImplToComponent(componentType, {
name: 'PublicKeyCamelImpl',
embed: true,
value: `${baseComponent}::PublicKeyCamelImpl<ContractState>`,
});
}

function addOutsideExecution(c: ContractBuilder) {
c.addUseClause('openzeppelin::account::extensions', 'SRC9Component');
c.addComponent(components.SRC9Component, [], true);
}

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

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

const components = defineComponents({
AccountComponent: {
path: 'openzeppelin::account',
path: 'openzeppelin_account',
substorage: {
name: 'account',
type: 'AccountComponent::Storage',
Expand All @@ -185,7 +191,7 @@ const components = defineComponents({
],
},
EthAccountComponent: {
path: 'openzeppelin::account::eth_account',
path: 'openzeppelin_account::eth_account',
substorage: {
name: 'eth_account',
type: 'EthAccountComponent::Storage',
Expand All @@ -203,7 +209,7 @@ const components = defineComponents({
],
},
SRC9Component: {
path: 'openzeppelin::account::extensions',
path: 'openzeppelin_account::extensions',
substorage: {
name: 'src9',
type: 'SRC9Component::Storage',
Expand All @@ -215,6 +221,7 @@ const components = defineComponents({
impls: [
{
name: 'OutsideExecutionV2Impl',
embed: true,
value: 'SRC9Component::OutsideExecutionV2Impl<ContractState>',
},
{
Expand Down
3 changes: 2 additions & 1 deletion packages/core/cairo_alpha/src/add-pausable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function addPausable(c: ContractBuilder, access: Access) {

const components = defineComponents({
PausableComponent: {
path: 'openzeppelin::security::pausable',
path: 'openzeppelin_security::pausable',
substorage: {
name: 'pausable',
type: 'PausableComponent::Storage',
Expand All @@ -29,6 +29,7 @@ const components = defineComponents({
impls: [
{
name: 'PausableImpl',
embed: true,
value: 'PausableComponent::PausableImpl<ContractState>',
},
{
Expand Down
13 changes: 8 additions & 5 deletions packages/core/cairo_alpha/src/common-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type Token = (typeof tokenTypes)[number];

const components = defineComponents({
SRC5Component: {
path: 'openzeppelin::introspection::src5',
path: 'openzeppelin_introspection::src5',
substorage: {
name: 'src5',
type: 'SRC5Component::Storage',
Expand All @@ -19,7 +19,7 @@ const components = defineComponents({
},

VotesComponent: {
path: 'openzeppelin::governance::votes',
path: 'openzeppelin_governance::votes',
substorage: {
name: 'votes',
type: 'VotesComponent::Storage',
Expand All @@ -38,7 +38,7 @@ const components = defineComponents({
},

NoncesComponent: {
path: 'openzeppelin::utils::cryptography::nonces',
path: 'openzeppelin_utils::cryptography::nonces',
substorage: {
name: 'nonces',
type: 'NoncesComponent::Storage',
Expand All @@ -50,6 +50,7 @@ const components = defineComponents({
impls: [
{
name: 'NoncesImpl',
embed: true,
value: 'NoncesComponent::NoncesImpl<ContractState>',
},
],
Expand All @@ -62,6 +63,7 @@ export function addSRC5Component(c: ContractBuilder, section?: string) {
if (!c.interfaceFlags.has('ISRC5')) {
c.addImplToComponent(components.SRC5Component, {
name: 'SRC5Impl',
embed: true,
value: 'SRC5Component::SRC5Impl<ContractState>',
section,
});
Expand All @@ -75,13 +77,14 @@ export function addVotesComponent(c: ContractBuilder, name: string, version: str
c.addComponent(components.VotesComponent, [], false);
c.addImplToComponent(components.VotesComponent, {
name: 'VotesImpl',
embed: true,
value: `VotesComponent::VotesImpl<ContractState>`,
});
c.addUseClause('openzeppelin::utils::contract_clock', 'ERC6372TimestampClock');
c.addUseClause('openzeppelin_utils::contract_clock', 'ERC6372TimestampClock');
}

export function addSNIP12Metadata(c: ContractBuilder, name: string, version: string, section?: string) {
c.addUseClause('openzeppelin::utils::cryptography::snip12', 'SNIP12Metadata');
c.addUseClause('openzeppelin_utils::cryptography::snip12', 'SNIP12Metadata');

const SNIP12Metadata: BaseImplementedTrait = {
name: 'SNIP12MetadataImpl',
Expand Down
5 changes: 5 additions & 0 deletions packages/core/cairo_alpha/src/common-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import { AccessControl } from './set-access-control';
import type { Info } from './set-info';
import { defaults as infoDefaults } from './set-info';
import type { Upgradeable } from './set-upgradeable';
import type { MacrosOptions } from './set-macros';
import { defaults as macrosDefaults } from './set-macros';

export const defaults: Required<CommonOptions> = {
upgradeable: true,
info: infoDefaults,
macros: macrosDefaults,
} as const;

export const contractDefaults: Required<CommonContractOptions> = {
Expand All @@ -18,6 +21,7 @@ export const contractDefaults: Required<CommonContractOptions> = {
export interface CommonOptions {
upgradeable?: Upgradeable;
info?: Info;
macros?: MacrosOptions;
}

export interface CommonContractOptions extends CommonOptions {
Expand All @@ -28,6 +32,7 @@ export function withCommonDefaults(opts: CommonOptions): Required<CommonOptions>
return {
upgradeable: opts.upgradeable ?? defaults.upgradeable,
info: opts.info ?? defaults.info,
macros: opts.macros ?? defaults.macros,
};
}

Expand Down
Binary file removed packages/core/cairo_alpha/src/contract.test.ts.snap
Binary file not shown.
12 changes: 9 additions & 3 deletions packages/core/cairo_alpha/src/contract.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { toIdentifier } from './utils/convert-strings';
import type { MacrosOptions } from './set-macros';

export interface Contract {
license: string;
documentations: string[];
name: string;
macros: MacrosOptions;
account: boolean;
useClauses: UseClause[];
components: Component[];
Expand Down Expand Up @@ -46,7 +48,7 @@ export interface Event {
export interface Impl {
name: string;
value: string;
embed?: boolean;
embed: boolean;
section?: string;
}

Expand Down Expand Up @@ -100,6 +102,7 @@ export interface Argument {

export class ContractBuilder implements Contract {
readonly name: string;
readonly macros: MacrosOptions;
readonly account: boolean;
license = 'MIT';
upgradeable = false;
Expand All @@ -116,8 +119,9 @@ export class ContractBuilder implements Contract {
private useClausesMap: Map<string, UseClause> = new Map();
private interfaceFlagsSet: Set<string> = new Set();

constructor(name: string, account: boolean = false) {
constructor(name: string, macros: MacrosOptions, account: boolean = false) {
this.name = toIdentifier(name, true);
this.macros = macros;
this.account = account;
}

Expand Down Expand Up @@ -165,7 +169,9 @@ export class ContractBuilder implements Contract {
}

addComponent(component: Component, params: Value[] = [], initializable: boolean = true): boolean {
this.addUseClause(component.path, component.name);
if (!this.macros.withComponents) {
this.addUseClause(component.path, component.name);
}
const key = component.name;
const present = this.componentsMap.has(key);
if (!present) {
Expand Down
Binary file removed packages/core/cairo_alpha/src/custom.test.ts.snap
Binary file not shown.
Loading
Loading