-
Notifications
You must be signed in to change notification settings - Fork 12
/
traits.rs
176 lines (164 loc) · 5.83 KB
/
traits.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
use ink::{
prelude::{string::String, vec::Vec},
primitives::AccountId,
};
use crate::errors::PSP22Error;
#[ink::trait_definition]
pub trait PSP22 {
/// Returns the total token supply.
#[ink(message)]
fn total_supply(&self) -> u128;
/// Returns the account balance for the specified `owner`.
///
/// Returns `0` if the account is non-existent.
#[ink(message)]
fn balance_of(&self, owner: AccountId) -> u128;
/// Returns the amount which `spender` is still allowed to withdraw from `owner`.
///
/// Returns `0` if no allowance has been set.
#[ink(message)]
fn allowance(&self, owner: AccountId, spender: AccountId) -> u128;
/// Transfers `value` amount of tokens from the caller's account to account `to`
/// with additional `data` in unspecified format.
///
/// # Events
///
/// On success a `Transfer` event is emitted.
///
/// No-op if the caller and `to` is the same address or `value` is zero, returns success
/// and no events are emitted.
///
/// # Errors
///
/// Reverts with `InsufficientBalance` if the `value` exceeds the caller's balance.
#[ink(message)]
fn transfer(&mut self, to: AccountId, value: u128, data: Vec<u8>) -> Result<(), PSP22Error>;
/// Transfers `value` tokens on the behalf of `from` to the account `to`
/// with additional `data` in unspecified format.
///
/// If `from` and the caller are different addresses, the caller must be allowed
/// by `from` to spend at least `value` tokens.
///
/// # Events
///
/// On success a `Transfer` event is emitted.
///
/// No-op if `from` and `to` is the same address or `value` is zero, returns success
/// and no events are emitted.
///
/// If `from` and the caller are different addresses, a successful transfer results
/// in decreased allowance by `from` to the caller and an `Approval` event with
/// the new allowance amount is emitted.
///
/// # Errors
///
/// Reverts with `InsufficientBalance` if the `value` exceeds the balance of the account `from`.
///
/// Reverts with `InsufficientAllowance` if `from` and the caller are different addresses and
/// the `value` exceeds the allowance granted by `from` to the caller.
///
/// If conditions for both `InsufficientBalance` and `InsufficientAllowance` errors are met,
/// reverts with `InsufficientAllowance`.
#[ink(message)]
fn transfer_from(
&mut self,
from: AccountId,
to: AccountId,
value: u128,
data: Vec<u8>,
) -> Result<(), PSP22Error>;
/// Allows `spender` to withdraw from the caller's account multiple times, up to
/// the total amount of `value`.
///
/// Successive calls of this method overwrite previous values.
///
/// # Events
///
/// An `Approval` event is emitted.
///
/// No-op if the caller and `spender` is the same address, returns success and no events are emitted.
#[ink(message)]
fn approve(&mut self, spender: AccountId, value: u128) -> Result<(), PSP22Error>;
/// Increases by `delta-value` the allowance granted to `spender` by the caller.
///
/// # Events
///
/// An `Approval` event with the new allowance amount is emitted.
///
/// No-op if the caller and `spender` is the same address or `delta-value` is zero, returns success
/// and no events are emitted.
#[ink(message)]
fn increase_allowance(
&mut self,
spender: AccountId,
delta_value: u128,
) -> Result<(), PSP22Error>;
/// Decreases by `delta-value` the allowance granted to `spender` by the caller.
///
/// # Events
///
/// An `Approval` event with the new allowance amount is emitted.
///
/// No-op if the caller and `spender` is the same address or `delta-value` is zero, returns success
/// and no events are emitted.
///
/// # Errors
///
/// Reverts with `InsufficientAllowance` if `spender` and the caller are different addresses and
/// the `delta-value` exceeds the allowance granted by the caller to `spender`.
#[ink(message)]
fn decrease_allowance(
&mut self,
spender: AccountId,
delta_value: u128,
) -> Result<(), PSP22Error>;
}
#[ink::trait_definition]
pub trait PSP22Metadata {
/// Returns the token name.
#[ink(message)]
fn token_name(&self) -> Option<String>;
/// Returns the token symbol.
#[ink(message)]
fn token_symbol(&self) -> Option<String>;
/// Returns the token decimals.
#[ink(message)]
fn token_decimals(&self) -> u8;
}
#[ink::trait_definition]
pub trait PSP22Burnable {
/// Burns `value` tokens from the senders account.
///
/// The selector for this message is `0x7a9da510` (first 4 bytes of `blake2b_256("PSP22Burnable::burn")`).
///
/// # Events
///
/// On success a `Transfer` event is emitted with `None` recipient.
///
/// No-op if `value` is zero, returns success and no events are emitted.
///
/// # Errors
///
/// Reverts with `InsufficientBalance` if the `value` exceeds the caller's balance.
#[ink(message)]
fn burn(&mut self, value: u128) -> Result<(), PSP22Error>;
}
#[ink::trait_definition]
pub trait PSP22Mintable {
/// Mints `value` tokens to the senders account.
///
/// The selector for this message is `0xfc3c75d4` (first 4 bytes of `blake2b_256("PSP22Mintable::mint")`).
///
/// # Events
///
/// On success a `Transfer` event is emitted with `None` sender.
///
/// No-op if `value` is zero, returns success and no events are emitted.
///
/// # Errors
///
/// Reverts with `Custom (max supply exceeded)` if the total supply increased by
/// `value` exceeds maximal value of `u128` type.
#[ink(message)]
fn mint(&mut self, value: u128) -> Result<(), PSP22Error>;
}