diff --git a/farm/contract/lib.rs b/farm/contract/lib.rs index 4672f1a3..37def6a9 100644 --- a/farm/contract/lib.rs +++ b/farm/contract/lib.rs @@ -5,7 +5,7 @@ mod farm { type TokenId = AccountId; type UserId = AccountId; use amm_helpers::{ensure, math::casted_mul, types::WrappedU256}; - use farm_trait::{Farm, FarmDetails, FarmError}; + use farm_trait::{Farm, FarmDetails, FarmError, Ownable}; use ink::{codegen::EmitEvent, contract_ref, reflect::ContractEventBase, storage::Mapping}; use ink::prelude::{vec, vec::Vec}; @@ -511,6 +511,21 @@ mod farm { } } + impl Ownable for FarmContract { + #[ink(message)] + fn owner(&self) -> AccountId { + self.owner + } + + #[ink(message)] + fn set_owner(&mut self, new_owner: AccountId) -> Result<(), FarmError> { + ensure!(self.env().caller() == self.owner, FarmError::CallerNotOwner); + ensure!(!self.is_active, FarmError::FarmIsRunning); + self.owner = new_owner; + Ok(()) + } + } + pub fn rewards_per_share_in_time_interval( reward_rate: U256, total_shares: u128, diff --git a/farm/trait/lib.rs b/farm/trait/lib.rs index ad024354..5faf5d00 100644 --- a/farm/trait/lib.rs +++ b/farm/trait/lib.rs @@ -133,3 +133,12 @@ pub trait Farm { #[ink(message)] fn view_farm_details(&self) -> FarmDetails; } + +#[ink::trait_definition] +pub trait Ownable { + #[ink(message)] + fn set_owner(&mut self, new_owner: AccountId) -> Result<(), FarmError>; + + #[ink(message)] + fn owner(&self) -> AccountId; +}