• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

helix-onchain / filecoin / 4191081979

pending completion
4191081979

Pull #197

github

GitHub
Merge f696a6385 into b20a4687a
Pull Request #197: pin toolchain version to match ref-fvm

19 of 19 new or added lines in 3 files covered. (100.0%)

3600 of 4162 relevant lines covered (86.5%)

12.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

14.06
/frc46_token/src/token/types.rs
1
use fvm_actor_utils::receiver::RecipientData;
2
use fvm_ipld_encoding::tuple::{Deserialize_tuple, Serialize_tuple};
3
use fvm_ipld_encoding::RawBytes;
4
use fvm_shared::address::Address;
5
use fvm_shared::econ::TokenAmount;
6

7
/// A standard fungible token interface allowing for on-chain transactions that implements the
8
/// FRC-0046 standard. This represents the external interface exposed to other on-chain actors
9
///
10
/// Token authors must implement this trait and link the methods to standard dispatch numbers (as
11
/// defined by [FRC-0042](https://github.com/filecoin-project/FIPs/blob/master/FRCs/frc-0042.md)).
12
pub trait FRC46Token {
13
    type TokenError;
14
    /// Returns the name of the token
15
    ///
16
    /// Must not be empty
17
    fn name(&self) -> String;
18

19
    /// Returns the ticker symbol of the token
20
    ///
21
    /// Must not be empty. Should be a short uppercase string
22
    fn symbol(&self) -> String;
23

24
    /// Returns the smallest amount of tokens which is indivisible.
25
    ///
26
    /// All transfers, burns, and mints must be a whole multiple of the granularity. All balances
27
    /// must be a multiple of this granularity (but allowances need not be). Must be at least 1.
28
    /// Must never change.
29
    ///
30
    /// A granularity of 10^18 corresponds to whole units only, with no further decimal precision.
31
    fn granularity(&self) -> GranularityReturn;
32

33
    /// Returns the total amount of the token in existence
34
    ///
35
    /// Must be non-negative. The total supply must equal the balances of all addresses. The total
36
    /// supply should equal the sum of all minted tokens less the sum of all burnt tokens.
37
    fn total_supply(&mut self) -> TotalSupplyReturn;
38

39
    /// Returns the balance of an address
40
    ///
41
    /// Balance is always non-negative. Uninitialised addresses have an implicit zero balance.
42
    fn balance_of(&mut self, params: Address) -> Result<BalanceReturn, Self::TokenError>;
43

44
    /// Returns the allowance approved for an operator on a spender's balance
45
    ///
46
    /// The operator can burn or transfer the allowance amount out of the owner's address.
47
    fn allowance(
48
        &mut self,
49
        params: GetAllowanceParams,
50
    ) -> Result<AllowanceReturn, Self::TokenError>;
51

52
    /// Transfers tokens from the caller to another address
53
    ///
54
    /// Amount must be non-negative (but can be zero). Transferring to the caller's own address must
55
    /// be treated as a normal transfer. Must call the receiver hook on the receiver's address,
56
    /// failing and aborting the transfer if calling the hook fails or aborts.
57
    fn transfer(&mut self, params: TransferParams) -> Result<TransferReturn, Self::TokenError>;
58

59
    /// Transfers tokens from one address to another
60
    ///
61
    /// The caller must have previously approved to control at least the sent amount. If successful,
62
    /// the amount transferred is deducted from the caller's allowance.
63
    fn transfer_from(
64
        &mut self,
65
        params: TransferFromParams,
66
    ) -> Result<TransferFromReturn, Self::TokenError>;
67

68
    /// Atomically increases the approved allowance that a operator can transfer/burn from the
69
    /// caller's balance
70
    ///
71
    /// The increase must be non-negative. Returns the new total allowance approved for that
72
    /// owner-operator pair.
73
    fn increase_allowance(
74
        &mut self,
75
        params: IncreaseAllowanceParams,
76
    ) -> Result<IncreaseAllowanceReturn, Self::TokenError>;
77

78
    /// Atomically decreases the approved balance that a operator can transfer/burn from the caller's
79
    /// balance
80
    ///
81
    /// The decrease must be non-negative. Sets the allowance to zero if the decrease is greater
82
    /// than the currently approved allowance. Returns the new total allowance approved for that
83
    /// owner-operator pair.
84
    fn decrease_allowance(
85
        &mut self,
86
        params: DecreaseAllowanceParams,
87
    ) -> Result<DecreaseAllowanceReturn, Self::TokenError>;
88

89
    /// Sets the allowance a operator has on the owner's account to zero
90
    fn revoke_allowance(
91
        &mut self,
92
        params: RevokeAllowanceParams,
93
    ) -> Result<RevokeAllowanceReturn, Self::TokenError>;
94

95
    /// Burns tokens from the caller's balance, decreasing the total supply
96
    fn burn(&mut self, params: BurnParams) -> Result<BurnReturn, Self::TokenError>;
97

98
    /// Burns tokens from an address's balance
99
    ///
100
    /// The caller must have been previously approved to control at least the burnt amount.
101
    fn burn_from(&mut self, params: BurnFromParams) -> Result<BurnFromReturn, Self::TokenError>;
102
}
103

104
pub type GranularityReturn = u64;
105
pub type TotalSupplyReturn = TokenAmount;
106
pub type BalanceReturn = TokenAmount;
107
pub type AllowanceReturn = TokenAmount;
108
pub type IncreaseAllowanceReturn = TokenAmount;
109
pub type DecreaseAllowanceReturn = TokenAmount;
110
pub type RevokeAllowanceReturn = ();
111

112
/// Return value after a successful mint.
113
/// The mint method is not standardised, so this is merely a useful library-level type,
114
/// and recommendation for token implementations.
115
#[derive(Serialize_tuple, Deserialize_tuple, Clone, Debug)]
×
116
pub struct MintReturn {
117
    /// The new balance of the owner address
118
    pub balance: TokenAmount,
×
119
    /// The new total supply.
120
    pub supply: TokenAmount,
×
121
    /// (Optional) data returned from receiver hook
122
    pub recipient_data: RawBytes,
×
123
}
124

125
/// Intermediate data used by mint_return to construct the return data
126
#[derive(Clone, Debug)]
×
127
pub struct MintIntermediate {
128
    /// Recipient address to use for querying balance
129
    pub recipient: Address,
×
130
    /// (Optional) data returned from receiver hook
131
    pub recipient_data: RawBytes,
×
132
}
133

134
impl RecipientData for MintIntermediate {
135
    fn set_recipient_data(&mut self, data: RawBytes) {
46✔
136
        self.recipient_data = data;
46✔
137
    }
46✔
138
}
139

140
/// Instruction to transfer tokens to another address
141
#[derive(Serialize_tuple, Deserialize_tuple, Clone, Debug)]
×
142
pub struct TransferParams {
143
    pub to: Address,
×
144
    /// A non-negative amount to transfer
145
    pub amount: TokenAmount,
×
146
    /// Arbitrary data to pass on via the receiver hook
147
    pub operator_data: RawBytes,
×
148
}
149

150
/// Return value after a successful transfer
151
#[derive(Serialize_tuple, Deserialize_tuple, Clone, Debug)]
×
152
pub struct TransferReturn {
153
    /// The new balance of the `from` address
154
    pub from_balance: TokenAmount,
×
155
    /// The new balance of the `to` address
156
    pub to_balance: TokenAmount,
×
157
    /// (Optional) data returned from receiver hook
158
    pub recipient_data: RawBytes,
×
159
}
160

161
/// Intermediate data used by transfer_return to construct the return data
162
#[derive(Debug)]
×
163
pub struct TransferIntermediate {
164
    pub from: Address,
×
165
    pub to: Address,
×
166
    /// (Optional) data returned from receiver hook
167
    pub recipient_data: RawBytes,
×
168
}
169

170
impl RecipientData for TransferIntermediate {
171
    fn set_recipient_data(&mut self, data: RawBytes) {
17✔
172
        self.recipient_data = data;
17✔
173
    }
17✔
174
}
175

176
/// Instruction to transfer tokens between two addresses as an operator
177
#[derive(Serialize_tuple, Deserialize_tuple, Clone, Debug)]
×
178
pub struct TransferFromParams {
179
    pub from: Address,
×
180
    pub to: Address,
×
181
    /// A non-negative amount to transfer
182
    pub amount: TokenAmount,
×
183
    /// Arbitrary data to pass on via the receiver hook
184
    pub operator_data: RawBytes,
×
185
}
186

187
/// Return value after a successful delegated transfer
188
#[derive(Serialize_tuple, Deserialize_tuple, Clone, Debug)]
×
189
pub struct TransferFromReturn {
190
    /// The new balance of the `from` address
191
    pub from_balance: TokenAmount,
×
192
    /// The new balance of the `to` address
193
    pub to_balance: TokenAmount,
×
194
    /// The new remaining allowance between `owner` and `operator` (caller)
195
    pub allowance: TokenAmount,
×
196
    /// (Optional) data returned from receiver hook
197
    pub recipient_data: RawBytes,
×
198
}
199

200
/// Intermediate data used by transfer_from_return to construct the return data
201
#[derive(Clone, Debug)]
×
202
pub struct TransferFromIntermediate {
203
    pub operator: Address,
×
204
    pub from: Address,
×
205
    pub to: Address,
×
206
    /// (Optional) data returned from receiver hook
207
    pub recipient_data: RawBytes,
×
208
}
209

210
impl RecipientData for TransferFromIntermediate {
211
    fn set_recipient_data(&mut self, data: RawBytes) {
8✔
212
        self.recipient_data = data;
8✔
213
    }
8✔
214
}
215

216
/// Instruction to increase an allowance between two addresses
217
#[derive(Serialize_tuple, Deserialize_tuple, Clone, Debug)]
×
218
pub struct IncreaseAllowanceParams {
219
    pub operator: Address,
×
220
    /// A non-negative amount to increase the allowance by
221
    pub increase: TokenAmount,
×
222
}
223

224
/// Instruction to decrease an allowance between two addresses
225
#[derive(Serialize_tuple, Deserialize_tuple, Clone, Debug)]
×
226
pub struct DecreaseAllowanceParams {
227
    pub operator: Address,
×
228
    /// A non-negative amount to decrease the allowance by
229
    pub decrease: TokenAmount,
×
230
}
231

232
/// Instruction to revoke (set to 0) an allowance
233
#[derive(Serialize_tuple, Deserialize_tuple, Clone, Debug)]
×
234
pub struct RevokeAllowanceParams {
235
    pub operator: Address,
×
236
}
237

238
/// Params to get allowance between to addresses
239
#[derive(Serialize_tuple, Deserialize_tuple, Clone, Debug)]
×
240
pub struct GetAllowanceParams {
241
    pub owner: Address,
×
242
    pub operator: Address,
×
243
}
244

245
/// Instruction to burn an amount of tokens
246
#[derive(Serialize_tuple, Deserialize_tuple, Clone, Debug)]
×
247
pub struct BurnParams {
248
    /// A non-negative amount to burn
249
    pub amount: TokenAmount,
×
250
}
251

252
/// The updated value after burning
253
#[derive(Serialize_tuple, Deserialize_tuple, Clone, Debug)]
×
254
pub struct BurnReturn {
255
    /// New balance in the account after the successful burn
256
    pub balance: TokenAmount,
×
257
}
258

259
/// Instruction to burn an amount of tokens from another address
260
#[derive(Serialize_tuple, Deserialize_tuple, Clone, Debug)]
×
261
pub struct BurnFromParams {
262
    pub owner: Address,
×
263
    /// A non-negative amount to burn
264
    pub amount: TokenAmount,
×
265
}
266

267
/// The updated value after a delegated burn
268
#[derive(Serialize_tuple, Deserialize_tuple, Clone, Debug)]
×
269
pub struct BurnFromReturn {
270
    /// New balance in the account after the successful burn
271
    pub balance: TokenAmount,
×
272
    /// New remaining allowance between the owner and operator (caller)
273
    pub allowance: TokenAmount,
×
274
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc