defuse/contract/tokens/nep141/
storage_deposit.rs

1use defuse_core::intents::tokens::StorageDeposit;
2use near_contract_standards::storage_management::ext_storage_management;
3use near_sdk::{Gas, Promise, env, near, require};
4
5use crate::contract::{Contract, ContractExt, tokens::STORAGE_DEPOSIT_GAS};
6
7#[near]
8impl Contract {
9    pub(crate) const DO_STORAGE_DEPOSIT_GAS: Gas =
10        Gas::from_tgas(5).saturating_add(STORAGE_DEPOSIT_GAS);
11
12    #[private]
13    pub fn do_storage_deposit(storage_deposit: StorageDeposit) -> Promise {
14        require!(
15            matches!(env::promise_result_checked(0, 0), Ok(data) if data.is_empty()),
16            "near_withdraw failed",
17        );
18
19        ext_storage_management::ext(storage_deposit.contract_id)
20            .with_attached_deposit(storage_deposit.amount)
21            .with_static_gas(STORAGE_DEPOSIT_GAS)
22            // do not distribute remaining gas here
23            .with_unused_gas_weight(0)
24            .storage_deposit(Some(storage_deposit.deposit_for_account_id), None)
25    }
26}