Skip to content

Commit

Permalink
fix: clear bond & generate rewards before top up
Browse files Browse the repository at this point in the history
  • Loading branch information
bucurdavid committed Jul 29, 2024
1 parent e05ce24 commit ddb6dba
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub trait LifeBondingContract:
.compensations_ids()
.get_id_non_zero((token_identifier, nonce));

let bond_cache = BondCache::new(self, bond_id);
let mut bond_cache = BondCache::new(self, bond_id);

require!(bond_cache.address == caller, ERR_BOND_NOT_FOUND);

Expand Down Expand Up @@ -226,6 +226,8 @@ pub trait LifeBondingContract:
&penalty_amount,
);

bond_cache.clear();

self.bonds().swap_remove(&bond_id);
self.address_bonds(&caller).swap_remove(&bond_id);
}
Expand Down Expand Up @@ -404,6 +406,12 @@ pub trait LifeBondingContract:
fn top_up_vault(&self, token_identifier: TokenIdentifier, nonce: u64) {
let caller = self.blockchain().get_caller();

self.tx()
.to(self.liveliness_stake_address().get())
.typed(core_mx_liveliness_stake::liveliness_stake_proxy::CoreMxLivelinessStakeProxy)
.generate_rewards()
.sync_call();

require!(
self.address_vault_nonce(&caller, &token_identifier).get() == nonce,
ERR_VAULT_NONCE_NOT_SET
Expand Down

0 comments on commit ddb6dba

Please sign in to comment.