Skip to content

Commit

Permalink
Use HTS NFTs as if they're deployed ERC721/IERC721Metadata/IERC721Enu…
Browse files Browse the repository at this point in the history
…merable contracts (hashgraph#82)

* Add tests

Signed-off-by: nikolay <[email protected]>

* Install @openzeppelin/contracts

Signed-off-by: nikolay <[email protected]>

* Edit tests

Signed-off-by: nikolay <[email protected]>

* Edit ci

Signed-off-by: nikolay <[email protected]>

* Edit ci

Signed-off-by: nikolay <[email protected]>

* Edit ci

Signed-off-by: nikolay <[email protected]>

* Edit ci

Signed-off-by: nikolay <[email protected]>

* Edit ci

Signed-off-by: nikolay <[email protected]>

* Edit ci

Signed-off-by: nikolay <[email protected]>

* Bump hedera local node version

Signed-off-by: nikolay <[email protected]>

* Edit ci

Signed-off-by: nikolay <[email protected]>

* Fix typos

Signed-off-by: nikolay <[email protected]>

* Edit workflow

Signed-off-by: nikolay <[email protected]>

* Edit ci

Signed-off-by: nikolay <[email protected]>

* Edit ci

Signed-off-by: nikolay <[email protected]>

* Edit ci

Signed-off-by: nikolay <[email protected]>

* Edit ci

Signed-off-by: nikolay <[email protected]>

* Add tmate for debugging

Signed-off-by: nikolay <[email protected]>

* Test ci

Signed-off-by: nikolay <[email protected]>

* Test ci

Signed-off-by: nikolay <[email protected]>

* Test ci

Signed-off-by: nikolay <[email protected]>

* Test ci

Signed-off-by: nikolay <[email protected]>

* Test ci

Signed-off-by: nikolay <[email protected]>

* Test ci

Signed-off-by: nikolay <[email protected]>

* Test ci

Signed-off-by: nikolay <[email protected]>

* Test ci

Signed-off-by: nikolay <[email protected]>

Signed-off-by: nikolay <[email protected]>
  • Loading branch information
natanasow authored and georg-getz committed Dec 12, 2022
1 parent 9044c83 commit efcf967
Show file tree
Hide file tree
Showing 7 changed files with 1,920 additions and 287 deletions.
17 changes: 8 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ jobs:
sudo curl -SL -o /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Linux-x86_64
sudo chmod +x /usr/local/bin/docker-compose
- name: Prepare the local node
run: |
echo 'hedera.recordStream.compressFilesOnCreation=true' >> node_modules/@hashgraph/hedera-local/compose-network/network-node/data/config/bootstrap.properties
echo 'contracts.chainId=298' >> node_modules/@hashgraph/hedera-local/compose-network/network-node/data/config/bootstrap.properties
sed -i 's/ STREAM_EXTENSION: "rcd"/ STREAM_EXTENSION: "rcd.gz"/' node_modules/@hashgraph/hedera-local/docker-compose.yml
- name: Start the local node
run: npx hedera start -d
run: npx hedera start -d --network local

- name: Run tests
run: npx hardhat test
- name: Run the tests
uses: nick-fields/retry@v2
with:
max_attempts: 3
timeout_minutes: 10
retry_wait_seconds: 60
command: npx hardhat test

- name: Stop the local node
run: npx hedera stop
13 changes: 13 additions & 0 deletions contracts/hts-precompile/examples/erc-721/ERC721Contract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ contract ERC721Contract {
return IERC721Enumerable(token).totalSupply();
}

// The `to` address will receive approval by the contract itself
// Be aware that the nft must be owned by the contract, not by the msg.sender address
function approve(address token, address to, uint256 tokenId) external payable {
IERC721(token).approve(to, tokenId);
}

// The `to` address will receive approval by msg.sender
function delegateApprove(address token, address to, uint256 tokenId) external payable {
address(IERC721(token)).delegatecall(abi.encodeWithSignature("approve(address,uint256)", to, tokenId));
}

function setApprovalForAll(address token, address operator, bool approved) external {
IERC721(token).setApprovalForAll(operator, approved);
}
Expand All @@ -47,10 +54,16 @@ contract ERC721Contract {
return IERC721(token).isApprovedForAll(owner, operator);
}

// The call will be executed by the contract itself, so the contract address has to be the owner of `tokenId`
function transferFrom(address token, address from, address to, uint256 tokenId) external payable {
IERC721(token).transferFrom(from, to, tokenId);
}

// The call will be executed by the msg.sender address
function delegateTransferFrom(address token, address from, address to, uint256 tokenId) external payable {
address(IERC721(token)).delegatecall(abi.encodeWithSignature("transferFrom(address,address,uint256)", from, to, tokenId));
}

// Not supported operations - should return a failure

function safeTransferFrom(address token, address from, address to, uint256 tokenId) external payable {
Expand Down
6 changes: 5 additions & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ require("@nomicfoundation/hardhat-chai-matchers");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
mocha: {
timeout: 3600000
},
solidity: {
version: "0.8.9",
settings: {
Expand All @@ -16,7 +19,8 @@ module.exports = {
relay: {
url: 'http://localhost:7546',
accounts: [
"0x2e1d968b041d84dd120a5860cee60cd83f9374ef527ca86996317ada3d0d03e7"
"0x2e1d968b041d84dd120a5860cee60cd83f9374ef527ca86996317ada3d0d03e7",
"0x45a5a7108a18dd5013cf2d5857a28144beadc9c70b3bdbd914e38df4e804b8d8"
],
chainId: 298,
}
Expand Down
Loading

0 comments on commit efcf967

Please sign in to comment.