Motoko - ICRC 1,2,3,4,21,106,107,Index-NG, and Rosetta

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 :fire: 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.

This is very cool. Index.Mo is the new lower cost indexer? I will play w this

It is lower cost, depending on how you set it up. On the tokens that I’ve deployed I set up an eight second bounce so that it only notifies the canister every eight seconds, but also only if there are new transactions. If you’re token becomes the paragon of international defi, you may want to check this back down two seconds, and it ultimately might not be much of a savings, but for low throughput tokens, you can save thousands a year(2.5xthousands). The caveat here is that your ledger has to support it..

A girl can dream. :nail_polish: