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

feat: port localnet to v2 #269

Merged
merged 8 commits into from
Jul 29, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ crytic-export

out
cache_forge
broadcast
1 change: 0 additions & 1 deletion v1/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "uniswap-v2-deploy-plugin";
import "solidity-coverage";
import "hardhat-gas-reporter";
import "./tasks/addresses";
import "./tasks/localnet";
import "@openzeppelin/hardhat-upgrades";

import { getHardhatConfigNetworks } from "@zetachain/networks";
Expand Down
5 changes: 1 addition & 4 deletions v1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,9 @@
"lint": "npx eslint . --ext .js,.ts --ignore-pattern lib/",
"lint:fix": "npx eslint . --ext .js,.ts,.json --fix --ignore-pattern coverage/ --ignore-pattern coverage.json --ignore-pattern lib/ --ignore-pattern out --ignore-pattern cache_forge/",
"lint:sol": "solhint 'contracts/**/*.sol'",
"localnet": "concurrently --names \"NODE,WORKER\" --prefix-colors \"blue.bold,green.bold\" \"npx hardhat node\" \"wait-on tcp:8545 && yarn worker\"",
"prepublishOnly": "yarn build",
"test": "npx hardhat test",
"test:prototypes": "yarn compile && npx hardhat test test/prototypes/*",
"tsc:watch": "npx tsc --watch",
"worker": "npx hardhat run scripts/worker.ts --network localhost"
"tsc:watch": "npx tsc --watch"
},
"types": "./dist/lib/index.d.ts",
"version": "0.0.8"
Expand Down
103 changes: 0 additions & 103 deletions v1/tasks/localnet.ts

This file was deleted.

9 changes: 9 additions & 0 deletions v2/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.yarn
artifacts
cache
dist
node_modules
typechain-types
docs
crytic-export
lib
10 changes: 10 additions & 0 deletions v2/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @ts-check

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,

);
106 changes: 0 additions & 106 deletions v2/package-lock.json

This file was deleted.

14 changes: 12 additions & 2 deletions v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@
"test": "test"
},
"scripts": {
"lint": "npx eslint . --ignore-pattern coverage/ --ignore-pattern coverage.json --ignore-pattern lib/ --ignore-pattern out --ignore-pattern cache_forge/",
"lint:fix": "npx eslint . --fix --ignore-pattern coverage/ --ignore-pattern coverage.json --ignore-pattern lib/ --ignore-pattern out --ignore-pattern cache_forge/",
"localnet": "concurrently --names \"NODE,WORKER\" --prefix-colors \"blue.bold,green.bold\" \"anvil --auto-impersonate\" \"wait-on tcp:8545 && npx ts-node scripts/localnet/worker.ts\"",
"test": "forge clean && forge test -vv"
},
"devDependencies": {
"@eslint/js": "^9.7.0",
"@types/eslint__js": "^8.42.3",
"concurrently": "^8.2.2",
"eslint": "^8.57.0",
"ts-node": "^10.9.2",
"typescript": "^5.5.4",
"typescript-eslint": "^7.17.0",
"wait-on": "^7.2.0"
},
"author": "",
"license": "ISC",
"license": "MIT",
"dependencies": {
"ethers": "^6.13.1"
}
Expand Down
36 changes: 36 additions & 0 deletions v2/scripts/localnet/EvmCall.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "forge-std/Script.sol";
import "src/evm/GatewayEVM.sol";
import "test/utils/TestZContract.sol";

// EvmCallScript executes call method on GatewayEVM and it should be used on localnet.
// It uses anvil private key, and sets default contract addresses deployed on fresh localnet, that can be overriden with env vars.
contract EvmCallScript is Script {
skosito marked this conversation as resolved.
Show resolved Hide resolved
function run() external {
address payable gatewayEVMAddress = payable(vm.envOr("GATEWAY_EVM", 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0));
address payable zContractAddress = payable(vm.envOr("Z_CONTRACT", 0x68B1D87F95878fE05B998F19b66F4baba5De1aed));
string memory mnemonic = "test test test test test test test test test test test junk";
uint256 privateKey = vm.deriveKey(mnemonic, 0);
address deployer = vm.rememberKey(privateKey);

vm.startBroadcast(deployer);

GatewayEVM gatewayEVM = GatewayEVM(gatewayEVMAddress);
TestZContract zContract = TestZContract(zContractAddress);

// Encode the message
bytes memory message = abi.encode("hello");

// Call the function on GatewayEVM
try gatewayEVM.call(zContractAddress, message) {
console.log("TestZContract called from EVM.");
} catch (bytes memory err) {
console.log("Error calling TestZContract:");
console.logBytes(err);
}

vm.stopBroadcast();
}
}
48 changes: 48 additions & 0 deletions v2/scripts/localnet/EvmDepositAndCall.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "forge-std/Script.sol";
import "src/evm/GatewayEVM.sol";
import "test/utils/TestZContract.sol";
import "test/utils/TestERC20.sol";

// EvmDepositAndCallScript executes depositAndCall method on GatewayEVM and it should be used on localnet.
// It uses anvil private key, and sets default contract addresses deployed on fresh localnet, that can be overriden with env vars.
contract EvmDepositAndCallScript is Script {
function run() external {
address payable gatewayEVMAddress = payable(vm.envOr("GATEWAY_EVM", 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0));
address payable zContractAddress = payable(vm.envOr("Z_CONTRACT", 0x68B1D87F95878fE05B998F19b66F4baba5De1aed));
address erc20Address = vm.envOr("ERC20", 0x9A676e781A523b5d0C0e43731313A708CB607508);
uint256 amount = vm.envOr("AMOUNT", uint256(1));
string memory mnemonic = "test test test test test test test test test test test junk";
uint256 privateKey = vm.deriveKey(mnemonic, 0);
address deployer = vm.rememberKey(privateKey);

vm.startBroadcast(deployer);

GatewayEVM gatewayEVM = GatewayEVM(gatewayEVMAddress);
TestZContract zContract = TestZContract(zContractAddress);
TestERC20 erc20 = TestERC20(erc20Address);

// Approve the ERC20 transfer
erc20.approve(gatewayEVMAddress, amount);

// Encode the payload
bytes memory payload = abi.encode("hello");

// Call the depositAndCall function on GatewayEVM
try gatewayEVM.depositAndCall(
zContractAddress,
amount,
erc20Address,
payload
) {
console.log("TestZContract called from EVM.");
} catch (bytes memory err) {
console.log("Error calling TestZContract:");
console.logBytes(err);
}

vm.stopBroadcast();
}
}
Loading
Loading