-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem_sc_proxy.rs
242 lines (222 loc) · 8.01 KB
/
system_sc_proxy.rs
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
use core::marker::PhantomData;
use crate::{
api::{AssetType, CallTypeApi, SendApi, StorageReadApi},
contract_base::{BlockchainWrapper, SendWrapper},
types::{
BigUint, KdaTokenType, ManagedAddress, ManagedBuffer, ManagedVec,
PropertiesInfo, RoyaltiesData, TokenIdentifier,
},
};
/// Proxy for the KDA system smart contract.
/// Unlike other contract proxies, this one has a fixed address,
/// so the proxy object doesn't really contain any data, it is more of a placeholder.
pub struct KDASystemSmartContractProxy<SA>
where
SA: SendApi + 'static,
{
_phantom: PhantomData<SA>,
}
impl<SA> KDASystemSmartContractProxy<SA>
where
SA: SendApi + 'static,
{
/// Constructor.
pub fn new_proxy_obj() -> Self {
KDASystemSmartContractProxy {
_phantom: PhantomData,
}
}
}
impl<SA> KDASystemSmartContractProxy<SA>
where
SA: StorageReadApi + CallTypeApi + 'static,
{
fn get_sc_address() -> ManagedAddress<SA> {
let b_wrapper = BlockchainWrapper::new();
b_wrapper.get_sc_address()
}
/// Produces a contract call to the KDA system SC,
/// which causes it to issue a new fungible KDA token.
pub fn issue_fungible(
self,
token_display_name: &ManagedBuffer<SA>,
num_decimals: u32,
token_ticker: &ManagedBuffer<SA>,
initial_supply: &BigUint<SA>,
max_supply: &BigUint<SA>,
properties: &PropertiesInfo,
) -> TokenIdentifier<SA> {
self.issue(
KdaTokenType::Fungible,
token_display_name,
token_ticker,
num_decimals,
initial_supply,
max_supply,
properties,
)
}
/// Produces a contract call to the KDA system SC,
/// which causes it to issue a new non-fungible KDA token.
pub fn issue_non_fungible(
self,
token_display_name: &ManagedBuffer<SA>,
token_ticker: &ManagedBuffer<SA>,
properties: &PropertiesInfo,
) -> TokenIdentifier<SA> {
self.issue(
KdaTokenType::NonFungible,
token_display_name,
token_ticker,
0,
&BigUint::zero(),
&BigUint::zero(),
properties,
)
}
/// Produces a contract call to the KDA system SC,
/// which causes it to issue a new semi-fungible KDA token.
pub fn issue_semi_fungible(
self,
token_display_name: &ManagedBuffer<SA>,
token_ticker: &ManagedBuffer<SA>,
num_decimals: u32,
properties: &PropertiesInfo,
) -> TokenIdentifier<SA> {
self.issue(
KdaTokenType::NonFungible,
token_display_name,
token_ticker,
num_decimals,
&BigUint::zero(),
&BigUint::zero(),
properties,
)
}
fn issue(
self,
token_type: KdaTokenType,
token_display_name: &ManagedBuffer<SA>,
token_ticker: &ManagedBuffer<SA>,
num_decimals: u32,
initial_supply: &BigUint<SA>,
max_supply: &BigUint<SA>,
properties: &PropertiesInfo,
) -> TokenIdentifier<SA> {
let asset_type = match token_type {
KdaTokenType::Fungible => AssetType::Fungible,
KdaTokenType::NonFungible => AssetType::NFT,
KdaTokenType::SemiFungible => AssetType::SemiFungible,
_ => panic!("Invalid token type"),
};
let send_wrapper = SendWrapper::<SA>::new();
let result = send_wrapper.kda_create(
asset_type,
token_display_name,
token_ticker,
num_decimals,
&Self::get_sc_address(),
&ManagedBuffer::new(),
initial_supply,
max_supply,
properties,
&RoyaltiesData::default(),
);
result
}
/// Produces a contract call to the KDA system SC,
/// which causes it to mint more fungible KDA tokens.
/// It will fail if the SC is not the owner of the token.
pub fn mint(
self,
token_identifier: &TokenIdentifier<SA>,
amount: &BigUint<SA>,
) -> ManagedVec<SA, ManagedBuffer<SA>> {
let send_wrapper = SendWrapper::<SA>::new();
send_wrapper.kda_mint(token_identifier, 0, amount)
}
/// Produces a contract call to the KDA system SC,
/// which causes it to mint more fungible KDA tokens.
/// It will fail if the SC is not the owner of the token.
pub fn mint_with_address(
self,
to: &ManagedAddress<SA>,
token_identifier: &TokenIdentifier<SA>,
amount: &BigUint<SA>,
) -> ManagedVec<SA, ManagedBuffer<SA>> {
let send_wrapper = SendWrapper::<SA>::new();
send_wrapper.kda_mint_with_address(token_identifier, 0, amount, to, 0)
}
/// Produces a contract call to the KDA system SC,
/// which causes it to burn fungible KDA tokens owned by the SC.
pub fn burn(self, token_identifier: &TokenIdentifier<SA>, amount: &BigUint<SA>) {
let send_wrapper = SendWrapper::<SA>::new();
send_wrapper.kda_burn(&token_identifier, 0, &amount);
}
/// The manager of an KDA token may choose to suspend all transactions of the token,
/// except minting, freezing/unfreezing and wiping.
pub fn pause(self, token_identifier: &TokenIdentifier<SA>) {
let send_wrapper = SendWrapper::<SA>::new();
send_wrapper.kda_pause(token_identifier)
}
/// The reverse operation of `pause`.
pub fn unpause(self, token_identifier: &TokenIdentifier<SA>) {
let send_wrapper = SendWrapper::<SA>::new();
send_wrapper.kda_resume(&token_identifier)
}
/// The manager of an KDA token may freeze the tokens held by a specific account.
/// As a consequence, no tokens may be transferred to or from the frozen account.
/// Freezing and unfreezing the tokens of an account are operations designed to help token managers to comply with regulations.
pub fn freeze(self, token_identifier: &TokenIdentifier<SA>, amount: &BigUint<SA>) -> ManagedBuffer<SA> {
let send_wrapper = SendWrapper::<SA>::new();
send_wrapper.freeze(token_identifier, amount)
}
/// The reverse operation of `freeze`, unfreezing, will allow further transfers to and from the account.
pub fn unfreeze(self, token_identifier: &TokenIdentifier<SA>, bucket_id: &ManagedBuffer<SA>) {
let send_wrapper = SendWrapper::<SA>::new();
send_wrapper.unfreeze(token_identifier, bucket_id)
}
/// The manager of an KDA token may wipe out all the tokens held by a frozen account.
/// This operation is similar to burning the tokens, but the account must have been frozen beforehand,
/// and it must be done by the token manager.
/// Wiping the tokens of an account is an operation designed to help token managers to comply with regulations.
pub fn wipe(
self,
token_identifier: &TokenIdentifier<SA>,
nonce: u64,
amount: &BigUint<SA>,
address: &ManagedAddress<SA>,
) {
let send_wrapper = SendWrapper::<SA>::new();
send_wrapper.kda_wipe(token_identifier, nonce, amount, address)
}
/// This function can be called only if owner of the token is the SC.
/// address will receiver special roles related to the token.
pub fn set_special_roles(
self,
address: &ManagedAddress<SA>,
token_identifier: &TokenIdentifier<SA>,
allow_mint: bool,
alow_set_ito_price: bool,
allow_deposit: bool,
allow_transfer: bool,
) {
let send_wrapper = SendWrapper::<SA>::new();
send_wrapper.kda_add_role(
token_identifier,
address,
allow_mint,
alow_set_ito_price,
allow_deposit,
allow_transfer,
)
}
pub fn transfer_ownership(
self,
token_identifier: &TokenIdentifier<SA>,
new_owner: &ManagedAddress<SA>,
) {
let send_wrapper = SendWrapper::<SA>::new();
send_wrapper.kda_change_owner(token_identifier, new_owner)
}
}