Skip to content

Commit

Permalink
Merge branch 'main' into finish-role-store
Browse files Browse the repository at this point in the history
  • Loading branch information
ametel01 committed Sep 24, 2023
2 parents 70178d0 + 11ee99a commit a1903bb
Show file tree
Hide file tree
Showing 33 changed files with 1,360 additions and 195 deletions.
2 changes: 1 addition & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/a
alexandria_math = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "a3052ff" }
alexandria_storage = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "a3052ff" }
alexandria_sorting = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "a3052ff" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.5.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.6.0" }


[tool.snforge]
Expand Down
3 changes: 2 additions & 1 deletion book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- [Fee Module](smart-contracts-architecture/fee-module.md)
- [Gas Module](smart-contracts-architecture/gas-module.md)
- [Liquidation](smart-contracts-architecture/liquidation-module.md)
- [Mock](smart-contracts-architecture/mock-module.md)
- [Nonce Module](smart-contracts-architecture/nonce-module.md)
- [Oracle Module](smart-contracts-architecture/oracle-module.md)
- [Order Module](smart-contracts-architecture/order-module.md)
Expand All @@ -29,4 +30,4 @@
- [Utils Module](smart-contracts-architecture/utils-module.md)
- [Withdrawal Module](smart-contracts-architecture/withdrawal-module.md)
- [Continuous Integration](continuous-integration/README.md)
- [Github Workflows Documentation](continuous-integration/workflows.md)
- [Github Workflows Documentation](continuous-integration/workflows.md)
12 changes: 12 additions & 0 deletions book/src/smart-contracts-architecture/mock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Mock module

The Mock module is used to store mocked implementation of contracts to use them in tests.

It contains the following Cairo library files:

- [error.cairo](https://github.com/keep-starknet-strange/satoru/blob/main/src/mock/error.cairo): Contains the error codes of the module.

It contains the following smart contracts:

- [ReferralStorage.cairo](https://github.com/keep-starknet-strange/satoru/blob/main/src/mock/referral_stoage.cairo): Set and Get of functions for managing referral-related data and operations.
- [Governable.cairo](https://github.com/keep-starknet-strange/satoru/blob/main/src/referral/governable.cairo): Referral storage for testing and testnets
5 changes: 1 addition & 4 deletions src/deposit/deposit_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ fn create_deposit(
initial_short_token_amount -= params.execution_fee;
} else {
let fee_token_amount = deposit_vault.record_transfer_in(fee_token);
assert(
fee_token_amount >= params.execution_fee,
GasError::INSUFFICIENT_FEE_TOKEN_AMOUNT_FOR_EXECUTION_FEE
);
assert(fee_token_amount >= params.execution_fee, GasError::INSUFF_EXEC_FEE);

params.execution_fee = fee_token_amount;
}
Expand Down
4 changes: 1 addition & 3 deletions src/deposit/execute_deposit_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use satoru::data::data_store::{IDataStoreDispatcher, IDataStoreDispatcherTrait};
use satoru::event::event_emitter::{IEventEmitterDispatcher, IEventEmitterDispatcherTrait};
use satoru::oracle::oracle::{IOracleDispatcher, IOracleDispatcherTrait};
use satoru::deposit::deposit_vault::{IDepositVaultDispatcher, IDepositVaultDispatcherTrait};
use satoru::referral::referral_storage::interface::{
IReferralStorageDispatcher, IReferralStorageDispatcherTrait
};
use satoru::mock::referral_storage::{IReferralStorageDispatcher, IReferralStorageDispatcherTrait};
use satoru::price::price::Price;
use satoru::market::market::Market;
use satoru::utils::span32::Span32;
Expand Down
149 changes: 149 additions & 0 deletions src/event/event_emitter.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,37 @@ trait IEventEmitter<TContractState> {
max_price: u128,
is_price_feed: bool
);

fn emit_set_handler(ref self: TContractState, handler: ContractAddress, is_active: bool);

fn emit_set_trader_referral_code(
ref self: TContractState, account: ContractAddress, code: felt252
);

fn emit_set_tier(
ref self: TContractState, tier_id: u128, total_rebate: u128, discount_share: u128
);

fn emit_set_referrer_tier(ref self: TContractState, referrer: ContractAddress, tier_id: u128);

fn emit_set_referrer_discount_share(
ref self: TContractState, referrer: ContractAddress, discount_share: u128
);

fn emit_register_code(ref self: TContractState, account: ContractAddress, code: felt252);

fn emit_set_code_owner(
ref self: TContractState,
account: ContractAddress,
new_account: ContractAddress,
code: felt252
);

fn emit_gov_set_code_owner(
ref self: TContractState, code: felt252, new_account: ContractAddress
);

fn emit_set_gov(ref self: TContractState, prev_gov: ContractAddress, next_gov: ContractAddress);
}

#[starknet::contract]
Expand Down Expand Up @@ -734,6 +765,15 @@ mod EventEmitter {
SwapReverted: SwapReverted,
SwapInfo: SwapInfo,
SwapFeesCollected: SwapFeesCollected,
SetHandler: SetHandler,
SetTraderReferralCode: SetTraderReferralCode,
SetTier: SetTier,
SetReferrerTier: SetReferrerTier,
SetReferrerDiscountShare: SetReferrerDiscountShare,
SetRegisterCode: SetRegisterCode,
SetCodeOwner: SetCodeOwner,
GovSetCodeOwner: GovSetCodeOwner,
SetGov: SetGov,
}

#[derive(Drop, starknet::Event)]
Expand Down Expand Up @@ -1467,6 +1507,61 @@ mod EventEmitter {
fees: SwapFees
}

#[derive(Drop, starknet::Event)]
struct SetHandler {
handler: ContractAddress,
is_active: bool
}

#[derive(Drop, starknet::Event)]
struct SetTraderReferralCode {
account: ContractAddress,
code: felt252
}

#[derive(Drop, starknet::Event)]
struct SetTier {
tier_id: u128,
total_rebate: u128,
discount_share: u128
}

#[derive(Drop, starknet::Event)]
struct SetReferrerTier {
referrer: ContractAddress,
tier_id: u128
}

#[derive(Drop, starknet::Event)]
struct SetReferrerDiscountShare {
referrer: ContractAddress,
discount_share: u128
}

#[derive(Drop, starknet::Event)]
struct SetRegisterCode {
account: ContractAddress,
code: felt252
}

#[derive(Drop, starknet::Event)]
struct SetCodeOwner {
account: ContractAddress,
new_account: ContractAddress,
code: felt252
}

#[derive(Drop, starknet::Event)]
struct GovSetCodeOwner {
code: felt252,
new_account: ContractAddress
}

#[derive(Drop, starknet::Event)]
struct SetGov {
prev_gov: ContractAddress,
next_gov: ContractAddress
}

// *************************************************************************
// EXTERNAL FUNCTIONS
Expand Down Expand Up @@ -2614,5 +2709,59 @@ mod EventEmitter {
) {
self.emit(OraclePriceUpdate { token, min_price, max_price, is_price_feed });
}

fn emit_set_handler(ref self: ContractState, handler: ContractAddress, is_active: bool) {
self.emit(SetHandler { handler, is_active });
}

fn emit_set_tier(
ref self: ContractState, tier_id: u128, total_rebate: u128, discount_share: u128
) {
self.emit(SetTier { tier_id, total_rebate, discount_share });
}

fn emit_set_referrer_tier(
ref self: ContractState, referrer: ContractAddress, tier_id: u128
) {
self.emit(SetReferrerTier { referrer, tier_id });
}

fn emit_set_referrer_discount_share(
ref self: ContractState, referrer: ContractAddress, discount_share: u128
) {
self.emit(SetReferrerDiscountShare { referrer, discount_share });
}

fn emit_set_trader_referral_code(
ref self: ContractState, account: ContractAddress, code: felt252
) {
self.emit(SetTraderReferralCode { account, code });
}


fn emit_register_code(ref self: ContractState, account: ContractAddress, code: felt252) {
self.emit(SetRegisterCode { account, code });
}

fn emit_set_code_owner(
ref self: ContractState,
account: ContractAddress,
new_account: ContractAddress,
code: felt252
) {
self.emit(SetCodeOwner { account, new_account, code });
}

fn emit_gov_set_code_owner(
ref self: ContractState, code: felt252, new_account: ContractAddress
) {
self.emit(GovSetCodeOwner { code, new_account });
}

fn emit_set_gov(
ref self: ContractState, prev_gov: ContractAddress, next_gov: ContractAddress
) {
self.emit(SetGov { prev_gov, next_gov });
}
}
}
2 changes: 1 addition & 1 deletion src/exchange/base_order_handler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ mod BaseOrderHandler {
use satoru::swap::swap_handler::{ISwapHandlerDispatcher, ISwapHandlerDispatcherTrait};
use satoru::exchange::error::ExchangeError;
use satoru::market::{market::Market, market_utils};
use satoru::referral::referral_storage::interface::{
use satoru::mock::referral_storage::{
IReferralStorageDispatcher, IReferralStorageDispatcherTrait
};
use satoru::utils::span32::Array32Trait;
Expand Down
4 changes: 2 additions & 2 deletions src/gas/error.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod GasError {
const INSUFFICIENT_FEE_TOKEN_AMOUNT_FOR_EXECUTION_FEE: felt252 =
'insffcient_tok_amt_for_exec_fee';
const INSUFF_EXEC_GAS: felt252 = 'insufficient_gas_for_execute';
const INSUFF_EXEC_FEE: felt252 = 'insufficient_execution_fee';
}
Loading

0 comments on commit a1903bb

Please sign in to comment.