Skip to content

Commit

Permalink
feat: deploy token (#151)
Browse files Browse the repository at this point in the history
Signed-off-by: Mariusz Jasuwienas <[email protected]>
  • Loading branch information
arianejasuwienas committed Jan 14, 2025
1 parent c410d3c commit f3c41fb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
26 changes: 26 additions & 0 deletions contracts/HRC719TokenProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import {IHederaTokenService} from "./IHederaTokenService.sol";

/// @dev HTS Token Proxy contract defined in HIP-719, Specification section.
///
/// For more information,
/// see https://github.com/hashgraph/hedera-smart-contracts/issues/885.
contract HRC719TokenProxy {
fallback() external payable {
address tokenAddress = address(this);
assembly {
let precompileAddress := 0x167
let dynamicData := sload(tokenAddress)
mstore(0, dynamicData)
calldatacopy(32, 0, calldatasize())
let result := call(gas(), precompileAddress, 0, 0, add(32, calldatasize()), 0, 0)
let size := returndatasize()
returndatacopy(0, 0, size)
switch result
case 0 { revert(0, size) }
default { return(0, size) }
}
}
}
24 changes: 24 additions & 0 deletions contracts/HtsSystemContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {IERC721, IERC721Events} from "./IERC721.sol";
import {IHRC719} from "./IHRC719.sol";
import {IHederaTokenService} from "./IHederaTokenService.sol";
import {IERC165} from "../lib/forge-std/src/interfaces/IERC165.sol";
import {HRC719TokenProxy} from "./HRC719TokenProxy.sol";

address constant HTS_ADDRESS = address(0x167);

Expand Down Expand Up @@ -427,6 +428,29 @@ contract HtsSystemContract is IHederaTokenService, IERC20Events, IERC721Events {
return __redirectForToken();
}

function createFungibleToken(
HederaToken memory token,
int64 initialTotalSupply,
int32 decimals
) htsCall external payable returns (int64 responseCode, address tokenAddress) {
HRC719TokenProxy deployed = new HRC719TokenProxy();
tokenAddress = address(token);
HtsSystemContract(tokenAddress)
.initTokenAsHts(token, initialTotalSupply, decimals);
responseCode = 22;
}

function initTokenAsHts(IHederaTokenService.HederaToken memory token, int64 initialTotalSupply, int32 decimals) public {
require(msg.sender == address(0x167));
tokenType = "FUNGIBLE_COMMON";
name = token.name;
symbol = token.symbol;
decimals = decimals;
totalSupply = uint256(uint64(totalSupply));
_tokenInfo.totalSupply = initialTotalSupply;
_tokenInfo.token = token;
}

/**
* @dev Addresses are word right-padded starting from memory position `28`.
*/
Expand Down
10 changes: 5 additions & 5 deletions contracts/IHederaTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,11 @@ interface IHederaTokenService {
/// @param decimals the number of decimal places a token is divisible by
/// @return responseCode The response code for the status of the request. SUCCESS is 22.
/// @return tokenAddress the created token's address
// function createFungibleToken(
// HederaToken memory token,
// int64 initialTotalSupply,
// int32 decimals
// ) external payable returns (int64 responseCode, address tokenAddress);
function createFungibleToken(
HederaToken memory token,
int64 initialTotalSupply,
int32 decimals
) external payable returns (int64 responseCode, address tokenAddress);

/// Creates a Fungible Token with the specified properties
/// @param token the basic properties of the token being created
Expand Down

0 comments on commit f3c41fb

Please sign in to comment.