loam_subcontract_ft/lib.rs
1#![no_std]
2use loam_sdk::{soroban_sdk::Lazy, subcontract};
3
4/// SEP-41: Fungible Token Interface
5///
6/// This trait defines a standard contract interface for fungible tokens on the Stellar network.
7/// It is a subset of the Stellar Asset contract and is compatible with the descriptive and token
8/// interfaces defined in CAP-46-6.
9///
10/// SEP-41 aims to provide a less opinionated interface than the Stellar Asset contract,
11/// supporting standard token functionality without the specialized behaviors of Stellar Assets.
12/// This allows for greater flexibility and interoperability among different token implementations.
13///
14/// For full specification, see: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0041.md
15#[subcontract]
16pub trait IsSep41 {
17 /// Returns the allowance for `spender` to transfer from `from`.
18 fn allowance(
19 &self,
20 from: loam_sdk::soroban_sdk::Address,
21 spender: loam_sdk::soroban_sdk::Address,
22 ) -> i128;
23
24 /// Set the allowance by `amount` for `spender` to transfer/burn from `from`.
25 fn approve(
26 &mut self,
27 from: loam_sdk::soroban_sdk::Address,
28 spender: loam_sdk::soroban_sdk::Address,
29 amount: i128,
30 live_until_ledger: u32,
31 );
32
33 /// Returns the balance of `id`.
34 fn balance(&self, id: loam_sdk::soroban_sdk::Address) -> i128;
35
36 /// Transfer `amount` from `from` to `to`.
37 fn transfer(
38 &mut self,
39 from: loam_sdk::soroban_sdk::Address,
40 to: loam_sdk::soroban_sdk::Address,
41 amount: i128,
42 );
43
44 /// Transfer `amount` from `from` to `to`, consuming the allowance of `spender`.
45 fn transfer_from(
46 &mut self,
47 spender: loam_sdk::soroban_sdk::Address,
48 from: loam_sdk::soroban_sdk::Address,
49 to: loam_sdk::soroban_sdk::Address,
50 amount: i128,
51 );
52
53 /// Burn `amount` from `from`.
54 fn burn(&mut self, from: loam_sdk::soroban_sdk::Address, amount: i128);
55
56 /// Burn `amount` from `from`, consuming the allowance of `spender`.
57 fn burn_from(
58 &mut self,
59 spender: loam_sdk::soroban_sdk::Address,
60 from: loam_sdk::soroban_sdk::Address,
61 amount: i128,
62 );
63
64 /// Returns the number of decimals used to represent amounts of this token.
65 fn decimals(&self) -> u32;
66
67 /// Returns the name for this token.
68 fn name(&self) -> loam_sdk::soroban_sdk::String;
69
70 /// Returns the symbol for this token.
71 fn symbol(&self) -> loam_sdk::soroban_sdk::String;
72}
73
74#[subcontract]
75pub trait IsFungible: IsSep41 {
76 /// Increases the allowance that one address can spend on behalf of another address.
77 fn increase_allowance(
78 &mut self,
79 from: loam_sdk::soroban_sdk::Address,
80 spender: loam_sdk::soroban_sdk::Address,
81 amount: i128,
82 );
83
84 /// Decreases the allowance that one address can spend on behalf of another address.
85 fn decrease_allowance(
86 &mut self,
87 from: loam_sdk::soroban_sdk::Address,
88 spender: loam_sdk::soroban_sdk::Address,
89 amount: i128,
90 );
91
92 /// Returns the spendable balance of tokens for a specific address.
93 fn spendable_balance(&self, id: loam_sdk::soroban_sdk::Address) -> i128;
94
95 /// Checks if a specific address is authorized.
96 fn authorized(&self, id: loam_sdk::soroban_sdk::Address) -> bool;
97
98 /// Sets the authorization status of a specific address.
99 fn set_authorized(&mut self, id: loam_sdk::soroban_sdk::Address, authorize: bool);
100
101 /// Mints a specified amount of tokens to a specific address.
102 fn mint(&mut self, to: loam_sdk::soroban_sdk::Address, amount: i128);
103
104 /// Retrieves a specified amount of tokens from a specific address (clawback).
105 fn clawback(&mut self, from: loam_sdk::soroban_sdk::Address, amount: i128);
106
107 /// Sets a new admin address.
108 fn set_admin(&mut self, new_admin: loam_sdk::soroban_sdk::Address);
109}
110
111#[subcontract]
112pub trait IsInitable {
113 /// Initialize ft Subcontract
114 fn ft_init(
115 &mut self,
116 admin: loam_sdk::soroban_sdk::Address,
117 name: loam_sdk::soroban_sdk::String,
118 symbol: loam_sdk::soroban_sdk::String,
119 decimals: u32,
120 );
121}