Skip to content

Commit 2b3232d

Browse files
authored
feat: transaction details and deployment info (#33)
* deploymentInfo * log formating, interval promise * yarn lock * typo fix * dependency fix
1 parent 1060069 commit 2b3232d

File tree

3 files changed

+114
-6
lines changed

3 files changed

+114
-6
lines changed

packages/plugin/src/MultichainHardhatRuntimeEnvironmentField.ts

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import {
1111
getConfigEnvironmentVariable,
1212
getNetworkChainId,
1313
sumedFees,
14+
transferStatusInterval,
1415
mapNetworkArgs,
1516
} from "./utils";
1617
import { AdapterABI } from "./adapterABI";
17-
import { DeployOptions, NetworkArguments } from "./types";
18+
import { DeployOptions, DeploymentInfo, NetworkArguments } from "./types";
1819

1920
export class MultichainHardhatRuntimeEnvironmentField {
2021
private isInitiated: boolean = false;
@@ -62,7 +63,10 @@ export class MultichainHardhatRuntimeEnvironmentField {
6263
contractName: string,
6364
networkArgs: NetworkArguments<Abi>,
6465
options?: DeployOptions
65-
): Promise<Transaction | void> {
66+
): Promise<{
67+
deploymentInfo: DeploymentInfo[];
68+
receipt: Transaction;
69+
} | void> {
6670
const artifact = this.hre.artifacts.readArtifactSync(contractName);
6771

6872
return this.deployMultichainBytecode(
@@ -78,7 +82,10 @@ export class MultichainHardhatRuntimeEnvironmentField {
7882
contractAbi: Abi,
7983
networkArgs: NetworkArguments<Abi>,
8084
options?: DeployOptions
81-
): Promise<Transaction | void> {
85+
): Promise<{
86+
deploymentInfo: DeploymentInfo[];
87+
receipt: Transaction;
88+
} | void> {
8289
if (!this.isInitiated) await this.initConfig();
8390
if (!this.web3) return;
8491

@@ -118,8 +125,8 @@ export class MultichainHardhatRuntimeEnvironmentField {
118125
value: sumedFees(fees),
119126
};
120127
}
121-
122-
return adapterContract.methods
128+
console.log("Sending transaction...");
129+
const receipt = await adapterContract.methods
123130
.deploy(
124131
contractBytecode,
125132
this.gasLimit,
@@ -131,5 +138,62 @@ export class MultichainHardhatRuntimeEnvironmentField {
131138
fees
132139
)
133140
.send(payableTxOptions);
141+
const networkNames = Object.keys(networkArgs);
142+
const { transactionHash } = receipt;
143+
console.log(
144+
`Multichain deployment initiated, transaction hash: ${transactionHash}
145+
146+
` +
147+
"\n" +
148+
"Destinaton networks:" +
149+
networkNames.join("\r\n")
150+
);
151+
152+
const [deployer] = await this.web3.eth.getAccounts();
153+
154+
const destinationDomainChainIDs = deployDomainIDs.map((deployDomainID) => {
155+
const deployDomain: Domain = this.domains.find(
156+
(domain) => BigInt(domain.id) === deployDomainID
157+
)!;
158+
return deployDomain.chainId;
159+
});
160+
161+
const deploymentInfo: DeploymentInfo[] = await Promise.all(
162+
destinationDomainChainIDs.map(async (domainChainID, index) => {
163+
const network = networkNames[index];
164+
165+
const contractAddress = await adapterContract.methods
166+
.computeContractAddressForChain(
167+
deployer,
168+
salt,
169+
isUniquePerChain,
170+
domainChainID
171+
)
172+
.call();
173+
console.log(
174+
`Contract deploying on ${network.toUpperCase()}: ${contractAddress}`
175+
);
176+
177+
const explorerUrl = await transferStatusInterval(
178+
this.hre.config.multichain.environment,
179+
transactionHash,
180+
domainChainID
181+
);
182+
183+
console.log(`Bridge transfer executed. More details: ${explorerUrl}`);
184+
185+
return {
186+
network,
187+
contractAddress,
188+
explorerUrl,
189+
transactionHash,
190+
};
191+
})
192+
);
193+
194+
return {
195+
receipt,
196+
deploymentInfo,
197+
};
134198
}
135199
}

packages/plugin/src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,10 @@ export interface DeployOptions {
3030
isUniquePerChain?: boolean;
3131
customNonPayableTxOptions?: NonPayableCallOptions;
3232
}
33+
34+
export interface DeploymentInfo {
35+
network: string;
36+
contractAddress: string;
37+
explorerUrl: string;
38+
transactionHash: string;
39+
}

packages/plugin/src/utils.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import assert from "assert";
22
import { HardhatRuntimeEnvironment } from "hardhat/types";
3-
import { Domain, Environment } from "@buildwithsygma/sygma-sdk-core";
3+
import {
4+
Domain,
5+
Environment,
6+
getTransferStatusData,
7+
} from "@buildwithsygma/sygma-sdk-core";
48
import {
59
AbiFallbackFragment,
610
Bytes,
@@ -146,3 +150,36 @@ export function mapNetworkArgs<Abi extends ContractAbi = any>(
146150
initDatas,
147151
};
148152
}
153+
154+
export async function transferStatusInterval(
155+
environment: Environment,
156+
txHash: string,
157+
domainID: number
158+
): Promise<string> {
159+
let explorerUrl: string = "";
160+
161+
await new Promise((resolve) => {
162+
let controller: AbortController;
163+
setInterval(() => {
164+
controller = new AbortController();
165+
void getTransferStatusData(environment, txHash, domainID.toString()).then(
166+
(transferStatus) => {
167+
explorerUrl = transferStatus.explorerUrl;
168+
169+
if (transferStatus.status === "executed") {
170+
controller.abort();
171+
resolve(explorerUrl);
172+
}
173+
if (transferStatus.status === "failed") {
174+
throw new HardhatPluginError(
175+
"@chainsafe/hardhat-plugin-multichain-deploy",
176+
`Bridge transfer failed`
177+
);
178+
}
179+
}
180+
);
181+
}, 1000);
182+
});
183+
184+
return explorerUrl;
185+
}

0 commit comments

Comments
 (0)