Skip to content

Commit 603a84c

Browse files
authored
Cairo: Support ERC-6909 extensions (#793)
1 parent 7105418 commit 603a84c

56 files changed

Lines changed: 2113 additions & 394 deletions

Some content is hidden

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

.changeset/deep-frogs-kneel.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@openzeppelin/wizard-common': patch
3+
---
4+
5+
Cairo: Add ERC6909Metadata, ERC6909ContentURI, ERC6909TokenSupply extensions.
6+
Cairo: Default DAR delay fields in the `access` schema so callers don't need to supply them for non-`roles-dar` access types.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Setup node
2727
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
2828
with:
29-
node-version: 20.x
29+
node-version: 22
3030
cache: 'yarn'
3131

3232
- name: Install dependencies
@@ -78,7 +78,7 @@ jobs:
7878
done
7979
done
8080
81-
elif [[ "$kind" == "ERC20" || "$kind" == "Custom" ]]; then
81+
elif [[ "$kind" == "ERC20" || "$kind" == "ERC6909" || "$kind" == "Custom" ]]; then
8282
for access_option in "${all_access_options[@]}"; do
8383
proj_name="'$kind, macros: $macros_option, access: $access_option' test project"
8484
echo "Generating $proj_name..."

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Setup node
2727
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
2828
with:
29-
node-version: 20.x
29+
node-version: 22
3030
cache: 'yarn'
3131

3232
- name: Install dependencies

packages/cli/src/cli-options.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,38 @@ test('cairo-erc20: access roles-dar', t => {
368368
t.is(output, cairoErc20.print(opts));
369369
});
370370

371+
// DAR delays are only used for `roles-dar`; non-dar access types should work
372+
// without requiring them — they fall back to defaults matching `darDefaultOpts`.
373+
test('cairo-erc20: access roles without dar delays', t => {
374+
const opts = {
375+
name: 'TestToken',
376+
symbol: 'TST',
377+
access: {
378+
type: 'roles' as const,
379+
darInitialDelay: '1 day',
380+
darDefaultDelayIncrease: '5 days',
381+
darMaxTransferDelay: '30 days',
382+
},
383+
};
384+
const output = run('cairo-erc20', '--name', opts.name, '--symbol', opts.symbol, '--access.type', 'roles');
385+
t.is(output, cairoErc20.print(opts));
386+
});
387+
388+
test('cairo-erc20: access ownable without dar delays', t => {
389+
const opts = {
390+
name: 'TestToken',
391+
symbol: 'TST',
392+
access: {
393+
type: 'ownable' as const,
394+
darInitialDelay: '1 day',
395+
darDefaultDelayIncrease: '5 days',
396+
darMaxTransferDelay: '30 days',
397+
},
398+
};
399+
const output = run('cairo-erc20', '--name', opts.name, '--symbol', opts.symbol, '--access.type', 'ownable');
400+
t.is(output, cairoErc20.print(opts));
401+
});
402+
371403
test('cairo-erc721: most options', t => {
372404
const opts = {
373405
name: 'TestNFT',

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ export const cairoERC1155Descriptions = {
7575
uriStorage: 'Allows updating token URIs for individual token IDs.',
7676
};
7777

78-
export const cairoERC6909Descriptions = {};
78+
export const cairoERC6909Descriptions = {
79+
contentUri: 'Whether to include Content URI extension for contract-level and per-token URI metadata.',
80+
tokenSupply: 'Whether to keep track of total supply per token ID.',
81+
metadata: 'Whether to include per-token metadata extension providing name, symbol, and decimals per token ID.',
82+
};
7983

8084
export const cairoGovernorDescriptions = {
8185
delay:

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
cairoERC721Descriptions,
1010
cairoRoyaltyInfoDescriptions,
1111
cairoERC1155Descriptions,
12+
cairoERC6909Descriptions,
1213
cairoAccountDescriptions,
1314
cairoGovernorDescriptions,
1415
cairoMultisigDescriptions,
@@ -24,9 +25,9 @@ export const cairoCommonSchema = {
2425
.or(z.literal('roles-dar'))
2526
.or(z.literal(false))
2627
.describe(cairoAccessDescriptions.accessType),
27-
darInitialDelay: z.string().describe(cairoAccessDescriptions.darInitialDelay),
28-
darDefaultDelayIncrease: z.string().describe(cairoAccessDescriptions.darDefaultDelayIncrease),
29-
darMaxTransferDelay: z.string().describe(cairoAccessDescriptions.darMaxTransferDelay),
28+
darInitialDelay: z.string().default('1 day').describe(cairoAccessDescriptions.darInitialDelay),
29+
darDefaultDelayIncrease: z.string().default('5 days').describe(cairoAccessDescriptions.darDefaultDelayIncrease),
30+
darMaxTransferDelay: z.string().default('30 days').describe(cairoAccessDescriptions.darMaxTransferDelay),
3031
})
3132
.optional(),
3233
upgradeable: z.boolean().optional().describe(cairoCommonDescriptions.upgradeable),
@@ -99,6 +100,17 @@ export const cairoERC1155Schema = {
99100
...cairoCommonSchema,
100101
} as const satisfies z.ZodRawShape;
101102

103+
export const cairoERC6909Schema = {
104+
name: z.string().describe(commonDescriptions.name),
105+
burnable: z.boolean().optional().describe(commonDescriptions.burnable),
106+
pausable: z.boolean().optional().describe(commonDescriptions.pausable),
107+
mintable: z.boolean().optional().describe(commonDescriptions.mintable),
108+
contentUri: z.boolean().optional().describe(cairoERC6909Descriptions.contentUri),
109+
tokenSupply: z.boolean().optional().describe(cairoERC6909Descriptions.tokenSupply),
110+
metadata: z.boolean().optional().describe(cairoERC6909Descriptions.metadata),
111+
...cairoCommonSchema,
112+
} as const satisfies z.ZodRawShape;
113+
102114
export const cairoAccountSchema = {
103115
name: z.string().describe(commonDescriptions.name),
104116
type: z.enum(['stark', 'eth']).describe(cairoAccountDescriptions.type),

packages/common/src/ai/schemas/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export {
1515
cairoERC20Schema,
1616
cairoERC721Schema,
1717
cairoERC1155Schema,
18+
cairoERC6909Schema,
1819
cairoAccountSchema,
1920
cairoMultisigSchema,
2021
cairoGovernorSchema,

packages/common/src/ai/schemas/schemas.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
cairoERC20Schema,
2121
cairoERC721Schema,
2222
cairoERC1155Schema,
23+
cairoERC6909Schema,
2324
cairoAccountSchema,
2425
cairoMultisigSchema,
2526
cairoGovernorSchema,
@@ -86,6 +87,7 @@ const allSchemas: [string, z.ZodRawShape][] = [
8687
['cairoERC20', cairoERC20Schema],
8788
['cairoERC721', cairoERC721Schema],
8889
['cairoERC1155', cairoERC1155Schema],
90+
['cairoERC6909', cairoERC6909Schema],
8991
['cairoAccount', cairoAccountSchema],
9092
['cairoMultisig', cairoMultisigSchema],
9193
['cairoGovernor', cairoGovernorSchema],

packages/core/cairo_alpha/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
## Unreleased
44

55
- Add ERC6909 contract kind ([#771](https://github.com/OpenZeppelin/contracts-wizard/pull/771))
6+
- Add ERC6909Metadata extension ([#793](https://github.com/OpenZeppelin/contracts-wizard/pull/793))
7+
- Add ERC6909ContentURI extension ([#793](https://github.com/OpenZeppelin/contracts-wizard/pull/793))
8+
- Add ERC6909TokenSupply extension ([#793](https://github.com/OpenZeppelin/contracts-wizard/pull/793))
69
- Add ERC1155URIStorage extension ([#772](https://github.com/OpenZeppelin/contracts-wizard/pull/772))
710
- Add ERC1155Supply extension ([#765](https://github.com/OpenZeppelin/contracts-wizard/pull/765))
811
- Add ERC721URIStorage extension ([#772](https://github.com/OpenZeppelin/contracts-wizard/pull/772))

0 commit comments

Comments
 (0)