Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: transaction details and deployment info #33

Merged
merged 7 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 69 additions & 5 deletions packages/plugin/src/MultichainHardhatRuntimeEnvironmentField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import {
getConfigEnvironmentVariable,
getNetworkChainId,
sumedFees,
transferStatusInterval,
mapNetworkArgs,
} from "./utils";
import { AdapterABI } from "./adapterABI";
import { DeployOptions, NetworkArguments } from "./types";
import { DeployOptions, DeploymentInfo, NetworkArguments } from "./types";

export class MultichainHardhatRuntimeEnvironmentField {
private isInitiated: boolean = false;
Expand Down Expand Up @@ -62,7 +63,10 @@ export class MultichainHardhatRuntimeEnvironmentField {
contractName: string,
networkArgs: NetworkArguments<Abi>,
options?: DeployOptions
): Promise<Transaction | void> {
): Promise<{
deploymentInfo: DeploymentInfo[];
receipt: Transaction;
} | void> {
const artifact = this.hre.artifacts.readArtifactSync(contractName);

return this.deployMultichainBytecode(
Expand All @@ -78,7 +82,10 @@ export class MultichainHardhatRuntimeEnvironmentField {
contractAbi: Abi,
networkArgs: NetworkArguments<Abi>,
options?: DeployOptions
): Promise<Transaction | void> {
): Promise<{
deploymentInfo: DeploymentInfo[];
receipt: Transaction;
} | void> {
if (!this.isInitiated) await this.initConfig();
if (!this.web3) return;

Expand Down Expand Up @@ -118,8 +125,8 @@ export class MultichainHardhatRuntimeEnvironmentField {
value: sumedFees(fees),
};
}

return adapterContract.methods
console.log("Sending transaction...");
const receipt = await adapterContract.methods
.deploy(
contractBytecode,
this.gasLimit,
Expand All @@ -131,5 +138,62 @@ export class MultichainHardhatRuntimeEnvironmentField {
fees
)
.send(payableTxOptions);
const networkNames = Object.keys(networkArgs);
const { transactionHash } = receipt;
console.log(
`Multichain deployment initiated, transaction hash: ${transactionHash}

` +
"\n" +
"Destinaton networks:" +
networkNames.join("\r\n")
);

const [deployer] = await this.web3.eth.getAccounts();

const destinationDomainChainIDs = deployDomainIDs.map((deployDomainID) => {
const deployDomain: Domain = this.domains.find(
(domain) => BigInt(domain.id) === deployDomainID
)!;
return deployDomain.chainId;
});

const deploymentInfo: DeploymentInfo[] = await Promise.all(
destinationDomainChainIDs.map(async (domainChainID, index) => {
const network = networkNames[index];

const contractAddress = await adapterContract.methods
.computeContractAddressForChain(
deployer,
salt,
isUniquePerChain,
domainChainID
)
.call();
console.log(
`Contract deploying on ${network.toUpperCase()}: ${contractAddress}`
);

const explorerUrl = await transferStatusInterval(
this.hre.config.multichain.environment,
transactionHash,
domainChainID
);

console.log(`Bridge transfer executed. More details: ${explorerUrl}`);

return {
network,
contractAddress,
explorerUrl,
transactionHash,
};
})
);

return {
receipt,
deploymentInfo,
};
}
}
7 changes: 7 additions & 0 deletions packages/plugin/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ export interface DeployOptions {
isUniquePerChain?: boolean;
customNonPayableTxOptions?: NonPayableCallOptions;
}

export interface DeploymentInfo {
network: string;
contractAddress: string;
explorerUrl: string;
transactionHash: string;
}
39 changes: 38 additions & 1 deletion packages/plugin/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import assert from "assert";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Domain, Environment } from "@buildwithsygma/sygma-sdk-core";
import {
Domain,
Environment,
getTransferStatusData,
} from "@buildwithsygma/sygma-sdk-core";
import {
AbiFallbackFragment,
Bytes,
Expand Down Expand Up @@ -146,3 +150,36 @@ export function mapNetworkArgs<Abi extends ContractAbi = any>(
initDatas,
};
}

export async function transferStatusInterval(
environment: Environment,
txHash: string,
domainID: number
): Promise<string> {
let explorerUrl: string = "";

await new Promise((resolve) => {
let controller: AbortController;
setInterval(() => {
controller = new AbortController();
void getTransferStatusData(environment, txHash, domainID.toString()).then(
(transferStatus) => {
explorerUrl = transferStatus.explorerUrl;

if (transferStatus.status === "executed") {
controller.abort();
resolve(explorerUrl);
}
if (transferStatus.status === "failed") {
throw new HardhatPluginError(
"@chainsafe/hardhat-plugin-multichain-deploy",
`Bridge transfer failed`
);
}
}
);
}, 1000);
});

return explorerUrl;
}
Loading