Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .github/workflows/compile-cairo-alpha-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
yarn run update_scarb_project --kind=$kind --macros=$macros_option --access=$access_option --royalty=$royalty_option

echo "Compiling $proj_name..."
scarb clean
scarb build

echo "✅ Compiled $proj_name!"
Expand All @@ -75,6 +76,7 @@ jobs:
yarn run update_scarb_project --kind=$kind --access=$access_option

echo "Compiling $proj_name..."
scarb clean
scarb build

echo "✅ Compiled $proj_name!"
Expand All @@ -88,6 +90,7 @@ jobs:
yarn run update_scarb_project --kind=$kind

echo "Compiling $proj_name..."
scarb clean
scarb build

echo "✅ Compiled $proj_name!"
Expand Down
63 changes: 42 additions & 21 deletions .github/workflows/compile-cairo-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,55 @@ jobs:
set -e

declare -a all_kinds=("ERC20" "ERC721" "ERC1155" "Account" "Multisig" "Governor" "Vesting" "Custom")
declare -a all_royalty_info_options=("disabled" "enabled_default" "enabled_custom")
for kind in "${all_kinds[@]}"; do
scarb clean
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 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 clean
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

echo "Compiling $proj_name..."
scarb clean
scarb build

echo "✅ Compiled $proj_name!"
echo "---------------------------------"
done

else
proj_name="'$kind' test project"

if [[ "$kind" == "ERC721" || "$kind" == "ERC1155" ]]; then
for royalty_info_option in "${all_royalty_info_options[@]}"; do
proj_name="'$kind (royalty info: $royalty_info_option)'' test project"
echo "Generating $proj_name..."
yarn run update_scarb_project $kind $royalty_info_option
yarn run update_scarb_project --kind=$kind

echo "Compiling $proj_name..."
scarb clean
scarb build

echo "✅ Compiled $proj_name!"
echo "---------------------------------"
done

else
proj_name="'$kind' test project"

echo "Generating $proj_name..."
yarn run update_scarb_project $kind

echo "Compiling $proj_name..."
scarb build

echo "✅ Compiled $proj_name!"
echo "---------------------------------"
fi
fi
done

done
2 changes: 1 addition & 1 deletion packages/common/src/ai/descriptions/cairo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const cairoMacrosDescriptions = {
withComponents: 'Whether to use the "with_components" macro for simplified contract structure.',
};

export const cairoAlphaAccessDescriptions = {
export const cairoAccessDescriptions = {
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.',
darInitialDelay: 'The initial delay for the default admin role (in case Roles (Default Admin Rules) is used).',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/cairo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ The following contract types are supported:
- `erc721`
- `erc1155`
- `account`
- `governor`
- `multisig`
- `governor`
- `vesting`
- `custom`

Expand Down
1 change: 1 addition & 0 deletions packages/core/cairo/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,
};
3 changes: 2 additions & 1 deletion packages/core/cairo/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "@openzeppelin/wizard-cairo",
"version": "2.1.0",
"description": "A boilerplate generator to get started with OpenZeppelin Contracts for Cairo",
"private": false,
"version": "3.0.0",
"license": "AGPL-3.0-only",
"repository": "https://github.com/OpenZeppelin/contracts-wizard",
"main": "dist/index.js",
Expand Down
Binary file removed packages/core/cairo/src/account.test.ts.snap
Binary file not shown.
21 changes: 14 additions & 7 deletions packages/core/cairo/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::account::interface', '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/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
12 changes: 8 additions & 4 deletions packages/core/cairo/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,12 +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');
}

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
8 changes: 7 additions & 1 deletion packages/core/cairo/src/common-options.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import type { Argument } from './contract';
import type { Access } from './set-access-control';
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> = {
...defaults,
access: false,
access: AccessControl.None(),
} as const;

export interface CommonOptions {
upgradeable?: Upgradeable;
info?: Info;
macros?: MacrosOptions;
}

export interface CommonContractOptions extends CommonOptions {
Expand All @@ -27,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/src/contract.test.ts.snap
Binary file not shown.
Loading
Loading