Skip to content

Commit

Permalink
Merge branch 'main' into feat/liquidation-handler-test
Browse files Browse the repository at this point in the history
  • Loading branch information
tevrat-aksoy committed Nov 10, 2023
2 parents 27870f4 + 44ac3b0 commit e668816
Show file tree
Hide file tree
Showing 44 changed files with 1,149 additions and 92 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.3.1"
- uses: foundry-rs/setup-snfoundry@v1
- uses: foundry-rs/setup-snfoundry@v2
with:
starknet-foundry-version: 0.9.0
starknet-foundry-version: 0.9.1
- name: Run cairo tests
run: snforge test
# - name: Set up Scarb
Expand Down
10 changes: 5 additions & 5 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@ version = 1
[[package]]
name = "alexandria_data_structures"
version = "0.1.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=ae1d514#ae1d5149ff601a7ac5b39edc867d33ebd83d7f4f"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?tag=cairo-v2.3.0-rc0#ae1d5149ff601a7ac5b39edc867d33ebd83d7f4f"
dependencies = [
"alexandria_encoding",
]

[[package]]
name = "alexandria_encoding"
version = "0.1.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=ae1d514#ae1d5149ff601a7ac5b39edc867d33ebd83d7f4f"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?tag=cairo-v2.3.0-rc0#ae1d5149ff601a7ac5b39edc867d33ebd83d7f4f"
dependencies = [
"alexandria_math",
]

[[package]]
name = "alexandria_math"
version = "0.2.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=ae1d514#ae1d5149ff601a7ac5b39edc867d33ebd83d7f4f"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?tag=cairo-v2.3.0-rc0#ae1d5149ff601a7ac5b39edc867d33ebd83d7f4f"
dependencies = [
"alexandria_data_structures",
]

[[package]]
name = "alexandria_sorting"
version = "0.1.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=ae1d514#ae1d5149ff601a7ac5b39edc867d33ebd83d7f4f"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?tag=cairo-v2.3.0-rc0#ae1d5149ff601a7ac5b39edc867d33ebd83d7f4f"

[[package]]
name = "alexandria_storage"
version = "0.2.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=ae1d514#ae1d5149ff601a7ac5b39edc867d33ebd83d7f4f"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?tag=cairo-v2.3.0-rc0#ae1d5149ff601a7ac5b39edc867d33ebd83d7f4f"

[[package]]
name = "satoru"
Expand Down
8 changes: 4 additions & 4 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ sierra-replace-ids = true

[dependencies]
starknet = ">=2.3.1"
alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "ae1d514" }
alexandria_math = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "ae1d514" }
alexandria_storage = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "ae1d514" }
alexandria_sorting = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "ae1d514" }
alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria.git", tag = "cairo-v2.3.0-rc0" }
alexandria_math = { git = "https://github.com/keep-starknet-strange/alexandria.git", tag = "cairo-v2.3.0-rc0" }
alexandria_storage = { git = "https://github.com/keep-starknet-strange/alexandria.git", tag = "cairo-v2.3.0-rc0" }
alexandria_sorting = { git = "https://github.com/keep-starknet-strange/alexandria.git", tag = "cairo-v2.3.0-rc0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.9.1" }


Expand Down
2 changes: 1 addition & 1 deletion book/src/continuous-integration/workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ jobs:
- uses: actions/checkout@v3
- uses: foundry-rs/setup-snfoundry@v1
with:
starknet-foundry-version: 0.9.0
starknet-foundry-version: 0.9.1
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "0.7.0"
Expand Down
2 changes: 1 addition & 1 deletion src/bank/bank.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mod Bank {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl BankImpl of super::IBank<ContractState> {
fn initialize(
ref self: ContractState,
Expand Down
2 changes: 1 addition & 1 deletion src/bank/strict_bank.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ mod StrictBank {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl StrictBank of super::IStrictBank<ContractState> {
fn initialize(
ref self: ContractState,
Expand Down
4 changes: 2 additions & 2 deletions src/callback/mocks.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ mod CallbackMock {
}


#[external(v0)]
#[abi(embed_v0)]
impl ICallbackMockImpl of super::ICallbackMock<ContractState> {
fn get_counter(self: @ContractState) -> u32 {
self.counter.read()
}
}

#[external(v0)]
#[abi(embed_v0)]
impl IDepositCallbackReceiverImpl of IDepositCallbackReceiver<ContractState> {
fn after_deposit_execution(
ref self: ContractState, key: felt252, deposit: Deposit, log_data: Array<felt252>,
Expand Down
2 changes: 1 addition & 1 deletion src/chain/chain.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod Chain {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl Chain of super::IChain<ContractState> {
fn get_block_number(self: @ContractState) -> u64 {
starknet::info::get_block_number()
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ mod Config {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl ConfigImpl of super::IConfig<ContractState> {
fn set_bool(
ref self: ContractState, base_key: felt252, data: Array<felt252>, value: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/config/timelock.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ mod Timelock {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl TimelockImpl of super::ITimelock<ContractState> {}
}
2 changes: 1 addition & 1 deletion src/data/data_store.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ mod DataStore {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl DataStore of super::IDataStore<ContractState> {
// *************************************************************************
// Felt252 related functions.
Expand Down
2 changes: 1 addition & 1 deletion src/deposit/deposit_vault.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ mod DepositVault {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl DepositVaultImpl of super::IDepositVault<ContractState> {
fn initialize(
ref self: ContractState,
Expand Down
2 changes: 1 addition & 1 deletion src/event/event_emitter.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ mod EventEmitter {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl EventEmitterImpl of super::IEventEmitter<ContractState> {
/// Emits the `ClaimableCollateralUpdated` event.
fn emit_claimable_collateral_updated(
Expand Down
4 changes: 2 additions & 2 deletions src/event/event_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl LogDataImpl of LogDataTrait {

/// Deserialize all the sub-dicts serialized into a LogData
fn deserialize(ref serialized: Span<felt252>) -> Option<LogData> {
// There should be the right amount of dictionnaries serialized
// There should be the right amount of dictionaries serialized
if serialized.occurrences_of(END_OF_DICT) != DICTS_IN_LOGDATA {
panic_with_felt252('serialized format error');
}
Expand Down Expand Up @@ -166,7 +166,7 @@ impl LogDataImpl of LogDataTrait {
// UTILITY FUNCTION
//

/// Pop every elements from the span until the next occurences of END_OF_DICT or
/// Pop every elements from the span until the next occurrences of END_OF_DICT or
/// the end of the Span and return those values in a Span.
fn get_next_dict_serialized(ref serialized: Span<felt252>) -> Span<felt252> {
let mut dict_data: Array<felt252> = array![];
Expand Down
2 changes: 1 addition & 1 deletion src/exchange/adl_handler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ mod AdlHandler {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl AdlHandlerImpl of super::IAdlHandler<ContractState> {
fn update_adl_state(
ref self: ContractState,
Expand Down
2 changes: 1 addition & 1 deletion src/exchange/base_order_handler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ mod BaseOrderHandler {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl BaseOrderHandlerImpl of super::IBaseOrderHandler<ContractState> {
fn initialize(
ref self: ContractState,
Expand Down
2 changes: 1 addition & 1 deletion src/exchange/deposit_handler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ mod DepositHandler {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl DepositHandlerImpl of super::IDepositHandler<ContractState> {
fn create_deposit(
ref self: ContractState, account: ContractAddress, params: CreateDepositParams
Expand Down
2 changes: 1 addition & 1 deletion src/exchange/liquidation_handler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ mod LiquidationHandler {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl LiquidationHandlerImpl of super::ILiquidationHandler<
ContractState
> { // executes a position liquidation
Expand Down
2 changes: 1 addition & 1 deletion src/exchange/order_handler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mod OrderHandler {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl OrderHandlerImpl of super::IOrderHandler<ContractState> {
fn create_order(
ref self: ContractState, account: ContractAddress, params: CreateOrderParams
Expand Down
2 changes: 1 addition & 1 deletion src/exchange/withdrawal_handler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ mod WithdrawalHandler {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl WithdrawalHandlerImpl of super::IWithdrawalHandler<ContractState> {
fn create_withdrawal(
ref self: ContractState, account: ContractAddress, params: CreateWithdrawalParams
Expand Down
2 changes: 1 addition & 1 deletion src/fee/fee_handler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ mod FeeHandler {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl FeeHandlerImpl of super::IFeeHandler<ContractState> {
fn initialize(
ref self: ContractState,
Expand Down
2 changes: 1 addition & 1 deletion src/market/market.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use zeroable::Zeroable;
use satoru::market::error::MarketError;
use satoru::market::market_token::{IMarketTokenDispatcher, IMarketTokenDispatcherTrait};

/// Deriving the `storage_access::StorageAccess` trait
/// Deriving the `storage_access::Store` trait
/// allows us to store the `Market` struct in a contract's storage.
/// We use `Copy` but this is inneficient.
/// TODO: Optimize this.
Expand Down
2 changes: 1 addition & 1 deletion src/market/market_factory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ mod MarketFactory {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl MarketFactory of super::IMarketFactory<ContractState> {
fn create_market(
ref self: ContractState,
Expand Down
3 changes: 1 addition & 2 deletions src/market/market_token.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ mod MarketToken {
//
// External
//

#[external(v0)]
#[abi(embed_v0)]
impl MarketTokenImpl of IMarketToken<ContractState> {
fn name(self: @ContractState) -> felt252 {
self.name.read()
Expand Down
2 changes: 1 addition & 1 deletion src/mock/governable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mod Governable {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl Governable of super::IGovernable<ContractState> {
fn initialize(ref self: ContractState, event_emitter_address: ContractAddress) {
assert(self.gov.read().is_zero(), MockError::ALREADY_INITIALIZED);
Expand Down
2 changes: 1 addition & 1 deletion src/mock/referral_storage.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ mod ReferralStorage {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl ReferralStorageImpl of super::IReferralStorage<ContractState> {
fn initialize(ref self: ContractState, event_emitter_address: ContractAddress) {
let mut gov_state = Governable::unsafe_new_contract_state();
Expand Down
2 changes: 1 addition & 1 deletion src/oracle/oracle.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ mod Oracle {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl OracleImpl of super::IOracle<ContractState> {
fn initialize(
ref self: ContractState,
Expand Down
45 changes: 31 additions & 14 deletions src/oracle/oracle_store.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ mod OracleStore {
/// Interface to interact with the `EventEmitter` contract.
event_emitter: IEventEmitterDispatcher,
// NOTE: temporarily implemented to complete oracle tests.
signers: List<ContractAddress>
signers: List<ContractAddress>,
signers_indexes: LegacyMap<ContractAddress, u32>
}

// *************************************************************************
Expand All @@ -107,7 +108,7 @@ mod OracleStore {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl OracleStoreImpl of super::IOracleStore<ContractState> {
fn initialize(
ref self: ContractState,
Expand All @@ -125,29 +126,45 @@ mod OracleStore {
self.role_store.write(IRoleStoreDispatcher { contract_address: role_store_address });
}

fn add_signer(ref self: ContractState, account: ContractAddress) { // TODO
// NOTE: temporarily implemented to complete oracle tests.
fn add_signer(ref self: ContractState, account: ContractAddress) {
let mut signers = self.signers.read();
let index = signers.len();
signers.append(account);
self.signers_indexes.write(account, index);
}

fn remove_signer(ref self: ContractState, account: ContractAddress) { // TODO
fn remove_signer(ref self: ContractState, account: ContractAddress) {
let mut signers = self.signers.read();
let last_signer_index = signers.len();
let signer_to_remove_index = self.signers_indexes.read(account);
let last_signer = signers.get(last_signer_index).expect('failed to get last signer');
signers.set(signer_to_remove_index, last_signer);
self.signers_indexes.write(last_signer, signer_to_remove_index);
signers.len = signers.len() - 1;
}

fn get_signer_count(self: @ContractState) -> u128 { // TODO
0
fn get_signer_count(self: @ContractState) -> u128 {
self.signers.read().len().into()
}

fn get_signer(self: @ContractState, index: usize) -> ContractAddress { // TODO
fn get_signer(self: @ContractState, index: usize) -> ContractAddress {
// NOTE: temporarily implemented to complete oracle tests.
let mut signers = self.signers.read();
signers.get(index).expect('array get failed')
self.signers.read().get(index).expect('failed to get signer')
}

fn get_signers(
self: @ContractState, start: u128, end: u128
) -> Array<ContractAddress> { // TODO
ArrayTrait::new()
fn get_signers(self: @ContractState, start: u128, end: u128) -> Array<ContractAddress> {
let mut signers_subset: Array<ContractAddress> = ArrayTrait::new();
let signers = self.signers.read();

let mut index: u32 = start.try_into().expect('failed convertion u32 to u128');
loop {
if start == end {
break;
}
signers_subset.append(signers.get(index).expect('out of bound signer index'))
};

signers_subset
}
}
}
2 changes: 1 addition & 1 deletion src/oracle/price_feed.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod PriceFeed {
#[storage]
struct Storage {}

#[external(v0)]
#[abi(embed_v0)]
impl PriceFeedImpl of super::IPriceFeed<ContractState> {
fn get_data_median(self: @ContractState, data_type: DataType) -> PragmaPricesResponse {
PragmaPricesResponse {
Expand Down
2 changes: 1 addition & 1 deletion src/order/order_vault.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ mod OrderVault {
// *************************************************************************
// EXTERNAL FUNCTIONS
// *************************************************************************
#[external(v0)]
#[abi(embed_v0)]
impl OrderVaultImpl of super::IOrderVault<ContractState> {
fn transfer_out(
ref self: ContractState,
Expand Down
Loading

0 comments on commit e668816

Please sign in to comment.