Skip to content

Commit

Permalink
fix: use all available gas for xcc
Browse files Browse the repository at this point in the history
  • Loading branch information
vasyafromrussia committed Feb 21, 2024
1 parent bb9acde commit f5aac58
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Binary file modified res/sweat.wasm
Binary file not shown.
18 changes: 12 additions & 6 deletions sweat/src/defer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ use sweat_model::SweatDefer;

use crate::{internal_deposit, Contract, ContractExt};

const ONE_GGAS: u64 = Gas::ONE_TERA.0 / 1000;
const GAS_FOR_DEFER_CALLBACK: Gas = Gas(5 * Gas::ONE_TERA.0);
const GAS_FOR_DEFER: Gas = Gas(30 * Gas::ONE_TERA.0);

#[near_bindgen]
impl SweatDefer for Contract {
fn defer_batch(&mut self, steps_batch: Vec<(AccountId, u32)>, holding_account_id: AccountId) -> PromiseOrValue<()> {
require!(
env::prepaid_gas() > GAS_FOR_DEFER,
"Not enough gas to complete the operation"
);

require!(
self.oracles.contains(&env::predecessor_account_id()),
"Unauthorized access! Only oracle can call that!"
);

let batch_len = steps_batch.len() as u64;

let mut accounts_tokens: Vec<(AccountId, U128)> = Vec::new();
let mut total_effective: U128 = U128(0);
let mut total_fee: U128 = U128(0);
Expand All @@ -36,8 +40,10 @@ impl SweatDefer for Contract {
"amounts": accounts_tokens,
});

// These values calculated in `measure_record_batch_for_hold_test` in claim contract.
let record_batch_for_hold_gas = Gas::ONE_TERA * 8 + Gas(batch_len * ONE_GGAS * 320);
let record_batch_for_hold_gas = Gas(env::prepaid_gas()
.0
.checked_sub(GAS_FOR_DEFER.0)
.unwrap_or_else(|| panic_str("Prepaid gas overflow")));

Promise::new(holding_account_id.clone())
.function_call(
Expand All @@ -48,7 +54,7 @@ impl SweatDefer for Contract {
)
.then(
ext_ft_transfer_callback::ext(env::current_account_id())
.with_static_gas(Gas::ONE_TERA * 5)
.with_static_gas(GAS_FOR_DEFER_CALLBACK)
.on_record(
holding_account_id,
total_effective,
Expand Down

0 comments on commit f5aac58

Please sign in to comment.