diff --git a/Cargo.lock b/Cargo.lock index 784e9583..e4e92587 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,7 +42,6 @@ version = "0.1.0" dependencies = [ "amm-helpers", "ink", - "openbrush", "parity-scale-codec", "primitive-types 0.12.1", "psp22-traits", diff --git a/farm/contracts/Cargo.toml b/farm/contracts/Cargo.toml index 3cd09b70..788e32ea 100644 --- a/farm/contracts/Cargo.toml +++ b/farm/contracts/Cargo.toml @@ -14,7 +14,6 @@ scale-info = { version = "2.3", default-features = false, features = [ "derive", ], optional = true } -openbrush = { version = "3.2.0", default-features = false } primitive-types = { version = "0.12.1", default-features = false, features = [ "codec", ] } @@ -31,7 +30,6 @@ std = [ "scale/std", "scale-info/std", "psp22-traits/std", - "openbrush/std", "primitive-types/std", "primitive-types/scale-info", "sp-arithmetic/std", diff --git a/farm/contracts/lib.rs b/farm/contracts/lib.rs index adb910c6..05027f3a 100644 --- a/farm/contracts/lib.rs +++ b/farm/contracts/lib.rs @@ -28,8 +28,6 @@ mod farm { rewards_earned, }; - use openbrush::modifiers; - use primitive_types::U256; use psp22_traits::PSP22; @@ -220,8 +218,8 @@ mod farm { /// 1. Farm is not in `Running` state. /// 2. Farm's `end` timestamp is still in the future. #[ink(message)] - #[modifiers(ensure_running(true))] pub fn stop(&mut self) -> Result<(), FarmError> { + self.ensure_running()?; let mut running = self.get_state()?; // We allow owner of the farm to stop it prematurely @@ -251,8 +249,9 @@ mod farm { /// Deposits the given amount of tokens into the farm. #[ink(message)] - #[modifiers(ensure_running(true), non_zero_amount(amount))] pub fn deposit(&mut self, amount: u128) -> Result<(), FarmError> { + Self::assert_non_zero_amount(amount)?; + self.ensure_running()?; self.update_reward_index()?; self.add_shares(amount) } @@ -260,17 +259,18 @@ mod farm { /// Deposits all of the LP tokens the caller has. /// NOTE: Requires that the caller has approved the farm to spend their tokens. #[ink(message)] - #[modifiers(ensure_running(true))] pub fn deposit_all(&mut self) -> Result<(), FarmError> { + self.ensure_running()?; self.update_reward_index()?; let token_balance = safe_balance_of(&self.pool.into(), self.env().caller()); + Self::assert_non_zero_amount(token_balance)?; self.add_shares(token_balance) } /// Withdraws the given amount of shares from the farm. #[ink(message)] - #[modifiers(non_zero_amount(amount))] pub fn withdraw(&mut self, amount: u128) -> Result<(), FarmError> { + Self::assert_non_zero_amount(amount)?; self.update_reward_index()?; let caller = self.env().caller(); @@ -446,6 +446,20 @@ mod farm { fn get_state(&self) -> Result { self.state.get().ok_or(FarmError::StateMissing) } + + fn ensure_running(&self) -> Result<(), FarmError> { + if !self.is_running { + return Err(FarmError::NotRunning) + } + Ok(()) + } + + fn assert_non_zero_amount(amount: u128) -> Result<(), FarmError> { + if amount == 0 { + return Err(FarmError::InvalidAmountArgument) + } + Ok(()) + } } type TokenId = AccountId; @@ -570,34 +584,6 @@ mod farm { } } - use openbrush::modifier_definition; - - #[modifier_definition] - pub fn ensure_running( - instance: &mut Farm, - body: F, - should_be_running: bool, - ) -> Result - where - F: FnOnce(&mut Farm) -> Result, - { - if !should_be_running && instance.is_running { - return Err(FarmError::StillRunning) - } - body(instance) - } - - #[modifier_definition] - pub fn non_zero_amount(instance: &mut Farm, body: F, amount: u128) -> Result - where - F: FnOnce(&mut Farm) -> Result, - { - if amount == 0 { - return Err(FarmError::InvalidAmountArgument) - } - body(instance) - } - use ink::codegen::TraitCallBuilder; // We're making a concious choice here that we don't want to fail the whole transaction