Skip to content

icrc2#10

Open
JingJingZhang9 wants to merge 1 commit into
NatLabs:mainfrom
JingJingZhang9:icrc2
Open

icrc2#10
JingJingZhang9 wants to merge 1 commit into
NatLabs:mainfrom
JingJingZhang9:icrc2

Conversation

@JingJingZhang9

Copy link
Copy Markdown

No description provided.

@tomijaga

Copy link
Copy Markdown
Member

Hey @JingJingZhang9,
I've made some changes to the main branch to fix the issues with the automated test workflows.
Could you merge the changes from the main branch to your PR?

In the meantime, I will review the PR and leave any feedback.

@tomijaga tomijaga requested a review from skilesare June 8, 2023 03:54
Comment thread dfx.json
"defaults": {
"build": {
"packtool": "mops sources",
"packtool": "vessel sources",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, mops is the preferred manager because of its ability to host packages that can be easily retrieved without the added effort of setting up complex package sets.

We would lose all these benefits if we switch back to vessel.

Comment thread readme.md
Comment on lines +1 to +3
# ICRC-2 Implementation
This repo contains the implementation of the
[ICRC-1](https://github.com/dfinity/ICRC-1) token standard.
[ICRC-2](https://github.com/dfinity/ICRC-1/blob/main/standards/ICRC-2/README.md).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of replacing the link, we could add a statement that says the repo contains implementations of ICRC-1 and ICRC-2 and link to them

Comment thread readme.md
Comment on lines +5 to +7
## References
- [ICRC-1](https://github.com/NatLabs/icrc1)
- [ICRC1 test](https://github.com/NatLabs/icrc1/blob/main/example/icrc1/main.mo)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to remove the references as they are links to other icrc1 implementations

Comment thread readme.md

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the readme, I think we can leave the previous information about ICRC-1 and then add sections with information for ICRC-2

Comment thread src/ICRC1/Account.mo
Comment on lines +17 to +20
import ArrayModule "array/Array";
import Itertools "itertools/Iter";
import StableBuffer "stable/StableBuffer";
import STMap "stable/StableTrieMap";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downloading the dependencies directly into the repo leads to increased project size and makes it harder to update or rollback package versions

Comment thread src/ICRC1/Types.mo
Comment on lines +108 to +118
public type TransferFromArgs = {
from_subaccount : Account;
to : Account;
amount : Balance;
fee : ?Balance;
memo : ?Blob;

/// The time at which the transaction was created.
/// If this is set, the canister will check for duplicate transactions and reject them.
created_at_time : ?Nat64;
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

icrc2_transfer_from

type TransferFromArgs = record {
    spender_subaccount : opt blob;
    from : Account;
    to : Account;
    amount : nat;
    fee : opt nat;
    memo : opt blob;
    created_at_time : opt nat64;
};

Missing the spender_subaccount and the from_subaccount should be replaced with the from account.

Comment thread src/ICRC1/Transfer.mo
Comment on lines +412 to +424
switch (allowance_pair.expires_at) {
case (null) {};
case (?expires_at_time) {
switch (tx_req.created_at_time) {
case (null) {};
case (?created_at_time) {
if (created_at_time > expires_at_time) {
return #err(#InsufficientFunds { balance = 0 });
};
};
};
};
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this condition, we need to check if the allowance time of the spender has expired or not. To do that we need to check if the expires_at field is less than the current time. We can get the current time by calling the Time.now() function.

Comment thread src/ICRC1/Transfer.mo
case (null) {};
case (?created_at_time) {
if (created_at_time > expires_at_time) {
return #err(#InsufficientFunds { balance = 0 });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In situations where there is not an explicit error type, you can use the

#GenericError : { error_code : Nat; message : Text };

Comment thread src/ICRC1/Transfer.mo
#ok();
};

public func validate_approve_request(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validate_approve_request and validate_transfer_from_request functions need to add conditions to check for transaction deduplication. This was introduced in the ICRC-1 standard.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the transfer_from function in lib.mo uses the Transfer.validate_request() which checks for transaction deduplication. It's just the approve function that doesn't have it.

Comment thread src/ICRC1/lib.mo
created_at_time = tx_transfer_from_req.created_at_time;
};

let normal_tx_kind = #transfer;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should say #transfer_from instead so deduplication does not happen for a #transfer kind with matching fields. The TxKind type should be updated for ICRC-2 to include it.

@JingJingZhang9

JingJingZhang9 commented Jul 18, 2023 via email

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants