Skip to content

Commit

Permalink
fix: renamed IHRC to IHRC719 (#808)
Browse files Browse the repository at this point in the history
Signed-off-by: Logan Nguyen <[email protected]>
  • Loading branch information
quiet-node authored Jun 14, 2024
1 parent ea72b2b commit c4691a4
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ artifacts/contracts/**/**/*.dbg.json
!artifacts/contracts/hts-precompile
artifacts/contracts/hts-precompile/*
!artifacts/contracts/hts-precompile/examples
!artifacts/contracts/hts-precompile/IHRC.sol
!artifacts/contracts/hts-precompile/IHRC719.sol

!artifacts/contracts/exchange-rate-precompile
artifacts/contracts/exchange-rate-precompile/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "IHRC",
"sourceName": "contracts/hts-precompile/IHRC.sol",
"contractName": "IHRC719",
"sourceName": "contracts/hts-precompile/IHRC719.sol",
"abi": [
{
"inputs": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "HRCContract",
"sourceName": "contracts/hts-precompile/examples/hrc/HRCContract.sol",
"contractName": "HRC719Contract",
"sourceName": "contracts/hts-precompile/examples/hrc-719/HRC719Contract.sol",
"abi": [
{
"inputs": [
Expand Down Expand Up @@ -42,8 +42,8 @@
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b506101a0806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063322e35501461003b578063d89f312314610060575b600080fd5b61004e610049366004610121565b610073565b60405190815260200160405180910390f35b61004e61006e366004610121565b6100df565b6000816001600160a01b0316635c9217e06040518163ffffffff1660e01b81526004016020604051808303816000875af11580156100b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100d99190610151565b92915050565b6000816001600160a01b0316630a754de66040518163ffffffff1660e01b81526004016020604051808303816000875af11580156100b5573d6000803e3d6000fd5b60006020828403121561013357600080fd5b81356001600160a01b038116811461014a57600080fd5b9392505050565b60006020828403121561016357600080fd5b505191905056fea26469706673582212209b69498c3d65324aca9a621cdb22b17518951d53b840cd6ab19db1d7118729a964736f6c63430008170033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100365760003560e01c8063322e35501461003b578063d89f312314610060575b600080fd5b61004e610049366004610121565b610073565b60405190815260200160405180910390f35b61004e61006e366004610121565b6100df565b6000816001600160a01b0316635c9217e06040518163ffffffff1660e01b81526004016020604051808303816000875af11580156100b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100d99190610151565b92915050565b6000816001600160a01b0316630a754de66040518163ffffffff1660e01b81526004016020604051808303816000875af11580156100b5573d6000803e3d6000fd5b60006020828403121561013357600080fd5b81356001600160a01b038116811461014a57600080fd5b9392505050565b60006020828403121561016357600080fd5b505191905056fea26469706673582212209b69498c3d65324aca9a621cdb22b17518951d53b840cd6ab19db1d7118729a964736f6c63430008170033",
"bytecode": "0x608060405234801561001057600080fd5b506101a0806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063322e35501461003b578063d89f312314610060575b600080fd5b61004e610049366004610121565b610073565b60405190815260200160405180910390f35b61004e61006e366004610121565b6100df565b6000816001600160a01b0316635c9217e06040518163ffffffff1660e01b81526004016020604051808303816000875af11580156100b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100d99190610151565b92915050565b6000816001600160a01b0316630a754de66040518163ffffffff1660e01b81526004016020604051808303816000875af11580156100b5573d6000803e3d6000fd5b60006020828403121561013357600080fd5b81356001600160a01b038116811461014a57600080fd5b9392505050565b60006020828403121561016357600080fd5b505191905056fea26469706673582212201f7d7d711f4ad53fba171b39af61c2bca7667409be78724526e5d3fed707264564736f6c63430008170033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100365760003560e01c8063322e35501461003b578063d89f312314610060575b600080fd5b61004e610049366004610121565b610073565b60405190815260200160405180910390f35b61004e61006e366004610121565b6100df565b6000816001600160a01b0316635c9217e06040518163ffffffff1660e01b81526004016020604051808303816000875af11580156100b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100d99190610151565b92915050565b6000816001600160a01b0316630a754de66040518163ffffffff1660e01b81526004016020604051808303816000875af11580156100b5573d6000803e3d6000fd5b60006020828403121561013357600080fd5b81356001600160a01b038116811461014a57600080fd5b9392505050565b60006020828403121561016357600080fd5b505191905056fea26469706673582212201f7d7d711f4ad53fba171b39af61c2bca7667409be78724526e5d3fed707264564736f6c63430008170033",
"linkReferences": {},
"deployedLinkReferences": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "spender",
"type": "address"
}
],
"name": "hbarAllowance",
"outputs": [
{
"internalType": "int64",
"name": "responseCode",
"type": "int64"
},
{
"internalType": "int256",
"name": "amount",
"type": "int256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "int256",
"name": "amount",
"type": "int256"
}
],
"name": "hbarApprove",
"outputs": [
{
"internalType": "int64",
"name": "responseCode",
"type": "int64"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
]
2 changes: 1 addition & 1 deletion contracts/hts-precompile/AtomicHTS.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import "./IHRC.sol";
import "./IHRC719.sol";
import "./HederaTokenService.sol";
import "./IHederaTokenService.sol";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.4.9 <0.9.0;

interface IHRC {
interface IHRC719 {
function associate() external returns (uint256 responseCode);
function dissociate() external returns (uint256 responseCode);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.7;

import "../../IHRC.sol";
import "../../IHRC719.sol";

contract HRCContract {
contract HRC719Contract {
function associate(address token) public returns (uint256 responseCode) {
return IHRC(token).associate();
return IHRC719(token).associate();
}

function dissociate(address token) public returns (uint256 responseCode) {
return IHRC(token).dissociate();
return IHRC719(token).dissociate();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ const getHederaSmartContractAssets = (HederaSmartContractsRootPath: string) => {
},
IHRC719Contract: {
name: 'IHRC719Contract',
contractPath: `${HederaSmartContractsRootPath}/contracts/hts-precompile/IHRC.sol`,
artifactPath: `${HederaSmartContractsRootPath}/artifacts/contracts/hts-precompile/IHRC.sol/IHRC.json`,
contractPath: `${HederaSmartContractsRootPath}/contracts/hts-precompile/IHRC719.sol`,
artifactPath: `${HederaSmartContractsRootPath}/artifacts/contracts/hts-precompile/IHRC719.sol/IHRC719.json`,
},
ExchangeRateMock: {
name: 'ExchangeRateMock',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/

import { TContractName } from '@/types/common';
import IHRC719Contract from '@hashgraph-smartcontract/artifacts/contracts/hts-precompile/IHRC719.sol/IHRC719.json';
import ERC20Mock from '@hashgraph-smartcontract/artifacts/contracts/openzeppelin/ERC-20/ERC20Mock.sol/ERC20Mock.json';
import IHRC719Contract from '@hashgraph-smartcontract/artifacts/contracts/hts-precompile/IHRC.sol/IHRC.json';
import ERC721Mock from '@hashgraph-smartcontract/artifacts/contracts/openzeppelin/ERC-721/ERC721Mock.sol/ERC721Mock.json';
import PrngSystemContract from '@hashgraph-smartcontract/artifacts/contracts/util-precompile/PrngSystemContract.sol/PrngSystemContract.json';
import ExchangeRatePrecompile from '@hashgraph-smartcontract/artifacts/contracts/exchange-rate-precompile/ExchangeRateMock.sol/ExchangeRateMock.json';
Expand Down
2 changes: 1 addition & 1 deletion test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const Contract = {
ERC20BurnableMock: 'ERC20BurnableMock',
ERC20CappedMock: 'ERC20CappedMock',
ERC20PausableMock: 'ERC20PausableMock',
HRCContract: 'HRCContract',
HRC719Contract: 'HRC719Contract',
ExchangeRateMock: 'ExchangeRateMock',
PrngSystemContract: 'PrngSystemContract',
Concatenation: 'Concatenation',
Expand Down
8 changes: 4 additions & 4 deletions test/foundry/mocks/hts-precompile/HederaFungibleToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

import '../../../../contracts/hts-precompile/HederaResponseCodes.sol';
import '../../../../contracts/hts-precompile/IHederaTokenService.sol';
import '../../../../contracts/hts-precompile/IHRC.sol';
import '../../../../contracts/hts-precompile/IHRC719.sol';
import './HtsSystemContractMock.sol';
import '../../../../contracts/libraries/Constants.sol';

contract HederaFungibleToken is IHRC, ERC20, Constants {
contract HederaFungibleToken is IHRC719, ERC20, Constants {
error HtsPrecompileError(int64 responseCode);
HtsSystemContractMock internal constant HtsPrecompile = HtsSystemContractMock(HTS_PRECOMPILE);

Expand Down Expand Up @@ -105,7 +105,7 @@ contract HederaFungibleToken is IHRC, ERC20, Constants {
return _decimals;
}

// IHRC setters:
// IHRC719 setters:

function associate() external returns (uint256 responseCode) {
responseCode = uint64(HtsPrecompile.preAssociate(msg.sender));
Expand All @@ -115,7 +115,7 @@ contract HederaFungibleToken is IHRC, ERC20, Constants {
responseCode = uint64(HtsPrecompile.preDissociate(msg.sender));
}

// IHRC getters:
// IHRC719 getters:

function isAssociated(address evmAddress) external view returns (bool) {
return HtsPrecompile.isAssociated(evmAddress, address(this));
Expand Down
8 changes: 4 additions & 4 deletions test/foundry/mocks/hts-precompile/HederaNonFungibleToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import '@openzeppelin/contracts/token/ERC721/ERC721.sol';

import '../../../../contracts/hts-precompile/HederaResponseCodes.sol';
import '../../../../contracts/hts-precompile/IHederaTokenService.sol';
import '../../../../contracts/hts-precompile/IHRC.sol';
import '../../../../contracts/hts-precompile/IHRC719.sol';
import './HtsSystemContractMock.sol';
import '../../../../contracts/libraries/Constants.sol';

contract HederaNonFungibleToken is IHRC, ERC721, Constants {
contract HederaNonFungibleToken is IHRC719, ERC721, Constants {
error HtsPrecompileError(int64 responseCode);

HtsSystemContractMock internal constant HtsPrecompile = HtsSystemContractMock(HTS_PRECOMPILE);
Expand Down Expand Up @@ -165,7 +165,7 @@ contract HederaNonFungibleToken is IHRC, ERC721, Constants {
burned = nftCount.burned;
}

// IHRC setters:
// IHRC719 setters:

function associate() external returns (uint256 responseCode) {
responseCode = uint64(HtsPrecompile.preAssociate(msg.sender));
Expand All @@ -175,7 +175,7 @@ contract HederaNonFungibleToken is IHRC, ERC721, Constants {
responseCode = uint64(HtsPrecompile.preDissociate(msg.sender));
}

// IHRC getters:
// IHRC719 getters:

function isAssociated(address evmAddress) external view returns (bool) {
return HtsPrecompile.isAssociated(evmAddress, address(this));
Expand Down
4 changes: 2 additions & 2 deletions test/foundry/mocks/interfaces/IHRCCommon.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.4.9 <0.9.0;

import "../../../../contracts/hts-precompile/IHRC.sol";
import "../../../../contracts/hts-precompile/IHRC719.sol";

interface IERCCommonToken {
function balanceOf(address account) external view returns (uint256);
}

interface IHRCCommon is IHRC, IERCCommonToken {
interface IHRCCommon is IHRC719, IERCCommonToken {
// NOTE: can be moved into IHRC once implemented https://hips.hedera.com/hip/hip-719
function isAssociated(address evmAddress) external view returns (bool);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ const hre = require('hardhat');
const { ethers } = hre;
const utils = require('../utils');

describe('HRC Test Suite', function () {
describe('@HRC-719 Test Suite', function () {
let tokenCreateContract;
let tokenAddress;
let hrcContract;
let hrc719Contract;
let signers;
let hrcToken;
let IHRC;
let IHRC719;

const parseCallResponseEventData = async (tx) => {
return (await tx.wait()).logs.filter(
Expand All @@ -52,7 +52,7 @@ describe('HRC Test Suite', function () {
]);

// This contract is a wrapper for the associate() and dissociate() functions
hrcContract = await utils.deployHRCContract();
hrc719Contract = await utils.deployHRC719Contract();
tokenAddress = await utils.createFungibleToken(
tokenCreateContract,
signers[0].address
Expand All @@ -62,16 +62,18 @@ describe('HRC Test Suite', function () {
]);

// create an interface for calling functions via redirectForToken()
IHRC = new ethers.Interface((await hre.artifacts.readArtifact('IHRC')).abi);
IHRC719 = new ethers.Interface(
(await hre.artifacts.readArtifact('IHRC719')).abi
);
// create a contract object for the token
hrcToken = new Contract(tokenAddress, IHRC, signers[0]);
console.log('hrcContract: ', await hrcContract.getAddress());
hrcToken = new Contract(tokenAddress, IHRC719, signers[0]);
console.log('hrc719Contract: ', await hrc719Contract.getAddress());
console.log('signer: ', signers[0].address);
console.log('tokenAddress: ', tokenAddress);
});

it('should be able to associate() to the token from a contract', async function () {
const txAssociate = await hrcContract.associate(
const txAssociate = await hrc719Contract.associate(
tokenAddress,
Constants.GAS_LIMIT_1_000_000
);
Expand All @@ -81,7 +83,7 @@ describe('HRC Test Suite', function () {
});

xit('should be able to disssociate() to the token from a contract', async function () {
const txDissociate = await hrcContract.dissociate(
const txDissociate = await hrc719Contract.dissociate(
tokenAddress,
Constants.GAS_LIMIT_1_000_000
);
Expand All @@ -107,7 +109,7 @@ describe('HRC Test Suite', function () {
});

xit('should be able to execute associate() via redirectForToken', async function () {
const encodedFunc = IHRC.encodeFunctionData('associate()');
const encodedFunc = IHRC719.encodeFunctionData('associate()');
const tx = await tokenCreateContract.redirectForToken(
tokenAddress,
encodedFunc,
Expand All @@ -119,7 +121,7 @@ describe('HRC Test Suite', function () {
});

xit('should be able to execute dissociate() via redirectForToken', async function () {
const encodedFunc = IHRC.encodeFunctionData('dissociate()');
const encodedFunc = IHRC719.encodeFunctionData('dissociate()');
const tx = await tokenCreateContract.redirectForToken(
tokenAddress,
encodedFunc,
Expand Down
10 changes: 4 additions & 6 deletions test/hts-precompile/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,16 @@ class Utils {
);
}

static async deployHRCContract() {
static async deployHRC719Contract() {
const hrcContractFactory = await ethers.getContractFactory(
Constants.Contract.HRCContract
Constants.Contract.HRC719Contract
);
const hrcContract = await hrcContractFactory.deploy(
Constants.GAS_LIMIT_1_000_000
);

return await ethers.getContractAt(
Constants.Contract.HRCContract,
Constants.Contract.HRC719Contract,
await hrcContract.getAddress()
);
}
Expand Down Expand Up @@ -550,9 +550,7 @@ class Utils {
}

for (const privateKey of ecdsaPrivateKeys) {
const pkSigner = PrivateKey.fromStringECDSA(
privateKey.replace('0x', '')
);
const pkSigner = PrivateKey.fromStringECDSA(privateKey.replace('0x', ''));
const accountId = await Utils.getAccountId(
pkSigner.publicKey.toEvmAddress(),
clientGenesis
Expand Down

0 comments on commit c4691a4

Please sign in to comment.