Skip to content

Commit

Permalink
Add facade specifictions and add exapand README tables
Browse files Browse the repository at this point in the history
Signed-off-by: Nana Essilfie-Conduah <[email protected]>
  • Loading branch information
Nana-EC committed Dec 13, 2024
1 parent 04b62e0 commit 2ef3170
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"inputs": [
{
"internalType": "bool",
"name": "enableAutoAssociations",
"type": "bool"
}
],
"name": "setUnlimitedAutomaticAssociations",
"outputs": [
{
"internalType": "int64",
"name": "responseCode",
"type": "int64"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"inputs": [
{
"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": "spender",
"type": "address"
},
{
"internalType": "int256",
"name": "amount",
"type": "int256"
}
],
"name": "hbarApprove",
"outputs": [
{
"internalType": "int64",
"name": "responseCode",
"type": "int64"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"inputs": [
{
"internalType": "bool",
"name": "enableAutoAssociations",
"type": "bool"
}
],
"name": "setUnlimitedAutomaticAssociations",
"outputs": [
{
"internalType": "int64",
"name": "responseCode",
"type": "int64"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
[
{
"inputs": [
{
"internalType": "address",
"name": "receiverAddress",
"type": "address"
}
],
"name": "cancelAirdropFT",
"outputs": [
{
"internalType": "int64",
"name": "responseCode",
"type": "int64"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "receiverAddress",
"type": "address"
},
{
"internalType": "int64",
"name": "serialNumber",
"type": "int64"
}
],
"name": "cancelAirdropNFT",
"outputs": [
{
"internalType": "int64",
"name": "responseCode",
"type": "int64"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "senderAddress",
"type": "address"
}
],
"name": "claimAirdropFT",
"outputs": [
{
"internalType": "int64",
"name": "responseCode",
"type": "int64"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "senderAddress",
"type": "address"
},
{
"internalType": "int64",
"name": "serialNumber",
"type": "int64"
}
],
"name": "claimAirdropNFT",
"outputs": [
{
"internalType": "int64",
"name": "responseCode",
"type": "int64"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "rejectTokenFT",
"outputs": [
{
"internalType": "int64",
"name": "responseCode",
"type": "int64"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "int64[]",
"name": "serialNumbers",
"type": "int64[]"
}
],
"name": "rejectTokenNFTs",
"outputs": [
{
"internalType": "int64",
"name": "responseCode",
"type": "int64"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.4.9 <0.9.0;

/**
* notice: This interface is applicable when msg.sender is an EOA or a smart contract and the target address is the same.
*/
interface IHRC904AccountFacade {
/// @notice Enables or disables automatic token associations for the calling account
/// @notice Responsible service: HAS
/// @param enableAutoAssociations True to enable unlimited automatic associations, false to disable
/// @return responseCode The response code indicating the result of the operation
function setUnlimitedAutomaticAssociations(bool enableAutoAssociations) external returns (int64 responseCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pragma solidity >=0.4.9 <0.9.0;

/**
* notice: This interface is applicable when msg.sender is an EOA or a smart contract.
* notice: This interface is applicable when msg.sender is an EOA or a smart contract and the target address is the same.
*/
interface IHRC906Facade {
interface IHRC906AccountFacade {
/// Returns the amount of hbar that the spender has been authorized to spend on behalf of the owner.
/// @param spender The account that has been authorized by the owner.
/// @return responseCode The response code for the status of the request. SUCCESS is 22.
Expand Down
8 changes: 8 additions & 0 deletions contracts/system-contracts/hedera-account-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ The table below outlines the available Hedera Account Service System Contract fu
| `hbarApprove` | `0x86aff07c` | [0.52](https://docs.hedera.com/hedera/networks/release-notes/services#release-v0.52) | [HIP 906](https://hips.hedera.com/hip/hip-906) | `hbarApprove(address spender, int256 amount)` |
| `isAuthorizedRaw` | `0xb2a31da4` | [0.52](https://docs.hedera.com/hedera/networks/release-notes/services#release-v0.52) | [HIP 632](https://hips.hedera.com/hip/hip-632) | `isAuthorizedRaw(address, bytes /*messageHash*/, bytes /*signatureBlob*/)` |
| `isAuthorized` | `0xb2526367` | [0.56](https://docs.hedera.com/hedera/networks/release-notes/services#release-v0.56) | [HIP 632](https://hips.hedera.com/hip/hip-632) | `isAuthorizedRaw(address, bytes /*messageHash*/, bytes /*signatureBlob*/)` |

The Hedera network also make facade contract calls available to EOAs for improved experience.
Facade function allow for EOAs to make calls without requiring a deployed contract
The table below outlines the available Hedera Account Service (HAS) System Contract facade functions:

| Function Name | Function Selector Hash | Consensus Node Release Version | HIP | Method Interface | Comments |
| -------------------------------------- | ---------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| `setUnlimitedAutomaticAssociations` | `0xf5677e99` | [0.56](https://docs.hedera.com/hedera/networks/release-notes/services#release-v0.56) | [HIP 904](https://hips.hedera.com/hip/hip-904) | `setUnlimitedAutomaticAssociations(bool enableAutoAssociations) external returns (int64 responseCode)` |
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pragma solidity >=0.4.9 <0.9.0;

/**
* notice: This interface is applicable when msg.sender is an EOA or a smart contract.
* notice: This interface is applicable when msg.sender is an EOA or a contract and the target address is an HTS token.
*/
interface IHRC904 {
interface IHRC904TokenFacade {
/// @notice Cancels a pending fungible token airdrop to a specific receiver
/// @notice Responsible service: HTS
/// @param receiverAddress The address of the receiver whose airdrop should be cancelled
Expand Down Expand Up @@ -41,10 +41,4 @@ interface IHRC904 {
/// @param serialNumbers Array of NFT serial numbers to reject
/// @return responseCode The response code indicating the result of the operation
function rejectTokenNFTs(int64[] memory serialNumbers) external returns (int64 responseCode);

/// @notice Enables or disables automatic token associations for the calling account
/// @notice Responsible service: HAS
/// @param enableAutoAssociations True to enable unlimited automatic associations, false to disable
/// @return responseCode The response code indicating the result of the operation
function setUnlimitedAutomaticAssociations(bool enableAutoAssociations) external returns (int64 responseCode);
}
18 changes: 17 additions & 1 deletion contracts/system-contracts/hedera-token-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ The table below outlines the available Hedera Token Service (HTS) System Contrac
| `getTokenKey` | `0x3c4dd32e` | [0.30](https://docs.hedera.com/hedera/networks/release-notes/services#v0.30) | [HIP 514](https://hips.hedera.com/hip/hip-514) | `getTokenKey(address token, uint256 keyType)` |
| `getTokenType` | `0x93272baf` | [0.30](https://docs.hedera.com/hedera/networks/release-notes/services#v0.30) | [HIP 514](https://hips.hedera.com/hip/hip-514) | `getTokenType(address token)` |
| `grantTokenKyc` | `0x8f8d7f99` | [0.29](https://docs.hedera.com/hedera/networks/release-notes/services#v0.29) | [HIP 514](https://hips.hedera.com/hip/hip-514) | `grantTokenKyc(address token, address account)` |
| `isAssociated` | `0x4d8fdd6d` | [0.53](https://docs.hedera.com/hedera/networks/release-notes/services#v0.53) | [HIP 719](https://hips.hedera.com/hip/hip-719) | `isAssociated()` | |
| `isApprovedForAll` | `0xf49f40db` | [0.26](https://docs.hedera.com/hedera/networks/release-notes/services#v0.26) | [HIP 376](https://hips.hedera.com/hip/hip-376) | `isApprovedForAll(address token, address owner, address operator)` | ERC |
| `isApprovedForAll` | `0xe985e9c5` | [0.26](https://docs.hedera.com/hedera/networks/release-notes/services#v0.26) | [HIP 376](https://hips.hedera.com/hip/hip-376) | `isApprovedForAll(address token, address owner, address operator)` |
| `isFrozen` | `0x46de0fb1` | [0.29](https://docs.hedera.com/hedera/networks/release-notes/services#v0.29) | [HIP 514](https://hips.hedera.com/hip/hip-514) | `isFrozen(address token, address account)` |
Expand Down Expand Up @@ -81,3 +80,20 @@ The table below outlines the available Hedera Token Service (HTS) System Contrac
| `wipeTokenAccount` | `0x9790686d` | [0.29](https://docs.hedera.com/hedera/networks/release-notes/services#v0.29) | [HIP 514](https://hips.hedera.com/hip/hip-514) | `wipeTokenAccount(address token, address account, uint32 amount)` |
| `wipeTokenAccount` | `0xefef57f9` | [0.32](https://docs.hedera.com/hedera/networks/release-notes/services#v0.32) | [HIP 514](https://hips.hedera.com/hip/hip-514) | `wipeTokenAccount(address token, address account, int64 amount)` | v2. Update amount to int64 |
| `wipeTokenAccountNFT` | `0xf7f38e26` | [0.29](https://docs.hedera.com/hedera/networks/release-notes/services#v0.29) | [HIP 514](https://hips.hedera.com/hip/hip-514) | `wipeTokenAccountNFT(address token, address account, int64[] serialNumbers)` |


The Hedera network also make facade contract calls available to EOAs for improved experience.
Facade function allow for EOAs to make calls without requiring a deployed contract
The table below outlines the available Hedera Token Service (HTS) System Contract facade functions:

| Function Name | Function Selector Hash | Consensus Node Release Version | HIP | Method Interface | Comments |
| -------------------------------------- | ---------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| `associate` | `0x0a754de6` | [0.53](https://docs.hedera.com/hedera/networks/release-notes/services#release-v0.56) | [HIP 719](https://hips.hedera.com/hip/hip-904) | `associate() external returns (int64 responseCode)` |
| `cancelAirdropFT` | `0xcef5b705` | [0.56](https://docs.hedera.com/hedera/networks/release-notes/services#release-v0.56) | [HIP 904](https://hips.hedera.com/hip/hip-904) | `cancelAirdropFT(address receiverAddress) external returns (int64 responseCode)` |
| `cancelAirdropNFT` | `0xad4917cf` | [0.56](https://docs.hedera.com/hedera/networks/release-notes/services#release-v0.56) | [HIP 904](https://hips.hedera.com/hip/hip-904) | `cancelAirdropNFT(address receiverAddress, int64 serialNumber) external returns (int64 responseCode)` |
| `claimAirdropFT` | `0xa83bc5b2` | [0.56](https://docs.hedera.com/hedera/networks/release-notes/services#release-v0.56) | [HIP 904](https://hips.hedera.com/hip/hip-904) | `claimAirdropFT(address senderAddress) external returns (int64 responseCode)` |
| `claimAirdropNFT` | `0x63ada5d7` | [0.56](https://docs.hedera.com/hedera/networks/release-notes/services#release-v0.56) | [HIP 904](https://hips.hedera.com/hip/hip-904) | `claimAirdropNFT(address senderAddress, int64 serialNumber) external returns (int64 responseCode)` |
| `dissociate` | `0x5c9217e0` | [0.53](https://docs.hedera.com/hedera/networks/release-notes/services#v0.53) | [HIP 719](https://hips.hedera.com/hip/hip-719) | `dissociate(int64 responseCode)` |
| `isAssociated` | `0x4d8fdd6d` | [0.53](https://docs.hedera.com/hedera/networks/release-notes/services#v0.53) | [HIP 719](https://hips.hedera.com/hip/hip-719) | `isAssociated(bool associated)` |
| `rejectTokenFT` | `0x76c6b391` | [0.56](https://docs.hedera.com/hedera/networks/release-notes/services#release-v0.56) | [HIP 904](https://hips.hedera.com/hip/hip-904) | `rejectTokenFT() external returns (int64 responseCode)` |
| `rejectTokenNFTs` | `0xa869c78a` | [0.56](https://docs.hedera.com/hedera/networks/release-notes/services#release-v0.56) | [HIP 904](https://hips.hedera.com/hip/hip-904) | `rejectTokenNFTs(int64[] memory serialNumbers) external returns (int64 responseCode)` |
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,20 @@ describe('@CryptoAllowance Test Suite', () => {
}
});

it('Should allow owner to grant an allowance to spender using IHRC906Facade and spender to transfer allowance to receiver on behalf of owner', async () => {
// set up IHRC906Facade
const IHRC906Facade = new ethers.Interface(
(await hre.artifacts.readArtifact('IHRC906Facade')).abi
it('Should allow owner to grant an allowance to spender using IHRC906AccountFacade and spender to transfer allowance to receiver on behalf of owner', async () => {
// set up IHRC906AccountFacade
const IHRC906AccountFacade = new ethers.Interface(
(await hre.artifacts.readArtifact('IHRC906AccountFacade')).abi
);

const walletAIHRC906Facade = new ethers.Contract(
const walletAIHRC906AccountFacade = new ethers.Contract(
walletA.address,
IHRC906Facade,
IHRC906AccountFacade,
walletA
);

// grant an allowance to cryptoAllowanceContract
const approveTx = await walletAIHRC906Facade.hbarApprove(
const approveTx = await walletAIHRC906AccountFacade.hbarApprove(
cryptoAllowanceAddress,
amount,
Constants.GAS_LIMIT_1_000_000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ const { Contract } = require('ethers');
const Constants = require('../../../constants');

describe('@IHRC-906 Facade @CryptoAllowance Test Suite', function () {
let walletA, walletB, walletC, walletIHRC906Facade;
let walletA, walletB, walletC, walletIHRC906AccountFacade;
const amount = 3_000;

before(async () => {
[walletA, walletB, walletC] = await ethers.getSigners();

const IHRC906Facade = new ethers.Interface(
(await hre.artifacts.readArtifact('IHRC906Facade')).abi
const IHRC906AccountFacade = new ethers.Interface(
(await hre.artifacts.readArtifact('IHRC906AccountFacade')).abi
);
walletIHRC906Facade = new Contract(walletA.address, IHRC906Facade, walletA);
walletIHRC906AccountFacade = new Contract(walletA.address, IHRC906AccountFacade, walletA);
});

it('should execute hbarApprove() by an EOA to grant an hbar allowance to another EOA', async () => {
const tx = await walletIHRC906Facade.hbarApprove(
const tx = await walletIHRC906AccountFacade.hbarApprove(
walletB.address,
amount,
Constants.GAS_LIMIT_1_000_000
Expand All @@ -49,15 +49,15 @@ describe('@IHRC-906 Facade @CryptoAllowance Test Suite', function () {

// @notice: skipping until mirror-node fully enables HIP906
xit('should execute hbarAllowance() by an EOA to retrieve allowance granted to a spender', async () => {
const approveTx = await walletIHRC906Facade.hbarApprove(
const approveTx = await walletIHRC906AccountFacade.hbarApprove(
walletC.address,
amount,
Constants.GAS_LIMIT_1_000_000
);
await approveTx.wait();

// @notice: staticCall() method gets the return values instead of transaction information
const result = await walletIHRC906Facade.hbarAllowance.staticCall(
const result = await walletIHRC906AccountFacade.hbarAllowance.staticCall(
walletC.address,
Constants.GAS_LIMIT_1_000_000
);
Expand Down

0 comments on commit 2ef3170

Please sign in to comment.