eth_ava_bridge/deploy/Bridge.ts

66 lines
2.0 KiB
TypeScript
Raw Permalink Normal View History

import {HardhatRuntimeEnvironment} from 'hardhat/types';
2021-01-31 18:45:46 +00:00
import { DeployFunction, DeployResult} from 'hardhat-deploy/types';
import { ethers, deployments, getNamedAccounts } from "hardhat";
import { Bridge } from "../types/Bridge";
import { ERC20Handler } from "../types/ERC20Handler";
import { MintableERC20 } from "../types/MintableERC20";
import {
createResourceID,
toWei,
generateDepositMetaData,
generateDepositDataHash,
createERCDepositData,
} from "../utils/helpers";
import { getContractFromDeploy } from "../utils/deploy"
import { SNT_ADDRESS } from "../constants/goerliAddress";
import MintableErc20Artifacts from "../artifacts/contracts/tokens/MintableErc20.sol/MintableERC20.json";
2021-01-31 18:45:46 +00:00
const ETHEREUM_CHAIN_ID: number = 1;
const relayerThreshold: number = 1;
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
2021-01-31 18:45:46 +00:00
const { deploy, execute, read, log } = deployments;
const { deployer } = await getNamedAccounts();
const [signer] = await ethers.getSigners();
const initialRelayers = [deployer];
let sntEthereum: MintableERC20 = new ethers.Contract(
SNT_ADDRESS,
MintableErc20Artifacts.abi,
signer
) as MintableERC20;
const bridgeDeploy: DeployResult = await deploy("Bridge", {
from: deployer,
args: [
ETHEREUM_CHAIN_ID,
initialRelayers,
relayerThreshold,
0,
100
],
log: true
});
const bridge: Bridge = getContractFromDeploy(bridgeDeploy, signer) as Bridge;
const sntEthereumResourceId = createResourceID(SNT_ADDRESS, ETHEREUM_CHAIN_ID);
const erc20HandlerDeploy: DeployResult = await deploy("ERC20Handler", {
from: deployer,
args: [
bridge.address,
[sntEthereumResourceId],
[sntEthereum.address],
[]
],
log: true
});
const erc20Handler: ERC20Handler = getContractFromDeploy(erc20HandlerDeploy, signer) as ERC20Handler;
await bridge.adminSetResource(
erc20Handler.address,
sntEthereumResourceId,
sntEthereum.address
);
};
2021-04-12 18:58:49 +00:00
func.tags = ["ethereum"];
export default func;