Skip to content

Commit

Permalink
Merge branch 'main' into chore/update-katana
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementWalter authored Sep 3, 2024
2 parents 4e87772 + dd5e975 commit efb26b8
Show file tree
Hide file tree
Showing 63 changed files with 1,331 additions and 811 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@v4
# Python setup
- name: Set up Python 3.10.14
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.10.14
- name: Load cached Poetry installation
Expand All @@ -40,8 +40,8 @@ jobs:
with:
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
installer-parallel: true
- run: poetry config installer.modern-installation false
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
Expand All @@ -51,7 +51,8 @@ jobs:
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: make setup

- uses: asdf-vm/actions/install@v3
- run: asdf install
# Build artifacts
- name: Compile all the cairo files
run: make build
Expand All @@ -70,7 +71,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10.14
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.10.14
- name: Load cached Poetry installation
Expand All @@ -85,8 +86,8 @@ jobs:
with:
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
installer-parallel: true
- run: poetry config installer.modern-installation false
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
Expand Down Expand Up @@ -123,7 +124,7 @@ jobs:
KATANA_VERSION=$(grep -oP '^KATANA_VERSION = \K.*' Makefile)
echo "katana_version=$KATANA_VERSION" >> "$GITHUB_OUTPUT"
- name: Set up Python 3.10
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.10.14
- name: Load cached Poetry installation
Expand All @@ -138,8 +139,8 @@ jobs:
with:
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
installer-parallel: true
- run: poetry config installer.modern-installation false
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
Expand All @@ -153,8 +154,7 @@ jobs:
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Install asdf & tools # For multiple versions of scarb - reads from .tool-versions and installs them
uses: asdf-vm/actions/install@v3
- uses: asdf-vm/actions/install@v3
- name: Load cached katana
id: cached-katana
uses: actions/cache@v4
Expand Down Expand Up @@ -204,7 +204,7 @@ jobs:
- name: Move ERC20
run: mv build/v0/ERC20.json build/common
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.10.14
- name: run tests
Expand All @@ -228,7 +228,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10.14
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.10.14
- name: Load cached Poetry installation
Expand All @@ -243,8 +243,8 @@ jobs:
with:
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
installer-parallel: true
- run: poetry config installer.modern-installation false
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.10.14
- name: Load cached Poetry installation
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/trunk-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions/checkout@v3

- name: Set up Python 3.10.14
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.10.14
cache: pip
Expand Down
1 change: 1 addition & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ lint:
- resources*
- tests/ef_tests/test_data
- .katana/messaging_config.json
- deployments
- linters: [solidity]
paths:
- solidity_contracts/src/UniswapV2/**/*.sol
Expand Down
44 changes: 4 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ fetch-ssj-artifacts:
setup: fetch-ssj-artifacts
poetry install

test: build-sol build-cairo1 deploy
test: deploy
poetry run pytest tests/src -m "not NoCI" --log-cli-level=INFO -n logical --seed 42
poetry run pytest tests/end_to_end --seed 42

test-unit: build-sol
poetry run pytest tests/src -m "not NoCI" -n logical --seed 42

# run make run-nodes in other terminal
test-end-to-end: build-sol build-cairo1 deploy
test-end-to-end: deploy
poetry run pytest tests/end_to_end --seed 42

deploy: build build-sol
Expand All @@ -70,52 +70,16 @@ build-sol:
git submodule update --init --recursive
forge build --names --force

# Builds Cairo 1.0 contracts by iterating over subdirectories,
# compiling contracts, and copying the resulting .sierra.json (old versions) or .contract_class.json
# files to the ROOT_DIR/build/fixtures directory with appropriate file extensions.
build-cairo1:
@mkdir -p build/ssj
@for d in cairo1_contracts/*/ ; do \
if [ "$$d" != "cairo1_contracts/build/" ]; then \
echo "Building $$d"; \
cd $$d; \
scarb build; \
for f in target/dev/*.sierra.json target/dev/*.contract_class.json target/dev/*.casm.json target/dev/*.compiled_contract_class.json; do \
if [ -e "$$f" ]; then \
case "$$f" in \
*.sierra.json) \
CONTRACT_NAME="$$(basename $$f | sed -E 's/^.*_([^_.]*)\.sierra\.json$$/\1/')"; \
cp "$$f" "$(ROOT_DIR)/build/ssj/contracts_$$CONTRACT_NAME.contract_class.json"; \
;; \
*.contract_class.json) \
CONTRACT_NAME="$$(basename $$f | sed -E 's/^.*_([^_.]*)\.contract_class\.json$$/\1/')"; \
cp "$$f" "$(ROOT_DIR)/build/ssj/contracts_$$CONTRACT_NAME.contract_class.json"; \
;; \
*.casm.json) \
CONTRACT_NAME="$$(basename $$f | sed -E 's/^.*_([^_.]*)\.casm\.json$$/\1/')"; \
cp "$$f" "$(ROOT_DIR)/build/ssj/contracts_$$CONTRACT_NAME.compiled_contract_class.json"; \
;; \
*.compiled_contract_class.json) \
CONTRACT_NAME="$$(basename $$f | sed -E 's/^.*_([^_.]*)\.compiled_contract_class\.json$$/\1/')"; \
cp "$$f" "$(ROOT_DIR)/build/ssj/contracts_$$CONTRACT_NAME.compiled_contract_class.json"; \
;; \
esac; \
fi; \
done; \
cd -; \
fi; \
done

install-katana:
cargo install --git https://github.com/dojoengine/dojo --locked --tag "${KATANA_VERSION}" katana

run-katana:
katana --chain-id test --validate-max-steps 6000000 --invoke-max-steps 14000000 --eth-gas-price 0 --strk-gas-price 0 --disable-fee
katana --chain-id test --validate-max-steps 6000000 --invoke-max-steps 14000000 --eth-gas-price 0 --strk-gas-price 0 --disable-fee --seed 0

run-anvil:
anvil --block-base-fee-per-gas 10

run-nodes:
@echo "Starting Anvil and Katana in messaging mode"
@anvil --block-base-fee-per-gas 10 &
@katana --chain-id test --validate-max-steps 6000000 --invoke-max-steps 14000000 --eth-gas-price 0 --strk-gas-price 0 --disable-fee --messaging .katana/messaging_config.json
@katana --chain-id test --validate-max-steps 6000000 --invoke-max-steps 14000000 --eth-gas-price 0 --strk-gas-price 0 --disable-fee --messaging .katana/messaging_config.json --seed 0
36 changes: 1 addition & 35 deletions cairo1_contracts/token/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,35 +1 @@
#[starknet::contract]
mod StarknetToken {
use openzeppelin::token::erc20::ERC20Component;
use starknet::ContractAddress;

component!(path: ERC20Component, storage: erc20, event: ERC20Event);

#[abi(embed_v0)]
impl ERC20Impl = ERC20Component::ERC20Impl<ContractState>;
#[abi(embed_v0)]
impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl<ContractState>;
impl ERC20InternalImpl = ERC20Component::InternalImpl<ContractState>;

#[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, initial_supply: u256, recipient: ContractAddress) {
let name = "MyToken";
let symbol = "MTK";

self.erc20.initializer(name, symbol);
self.erc20._mint(recipient, initial_supply);
}
}
mod starknet_token;
35 changes: 35 additions & 0 deletions cairo1_contracts/token/src/starknet_token.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#[starknet::contract]
mod StarknetToken {
use openzeppelin::token::erc20::ERC20Component;
use starknet::ContractAddress;

component!(path: ERC20Component, storage: erc20, event: ERC20Event);

#[abi(embed_v0)]
impl ERC20Impl = ERC20Component::ERC20Impl<ContractState>;
#[abi(embed_v0)]
impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl<ContractState>;
impl ERC20InternalImpl = ERC20Component::InternalImpl<ContractState>;

#[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, initial_supply: u256, recipient: ContractAddress) {
let name = "MyToken";
let symbol = "MTK";

self.erc20.initializer(name, symbol);
self.erc20._mint(recipient, initial_supply);
}
}
1 change: 1 addition & 0 deletions cairo1_contracts/utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
1 change: 1 addition & 0 deletions cairo1_contracts/utils/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scarb 2.6.5
6 changes: 6 additions & 0 deletions cairo1_contracts/utils/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "utils"
version = "0.1.0"
12 changes: 12 additions & 0 deletions cairo1_contracts/utils/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "utils"
version = "0.1.0"
edition = "2023_11"

[dependencies]
starknet = "2.6.4"

[[target.starknet-contract]]
casm = true
sierra = true
casm-add-pythonic-hints = true
39 changes: 39 additions & 0 deletions cairo1_contracts/utils/src/balance_sender.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use core::starknet::{get_caller_address, ContractAddress};


#[starknet::interface]
pub trait IERC20<TState> {
fn name(self: @TState) -> felt252;
fn symbol(self: @TState) -> felt252;
fn decimals(self: @TState) -> u8;
fn total_supply(self: @TState) -> u256;
fn balance_of(self: @TState, account: ContractAddress) -> u256;
fn allowance(self: @TState, owner: ContractAddress, spender: ContractAddress) -> u256;
fn transfer(ref self: TState, recipient: ContractAddress, amount: u256) -> bool;
fn transfer_from(
ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256
) -> bool;
fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool;
}

#[starknet::contract]
pub mod BalanceSender {
use core::starknet::{get_caller_address, ContractAddress, ClassHash, get_contract_address, SyscallResult};
use super::{IERC20Dispatcher, IERC20DispatcherTrait};
use core::starknet::syscalls::{replace_class_syscall};

#[storage]
struct Storage {}

#[external(v0)]
fn send_balance(self: @ContractState, token_address: ContractAddress, recipient: ContractAddress) -> bool {
let erc20_dispatcher = IERC20Dispatcher { contract_address: token_address };
let balance = erc20_dispatcher.balance_of(get_contract_address());
erc20_dispatcher.transfer(recipient, balance)
}

#[external(v0)]
fn replace_class(ref self: ContractState, new_class: ClassHash) -> SyscallResult<()>{
replace_class_syscall(new_class)
}
}
3 changes: 3 additions & 0 deletions cairo1_contracts/utils/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod universal_library_caller;

mod balance_sender;
28 changes: 28 additions & 0 deletions cairo1_contracts/utils/src/universal_library_caller.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use starknet::{
SyscallResult, storage_access::StorageAddress, class_hash::ClassHash,
};


#[starknet::interface]
pub trait IUniversalLibraryCaller<TContractState> {
fn library_call(self: @TContractState, class_hash: ClassHash, function_selector: felt252, calldata: Span<felt252>) -> SyscallResult<Span<felt252>>;
}

#[starknet::contract]
pub mod UniversalLibraryCaller {
use starknet::syscalls::library_call_syscall;
use starknet::{
SyscallResult, storage_access::StorageAddress, class_hash::ClassHash,
};


#[storage]
struct Storage {}

#[abi(embed_v0)]
impl UniversalLibraryCallerImpl of super::IUniversalLibraryCaller<ContractState> {
fn library_call(self: @ContractState, class_hash: ClassHash, function_selector: felt252, calldata: Span<felt252>) -> SyscallResult<Span<felt252>> {
library_call_syscall(class_hash, function_selector, calldata)
}
}
}
22 changes: 15 additions & 7 deletions deployments/starknet-sepolia/declarations.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
{
"kakarot": "0x6aa7b2a71ce0e28301a6547b8eb38c5f4130d0091b5aa8a12c8f380efcbc4c4",
"account_contract": "0x56d311021950bf65ee500426e007b9e3ced0db97f9c1e0d29a9e03d79a9bf6c",
"uninitialized_account": "0x1d8b8047e26b484d3f6262d1967217d980d0f2dfc69afa5661492bd5bfe2954",
"EVM": "0x78e943202d567c81ec9b523e5121c15914210f915dd7bce69f09ceb5ae91934",
"OpenzeppelinAccount": "0x452189b6cd1ef66a7daef29cbffb77ce809cac95449687aabb169117c04e2f9",
"Cairo1Helpers": "0xff0ec0846982c93e48ed5130dba8efe5905c099d0ffe45c1fd777a97a2b71a",
"replace_class": "0x5cd1a33bc766f50965fe2343e6aec12a12c562b3bb653085b88dc6751b71682"
"account_contract": "0x6cb1275516c11f6c1f9d2758bd212d2c40d8136ebd353c316779b754a216d83",
"uninitialized_account_fixture": "0x2957ff0877441dddcd140e6af50a3d45712f4f7205a36a846110a70297036be",
"uninitialized_account": "0x45f7d0803659c3f58b5b6ba46f349178253dadabbfc6ab47fa1ba4bab4699f8",
"EVM": "0x1ce258b332ad964d0d0a472b7795615a84f25196b733a319e101b948f3064a8",
"OpenzeppelinAccount": "0x6153ccf69fd20f832c794df36e19135f0070d0576144f0b47f75a226e4be530",
"Cairo1Helpers": "0x28ece3751ecf5bdf2d791eb64a65bfb6a8816432b698870dba2f38a36101d58",
"Cairo1HelpersFixture": "0x4e7811d9bbba41193bd3c77d05c16f7aaa55dd1d601686b50f6fa0e3766a712",
"replace_class": "0xa187318c5e79b010cf45975f589f0a8d441fadde5b1e7ccad46501568437b5",
"Counter": "0x4fc47610d8c9ce0bcfc2f9e03658f0fbcd3e0a9c351a1aa59d465a33533a7c8",
"MockPragmaOracle": "0x675f00328ff84f127d71b179b3f3a3a06ce8432054770cddd5729c8d62866da",
"StarknetToken": "0x27dd8ce628866f1544202ae06ec57b3c9b1f775d5f7c2797de7aa1586ecf693",
"ERC20": "0x3c5ee4bc12f4247cd8071150c3f5d9bee71f40b0ef7aeae59f468d898f60933",
"kakarot": "0x3f9e4ac97c943181453ce74f1fd1c163c154c40d9cbbbe5c2453512ee1a86e6",
"UniversalLibraryCaller": "0x5e84816dcbfd11581d8d5160af5754a4adc71ab35a0c0aaa053773f61838627",
"BalanceSender": "0x2cc118f56b9d3ad311900db5254f3dca75fbf24de3b68ee670a0fb3691ac5b3"
}
Loading

0 comments on commit efb26b8

Please sign in to comment.