diff --git a/.tool-versions b/.tool-versions index c69b5af8..50187399 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -scarb 2.9.2 -starknet-foundry 0.35.0 +scarb 2.9.4 +starknet-foundry 0.37.0 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 40f4b0ef..5a2dbf1b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -103,7 +103,7 @@ version.workspace = true starknet.workspace = true # Uncomment the following lines if you want to use additional dependencies: # OpenZeppelin: -# openzeppelin.workspace = true +# openzeppelin_{package_name}.workspace = true # If you want to use another Starknet By Example's listing, you can add it as a dependency like this: # erc20 = { path = "../../getting-started/erc20" } @@ -137,7 +137,7 @@ version.workspace = true starknet.workspace = true # Uncomment the following lines if you want to use additional dependencies: # OpenZeppelin: -# openzeppelin.workspace = true +# openzeppelin_{package_name}.workspace = true # If you want to use another Starknet By Example's listing, you can add it as a dependency like this: # erc20 = { path = "../../getting-started/erc20" } diff --git a/Scarb.lock b/Scarb.lock index da42f857..26cde18f 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -1,14 +1,6 @@ # Code generated by scarb DO NOT EDIT. version = 1 -[[package]] -name = "account_spending_limits" -version = "0.1.0" -dependencies = [ - "openzeppelin", - "snforge_std", -] - [[package]] name = "advanced_factory" version = "0.1.0" @@ -29,7 +21,8 @@ dependencies = [ name = "coin_flip" version = "0.1.0" dependencies = [ - "openzeppelin", + "openzeppelin_presets", + "openzeppelin_token", "pragma_lib", "snforge_std", ] @@ -53,7 +46,7 @@ dependencies = [ name = "constant_product_amm" version = "0.1.0" dependencies = [ - "openzeppelin", + "openzeppelin_token", ] [[package]] @@ -75,7 +68,8 @@ name = "crowdfunding" version = "0.1.0" dependencies = [ "components", - "openzeppelin", + "openzeppelin_presets", + "openzeppelin_token", "snforge_std", ] @@ -143,39 +137,21 @@ dependencies = [ "snforge_std", ] -[[package]] -name = "openzeppelin" -version = "0.20.0" -source = "registry+https://scarbs.xyz/" -checksum = "sha256:05fd9365be85a4a3e878135d5c52229f760b3861ce4ed314cb1e75b178b553da" -dependencies = [ - "openzeppelin_access", - "openzeppelin_account", - "openzeppelin_finance", - "openzeppelin_governance", - "openzeppelin_introspection", - "openzeppelin_merkle_tree", - "openzeppelin_presets", - "openzeppelin_security", - "openzeppelin_token", - "openzeppelin_upgrades", - "openzeppelin_utils", -] - [[package]] name = "openzeppelin_access" -version = "0.20.0" +version = "1.0.0" source = "registry+https://scarbs.xyz/" -checksum = "sha256:7734901a0ca7a7065e69416fea615dd1dc586c8dc9e76c032f25ee62e8b2a06c" +checksum = "sha256:a39a4ea1582916c637bf7e3aee0832c3fe1ea3a3e39191955e8dc39d08327f9b" dependencies = [ "openzeppelin_introspection", + "openzeppelin_utils", ] [[package]] name = "openzeppelin_account" -version = "0.20.0" +version = "1.0.0" source = "registry+https://scarbs.xyz/" -checksum = "sha256:1aa3a71e2f40f66f98d96aa9bf9f361f53db0fd20fa83ef7df04426a3c3a926a" +checksum = "sha256:7e943a2de32ddca4d48e467e52790e380ab1f49c4daddbbbc4634dd930d0243f" dependencies = [ "openzeppelin_introspection", "openzeppelin_utils", @@ -183,44 +159,25 @@ dependencies = [ [[package]] name = "openzeppelin_finance" -version = "0.20.0" -source = "registry+https://scarbs.xyz/" -checksum = "sha256:f0c507fbff955e4180ea3fa17949c0ff85518c40101f4948948d9d9a74143d6c" -dependencies = [ - "openzeppelin_access", - "openzeppelin_token", -] - -[[package]] -name = "openzeppelin_governance" -version = "0.20.0" +version = "1.0.0" source = "registry+https://scarbs.xyz/" -checksum = "sha256:c0fb60fad716413d537fabd5fcbb2c499ca6beb95af5f0d1699955ecec4c6f63" +checksum = "sha256:9fa9e91d39b6ccdfa31eef32fdc087cd06c0269cc9c6b86e32d57f5a6997d98b" dependencies = [ "openzeppelin_access", - "openzeppelin_account", - "openzeppelin_introspection", "openzeppelin_token", - "openzeppelin_utils", ] [[package]] name = "openzeppelin_introspection" -version = "0.20.0" -source = "registry+https://scarbs.xyz/" -checksum = "sha256:13e04a2190684e6804229a77a6c56de7d033db8b9ef519e5e8dee400a70d8a3d" - -[[package]] -name = "openzeppelin_merkle_tree" -version = "0.20.0" +version = "1.0.0" source = "registry+https://scarbs.xyz/" -checksum = "sha256:039608900e92f3dcf479bf53a49a1fd76452acd97eb86e390d1eb92cacdaf3af" +checksum = "sha256:34e088ecf19e0b3012481a29f1fbb20e600540cb9a5db1c3002a97ebb7f5a32a" [[package]] name = "openzeppelin_presets" -version = "0.20.0" +version = "1.0.0" source = "registry+https://scarbs.xyz/" -checksum = "sha256:5c07a8de32e5d9abe33988c7927eaa8b5f83bc29dc77302d9c8c44c898611042" +checksum = "sha256:4eb098e2ee3ac0e67b6828115a7de62f781418beab767d4e80b54e176808369d" dependencies = [ "openzeppelin_access", "openzeppelin_account", @@ -231,17 +188,11 @@ dependencies = [ "openzeppelin_utils", ] -[[package]] -name = "openzeppelin_security" -version = "0.20.0" -source = "registry+https://scarbs.xyz/" -checksum = "sha256:27155597019ecf971c48d7bfb07fa58cdc146d5297745570071732abca17f19f" - [[package]] name = "openzeppelin_token" -version = "0.20.0" +version = "1.0.0" source = "registry+https://scarbs.xyz/" -checksum = "sha256:4452f449dc6c1ea97cf69d1d9182749abd40e85bd826cd79652c06a627eafd91" +checksum = "sha256:33fcb84a1a76d2d3fff9302094ff564f78d45b743548fd7568c130b272473f66" dependencies = [ "openzeppelin_access", "openzeppelin_account", @@ -251,15 +202,15 @@ dependencies = [ [[package]] name = "openzeppelin_upgrades" -version = "0.20.0" +version = "1.0.0" source = "registry+https://scarbs.xyz/" -checksum = "sha256:15fdd63f6b50a0fda7b3f8f434120aaf7637bcdfe6fd8d275ad57343d5ede5e1" +checksum = "sha256:36f7a03e7e7111577916aacf31f88ad0053de20f33ee10b0ab3804849c3aa373" [[package]] name = "openzeppelin_utils" -version = "0.20.0" +version = "1.0.0" source = "registry+https://scarbs.xyz/" -checksum = "sha256:44f32d242af1e43982decc49c563e613a9b67ade552f5c3d5cde504e92f74607" +checksum = "sha256:fd348b31c4a4407add33adc3c2b8f26dca71dbd7431faaf726168f37a91db0c1" [[package]] name = "pragma_lib" @@ -274,7 +225,8 @@ version = "0.1.0" name = "simple_account" version = "0.1.0" dependencies = [ - "openzeppelin", + "openzeppelin_account", + "openzeppelin_introspection", ] [[package]] @@ -290,15 +242,15 @@ dependencies = [ [[package]] name = "snforge_scarb_plugin" -version = "0.35.0" +version = "0.37.0" source = "registry+https://scarbs.xyz/" -checksum = "sha256:20bd6a488fda7201ce2a5fd680d8e715b10e3545147b276747ad079c96c3d5d2" +checksum = "sha256:9dbb114f853decc27b2d6d53e2ddd207217ce63c2d24a47c5c48d5f475b0b9a5" [[package]] name = "snforge_std" -version = "0.35.0" +version = "0.37.0" source = "registry+https://scarbs.xyz/" -checksum = "sha256:fe4e1b1526c815441183baed7f93e73bc76a6393d23e1f9c34fbe227bfaedfd6" +checksum = "sha256:f5702c4a6d54e3563b4aa78c834de6ddcf18ef8ca8fd35dc1bceb7ece58e9571" dependencies = [ "snforge_scarb_plugin", ] @@ -307,7 +259,7 @@ dependencies = [ name = "staking" version = "0.1.0" dependencies = [ - "openzeppelin", + "openzeppelin_token", ] [[package]] @@ -344,7 +296,9 @@ name = "timelock" version = "0.1.0" dependencies = [ "components", - "openzeppelin", + "openzeppelin_introspection", + "openzeppelin_token", + "openzeppelin_utils", "snforge_std", ] diff --git a/Scarb.toml b/Scarb.toml index 37e6b8f1..99652d60 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -12,11 +12,15 @@ test = "$(git rev-parse --show-toplevel)/scripts/test_resolver.sh" [workspace.tool.snforge] [workspace.dependencies] -starknet = "2.9.2" -cairo_test = "2.9.2" -assert_macros = "2.9.2" -snforge_std = "0.35.0" -openzeppelin = "0.20.0" +starknet = "2.9.4" +cairo_test = "2.9.4" +assert_macros = "2.9.4" +snforge_std = "0.37.0" +openzeppelin_account = "1.0.0" +openzeppelin_introspection = "1.0.0" +openzeppelin_presets = "1.0.0" +openzeppelin_token = "1.0.0" +openzeppelin_utils = "1.0.0" components = { path = "listings/applications/components" } pragma_lib = { git = "https://github.com/astraly-labs/pragma-lib", tag = "2.9.1" } diff --git a/listings/advanced-concepts/account_spending_limits/Scarb.lock b/listings/advanced-concepts/account_spending_limits/Scarb.lock deleted file mode 100644 index 318293a5..00000000 --- a/listings/advanced-concepts/account_spending_limits/Scarb.lock +++ /dev/null @@ -1,20 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "aa_tutorial" -version = "0.1.0" -dependencies = [ - "openzeppelin", - "snforge_std", -] - -[[package]] -name = "openzeppelin" -version = "0.9.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.9.0#364db5b1aecc1335d2e65db887291d19aa28937d" - -[[package]] -name = "snforge_std" -version = "0.25.0" -source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.25.0#5b366e24821e530fea97f11b211d220e8493fbea" diff --git a/listings/advanced-concepts/account_spending_limits/Scarb.toml b/listings/advanced-concepts/account_spending_limits/Scarb.toml deleted file mode 100644 index f5671a4a..00000000 --- a/listings/advanced-concepts/account_spending_limits/Scarb.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "account_spending_limits" -version.workspace = true -edition.workspace = true - -[dependencies] -starknet.workspace = true -openzeppelin.workspace = true - -[dev-dependencies] -assert_macros.workspace = true -snforge_std.workspace = true - -[scripts] -test.workspace = true - -[[target.starknet-contract]] -build-external-contracts = ["openzeppelin_presets::erc20::ERC20Upgradeable"] diff --git a/listings/advanced-concepts/account_spending_limits/src/account.cairo b/listings/advanced-concepts/account_spending_limits/src/account.cairo deleted file mode 100644 index 922c672d..00000000 --- a/listings/advanced-concepts/account_spending_limits/src/account.cairo +++ /dev/null @@ -1,260 +0,0 @@ -use starknet::account::Call; -use starknet::ContractAddress; - -#[starknet::interface] -trait ISRC6 { - fn __execute__(ref self: TContractState, calls: Array) -> Array>; - fn __validate__(self: @TContractState, calls: Array) -> felt252; - fn is_valid_signature( - self: @TContractState, hash: felt252, signature: Array - ) -> felt252; -} - -#[starknet::interface] -trait ISRC5 { - fn supports_interface(self: @TContractState, interface_id: felt252) -> bool; -} - -#[starknet::interface] -trait IDeployableAccount { - fn __validate_deploy__( - self: @TContractState, class_hash: felt252, salt: felt252, public_key: felt252 - ) -> felt252; -} - -#[starknet::interface] -trait IDeclarerAccount { - fn __validate_declare__(self: @TContractState, class_hash: felt252) -> felt252; -} - -#[starknet::interface] -trait ISpendingLimitsAccount { - fn public_key(self: @TContractState) -> felt252; - fn get_time_limit(self: @TContractState) -> u64; - fn set_spending_limit(ref self: TContractState, token_address: ContractAddress, _limit: u256); - fn get_spending_limit_timestamp(self: @TContractState, token_address: ContractAddress) -> u64; - fn get_current_spending_limit(self: @TContractState, token_address: ContractAddress) -> u256; - fn get_spending_limit(self: @TContractState, token_address: ContractAddress) -> u256; -} - -#[derive(Copy, Drop, Serde, starknet::Store)] -struct SpendingLimit { - exists: bool, - timestamp: u64, - limit: u256, -} - -#[starknet::contract(account)] -mod Account { - use super::{ - ISRC6, ISRC5, IDeployableAccount, IDeclarerAccount, ISpendingLimitsAccount, SpendingLimit - }; - use starknet::{ - ContractAddress, get_caller_address, get_tx_info, VALIDATED, get_block_timestamp, - get_contract_address, account::Call, syscalls::call_contract_syscall - }; - use starknet::storage::{ - Map, StorageMapReadAccess, StorageMapWriteAccess, StoragePointerReadAccess, - StoragePointerWriteAccess - }; - use core::num::traits::Zero; - - #[storage] - struct Storage { - public_key: felt252, - spending_limit: Map, - current_spending_limit: Map, - time_limit: u64, - } - const SRC6_TRAIT_ID: felt252 = - 1270010605630597976495846281167968799381097569185364931397797212080166453709; - - pub mod Selectors { - pub const TRANSFER: felt252 = - 0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e; - pub const APPROVE: felt252 = - 0x0219209e083275171774dab1df80982e9df2096516f06319c5c6d71ae0a8480c; - } - - pub mod Errors { - pub const INVALID_CALLER: felt252 = 'Account: Invalid caller'; - pub const INVALID_SIGNATURE: felt252 = 'Account: Invalid tx signature'; - pub const INVALID_TX_VERSION: felt252 = 'Account: Invalid tx version'; - pub const UNAUTHORIZED: felt252 = 'Account: Unauthorized'; - } - - // time_limit is in seconds - #[constructor] - fn constructor(ref self: ContractState, public_key: felt252, time_limit: u64) { - self.public_key.write(public_key); - self.time_limit.write(time_limit); - } - - // - // External - // - - #[abi(embed_v0)] - impl SRC6 of ISRC6 { - fn __execute__(ref self: ContractState, mut calls: Array) -> Array> { - self.only_protocol(); - - let mut res = array![]; - for call in calls { - let Call { to, selector, calldata } = call; - - let limit_exists: bool = self.spending_limit.read(to).exists; - if (self.is_spending_tx(selector) && limit_exists) { - let low: u128 = (*calldata[1]).try_into().unwrap(); - let high: u128 = (*calldata[2]).try_into().unwrap(); - let value: u256 = u256 { low, high }; - - let mut current_limit: u256 = self.get_spending_limit(to); - current_limit -= value; - self.current_spending_limit.write(to, current_limit); - self.update_timestamp(to); - } - - let syscall_res = call_contract_syscall(to, selector, calldata).unwrap_syscall(); - res.append(syscall_res); - }; - res - } - - fn __validate__(self: @ContractState, calls: Array) -> felt252 { - self.only_protocol(); - self.validate_transaction() - } - - fn is_valid_signature( - self: @ContractState, hash: felt252, signature: Array - ) -> felt252 { - let is_valid = self._is_valid_signature(hash, signature.span()); - if is_valid { - VALIDATED - } else { - 0 - } - } - } - - #[abi(embed_v0)] - impl SRC5 of ISRC5 { - fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { - interface_id == SRC6_TRAIT_ID - } - } - - #[abi(embed_v0)] - impl DeployableAccount of IDeployableAccount { - fn __validate_deploy__( - self: @ContractState, class_hash: felt252, salt: felt252, public_key: felt252 - ) -> felt252 { - self.only_protocol(); - self.validate_transaction() - } - } - - #[abi(embed_v0)] - impl DeclarerAccount of IDeclarerAccount { - fn __validate_declare__(self: @ContractState, class_hash: felt252) -> felt252 { - self.only_protocol(); - self.validate_transaction() - } - } - - #[abi(embed_v0)] - impl SpendingLimitsAccount of ISpendingLimitsAccount { - fn public_key(self: @ContractState) -> felt252 { - self.public_key.read() - } - - fn get_time_limit(self: @ContractState) -> u64 { - self.time_limit.read() - } - - fn set_spending_limit( - ref self: ContractState, token_address: ContractAddress, _limit: u256 - ) { - assert(get_caller_address() == get_contract_address(), 'Invalid caller'); - let timemstamp = get_block_timestamp(); - let new_limit: SpendingLimit = SpendingLimit { - exists: true, limit: _limit, timestamp: timemstamp - }; - self.spending_limit.write(token_address, new_limit); - self.current_spending_limit.write(token_address, _limit); - } - - fn get_current_spending_limit( - self: @ContractState, token_address: ContractAddress - ) -> u256 { - self.current_spending_limit.read(token_address) - } - - fn get_spending_limit_timestamp( - self: @ContractState, token_address: ContractAddress - ) -> u64 { - self.spending_limit.read(token_address).timestamp - } - - fn get_spending_limit(self: @ContractState, token_address: ContractAddress) -> u256 { - let spending_limit = self.spending_limit.read(token_address); - let time_limit: u64 = self.time_limit.read(); - let current_timestamp: u64 = get_block_timestamp(); - - if ((spending_limit.timestamp + time_limit) >= current_timestamp) { - self.current_spending_limit.read(token_address) - } else { - spending_limit.limit - } - } - } - - #[generate_trait] - impl PrivateImpl of PrivateTrait { - fn only_protocol(self: @ContractState) { - let sender = get_caller_address(); - assert(sender.is_zero(), Errors::INVALID_CALLER); - } - - // If the current block timestamp is past the time_limit, - // The max new limit set by the account owner is written to the current spending limit. - // And the current timestamp is updated. - fn update_timestamp(ref self: ContractState, token_address: ContractAddress) { - let mut spending_limit = self.spending_limit.read(token_address); - let current_timestamp: u64 = get_block_timestamp(); - let time_limit: u64 = self.time_limit.read(); - let timestamp: u64 = spending_limit.timestamp; - - if ((timestamp + time_limit) < current_timestamp) { - spending_limit.timestamp = current_timestamp; - self.spending_limit.write(token_address, spending_limit); - } - } - - fn is_spending_tx(ref self: ContractState, selector: felt252) -> bool { - selector == Selectors::TRANSFER || selector == Selectors::APPROVE - } - - fn _is_valid_signature( - self: @ContractState, hash: felt252, signature: Span - ) -> bool { - if signature.len() == 2_u32 { - core::ecdsa::check_ecdsa_signature( - hash, self.public_key.read(), *signature.at(0_u32), *signature.at(1_u32) - ) - } else { - false - } - } - - fn validate_transaction(self: @ContractState) -> felt252 { - let tx_info = get_tx_info().unbox(); - let tx_hash = tx_info.transaction_hash; - let signature = tx_info.signature; - - assert(self._is_valid_signature(tx_hash, signature), Errors::INVALID_SIGNATURE); - VALIDATED - } - } -} diff --git a/listings/advanced-concepts/account_spending_limits/src/erc20.cairo b/listings/advanced-concepts/account_spending_limits/src/erc20.cairo deleted file mode 100644 index 91a7fbc8..00000000 --- a/listings/advanced-concepts/account_spending_limits/src/erc20.cairo +++ /dev/null @@ -1,40 +0,0 @@ -#[starknet::contract] -mod MyERC20Token { - use openzeppelin::token::erc20::ERC20Component; - use starknet::ContractAddress; - - component!(path: ERC20Component, storage: erc20, event: ERC20Event); - - #[abi(embed_v0)] - impl ERC20Impl = ERC20Component::ERC20Impl; - #[abi(embed_v0)] - impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl; - #[abi(embed_v0)] - impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl; - impl InternalImpl = ERC20Component::InternalImpl; - - #[storage] - struct Storage { - #[substorage(v0)] - erc20: ERC20Component::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC20Event: ERC20Component::Event - } - - #[constructor] - fn constructor( - ref self: ContractState, - name: felt252, - symbol: felt252, - fixed_supply: u256, - recipient: ContractAddress - ) { - self.erc20.initializer(name, symbol); - self.erc20._mint(recipient, fixed_supply); - } -} diff --git a/listings/advanced-concepts/account_spending_limits/src/lib.cairo b/listings/advanced-concepts/account_spending_limits/src/lib.cairo deleted file mode 100644 index 370ce69b..00000000 --- a/listings/advanced-concepts/account_spending_limits/src/lib.cairo +++ /dev/null @@ -1,2 +0,0 @@ -mod account; -mod erc20; diff --git a/listings/advanced-concepts/account_spending_limits/tests/aa.cairo b/listings/advanced-concepts/account_spending_limits/tests/aa.cairo deleted file mode 100644 index f0e41c4a..00000000 --- a/listings/advanced-concepts/account_spending_limits/tests/aa.cairo +++ /dev/null @@ -1,217 +0,0 @@ -use core::option::OptionTrait; -use core::traits::TryInto; -use core::traits::Into; -use starknet::{ContractAddress, contract_address_const, account::Call}; -use core::integer::{U64IntoFelt252}; - -use snforge_std::{ - declare, ContractClassTrait, start_mock_call, stop_mock_call, start_cheat_caller_address, - stop_cheat_caller_address, start_cheat_block_timestamp, stop_cheat_block_timestamp -}; -use snforge_std::signature::KeyPairTrait; -use snforge_std::signature::stark_curve::{ - StarkCurveKeyPairImpl, StarkCurveSignerImpl, StarkCurveVerifierImpl -}; -use super::utils::{ - deploy_account_contract, deploy_erc20_contract, create_transfer_call, create_approve_call, - declare_erc20_contract, deploy_declared_erc20 -}; - -use aa_tutorial::standard_account::IAccountDispatcher; -use aa_tutorial::standard_account::IAccountDispatcherTrait; -use aa_tutorial::standard_account::IAccountSafeDispatcher; -use aa_tutorial::standard_account::IAccountSafeDispatcherTrait; - -use openzeppelin::token::erc20::interface::IERC20Dispatcher; -use openzeppelin::token::erc20::interface::IERC20DispatcherTrait; - -#[test] -fn check_stored_pub_key() { - let public_key = 999; - let limit = 1000000000000000; //0.001 * 10 ** 18 - let contract_address = deploy_account_contract(public_key, limit); - let dispatcher = IAccountDispatcher { contract_address }; - let stored_pub_key = dispatcher.public_key(); - assert(public_key == stored_pub_key, 'Wrong pub key'); -} - -#[test] -fn check_stored_time_limit() { - let mut signer = KeyPairTrait::::from_secret_key(123); - let time_limit = 600; //600 seconds - 10 minutes - let contract_address = deploy_account_contract(signer.public_key, time_limit); - let dispatcher = IAccountDispatcher { contract_address }; - - let stored_time_limit = dispatcher.get_time_limit(); - - assert(time_limit == stored_time_limit, 'Time limit wrong'); -} - -#[test] -fn check_stored_spending_limit() { - let mut signer = KeyPairTrait::::from_secret_key(123); - let time_limit = 600; - let spending_limit = 1000000000000000; //0.001 * 10 ** 18 - let contract_address = deploy_account_contract(signer.public_key, time_limit); - let dispatcher = IAccountDispatcher { contract_address }; - - let mock_token_address: ContractAddress = contract_address_const::<1121321>(); - dispatcher.set_spending_limit(mock_token_address, spending_limit); - let stored_spending_limit = dispatcher.get_spending_limit(mock_token_address); - - //Will revert after time_limit seconds have passed. - assert(stored_spending_limit == spending_limit, 'Wrong spending limit'); -} - -#[test] -fn check_spending_limit_after_transfer() { - let mut signer = KeyPairTrait::::from_secret_key(123); - let time_limit = 600; - let spending_limit = 10000000000000000; //0.01 * 10 ** 18 - let account_address = deploy_account_contract(signer.public_key, time_limit); - let token_address = deploy_erc20_contract( - 'MyToken', 'MTK', 10000000000000000000, account_address - ); //Pre-mints 10 MTK. - - let account_dispatcher = IAccountDispatcher { contract_address: account_address }; - - account_dispatcher.set_spending_limit(token_address, spending_limit); - let mock_account_address = contract_address_const::< - 0x067981c7f9f55bcbdd4e0d0a9c5bbcea77dacb42cccbf13554a847d6353f728e - >(); - let transfer_value: u256 = 1000000000000000; //0.001 MTK - - let transferCall = create_transfer_call(token_address, mock_account_address, transfer_value); - - start_cheat_caller_address(account_address, 0.try_into().unwrap()); - account_dispatcher.__execute__(array![transferCall]); - stop_cheat_caller_address(account_address); - - let remaining_limit = account_dispatcher.get_spending_limit(token_address); - println!("Remaining limit: {}", remaining_limit); - let current_limit = account_dispatcher.get_current_spending_limit(token_address); - println!("Remaining current limit: {}", current_limit); - - assert(remaining_limit == (spending_limit - transfer_value), 'Spending limit wrong'); -} - -#[test] -fn spending_limit_after_time_limit() { - let mut signer = KeyPairTrait::::from_secret_key(123); - let time_limit = 600; - let spending_limit = 10000000000000000; //0.01 * 10 ** 18 - let account_address = deploy_account_contract(signer.public_key, time_limit); - let token_address = deploy_erc20_contract( - 'MyToken', 'MTK', 10000000000000000000, account_address - ); //Pre-mints 10 MTK. - - let account_dispatcher = IAccountDispatcher { contract_address: account_address }; - - let start_timestamp = 1000; - start_cheat_block_timestamp(account_address, start_timestamp); - account_dispatcher.set_spending_limit(token_address, spending_limit); - stop_cheat_block_timestamp(account_address); - let mock_account_address = contract_address_const::<123456789>(); - let transfer_value: u256 = 1000000000000000; //0.001 MTK - - let transferCall1 = create_transfer_call(token_address, mock_account_address, transfer_value); - - start_cheat_caller_address(account_address, 0.try_into().unwrap()); - account_dispatcher.__execute__(array![transferCall1]); - - let new_timestamp = start_timestamp + time_limit + 10; - start_cheat_block_timestamp(account_address, new_timestamp); - let new_limit = account_dispatcher.get_spending_limit(token_address); - assert(new_limit == spending_limit, 'Spending limit wrong'); - - let transferCall2 = create_transfer_call(token_address, mock_account_address, transfer_value); - account_dispatcher.__execute__(array![transferCall2]); - - let spending_limit_timestamp = account_dispatcher.get_spending_limit_timestamp(token_address); - stop_cheat_block_timestamp(account_address); - - assert(spending_limit_timestamp == new_timestamp, 'Timestamp not updated'); -} - -#[test] -fn multicall_spending_limit() { - let mut signer = KeyPairTrait::::from_secret_key(123); - let time_limit = 600; - let spending_limit = 10000000000000000; //0.01 * 10 ** 18 - let account_address = deploy_account_contract(signer.public_key, time_limit); - let erc20_class = declare_erc20_contract(); - - let token_address1 = deploy_declared_erc20( - erc20_class, 'MyToken', 'MTK', 10000000000000000000, account_address - ); //Pre-mints 10 MTK. - let token_address2 = deploy_declared_erc20( - erc20_class, 'MyTokenTest', 'MTKT', 10000000000000000000, account_address - ); //Pre-mints 10 MTK1. - let account_dispatcher = IAccountDispatcher { contract_address: account_address }; - - let transfer_value: u256 = 1000000000000000; //0.001 MTK - let approve_value: u256 = 5000000000000000; //0.005 MTK - - let mock_account_address = contract_address_const::<123456789>(); - let transferCall_1 = create_transfer_call(token_address1, mock_account_address, transfer_value); - let approveCall_1 = create_approve_call(token_address1, mock_account_address, approve_value); - let approveCall_2 = create_approve_call(token_address2, mock_account_address, approve_value); - let start_timestamp_1 = 1000; - let start_timestamp_2 = 1200; - start_cheat_block_timestamp(account_address, start_timestamp_1); - account_dispatcher.set_spending_limit(token_address1, spending_limit); - stop_cheat_block_timestamp(account_address); - - start_cheat_block_timestamp(account_address, start_timestamp_2); - account_dispatcher.set_spending_limit(token_address2, spending_limit); - stop_cheat_block_timestamp(account_address); - - start_cheat_caller_address(account_address, 0.try_into().unwrap()); - account_dispatcher.__execute__(array![transferCall_1, approveCall_1, approveCall_2]); - - let spending_limit_1 = account_dispatcher.get_spending_limit(token_address1); - let spending_limit_2 = account_dispatcher.get_spending_limit(token_address2); - assert( - spending_limit_1 == (spending_limit - (approve_value + transfer_value)), - 'Multicall limit wrong' - ); - assert(spending_limit_2 == (spending_limit - approve_value), 'Token2 limit wrong'); - - start_cheat_block_timestamp(account_address, start_timestamp_2 + time_limit + 150); - let transferCall_2 = create_transfer_call(token_address2, mock_account_address, transfer_value); - account_dispatcher.__execute__(array![transferCall_2]); - stop_cheat_block_timestamp(account_address); - let spending_limit_21 = account_dispatcher.get_spending_limit(token_address2); - println!("spending_limit_21: {}", spending_limit_21); - assert(spending_limit_21 == (spending_limit - transfer_value), 'Spending limit wrong'); - stop_cheat_caller_address(account_address); -} - -#[test] -#[should_panic(expected: ('u256_sub Overflow',))] -fn check_over_spending_limit() { - let mut signer = KeyPairTrait::::from_secret_key(123); - let time_limit = 600; - let spending_limit = 10000000000000000; //0.01 * 10 ** 18 - let account_address = deploy_account_contract(signer.public_key, time_limit); - let token_address = deploy_erc20_contract( - 'MyToken', 'MTK', 10000000000000000000, account_address - ); //Pre-mints 10 MTK. - let mock_account_address = contract_address_const::<123456789>(); - - let account_dispatcher = IAccountDispatcher { contract_address: account_address }; - - let start_timestamp = 1000; - let approve_value = 11000000000000000; // 0.0011 * 10 ** 18 - - start_cheat_block_timestamp(account_address, start_timestamp); - account_dispatcher.set_spending_limit(token_address, spending_limit); - stop_cheat_block_timestamp(account_address); - - start_cheat_caller_address(account_address, 0.try_into().unwrap()); - let approveCall = create_approve_call(token_address, mock_account_address, approve_value); - start_cheat_block_timestamp(account_address, start_timestamp + 500); - account_dispatcher.__execute__(array![approveCall]); - stop_cheat_block_timestamp(account_address); - stop_cheat_caller_address(account_address); -} diff --git a/listings/advanced-concepts/account_spending_limits/tests/lib.cairo b/listings/advanced-concepts/account_spending_limits/tests/lib.cairo deleted file mode 100644 index b0d4a61d..00000000 --- a/listings/advanced-concepts/account_spending_limits/tests/lib.cairo +++ /dev/null @@ -1,2 +0,0 @@ -mod utils; -mod aa; diff --git a/listings/advanced-concepts/account_spending_limits/tests/utils.cairo b/listings/advanced-concepts/account_spending_limits/tests/utils.cairo deleted file mode 100644 index da6d200b..00000000 --- a/listings/advanced-concepts/account_spending_limits/tests/utils.cairo +++ /dev/null @@ -1,65 +0,0 @@ -use core::result::ResultTrait; -use starknet::{ContractAddress, account::Call, contract_address_const}; -use core::integer::{U64IntoFelt252, U256TryIntoFelt252}; - -use snforge_std::{declare, ContractClassTrait, ContractClass}; - -fn deploy_account_contract(public_key: felt252, time_limit: u64) -> ContractAddress { - let contract = declare("Account").unwrap(); - let time_limit_felt252: felt252 = U64IntoFelt252::into(time_limit); - let constructor_args = array![public_key, time_limit_felt252]; - let (contract_address, _) = contract.deploy(@constructor_args).unwrap(); - contract_address -} - -fn deploy_erc20_contract( - name: felt252, symbol: felt252, fixed_supply: u256, recipient: ContractAddress -) -> ContractAddress { - let contract = declare("MyERC20Token").unwrap(); - let constructor_args = array![ - name, symbol, fixed_supply.low.into(), fixed_supply.high.into(), recipient.into() - ]; - - let (contract_address, _) = contract.deploy(@constructor_args).unwrap(); - contract_address -} - -fn declare_erc20_contract() -> ContractClass { - declare("MyERC20Token").unwrap() -} - -fn deploy_declared_erc20( - class: ContractClass, - name: felt252, - symbol: felt252, - fixed_supply: u256, - recipient: ContractAddress -) -> ContractAddress { - let constructor_args = array![ - name, symbol, fixed_supply.low.into(), fixed_supply.high.into(), recipient.into() - ]; - - let (contract_address, _) = class.deploy(@constructor_args).unwrap(); - contract_address -} - - -fn create_transfer_call( - token_address: ContractAddress, recipient: ContractAddress, value: u256 -) -> Call { - return Call { - to: token_address, - selector: selector!("transfer"), - calldata: array![recipient.into(), value.low.into(), value.high.into()].span(), - }; -} - -fn create_approve_call( - token_address: ContractAddress, allowed_address: ContractAddress, value: u256 -) -> Call { - return Call { - to: token_address, - selector: selector!("approve"), - calldata: array![allowed_address.into(), value.low.into(), value.high.into()].span(), - }; -} diff --git a/listings/advanced-concepts/simple_account/Scarb.toml b/listings/advanced-concepts/simple_account/Scarb.toml index 4c2912fd..b5c917e4 100644 --- a/listings/advanced-concepts/simple_account/Scarb.toml +++ b/listings/advanced-concepts/simple_account/Scarb.toml @@ -5,7 +5,8 @@ edition.workspace = true [dependencies] starknet.workspace = true -openzeppelin.workspace = true +openzeppelin_account.workspace = true +openzeppelin_introspection.workspace = true [scripts] test.workspace = true diff --git a/listings/advanced-concepts/simple_account/src/simple_account.cairo b/listings/advanced-concepts/simple_account/src/simple_account.cairo index f1e1386b..06e5350c 100644 --- a/listings/advanced-concepts/simple_account/src/simple_account.cairo +++ b/listings/advanced-concepts/simple_account/src/simple_account.cairo @@ -18,8 +18,8 @@ mod simpleAccount { use starknet::storage::{StoragePointerWriteAccess, StoragePointerReadAccess}; // Implement SRC5 with openzeppelin - use openzeppelin::account::interface; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_account::interface; + use openzeppelin_introspection::src5::SRC5Component; component!(path: SRC5Component, storage: src5, event: SRC5Event); #[abi(embed_v0)] diff --git a/listings/applications/coin_flip/Scarb.toml b/listings/applications/coin_flip/Scarb.toml index c59791c8..0335ca5a 100644 --- a/listings/applications/coin_flip/Scarb.toml +++ b/listings/applications/coin_flip/Scarb.toml @@ -5,10 +5,11 @@ edition.workspace = true [dependencies] starknet.workspace = true -openzeppelin.workspace = true +openzeppelin_token.workspace = true pragma_lib.workspace = true [dev-dependencies] +openzeppelin_presets.workspace = true assert_macros.workspace = true snforge_std.workspace = true diff --git a/listings/applications/coin_flip/src/contract.cairo b/listings/applications/coin_flip/src/contract.cairo index 74fec7b3..279f1bbf 100644 --- a/listings/applications/coin_flip/src/contract.cairo +++ b/listings/applications/coin_flip/src/contract.cairo @@ -25,7 +25,7 @@ pub mod CoinFlip { Map, StoragePointerReadAccess, StoragePathEntry, StoragePointerWriteAccess, }; use pragma_lib::abi::{IRandomnessDispatcher, IRandomnessDispatcherTrait}; - use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; + use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; #[storage] struct Storage { diff --git a/listings/applications/coin_flip/src/mock_randomness.cairo b/listings/applications/coin_flip/src/mock_randomness.cairo index 493be34a..2df7267a 100644 --- a/listings/applications/coin_flip/src/mock_randomness.cairo +++ b/listings/applications/coin_flip/src/mock_randomness.cairo @@ -8,7 +8,7 @@ pub mod MockRandomness { }; use core::num::traits::zero::Zero; use coin_flip::contract::{IPragmaVRFDispatcher, IPragmaVRFDispatcherTrait}; - use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; + use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; #[storage] struct Storage { diff --git a/listings/applications/coin_flip/src/tests.cairo b/listings/applications/coin_flip/src/tests.cairo index 74bb63e9..2c7d71ac 100644 --- a/listings/applications/coin_flip/src/tests.cairo +++ b/listings/applications/coin_flip/src/tests.cairo @@ -6,7 +6,7 @@ use snforge_std::{ declare, start_cheat_caller_address, stop_cheat_caller_address, spy_events, EventSpyAssertionsTrait, DeclareResultTrait, ContractClassTrait, }; -use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; +use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; use pragma_lib::abi::{IRandomnessDispatcher, IRandomnessDispatcherTrait}; fn deploy() -> (ICoinFlipDispatcher, IRandomnessDispatcher, IERC20Dispatcher, ContractAddress) { diff --git a/listings/applications/constant_product_amm/Scarb.toml b/listings/applications/constant_product_amm/Scarb.toml index 0d57dce7..40ee6d1c 100644 --- a/listings/applications/constant_product_amm/Scarb.toml +++ b/listings/applications/constant_product_amm/Scarb.toml @@ -5,7 +5,7 @@ edition.workspace = true [dependencies] starknet.workspace = true -openzeppelin.workspace = true +openzeppelin_token.workspace = true [dev-dependencies] cairo_test.workspace = true diff --git a/listings/applications/constant_product_amm/src/contracts.cairo b/listings/applications/constant_product_amm/src/contracts.cairo index 9b203a8a..9927318b 100644 --- a/listings/applications/constant_product_amm/src/contracts.cairo +++ b/listings/applications/constant_product_amm/src/contracts.cairo @@ -11,7 +11,7 @@ pub trait IConstantProductAmm { #[starknet::contract] pub mod ConstantProductAmm { use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; - use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; + use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; use starknet::{ContractAddress, get_caller_address, get_contract_address}; use starknet::storage::{Map, StorageMapReadAccess, StorageMapWriteAccess}; use core::num::traits::Sqrt; diff --git a/listings/applications/constant_product_amm/src/tests.cairo b/listings/applications/constant_product_amm/src/tests.cairo index e1d1970a..aefc4869 100644 --- a/listings/applications/constant_product_amm/src/tests.cairo +++ b/listings/applications/constant_product_amm/src/tests.cairo @@ -1,6 +1,6 @@ #[starknet::contract] pub mod ERC20Token { - use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; use starknet::ContractAddress; component!(path: ERC20Component, storage: erc20, event: ERC20Event); @@ -38,10 +38,10 @@ pub mod ERC20Token { // Wait for OZ #953 fix // mod tests { // use super::ERC20Token; -// use openzeppelin::token::erc20::{interface::IERC20Dispatcher, +// use openzeppelin_token::erc20::{interface::IERC20Dispatcher, // interface::IERC20DispatcherTrait}; -// use openzeppelin::tests::utils; -// use openzeppelin::utils::serde::SerializedAppend; +// use openzeppelin_tests::utils; +// use openzeppelin_utils::serde::SerializedAppend; // use constant_product_amm::contracts::{ // ConstantProductAmm, IConstantProductAmmDispatcher, IConstantProductAmmDispatcherTrait diff --git a/listings/applications/crowdfunding/Scarb.toml b/listings/applications/crowdfunding/Scarb.toml index ae5131d4..0352decb 100644 --- a/listings/applications/crowdfunding/Scarb.toml +++ b/listings/applications/crowdfunding/Scarb.toml @@ -7,7 +7,8 @@ edition.workspace = true [dependencies] starknet.workspace = true -openzeppelin.workspace = true +openzeppelin_token.workspace = true +openzeppelin_presets.workspace = true components.workspace = true [dev-dependencies] diff --git a/listings/applications/crowdfunding/src/campaign.cairo b/listings/applications/crowdfunding/src/campaign.cairo index 684093f7..3bec46eb 100644 --- a/listings/applications/crowdfunding/src/campaign.cairo +++ b/listings/applications/crowdfunding/src/campaign.cairo @@ -35,7 +35,7 @@ pub mod Campaign { use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; use components::ownable::ownable_component::OwnableInternalTrait; use core::num::traits::Zero; - use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; + use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; use starknet::{ ClassHash, ContractAddress, get_block_timestamp, get_caller_address, get_contract_address, }; diff --git a/listings/applications/crowdfunding/src/mock_upgrade.cairo b/listings/applications/crowdfunding/src/mock_upgrade.cairo index ee89427c..952cd9a0 100644 --- a/listings/applications/crowdfunding/src/mock_upgrade.cairo +++ b/listings/applications/crowdfunding/src/mock_upgrade.cairo @@ -3,7 +3,7 @@ pub mod MockUpgrade { use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; use components::ownable::ownable_component::OwnableInternalTrait; use core::num::traits::Zero; - use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; + use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; use starknet::{ ClassHash, ContractAddress, get_block_timestamp, get_caller_address, get_contract_address, }; diff --git a/listings/applications/crowdfunding/src/tests.cairo b/listings/applications/crowdfunding/src/tests.cairo index 57f0ecec..bbbbd3e9 100644 --- a/listings/applications/crowdfunding/src/tests.cairo +++ b/listings/applications/crowdfunding/src/tests.cairo @@ -7,7 +7,7 @@ use snforge_std::{ use crowdfunding::campaign::{Campaign, ICampaignDispatcher, ICampaignDispatcherTrait}; use components::ownable::{IOwnableDispatcher, IOwnableDispatcherTrait}; -use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; +use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; /// Deploy a campaign contract with the provided data fn deploy( diff --git a/listings/applications/staking/Scarb.toml b/listings/applications/staking/Scarb.toml index 8479363a..0ca59f05 100644 --- a/listings/applications/staking/Scarb.toml +++ b/listings/applications/staking/Scarb.toml @@ -5,7 +5,7 @@ edition.workspace = true [dependencies] starknet.workspace = true -openzeppelin.workspace = true +openzeppelin_token.workspace = true [dev-dependencies] cairo_test.workspace = true diff --git a/listings/applications/staking/src/contract.cairo b/listings/applications/staking/src/contract.cairo index 7cebd961..155d4b5f 100644 --- a/listings/applications/staking/src/contract.cairo +++ b/listings/applications/staking/src/contract.cairo @@ -25,7 +25,7 @@ pub mod StakingContract { use core::starknet::event::EventEmitter; use core::num::traits::Zero; use starknet::{ContractAddress, get_caller_address, get_block_timestamp, get_contract_address}; - use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; + use openzeppelin_token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; use starknet::storage::{ Map, StorageMapReadAccess, StorageMapWriteAccess, StoragePointerReadAccess, StoragePointerWriteAccess, diff --git a/listings/applications/staking/src/tests/staking_tests.cairo b/listings/applications/staking/src/tests/staking_tests.cairo index 50d95f5e..906e16ac 100644 --- a/listings/applications/staking/src/tests/staking_tests.cairo +++ b/listings/applications/staking/src/tests/staking_tests.cairo @@ -1,13 +1,13 @@ mod tests { - use openzeppelin::token::erc20::interface::IERC20DispatcherTrait; - use openzeppelin::token::erc20::erc20::ERC20Component::InternalTrait; + use openzeppelin_token::erc20::interface::IERC20DispatcherTrait; + use openzeppelin_token::erc20::erc20::ERC20Component::InternalTrait; use staking::contract::IStakingContractDispatcherTrait; use staking::tests::tokens::{RewardToken, StakingToken}; use staking::contract::{ StakingContract, IStakingContractDispatcher, StakingContract::Event, StakingContract::Deposit, StakingContract::Withdrawal, StakingContract::RewardsFinished, }; - use openzeppelin::token::erc20::{interface::IERC20Dispatcher}; + use openzeppelin_token::erc20::{interface::IERC20Dispatcher}; use starknet::syscalls::deploy_syscall; use core::serde::Serde; use starknet::testing::{set_contract_address, set_block_timestamp, pop_log}; diff --git a/listings/applications/staking/src/tests/tokens.cairo b/listings/applications/staking/src/tests/tokens.cairo index 89e1a4bd..8effd5fa 100644 --- a/listings/applications/staking/src/tests/tokens.cairo +++ b/listings/applications/staking/src/tests/tokens.cairo @@ -1,6 +1,6 @@ #[starknet::contract] pub mod RewardToken { - use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; use starknet::ContractAddress; component!(path: ERC20Component, storage: erc20, event: ERC20Event); @@ -37,7 +37,7 @@ pub mod RewardToken { #[starknet::contract] pub mod StakingToken { - use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; use starknet::ContractAddress; component!(path: ERC20Component, storage: erc20, event: ERC20Event); diff --git a/listings/applications/timelock/Scarb.toml b/listings/applications/timelock/Scarb.toml index 9ccf8c4e..5118d351 100644 --- a/listings/applications/timelock/Scarb.toml +++ b/listings/applications/timelock/Scarb.toml @@ -5,7 +5,9 @@ edition.workspace = true [dependencies] starknet.workspace = true -openzeppelin.workspace = true +openzeppelin_utils.workspace = true +openzeppelin_token.workspace = true +openzeppelin_introspection.workspace = true components.workspace = true [dev-dependencies] diff --git a/listings/applications/timelock/src/erc721.cairo b/listings/applications/timelock/src/erc721.cairo index 36ae6448..ca68cd53 100644 --- a/listings/applications/timelock/src/erc721.cairo +++ b/listings/applications/timelock/src/erc721.cairo @@ -1,8 +1,8 @@ #[starknet::contract] pub mod ERC721 { use starknet::ContractAddress; - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl}; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc721::{ERC721Component, ERC721HooksEmptyImpl}; component!(path: ERC721Component, storage: erc721, event: ERC721Event); component!(path: SRC5Component, storage: src5, event: SRC5Event); diff --git a/listings/applications/timelock/src/tests/timelock.cairo b/listings/applications/timelock/src/tests/timelock.cairo index bfc1893e..79c09921 100644 --- a/listings/applications/timelock/src/tests/timelock.cairo +++ b/listings/applications/timelock/src/tests/timelock.cairo @@ -5,8 +5,8 @@ use core::hash::HashStateTrait; use snforge_std::{ cheat_caller_address, cheat_block_timestamp, CheatSpan, spy_events, EventSpyAssertionsTrait, }; -use openzeppelin::token::erc721::interface::IERC721DispatcherTrait; -use openzeppelin::token::erc721::erc721::ERC721Component; +use openzeppelin_token::erc721::interface::IERC721DispatcherTrait; +use openzeppelin_token::erc721::erc721::ERC721Component; use components::ownable; use timelock::timelock::{TimeLock, ITimeLockDispatcherTrait, ITimeLockSafeDispatcherTrait}; use timelock::tests::utils::{TimeLockTestTrait, TOKEN_ID, OTHER}; diff --git a/listings/applications/timelock/src/tests/utils.cairo b/listings/applications/timelock/src/tests/utils.cairo index f380b445..adf9989e 100644 --- a/listings/applications/timelock/src/tests/utils.cairo +++ b/listings/applications/timelock/src/tests/utils.cairo @@ -1,8 +1,8 @@ use starknet::{ContractAddress, contract_address_const, get_block_timestamp}; use starknet::account::Call; use snforge_std::{declare, ContractClassTrait, test_address, DeclareResultTrait}; -use openzeppelin::utils::serde::SerializedAppend; -use openzeppelin::token::erc721::interface::IERC721Dispatcher; +use openzeppelin_utils::serde::SerializedAppend; +use openzeppelin_token::erc721::interface::IERC721Dispatcher; use timelock::timelock::{TimeLock, ITimeLockDispatcher, ITimeLockSafeDispatcher}; pub const TOKEN_ID: u256 = 1; diff --git a/listings/applications/upgradeable_contract/src/lib.cairo b/listings/applications/upgradeable_contract/src/lib.cairo index a9f2793d..6cd3b9f3 100644 --- a/listings/applications/upgradeable_contract/src/lib.cairo +++ b/listings/applications/upgradeable_contract/src/lib.cairo @@ -1,5 +1,5 @@ -mod upgradeable_contract_v0; -mod upgradeable_contract_v1; +pub mod upgradeable_contract_v0; +pub mod upgradeable_contract_v1; #[cfg(test)] mod tests; diff --git a/listings/applications/upgradeable_contract/src/tests.cairo b/listings/applications/upgradeable_contract/src/tests.cairo index fe9f11a6..88e91a16 100644 --- a/listings/applications/upgradeable_contract/src/tests.cairo +++ b/listings/applications/upgradeable_contract/src/tests.cairo @@ -1,25 +1,20 @@ mod tests { use starknet::class_hash::ClassHash; - use super::super::upgradeable_contract_v0::{ + use crate::upgradeable_contract_v0::{ UpgradeableContract_V0, IUpgradeableContractDispatcher as IUpgradeableContractDispatcher_v0, IUpgradeableContractDispatcherTrait as UpgradeableContractDispatcherTrait_v0, UpgradeableContract_V0::{Event, Upgraded}, }; - use super::super::upgradeable_contract_v1::{ + use crate::upgradeable_contract_v1::{ UpgradeableContract_V1, IUpgradeableContractDispatcher as IUpgradeableContractDispatcher_v1, - IUpgradeableContractDispatcherTrait as UpgradeableContractDispatcherTrait_v1, }; - use starknet::{ - ContractAddress, syscalls::deploy_syscall, get_caller_address, contract_address_const, - }; + use starknet::{ContractAddress, syscalls::deploy_syscall}; use core::num::traits::Zero; - use starknet::testing::{set_contract_address, set_account_contract_address}; - // deploy v0 contract fn deploy_v0() -> (IUpgradeableContractDispatcher_v0, ContractAddress, ClassHash) { let (contract_address, _) = deploy_syscall( diff --git a/pages/applications/erc20.md b/pages/applications/erc20.md index 85970633..07120417 100644 --- a/pages/applications/erc20.md +++ b/pages/applications/erc20.md @@ -17,4 +17,4 @@ Here's an implementation of the ERC20 interface in Cairo: // [!include ~/listings/applications/erc20/src/token.cairo:erc20] ``` -There's several other implementations, such as the [Open Zeppelin](https://docs.openzeppelin.com/contracts-cairo/0.7.0/erc20) or the [Cairo By Example](https://cairo-by-example.com/examples/erc20/) ones. +There's several other implementations, such as the [Open Zeppelin](https://docs.openzeppelin.com/contracts-cairo/1.0.0/erc20) or the [Cairo By Example](https://cairo-by-example.com/examples/erc20/) ones. diff --git a/pages/applications/random_number_generator.md b/pages/applications/random_number_generator.md index a226127f..e42ce30e 100644 --- a/pages/applications/random_number_generator.md +++ b/pages/applications/random_number_generator.md @@ -53,7 +53,7 @@ There are other ways to generate randomness on-chain, for more information read ## CoinFlip using Pragma VRF -Below is an implementation of a `CoinFlip` contract that utilizes a [Pragma Verifiable Random Function (VRF)](https://docs.pragma.build/Resources/Cairo%201/randomness/randomness) to generate random numbers on-chain. +Below is an implementation of a `CoinFlip` contract that utilizes a [Pragma Verifiable Random Function (VRF)](https://docs.pragma.build/v1/Resources/randomness/randomness) to generate random numbers on-chain. - Players can flip a virtual coin and receive a random outcome of `Heads` or `Tails` - The contract needs to be funded with enough ETH to perform the necessary operations, including paying fees to Pragma's Randomness Oracle which returns a random value diff --git a/pages/applications/simple_storage_starknetjs.md b/pages/applications/simple_storage_starknetjs.md index 4c12abcd..0baa5922 100644 --- a/pages/applications/simple_storage_starknetjs.md +++ b/pages/applications/simple_storage_starknetjs.md @@ -94,7 +94,7 @@ The setup is finished! By calling the `fn get(self: @ContractState) -> u128` fun In order to run your code, run the command `node index.js{:md}` in your project directory. After a short amount of time, you should see a "0" as the stored data. -Now, we will set a new number to the `stored_data` variable by calling the `fn set(self: @mut ContractState, new_data: u128)` function. This is an `INVOKE:{md}` transaction, so we need to sign the transaction with our account's private key and pass along the calldata. +Now, we will set a new number to the `stored_data` variable by calling the `fn set(self: @mut ContractState, new_data: u128)` function. This is an `INVOKE{:md}` transaction, so we need to sign the transaction with our account's private key and pass along the calldata. The transaction is signed and broadcasted to the network and it can takes a few seconds for the transaction to be confirmed. diff --git a/pages/getting-started/interacting/how_to_deploy.md b/pages/getting-started/interacting/how_to_deploy.md index 161d588e..b49a36ba 100644 --- a/pages/getting-started/interacting/how_to_deploy.md +++ b/pages/getting-started/interacting/how_to_deploy.md @@ -38,7 +38,7 @@ After this command, the address of the account is shown once it is deployed alon starkli account deploy ./starkli-wallet/account.json ``` -This command wants you to fund the address (given in the instructions below the command) in order to deploy the account on the Starknet Sepolia Testnet. We need Starknet Sepolia testnet ethers which could be obtained from [this faucet](https://starknet-faucet.vercel.app/). +This command wants you to fund the address (given in the instructions below the command) in order to deploy the account on the Starknet Sepolia Testnet. We need Starknet Sepolia testnet ethers, you can find [a list of available faucets](https://docs.starknet.io/tools/oracles-faucets/). Once the transaction is confirmed on the faucet page, press ENTER, and the account will be deployed on Starknet Sepolia! Try to find your account on [Voyager Sepolia](https://sepolia.voyager.online/)! diff --git a/pages/getting-started/syscalls.md b/pages/getting-started/syscalls.md index a07d0599..07a1edb8 100644 --- a/pages/getting-started/syscalls.md +++ b/pages/getting-started/syscalls.md @@ -248,4 +248,4 @@ The system call does not add any padding and the input needs to be a multiple of ## Additional Resources - [Official Syscalls Documentation](https://docs.starknet.io/documentation/architecture_and_concepts/Smart_Contracts/system-calls-cairo1/) -- [Source Code](https://github.com/starkware-libs/cairo/blob/v2.9.2/corelib/src/starknet/syscalls.cairo) +- [Source Code](https://github.com/starkware-libs/cairo/blob/v2.9.4/corelib/src/starknet/syscalls.cairo) diff --git a/pages/index.mdx b/pages/index.mdx index 34b6bcdb..0e7aed02 100644 --- a/pages/index.mdx +++ b/pages/index.mdx @@ -47,10 +47,11 @@ To deepen your knowledge: The current version of this book uses: ```md -cairo 2.9.2 +cairo 2.9.4 edition 2024_07 -// [!include ~/.tool-versions] sierra 1.6.0 +// .tool-versions: +// [!include ~/.tool-versions] ```