Skip to content

Commit

Permalink
chore: minor refactoring & adding types
Browse files Browse the repository at this point in the history
  • Loading branch information
ljankovic-txfusion committed Oct 9, 2024
1 parent d0fb3c8 commit 9bf46bc
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 32 deletions.
1 change: 1 addition & 0 deletions typescript/infra/src/config/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export async function fetchProvider(
if (rpcData.length === 0) {
throw Error(`No RPC URLs found for chain: ${chainName}`);
}

return new HyperlaneSmartProvider(
chainId,
rpcData.map((url) => ({ http: url })),
Expand Down
1 change: 1 addition & 0 deletions typescript/infra/src/govern/multisend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class SignerMultiSend extends MultiSend {
for (const call of calls) {
const estimate = await this.multiProvider.estimateGas(this.chain, call);
const receipt = await this.multiProvider.sendTransaction(this.chain, {
gasLimit: estimate.mul(11).div(10), // 10% buffer
...call,
});
console.log(`confirmed tx ${receipt.transactionHash}`);
Expand Down
2 changes: 0 additions & 2 deletions typescript/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@
"test:ci": "yarn test",
"test:unit": "mocha --config .mocharc.json './src/**/*.test.ts' --exit",
"test:hardhat": "NODE_OPTIONS='--experimental-loader ts-node/esm/transpile-only --no-warnings=ExperimentalWarning' hardhat --config hardhat.config.cts test $(find ./src -name \"*.hardhat-test.ts\")",
"test:hardhat:accounts": "NODE_OPTIONS='--experimental-loader ts-node/esm/transpile-only --no-warnings=ExperimentalWarning' hardhat --config hardhat.config.cts test $(find ./src -name \"accounts.hardhat-test.ts\")",
"test:govern": "NODE_OPTIONS='--experimental-loader ts-node/esm/transpile-only --no-warnings=ExperimentalWarning' hardhat --config hardhat.config.cts test $(find ./src -name \"govern.hardhat-test.ts\")",
"test:foundry": "./scripts/foundry-test.sh"
},
"peerDependencies": {
Expand Down
2 changes: 0 additions & 2 deletions typescript/sdk/src/core/TestRecipientDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ export class TestRecipientDeployer extends HyperlaneDeployer<
): Promise<TestRecipientContracts> {
this.logger.debug(`Deploying TestRecipient on ${chain}`, config);
const testRecipient = await this.deployContract(chain, 'testRecipient', []);

if (config.interchainSecurityModule) {
this.logger.debug(`Checking TestRecipient ISM on ${chain}`);

await this.configureIsm(
chain,
testRecipient,
Expand Down
3 changes: 2 additions & 1 deletion typescript/sdk/src/ism/HyperlaneIsmFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
} from '../deploy/contracts.js';
import { MultiProvider } from '../providers/MultiProvider.js';
import { ChainMap, ChainName } from '../types.js';
import { ZkSyncArtifact } from '../utils/zksync.js';

import {
AggregationIsmConfig,
Expand Down Expand Up @@ -243,7 +244,7 @@ export class HyperlaneIsmFactory extends HyperlaneApp<ProxyFactoryFactories> {
factory:
| StorageMerkleRootMultisigIsm__factory
| StorageMessageIdMultisigIsm__factory,
artifact: any,
artifact: ZkSyncArtifact,
) => {
const contract = await this.multiProvider.handleDeploy(
destination,
Expand Down
13 changes: 7 additions & 6 deletions typescript/sdk/src/providers/MultiProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { testChainMetadata, testChains } from '../consts/testChains.js';
import { ChainMetadataManager } from '../metadata/ChainMetadataManager.js';
import { ChainMetadata } from '../metadata/chainMetadataTypes.js';
import { ChainMap, ChainName, ChainNameOrId } from '../types.js';
import { ZkSyncArtifact } from '../utils/zksync.js';
import { ZKDeployer } from '../zksync/ZKDeployer.js';

import { AnnotatedEV5Transaction } from './ProviderType.js';
Expand All @@ -25,12 +26,12 @@ import {
defaultZKProviderBuilder,
} from './providerBuilders.js';

type Provider = providers.Provider;
type Provider = providers.Provider | zk.Provider;

export interface MultiProviderOptions {
logger?: Logger;
providers?: ChainMap<Provider | zk.Provider>;
providerBuilder?: ProviderBuilderFn<Provider>;
providerBuilder?: ProviderBuilderFn<Provider | zk.Provider>;
signers?: ChainMap<Signer | zk.Wallet>;
}

Expand Down Expand Up @@ -211,7 +212,7 @@ export class MultiProvider<MetaExt = {}> extends ChainMetadataManager<MetaExt> {
* Sets Ethers Signers for a set of chains
* @throws if chain's metadata has not been set or shared signer has already been set
*/
setSigners(signers: ChainMap<zk.Wallet>): void {
setSigners(signers: ChainMap<Signer | zk.Wallet>): void {
if (this.useSharedSigner) {
throw new Error('MultiProvider already set to use a shared signer');
}
Expand All @@ -226,7 +227,7 @@ export class MultiProvider<MetaExt = {}> extends ChainMetadataManager<MetaExt> {
*/
tryGetSignerOrProvider(
chainNameOrId: ChainNameOrId,
): zk.Wallet | Signer | Provider | zk.Provider | null {
): Signer | Provider | zk.Wallet | zk.Provider | null {
return (
this.tryGetSigner(chainNameOrId) || this.tryGetProvider(chainNameOrId)
);
Expand Down Expand Up @@ -327,8 +328,8 @@ export class MultiProvider<MetaExt = {}> extends ChainMetadataManager<MetaExt> {
async handleDeploy<F extends zk.ContractFactory | ContractFactory>(
chainNameOrId: ChainNameOrId,
factory: F,
params: any,
artifact: any,
params: Parameters<F['deploy']>,
artifact: ZkSyncArtifact,
): Promise<Awaited<ReturnType<F['deploy']>>> {
const metadata = this.tryGetChainMetadata(chainNameOrId);
if (!metadata) {
Expand Down
6 changes: 3 additions & 3 deletions typescript/sdk/src/providers/providerBuilders.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
import { StargateClient } from '@cosmjs/stargate';
import { Connection } from '@solana/web3.js';
import { ethers } from 'ethers';
import { providers } from 'ethers';
import { createPublicClient, http } from 'viem';
import * as zk from 'zksync-ethers';

Expand Down Expand Up @@ -113,7 +113,7 @@ export function defaultCosmJsWasmProviderBuilder(

export function defaultZKSyncProviderBuilder(
rpcUrls: RpcUrl[],
network: ethers.providers.Networkish,
network: providers.Networkish,
): ZKSyncProvider {
if (!rpcUrls.length) throw new Error('No RPC URLs provided');
const url = rpcUrls[0].http;
Expand All @@ -125,7 +125,7 @@ export function defaultZKSyncProviderBuilder(
export function defaultProviderBuilder(
rpcUrls: RpcUrl[],
_network: number | string,
): ethers.providers.Provider {
): providers.Provider {
return defaultEthersV5ProviderBuilder(rpcUrls, _network).provider;
}
// Kept for backwards compatibility
Expand Down
9 changes: 4 additions & 5 deletions typescript/sdk/src/router/HyperlaneRouterDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ export abstract class HyperlaneRouterDeployer<
_: ChainMap<Config>,
foreignRouters: ChainMap<Address> = {},
): Promise<void> {
this.logger.info(
this.logger.debug(
`Enrolling deployed routers with each other (if not already)...`,
);
// Make all routers aware of each other.

// Routers that were deployed.
const deployedRouters: ChainMap<Address> = objMap(
Expand All @@ -56,6 +57,7 @@ export abstract class HyperlaneRouterDeployer<
const allRemoteChains = this.multiProvider
.getRemoteChains(chain)
.filter((c) => allChains.includes(c));

const enrollEntries = await Promise.all(
allRemoteChains.map(async (remote) => {
const remoteDomain = this.multiProvider.getDomainId(remote);
Expand All @@ -64,11 +66,9 @@ export abstract class HyperlaneRouterDeployer<
return current !== expected ? [remoteDomain, expected] : undefined;
}),
);

const entries = enrollEntries.filter(
(entry): entry is [number, string] => entry !== undefined,
);

const domains = entries.map(([id]) => id);
const addresses = entries.map(([, address]) => address);

Expand All @@ -88,7 +88,6 @@ export abstract class HyperlaneRouterDeployer<
const enrollTx = await router.enrollRemoteRouters(domains, addresses, {
...this.multiProvider.getTransactionOverrides(chain),
});

await this.multiProvider.handleTx(chain, enrollTx);
});
}
Expand Down Expand Up @@ -120,6 +119,7 @@ export abstract class HyperlaneRouterDeployer<
configMap,
(_chainName, config): config is Config => !config.foreignDeployment,
);

// Create a map of chains that have foreign deployments.
const foreignDeployments: ChainMap<Address> = objFilter(
objMap(configMap, (_, config) => config.foreignDeployment),
Expand All @@ -134,7 +134,6 @@ export abstract class HyperlaneRouterDeployer<
configMap,
foreignDeployments,
);

await this.configureClients(deployedContractsMap, configMap);
await this.transferOwnership(deployedContractsMap, configMap);
this.logger.debug(`Finished deploying router contracts for all chains.`);
Expand Down
2 changes: 0 additions & 2 deletions typescript/sdk/src/token/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const hypERC20factories = {
[TokenType.native]: new HypNative__factory(),
[TokenType.nativeScaled]: new HypNativeScaled__factory(),
};

export type HypERC20Factories = typeof hypERC20factories;

export const hypERC721contracts = {
Expand All @@ -61,7 +60,6 @@ export const hypERC721factories = {
[TokenType.syntheticUri]: new HypERC721URIStorage__factory(),
[TokenType.synthetic]: new HypERC721__factory(),
};

export type HypERC721Factories = typeof hypERC721factories;

export type TokenFactories = HypERC20Factories | HypERC721Factories;
1 change: 0 additions & 1 deletion typescript/sdk/src/token/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ abstract class TokenDeployer<
gas: gasOverhead(config.type),
...config,
}));

return super.deploy(resolvedConfigMap);
}
}
Expand Down
6 changes: 1 addition & 5 deletions typescript/sdk/src/utils/zksync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ import { zksyncArtifacts } from '@hyperlane-xyz/core/artifacts';
export interface ZkSyncArtifact {
contractName: string;
sourceName: string;
abi: any[];
abi: any;
bytecode: string;
deployedBytecode: string;
compiler: {
version: string;
settings: any;
};
factoryDeps?: Record<string, string>;
}

Expand Down
10 changes: 5 additions & 5 deletions typescript/sdk/src/zksync/ZKDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class ZKDeployer {
* @returns Calculated fee in ETH wei
*/
public async estimateDeployFee(
artifact: any,
artifact: ZkSyncArtifact,
constructorArguments: any[],
): Promise<ethers.BigNumber> {
const gas = await this.estimateDeployGas(artifact, constructorArguments);
Expand All @@ -83,7 +83,7 @@ export class ZKDeployer {
* @returns Calculated amount of gas.
*/
public async estimateDeployGas(
artifact: any,
artifact: ZkSyncArtifact,
constructorArguments: any[],
): Promise<ethers.BigNumber> {
const factoryDeps = await this.extractFactoryDeps(artifact);
Expand Down Expand Up @@ -119,7 +119,7 @@ export class ZKDeployer {
* @returns A contract object.
*/
public async deploy(
artifact: any,
artifact: ZkSyncArtifact,
constructorArguments: any[] = [],
overrides?: ethers.Overrides,
additionalFactoryDeps?: ethers.BytesLike[],
Expand Down Expand Up @@ -160,15 +160,15 @@ export class ZKDeployer {
*
* @returns Factory dependencies in the format expected by SDK.
*/
async extractFactoryDeps(artifact: any): Promise<string[]> {
async extractFactoryDeps(artifact: ZkSyncArtifact): Promise<string[]> {
const visited = new Set<string>();

visited.add(`${artifact.sourceName}:${artifact.contractName}`);
return await this.extractFactoryDepsRecursive(artifact, visited);
}

private async extractFactoryDepsRecursive(
artifact: any,
artifact: ZkSyncArtifact,
visited: Set<string>,
): Promise<string[]> {
// Load all the dependency bytecodes.
Expand Down

0 comments on commit 9bf46bc

Please sign in to comment.