Skip to content

Commit

Permalink
feat: stake rewards to vault
Browse files Browse the repository at this point in the history
  • Loading branch information
bucurdavid committed Jul 29, 2024
1 parent 2f28d69 commit 35f7f5a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
40 changes: 40 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,44 @@ pub trait LifeBondingContract:
self.total_bond_amount()
.update(|value| *value += &payment.amount);
}

#[endpoint(stakeRewards)]
fn stake_rewards(
&self,
original_caller: ManagedAddress,
token_identifier: TokenIdentifier,
amount: BigUint,
) {
let caller = self.blockchain().get_caller();
require!(
caller == self.liveliness_stake_address().get(),
ERR_ENDPOINT_CALLABLE_ONLY_BY_ACCEPTED_CALLERS
);

require!(
!self
.address_vault_nonce(&caller, &token_identifier)
.is_empty(),
ERR_VAULT_NONCE_NOT_SET
);

let vault_nonce = self.address_vault_nonce(&caller, &token_identifier).get();

let bond_id = self
.bonds_ids()
.get_id_non_zero((token_identifier.clone(), vault_nonce));

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

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

let current_timestamp = self.blockchain().get_block_timestamp();

bond_cache.unbond_timestamp = current_timestamp + bond_cache.lock_period;
bond_cache.bond_timestamp = current_timestamp;
bond_cache.bond_amount += &amount;
bond_cache.remaining_amount += &amount;

self.total_bond_amount().update(|value| *value += amount);
}
}
21 changes: 20 additions & 1 deletion src/life_bonding_sc_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,25 @@ where
.original_result()
}

pub fn stake_rewards<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<TokenIdentifier<Env::Api>>,
Arg2: ProxyArg<BigUint<Env::Api>>,
>(
self,
original_caller: Arg0,
token_identifier: Arg1,
amount: Arg2,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("stakeRewards")
.argument(&original_caller)
.argument(&token_identifier)
.argument(&amount)
.original_result()
}

pub fn compensation_blacklist<
Arg0: ProxyArg<u64>,
>(
Expand Down Expand Up @@ -837,7 +856,7 @@ where
}

#[type_abi]
#[derive(TopEncode, TopDecode, NestedDecode, NestedEncode)]
#[derive(TopEncode, TopDecode)]
pub struct ContractConfiguration<Api>
where
Api: ManagedTypeApi,
Expand Down
5 changes: 3 additions & 2 deletions wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

// Init: 1
// Upgrade: 1
// Endpoints: 55
// Endpoints: 56
// Async Callback (empty): 1
// Total number of exported functions: 58
// Total number of exported functions: 59

#![no_std]

Expand All @@ -27,6 +27,7 @@ multiversx_sc_wasm_adapter::endpoints! {
claimRefund => claim_refund
setVaultNonce => set_vault_nonce
topUpVault => top_up_vault
stakeRewards => stake_rewards
getCompensationBlacklist => compensation_blacklist
getTotalBondAmount => total_bond_amount
getAddressVaultNone => address_vault_nonce
Expand Down

0 comments on commit 35f7f5a

Please sign in to comment.