forked from theahaco/scaffold-stellar-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontract.rs
More file actions
72 lines (59 loc) · 2.02 KB
/
contract.rs
File metadata and controls
72 lines (59 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Fungible AllowList Example Contract.
//! This contract showcases how to integrate the AllowList extension with a
//! SEP-41-compliant fungible token. It includes essential features such as
//! controlled token transfers by an admin who can allow or disallow specific
//! accounts.
use soroban_sdk::{
contract, contractimpl, symbol_short, Address, Env, MuxedAddress, String, Symbol, Vec,
};
use stellar_access::access_control::{self as access_control, AccessControl};
use stellar_macros::only_role;
use stellar_tokens::fungible::{
allowlist::{AllowList, FungibleAllowList},
burnable::FungibleBurnable,
Base, FungibleToken,
};
#[contract]
pub struct ExampleContract;
#[contractimpl]
impl ExampleContract {
pub fn __constructor(
e: &Env,
name: String,
symbol: String,
admin: Address,
manager: Address,
initial_supply: i128,
) {
Base::set_metadata(e, 18, name, symbol);
access_control::set_admin(e, &admin);
// create a role "manager" and grant it to `manager`
access_control::grant_role_no_auth(e, &manager, &symbol_short!("manager"), &admin);
// Allow the admin to transfer tokens
AllowList::allow_user(e, &admin);
// Mint initial supply to the admin
Base::mint(e, &admin, initial_supply);
}
}
#[contractimpl(contracttrait)]
impl FungibleToken for ExampleContract {
type ContractType = AllowList;
}
#[contractimpl]
impl FungibleAllowList for ExampleContract {
fn allowed(e: &Env, account: Address) -> bool {
AllowList::allowed(e, &account)
}
#[only_role(operator, "manager")]
fn allow_user(e: &Env, user: Address, operator: Address) {
AllowList::allow_user(e, &user)
}
#[only_role(operator, "manager")]
fn disallow_user(e: &Env, user: Address, operator: Address) {
AllowList::disallow_user(e, &user)
}
}
#[contractimpl(contracttrait)]
impl AccessControl for ExampleContract {}
#[contractimpl(contracttrait)]
impl FungibleBurnable for ExampleContract {}