Skip to content

Commit

Permalink
chore: minor changes & refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ljankovic-txfusion committed Oct 9, 2024
1 parent 9bf46bc commit 8b5afe3
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 62 deletions.
1 change: 0 additions & 1 deletion typescript/cli/local-warp-deploy.sh

This file was deleted.

1 change: 0 additions & 1 deletion typescript/cli/local-warp-test.sh

This file was deleted.

1 change: 0 additions & 1 deletion typescript/cli/localCore.sh

This file was deleted.

1 change: 0 additions & 1 deletion typescript/cli/localSendMessage.sh

This file was deleted.

15 changes: 0 additions & 15 deletions typescript/sdk/build-sdk-cli.sh

This file was deleted.

12 changes: 6 additions & 6 deletions typescript/sdk/src/deploy/EvmModuleDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TransparentUpgradeableProxy__factory,
} from '@hyperlane-xyz/core';
import { buildArtifact as coreBuildArtifact } from '@hyperlane-xyz/core/buildArtifact.js';
import { Address, rootLogger } from '@hyperlane-xyz/utils';
import { Address, addBufferToGasLimit, rootLogger } from '@hyperlane-xyz/utils';

import { HyperlaneContracts, HyperlaneFactories } from '../contracts/types.js';
import { MultiProvider } from '../providers/MultiProvider.js';
Expand Down Expand Up @@ -267,6 +267,7 @@ export class EvmModuleDeployer<Factories extends HyperlaneFactories> {
values,
threshold,
);
const signer = multiProvider.getSigner(chain);
const code = await multiProvider.getProvider(chain).getCode(address);
if (code === '0x') {
logger.debug(
Expand All @@ -275,15 +276,14 @@ export class EvmModuleDeployer<Factories extends HyperlaneFactories> {
const overrides = multiProvider.getTransactionOverrides(chain);

// estimate gas
// const estimatedGas = await factory.estimateGas['deploy(address[],uint8)'](
// values,
// threshold,
// overrides,
// );
const estimatedGas = await factory
.connect(signer)
.estimateGas['deploy(address[],uint8)'](values, threshold, overrides);

// add 10% buffer
const hash = await factory['deploy(address[],uint8)'](values, threshold, {
...overrides,
gasLimit: addBufferToGasLimit(estimatedGas),
});

await multiProvider.handleTx(chain, hash);
Expand Down
35 changes: 9 additions & 26 deletions typescript/sdk/src/deploy/HyperlaneDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ export abstract class HyperlaneDeployer<
);

const { protocol } = this.multiProvider.getChainMetadata(chain);

const signer = this.multiProvider.getSigner(chain);
const artifact = getArtifactByContractName(contractName);

const contract = await this.multiProvider.handleDeploy(
Expand All @@ -436,32 +436,15 @@ export abstract class HyperlaneDeployer<

const overrides = this.multiProvider.getTransactionOverrides(chain);

let enhancedOverrides;
if (protocol === ProtocolType.ZKSync) {
this.logger.info('Skipping gas estimation on ZKSync...');

// deploy with 10% buffer on gas limit
enhancedOverrides = {
// TODO: zksync gas estimation
...overrides,
};
} else {
// Estimate gas for the initialize transaction
const estimatedGas = await contract.estimateGas.initialize(
...initializeArgs,
);

// deploy with 10% buffer on gas limit
enhancedOverrides = {
gasLimit: addBufferToGasLimit(estimatedGas),
...overrides,
};
}
// Estimate gas for the initialize transaction
const estimatedGas = await contract
.connect(signer)
.estimateGas.initialize(...initializeArgs);

const initTx = await contract.initialize(
...initializeArgs,
enhancedOverrides,
);
const initTx = await contract.initialize(...initializeArgs, {
...overrides,
gasLimit: addBufferToGasLimit(estimatedGas),
});
this.logger.info(`Contract ${contractName} initialized`);
const receipt = await this.multiProvider.handleTx(chain, initTx);

Expand Down
14 changes: 8 additions & 6 deletions typescript/sdk/src/ism/EvmIsmModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
Address,
Domain,
ProtocolType,
addBufferToGasLimit,
assert,
deepEquals,
eqAddress,
Expand Down Expand Up @@ -586,12 +587,12 @@ export class EvmIsmModule extends HyperlaneModule<
);

// estimate gas
// const estimatedGas = await domainRoutingIsmFactory.estimateGas.deploy(
// owner,
// domainIds,
// submoduleAddresses,
// overrides,
// );
const estimatedGas = await domainRoutingIsmFactory.estimateGas.deploy(
owner,
domainIds,
submoduleAddresses,
overrides,
);

// deploying new domain routing ISM, add 10% buffer
const tx = await domainRoutingIsmFactory.deploy(
Expand All @@ -600,6 +601,7 @@ export class EvmIsmModule extends HyperlaneModule<
submoduleAddresses,
{
...overrides,
gasLimit: addBufferToGasLimit(estimatedGas),
},
);

Expand Down
20 changes: 16 additions & 4 deletions typescript/sdk/src/providers/MultiProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import {
import { Logger } from 'pino';
import * as zk from 'zksync-ethers';

import { Address, ProtocolType, pick, rootLogger } from '@hyperlane-xyz/utils';
import {
Address,
ProtocolType,
addBufferToGasLimit,
pick,
rootLogger,
} from '@hyperlane-xyz/utils';

import { testChainMetadata, testChains } from '../consts/testChains.js';
import { ChainMetadataManager } from '../metadata/ChainMetadataManager.js';
Expand Down Expand Up @@ -343,19 +349,25 @@ export class MultiProvider<MetaExt = {}> extends ChainMetadataManager<MetaExt> {
const signer = this.getSigner(chainNameOrId);

if (protocol === ProtocolType.ZKSync) {
// Handle deployment for ZKSync protocol
const deployer = new ZKDeployer(signer as zk.Wallet);

contract = await deployer.deploy(artifact, params);
const estimatedGas = await deployer.estimateDeployGas(artifact, params);

contract = await deployer.deploy(artifact, params, {
gasLimit: addBufferToGasLimit(estimatedGas),
...overrides,
});

this.logger.trace(
`Contract deployed at ${contract.address} on ${chainNameOrId}:`,
);
} else {
const contractFactory = factory.connect(signer);
const deployTx = contractFactory.getDeployTransaction(...params);
const gasEstimated = await signer.estimateGas(deployTx);
const estimatedGas = await signer.estimateGas(deployTx);
contract = await contractFactory.deploy(...params, {
gasLimit: gasEstimated.mul(2), // 10% buffer
gasLimit: addBufferToGasLimit(estimatedGas), // 10% buffer
...overrides,
});

Expand Down
1 change: 0 additions & 1 deletion typescript/sdk/src/providers/transactionFeeEstimators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ export function estimateTransactionFee({
sender: Address;
senderPubKey?: HexString;
}): Promise<TransactionFeeEstimate> {
console.log({ type: transaction.type });
if (
transaction.type === ProviderType.EthersV5 &&
provider.type === ProviderType.EthersV5
Expand Down

0 comments on commit 8b5afe3

Please sign in to comment.