forked from NatLabs/icrc1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.mo
89 lines (70 loc) · 2.76 KB
/
main.mo
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
import Iter "mo:base/Iter";
import Option "mo:base/Option";
import Time "mo:base/Time";
import ExperimentalCycles "mo:base/ExperimentalCycles";
import ICRC1 "../../src/ICRC1"; // replace with "mo:icrc1/ICRC1"
import Array "mo:base/Array";
shared ({ caller = _owner }) actor class Token(
token_args : ICRC1.TokenInitArgs,
) : async ICRC1.FullInterface {
stable let token = ICRC1.init({
token_args with minting_account = Option.get(
token_args.minting_account,
{
owner = _owner;
subaccount = null;
},
);
});
/// Functions for the ICRC1 token standard
public shared query func icrc1_name() : async Text {
ICRC1.name(token);
};
public shared query func icrc1_symbol() : async Text {
ICRC1.symbol(token);
};
public shared query func icrc1_decimals() : async Nat8 {
ICRC1.decimals(token);
};
public shared query func icrc1_fee() : async ICRC1.Balance {
ICRC1.fee(token);
};
public shared query func icrc1_metadata() : async [ICRC1.MetaDatum] {
ICRC1.metadata(token);
};
public shared query func icrc1_total_supply() : async ICRC1.Balance {
ICRC1.total_supply(token);
};
public shared query func icrc1_minting_account() : async ?ICRC1.Account {
?ICRC1.minting_account(token);
};
public shared query func icrc1_balance_of(args : ICRC1.Account) : async ICRC1.Balance {
ICRC1.balance_of(token, args);
};
public shared query func icrc1_supported_standards() : async [ICRC1.SupportedStandard] {
ICRC1.supported_standards(token);
};
public shared ({ caller }) func icrc1_transfer(args : ICRC1.TransferArgs) : async ICRC1.TransferResult {
await ICRC1.transfer(token, args, caller);
};
public shared ({ caller }) func mint(args : ICRC1.Mint) : async ICRC1.TransferResult {
await ICRC1.mint(token, args, caller);
};
public shared ({ caller }) func burn(args : ICRC1.BurnArgs) : async ICRC1.TransferResult {
await ICRC1.burn(token, args, caller);
};
// Functions from the rosetta icrc1 ledger
public shared query func get_transactions(req : ICRC1.GetTransactionsRequest) : async ICRC1.GetTransactionsResponse {
ICRC1.get_transactions(token, req);
};
// Additional functions not included in the ICRC1 standard
public shared func get_transaction(i : ICRC1.TxIndex) : async ?ICRC1.Transaction {
await ICRC1.get_transaction(token, i);
};
// Deposit cycles into this archive canister.
public shared func deposit_cycles() : async () {
let amount = ExperimentalCycles.available();
let accepted = ExperimentalCycles.accept(amount);
assert (accepted == amount);
};
};