-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add fungible token contract, via HTS #48
base: main
Are you sure you want to change the base?
Conversation
markogracin
commented
Feb 13, 2025
- due compatibility with Hedera (hashscan), and usage with Hashpack, we went in the HTS direction over standard ERC20.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
e3a95d4
to
39f4435
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.
I quickly glanced through the contract and left some comments.
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 recommend setting the optimiser settings explicitly:
version: "0.8.28",
settings: {
optimizer: {
enabled: true,
runs: 999_999,
},
evmVersion: "cancun",
},
Please note that Hedera is compatible with the cancun
hard fork: https://docs.hedera.com/hedera/core-concepts/smart-contracts/deploying-smart-contracts#cancun-hard-fork. You should be aware of the semantic differences of the opcodes used on Hedera; see here: https://docs.hedera.com/hedera/core-concepts/smart-contracts/deploying-smart-contracts#solidity-variables-and-opcodes.
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity 0.8.28; | ||
|
||
import './utils/HederaResponseCodes.sol'; |
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.
Nit: please use explicit imports, e.g.:
import {HederaResponseCodes} from "./utils/HederaResponseCodes.sol";
contract TokenCreator is ExpiryHelper, HederaTokenService { | ||
address private _tokenAddress; | ||
address private _collateralTokenAddress; | ||
address private _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.
There is the full logic missing around exposing the owner publicly in the ABI & changing the owner. My recommendation would be to import this contract and inherit from it instead: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol.
/** | ||
* @dev Constructor sets the contract owner and initial fee recipient as the deployer | ||
*/ | ||
constructor() { |
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 could pass the owner address as a configurable parameter in the constructor. As proposed above, use https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol.
*/ | ||
constructor() { | ||
_owner = msg.sender; | ||
_feeRecipient = msg.sender; |
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.
constructor(address feeRecipient_) {
...
if (feeRecipient_== address(0)) {
revert FeeReceiptInvalid(address(0));
}
_feeRecipient = feeRecipient_;
}
* @notice Sets up a 1% fractional fee with min/max limits | ||
* @notice Contract maintains supply and fee management permissions | ||
*/ | ||
function createFungible() external payable returns (address createdTokenAddress) { |
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 have never seen such a function tbh and I'm not sure if this the right way to do it, it's definitely not the right way on Ethereum lol
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.
Also should only be invoked by the owner
?
* @return feeRecipient Address where fees are sent | ||
* @return lockedCollateral Amount of collateral currently locked in contract | ||
*/ | ||
function getContractInfo() external view returns ( |
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.
why not additionally defining for each variable a separate function? You can keep this function and simply invoke the functions in the return
statement but many times you are only interested in one or two params, e.g. who is the owner
.
* @param token Address of the collateral token | ||
* @return responseCode Response code from the Hedera Token Service | ||
*/ | ||
function setCollateralToken(address token) external returns (int) { |
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 be protected no? Only the owner
should be able to do this.
address(this), | ||
amount | ||
); | ||
if (transfer != HederaResponseCodes.SUCCESS) revert("Collateral coin transfer 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 contract uses inconsistently require
and revert
. Can we use everywhere custom errors please?
* @notice Transfers all available balance to fee recipient | ||
* @notice Reverts if no fees are available to collect | ||
*/ | ||
function collectFees() 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.
we should have another emergency function to save any wrongly sent tokens to the contract.
Thanks @pcaversaccio, appreciate it! Will take a look this weekend, and get back to re-check. |