Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Nov 15, 2024
1 parent 1d72aee commit 5b6234f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 34 deletions.
10 changes: 0 additions & 10 deletions examples/call/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2775,16 +2775,6 @@
"@zetachain/networks" "^10.0.0"
ethers "5.6.8"

"@zetachain/[email protected]":
version "10.0.0-rc11"
resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-10.0.0-rc11.tgz#53f55ead492f7b5802b1feae4e51abc75730af33"
integrity sha512-qWazjqnIGRngf4OmyeSIv7sHICQRdMQ1CKPIQIqxA8qFR+gHhDHSfvMdRAvgWbsfkimXOIFiHVIATypyWhviJw==
dependencies:
"@openzeppelin/contracts" "^5.0.2"
"@openzeppelin/contracts-upgradeable" "^5.0.2"
"@zetachain/networks" "^10.0.0"
ethers "^6.13.1"

"@zetachain/[email protected]":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-9.0.0.tgz#c20ad5da43f6f3676f31556b303d1cb4ea17357e"
Expand Down
9 changes: 6 additions & 3 deletions examples/nft/contracts/Connected.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ contract Connected is
}

function safeMint(address to, string memory uri) public onlyOwner {
if (to == address(0)) revert InvalidAddress();
uint256 hash = uint256(
keccak256(
abi.encodePacked(address(this), block.number, _nextTokenId++)
)
);

uint256 tokenId = _nextTokenId++;
uint256 tokenId = hash & 0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;

_safeMint(to, tokenId);
_setTokenURI(tokenId, uri);
Expand All @@ -74,7 +78,6 @@ contract Connected is
message,
0
);

if (destination == address(0)) {
gateway.call(counterparty, message, revertOptions);
} else {
Expand Down
17 changes: 9 additions & 8 deletions examples/nft/contracts/Universal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ contract Universal is
Events
{
GatewayZEVM public immutable gateway;
SystemContract public immutable systemContract =
SystemContract(0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9);
SystemContract public immutable systemContract;
uint256 private _nextTokenId;
bool public isUniversal = true;
uint256 public gasLimit;
Expand All @@ -46,12 +45,17 @@ contract Universal is
address owner,
string memory name,
string memory symbol,
uint256 gas
uint256 gas,
address systemContractAddress
) ERC721(name, symbol) Ownable(owner) {
if (gatewayAddress == address(0) || owner == address(0))
revert InvalidAddress();
if (
gatewayAddress == address(0) ||
owner == address(0) ||
systemContractAddress == address(0)
) revert InvalidAddress();
if (gas == 0) revert InvalidGasLimit();
gateway = GatewayZEVM(gatewayAddress);
systemContract = SystemContract(systemContractAddress);
gasLimit = gas;
}

Expand Down Expand Up @@ -115,15 +119,12 @@ contract Universal is
_setTokenURI(tokenId, uri);
}

event Foo(address);

function onCall(
MessageContext calldata context,
address zrc20,
uint256 amount,
bytes calldata message
) external override onlyGateway {
emit Foo(context.sender);
if (context.sender != counterparty[zrc20]) revert("Unauthorized");

(
Expand Down
21 changes: 21 additions & 0 deletions examples/nft/scripts/testnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -e
set -x

npx hardhat compile --force --quiet

UNIVERSAL=$(npx hardhat deploy --name Universal --network zeta_testnet --gateway 0x6c533f7fe93fae114d0954697069df33c9b74fd7 --system-contract 0xEdf1c3275d13489aCdC6cD6eD246E72458B8795B --gas-limit 500000 --json | jq -r '.contractAddress')
CONNECTED_BASE=$(npx hardhat deploy --name Connected --network base_sepolia --gateway 0x0c487a766110c85d301d96e33579c5b317fa4995 --json | jq -r '.contractAddress')
CONNECTED_BNB=$(npx hardhat deploy --name Connected --network bsc_testnet --gateway 0x0c487a766110c85d301d96e33579c5b317fa4995 --json | jq -r '.contractAddress')

ZRC20_BASE=0x236b0DE675cC8F46AE186897fCCeFe3370C9eDeD
ZRC20_BNB=0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891

npx hardhat connected-set-counterparty --network base_sepolia --contract "$CONNECTED_BASE" --counterparty "$UNIVERSAL" --json

npx hardhat connected-set-counterparty --network bsc_testnet --contract "$CONNECTED_BNB" --counterparty "$UNIVERSAL" --json

npx hardhat universal-set-counterparty --network zeta_testnet --contract "$UNIVERSAL" --counterparty "$CONNECTED_BASE" --zrc20 "$ZRC20_BASE" --json

npx hardhat universal-set-counterparty --network zeta_testnet --contract "$UNIVERSAL" --counterparty "$CONNECTED_BNB" --zrc20 "$ZRC20_BNB" --json
8 changes: 6 additions & 2 deletions examples/nft/tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
}

const factory: any = await hre.ethers.getContractFactory(args.name);

const contract = await factory.deploy(
args.gateway,
signer.address,
args.nftName,
args.nftSymbol,
...(args.gasLimit ? [args.gasLimit] : [])
...(args.gasLimit ? [args.gasLimit] : []),
...(args.systemContract ? [args.systemContract] : [])
);

await contract.deployed();

if (args.json) {
Expand Down Expand Up @@ -47,4 +50,5 @@ task("deploy", "Deploy the NFT contract", main)
"gateway",
"Gateway address (default: ZetaChain Gateway)",
"0x5FC8d32690cc91D4c39d9d3abcBD16989F875707"
);
)
.addOptionalParam("systemContract", "System contract address");
17 changes: 6 additions & 11 deletions examples/nft/tasks/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const gasAmount = ethers.utils.parseUnits(args.gasAmount, 18);

const receiver = args.receiver || signer.address;

tx = await (contract as any).transferCrossChain(
args.tokenId,
receiver,
args.to,
{ ...txOptions, value: gasAmount }
);
console.log(args.tokenId, receiver, args.to);
tx = await contract.transferCrossChain(args.tokenId, receiver, args.to);

await tx.wait();
if (args.json) {
Expand All @@ -53,10 +48,10 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
);
} else {
console.log(`🚀 Successfully transferred NFT to the contract.
📜 Contract address: ${args.from}
🖼 NFT Contract address: ${args.nftContract}
🆔 Token ID: ${args.tokenId}
🔗 Transaction hash: ${tx.hash}`);
📜 Contract address: ${args.from}
🖼 NFT Contract address: ${args.nftContract}
🆔 Token ID: ${args.tokenId}
🔗 Transaction hash: ${tx.hash}`);
}
};

Expand Down

0 comments on commit 5b6234f

Please sign in to comment.