Skip to content

Add fungible token contract, via HTS#48

Draft
markogracin wants to merge 8 commits into
mainfrom
feature/add-fungible-token-contract
Draft

Add fungible token contract, via HTS#48
markogracin wants to merge 8 commits into
mainfrom
feature/add-fungible-token-contract

Conversation

@markogracin

Copy link
Copy Markdown
Collaborator
  • due compatibility with Hedera (hashscan), and usage with Hashpack, we went in the HTS direction over standard ERC20.

@markogracin markogracin self-assigned this Feb 13, 2025
@vercel

vercel Bot commented Feb 13, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
bidi-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 9, 2025 7:44am

@pcaversaccio pcaversaccio left a comment

Copy link
Copy Markdown
Member

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.

Comment thread contracts/hardhat.config.ts
Comment thread contracts/contracts/TokenContract.sol Outdated
Comment thread contracts/contracts/TokenContract.sol Outdated
Comment thread contracts/contracts/TokenContract.sol Outdated
*/
constructor() {
_owner = msg.sender;
_feeRecipient = msg.sender;

Copy link
Copy Markdown
Member

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_;
}

Comment thread contracts/contracts/TokenContract.sol Outdated
* @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) {

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this part that differs from the standard contracts, as it's using HederaTokenService, to make it compatible with hashpack wallet and hashscan. Will find the examples and documentation that I used to add this, as a reference.

Comment thread contracts/contracts/TokenContract.sol
Comment thread contracts/contracts/TokenContract.sol Outdated
Comment thread contracts/contracts/TokenContract.sol Outdated
address(this),
amount
);
if (transfer != HederaResponseCodes.SUCCESS) revert("Collateral coin transfer failed");

Copy link
Copy Markdown
Member

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 {

Copy link
Copy Markdown
Member

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.

@markogracin

Copy link
Copy Markdown
Collaborator Author

I quickly glanced through the contract and left some comments.

Thanks @pcaversaccio, appreciate it! Will take a look this weekend, and get back to re-check.

Introduced OpenZeppelin's `Ownable` contract to simplify ownership management and removed custom `onlyOwner` modifier logic. Updated `TokenCreator` to inherit `Ownable`, refactored constructor, and replaced `_owner` references with `owner()`. Added `@openzeppelin/contracts` as a dependency in `package.json`, and updated import statements accordingly.
Introduce public getter functions to retrieve addresses for the token, collateral token, contract owner, and fee recipient, as well as the amount of locked collateral.
…wner

Add `onlyOwner` modifier to `createFungible` and `setCollateralToken` functions to ensure only the contract owner can execute these actions.
Replaced generic string-based revert messages with custom error types for improved clarity and gas efficiency.
Introduce `emergencyTokenRecovery` to allow the contract owner to recover wrongly sent tokens, ensuring collateral or main token fees remain unaffected. Added relevant event and error.
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.

2 participants