-
Notifications
You must be signed in to change notification settings - Fork 55
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
Adds SafeHTS library #41
Adds SafeHTS library #41
Conversation
Signed-off-by: Stoyan Panayotov <[email protected]>
Signed-off-by: Miroslav Gatsanoga <[email protected]>
a51a6b8
to
922aa0d
Compare
Signed-off-by: Miroslav Gatsanoga <[email protected]>
bfe3bc0
to
792c415
Compare
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.
All the address->IHederaTokenService changes that came in the force push need to be undone.
safe-hts-precompile/SafeHTS.sol
Outdated
require(responseCode == HederaResponseCodes.SUCCESS, "Safe crypto transfer failed!"); | ||
} | ||
|
||
function safeMintToken(IHederaTokenService token, uint64 amount, bytes[] memory metadata) 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.
These should all go back to address
. IHederaTokenService
is the interface for the precompile, not the type of the tokens. These contracts are untyped.
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.
Done.
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.
After going back to address
the example usages of the library in SafeOperations.sol
are in the form SafeHTS.safe<MethodName>
which stutters. Perhaps I can update the library functions so that they don't start with safe
to avoid this stuttering in the usage e.g. resulting in SafeHTS.<methodName>
. Any thoughts?
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 the goal is to mimic OpenZeppelin's SafeERC20 then the name should stutter. Example - https://github.com/code-423n4/2022-05-alchemix/blob/71abbe683dfd5c0686b7e594fb4f78a14b668d8b/contracts-full/adapters/fuse/FuseTokenAdapterV1.sol#L70
Signed-off-by: Miroslav Gatsanoga <[email protected]>
792c415
to
7a5060b
Compare
Signed-off-by: Miroslav Gatsanoga <[email protected]>
Signed-off-by: Miroslav Gatsanoga <[email protected]>
Signed-off-by: Miroslav Gatsanoga <[email protected]>
Signed-off-by: Miroslav Gatsanoga <[email protected]>
safe-hts-precompile/SafeHTS.sol
Outdated
function safeMintToken(address token, uint64 amount, bytes[] memory metadata) internal | ||
returns (uint64 newTotalSupply, int64[] memory serialNumbers) { | ||
int32 responseCode; | ||
(bool success, bytes memory result) = precompileAddress.delegatecall( |
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.
Do we deliberately use delegatetcall
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.
It was not added in the commits made by me, but looking at the hedera-services PR that precedes this PR it seems to be fixed there.
I don't see an obvious reason to use delegatecall
here so I will change it to call
.
safe-hts-precompile/SafeHTS.sol
Outdated
(bool success, bytes memory result) = precompileAddress.call( | ||
abi.encodeWithSelector(IHederaTokenService.setApprovalForAll.selector, token, operator, approved)); | ||
responseCode = success ? abi.decode(result, (int32)) : HederaResponseCodes.UNKNOWN; | ||
require(responseCode == HederaResponseCodes.SUCCESS, "Safe set token approval failed!"); |
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.
The error message could be changed to: "Safe set token approval for all failed!"
safe-hts-precompile/SafeHTS.sol
Outdated
(bool success, bytes memory result) = precompileAddress.call( | ||
abi.encodeWithSelector(IHederaTokenService.isApprovedForAll.selector, token, owner, operator)); | ||
(responseCode, approved) = success ? abi.decode(result, (int32, bool)) : (HederaResponseCodes.UNKNOWN, false); | ||
require(responseCode == HederaResponseCodes.SUCCESS, "Safe query for if approved for all failed!"); |
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.
Safe is approved for all failed!
safe-hts-precompile/SafeHTS.sol
Outdated
(bool success, bytes memory result) = precompileAddress.call( | ||
abi.encodeWithSelector(IHederaTokenService.updateTokenInfo.selector, token, tokenInfo)); | ||
responseCode = success ? abi.decode(result, (int32)) : HederaResponseCodes.UNKNOWN; | ||
require(responseCode == HederaResponseCodes.SUCCESS, "Safe update token info operation failed!"); |
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.
Safe update token info failed!
safe-hts-precompile/SafeHTS.sol
Outdated
(bool success, bytes memory result) = precompileAddress.call( | ||
abi.encodeWithSelector(IHederaTokenService.updateTokenExpiryInfo.selector, token, expiryInfo)); | ||
responseCode = success ? abi.decode(result, (int32)) : HederaResponseCodes.UNKNOWN; | ||
require(responseCode == HederaResponseCodes.SUCCESS, "Safe update token expiry info operation failed!"); |
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.
Safe update token expiry info failed!
safe-hts-precompile/SafeHTS.sol
Outdated
(bool success, bytes memory result) = precompileAddress.call( | ||
abi.encodeWithSelector(IHederaTokenService.updateTokenKeys.selector, token, keys)); | ||
responseCode = success ? abi.decode(result, (int32)) : HederaResponseCodes.UNKNOWN; | ||
require(responseCode == HederaResponseCodes.SUCCESS, "Safe update token keys operation failed!"); |
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.
Safe update token keys failed!
safe-hts-precompile/SafeHTS.sol
Outdated
(bool success, bytes memory result) = precompileAddress.call( | ||
abi.encodeWithSelector(IHederaTokenService.isToken.selector, token)); | ||
(responseCode, isToken) = success ? abi.decode(result, (int32, bool)) : (HederaResponseCodes.UNKNOWN, false); | ||
require(responseCode == HederaResponseCodes.SUCCESS, "Safe query for if valid token at address failed!"); |
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.
Safe is token failed!
safe-hts-precompile/SafeHTS.sol
Outdated
(bool success, bytes memory result) = precompileAddress.call( | ||
abi.encodeWithSelector(IHederaTokenService.getTokenType.selector, token)); | ||
(responseCode, tokenType) = success ? abi.decode(result, (int32, int32)) : (HederaResponseCodes.UNKNOWN, int32(0)); | ||
require(responseCode == HederaResponseCodes.SUCCESS, "Safe query for token type failed!"); |
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.
Safe get token type failed!
|
||
contract SafeOperations { | ||
|
||
function safeTokenAssociate(address sender, address tokenAddress) external { |
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.
You can keep the same names for all methods as they are in the SafeHTS library, e.g. safeAssociateToken
Signed-off-by: Miroslav Gatsanoga <[email protected]>
Signed-off-by: Miroslav Gatsanoga <[email protected]>
Signed-off-by: Miroslav Gatsanoga <[email protected]>
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
safe-hts-precompile/SafeHTS.sol
Outdated
@@ -435,7 +435,7 @@ library SafeHTS { | |||
(bool success, bytes memory result) = precompileAddress.call( | |||
abi.encodeWithSelector(IHederaTokenService.isToken.selector, token)); | |||
(responseCode, isToken) = success ? abi.decode(result, (int32, bool)) : (HederaResponseCodes.UNKNOWN, false); | |||
require(responseCode == HederaResponseCodes.SUCCESS, "Safe query for if valid token at address failed!"); | |||
require(responseCode == HederaResponseCodes.SUCCESS, "Safe is token failed!"); |
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 reads weird. While all the other variants split out the words I think we should consider keeping this camelCase - Safe isToken failed!
or Safe 'is token' failed
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.
Updated.
Signed-off-by: Miroslav Gatsanoga <[email protected]>
56f994d
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
* Adds SafeHTS library Signed-off-by: Stoyan Panayotov <[email protected]> * Use IHederaTokenService instead of IHTS Signed-off-by: Miroslav Gatsanoga <[email protected]> * Update solidity pragma in SafeOperations Signed-off-by: Miroslav Gatsanoga <[email protected]> * Add HIP-514 functions to SafeHTS library Signed-off-by: Miroslav Gatsanoga <[email protected]> * Use address instead of IHederaTokenService for token params Signed-off-by: Miroslav Gatsanoga <[email protected]> * Delete unused IHTS.sol Signed-off-by: Miroslav Gatsanoga <[email protected]> * Update SafeOperations.sol Signed-off-by: Miroslav Gatsanoga <[email protected]> * Add HIP-514 functions to SafeOperations.sol Signed-off-by: Miroslav Gatsanoga <[email protected]> * Improve error messages Signed-off-by: Miroslav Gatsanoga <[email protected]> * Use same method names in SafeOperations as in SafeHTS Signed-off-by: Miroslav Gatsanoga <[email protected]> * Use call instead of delegatecall in safeMintToken Signed-off-by: Miroslav Gatsanoga <[email protected]> * Update safeIsToken error message Signed-off-by: Miroslav Gatsanoga <[email protected]> Signed-off-by: Stoyan Panayotov <[email protected]> Signed-off-by: Miroslav Gatsanoga <[email protected]> Co-authored-by: Miroslav Gatsanoga <[email protected]>
Adds
SafeHTS.sol
providing functionality allowing to execute safe operations on the HTS precompiled contract.Adds
SafeOperations.sol
which showcasesSafeHTS.sol
usage.Related issue(s):
Fixes #43
Notes for reviewer:
Checklist