Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
feat: support strk as fee token (#1597)
Browse files Browse the repository at this point in the history
Co-authored-by: j1mbo64 <[email protected]>
  • Loading branch information
j1mbo64 and j1mbo64 authored May 17, 2024
1 parent e530bae commit 9db7708
Show file tree
Hide file tree
Showing 12 changed files with 613 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- feat: support strk as fee token
- dev: pallet test for estimate_fee that skip validation
- feat: add versioned constants to pallet constants
- bug: fix contract serialisation
Expand Down
90 changes: 89 additions & 1 deletion configs/genesis-assets/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@
"0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"0x0372ee6669dc86563007245ed7343d5180b96221ce28f44408cff2898038dbd4"
],
[
"0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"0x0372ee6669dc86563007245ed7343d5180b96221ce28f44408cff2898038dbd4"
],
[
"0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
"0x07b3e05f48f0c69e4a65ce5e076a66271a527aff2c34ce1083ec6e1526997a69"
Expand Down Expand Up @@ -244,6 +248,90 @@
],
"0xffffffffffffffffffffffffffffffff"
],
[
[
"0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"0x341c1bdfd89f69748aa00b5742b03adbffd79b8e80cab5c50d91cd8c2a79be1"
],
"0x20202020537461726b6e657420546f6b656e"
],
[
[
"0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"0x0b6ce5410fca59d078ee9b2a4371a9d684c530d697c64fbef0ae6d5e8f0ac72"
],
"0x5354524b"
],
[
[
"0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"0x1f0d4aa99431d246bac9b8e48c33e888245b15e9678f64f9bdfc8823dc8f979"
],
"0x12"
],
[
[
"0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"0x7b62949c85c6af8a50c11c22927f9302f7a2e40bc93b4c988415915b0f97f09"
],
"0xffffffffffffffffffffffffffffffff"
],
[
[
"0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"0x7b62949c85c6af8a50c11c22927f9302f7a2e40bc93b4c988415915b0f97f0a"
],
"0xffffffffffffffffffffffffffffffff"
],
[
[
"0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"0x45abe05a3e7fb0c2ae1fa912be22a7dbc4832915e00562e2783dee710b9e4bc"
],
"0xffffffffffffffffffffffffffffffff"
],
[
[
"0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"0x40795dc9acd6d37d07ba939bbafe8ff2d0a9b78de88db2c74b4eb57d757c0eb"
],
"0xffffffffffffffffffffffffffffffff"
],
[
[
"0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"0x45abe05a3e7fb0c2ae1fa912be22a7dbc4832915e00562e2783dee710b9e4bd"
],
"0xffffffffffffffffffffffffffffffff"
],
[
[
"0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"0x262e096a838c0d8f34f641ff917d47d7dcb345c69efe61d9ab6b675e7340fc6"
],
"0xffffffffffffffffffffffffffffffff"
],
[
[
"0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"0x262e096a838c0d8f34f641ff917d47d7dcb345c69efe61d9ab6b675e7340fc7"
],
"0xffffffffffffffffffffffffffffffff"
],
[
[
"0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"0x1d8bbc4f93f5ab9858f6c0c0de2769599fb97511503d5bf2872ef6846f2146f"
],
"0xffffffffffffffffffffffffffffffff"
],
[
[
"0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"0x1d8bbc4f93f5ab9858f6c0c0de2769599fb97511503d5bf2872ef6846f21470"
],
"0xffffffffffffffffffffffffffffffff"
],
[
[
"0x040e59c2c182a58fb0a74349bfa4769cbbcba32547591dd3fb1def8623997d00",
Expand Down Expand Up @@ -281,6 +369,6 @@
]
],
"eth_fee_token_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"strk_fee_token_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc8",
"strk_fee_token_address": "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"chain_id": "MADARA"
}
2 changes: 1 addition & 1 deletion configs/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
{
"name": "genesis.json",
"sha3_256": "ec869153b70b838f5c58d602948145552bf9e8fcc1e22f28bd9250d3cf321993"
"sha3_256": "c35bcc00b70f9d6bfee3416fae0a0ec1e7a1fffe01c3d7fbb660db93a7bed87a"
},
{
"name": "NoValidateAccount.casm.json",
Expand Down
4 changes: 2 additions & 2 deletions crates/pallets/starknet/src/tests/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use starknet_api::hash::StarkFelt;

use super::mock::default_mock::*;
use super::mock::*;
use crate::tests::constants::FEE_TOKEN_ADDRESS;
use crate::tests::constants::ETH_FEE_TOKEN_ADDRESS;
use crate::tests::get_invoke_dummy;
use crate::{SeqAddrUpdate, SequencerAddress};

Expand Down Expand Up @@ -108,7 +108,7 @@ fn get_block_context_works() {
assert_eq!(default_addr, block_context.block_info().sequencer_address);
// correct fee_token_address
assert_eq!(
ContractAddress::try_from(StarkFelt::try_from(FEE_TOKEN_ADDRESS).unwrap()).unwrap(),
ContractAddress::try_from(StarkFelt::try_from(ETH_FEE_TOKEN_ADDRESS).unwrap()).unwrap(),
block_context.chain_info().fee_token_address(&FeeType::Eth)
);
// correct gas_price,
Expand Down
3 changes: 2 additions & 1 deletion crates/pallets/starknet/src/tests/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ pub const BLOCKIFIER_ACCOUNT_ADDRESS: &str = "0x02356b628d108863baf8644c945d97ba
pub const BRAAVOS_ACCOUNT_CLASS_HASH_CAIRO_0: &str =
"0x0244ca3d9fe8b47dd565a6f4270d979ba31a7d6ff2c3bf8776198161505e8b52";
pub const BRAAVOS_PROXY_CLASS_HASH_CAIRO_0: &str = "0x06a89ae7bd72c96202c040341c1ee422474b562e1d73c6848f08cae429c33262";
pub const FEE_TOKEN_ADDRESS: &str = "0x00000000000000000000000000000000000000000000000000000000000000AA";
pub const ETH_FEE_TOKEN_ADDRESS: &str = "0x00000000000000000000000000000000000000000000000000000000000000AA";
pub const STRK_FEE_TOKEN_ADDRESS: &str = "0x00000000000000000000000000000000000000000000000000000000000000BB";
pub const K: &str = "0x0000000000000000000000000000000000000000000000000000000000000001";
pub const OPENZEPPELIN_ACCOUNT_CLASS_HASH_CAIRO_0: &str =
"0x006280083f8c2a2db9f737320d5e3029b380e0e820fe24b8d312a6a34fdba0cd";
Expand Down
4 changes: 2 additions & 2 deletions crates/pallets/starknet/src/tests/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use starknet_api::hash::StarkFelt;
use starknet_api::transaction::{Calldata, Fee, InvokeTransactionV1, TransactionSignature};
use starknet_core::utils::get_selector_from_name;

use super::constants::{FEE_TOKEN_ADDRESS, MULTIPLE_EVENT_EMITTING_CONTRACT_ADDRESS};
use super::constants::{ETH_FEE_TOKEN_ADDRESS, MULTIPLE_EVENT_EMITTING_CONTRACT_ADDRESS};
use super::mock::default_mock::*;
use super::mock::*;

Expand All @@ -25,7 +25,7 @@ fn internal_and_external_events_are_emitted_in_the_right_order() {
ContractAddress(PatriciaKey(StarkFelt::try_from(MULTIPLE_EVENT_EMITTING_CONTRACT_ADDRESS).unwrap()));
let inner_contract_address =
ContractAddress(PatriciaKey(StarkFelt::try_from(INNER_EVENT_EMITTING_CONTRACT_ADDRESS).unwrap()));
let fee_token_address = ContractAddress(PatriciaKey(StarkFelt::try_from(FEE_TOKEN_ADDRESS).unwrap()));
let fee_token_address = ContractAddress(PatriciaKey(StarkFelt::try_from(ETH_FEE_TOKEN_ADDRESS).unwrap()));

let sender_account = get_account_address(None, AccountType::V0(AccountTypeV0Inner::NoValidate));
let emit_selector: StarkFelt = Felt252Wrapper::from(get_selector_from_name("emit_sandwich").unwrap()).into();
Expand Down
8 changes: 4 additions & 4 deletions crates/pallets/starknet/src/tests/fees_disabled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use starknet_api::core::{ContractAddress, EntryPointSelector, Nonce, PatriciaKey
use starknet_api::hash::StarkFelt;
use starknet_api::transaction::Calldata;

use super::constants::FEE_TOKEN_ADDRESS;
use super::constants::ETH_FEE_TOKEN_ADDRESS;
use super::mock::*;
use super::utils::{
build_get_balance_contract_call, build_transfer_invoke_transaction, BuildTransferInvokeTransaction,
Expand Down Expand Up @@ -59,7 +59,7 @@ fn build_invoke_transaction(
chain_id,
BuildTransferInvokeTransaction {
sender_address: address,
token_address: ContractAddress(PatriciaKey(StarkFelt::try_from(FEE_TOKEN_ADDRESS).unwrap())),
token_address: ContractAddress(PatriciaKey(StarkFelt::try_from(ETH_FEE_TOKEN_ADDRESS).unwrap())),
recipient: address,
amount_low: StarkFelt::ZERO,
amount_high: StarkFelt::ZERO,
Expand All @@ -71,7 +71,7 @@ fn build_invoke_transaction(
fn get_balance_default_mock(account_address: ContractAddress) -> (Felt252Wrapper, Felt252Wrapper) {
let (selector, calldata) = build_get_balance_call(account_address);
let result = default_mock::Starknet::call_contract(
ContractAddress(PatriciaKey(StarkFelt::try_from(FEE_TOKEN_ADDRESS).unwrap())),
ContractAddress(PatriciaKey(StarkFelt::try_from(ETH_FEE_TOKEN_ADDRESS).unwrap())),
selector,
calldata,
)
Expand All @@ -82,7 +82,7 @@ fn get_balance_default_mock(account_address: ContractAddress) -> (Felt252Wrapper
fn get_balance_fees_disabled_mock(account_address: ContractAddress) -> (Felt252Wrapper, Felt252Wrapper) {
let (selector, calldata) = build_get_balance_call(account_address);
let result = fees_disabled_mock::Starknet::call_contract(
ContractAddress(PatriciaKey(StarkFelt::try_from(FEE_TOKEN_ADDRESS).unwrap())),
ContractAddress(PatriciaKey(StarkFelt::try_from(ETH_FEE_TOKEN_ADDRESS).unwrap())),
selector,
calldata,
)
Expand Down
Loading

0 comments on commit 9db7708

Please sign in to comment.