Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HTS NFTs as if they're deployed ERC721/IERC721Metadata/IERC721Enumerable contracts #82

Merged
merged 26 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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