Skip to content

Commit

Permalink
fix: hacken auditing finding F-2024-1975 (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
linguists committed May 7, 2024
1 parent 4e8a6d2 commit ee3088a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
26 changes: 26 additions & 0 deletions contracts/linear/src/events.rs
Expand Up @@ -149,6 +149,32 @@ pub enum Event<'a> {
ValidatorRemoved {
account_id: &'a AccountId,
},
// Owner
ChangeOwner {
old_owner_id: &'a AccountId,
new_owner_id: &'a AccountId,
},
AddManager {
manager_id: &'a AccountId,
},
RemoveManager {
manager_id: &'a AccountId,
},
SetBeneficiary {
account_id: &'a AccountId,
bps: &'a u32,
},
RemoveBeneficiary {
account_id: &'a AccountId,
},
SetTreasury {
account_id: &'a AccountId,
},
SetWhitelist {
account_id: &'a AccountId,
},
PauseContract {},
ResumeContract {},
}

impl Event<'_> {
Expand Down
43 changes: 40 additions & 3 deletions contracts/linear/src/owner.rs
@@ -1,3 +1,4 @@
use crate::events::Event;
use crate::*;
use near_sdk::near_bindgen;

Expand All @@ -7,19 +8,36 @@ const MAX_BENEFICIARIES: u64 = 10;
impl LiquidStakingContract {
pub fn set_owner(&mut self, new_owner_id: AccountId) {
self.assert_owner();
let old_owner_id = self.owner_id.clone();
self.owner_id = new_owner_id;
Event::ChangeOwner {
old_owner_id: &old_owner_id,
new_owner_id: &self.owner_id,
}
.emit();
}

pub fn add_manager(&mut self, new_manager_id: AccountId) {
self.assert_running();
self.assert_owner();
self.internal_add_manager(&new_manager_id);
Event::AddManager {
manager_id: &new_manager_id,
}
.emit();
}

pub fn remove_manager(&mut self, manager_id: AccountId) -> bool {
self.assert_running();
self.assert_owner();
self.internal_remove_manager(&manager_id)
let removed = self.internal_remove_manager(&manager_id);
if removed {
Event::RemoveManager {
manager_id: &manager_id,
}
.emit();
}
removed
}

pub fn set_beneficiary(&mut self, account_id: AccountId, bps: u32) {
Expand All @@ -43,26 +61,43 @@ impl LiquidStakingContract {
);

self.beneficiaries.insert(&account_id, &bps);
Event::SetBeneficiary {
account_id: &account_id,
bps: &bps,
}
.emit();
}

pub fn remove_beneficiary(&mut self, account_id: AccountId) {
self.assert_running();
self.assert_owner();
self.beneficiaries.remove(&account_id);
Event::RemoveBeneficiary {
account_id: &account_id,
}
.emit();
}

/// Set account ID of the treasury
pub fn set_treasury(&mut self, account_id: AccountId) {
self.assert_running();
self.assert_owner();
self.treasury_id = account_id;
self.treasury_id = account_id.clone();
Event::SetTreasury {
account_id: &account_id,
}
.emit();
}

/// Set whitelist account ID
pub fn set_whitelist_contract_id(&mut self, account_id: AccountId) {
self.assert_running();
self.assert_owner();
self.whitelist_account_id = Some(account_id);
self.whitelist_account_id = Some(account_id.clone());
Event::SetWhitelist {
account_id: &account_id,
}
.emit();
}

// --- Pause ---
Expand All @@ -71,11 +106,13 @@ impl LiquidStakingContract {
self.assert_owner();
require!(!self.paused, ERR_ALREADY_PAUSED);
self.paused = true;
Event::PauseContract {}.emit();
}

pub fn resume(&mut self) {
self.assert_owner();
require!(self.paused, ERR_NOT_PAUSED);
self.paused = false;
Event::ResumeContract {}.emit();
}
}
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ee3088a

Please sign in to comment.