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

ZRC-2 - Fungible Tokens standard #31

Merged
merged 8 commits into from
Jan 16, 2020
Merged

ZRC-2 - Fungible Tokens standard #31

merged 8 commits into from
Jan 16, 2020

Conversation

snowsledge
Copy link
Contributor

Implementation of Fungible Tokens standard in Scilla.

Reference contract: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC777/ERC777.sol

@AmritKumar
Copy link
Contributor

@vaivaswatha Can you take a look at it too?

@vaivaswatha
Copy link
Contributor

  1. Does this PR mean that Create FungibleToken.scilla #26 will be discarded?
  2. The spec here ZRC-2: Fungible Token #25 has removed the concept of default operators, but the implementation has it.

@snowsledge
Copy link
Contributor Author

  1. Yes, Create FungibleToken.scilla #26 will be discarded. This will replace that PR.
  2. That is a conflict that is resolved in this PR too. default_operator role is resumed in both tech spec and reference contract implementation.

@vaivaswatha
Copy link
Contributor

  1. Yes, Create FungibleToken.scilla #26 will be discarded. This will replace that PR.
  2. That is a conflict that is resolved in this PR too. default_operator role is resumed in both tech spec and reference contract implementation.

Can you link to the spec that I must refer to, which is compatible with this PR ?

@snowsledge
Copy link
Contributor Author

zrcs/zrc-2.md Outdated Show resolved Hide resolved
reference/FungibleToken.scilla Outdated Show resolved Hide resolved
reference/FungibleToken.scilla Outdated Show resolved Hide resolved
reference/FungibleToken.scilla Outdated Show resolved Hide resolved
reference/FungibleToken.scilla Outdated Show resolved Hide resolved
can_do = uint128_le amount min;
match can_do with
| True =>
new_from_bal = builtin sub bal amount;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you not call ProcedureMove here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Due to this min = min_int bal allowed; requirement, we cannot call ProcedureMove as it takes only balance into account.

reference/FungibleToken.scilla Outdated Show resolved Hide resolved
reference/FungibleToken.scilla Outdated Show resolved Hide resolved
@snowsledge snowsledge mentioned this pull request Jan 8, 2020
@GreyEcologist GreyEcologist mentioned this pull request Jan 8, 2020
@snowsledge snowsledge requested a review from teye January 14, 2020 02:54

(* @dev: Revoke an address from being an operator or default_operator of the caller. *)
(* @param operator: Address to be removed as operator or default_operator. *)
transition RevokeOperator(operator: ByStr20)
Copy link
Contributor

Choose a reason for hiding this comment

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

For AuthorizeOperator there is a check to see if the sender is trying to add themselves into the authorized list. However for the RevokeOperator, there is no such check if the sender is trying to add themselves into the revoked list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion, adding the check for self.

Copy link
Contributor

@anton-trunov anton-trunov left a comment

Choose a reason for hiding this comment

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

LGTM
I've proposed a few suggestions, though.

match result with
| CodeNotAuthorized => Int32 -1
| CodeNotFound => Int32 -2
| CodeNotAllowed => Int32 -3
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
| CodeNotAllowed => Int32 -3
| CodeNotAllowed => Int32 -3

field balances_map: Map ByStr20 Uint128
= Emp ByStr20 Uint128

field operators_map: Map ByStr20 (Map ByStr20 Bool)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would redefine the type of operators_map to Map ByStr20 (Map ByStr20 Unit), where Unit is defined as follows: type Unit = | Unit. This clearly indicates that Map ByStr20 Unit is a set, i.e. we don't care about the value stored at a particular address, but only about the presence of the address. Whereas I find using Bool type (and only one its value True) for that a bit confusing.

The same applies to revoked_default_operators down below.

(* Procedures *)

(* Emit Errors *)
procedure MakeErrorEvent(err : Error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
procedure MakeErrorEvent(err : Error)
procedure IssueErrorEvent(err : Error)

We already have make_error_event. The name suggestion here stresses that it's an action. PublishErrorEven or something like that would do too. Note that I didn't put suggestions on the call sites of MakeErrorEvent.

Comment on lines 91 to 94
match get_bal with
| Some bal => bal
| None => Uint128 0
end;
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this can be factored out as a function. It's also used in BalanceOf transition.

end

(* Mint Tokens *)
procedure ProcedureMint(recipient: ByStr20, amount: Uint128)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
procedure ProcedureMint(recipient: ByStr20, amount: Uint128)
procedure AuthorizedMint(recipient: ByStr20, amount: Uint128)

Comment on lines 324 to 328
is_operator_approved =
match get_operator with
| None => False
| Some status => status
end;
Copy link
Contributor

Choose a reason for hiding this comment

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

This block is not needed if the suggestion above is accepted.

end
end

(* @dev: Returns the number of tokens an approved_spender is allowed to spend on behalf of the token_owner. *)
Copy link
Contributor

Choose a reason for hiding this comment

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

"Returns" here is a bit confusing.

end


(* @dev: Returns the total amount of tokens in existence. *)
Copy link
Contributor

Choose a reason for hiding this comment

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

just the same as for "Returns" above

event e
end

(* @dev: Returns the amount of tokens owned by an address. *)
Copy link
Contributor

Choose a reason for hiding this comment

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

"Returns" too

Comment on lines 387 to 391
balance =
match get_bal with
| Some bal => bal
| None => Uint128 0
end;
Copy link
Contributor

Choose a reason for hiding this comment

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

Candidate to be replace by a function call as in an analogous suggestion at the beginning of the contracts

@snowsledge snowsledge merged commit f9d07dd into master Jan 16, 2020
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.

5 participants