Skip to content

Commit

Permalink
chore: fix contracts
Browse files Browse the repository at this point in the history
Signed-off-by: nikolay <n.atanasow94@gmail.com>
  • Loading branch information
natanasow committed Dec 18, 2024
1 parent cf025fd commit 5ee7083
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 15 deletions.
2 changes: 2 additions & 0 deletions tools/layer-zero-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ npx hardhat set-peer --source <bsc_oft_address> --target <hedera_oft_address> --

fill the .env

npx hardhat test --grep "OFTHTSTests @hedera @approve" --network hedera_testnet

npx hardhat test --grep "OFTHTSTests @hedera @send" --network hedera_testnet
npx hardhat test --grep "OFTHTSTests @bsc @send" --network bsc_testnet

Expand Down
2 changes: 1 addition & 1 deletion tools/layer-zero-example/contracts/BaseHTSOFT.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.20;

Expand Down
2 changes: 1 addition & 1 deletion tools/layer-zero-example/contracts/ERC20Mock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.22;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
Expand Down
2 changes: 1 addition & 1 deletion tools/layer-zero-example/contracts/ERC721Mock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.22;

import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
Expand Down
2 changes: 1 addition & 1 deletion tools/layer-zero-example/contracts/ExampleOApp.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.22;

import {OApp, Origin, MessagingFee} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OApp.sol";
Expand Down
2 changes: 1 addition & 1 deletion tools/layer-zero-example/contracts/ExampleOFT.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.22;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
Expand Down
2 changes: 1 addition & 1 deletion tools/layer-zero-example/contracts/ExampleOFTAdapter.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.22;

import {OFTAdapter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/OFTAdapter.sol";
Expand Down
14 changes: 7 additions & 7 deletions tools/layer-zero-example/contracts/ExampleOFTHTS.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
Expand Down Expand Up @@ -34,14 +34,17 @@ contract ExampleOFTHTS is Ownable, KeyHelper, ExpiryHelper, HederaTokenService,

IHederaTokenService.Expiry memory expiry = IHederaTokenService.Expiry(0, address(this), 8000000);
IHederaTokenService.HederaToken memory token = IHederaTokenService.HederaToken(
_name, _symbol, address(this), "memo", true, 1000, false, keys, expiry
_name, _symbol, address(this), "memo", true, 5000, false, keys, expiry
);

(int responseCode, address tokenAddress) = HederaTokenService.createFungibleToken(
token, 1000, int32(int256(uint256(8)))
);
require(responseCode == HederaResponseCodes.SUCCESS, "Failed to create HTS token");

int256 transferResponse = HederaTokenService.transferToken(tokenAddress, address(this), msg.sender, 1000);
require(transferResponse == HederaResponseCodes.SUCCESS, "HTS: Transfer failed");

htsTokenAddress = tokenAddress;

emit CreatedToken(tokenAddress);
Expand All @@ -64,11 +67,8 @@ contract ExampleOFTHTS is Ownable, KeyHelper, ExpiryHelper, HederaTokenService,
) internal virtual override returns (uint256 amountSentLD, uint256 amountReceivedLD) {
(amountSentLD, amountReceivedLD) = _debitView(_amountLD, _minAmountLD, _dstEid);

address spender = _msgSender();
if (_from != spender) {
int256 response = HederaTokenService.approve(htsTokenAddress, spender, amountSentLD);
require(response == HederaResponseCodes.SUCCESS, "HTS: Approve failed");
}
int256 transferResponse = HederaTokenService.transferToken(htsTokenAddress, _from, address(this), int64(uint64(_amountLD)));
require(transferResponse == HederaResponseCodes.SUCCESS, "HTS: Transfer failed");

(int256 response,) = HederaTokenService.burnToken(htsTokenAddress, int64(uint64(amountSentLD)), new int64[](0));
require(response == HederaResponseCodes.SUCCESS, "HTS: Burn failed");
Expand Down
2 changes: 1 addition & 1 deletion tools/layer-zero-example/contracts/ExampleONFT.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.22;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
Expand Down
2 changes: 1 addition & 1 deletion tools/layer-zero-example/contracts/ExampleONFTAdapter.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.22;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
Expand Down
15 changes: 15 additions & 0 deletions tools/layer-zero-example/test/oftHtsTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ const receiverAddress = '0xF51c7a9407217911d74e91642dbC58F18E51Deac';
const amount = '100';

describe('OFTHTSTests', function() {
it('@hedera @approve oft hts contract', async() => {
const oftHts = await ethers.getContractAt('ExampleOFTHTS', process.env.OFT_HTS_HEDERA_CONTRACT);
const tokenAddress = await oftHts.htsTokenAddress();

const contract = await ethers.getContractAt('ERC20', tokenAddress);
const txApprove = await contract.approve(process.env.OFT_HTS_HEDERA_CONTRACT, amount)
const receipt = await txApprove.wait();

expect(receipt.status).to.equal(1);
});

it('@hedera @send to bsc', async () => {
const signers = await ethers.getSigners();

Expand Down Expand Up @@ -92,7 +103,9 @@ describe('OFTHTSTests', function() {
const contract = await ethers.getContractAt('ERC20', tokenAddress);
const receiverBalance = await contract.balanceOf(receiverAddress);

console.log(`(${hre.network.name}) oft contract balance: ${await contract.balanceOf(process.env.OFT_HTS_HEDERA_CONTRACT)}`);
console.log(`(${hre.network.name}) signer balance: ${await contract.balanceOf(signers[0].address)}`);
console.log(`(${hre.network.name}) total supply: ${await contract.totalSupply()}`);
console.log(`(${hre.network.name}) receiver balance: ${receiverBalance}`);

expect(receiverBalance).to.equal(amount);
Expand All @@ -104,7 +117,9 @@ describe('OFTHTSTests', function() {
const contract = await ethers.getContractAt('ERC20', process.env.OFT_HTS_BSC_CONTRACT);
const receiverBalance = await contract.balanceOf(receiverAddress);

console.log(`(${hre.network.name}) oft contract balance: ${await contract.balanceOf(process.env.OFT_HTS_BSC_CONTRACT)}`);
console.log(`(${hre.network.name}) signer balance: ${await contract.balanceOf(signers[0].address)}`);
console.log(`(${hre.network.name}) total supply: ${await contract.totalSupply()}`);
console.log(`(${hre.network.name}) receiver balance: ${receiverBalance}`);

expect(receiverBalance).to.equal(amount);
Expand Down

0 comments on commit 5ee7083

Please sign in to comment.