Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ICRC2 project #120

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions I2-code/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Tomi Jaga

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 21 additions & 0 deletions I2-code/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": 1,
"canisters": {
"icrc1": {
"type": "motoko",
"main": "src/ICRC1/Canisters/Token.mo"
},
"test": {
"type": "motoko",
"main": "tests/ActorTest.mo",
"args": "-v --compacting-gc"
}
},
"defaults": {
"build": {
"packtool": "mops sources",
"args": ""
}
}

}
8 changes: 8 additions & 0 deletions I2-code/docs/ICRC1/Account.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html><head title="Doc"><meta charset="UTF-8"/><link href="../styles.css" rel="stylesheet"/></head><body><nav class="sidebar"><h3>Modules</h3><ul><li><li><a href="../ICRC1/Account.html">ICRC1/Account</a></li></li><li><li><a href="../ICRC1/Canisters/Archive.html">ICRC1/Canisters/Archive</a></li></li><li><li><a href="../ICRC1/Canisters/Token.html">ICRC1/Canisters/Token</a></li></li><li><li><a href="../ICRC1/Transfer.html">ICRC1/Transfer</a></li></li><li><li><a href="../ICRC1/Types.html">ICRC1/Types</a></li></li><li><li><a href="../ICRC1/Utils.html">ICRC1/Utils</a></li></li><li><li><a href="../ICRC1/lib.html">ICRC1/lib</a></li></li></ul><h3>Declarations</h3><ul><li><li><a href="#validate_subaccount">validate_subaccount</a></li></li><li><li><a href="#validate">validate</a></li></li><li><li><a href="#encode">encode</a></li></li><li><li><a href="#decode">decode</a></li></li><li><li><a href="#fromText">fromText</a></li></li><li><li><a href="#toText">toText</a></li></li></ul></nav><div class="documentation"><h1>ICRC1/Account</h1><div class="declaration"><h4 class="function" id="validate_subaccount"><code><span class="keyword">public func </span><span class="fnname">validate_subaccount</span>(<span class="parameter">subaccount</span> : ?<a href="Types.html#type.Subaccount"><span class="type">T.Subaccount</span></a>) : <span class="type">Bool</span></code></h4><p><p>Checks if a subaccount is valid</p>
</p></div><div class="declaration"><h4 class="function" id="validate"><code><span class="keyword">public func </span><span class="fnname">validate</span>(<span class="parameter">account</span> : <a href="Types.html#type.Account"><span class="type">T.Account</span></a>) : <span class="type">Bool</span></code></h4><p><p>Checks if an account is valid</p>
</p></div><div class="declaration"><h4 class="function" id="encode"><code><span class="keyword">public func </span><span class="fnname">encode</span>() : <a href="Types.html#type.EncodedAccount"><span class="type">T.EncodedAccount</span></a></code></h4><p><p>Implementation of ICRC1's Textual representation of accounts <a href="https://github.com/dfinity/ICRC-1/tree/main/standards/ICRC-1#encoding">Encoding Standard</a></p>
</p></div><div class="declaration"><h4 class="function" id="decode"><code><span class="keyword">public func </span><span class="fnname">decode</span>(<span class="parameter">encoded</span> : <a href="Types.html#type.EncodedAccount"><span class="type">T.EncodedAccount</span></a>) : ?<a href="Types.html#type.Account"><span class="type">T.Account</span></a></code></h4><p><p>Implementation of ICRC1's Textual representation of accounts <a href="https://github.com/dfinity/ICRC-1/tree/main/standards/ICRC-1#decoding">Decoding Standard</a></p>
</p></div><div class="declaration"><h4 class="function" id="fromText"><code><span class="keyword">public func </span><span class="fnname">fromText</span>(<span class="parameter">encoded</span> : <span class="type">Text</span>) : ?<a href="Types.html#type.Account"><span class="type">T.Account</span></a></code></h4><p><p>Converts an ICRC-1 Account from its Textual representation to the <code>Account</code> type</p>
</p></div><div class="declaration"><h4 class="function" id="toText"><code><span class="keyword">public func </span><span class="fnname">toText</span>(<span class="parameter">account</span> : <a href="Types.html#type.Account"><span class="type">T.Account</span></a>) : <span class="type">Text</span></code></h4><p><p>Converts an ICRC-1 <code>Account</code> to its Textual representation</p>
</p></div></div></body></html>
43 changes: 43 additions & 0 deletions I2-code/docs/ICRC1/Account.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# ICRC1/Account

## Function `validate_subaccount`
``` motoko no-repl
func validate_subaccount(subaccount : ?T.Subaccount) : Bool
```

Checks if a subaccount is valid

## Function `validate`
``` motoko no-repl
func validate(account : T.Account) : Bool
```

Checks if an account is valid

## Function `encode`
``` motoko no-repl
func encode() : T.EncodedAccount
```

Implementation of ICRC1's Textual representation of accounts [Encoding Standard](https://github.com/dfinity/ICRC-1/tree/main/standards/ICRC-1#encoding)

## Function `decode`
``` motoko no-repl
func decode(encoded : T.EncodedAccount) : ?T.Account
```

Implementation of ICRC1's Textual representation of accounts [Decoding Standard](https://github.com/dfinity/ICRC-1/tree/main/standards/ICRC-1#decoding)

## Function `fromText`
``` motoko no-repl
func fromText(encoded : Text) : ?T.Account
```

Converts an ICRC-1 Account from its Textual representation to the `Account` type

## Function `toText`
``` motoko no-repl
func toText(account : T.Account) : Text
```

Converts an ICRC-1 `Account` to its Textual representation
6 changes: 6 additions & 0 deletions I2-code/docs/ICRC1/ArchiveApi.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html><head title="Doc"><meta charset="UTF-8"/><link href="../styles.css" rel="stylesheet"/></head><body><nav class="sidebar"><h3>Modules</h3><ul><li><li><a href="../ICRC1/Account.html">ICRC1/Account</a></li></li><li><li><a href="../ICRC1/ArchiveApi.html">ICRC1/ArchiveApi</a></li></li><li><li><a href="../ICRC1/Canisters/Archive.html">ICRC1/Canisters/Archive</a></li></li><li><li><a href="../ICRC1/Canisters/Token.html">ICRC1/Canisters/Token</a></li></li><li><li><a href="../ICRC1/Transfer.html">ICRC1/Transfer</a></li></li><li><li><a href="../ICRC1/Types.html">ICRC1/Types</a></li></li><li><li><a href="../ICRC1/Utils.html">ICRC1/Utils</a></li></li><li><li><a href="../ICRC1/lib.html">ICRC1/lib</a></li></li></ul><h3>Declarations</h3><ul><li><li><a href="#create_canister">create_canister</a></li></li><li><li><a href="#total_txs">total_txs</a></li></li><li><li><a href="#append_transactions">append_transactions</a></li></li></ul></nav><div class="documentation"><h1>ICRC1/ArchiveApi</h1><div class="declaration"><h4 class="function" id="create_canister"><code><span class="keyword">public func </span><span class="fnname">create_canister</span>() : <span class="keyword">async </span><a href="Types.html#type.ArchiveInterface"><span class="type">T.ArchiveInterface</span></a></code></h4><p><p>creates a new archive canister</p>
</p></div><div class="declaration"><h4 class="function" id="total_txs"><code><span class="keyword">public func </span><span class="fnname">total_txs</span>(<span class="parameter">archives</span> : <a href="Types.html#type.StableBuffer"><span class="type">T.StableBuffer</span></a>&lt;<a href="Types.html#type.ArchiveData"><span class="type">T.ArchiveData</span></a>&gt;) : <span class="type">Nat</span></code></h4><p><p>Get the total number of archived transactions</p>
</p></div><div class="declaration"><h4 class="function" id="append_transactions"><code><span class="keyword">public func </span><span class="fnname">append_transactions</span>(<span class="parameter">token</span> : <a href="Types.html#type.TokenData"><span class="type">T.TokenData</span></a>) : <span class="keyword">async </span>()</code></h4><p><p>Moves the transactions from the ICRC1 canister to the archive canister
and returns a boolean that indicates the success of the data transfer</p>
</p></div></div></body></html>
23 changes: 23 additions & 0 deletions I2-code/docs/ICRC1/ArchiveApi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ICRC1/ArchiveApi

## Function `create_canister`
``` motoko no-repl
func create_canister() : async T.ArchiveInterface
```

creates a new archive canister

## Function `total_txs`
``` motoko no-repl
func total_txs(archives : T.StableBuffer<T.ArchiveData>) : Nat
```

Get the total number of archived transactions

## Function `append_transactions`
``` motoko no-repl
func append_transactions(token : T.TokenData) : async ()
```

Moves the transactions from the ICRC1 canister to the archive canister
and returns a boolean that indicates the success of the data transfer
3 changes: 3 additions & 0 deletions I2-code/docs/ICRC1/Canisters/Token.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!DOCTYPE html>
<html><head title="Doc"><meta charset="UTF-8"/><link href="../../styles.css" rel="stylesheet"/></head><body><nav class="sidebar"><h3>Modules</h3><ul><li><li><a href="../../ICRC1/Account.html">ICRC1/Account</a></li></li><li><li><a href="../../ICRC1/ArchiveApi.html">ICRC1/ArchiveApi</a></li></li><li><li><a href="../../ICRC1/Canisters/Archive.html">ICRC1/Canisters/Archive</a></li></li><li><li><a href="../../ICRC1/Canisters/Token.html">ICRC1/Canisters/Token</a></li></li><li><li><a href="../../ICRC1/Transfer.html">ICRC1/Transfer</a></li></li><li><li><a href="../../ICRC1/Types.html">ICRC1/Types</a></li></li><li><li><a href="../../ICRC1/Utils.html">ICRC1/Utils</a></li></li><li><li><a href="../../ICRC1/lib.html">ICRC1/lib</a></li></li></ul><h3>Declarations</h3><ul><li><li><a href="#type.TokenInitArgs">TokenInitArgs</a></li></li><li><li><a href="#type.Token">Token</a></li></li></ul></nav><div class="documentation"><h1>ICRC1/Canisters/Token</h1><div class="declaration"><h4 class="type-declaration" id="type.TokenInitArgs"><span class="keyword">type </span><span class="type">TokenInitArgs</span> = { name : <span class="type">Text</span>; symbol : <span class="type">Text</span>; decimals : <span class="type">Nat8</span>; fee : <a href="../.html#type.Balance"><span class="type">ICRC1.Balance</span></a>; max_supply : <a href="../.html#type.Balance"><span class="type">ICRC1.Balance</span></a>; minting_account : ?<a href="../.html#type.Account"><span class="type">ICRC1.Account</span></a>; initial_balances : [(<a href="../.html#type.Account"><span class="type">ICRC1.Account</span></a>, <a href="../.html#type.Balance"><span class="type">ICRC1.Balance</span></a>)] }</h4><p></p></div><div class="declaration"><h4 class="class-declaration" id="type.Token"><span class="keyword">actor </span><span class="keyword">class </span><span class="classname">Token</span>(<span class="parameter">token_args</span> : <a href="#type.TokenInitArgs"><span class="type">TokenInitArgs</span></a>)</h4><div class="declaration"><h4 class="function" id="Token.icrc1_name"><code><span class="keyword">public func </span><span class="fnname">icrc1_name</span>() : <span class="keyword">async </span><span class="type">Text</span></code></h4><p><p>Functions for the ICRC1 token standard</p>
</p></div><div class="declaration"><h4 class="function" id="Token.icrc1_symbol"><code><span class="keyword">public func </span><span class="fnname">icrc1_symbol</span>() : <span class="keyword">async </span><span class="type">Text</span></code></h4><p></p></div><div class="declaration"><h4 class="function" id="Token.icrc1_decimals"><code><span class="keyword">public func </span><span class="fnname">icrc1_decimals</span>() : <span class="keyword">async </span><span class="type">Nat8</span></code></h4><p></p></div><div class="declaration"><h4 class="function" id="Token.icrc1_fee"><code><span class="keyword">public func </span><span class="fnname">icrc1_fee</span>() : <span class="keyword">async </span><a href="../.html#type.Balance"><span class="type">ICRC1.Balance</span></a></code></h4><p></p></div><div class="declaration"><h4 class="function" id="Token.icrc1_metadata"><code><span class="keyword">public func </span><span class="fnname">icrc1_metadata</span>() : <span class="keyword">async </span>[<a href="../.html#type.MetaDatum"><span class="type">ICRC1.MetaDatum</span></a>]</code></h4><p></p></div><div class="declaration"><h4 class="function" id="Token.icrc1_total_supply"><code><span class="keyword">public func </span><span class="fnname">icrc1_total_supply</span>() : <span class="keyword">async </span><a href="../.html#type.Balance"><span class="type">ICRC1.Balance</span></a></code></h4><p></p></div><div class="declaration"><h4 class="function" id="Token.icrc1_minting_account"><code><span class="keyword">public func </span><span class="fnname">icrc1_minting_account</span>() : <span class="keyword">async </span>?<a href="../.html#type.Account"><span class="type">ICRC1.Account</span></a></code></h4><p></p></div><div class="declaration"><h4 class="function" id="Token.icrc1_balance_of"><code><span class="keyword">public func </span><span class="fnname">icrc1_balance_of</span>(<span class="parameter">args</span> : <a href="../.html#type.Account"><span class="type">ICRC1.Account</span></a>) : <span class="keyword">async </span><a href="../.html#type.Balance"><span class="type">ICRC1.Balance</span></a></code></h4><p></p></div><div class="declaration"><h4 class="function" id="Token.icrc1_supported_standards"><code><span class="keyword">public func </span><span class="fnname">icrc1_supported_standards</span>() : <span class="keyword">async </span>[<a href="../.html#type.SupportedStandard"><span class="type">ICRC1.SupportedStandard</span></a>]</code></h4><p></p></div><div class="declaration"><h4 class="function" id="Token.icrc1_transfer"><code><span class="keyword">public func </span><span class="fnname">icrc1_transfer</span>(<span class="parameter">args</span> : <a href="../.html#type.TransferArgs"><span class="type">ICRC1.TransferArgs</span></a>) : <span class="keyword">async </span><span class="type">Result.Result</span>&lt;<a href="../.html#type.Balance"><span class="type">ICRC1.Balance</span></a>, <a href="../.html#type.TransferError"><span class="type">ICRC1.TransferError</span></a>&gt;</code></h4><p></p></div><div class="declaration"><h4 class="function" id="Token.mint"><code><span class="keyword">public func </span><span class="fnname">mint</span>(<span class="parameter">args</span> : <a href="../.html#type.Mint"><span class="type">ICRC1.Mint</span></a>) : <span class="keyword">async </span><span class="type">Result.Result</span>&lt;<a href="../.html#type.Balance"><span class="type">ICRC1.Balance</span></a>, <a href="../.html#type.TransferError"><span class="type">ICRC1.TransferError</span></a>&gt;</code></h4><p></p></div><div class="declaration"><h4 class="function" id="Token.burn"><code><span class="keyword">public func </span><span class="fnname">burn</span>(<span class="parameter">args</span> : <a href="../.html#type.BurnArgs"><span class="type">ICRC1.BurnArgs</span></a>) : <span class="keyword">async </span><span class="type">Result.Result</span>&lt;<a href="../.html#type.Balance"><span class="type">ICRC1.Balance</span></a>, <a href="../.html#type.TransferError"><span class="type">ICRC1.TransferError</span></a>&gt;</code></h4><p></p></div><div class="declaration"><h4 class="function" id="Token.get_transaction"><code><span class="keyword">public func </span><span class="fnname">get_transaction</span>(<span class="parameter">token_id</span> : <span class="type">Nat</span>) : <span class="keyword">async </span>?<a href="../.html#type.Transaction"><span class="type">ICRC1.Transaction</span></a></code></h4><p></p></div><div class="declaration"><h4 class="function" id="Token.get_transactions"><code><span class="keyword">public func </span><span class="fnname">get_transactions</span>(<span class="parameter">req</span> : <a href="../.html#type.GetTransactionsRequest"><span class="type">ICRC1.GetTransactionsRequest</span></a>) : <span class="keyword">async </span>()</code></h4><p></p></div><p></p></div></div></body></html>
108 changes: 108 additions & 0 deletions I2-code/docs/ICRC1/Canisters/Token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# ICRC1/Canisters/Token

## Type `TokenInitArgs`
``` motoko no-repl
type TokenInitArgs = { name : Text; symbol : Text; decimals : Nat8; fee : ICRC1.Balance; max_supply : ICRC1.Balance; minting_account : ?ICRC1.Account; initial_balances : [(ICRC1.Account, ICRC1.Balance)] }
```


## `actor class Token`


### Function `icrc1_name`
``` motoko no-repl
func icrc1_name() : async Text
```

Functions for the ICRC1 token standard


### Function `icrc1_symbol`
``` motoko no-repl
func icrc1_symbol() : async Text
```



### Function `icrc1_decimals`
``` motoko no-repl
func icrc1_decimals() : async Nat8
```



### Function `icrc1_fee`
``` motoko no-repl
func icrc1_fee() : async ICRC1.Balance
```



### Function `icrc1_metadata`
``` motoko no-repl
func icrc1_metadata() : async [ICRC1.MetaDatum]
```



### Function `icrc1_total_supply`
``` motoko no-repl
func icrc1_total_supply() : async ICRC1.Balance
```



### Function `icrc1_minting_account`
``` motoko no-repl
func icrc1_minting_account() : async ?ICRC1.Account
```



### Function `icrc1_balance_of`
``` motoko no-repl
func icrc1_balance_of(args : ICRC1.Account) : async ICRC1.Balance
```



### Function `icrc1_supported_standards`
``` motoko no-repl
func icrc1_supported_standards() : async [ICRC1.SupportedStandard]
```



### Function `icrc1_transfer`
``` motoko no-repl
func icrc1_transfer(args : ICRC1.TransferArgs) : async Result.Result<ICRC1.Balance, ICRC1.TransferError>
```



### Function `mint`
``` motoko no-repl
func mint(args : ICRC1.Mint) : async Result.Result<ICRC1.Balance, ICRC1.TransferError>
```



### Function `burn`
``` motoko no-repl
func burn(args : ICRC1.BurnArgs) : async Result.Result<ICRC1.Balance, ICRC1.TransferError>
```



### Function `get_transaction`
``` motoko no-repl
func get_transaction(token_id : Nat) : async ?ICRC1.Transaction
```



### Function `get_transactions`
``` motoko no-repl
func get_transactions(req : ICRC1.GetTransactionsRequest) : async ()
```

Loading