Skip to content

Commit

Permalink
chore: scarb, foundry, oz updates (NethermindEth#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
julio4 committed Oct 24, 2024
1 parent 60e63cc commit 4724fe8
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scarb 2.6.4
starknet-foundry 0.24.0
scarb 2.6.5
starknet-foundry 0.25.0
8 changes: 4 additions & 4 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
11 changes: 4 additions & 7 deletions listings/applications/constant_product_amm/src/tests.cairo
Original file line number Diff line number Diff line change
@@ -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<ContractState>;
#[abi(embed_v0)]
impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl<ContractState>;
#[abi(embed_v0)]
impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl<ContractState>;
impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl<ContractState>;
impl ERC20InternalImpl = ERC20Component::InternalImpl<ContractState>;

#[storage]
Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions listings/applications/staking/src/tests/staking_tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<felt252> = 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 })
Expand All @@ -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(
Expand All @@ -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);
Expand All @@ -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]
Expand Down
26 changes: 20 additions & 6 deletions listings/applications/staking/src/tests/tokens.cairo
Original file line number Diff line number Diff line change
@@ -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<ContractState>;
impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl<ContractState>;
impl ERC20InternalImpl = ERC20Component::InternalImpl<ContractState>;

#[storage]
Expand All @@ -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<ContractState>;
impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl<ContractState>;
impl ERC20InternalImpl = ERC20Component::InternalImpl<ContractState>;

#[storage]
Expand All @@ -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);
}
}
6 changes: 3 additions & 3 deletions listings/applications/timelock/src/erc721.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 4724fe8

Please sign in to comment.