-
Notifications
You must be signed in to change notification settings - Fork 1
/
icrc1_ledger.did
453 lines (394 loc) · 13.5 KB
/
icrc1_ledger.did
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
type BlockIndex = nat;
type Subaccount = blob;
// Number of nanoseconds since the UNIX epoch in UTC timezone.
type Timestamp = nat64;
// Number of nanoseconds between two [Timestamp]s.
type Duration = nat64;
type Tokens = nat;
type TxIndex = nat;
type Allowance = record { allowance : nat; expires_at : opt Timestamp };
type AllowanceArgs = record { account : Account; spender : Account };
type Approve = record {
fee : opt nat;
from : Account;
memo : opt blob;
created_at_time : opt Timestamp;
amount : nat;
expected_allowance : opt nat;
expires_at : opt Timestamp;
spender : Account;
};
type ApproveArgs = record {
fee : opt nat;
memo : opt blob;
from_subaccount : opt blob;
created_at_time : opt Timestamp;
amount : nat;
expected_allowance : opt nat;
expires_at : opt Timestamp;
spender : Account;
};
type ApproveError = variant {
GenericError : record { message : text; error_code : nat };
TemporarilyUnavailable;
Duplicate : record { duplicate_of : BlockIndex };
BadFee : record { expected_fee : nat };
AllowanceChanged : record { current_allowance : nat };
CreatedInFuture : record { ledger_time : Timestamp };
TooOld;
Expired : record { ledger_time : Timestamp };
InsufficientFunds : record { balance : nat };
};
type ApproveResult = variant { Ok : BlockIndex; Err : ApproveError };
type HttpRequest = record {
url : text;
method : text;
body : blob;
headers : vec record { text; text };
};
type HttpResponse = record {
body : blob;
headers : vec record { text; text };
status_code : nat16;
};
type Account = record {
owner : principal;
subaccount : opt Subaccount;
};
type TransferArg = record {
from_subaccount : opt Subaccount;
to : Account;
amount : Tokens;
fee : opt Tokens;
memo : opt blob;
created_at_time: opt Timestamp;
};
type TransferError = variant {
BadFee : record { expected_fee : Tokens };
BadBurn : record { min_burn_amount : Tokens };
InsufficientFunds : record { balance : Tokens };
TooOld;
CreatedInFuture : record { ledger_time : Timestamp };
TemporarilyUnavailable;
Duplicate : record { duplicate_of : BlockIndex };
GenericError : record { error_code : nat; message : text };
};
type TransferResult = variant {
Ok : BlockIndex;
Err : TransferError;
};
// The value returned from the [icrc1_metadata] endpoint.
type MetadataValue = variant {
Nat : nat;
Int : int;
Text : text;
Blob : blob;
};
type FeatureFlags = record {
icrc2 : bool;
};
// The initialization parameters of the Ledger
type InitArgs = record {
minting_account : Account;
fee_collector_account : opt Account;
transfer_fee : nat;
decimals : opt nat8;
max_memo_length : opt nat16;
token_symbol : text;
token_name : text;
metadata : vec record { text; MetadataValue };
initial_balances : vec record { Account; nat };
feature_flags : opt FeatureFlags;
maximum_number_of_accounts : opt nat64;
accounts_overflow_trim_quantity : opt nat64;
archive_options : record {
num_blocks_to_archive : nat64;
max_transactions_per_response : opt nat64;
trigger_threshold : nat64;
max_message_size_bytes : opt nat64;
cycles_for_archive_creation : opt nat64;
node_max_memory_size_bytes : opt nat64;
controller_id : principal;
more_controller_ids : opt vec principal;
};
};
type ChangeFeeCollector = variant {
Unset; SetTo: Account;
};
type ChangeArchiveOptions = record {
num_blocks_to_archive : opt nat64;
max_transactions_per_response : opt nat64;
trigger_threshold : opt nat64;
max_message_size_bytes : opt nat64;
cycles_for_archive_creation : opt nat64;
node_max_memory_size_bytes : opt nat64;
controller_id : opt principal;
more_controller_ids : opt vec principal;
};
type UpgradeArgs = record {
metadata : opt vec record { text; MetadataValue };
token_symbol : opt text;
token_name : opt text;
transfer_fee : opt nat;
change_fee_collector : opt ChangeFeeCollector;
max_memo_length : opt nat16;
feature_flags : opt FeatureFlags;
maximum_number_of_accounts: opt nat64;
accounts_overflow_trim_quantity: opt nat64;
change_archive_options : opt ChangeArchiveOptions;
};
type LedgerArg = variant {
Init: InitArgs;
Upgrade: opt UpgradeArgs;
};
type GetTransactionsRequest = record {
// The index of the first tx to fetch.
start : TxIndex;
// The number of transactions to fetch.
length : nat;
};
type GetTransactionsResponse = record {
// The total number of transactions in the log.
log_length : nat;
// List of transaction that were available in the ledger when it processed the call.
//
// The transactions form a contiguous range, with the first transaction having index
// [first_index] (see below), and the last transaction having index
// [first_index] + len(transactions) - 1.
//
// The transaction range can be an arbitrary sub-range of the originally requested range.
transactions : vec Transaction;
// The index of the first transaction in [transactions].
// If the transaction vector is empty, the exact value of this field is not specified.
first_index : TxIndex;
// Encoding of instructions for fetching archived transactions whose indices fall into the
// requested range.
//
// For each entry `e` in [archived_transactions], `[e.from, e.from + len)` is a sub-range
// of the originally requested transaction range.
archived_transactions : vec record {
// The index of the first archived transaction you can fetch using the [callback].
start : TxIndex;
// The number of transactions you can fetch using the callback.
length : nat;
// The function you should call to fetch the archived transactions.
// The range of the transaction accessible using this function is given by [from]
// and [len] fields above.
callback : QueryArchiveFn;
};
};
// A prefix of the transaction range specified in the [GetTransactionsRequest] request.
type TransactionRange = record {
// A prefix of the requested transaction range.
// The index of the first transaction is equal to [GetTransactionsRequest.from].
//
// Note that the number of transactions might be less than the requested
// [GetTransactionsRequest.length] for various reasons, for example:
//
// 1. The query might have hit the replica with an outdated state
// that doesn't have the whole range yet.
// 2. The requested range is too large to fit into a single reply.
//
// NOTE: the list of transactions can be empty if:
//
// 1. [GetTransactionsRequest.length] was zero.
// 2. [GetTransactionsRequest.from] was larger than the last transaction known to
// the canister.
transactions : vec Transaction;
};
// A function for fetching archived transaction.
type QueryArchiveFn = func (GetTransactionsRequest) -> (TransactionRange) query;
type Transaction = record {
burn : opt Burn;
kind : text;
mint : opt Mint;
approve : opt Approve;
timestamp : Timestamp;
transfer : opt Transfer;
};
type Burn = record {
from : Account;
memo : opt blob;
created_at_time : opt Timestamp;
amount : nat;
spender : opt Account;
};
type Mint = record {
to : Account;
memo : opt blob;
created_at_time : opt Timestamp;
amount : nat;
};
type Transfer = record {
to : Account;
fee : opt nat;
from : Account;
memo : opt blob;
created_at_time : opt Timestamp;
amount : nat;
spender : opt Account;
};
type Value = variant {
Blob : blob;
Text : text;
Nat : nat;
Nat64: nat64;
Int : int;
Array : vec Value;
Map : Map;
};
type Map = vec record { text; Value };
type Block = Value;
type GetBlocksArgs = record {
// The index of the first block to fetch.
start : BlockIndex;
// Max number of blocks to fetch.
length : nat;
};
// A prefix of the block range specified in the [GetBlocksArgs] request.
type BlockRange = record {
// A prefix of the requested block range.
// The index of the first block is equal to [GetBlocksArgs.start].
//
// Note that the number of blocks might be less than the requested
// [GetBlocksArgs.length] for various reasons, for example:
//
// 1. The query might have hit the replica with an outdated state
// that doesn't have the whole range yet.
// 2. The requested range is too large to fit into a single reply.
//
// NOTE: the list of blocks can be empty if:
//
// 1. [GetBlocksArgs.length] was zero.
// 2. [GetBlocksArgs.start] was larger than the last block known to
// the canister.
blocks : vec Block;
};
// A function for fetching archived blocks.
type QueryBlockArchiveFn = func (GetBlocksArgs) -> (BlockRange) query;
// The result of a "get_blocks" call.
type GetBlocksResponse = record {
// The index of the first block in "blocks".
// If the blocks vector is empty, the exact value of this field is not specified.
first_index : BlockIndex;
// The total number of blocks in the chain.
// If the chain length is positive, the index of the last block is `chain_len - 1`.
chain_length : nat64;
// System certificate for the hash of the latest block in the chain.
// Only present if `get_blocks` is called in a non-replicated query context.
certificate : opt blob;
// List of blocks that were available in the ledger when it processed the call.
//
// The blocks form a contiguous range, with the first block having index
// [first_block_index] (see below), and the last block having index
// [first_block_index] + len(blocks) - 1.
//
// The block range can be an arbitrary sub-range of the originally requested range.
blocks : vec Block;
// Encoding of instructions for fetching archived blocks.
archived_blocks : vec record {
// The index of the first archived block.
start : BlockIndex;
// The number of blocks that can be fetched.
length : nat;
// Callback to fetch the archived blocks.
callback : QueryBlockArchiveFn;
};
};
// Certificate for the block at `block_index`.
type DataCertificate = record {
certificate : opt blob;
hash_tree : blob;
};
type StandardRecord = record { url : text; name : text };
type TransferFromArgs = record {
spender_subaccount : opt Subaccount;
from : Account;
to : Account;
amount : Tokens;
fee : opt Tokens;
memo : opt blob;
created_at_time: opt Timestamp;
};
type TransferFromResult = variant {
Ok : BlockIndex;
Err : TransferFromError;
};
type TransferFromError = variant {
BadFee : record { expected_fee : Tokens };
BadBurn : record { min_burn_amount : Tokens };
InsufficientFunds : record { balance : Tokens };
InsufficientAllowance : record { allowance : Tokens };
TooOld;
CreatedInFuture : record { ledger_time : Timestamp };
Duplicate : record { duplicate_of : BlockIndex };
TemporarilyUnavailable;
GenericError : record { error_code : nat; message : text };
};
type ArchiveInfo = record {
canister_id: principal;
block_range_start: BlockIndex;
block_range_end: BlockIndex;
};
type ICRC3Value = variant {
Blob : blob;
Text : text;
Nat : nat;
Int : int;
Array : vec ICRC3Value;
Map : vec record { text; ICRC3Value };
};
type GetArchivesArgs = record {
// The last archive seen by the client.
// The Ledger will return archives coming
// after this one if set, otherwise it
// will return the first archives.
from : opt principal;
};
type GetArchivesResult = vec record {
// The id of the archive
canister_id : principal;
// The first block in the archive
start : nat;
// The last block in the archive
end : nat;
};
type GetBlocksResult = record {
// Total number of blocks in the
// block log
log_length : nat;
blocks : vec record { id : nat; block: ICRC3Value };
archived_blocks : vec record {
args : vec GetBlocksArgs;
callback : func (vec GetBlocksArgs) -> (GetBlocksResult) query;
};
};
type ICRC3DataCertificate = record {
// See https://internetcomputer.org/docs/current/references/ic-interface-spec#certification
certificate : blob;
// CBOR encoded hash_tree
hash_tree : blob;
};
service : (ledger_arg : LedgerArg) -> {
archives : () -> (vec ArchiveInfo) query;
get_transactions : (GetTransactionsRequest) -> (GetTransactionsResponse) query;
get_blocks : (GetBlocksArgs) -> (GetBlocksResponse) query;
get_data_certificate : () -> (DataCertificate) query;
icrc1_name : () -> (text) query;
icrc1_symbol : () -> (text) query;
icrc1_decimals : () -> (nat8) query;
icrc1_metadata : () -> (vec record { text; MetadataValue }) query;
icrc1_total_supply : () -> (Tokens) query;
icrc1_fee : () -> (Tokens) query;
icrc1_minting_account : () -> (opt Account) query;
icrc1_balance_of : (Account) -> (Tokens) query;
icrc1_transfer : (TransferArg) -> (TransferResult);
icrc1_supported_standards : () -> (vec StandardRecord) query;
icrc2_approve : (ApproveArgs) -> (ApproveResult);
icrc2_allowance : (AllowanceArgs) -> (Allowance) query;
icrc2_transfer_from : (TransferFromArgs) -> (TransferFromResult);
icrc3_get_archives : (GetArchivesArgs) -> (GetArchivesResult) query;
icrc3_get_tip_certificate : () -> (opt ICRC3DataCertificate) query;
icrc3_get_blocks : (vec GetBlocksArgs) -> (GetBlocksResult) query;
icrc3_supported_block_types : () -> (vec record { block_type : text; url : text }) query;
}