From 4724fe8a1e7063e61b7faa3b505f700b13632456 Mon Sep 17 00:00:00 2001 From: Jules Doumeche <30329843+julio4@users.noreply.github.com> Date: Tue, 25 Jun 2024 16:58:31 +0900 Subject: [PATCH] chore: scarb, foundry, oz updates (#227) --- .tool-versions | 4 +-- Scarb.lock | 8 +++--- Scarb.toml | 6 ++--- .../constant_product_amm/src/tests.cairo | 11 +++----- .../staking/src/tests/staking_tests.cairo | 13 +++++++--- .../staking/src/tests/tokens.cairo | 26 ++++++++++++++----- .../applications/timelock/src/erc721.cairo | 6 ++--- 7 files changed, 45 insertions(+), 29 deletions(-) diff --git a/.tool-versions b/.tool-versions index c62bafce..dc8930c0 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -scarb 2.6.4 -starknet-foundry 0.24.0 +scarb 2.6.5 +starknet-foundry 0.25.0 diff --git a/Scarb.lock b/Scarb.lock index 952ac331..74cfb60e 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -102,8 +102,8 @@ dependencies = [ [[package]] name = "openzeppelin" -version = "0.11.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.11.0#a83f36b23f1af6e160288962be4a2701c3ecbcda" +version = "0.14.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.14.0#f091c4f51ddeb10297db984acae965328c5a4e5b" [[package]] name = "scarb" @@ -119,8 +119,8 @@ version = "0.1.0" [[package]] name = "snforge_std" -version = "0.24.0" -source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.24.0#95e9fb09cb91b3c05295915179ee1b55bf923653" +version = "0.25.0" +source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.25.0#5b366e24821e530fea97f11b211d220e8493fbea" [[package]] name = "staking" diff --git a/Scarb.toml b/Scarb.toml index 4c5c042d..d15c540a 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -12,10 +12,10 @@ test = "$(git rev-parse --show-toplevel)/scripts/test_resolver.sh" [workspace.tool.snforge] [workspace.dependencies] -starknet = ">=2.6.3" -openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag="v0.11.0" } +starknet = ">=2.6.4" +openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag="v0.14.0" } components = { path = "listings/applications/components" } -snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.24.0" } +snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.25.0" } [workspace.package] description = "Collection of examples of how to use the Cairo programming language to create smart contracts on Starknet." diff --git a/listings/applications/constant_product_amm/src/tests.cairo b/listings/applications/constant_product_amm/src/tests.cairo index 412d9ce9..a94d111c 100644 --- a/listings/applications/constant_product_amm/src/tests.cairo +++ b/listings/applications/constant_product_amm/src/tests.cairo @@ -1,16 +1,13 @@ #[starknet::contract] pub mod ERC20Token { - use openzeppelin::token::erc20::ERC20Component; + use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; use starknet::ContractAddress; component!(path: ERC20Component, storage: erc20, event: ERC20Event); + // ERC20 Mixin #[abi(embed_v0)] - impl ERC20Impl = ERC20Component::ERC20Impl; - #[abi(embed_v0)] - impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl; - #[abi(embed_v0)] - impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl; + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl; impl ERC20InternalImpl = ERC20Component::InternalImpl; #[storage] @@ -35,7 +32,7 @@ pub mod ERC20Token { symbol: ByteArray ) { self.erc20.initializer(name, symbol); - self.erc20._mint(recipient, initial_supply); + self.erc20.mint(recipient, initial_supply); } } // Wait for OZ #953 fix diff --git a/listings/applications/staking/src/tests/staking_tests.cairo b/listings/applications/staking/src/tests/staking_tests.cairo index d1004867..6ff1e1c8 100644 --- a/listings/applications/staking/src/tests/staking_tests.cairo +++ b/listings/applications/staking/src/tests/staking_tests.cairo @@ -41,9 +41,14 @@ mod tests { fn deploy_erc20( class_hash: felt252, name: ByteArray, symbol: ByteArray ) -> (ContractAddress, IERC20Dispatcher) { + let supply: u256 = 1000000; + let recipient = contract_address_const::<'recipient'>(); + let mut call_data: Array = ArrayTrait::new(); Serde::serialize(@name, ref call_data); Serde::serialize(@symbol, ref call_data); + Serde::serialize(@supply, ref call_data); + Serde::serialize(@recipient, ref call_data); let address = deploy_util(class_hash, call_data); (address, IERC20Dispatcher { contract_address: address }) @@ -65,10 +70,10 @@ mod tests { fn setup() -> Deployment { let (staking_token_address, staking_token) = deploy_erc20( - StakingToken::TEST_CLASS_HASH, "StakingToken", "StakingTKN" + StakingToken::TEST_CLASS_HASH, "StakingToken", "StakingTKN", ); let (reward_token_address, reward_token) = deploy_erc20( - RewardToken::TEST_CLASS_HASH, "RewardToken", "RewardTKN" + RewardToken::TEST_CLASS_HASH, "RewardToken", "RewardTKN", ); let (_, staking_contract) = deploy_staking_contract( @@ -85,7 +90,7 @@ mod tests { let mut state = StakingToken::contract_state_for_testing(); // pretend as if we were in the deployed staking token contract set_contract_address(deploy.staking_token.contract_address); - state.erc20._mint(recipient, amount); + state.erc20.mint(recipient, amount); // approve staking contract to spend user's tokens set_contract_address(recipient); @@ -99,7 +104,7 @@ mod tests { let mut state = RewardToken::contract_state_for_testing(); // pretend as if we were in the deployed reward token contract set_contract_address(reward_token_address); - state.erc20._mint(deployed_contract, amount); + state.erc20.mint(deployed_contract, amount); } #[test] diff --git a/listings/applications/staking/src/tests/tokens.cairo b/listings/applications/staking/src/tests/tokens.cairo index c6ce3a19..ea788565 100644 --- a/listings/applications/staking/src/tests/tokens.cairo +++ b/listings/applications/staking/src/tests/tokens.cairo @@ -1,12 +1,12 @@ #[starknet::contract] pub mod RewardToken { - use openzeppelin::token::erc20::ERC20Component; + use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; use starknet::ContractAddress; component!(path: ERC20Component, storage: erc20, event: ERC20Event); #[abi(embed_v0)] - impl ERC20Impl = ERC20Component::ERC20Impl; + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl; impl ERC20InternalImpl = ERC20Component::InternalImpl; #[storage] @@ -23,20 +23,27 @@ pub mod RewardToken { } #[constructor] - fn constructor(ref self: ContractState, name: ByteArray, symbol: ByteArray) { + fn constructor( + ref self: ContractState, + name: ByteArray, + symbol: ByteArray, + initial_supply: u256, + recipient: ContractAddress + ) { self.erc20.initializer(name, symbol); + self.erc20.mint(recipient, initial_supply); } } #[starknet::contract] pub mod StakingToken { - use openzeppelin::token::erc20::ERC20Component; + use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; use starknet::ContractAddress; component!(path: ERC20Component, storage: erc20, event: ERC20Event); #[abi(embed_v0)] - impl ERC20Impl = ERC20Component::ERC20Impl; + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl; impl ERC20InternalImpl = ERC20Component::InternalImpl; #[storage] @@ -53,7 +60,14 @@ pub mod StakingToken { } #[constructor] - fn constructor(ref self: ContractState, name: ByteArray, symbol: ByteArray) { + fn constructor( + ref self: ContractState, + name: ByteArray, + symbol: ByteArray, + initial_supply: u256, + recipient: ContractAddress + ) { self.erc20.initializer(name, symbol); + self.erc20.mint(recipient, initial_supply); } } diff --git a/listings/applications/timelock/src/erc721.cairo b/listings/applications/timelock/src/erc721.cairo index be7a023c..fddeda94 100644 --- a/listings/applications/timelock/src/erc721.cairo +++ b/listings/applications/timelock/src/erc721.cairo @@ -2,10 +2,10 @@ pub mod ERC721 { use starknet::ContractAddress; use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc721::ERC721Component; + use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl}; - component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721Component, storage: erc721, event: ERC721Event); + component!(path: SRC5Component, storage: src5, event: SRC5Event); // ERC20Mixin #[abi(embed_v0)] @@ -39,6 +39,6 @@ pub mod ERC721 { token_id: u256 ) { self.erc721.initializer(name, symbol, base_uri); - self.erc721._mint(recipient, token_id); + self.erc721.mint(recipient, token_id); } }