From 2583b90521b6d66db573f6abbf2957e454e750c2 Mon Sep 17 00:00:00 2001 From: parketh Date: Thu, 18 Apr 2024 00:59:34 +0100 Subject: [PATCH] fix: some interfaces + naming convention --- src/contracts/strategy.cairo | 27 ++++++++++++++----- src/interfaces.cairo | 2 +- ...trategy.cairo => IReversionStrategy.cairo} | 7 +++-- src/tests/helpers.cairo | 6 ++--- src/tests/test_strategy.cairo | 10 +++---- 5 files changed, 34 insertions(+), 18 deletions(-) rename src/interfaces/{ITrendStrategy.cairo => IReversionStrategy.cairo} (96%) diff --git a/src/contracts/strategy.cairo b/src/contracts/strategy.cairo index 8f1c915..9f810d4 100644 --- a/src/contracts/strategy.cairo +++ b/src/contracts/strategy.cairo @@ -12,7 +12,7 @@ pub mod ReversionStrategy { // Local imports. use haiko_strategy_reversion::libraries::{trend_math, store_packing::StrategyStateStorePacking}; use haiko_strategy_reversion::types::{Trend, StrategyState}; - use haiko_strategy_reversion::interfaces::ITrendStrategy::ITrendStrategy; + use haiko_strategy_reversion::interfaces::IReversionStrategy::IReversionStrategy; use haiko_strategy_reversion::interfaces::IVaultToken::{ IVaultTokenDispatcher, IVaultTokenDispatcherTrait }; @@ -229,6 +229,9 @@ pub mod ReversionStrategy { // Get list of positions currently placed by strategy. // + // # Arguments + // * `market_id` - market id + // // # Returns // * `positions` - list of positions fn placed_positions(self: @ContractState, market_id: felt252) -> Span { @@ -261,6 +264,10 @@ pub mod ReversionStrategy { // are queued, the returned list will match the list returned by `placed_positions`. Note that // the list of queued positions can differ depending on the incoming swap. // + // # Arguments + // * `market_id` - market id + // * `swap_params` - (optional) incoming swap parameters + // // # Returns // * `positions` - list of positions fn queued_positions( @@ -312,7 +319,6 @@ pub mod ReversionStrategy { Trend::Down => !is_buy && curr_limit < bid_upper, } }; - // println!("update_bid: {}, update_ask: {}", update_bid, update_ask); // Fetch amounts in existing position. let contract: felt252 = get_contract_address().into(); @@ -405,7 +411,7 @@ pub mod ReversionStrategy { } #[abi(embed_v0)] - impl ReversionStrategy of ITrendStrategy { + impl ReversionStrategy of IReversionStrategy { // Contract owner fn owner(self: @ContractState) -> ContractAddress { self.owner.read() @@ -421,6 +427,11 @@ pub mod ReversionStrategy { self.strategy_state.read(market_id).trend } + // Queued trend + fn queued_trend(self: @ContractState, market_id: felt252) -> Trend { + self.strategy_state.read(market_id).queued_trend + } + // Strategy state fn strategy_state(self: @ContractState, market_id: felt252) -> StrategyState { self.strategy_state.read(market_id) @@ -867,6 +878,9 @@ pub mod ReversionStrategy { // Manually trigger contract to collect all outstanding positions and pause the contract. // Only callable by owner. + // + // # Arguments + // * `market_id` - market id fn collect_and_pause(ref self: ContractState, market_id: felt252) { self.assert_owner(); self._collect_and_pause(market_id); @@ -879,6 +893,9 @@ pub mod ReversionStrategy { // * `receiver` - address to receive fees // * `token` - token to collect fees for // * `amount` - amount of fees requested + // + // # Returns + // * `amount` - amount collected fn collect_withdraw_fees( ref self: ContractState, receiver: ContractAddress, token: ContractAddress, amount: u256 ) -> u256 { @@ -1050,10 +1067,6 @@ pub mod ReversionStrategy { let mut ask = *placed_positions.at(1); let next_bid = *queued_positions.at(0); let next_ask = *queued_positions.at(1); - // println!("[placed] bid_lower: {}, bid_upper: {}, bid_liquidity: {}", bid.lower_limit, bid.upper_limit, bid.liquidity); - // println!("[placed] ask_lower: {}, ask_upper: {}, ask_liquidity: {}", ask.lower_limit, ask.upper_limit, ask.liquidity); - // println!("[queued] bid_lower: {}, bid_upper: {}, bid_liquidity: {}", next_bid.lower_limit, next_bid.upper_limit, next_bid.liquidity); - // println!("[queued] ask_lower: {}, ask_upper: {}, ask_liquidity: {}", next_ask.lower_limit, next_ask.upper_limit, next_ask.liquidity); let update_bid: bool = next_bid.lower_limit != bid.lower_limit || next_bid.upper_limit != bid.upper_limit; let update_ask: bool = next_ask.lower_limit != ask.lower_limit diff --git a/src/interfaces.cairo b/src/interfaces.cairo index c5bb25b..c529ab4 100644 --- a/src/interfaces.cairo +++ b/src/interfaces.cairo @@ -1,2 +1,2 @@ -pub mod ITrendStrategy; +pub mod IReversionStrategy; pub mod IVaultToken; diff --git a/src/interfaces/ITrendStrategy.cairo b/src/interfaces/IReversionStrategy.cairo similarity index 96% rename from src/interfaces/ITrendStrategy.cairo rename to src/interfaces/IReversionStrategy.cairo index 08bb833..5459e91 100644 --- a/src/interfaces/ITrendStrategy.cairo +++ b/src/interfaces/IReversionStrategy.cairo @@ -10,16 +10,19 @@ use haiko_lib::types::core::{PositionInfo, SwapParams}; #[starknet::interface] -pub trait ITrendStrategy { +pub trait IReversionStrategy { // Contract owner fn owner(self: @TContractState) -> ContractAddress; // Queued contract owner, used for ownership transfers fn queued_owner(self: @TContractState) -> ContractAddress; - // Set trend for a given market + // Get trend for a given market fn trend(self: @TContractState, market_id: felt252) -> Trend; + // Get queued trend for a given market + fn queued_trend(self: @TContractState, market_id: felt252) -> Trend; + // Strategy state fn strategy_state(self: @TContractState, market_id: felt252) -> StrategyState; diff --git a/src/tests/helpers.cairo b/src/tests/helpers.cairo index d87b2b9..9065ab0 100644 --- a/src/tests/helpers.cairo +++ b/src/tests/helpers.cairo @@ -4,14 +4,14 @@ use starknet::ContractAddress; use starknet::class_hash::ClassHash; // Local imports. -use haiko_strategy_reversion::interfaces::ITrendStrategy::ITrendStrategyDispatcher; +use haiko_strategy_reversion::interfaces::IReversionStrategy::IReversionStrategyDispatcher; // External imports. use snforge_std::{declare, ContractClassTrait}; pub fn deploy_trend_strategy( owner: ContractAddress, market_manager: ContractAddress, vault_token_class: ClassHash, -) -> ITrendStrategyDispatcher { +) -> IReversionStrategyDispatcher { let contract = declare("ReversionStrategy"); let name: ByteArray = "Trend"; let symbol: ByteArray = "TRND"; @@ -22,5 +22,5 @@ pub fn deploy_trend_strategy( market_manager.serialize(ref calldata); vault_token_class.serialize(ref calldata); let contract_address = contract.deploy(@calldata).unwrap(); - ITrendStrategyDispatcher { contract_address } + IReversionStrategyDispatcher { contract_address } } diff --git a/src/tests/test_strategy.cairo b/src/tests/test_strategy.cairo index 5a61e97..289def5 100644 --- a/src/tests/test_strategy.cairo +++ b/src/tests/test_strategy.cairo @@ -5,7 +5,7 @@ use starknet::ContractAddress; use haiko_strategy_reversion::contracts::strategy::ReversionStrategy; use haiko_strategy_reversion::types::{Trend, StrategyState}; use haiko_strategy_reversion::interfaces::{ - ITrendStrategy::{ITrendStrategyDispatcher, ITrendStrategyDispatcherTrait}, + IReversionStrategy::{IReversionStrategyDispatcher, IReversionStrategyDispatcherTrait}, IVaultToken::{IVaultTokenDispatcher, IVaultTokenDispatcherTrait} }; use haiko_strategy_reversion::tests::helpers::deploy_trend_strategy; @@ -43,7 +43,7 @@ fn _before( ERC20ABIDispatcher, ERC20ABIDispatcher, felt252, - ITrendStrategyDispatcher, + IReversionStrategyDispatcher, Option, ) { // Deploy market manager. @@ -113,7 +113,7 @@ fn before() -> ( ERC20ABIDispatcher, ERC20ABIDispatcher, felt252, - ITrendStrategyDispatcher, + IReversionStrategyDispatcher, ERC20ABIDispatcher, ) { let (market_manager, base_token, quote_token, market_id, strategy, token) = _before(true); @@ -125,7 +125,7 @@ fn before_skip_initialise() -> ( ERC20ABIDispatcher, ERC20ABIDispatcher, felt252, - ITrendStrategyDispatcher, + IReversionStrategyDispatcher, ) { let (market_manager, base_token, quote_token, market_id, strategy, _) = _before(false); (market_manager, base_token, quote_token, market_id, strategy) @@ -1309,7 +1309,7 @@ struct Snapshot { fn _snapshot_state( market_manager: IMarketManagerDispatcher, - strategy: ITrendStrategyDispatcher, + strategy: IReversionStrategyDispatcher, market_id: felt252, base_token: ERC20ABIDispatcher, quote_token: ERC20ABIDispatcher,