We’ve updated the ICRC Fungible token suite to support all the latest goodies, including Mixins and the Core libraries!
or
mops add icrc-fungible
An ICRC-1 motoko token can now be created with as little motoko code as this:
import ICRC1Mixin "mo:icrc1-mo/ICRC1/mixin";
import ICRC1 "mo:icrc1-mo/ICRC1";
import ClassPlus "mo:class-plus";
import Principal "mo:core/Principal";
shared ({ caller = _owner }) persistent actor class MyToken(
init_args : ?ICRC1.InitArgs
) = this {
transient let canisterId = Principal.fromActor(this);
transient let manager = ClassPlus.ClassPlusInitializationManager<system>(_owner, canisterId, true);
private func get_icrc1_environment() : ICRC1.Environment {
{
advanced = null;
add_ledger_transaction = null; // or ?icrc3().add_record for ICRC-3 integration
var org_icdevs_timer_tool = null;
var org_icdevs_class_plus_manager = ?manager;
};
};
include ICRC1Mixin.mixin({
ICRC1.defaultMixinArgs(manager) with
args = init_args;
pullEnvironment = ?get_icrc1_environment;
canSetFeeCollector = ?(func(caller : Principal) : Bool { Principal.isController(caller) }); // Enable ICRC-107
canSetIndexPrincipal = ?(func(caller : Principal) : Bool { Principal.isController(caller) }); // Enable ICRC-106
});
// The mixin provides:
// icrc1() - access the ICRC1 class instance
// org_icdevs_icrc1_interface - extensible interface for before/after hooks
// All ICRC-1, ICRC-10, ICRC-21, ICRC-106, ICRC-107 endpoints
};
The previous version was hundred of lines (read: much less for caffeine or other LLMs to have to worry about).
The suite also supports a motoko version of the Index canister ( https://github.com/icdevsorg/index.mo mops add icrc-fungible-index) with has a notify function that uses best-effort messaging to safely allow the index to receive push notifications instead of
burning cycles checking for new transactions every 2 seconds.
The token is made up from
The suite passes all DFINITY Tests from https://github.com/dfinity/ICRC-1/tree/main/test as well as the Neutrinomic https://github.com/Neutrinomic/devefi_ledger_tests.
Fork, contribute, send pull requests.