Skip to content

Commit c998ef0

Browse files
committed
feat: add supply option to ERC1155
1 parent 3b4f8f4 commit c998ef0

Some content is hidden

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

46 files changed

+458
-302
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@openzeppelin/wizard-common": patch
3+
---
4+
5+
Cairo: ERC1155 supply tracking description for AI prompts.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const cairoERC1155Descriptions = {
6666
baseUri:
6767
'The location of the metadata for the token. Clients will replace any instance of {id} in this string with the tokenId.',
6868
updatableUri: 'Whether privileged accounts will be able to set a new URI for all token types.',
69+
supply: 'Whether to keep track of total supply of tokens.',
6970
};
7071

7172
export const cairoGovernorDescriptions = {

packages/core/cairo_alpha/CHANGELOG.md

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

3+
## 3.1.0 (Unreleased)
4+
5+
- Add ERC1155 supply tracking extension () <!-- TODO: Add linked PR>
6+
37
## 3.0.0 (2026-01-10)
48

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

packages/core/cairo_alpha/ava.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
extensions: ['ts'],
33
require: ['ts-node/register'],
4+
files: ['src/**/*.test.ts'],
45
watchmode: {
56
ignoreChanges: ['contracts', 'artifacts', 'cache'],
67
},

packages/core/cairo_alpha/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@openzeppelin/wizard-cairo-alpha",
33
"private": true,
4-
"version": "3.0.0",
4+
"version": "4.0.0-alpha.0",
55
"description": "A boilerplate generator to get started with the latest alpha version of OpenZeppelin Contracts for Cairo",
66
"license": "AGPL-3.0-only",
77
"repository": "https://github.com/OpenZeppelin/contracts-wizard",

packages/core/cairo_alpha/src/erc1155.ts

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const defaults: Required<ERC1155Options> = {
2323
burnable: false,
2424
pausable: false,
2525
mintable: false,
26+
supply: false,
2627
updatableUri: true,
2728
royaltyInfo: royaltyInfoDefaults,
2829
access: commonDefaults.access,
@@ -41,6 +42,7 @@ export interface ERC1155Options extends CommonContractOptions {
4142
burnable?: boolean;
4243
pausable?: boolean;
4344
mintable?: boolean;
45+
supply?: boolean;
4446
updatableUri?: boolean;
4547
royaltyInfo?: RoyaltyInfoOptions;
4648
}
@@ -52,6 +54,7 @@ function withDefaults(opts: ERC1155Options): Required<ERC1155Options> {
5254
burnable: opts.burnable ?? defaults.burnable,
5355
pausable: opts.pausable ?? defaults.pausable,
5456
mintable: opts.mintable ?? defaults.mintable,
57+
supply: opts.supply ?? defaults.supply,
5558
updatableUri: opts.updatableUri ?? defaults.updatableUri,
5659
royaltyInfo: opts.royaltyInfo ?? defaults.royaltyInfo,
5760
};
@@ -86,6 +89,10 @@ export function buildERC1155(opts: ERC1155Options): Contract {
8689
addMintable(c, allOpts.access);
8790
}
8891

92+
if (allOpts.supply) {
93+
addSupply(c);
94+
}
95+
8996
if (allOpts.updatableUri) {
9097
addSetBaseUri(c, allOpts.access);
9198
}
@@ -101,7 +108,7 @@ export function buildERC1155(opts: ERC1155Options): Contract {
101108
}
102109

103110
function addHooks(c: ContractBuilder, allOpts: Required<ERC1155Options>) {
104-
const usesCustomHooks = allOpts.pausable;
111+
const usesCustomHooks = allOpts.pausable || allOpts.supply;
105112
if (usesCustomHooks) {
106113
const hooksTrait = {
107114
name: 'ERC1155HooksImpl',
@@ -112,20 +119,43 @@ function addHooks(c: ContractBuilder, allOpts: Required<ERC1155Options>) {
112119
c.addImplementedTrait(hooksTrait);
113120
c.addUseClause('starknet', 'ContractAddress');
114121

115-
c.addFunction(hooksTrait, {
116-
name: 'before_update',
117-
args: [
118-
{
119-
name: 'ref self',
120-
type: `ERC1155Component::ComponentState<ContractState>`,
121-
},
122-
{ name: 'from', type: 'ContractAddress' },
123-
{ name: 'to', type: 'ContractAddress' },
124-
{ name: 'token_ids', type: 'Span<u256>' },
125-
{ name: 'values', type: 'Span<u256>' },
126-
],
127-
code: ['let contract_state = self.get_contract()', 'contract_state.pausable.assert_not_paused()'],
128-
});
122+
if (allOpts.pausable) {
123+
c.addFunction(hooksTrait, {
124+
name: 'before_update',
125+
args: [
126+
{
127+
name: 'ref self',
128+
type: `ERC1155Component::ComponentState<ContractState>`,
129+
},
130+
{ name: 'from', type: 'ContractAddress' },
131+
{ name: 'to', type: 'ContractAddress' },
132+
{ name: 'token_ids', type: 'Span<u256>' },
133+
{ name: 'values', type: 'Span<u256>' },
134+
],
135+
code: ['let contract_state = self.get_contract()', 'contract_state.pausable.assert_not_paused()'],
136+
});
137+
}
138+
139+
if (allOpts.supply) {
140+
const afterUpdateFn = c.addFunction(hooksTrait, {
141+
name: 'after_update',
142+
args: [
143+
{
144+
name: 'ref self',
145+
type: `ERC1155Component::ComponentState<ContractState>`,
146+
},
147+
{ name: 'from', type: 'ContractAddress' },
148+
{ name: 'to', type: 'ContractAddress' },
149+
{ name: 'token_ids', type: 'Span<u256>' },
150+
{ name: 'values', type: 'Span<u256>' },
151+
],
152+
code: [],
153+
});
154+
afterUpdateFn.code.push(
155+
'let mut contract_state = self.get_contract_mut();',
156+
'contract_state.erc1155_supply.after_update(from, to, token_ids, values);',
157+
);
158+
}
129159
} else {
130160
c.addUseClause('openzeppelin_token::erc1155', 'ERC1155HooksEmptyImpl');
131161
}
@@ -153,6 +183,10 @@ function addBurnable(c: ContractBuilder) {
153183
c.addFunction(externalTrait, functions.batchBurn);
154184
}
155185

186+
function addSupply(c: ContractBuilder) {
187+
c.addComponent(components.ERC1155SupplyComponent, [], true);
188+
}
189+
156190
function addMintable(c: ContractBuilder, access: Access) {
157191
c.addUseClause('starknet', 'ContractAddress');
158192
requireAccessControl(c, externalTrait, functions.mint, access, 'MINTER', 'minter');
@@ -188,6 +222,29 @@ const components = defineComponents({
188222
},
189223
],
190224
},
225+
ERC1155SupplyComponent: {
226+
path: 'openzeppelin_token::erc1155::extensions',
227+
substorage: {
228+
name: 'erc1155_supply',
229+
type: 'ERC1155SupplyComponent::Storage',
230+
},
231+
event: {
232+
name: 'ERC1155SupplyEvent',
233+
type: 'ERC1155SupplyComponent::Event',
234+
},
235+
impls: [
236+
{
237+
name: 'ERC1155SupplyImpl',
238+
embed: true,
239+
value: 'ERC1155SupplyComponent::ERC1155SupplyImpl<ContractState>',
240+
},
241+
{
242+
name: 'ERC1155SupplyInternalImpl',
243+
embed: false,
244+
value: 'ERC1155SupplyComponent::InternalImpl<ContractState>',
245+
},
246+
],
247+
},
191248
});
192249

193250
const functions = defineFunctions({

packages/core/cairo_alpha/src/generate/erc1155.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function prepareBlueprint(opts: GeneratorOptions) {
2424
burnable: booleans,
2525
pausable: booleans,
2626
mintable: booleans,
27+
supply: booleans,
2728
updatableUri: booleans,
2829
upgradeable: upgradeableOptions,
2930
royaltyInfo: resolveRoyaltyOptionsSubset(opts.royaltyInfo),

0 commit comments

Comments
 (0)