defuse/tokens/
nep141.rs

1use near_contract_standards::fungible_token::receiver::FungibleTokenReceiver;
2use near_plugins::AccessControllable;
3use near_sdk::{AccountId, PromiseOrValue, ext_contract, json_types::U128};
4
5#[ext_contract(ext_ft_withdraw)]
6pub trait FungibleTokenWithdrawer: FungibleTokenReceiver + FungibleTokenWithdrawResolver {
7    /// Returns number of tokens were successfully withdrawn.
8    ///
9    /// Optionally can specify `storage_deposit` for `receiver_id` on `token`.
10    /// The amount will be subtracted from user's NEP-141 `wNEAR` balance.
11    ///
12    /// NOTE: MUST attach 1 yⓃ for security purposes.
13    fn ft_withdraw(
14        &mut self,
15        token: AccountId,
16        receiver_id: AccountId,
17        amount: U128,
18        memo: Option<String>,
19        msg: Option<String>,
20    ) -> PromiseOrValue<U128>;
21}
22
23#[ext_contract(ext_ft_withdraw_resolver)]
24pub trait FungibleTokenWithdrawResolver {
25    fn ft_resolve_withdraw(
26        &mut self,
27        token: AccountId,
28        sender_id: AccountId,
29        amount: U128,
30        is_call: bool,
31    ) -> U128;
32}
33
34#[ext_contract(ext_ft_force_withdraw)]
35pub trait FungibleTokenForceWithdrawer: FungibleTokenWithdrawer + AccessControllable {
36    fn ft_force_withdraw(
37        &mut self,
38        owner_id: AccountId,
39        token: AccountId,
40        receiver_id: AccountId,
41        amount: U128,
42        memo: Option<String>,
43        msg: Option<String>,
44    ) -> PromiseOrValue<U128>;
45}