From f38009b388da30b2dbd6d541bfdeac97e15536b8 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Sun, 8 Oct 2023 10:52:37 +0300 Subject: [PATCH 1/2] feat: added gas limit to CCM template (#65) --- tasks/cctx.ts | 2 +- templates/messaging/tasks/deploy.ts.hbs | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/tasks/cctx.ts b/tasks/cctx.ts index 7195c4c0..c716e2e0 100644 --- a/tasks/cctx.ts +++ b/tasks/cctx.ts @@ -6,7 +6,7 @@ import { trackCCTX } from "../helpers"; declare const hre: any; const main = async (args: any, hre: HardhatRuntimeEnvironment) => { - await trackCCTX(args.tx); + await trackCCTX(args.tx, args.json); }; export const cctxTask = task( diff --git a/templates/messaging/tasks/deploy.ts.hbs b/templates/messaging/tasks/deploy.ts.hbs index 1d125b7d..b3b3430a 100644 --- a/templates/messaging/tasks/deploy.ts.hbs +++ b/templates/messaging/tasks/deploy.ts.hbs @@ -1,6 +1,6 @@ import { getAddress } from "@zetachain/protocol-contracts"; import { ethers } from "ethers"; -import { task } from "hardhat/config"; +import { task, types } from "hardhat/config"; import { HardhatRuntimeEnvironment } from "hardhat/types"; import { getSupportedNetworks } from "@zetachain/networks"; @@ -11,12 +11,17 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { const contracts: { [key: string]: string } = {}; await Promise.all( networks.map(async (networkName: string) => { - contracts[networkName] = await deployContract(hre, networkName, args.json); + contracts[networkName] = await deployContract( + hre, + networkName, + args.json, + args.gasLimit + ); }) ); for (const source in contracts) { - await setInteractors(hre, source, contracts, args.json); + await setInteractors(hre, source, contracts, args.json, args.gasLimit); } if (args.json) { @@ -35,7 +40,8 @@ const initWallet = (hre: HardhatRuntimeEnvironment, networkName: string) => { const deployContract = async ( hre: HardhatRuntimeEnvironment, networkName: string, - json: boolean = false + json: boolean = false, + gasLimit: number ) => { const wallet = initWallet(hre, networkName); @@ -54,7 +60,7 @@ const deployContract = async ( const { abi, bytecode } = await hre.artifacts.readArtifact(contractName); const factory = new ethers.ContractFactory(abi, bytecode, wallet); - const contract = await factory.deploy(connector, zetaToken{{#if arguments.feesNative}}, zetaTokenConsumerUniV2 || zetaTokenConsumerUniV3{{/if}}); + const contract = await factory.deploy(connector, zetaToken{{#if arguments.feesNative}}, zetaTokenConsumerUniV2 || zetaTokenConsumerUniV3{{/if}}, { gasLimit }); await contract.deployed(); if (!json) { @@ -69,7 +75,8 @@ const setInteractors = async ( hre: HardhatRuntimeEnvironment, source: string, contracts: { [key: string]: string }, - json: boolean = false + json: boolean = false, + gasLimit: number ) => { if (!json) { console.log(` @@ -90,7 +97,9 @@ const setInteractors = async ( ); const chainId = hre.config.networks[counterparty].chainId; await ( - await contract.setInteractorByChainId(chainId, counterpartyContract) + await contract.setInteractorByChainId(chainId, counterpartyContract, { + gasLimit, + }) ).wait(); if (!json) { console.log( @@ -107,4 +116,5 @@ task("deploy", "Deploy the contract", main) "ccm" )})` ) + .addOptionalParam("gasLimit", "Gas limit", 10000000, types.int) .addFlag("json", "Output JSON"); From 2cede918ba62880ce6ec2d76fa163d9216bc671e Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Tue, 10 Oct 2023 09:33:22 +0300 Subject: [PATCH 2/2] ci: multiply dynamic gas value by 2 to ensure no gas errors (#72) --- scripts/integration.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/integration.sh b/scripts/integration.sh index cde463b4..f99501ca 100755 --- a/scripts/integration.sh +++ b/scripts/integration.sh @@ -73,7 +73,11 @@ CCM_CONTRACT=$(npx hardhat deploy --networks goerli_testnet,mumbai_testnet --jso echo "Deployed CCM contract address: $CCM_CONTRACT" -CCM_FEE=$(npx hardhat fees --json | jq -r ".feesCCM.mumbai_testnet.totalFee") +PROTOCOL_FEE=$(npx hardhat fees --json | jq -r ".feesCCM.mumbai_testnet.protocolFee") +GAS_FEE=$(npx hardhat fees --json | jq -r ".feesCCM.mumbai_testnet.gasFee") + +# Multiply by 2 to be on the safe side +CCM_FEE=$(echo "$PROTOCOL_FEE + $GAS_FEE * 2" | bc -l) echo "CCM fee: $CCM_FEE"