From 0baa9b15d9ed6c1b6689fe3f5a23aa6026f75f43 Mon Sep 17 00:00:00 2001 From: Richard Watts Date: Thu, 25 Jul 2024 21:08:05 +0100 Subject: [PATCH] (fix) The chain gateway address was hardwired in the deployment script, so we were using the wrong one (or at least, being confused about which one was in use). Need to align everything, but this makes the bridge txn succeed --- bridge-web/src/App.tsx | 5 +- bridge-web/src/abi/ZilTokenManager.ts | 718 ++++++++++++++++++ bridge-web/src/config/config.ts | 16 +- docs/zilbridge.md | 2 + ...leaseOrNativeTokenManagerUpgradeableV3.sol | 13 +- smart-contracts/script/testnet_config.s.sol | 15 +- .../deployNativeTokenManagerV3.s.sol | 7 +- .../setChainGatewayOnTokenManager.s.sol | 10 +- .../script/zq-testnet/zilBridgeDebug.s.sol | 65 +- 9 files changed, 801 insertions(+), 50 deletions(-) create mode 100644 bridge-web/src/abi/ZilTokenManager.ts diff --git a/bridge-web/src/App.tsx b/bridge-web/src/App.tsx index 8da1fda..f8257c6 100644 --- a/bridge-web/src/App.tsx +++ b/bridge-web/src/App.tsx @@ -21,6 +21,7 @@ import { import { formatEther, formatUnits, getAbiItem, parseUnits } from "viem"; import { Id, toast } from "react-toastify"; import { tokenManagerAbi } from "./abi/TokenManager"; +import { ZilTokenManagerAbi } from "./abi/ZilTokenManager"; import Navbar from "./components/Navbar"; import useRecipientInput from "./hooks/useRecipientInput"; import RecipientInput from "./components/RecipientInput"; @@ -183,7 +184,7 @@ function App() { mode: "prepared", request: { address: token.tokenManagerAddress, - abi: tokenManagerAbi, + abi: ZilTokenManagerAbi, args: [ addressForTokenManager, BigInt(toChainConfig.chainId), @@ -194,7 +195,7 @@ function App() { account: account!, value: transferAmount ?? 0n, functionName: "transfer", - gas: 600_000n, + gas: 6_000_000n, type: "legacy", }, }); diff --git a/bridge-web/src/abi/ZilTokenManager.ts b/bridge-web/src/abi/ZilTokenManager.ts new file mode 100644 index 0000000..4b0bd1f --- /dev/null +++ b/bridge-web/src/abi/ZilTokenManager.ts @@ -0,0 +1,718 @@ +export const ZilTokenManagerAbi = [ + { + "type": "constructor", + "inputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "receive", + "stateMutability": "payable" + }, + { + "type": "function", + "name": "NATIVE_ASSET_HASH", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "UPGRADE_INTERFACE_VERSION", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "string", + "internalType": "string" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "accept", + "inputs": [ + { + "name": "metadata", + "type": "tuple", + "internalType": "struct CallMetadata", + "components": [ + { + "name": "sourceChainId", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "sender", + "type": "address", + "internalType": "address" + } + ] + }, + { + "name": "_args", + "type": "bytes", + "internalType": "bytes" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "acceptOwnership", + "inputs": [], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "getFees", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getGateway", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "getRemoteTokens", + "inputs": [ + { + "name": "token", + "type": "address", + "internalType": "address" + }, + { + "name": "remoteChainId", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "tuple", + "internalType": "struct ITokenManagerStructs.RemoteToken", + "components": [ + { + "name": "token", + "type": "address", + "internalType": "address" + }, + { + "name": "tokenManager", + "type": "address", + "internalType": "address" + }, + { + "name": "chainId", + "type": "uint256", + "internalType": "uint256" + } + ] + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "owner", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "pause", + "inputs": [], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "paused", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "bool", + "internalType": "bool" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "pendingOwner", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "proxiableUUID", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "bytes32", + "internalType": "bytes32" + } + ], + "stateMutability": "view" + }, + { + "type": "function", + "name": "registerToken", + "inputs": [ + { + "name": "token", + "type": "address", + "internalType": "address" + }, + { + "name": "remoteToken", + "type": "tuple", + "internalType": "struct ITokenManagerStructs.RemoteToken", + "components": [ + { + "name": "token", + "type": "address", + "internalType": "address" + }, + { + "name": "tokenManager", + "type": "address", + "internalType": "address" + }, + { + "name": "chainId", + "type": "uint256", + "internalType": "uint256" + } + ] + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "renounceOwnership", + "inputs": [], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setFees", + "inputs": [ + { + "name": "newFees", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "setGateway", + "inputs": [ + { + "name": "_gateway", + "type": "address", + "internalType": "address" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "transfer", + "inputs": [ + { + "name": "token", + "type": "address", + "internalType": "address" + }, + { + "name": "remoteChainId", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "remoteRecipient", + "type": "address", + "internalType": "address" + }, + { + "name": "amount", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [], + "stateMutability": "payable" + }, + { + "type": "function", + "name": "transferOwnership", + "inputs": [ + { + "name": "newOwner", + "type": "address", + "internalType": "address" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "unpause", + "inputs": [], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "upgradeToAndCall", + "inputs": [ + { + "name": "newImplementation", + "type": "address", + "internalType": "address" + }, + { + "name": "data", + "type": "bytes", + "internalType": "bytes" + } + ], + "outputs": [], + "stateMutability": "payable" + }, + { + "type": "function", + "name": "withdrawFees", + "inputs": [ + { + "name": "to", + "type": "address", + "internalType": "address payable" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, + { + "type": "function", + "name": "xtransfer", + "inputs": [ + { + "name": "token", + "type": "address", + "internalType": "address" + }, + { + "name": "remoteChainId", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "remoteRecipient", + "type": "address", + "internalType": "address" + }, + { + "name": "amount", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [], + "stateMutability": "payable" + }, + { + "type": "event", + "name": "FeesUpdated", + "inputs": [ + { + "name": "feesBefore", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + }, + { + "name": "feesAfter", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "FeesWithdrawn", + "inputs": [ + { + "name": "amount", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Initialized", + "inputs": [ + { + "name": "version", + "type": "uint64", + "indexed": false, + "internalType": "uint64" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Locked", + "inputs": [ + { + "name": "token", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "from", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "amount", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "OwnershipTransferStarted", + "inputs": [ + { + "name": "previousOwner", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "newOwner", + "type": "address", + "indexed": true, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "OwnershipTransferred", + "inputs": [ + { + "name": "previousOwner", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "newOwner", + "type": "address", + "indexed": true, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Paused", + "inputs": [ + { + "name": "account", + "type": "address", + "indexed": false, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Released", + "inputs": [ + { + "name": "token", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "recipient", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "amount", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "TokenRegistered", + "inputs": [ + { + "name": "token", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "remoteToken", + "type": "address", + "indexed": false, + "internalType": "address" + }, + { + "name": "remoteTokenManager", + "type": "address", + "indexed": false, + "internalType": "address" + }, + { + "name": "remoteChainId", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "TokenRemoved", + "inputs": [ + { + "name": "token", + "type": "address", + "indexed": false, + "internalType": "address" + }, + { + "name": "remoteChainId", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Unpaused", + "inputs": [ + { + "name": "account", + "type": "address", + "indexed": false, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "Upgraded", + "inputs": [ + { + "name": "implementation", + "type": "address", + "indexed": true, + "internalType": "address" + } + ], + "anonymous": false + }, + { + "type": "error", + "name": "AddressEmptyCode", + "inputs": [ + { + "name": "target", + "type": "address", + "internalType": "address" + } + ] + }, + { + "type": "error", + "name": "ERC1967InvalidImplementation", + "inputs": [ + { + "name": "implementation", + "type": "address", + "internalType": "address" + } + ] + }, + { + "type": "error", + "name": "ERC1967NonPayable", + "inputs": [] + }, + { + "type": "error", + "name": "EnforcedPause", + "inputs": [] + }, + { + "type": "error", + "name": "ExpectedPause", + "inputs": [] + }, + { + "type": "error", + "name": "FailedInnerCall", + "inputs": [] + }, + { + "type": "error", + "name": "InsufficientFees", + "inputs": [ + { + "name": "received", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "expected", + "type": "uint256", + "internalType": "uint256" + } + ] + }, + { + "type": "error", + "name": "InvalidInitialization", + "inputs": [] + }, + { + "type": "error", + "name": "InvalidSourceChainId", + "inputs": [] + }, + { + "type": "error", + "name": "InvalidTokenManager", + "inputs": [] + }, + { + "type": "error", + "name": "NotGateway", + "inputs": [] + }, + { + "type": "error", + "name": "NotInitializing", + "inputs": [] + }, + { + "type": "error", + "name": "OwnableInvalidOwner", + "inputs": [ + { + "name": "owner", + "type": "address", + "internalType": "address" + } + ] + }, + { + "type": "error", + "name": "OwnableUnauthorizedAccount", + "inputs": [ + { + "name": "account", + "type": "address", + "internalType": "address" + } + ] + }, + { + "type": "error", + "name": "UUPSUnauthorizedCallContext", + "inputs": [] + }, + { + "type": "error", + "name": "UUPSUnsupportedProxiableUUID", + "inputs": [ + { + "name": "slot", + "type": "bytes32", + "internalType": "bytes32" + } + ] + } +]; diff --git a/bridge-web/src/config/config.ts b/bridge-web/src/config/config.ts index 230dbfc..b6e9f35 100644 --- a/bridge-web/src/config/config.ts +++ b/bridge-web/src/config/config.ts @@ -102,28 +102,28 @@ export const chainConfigs: Partial> = tokens: [ { name: "xTST", - address: "0x8CB156B19947283F9700e5891ed6d013454b0570", + address: "0x2aDFdb71103b8587F609b262b3E7E6161D3f6B1f", blockExplorer: "https://otterscan.testnet.zilliqa.com/address/0x8CB156B19947283F9700e5891ed6d013454b0570", logo: fps_token, - tokenManagerAddress: "0xBe90AB2cd65E207F097bEF733F8D239A59698b8A", + tokenManagerAddress: "0x5e502559ab6e99949b0eE72d4ebCe05f31E026dC", tokenManagerType: TokenManagerType.ZilBridge, }, { name: "ZBTST", - address: "0x2A82a13A118c0f9E203a9C006742024354D0f4Ca", + address: "0xCf795CF70C29588fb6885CB8982EAE04354e1BB4", blockExplorer: "https://otterscan.testnet.zilliqa.com/address/0x2A82a13A118c0f9E203a9C006742024354D0f4Ca", - logo: test_hrse_token, - tokenManagerAddress: "0x86c4405C2e3914490BC043A19dA5373D6d187aa7", + logo: test_hrse_token, + tokenManagerAddress: "0x5e502559ab6e99949b0eE72d4ebCe05f31E026dC", tokenManagerType: TokenManagerType.ZilBridge, }, { name: "zBNB", - address: "0xe99aCb73ca54766013A253d040021f392302159E", + address: "0x9707F1C6A02c5D8682669d309c046c5Af6c3130e", blockExplorer: "https://otterscan.testnet.zilliqa.com/address/0xe99aCb73ca54766013A253d040021f392302159E", logo: fps_token, - tokenManagerAddress: "0xBe90AB2cd65E207F097bEF733F8D239A59698b8A", + tokenManagerAddress: "0x5e502559ab6e99949b0eE72d4ebCe05f31E026dC", tokenManagerType: TokenManagerType.ZilBridge }, { @@ -131,7 +131,7 @@ export const chainConfigs: Partial> = address: "0x", blockExplorer: null, logo: fps_token, - tokenManagerAddress: "0xBe90AB2cd65E207F097bEF733F8D239A59698b8A", + tokenManagerAddress: "0x5e502559ab6e99949b0eE72d4ebCe05f31E026dC", tokenManagerType: TokenManagerType.ZilBridge }, ], diff --git a/docs/zilbridge.md b/docs/zilbridge.md index de8f5dc..f67e96e 100644 --- a/docs/zilbridge.md +++ b/docs/zilbridge.md @@ -211,6 +211,8 @@ Since Zilliqa testnet doesn't support tracing, this is done by bisection. You on ``` forge script script/zq-testnet/deployNativeTokenManagerV3.s.sol --rpc-url https://dev-api.zilliqa.com --broadcast --legacy + +forge script script/zq-testnet/setChainGatewayOnTokenManager.s.sol --rpc-url https://dev-api.zilliqa.com --broadcast --legacy forge verify-contract
--rpc-url https://dev-api.zilliqa.com --chain-id 33101 ``` diff --git a/smart-contracts/contracts/periphery/TokenManagerV3/LockAndReleaseOrNativeTokenManagerUpgradeableV3.sol b/smart-contracts/contracts/periphery/TokenManagerV3/LockAndReleaseOrNativeTokenManagerUpgradeableV3.sol index a618dd5..a17ede0 100644 --- a/smart-contracts/contracts/periphery/TokenManagerV3/LockAndReleaseOrNativeTokenManagerUpgradeableV3.sol +++ b/smart-contracts/contracts/periphery/TokenManagerV3/LockAndReleaseOrNativeTokenManagerUpgradeableV3.sol @@ -58,11 +58,18 @@ contract LockAndReleaseOrNativeTokenManagerUpgradeableV3 is emit Released(token, recipient, amount); } - function xtransfer(address token, uint remoteChainId, address remoteRecipient, uint amount) public { + function xtransfer( + address token, + uint remoteChainId, + address remoteRecipient, + uint amount + ) external payable virtual whenNotPaused checkFees { RemoteToken memory remoteToken = getRemoteTokens(token, remoteChainId); - _handleTransfer(token, msg.sender, amount); + // Works here. + _handleTransfer(token, _msgSender(), amount); + // Works here. IRelayer(getGateway()).relayWithMetadata( remoteToken.chainId, remoteToken.tokenManager, @@ -70,6 +77,6 @@ contract LockAndReleaseOrNativeTokenManagerUpgradeableV3 is abi.encode(AcceptArgs(remoteToken.token, remoteRecipient, amount)), 1_000_000 ); - + // Fails here. } } diff --git a/smart-contracts/script/testnet_config.s.sol b/smart-contracts/script/testnet_config.s.sol index a367ff7..3439914 100644 --- a/smart-contracts/script/testnet_config.s.sol +++ b/smart-contracts/script/testnet_config.s.sol @@ -15,7 +15,8 @@ abstract contract TestnetConfig { /// Deployed by XBridge testnet deployment address public constant bsc_chainGateway = 0xa9A14C90e53EdCD89dFd201A3bF94D867f8098fE; address public constant zq_chainGateway = 0x7370e69565BB2313C4dA12F9062C282513919230; - address public constant zq_lockAndReleaseOrNativeTokenManager = 0x86c4405C2e3914490BC043A19dA5373D6d187aa7; + address public constant zq_lockAndReleaseTokenManager = 0x1509988c41f02014aA59d455c6a0D67b5b50f129; + address public constant zq_lockAndReleaseOrNativeTokenManager = 0x5e502559ab6e99949b0eE72d4ebCe05f31E026dC; // BSC zilbridge tokens. address public constant bsc_erc20 = 0xa1a47FA4D26137329BB08aC2E5F9a6C32D180fE3; @@ -23,12 +24,12 @@ abstract contract TestnetConfig { address public constant bsc_bridgedzil = 0xfA3cF3BBa7f0fA1E8FECeE532512434A7d275d41; // Scilla contracts. - address public constant zq_bridged_erc20 = address(0x00c8704B0196FE5a15E33B2a328Dae1d4275Bb5A6F); - address public constant zq_bridged_bnb = address(0x0067e5375cd3B2738A591050589452B8189dc470eF); - address public constant zq_zrc2 = address(0x00d5eD1175af29C49237BB82663Ea2e7Fa2eaa9EDb); + address public constant zq_bridged_erc20 = address(0x00f281D459E5FdA75f12eEca2D33E3aa03f6456994); + address public constant zq_bridged_bnb = address(0x00976050703b8067ab25a56A22e24e404222B07a33); + address public constant zq_zrc2 = address(0x00f1c2F2dadC13d03939c52d7A763dAF188f431AD6); // ERC20 fascias for Scilla contracts - address public constant zq_bridged_erc20_evm = address(0x8CB156B19947283F9700e5891ed6d013454b0570); - address public constant zq_bridged_bnb_evm = address(0xe99aCb73ca54766013A253d040021f392302159E); - address public constant zq_zrc2_evm = address(0x2A82a13A118c0f9E203a9C006742024354D0f4Ca); + address public constant zq_bridged_erc20_evm = address(0x2aDFdb71103b8587F609b262b3E7E6161D3f6B1f); + address public constant zq_bridged_bnb_evm = address(0x9707F1C6A02c5D8682669d309c046c5Af6c3130e); + address public constant zq_zrc2_evm = address(0xCf795CF70C29588fb6885CB8982EAE04354e1BB4); } diff --git a/smart-contracts/script/zq-testnet/deployNativeTokenManagerV3.s.sol b/smart-contracts/script/zq-testnet/deployNativeTokenManagerV3.s.sol index 550e454..f61d346 100644 --- a/smart-contracts/script/zq-testnet/deployNativeTokenManagerV3.s.sol +++ b/smart-contracts/script/zq-testnet/deployNativeTokenManagerV3.s.sol @@ -7,18 +7,19 @@ import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.s import {ChainGateway} from "contracts/core/ChainGateway.sol"; import {LockAndReleaseOrNativeTokenManagerDeployer} from "test/periphery/TokenManagerDeployers/LockAndReleaseOrNativeTokenManagerDeployer.sol"; import "forge-std/console.sol"; +import "script/testnet_config.s.sol"; -contract Deployment is Script, LockAndReleaseOrNativeTokenManagerDeployer { +contract Deployment is Script, LockAndReleaseOrNativeTokenManagerDeployer,TestnetConfig { function run() external { uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY_TESTNET"); - address chainGatewayAddress = 0x10917A34FE60eE8364a401a6b1d3adaf80D84eb6; + address chainGatewayAddress = zq_chainGateway; uint fees = 60 ether; // 60 ZIL vm.startBroadcast(deployerPrivateKey); LockAndReleaseOrNativeTokenManagerUpgradeableV3 tokenManager = deployLatestLockAndReleaseOrNativeTokenManager(chainGatewayAddress, fees); console.log( - "LockAndReleaseTokenManager Proxy deployed to %s, with owner %s and gateway %s", + "LockAndReleaseOrNativeTokenManager Proxy deployed to %s, with owner %s and gateway %s", address(tokenManager), tokenManager.owner(), tokenManager.getGateway() diff --git a/smart-contracts/script/zq-testnet/setChainGatewayOnTokenManager.s.sol b/smart-contracts/script/zq-testnet/setChainGatewayOnTokenManager.s.sol index 5cf0a4d..2901228 100644 --- a/smart-contracts/script/zq-testnet/setChainGatewayOnTokenManager.s.sol +++ b/smart-contracts/script/zq-testnet/setChainGatewayOnTokenManager.s.sol @@ -4,18 +4,18 @@ pragma solidity ^0.8.20; import {Script} from "forge-std/Script.sol"; import {LockAndReleaseTokenManagerUpgradeableV3} from "contracts/periphery/TokenManagerV3/LockAndReleaseTokenManagerUpgradeableV3.sol"; import {LockAndReleaseOrNativeTokenManagerUpgradeableV3} from "contracts/periphery/TokenManagerV3/LockAndReleaseOrNativeTokenManagerUpgradeableV3.sol"; - +import "script/testnet_config.s.sol"; import "forge-std/console.sol"; -contract Update is Script { +contract Update is TestnetConfig,Script { function run() external { uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY_TESTNET"); address owner = vm.addr(deployerPrivateKey); console.log("Deployer is %s", owner); - address newChainGateway = 0x7370e69565BB2313C4dA12F9062C282513919230; // UPDATE; - address tokenManagerAddress = 0x1509988c41f02014aA59d455c6a0D67b5b50f129; - address nativeTokenManagerAddress = 0xBe90AB2cd65E207F097bEF733F8D239A59698b8A; + address newChainGateway = zq_chainGateway; + address tokenManagerAddress = zq_lockAndReleaseTokenManager; + address nativeTokenManagerAddress = zq_lockAndReleaseOrNativeTokenManager; vm.startBroadcast(deployerPrivateKey); LockAndReleaseTokenManagerUpgradeableV3 tokenManager = LockAndReleaseTokenManagerUpgradeableV3( diff --git a/smart-contracts/script/zq-testnet/zilBridgeDebug.s.sol b/smart-contracts/script/zq-testnet/zilBridgeDebug.s.sol index 27c5b5f..11bd4ea 100644 --- a/smart-contracts/script/zq-testnet/zilBridgeDebug.s.sol +++ b/smart-contracts/script/zq-testnet/zilBridgeDebug.s.sol @@ -8,39 +8,60 @@ import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import {ZRC2ProxyForZRC2} from "test/zilbridge/zrc2erc20/ZRC2ProxyForZRC2.sol"; import "forge-std/console.sol"; import "script/testnet_config.s.sol"; +import {IERC20} from "contracts/periphery/LockAndReleaseTokenManagerUpgradeable.sol"; +import {IRelayer, Relayer, CallMetadata} from "contracts/core/Relayer.sol"; +import {Registry} from "contracts/core/Registry.sol"; +import {ChainGateway} from "contracts/core/ChainGateway.sol"; contract Deployment is Script, TestnetConfig { function run() external { - uint256 validatorPrivateKey = vm.envUint("PRIVATE_KEY_ZILBRIDGE"); + // uint256 validatorPrivateKey = vm.envUint("PRIVATE_KEY_ZILBRIDGE"); + uint256 validatorPrivateKey = vm.envUint("PRIVATE_KEY_TESTNET"); + address validator = vm.addr(validatorPrivateKey); vm.startBroadcast(validatorPrivateKey); console.log("I am %s", validator); console.log("Token manager at %s", zq_lockAndReleaseOrNativeTokenManager); - ITokenManager tok = ITokenManager(zq_lockAndReleaseOrNativeTokenManager); - ITokenManagerStructs.RemoteToken memory rt = tok.getRemoteTokens(0x2A82a13A118c0f9E203a9C006742024354D0f4Ca, 97); - console.log("remoteToken = %s / mgr %s / chainId %d", rt.token, rt.tokenManager, rt.chainId); - // Now find out what our balance of local tokens is.. - ERC20 nativeToken = ERC20(zq_zrc2_evm); - ZRC2ProxyForZRC2 proxy = ZRC2ProxyForZRC2(zq_zrc2_evm); - uint256 bal = nativeToken.balanceOf(validator); - console.log("my balance of %s is %d", zq_zrc2_evm, bal); - console.log("for %s", validator); - uint256 bal2 = proxy.balanceOf(address(0x003ceb00d128fc46adda183aa9e4dd832af2b3dfe3)); - console.log("or %d", bal2); - console.log("%s proxies .. ", zq_zrc2_evm); - console.log(" ... to zrc2 %s", proxy.zrc2_proxy()); - console.log(" ... decimals %d", proxy.decimals()); - console.log(" ... symbol %s", proxy.symbol()); + console.log("ChainGateway %s", zq_chainGateway); + ChainGateway chainGateway = ChainGateway(zq_chainGateway); + chainGateway.register(address(zq_lockAndReleaseOrNativeTokenManager)); + console.log( + "TokenManager %s registered to %s ChainGateway: %s", + address(zq_lockAndReleaseOrNativeTokenManager), + address(chainGateway), + chainGateway.registered(address(zq_lockAndReleaseOrNativeTokenManager)) + ); + + Relayer relayer = Relayer(zq_chainGateway); + bool amRegistered = relayer.registered(zq_lockAndReleaseOrNativeTokenManager); + console.log("isRegistered %d", amRegistered); + + + /* ITokenManager tok = ITokenManager(zq_lockAndReleaseOrNativeTokenManager); */ + /* ITokenManagerStructs.RemoteToken memory rt = tok.getRemoteTokens(0x2A82a13A118c0f9E203a9C006742024354D0f4Ca, 97); */ + /* console.log("remoteToken = %s / mgr %s / chainId %d", rt.token, rt.tokenManager, rt.chainId); */ + /* // Now find out what our balance of local tokens is.. */ + /* ERC20 nativeToken = ERC20(zq_zrc2_evm); */ + /* ZRC2ProxyForZRC2 proxy = ZRC2ProxyForZRC2(zq_zrc2_evm); */ + /* uint256 bal = nativeToken.balanceOf(validator); */ + /* console.log("my balance of %s is %d", zq_zrc2_evm, bal); */ + /* console.log("for %s", validator); */ + /* uint256 bal2 = proxy.balanceOf(address(0x003ceb00d128fc46adda183aa9e4dd832af2b3dfe3)); */ + /* console.log("or %d", bal2); */ + /* console.log("%s proxies .. ", zq_zrc2_evm); */ + /* console.log(" ... to zrc2 %s", proxy.zrc2_proxy()); */ + /* console.log(" ... decimals %d", proxy.decimals()); */ + /* console.log(" ... symbol %s", proxy.symbol()); */ // Fails, so... //console.log("Transfer .. "); //nativeToken.transfer(address(0x00b85ff091342e2e7a7461238796d5224fa81ca556), 1); - console.log("Deploying proxy for %s",address(zq_zrc2)); - ZRC2ProxyForZRC2 proxy2 = new ZRC2ProxyForZRC2(zq_zrc2); - console.log("new ZRC2 proxy %s", address(proxy2)); - vm.stopBroadcast(); - uint256 bal3 = proxy2.balanceOf(validator); - console.log("proxy2 balance %d", bal3); + /* console.log("Deploying proxy for %s",address(zq_zrc2)); */ + /* ZRC2ProxyForZRC2 proxy2 = new ZRC2ProxyForZRC2(zq_zrc2); */ + /* console.log("new ZRC2 proxy %s", address(proxy2)); */ + /* vm.stopBroadcast(); */ + /* uint256 bal3 = proxy2.balanceOf(validator); */ + /* console.log("proxy2 balance %d", bal3); */ }