-
Notifications
You must be signed in to change notification settings - Fork 57
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
Conversation
@vaivaswatha Can you take a look at it too? |
|
|
Can you link to the spec that I must refer to, which is compatible with this PR ? |
This is the spec link which is in this PR: The reference ERC-777 contract is located here: |
reference/FungibleToken.scilla
Outdated
can_do = uint128_le amount min; | ||
match can_do with | ||
| True => | ||
new_from_bal = builtin sub bal amount; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
…eOperator with RevokedDefaultOperator transitions
|
||
(* @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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
reference/FungibleToken.scilla
Outdated
match result with | ||
| CodeNotAuthorized => Int32 -1 | ||
| CodeNotFound => Int32 -2 | ||
| CodeNotAllowed => Int32 -3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| CodeNotAllowed => Int32 -3 | |
| CodeNotAllowed => Int32 -3 |
reference/FungibleToken.scilla
Outdated
field balances_map: Map ByStr20 Uint128 | ||
= Emp ByStr20 Uint128 | ||
|
||
field operators_map: Map ByStr20 (Map ByStr20 Bool) |
There was a problem hiding this comment.
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.
reference/FungibleToken.scilla
Outdated
(* Procedures *) | ||
|
||
(* Emit Errors *) | ||
procedure MakeErrorEvent(err : Error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
reference/FungibleToken.scilla
Outdated
match get_bal with | ||
| Some bal => bal | ||
| None => Uint128 0 | ||
end; |
There was a problem hiding this comment.
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.
reference/FungibleToken.scilla
Outdated
end | ||
|
||
(* Mint Tokens *) | ||
procedure ProcedureMint(recipient: ByStr20, amount: Uint128) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
procedure ProcedureMint(recipient: ByStr20, amount: Uint128) | |
procedure AuthorizedMint(recipient: ByStr20, amount: Uint128) |
reference/FungibleToken.scilla
Outdated
is_operator_approved = | ||
match get_operator with | ||
| None => False | ||
| Some status => status | ||
end; |
There was a problem hiding this comment.
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.
reference/FungibleToken.scilla
Outdated
end | ||
end | ||
|
||
(* @dev: Returns the number of tokens an approved_spender is allowed to spend on behalf of the token_owner. *) |
There was a problem hiding this comment.
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.
reference/FungibleToken.scilla
Outdated
end | ||
|
||
|
||
(* @dev: Returns the total amount of tokens in existence. *) |
There was a problem hiding this comment.
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
reference/FungibleToken.scilla
Outdated
event e | ||
end | ||
|
||
(* @dev: Returns the amount of tokens owned by an address. *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Returns" too
reference/FungibleToken.scilla
Outdated
balance = | ||
match get_bal with | ||
| Some bal => bal | ||
| None => Uint128 0 | ||
end; |
There was a problem hiding this comment.
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
Implementation of Fungible Tokens standard in Scilla.
Reference contract: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC777/ERC777.sol