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

icrc2 #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

icrc2 #10

wants to merge 1 commit into from

Conversation

JingJingZhang9
Copy link

No description provided.

@tomijaga
Copy link
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
@@ -14,7 +14,7 @@
},
"defaults": {
"build": {
"packtool": "mops sources",
"packtool": "vessel sources",
Copy link
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 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
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 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
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

Copy link
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 on lines +17 to +20
import ArrayModule "array/Array";
import Itertools "itertools/Iter";
import StableBuffer "stable/StableBuffer";
import STMap "stable/StableTrieMap";
Copy link
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 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
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 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
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.

case (null) {};
case (?created_at_time) {
if (created_at_time > expires_at_time) {
return #err(#InsufficientFunds { balance = 0 });
Copy link
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 };

@@ -281,4 +281,169 @@ module {
#ok();
};

public func validate_approve_request(
Copy link
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
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.

created_at_time = tx_transfer_from_req.created_at_time;
};

let normal_tx_kind = #transfer;
Copy link
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
Copy link
Author

JingJingZhang9 commented Jul 18, 2023 via email

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