├── .github └── workflows │ └── makefile.yml ├── .gitignore ├── .gitmodules ├── LICENSE ├── dfx.json ├── docs ├── ICRC1 │ ├── Account.html │ ├── Account.md │ ├── ArchiveApi.html │ ├── ArchiveApi.md │ ├── Canisters │ │ ├── Token.html │ │ └── Token.md │ ├── Transfer.html │ ├── Transfer.md │ ├── Types.html │ ├── Types.md │ ├── Utils.html │ ├── Utils.md │ ├── lib.html │ └── lib.md ├── index.html ├── index.md └── styles.css ├── example ├── .gitignore ├── dfx.json └── icrc1 │ └── main.mo ├── icrc1-default-args.txt ├── makefile ├── mops.toml ├── package-set.dhall ├── readme.md ├── src └── ICRC1 │ ├── Account.mo │ ├── Canisters │ ├── Archive.mo │ └── Token.mo │ ├── Transfer.mo │ ├── Types.mo │ ├── Utils.mo │ └── lib.mo ├── tests ├── ActorTest.mo ├── ICRC1 │ ├── Account.Test.mo │ ├── Archive.ActorTest.mo │ └── ICRC1.ActorTest.mo ├── test_template.md └── utils │ └── ActorSpec.mo └── vessel.dhall /.github/workflows/makefile.yml: -------------------------------------------------------------------------------- 1 | name: Makefile CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - dev 8 | pull_request_target: 9 | branches: 10 | - "*" 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | 16 | name: Build and test 17 | steps: 18 | - uses: actions/checkout@v3 19 | - uses: actions/setup-node@v3 20 | with: 21 | node-version: 18 22 | - uses: aviate-labs/setup-dfx@v0.2.3 23 | with: 24 | dfx-version: 0.15.1 25 | 26 | - name: Cache Node modules 27 | uses: actions/cache@v2 28 | with: 29 | path: ~/.npm 30 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} 31 | restore-keys: | 32 | ${{ runner.os }}-node- 33 | 34 | - name: Install moc version manager 35 | run: | 36 | npm --yes -g i mocv 37 | mocv use 0.10.2 38 | export DFX_MOC_PATH=$(mocv bin current)/moc 39 | 40 | - name: install mops 41 | run: | 42 | npm --yes -g i ic-mops 43 | mops i 44 | 45 | # - name: Detect warnings 46 | # run: make no-warn 47 | 48 | - name: Run Tests 49 | run: | 50 | make test 51 | make actor-test 52 | 53 | icrc1-ref-test: 54 | runs-on: ubuntu-latest 55 | 56 | name: ICRC-1 reference test 57 | steps: 58 | - uses: actions/checkout@v3 59 | with: 60 | submodules: recursive 61 | - uses: actions/setup-node@v3 62 | with: 63 | node-version: 18 64 | - uses: aviate-labs/setup-dfx@v0.2.3 65 | with: 66 | dfx-version: 0.15.1 67 | 68 | - name: Install moc version manager 69 | run: | 70 | npm --yes -g i mocv 71 | mocv use 0.10.2 72 | export DFX_MOC_PATH=$(mocv bin current)/moc 73 | 74 | - name: Install stable toolchain 75 | uses: actions-rs/toolchain@v1 76 | with: 77 | profile: minimal 78 | toolchain: stable 79 | override: true 80 | 81 | - name: install mops 82 | run: | 83 | npm --yes -g i ic-mops 84 | mops i 85 | 86 | - name: Run reference tests 87 | run: | 88 | echo "${{ secrets.IDENTITY_SSH }}" > ./identity.pem 89 | dfx identity import icrc-ref-test ./identity.pem --storage-mode plaintext 90 | dfx identity use icrc-ref-test 91 | dfx identity whoami 92 | make ref-test 93 | 94 | 95 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Various IDEs and Editors 2 | .vscode/ 3 | .idea/ 4 | **/*~ 5 | 6 | # Mac OSX temporary files 7 | .DS_Store 8 | **/.DS_Store 9 | 10 | # dfx temporary files 11 | .dfx/ 12 | .vessel/ 13 | .mops/ 14 | 15 | # frontend code 16 | node_modules/ 17 | dist/ 18 | 19 | Cargo.lock -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Dfnity-ICRC1-Reference"] 2 | path = Dfnity-ICRC1-Reference 3 | url = https://github.com/dfinity/ICRC-1 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Tomi Jaga 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /dfx.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "canisters": { 4 | "icrc1": { 5 | "type": "motoko", 6 | "main": "src/ICRC1/Canisters/Token.mo" 7 | }, 8 | "test": { 9 | "type": "motoko", 10 | "main": "tests/ActorTest.mo", 11 | "args": "-v --compacting-gc" 12 | } 13 | }, 14 | "defaults": { 15 | "build": { 16 | "packtool": "mops sources", 17 | "args": "" 18 | } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /docs/ICRC1/Account.html: -------------------------------------------------------------------------------- 1 | 2 |
public func validate_subaccount(subaccount : ?T.Subaccount) : Bool
Checks if a subaccount is valid
3 |public func validate(account : T.Account) : Bool
Checks if an account is valid
4 |public func encode() : T.EncodedAccount
Implementation of ICRC1's Textual representation of accounts Encoding Standard
5 |public func decode(encoded : T.EncodedAccount) : ?T.Account
Implementation of ICRC1's Textual representation of accounts Decoding Standard
6 |public func fromText(encoded : Text) : ?T.Account
Converts an ICRC-1 Account from its Textual representation to the Account
type
public func toText(account : T.Account) : Text
Converts an ICRC-1 Account
to its Textual representation
public func create_canister() : async T.ArchiveInterface
creates a new archive canister
3 |public func total_txs(archives : T.StableBuffer<T.ArchiveData>) : Nat
Get the total number of archived transactions
4 |public func append_transactions(token : T.TokenData) : async ()
Moves the transactions from the ICRC1 canister to the archive canister 5 | and returns a boolean that indicates the success of the data transfer
6 |public func icrc1_name() : async Text
Functions for the ICRC1 token standard
3 |public func icrc1_symbol() : async Text
public func icrc1_decimals() : async Nat8
public func icrc1_fee() : async ICRC1.Balance
public func icrc1_metadata() : async [ICRC1.MetaDatum]
public func icrc1_total_supply() : async ICRC1.Balance
public func icrc1_minting_account() : async ?ICRC1.Account
public func icrc1_balance_of(args : ICRC1.Account) : async ICRC1.Balance
public func icrc1_supported_standards() : async [ICRC1.SupportedStandard]
public func icrc1_transfer(args : ICRC1.TransferArgs) : async Result.Result<ICRC1.Balance, ICRC1.TransferError>
public func mint(args : ICRC1.Mint) : async Result.Result<ICRC1.Balance, ICRC1.TransferError>
public func burn(args : ICRC1.BurnArgs) : async Result.Result<ICRC1.Balance, ICRC1.TransferError>
public func get_transaction(token_id : Nat) : async ?ICRC1.Transaction
public func get_transactions(req : ICRC1.GetTransactionsRequest) : async ()
public func validate_memo(memo : ?T.Memo) : Bool
Checks if a transaction memo is valid
3 |public func is_too_old(token : T.TokenData, created_at_time : Nat64) : Bool
Checks if the created_at_time
of a transfer request is before the accepted time range
public func is_in_future(token : T.TokenData, created_at_time : Nat64) : Bool
Checks if the created_at_time
of a transfer request has not been reached yet relative to the canister's time.
public func deduplicate(token : T.TokenData, tx_req : T.TransactionRequest) : Result.Result<(), Nat>
Checks if there is a duplicate transaction that matches the transfer request in the main canister.
6 |If a duplicate is found, the function returns an error (#err
) with the duplicate transaction's index.
public func validate_fee(token : T.TokenData, opt_fee : ?T.Balance) : Bool
Checks if a transfer fee is valid
8 |public func validate_request(token : T.TokenData, tx_req : T.TransactionRequest) : Result.Result<(), T.TransferError>
Checks if a transfer request is valid
9 |Arguments for a transfer operation
3 |Internal representation of a transaction request
4 |Interface for the ICRC token canister
5 |The Interface for the Archive canister
6 |Initial arguments for the setting up the icrc1 token canister
7 |InitArgs with optional fields for initializing a token canister
8 |Additional settings for the InitArgs type during initialization of an icrc1 token canister
9 |The details of the archive canister
10 |The state of the token canister
11 |The type to request a range of transactions from the ledger canister
12 |Functions supported by the rosetta
13 |Interface of the ICRC token and Rosetta canister
14 |public func init_metadata(args : T.InitArgs) : StableBuffer.StableBuffer<T.MetaDatum>
public let default_standard : T.SupportedStandard
public func init_standards() : StableBuffer.StableBuffer<T.SupportedStandard>
public func default_subaccount() : T.Subaccount
public func hash(n : Nat) : Hash.Hash
public func create_transfer_req(
args : T.TransferArgs,
owner : Principal,
tx_kind : T.TxKind
) : T.TransactionRequest
public func kind_to_text(kind : T.TxKind) : Text
public func req_to_tx(tx_req : T.TransactionRequest, index : Nat) : T.Transaction
public func div_ceil(n : Nat, d : Nat) : Nat
public func get_balance(accounts : T.AccountBalances, encoded_account : T.EncodedAccount) : T.Balance
Retrieves the balance of an account
3 |public func update_balance(
accounts : T.AccountBalances,
encoded_account : T.EncodedAccount,
update : (T.Balance) -> T.Balance
)
Updates the balance of an account
4 |public func transfer_balance(token : T.TokenData, tx_req : T.TransactionRequest)
public func mint_balance(
token : T.TokenData,
encoded_account : T.EncodedAccount,
amount : T.Balance
)
public func burn_balance(
token : T.TokenData,
encoded_account : T.EncodedAccount,
amount : T.Balance
)
public let SB :
public let MAX_TRANSACTIONS_IN_LEDGER :
public let MAX_TRANSACTION_BYTES : Nat64
public let MAX_TRANSACTIONS_PER_REQUEST :
public func init(args : T.InitArgs) : T.TokenData
Initialize a new ICRC-1 token
3 |public func name(token : T.TokenData) : Text
Retrieve the name of the token
4 |public func symbol(token : T.TokenData) : Text
Retrieve the symbol of the token
5 |public func decimals() : Nat8
Retrieve the number of decimals specified for the token
6 |public func fee(token : T.TokenData) : T.Balance
Retrieve the fee for each transfer
7 |public func set_fee(token : T.TokenData, fee : Nat)
Set the fee for each transfer
8 |public func metadata(token : T.TokenData) : [T.MetaDatum]
Retrieve all the metadata of the token
9 |public func total_supply(token : T.TokenData) : T.Balance
Returns the total supply of circulating tokens
10 |public func minted_supply(token : T.TokenData) : T.Balance
Returns the total supply of minted tokens
11 |public func burned_supply(token : T.TokenData) : T.Balance
Returns the total supply of burned tokens
12 |public func max_supply(token : T.TokenData) : T.Balance
Returns the maximum supply of tokens
13 |public func minting_account(token : T.TokenData) : T.Account
Returns the account with the permission to mint tokens
14 |Note: The minting account can only participate in minting 15 | and burning transactions, so any tokens sent to it will be 16 | considered burned.
17 |public func supported_standards(token : T.TokenData) : [T.SupportedStandard]
Returns an array of standards supported by this token
19 |public func balance_from_float(token : T.TokenData, float : Float) : T.Balance
Formats a float to a nat balance and applies the correct number of decimal places
20 |public func transfer(
token : T.TokenData,
args : T.TransferArgs,
caller : Principal
) : async T.TransferResult
Transfers tokens from one account to another account (minting and burning included)
21 |public func mint(
token : T.TokenData,
args : T.Mint,
caller : Principal
) : async T.TransferResult
Helper function to mint tokens with minimum args
22 |public func burn(
token : T.TokenData,
args : T.BurnArgs,
caller : Principal
) : async T.TransferResult
Helper function to burn tokens with minimum args
23 |public func total_transactions(token : T.TokenData) : Nat
Returns the total number of transactions that have been processed by the given token.
24 |public func get_transaction(token : T.TokenData, tx_index : T.TxIndex) : async ?T.Transaction
Retrieves the transaction specified by the given tx_index
public func get_transactions(token : T.TokenData, req : T.GetTransactionsRequest) : T.GetTransactionsResponse
Retrieves the transactions specified by the given range
26 |