-
Notifications
You must be signed in to change notification settings - Fork 6
Initial/draft implementation of token rules. #161
base: feature/token-holder
Are you sure you want to change the base?
Conversation
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.
A few comments—mostly about design choices that are probably OK, but of which I want to make sure we understand the implications.
Two global comments:
- I mostly did not comment on style because I wasn't sure that makes sense given the evident inchoate state, but to the extent you know that (a) there are inconsistencies with the style guide that are not only because more work is forthcoming (e.g., spacing, function documentation, etc.) and (b) there are decisions in here that are not spoken to in the style guide (e.g., doxygen comments that are not part of Ethereum's Natspec), please correct/update this code or the style guide as relevant; and
- where decisions reflect assumptions about what will or may be true in the future, please provide comments so it is clear what is intended (e.g., how constraints will be used, why the token rules are in a mapping where key and value are the same, etc.) and how to move forward when the future is now 🤖
contracts/TokenRules.sol
Outdated
} | ||
|
||
/** | ||
* @param _rule The address of rule to add. |
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.
_ruleAddress
?
contracts/TokenRules.sol
Outdated
SharedStructs.TokenRuleTransfer[] _transfers | ||
) | ||
external | ||
view |
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 think that, because this calls non-view functions (transferFrom
, clearAllowance
), it is not a view
function.
contracts/TokenRules.sol
Outdated
|
||
require ( | ||
checkConstraints(_from, _transfers), | ||
"Constraints do not fullfilled." |
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.
Please strike "do".
contracts/TokenRules.sol
Outdated
"Constraints do not fullfilled." | ||
); | ||
|
||
for (uint256 i = 0; i < _transfers.length; ++i) { |
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 believe best practice advises avoiding usage of loops in this manner. Should we be concerned about gas here?
contracts/TokenRules.sol
Outdated
); | ||
} | ||
|
||
brandedToken.clearAllowance(_from); |
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 appears to be duplicative with TokenHolder
: https://github.com/OpenSTFoundation/openst-contracts/pull/160/files#diff-65cbb9bc9658dc2fe0c2f217fa670020R339
As the approach in TokenHolder
is consistent with EIP20, I'd vote for that one; but, ultimately, my primary concern is eliminating the duplication, so please come to a view with @abhayks1 and @gulshanvasnani.
"Index is out of range." | ||
); | ||
|
||
while ( _index < constraints.length - 1) { |
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.
And still the same question about loops :-)
SharedStructs.TokenRuleTransfer[] _transfers | ||
) | ||
public | ||
view |
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.
Would it make sense to mark this as pure
? Or no because it is clearly a work in progress?
@@ -170,6 +170,17 @@ contract EIP20Token is EIP20Interface { | |||
return true; | |||
} | |||
|
|||
function clearAllowance(address _approver) |
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.
If resetting the allowance to 0 is kept in TokenHolder
, then this change should be struck.
contracts/SharedStructs.sol
Outdated
address ruleAddress; | ||
} | ||
|
||
struct TokenRuleConstraint { |
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.
Is the idea behind a constraint to give the flexibility of having global constraints that apply to one or more (or every?) token rule but that is not reflected in any individual token rule?
- if yes:
- I'd argue this is an enhancement that may not be apposite for a first complete iteration.
- but if the decision is to retain the concept all the same, I suggest renaming to "TokenRulesConstraint".
- if no—each constraint will be specific to a token rule—then I suggest reflecting that in the token rule, and not in the token rules
contracts/TokenRules.sol
Outdated
@@ -0,0 +1,264 @@ | |||
pragma solidity ^0.4.24; | |||
pragma experimental ABIEncoderV2; |
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.
As discussed, considering that experimental features may likely still be experimental by the time we intend to have these concepts on Mainnet, please make the necessary changes to not need to rely on those features.
contracts/TokenRules.sol
Outdated
) | ||
public | ||
{ | ||
organization = _organization; |
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.
Should these inputs be validated?
@@ -44,7 +45,8 @@ import "./Internal.sol"; | |||
* on Ethereum (before v1.0). | |||
* | |||
*/ | |||
contract BrandedToken is EIP20Token, UtilityTokenAbstract, Internal { | |||
contract BrandedToken | |||
is EIP20Token, UtilityTokenAbstract, TokenRulesTokenInterface, Internal { |
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.
TokenRulesTokenInterface
can be renamed AllowanceClearable
?
No description provided.