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 1 commit
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
70 changes: 65 additions & 5 deletions packages/plugin/src/MultichainHardhatRuntimeEnvironmentField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import {
getNetworkChainId,
mapNetworkArgs,
sumedFees,
transferStatusInterval,
} from "./utils";
import { AdapterABI } from "./adapterABI";
import { DeployOptions, NetworkArguments } from "./types";
import { DeployOptions, DeploymentInfo, NetworkArguments } from "./types";

export class MultichainHardhatRuntimeEnvironmentField {
private isValidated: 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.isValidated) await this.validateConfig();
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,58 @@ export class MultichainHardhatRuntimeEnvironmentField {
fees
)
.send(payableTxOptions);

const { from, to, transactionHash } = receipt;
console.log(
`Transacion sent from ${from} to ${to}, transaction hash: ${transactionHash}`
irubido marked this conversation as resolved.
Show resolved Hide resolved
);

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 networkNames = Object.keys(networkArgs);

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 address for ${network.toUpperCase()}: ${contractAddress}`
irubido marked this conversation as resolved.
Show resolved Hide resolved
);

const explorerUrl = transferStatusInterval(
this.hre.config.multichain.environment,
transactionHash,
domainChainID
);
console.log(`Bridge transfer executed, explorer url: ${explorerUrl}`);
irubido marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -22,3 +22,10 @@ export interface DeployOptions {
isUniquePerChain?: boolean;
customNonPayableTxOptions?: NonPayableCallOptions;
}

export interface DeploymentInfo {
network: string;
contractAddress: string;
explorerUrl: string;
transactionHash: string;
}
32 changes: 31 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 @@ -150,3 +154,29 @@ export function mapNetworkArgs<Abi extends ContractAbi = any>(
initDatas,
};
}

export function transferStatusInterval(
environment: Environment,
txHash: string,
domainID: number
): string {
let controller: AbortController;
let explorerUrl: string = "";

const interval = setInterval(() => {
controller = new AbortController();
void getTransferStatusData(environment, txHash, domainID.toString()).then(
(transferStatus) => {
explorerUrl = transferStatus.explorerUrl;

if (transferStatus.status === "executed") {
clearInterval(interval);
controller.abort();
return;
}
}
);
}, 1000) as unknown as number;

return explorerUrl;
}
irubido marked this conversation as resolved.
Show resolved Hide resolved
Loading