diff --git a/packages/core-cairo/src/erc20.test.ts.md b/packages/core-cairo/src/erc20.test.ts.md index 8c6a35cb..a0af71ea 100644 --- a/packages/core-cairo/src/erc20.test.ts.md +++ b/packages/core-cairo/src/erc20.test.ts.md @@ -789,8 +789,8 @@ Generated by [AVA](https://avajs.dev). mod MyToken {␊ use openzeppelin::token::erc20::ERC20Component;␊ use openzeppelin::token::erc20::interface;␊ - use openzeppelin::security::pausable::PausableComponent;␊ use openzeppelin::access::ownable::OwnableComponent;␊ + use openzeppelin::security::pausable::PausableComponent;␊ use openzeppelin::upgrades::UpgradeableComponent;␊ use openzeppelin::upgrades::interface::IUpgradeable;␊ use starknet::ContractAddress;␊ @@ -798,22 +798,22 @@ Generated by [AVA](https://avajs.dev). use starknet::ClassHash;␊ ␊ component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ - component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ + component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ ␊ #[abi(embed_v0)]␊ impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl;␊ #[abi(embed_v0)]␊ - impl PausableImpl = PausableComponent::PausableImpl;␊ - #[abi(embed_v0)]␊ impl OwnableImpl = OwnableComponent::OwnableImpl;␊ #[abi(embed_v0)]␊ impl OwnableCamelOnlyImpl = OwnableComponent::OwnableCamelOnlyImpl;␊ + #[abi(embed_v0)]␊ + impl PausableImpl = PausableComponent::PausableImpl;␊ ␊ impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ - impl PausableInternalImpl = PausableComponent::InternalImpl;␊ impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ + impl PausableInternalImpl = PausableComponent::InternalImpl;␊ impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ ␊ #[storage]␊ @@ -821,10 +821,10 @@ Generated by [AVA](https://avajs.dev). #[substorage(v0)]␊ erc20: ERC20Component::Storage,␊ #[substorage(v0)]␊ - pausable: PausableComponent::Storage,␊ - #[substorage(v0)]␊ ownable: OwnableComponent::Storage,␊ #[substorage(v0)]␊ + pausable: PausableComponent::Storage,␊ + #[substorage(v0)]␊ upgradeable: UpgradeableComponent::Storage,␊ }␊ ␊ @@ -834,10 +834,10 @@ Generated by [AVA](https://avajs.dev). #[flat]␊ ERC20Event: ERC20Component::Event,␊ #[flat]␊ - PausableEvent: PausableComponent::Event,␊ - #[flat]␊ OwnableEvent: OwnableComponent::Event,␊ #[flat]␊ + PausableEvent: PausableComponent::Event,␊ + #[flat]␊ UpgradeableEvent: UpgradeableComponent::Event,␊ }␊ ␊ @@ -934,6 +934,12 @@ Generated by [AVA](https://avajs.dev). #[generate_trait]␊ #[external(v0)]␊ impl ExternalImpl of ExternalTrait {␊ + fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {␊ + self.ownable.assert_only_owner();␊ + self.pausable.assert_not_paused();␊ + self.erc20._mint(recipient, amount);␊ + }␊ + ␊ fn burn(ref self: ContractState, value: u256) {␊ self.pausable.assert_not_paused();␊ let caller = get_caller_address();␊ @@ -949,11 +955,6 @@ Generated by [AVA](https://avajs.dev). self.ownable.assert_only_owner();␊ self.pausable._unpause();␊ }␊ - ␊ - fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {␊ - self.ownable.assert_only_owner();␊ - self.erc20._mint(recipient, amount);␊ - }␊ }␊ ␊ #[external(v0)]␊ @@ -972,45 +973,45 @@ Generated by [AVA](https://avajs.dev). `// SPDX-License-Identifier: MIT␊ ␊ - const PAUSER_ROLE: felt252 = selector!("PAUSER_ROLE");␊ const MINTER_ROLE: felt252 = selector!("MINTER_ROLE");␊ + const PAUSER_ROLE: felt252 = selector!("PAUSER_ROLE");␊ const UPGRADER_ROLE: felt252 = selector!("UPGRADER_ROLE");␊ ␊ #[starknet::contract]␊ mod MyToken {␊ use openzeppelin::token::erc20::ERC20Component;␊ use openzeppelin::token::erc20::interface;␊ - use openzeppelin::security::pausable::PausableComponent;␊ use openzeppelin::access::accesscontrol::AccessControlComponent;␊ use openzeppelin::introspection::src5::SRC5Component;␊ + use openzeppelin::security::pausable::PausableComponent;␊ use openzeppelin::upgrades::UpgradeableComponent;␊ use openzeppelin::access::accesscontrol::DEFAULT_ADMIN_ROLE;␊ use openzeppelin::upgrades::interface::IUpgradeable;␊ use starknet::ContractAddress;␊ use starknet::get_caller_address;␊ use starknet::ClassHash;␊ - use super::{PAUSER_ROLE, MINTER_ROLE, UPGRADER_ROLE};␊ + use super::{MINTER_ROLE, PAUSER_ROLE, UPGRADER_ROLE};␊ ␊ component!(path: ERC20Component, storage: erc20, event: ERC20Event);␊ - component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent);␊ component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ + component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ ␊ #[abi(embed_v0)]␊ impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl;␊ #[abi(embed_v0)]␊ - impl PausableImpl = PausableComponent::PausableImpl;␊ - #[abi(embed_v0)]␊ impl AccessControlImpl = AccessControlComponent::AccessControlImpl;␊ #[abi(embed_v0)]␊ impl AccessControlCamelImpl = AccessControlComponent::AccessControlCamelImpl;␊ #[abi(embed_v0)]␊ impl SRC5Impl = SRC5Component::SRC5Impl;␊ + #[abi(embed_v0)]␊ + impl PausableImpl = PausableComponent::PausableImpl;␊ ␊ impl ERC20InternalImpl = ERC20Component::InternalImpl;␊ - impl PausableInternalImpl = PausableComponent::InternalImpl;␊ impl AccessControlInternalImpl = AccessControlComponent::InternalImpl;␊ + impl PausableInternalImpl = PausableComponent::InternalImpl;␊ impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ ␊ #[storage]␊ @@ -1018,12 +1019,12 @@ Generated by [AVA](https://avajs.dev). #[substorage(v0)]␊ erc20: ERC20Component::Storage,␊ #[substorage(v0)]␊ - pausable: PausableComponent::Storage,␊ - #[substorage(v0)]␊ accesscontrol: AccessControlComponent::Storage,␊ #[substorage(v0)]␊ src5: SRC5Component::Storage,␊ #[substorage(v0)]␊ + pausable: PausableComponent::Storage,␊ + #[substorage(v0)]␊ upgradeable: UpgradeableComponent::Storage,␊ }␊ ␊ @@ -1033,12 +1034,12 @@ Generated by [AVA](https://avajs.dev). #[flat]␊ ERC20Event: ERC20Component::Event,␊ #[flat]␊ - PausableEvent: PausableComponent::Event,␊ - #[flat]␊ AccessControlEvent: AccessControlComponent::Event,␊ #[flat]␊ SRC5Event: SRC5Component::Event,␊ #[flat]␊ + PausableEvent: PausableComponent::Event,␊ + #[flat]␊ UpgradeableEvent: UpgradeableComponent::Event,␊ }␊ ␊ @@ -1047,8 +1048,8 @@ Generated by [AVA](https://avajs.dev). ref self: ContractState,␊ recipient: ContractAddress,␊ default_admin: ContractAddress,␊ - pauser: ContractAddress,␊ minter: ContractAddress,␊ + pauser: ContractAddress,␊ upgrader: ContractAddress,␊ ) {␊ self.erc20.initializer('MyToken', 'MTK');␊ @@ -1056,8 +1057,8 @@ Generated by [AVA](https://avajs.dev). ␊ self.erc20._mint(recipient, 2000000000000000000000);␊ self.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, default_admin);␊ - self.accesscontrol._grant_role(PAUSER_ROLE, pauser);␊ self.accesscontrol._grant_role(MINTER_ROLE, minter);␊ + self.accesscontrol._grant_role(PAUSER_ROLE, pauser);␊ self.accesscontrol._grant_role(UPGRADER_ROLE, upgrader);␊ }␊ ␊ @@ -1146,6 +1147,12 @@ Generated by [AVA](https://avajs.dev). #[generate_trait]␊ #[external(v0)]␊ impl ExternalImpl of ExternalTrait {␊ + fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {␊ + self.accesscontrol.assert_only_role(MINTER_ROLE);␊ + self.pausable.assert_not_paused();␊ + self.erc20._mint(recipient, amount);␊ + }␊ + ␊ fn burn(ref self: ContractState, value: u256) {␊ self.pausable.assert_not_paused();␊ let caller = get_caller_address();␊ @@ -1161,11 +1168,6 @@ Generated by [AVA](https://avajs.dev). self.accesscontrol.assert_only_role(PAUSER_ROLE);␊ self.pausable._unpause();␊ }␊ - ␊ - fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {␊ - self.accesscontrol.assert_only_role(MINTER_ROLE);␊ - self.erc20._mint(recipient, amount);␊ - }␊ }␊ ␊ #[external(v0)]␊ diff --git a/packages/core-cairo/src/erc20.test.ts.snap b/packages/core-cairo/src/erc20.test.ts.snap index 0415413d..8665e15b 100644 Binary files a/packages/core-cairo/src/erc20.test.ts.snap and b/packages/core-cairo/src/erc20.test.ts.snap differ diff --git a/packages/core-cairo/src/erc20.ts b/packages/core-cairo/src/erc20.ts index 9c65d7f1..3564e37c 100644 --- a/packages/core-cairo/src/erc20.ts +++ b/packages/core-cairo/src/erc20.ts @@ -71,6 +71,10 @@ export function buildERC20(opts: ERC20Options): Contract { addPremint(c, allOpts.premint); } + if (allOpts.mintable) { + addMintable(c, allOpts.access); + } + if (allOpts.burnable) { addBurnable(c); } @@ -80,10 +84,9 @@ export function buildERC20(opts: ERC20Options): Contract { if (allOpts.burnable) { setPausable(c, externalTrait, functions.burn); } - } - - if (allOpts.mintable) { - addMintable(c, allOpts.access); + if (allOpts.mintable) { + setPausable(c, externalTrait, functions.mint); + } } setAccessControl(c, allOpts.access); diff --git a/packages/core-cairo/src/erc721.test.ts.md b/packages/core-cairo/src/erc721.test.ts.md index cf8072e5..1b8c0f8f 100644 --- a/packages/core-cairo/src/erc721.test.ts.md +++ b/packages/core-cairo/src/erc721.test.ts.md @@ -474,18 +474,18 @@ Generated by [AVA](https://avajs.dev). use openzeppelin::token::erc721::ERC721Component;␊ use openzeppelin::token::erc721::interface;␊ use openzeppelin::introspection::src5::SRC5Component;␊ - use openzeppelin::security::pausable::PausableComponent;␊ use openzeppelin::access::ownable::OwnableComponent;␊ + use openzeppelin::security::pausable::PausableComponent;␊ use openzeppelin::upgrades::UpgradeableComponent;␊ use openzeppelin::upgrades::interface::IUpgradeable;␊ - use starknet::get_caller_address;␊ use starknet::ContractAddress;␊ + use starknet::get_caller_address;␊ use starknet::ClassHash;␊ ␊ component!(path: ERC721Component, storage: erc721, event: ERC721Event);␊ component!(path: SRC5Component, storage: src5, event: SRC5Event);␊ - component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);␊ + component!(path: PausableComponent, storage: pausable, event: PausableEvent);␊ component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);␊ ␊ #[abi(embed_v0)]␊ @@ -495,15 +495,15 @@ Generated by [AVA](https://avajs.dev). #[abi(embed_v0)]␊ impl SRC5Impl = SRC5Component::SRC5Impl;␊ #[abi(embed_v0)]␊ - impl PausableImpl = PausableComponent::PausableImpl;␊ - #[abi(embed_v0)]␊ impl OwnableImpl = OwnableComponent::OwnableImpl;␊ #[abi(embed_v0)]␊ impl OwnableCamelOnlyImpl = OwnableComponent::OwnableCamelOnlyImpl;␊ + #[abi(embed_v0)]␊ + impl PausableImpl = PausableComponent::PausableImpl;␊ ␊ impl ERC721InternalImpl = ERC721Component::InternalImpl;␊ - impl PausableInternalImpl = PausableComponent::InternalImpl;␊ impl OwnableInternalImpl = OwnableComponent::InternalImpl;␊ + impl PausableInternalImpl = PausableComponent::InternalImpl;␊ impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl;␊ ␊ #[storage]␊ @@ -513,10 +513,10 @@ Generated by [AVA](https://avajs.dev). #[substorage(v0)]␊ src5: SRC5Component::Storage,␊ #[substorage(v0)]␊ - pausable: PausableComponent::Storage,␊ - #[substorage(v0)]␊ ownable: OwnableComponent::Storage,␊ #[substorage(v0)]␊ + pausable: PausableComponent::Storage,␊ + #[substorage(v0)]␊ upgradeable: UpgradeableComponent::Storage,␊ }␊ ␊ @@ -528,10 +528,10 @@ Generated by [AVA](https://avajs.dev). #[flat]␊ SRC5Event: SRC5Component::Event,␊ #[flat]␊ - PausableEvent: PausableComponent::Event,␊ - #[flat]␊ OwnableEvent: OwnableComponent::Event,␊ #[flat]␊ + PausableEvent: PausableComponent::Event,␊ + #[flat]␊ UpgradeableEvent: UpgradeableComponent::Event,␊ }␊ ␊ @@ -639,6 +639,19 @@ Generated by [AVA](https://avajs.dev). #[generate_trait]␊ #[external(v0)]␊ impl ExternalImpl of ExternalTrait {␊ + fn safe_mint(␊ + ref self: ContractState,␊ + recipient: ContractAddress,␊ + token_id: u256,␊ + data: Span,␊ + token_uri: felt252,␊ + ) {␊ + self.ownable.assert_only_owner();␊ + self.pausable.assert_not_paused();␊ + self.erc721._safe_mint(recipient, token_id, data);␊ + self.erc721._set_token_uri(token_id, token_uri);␊ + }␊ + ␊ fn burn(ref self: ContractState, token_id: u256) {␊ self.pausable.assert_not_paused();␊ let caller = get_caller_address();␊ @@ -655,18 +668,6 @@ Generated by [AVA](https://avajs.dev). self.ownable.assert_only_owner();␊ self.pausable._unpause();␊ }␊ - ␊ - fn safe_mint(␊ - ref self: ContractState,␊ - recipient: ContractAddress,␊ - token_id: u256,␊ - data: Span,␊ - token_uri: felt252,␊ - ) {␊ - self.ownable.assert_only_owner();␊ - self.erc721._safe_mint(recipient, token_id, data);␊ - self.erc721._set_token_uri(token_id, token_uri);␊ - }␊ }␊ ␊ #[external(v0)]␊ diff --git a/packages/core-cairo/src/erc721.test.ts.snap b/packages/core-cairo/src/erc721.test.ts.snap index aeb98c53..1115ea6a 100644 Binary files a/packages/core-cairo/src/erc721.test.ts.snap and b/packages/core-cairo/src/erc721.test.ts.snap differ diff --git a/packages/core-cairo/src/erc721.ts b/packages/core-cairo/src/erc721.ts index 15e5be50..1e756b88 100644 --- a/packages/core-cairo/src/erc721.ts +++ b/packages/core-cairo/src/erc721.ts @@ -57,6 +57,10 @@ export function buildERC721(opts: ERC721Options): Contract { addBase(c, toShortString(allOpts.name, 'name'), toShortString(allOpts.symbol, 'symbol')); addERC721ImplAndCamelOnlyImpl(c, allOpts.pausable); + if (allOpts.mintable) { + addMintable(c, allOpts.access); + } + if (allOpts.burnable) { addBurnable(c); } @@ -66,10 +70,9 @@ export function buildERC721(opts: ERC721Options): Contract { if (allOpts.burnable) { setPausable(c, externalTrait, functions.burn); } - } - - if (allOpts.mintable) { - addMintable(c, allOpts.access); + if (allOpts.mintable) { + setPausable(c, externalTrait, functions.safe_mint); + } } setAccessControl(c, allOpts.access);