Skip to content

Commit

Permalink
feat: refactor of contract deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
ljankovic-txfusion committed Oct 4, 2024
1 parent 5e36ece commit 4273265
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 17 deletions.
2 changes: 1 addition & 1 deletion solidity/exportBuildArtifact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ if [ ! -f "$jsonFiles" ]; then
fi

# Extract required keys and write to outputFile
if jq -c '{input, solcLongVersion}' "$jsonFiles" > "$outputFileJson"; then
if jq -c '{input, solcLongVersion, zk_version: .output.zk_version}' "$jsonFiles" > "$outputFileJson"; then
echo "export const buildArtifact = " > "$outputFileJs"
cat "$outputFileJson" >> "$outputFileJs"
echo "export const buildArtifact: any" > "$outputFileTsd"
Expand Down
5 changes: 5 additions & 0 deletions typescript/sdk/src/deploy/EvmModuleDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Address, rootLogger } from '@hyperlane-xyz/utils';
import { HyperlaneContracts, HyperlaneFactories } from '../contracts/types.js';
import { MultiProvider } from '../providers/MultiProvider.js';
import { ChainMap, ChainName } from '../types.js';
import { getArtifactByContractName } from '../utils/zksync.js';

import { isProxy, proxyConstructorArgs } from './proxy.js';
import { ContractVerifier } from './verify/ContractVerifier.js';
Expand Down Expand Up @@ -63,10 +64,14 @@ export class EvmModuleDeployer<Factories extends HyperlaneFactories> {
', ',
)})...`,
);

const artifact = getArtifactByContractName(contractName);

const contract = await this.multiProvider.handleDeploy(
chain,
factory,
constructorArgs,
artifact,
);

if (initializeArgs) {
Expand Down
7 changes: 6 additions & 1 deletion typescript/sdk/src/deploy/HyperlaneDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
TimelockController__factory,
TransparentUpgradeableProxy__factory,
} from '@hyperlane-xyz/core';
// import { TransparentUpgradeableProxy__artifact } from '@hyperlane-xyz/core/artifacts';
import { TimelockController__artifact } from '@hyperlane-xyz/core/artifacts';
import { buildArtifact as coreBuildArtifact } from '@hyperlane-xyz/core/buildArtifact.js';
import {
Address,
Expand All @@ -36,6 +36,7 @@ import { InterchainAccount } from '../middleware/account/InterchainAccount.js';
import { MultiProvider } from '../providers/MultiProvider.js';
import { MailboxClientConfig } from '../router/types.js';
import { ChainMap, ChainName } from '../types.js';
import { getArtifactByContractName } from '../utils/zksync.js';

import {
UpgradeConfig,
Expand Down Expand Up @@ -408,10 +409,13 @@ export abstract class HyperlaneDeployer<
)})...`,
);

const artifact = getArtifactByContractName(contractName);

const contract = await this.multiProvider.handleDeploy(
chain,
factory,
constructorArgs,
artifact,
);

if (initializeArgs) {
Expand Down Expand Up @@ -646,6 +650,7 @@ export abstract class HyperlaneDeployer<
[timelockConfig.roles.executor],
ethers.constants.AddressZero,
],
TimelockController__artifact,
);
}

Expand Down
17 changes: 9 additions & 8 deletions typescript/sdk/src/deploy/HyperlaneProxyFactoryDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ProxyFactoryFactories,
proxyFactoryFactories,
proxyFactoryFactoriesArtifacts,
proxyFactoryImplementations,
} from './contracts.js';
import { ContractVerifier } from './verify/ContractVerifier.js';

Expand Down Expand Up @@ -41,14 +42,14 @@ export class HyperlaneProxyFactoryDeployer extends HyperlaneDeployer<
this.factories,
) as (keyof ProxyFactoryFactories)[]) {
const factory = await this.deployContract(chain, factoryName, []);
// this.addVerificationArtifacts(chain, [
// {
// name: proxyFactoryImplementations[factoryName],
// address: await factory.implementation(),
// constructorArguments: '',
// isProxy: true,
// },
// ]);
this.addVerificationArtifacts(chain, [
{
name: proxyFactoryImplementations[factoryName],
address: await factory.implementation(),
constructorArguments: '',
isProxy: true,
},
]);
contracts[factoryName] = factory;
}
return contracts as HyperlaneContracts<ProxyFactoryFactories>;
Expand Down
2 changes: 2 additions & 0 deletions typescript/sdk/src/ism/EvmIsmModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
TestIsm__factory,
TrustedRelayerIsm__factory,
} from '@hyperlane-xyz/core';
import { DefaultFallbackRoutingIsm__artifact } from '@hyperlane-xyz/core/artifacts';
// import { TrustedRelayerIsm__artifact } from '@hyperlane-xyz/core/artifacts';
import {
Address,
Expand Down Expand Up @@ -542,6 +543,7 @@ export class EvmIsmModule extends HyperlaneModule<
this.chain,
new DefaultFallbackRoutingIsm__factory(),
[this.args.addresses.mailbox],
DefaultFallbackRoutingIsm__artifact,
);

// initialize the fallback routing ISM
Expand Down
10 changes: 10 additions & 0 deletions typescript/sdk/src/ism/HyperlaneIsmFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import {
TestIsm__factory,
TrustedRelayerIsm__factory,
} from '@hyperlane-xyz/core';
import {
DefaultFallbackRoutingIsm__artifact,
StorageMerkleRootMultisigIsm__artifact,
StorageMessageIdMultisigIsm__artifact,
} from '@hyperlane-xyz/core/artifacts';
import {
Address,
Domain,
Expand Down Expand Up @@ -238,11 +243,13 @@ export class HyperlaneIsmFactory extends HyperlaneApp<ProxyFactoryFactories> {
factory:
| StorageMerkleRootMultisigIsm__factory
| StorageMessageIdMultisigIsm__factory,
artifact: any,
) => {
const contract = await this.multiProvider.handleDeploy(
destination,
factory,
[config.validators, config.threshold],
artifact,
);
return contract.address;
};
Expand All @@ -263,11 +270,13 @@ export class HyperlaneIsmFactory extends HyperlaneApp<ProxyFactoryFactories> {
case IsmType.STORAGE_MERKLE_ROOT_MULTISIG:
address = await deployStorage(
new StorageMerkleRootMultisigIsm__factory(),
StorageMerkleRootMultisigIsm__artifact,
);
break;
case IsmType.STORAGE_MESSAGE_ID_MULTISIG:
address = await deployStorage(
new StorageMessageIdMultisigIsm__factory(),
StorageMessageIdMultisigIsm__artifact,
);
break;
default:
Expand Down Expand Up @@ -420,6 +429,7 @@ export class HyperlaneIsmFactory extends HyperlaneApp<ProxyFactoryFactories> {
destination,
new DefaultFallbackRoutingIsm__factory(),
[mailbox],
DefaultFallbackRoutingIsm__artifact,
);
// TODO: Should verify contract here
logger.debug('Initialising fallback routing ISM ...');
Expand Down
7 changes: 2 additions & 5 deletions typescript/sdk/src/providers/MultiProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ export class MultiProvider<MetaExt = {}> extends ChainMetadataManager<MetaExt> {
chainNameOrId: ChainNameOrId,
factory: F,
params: any,
artifact: any,
): Promise<Awaited<ReturnType<F['deploy']>>> {
const metadata = this.tryGetChainMetadata(chainNameOrId);
if (!metadata) {
Expand All @@ -343,11 +344,7 @@ export class MultiProvider<MetaExt = {}> extends ChainMetadataManager<MetaExt> {
if (protocol === ProtocolType.ZKSync) {
const deployer = new ZKDeployer(signer as zk.Wallet);

const localArtifact = deployer.loadArtifactByEvmBytecode(
factory.bytecode,
);

contract = await deployer.deploy(localArtifact, params);
contract = await deployer.deploy(artifact, params);

this.logger.trace(
`Contract deployed at ${contract.address} on ${chainNameOrId}:`,
Expand Down
33 changes: 33 additions & 0 deletions typescript/sdk/src/utils/zksync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { zksyncArtifacts } from '@hyperlane-xyz/core/artifacts';

export interface ZkSyncArtifact {
contractName: string;
sourceName: string;
abi: any[];
bytecode: string;
deployedBytecode: string;
compiler: {
version: string;
settings: any;
};
factoryDeps?: Record<string, string>;
}

export const getArtifactByContractName = (name: string): ZkSyncArtifact => {
const artifact = (zksyncArtifacts as ZkSyncArtifact[]).find(
({ contractName, sourceName }) => {
if (contractName.toLowerCase() === name.toLowerCase()) {
return true;
}

const qualifiedName = `${sourceName}:${contractName}`;
if (name === qualifiedName) {
return true;
}

return false;
},
);

return artifact as any;
};
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5067,7 +5067,7 @@ __metadata:

"@hyperlane-xyz/core@file:../../solidity::locator=%40hyperlane-xyz%2Fsdk%40workspace%3Atypescript%2Fsdk":
version: 5.1.0
resolution: "@hyperlane-xyz/core@file:../../solidity#../../solidity::hash=f3a4cc&locator=%40hyperlane-xyz%2Fsdk%40workspace%3Atypescript%2Fsdk"
resolution: "@hyperlane-xyz/core@file:../../solidity#../../solidity::hash=52f19a&locator=%40hyperlane-xyz%2Fsdk%40workspace%3Atypescript%2Fsdk"
dependencies:
"@arbitrum/nitro-contracts": "npm:^1.2.1"
"@eth-optimism/contracts": "npm:^0.6.0"
Expand All @@ -5081,7 +5081,7 @@ __metadata:
"@ethersproject/abi": "*"
"@ethersproject/providers": "*"
"@types/sinon-chai": "*"
checksum: ce6040530dc6d1a6f9c14835fd89543d03d410a565576cebfc4a1c320c68ab930e2dd0c4a58baf2761433ad505892be7c03b41444deb46a90551b9d48465b336
checksum: 26fbd298737af087b37175effe46c80edc73e8c2360e306993508abbe51e193239942c1c79d0756b7b4453b3a29a38efe6b439534f82e8f764494c59da7e9770
languageName: node
linkType: hard

Expand Down

0 comments on commit 4273265

Please sign in to comment.