diff --git a/constants/goerliAddress.ts b/constants/goerliAddress.ts new file mode 100644 index 0000000..d3db51c --- /dev/null +++ b/constants/goerliAddress.ts @@ -0,0 +1 @@ +export const SNT_ADDRESS = '0x86e5C5c884740894644dAD30021aAaAdE2B7bAbd'; diff --git a/deploy/Bridge.ts b/deploy/Bridge.ts index b810ec3..aa96f7f 100644 --- a/deploy/Bridge.ts +++ b/deploy/Bridge.ts @@ -1,15 +1,64 @@ import {HardhatRuntimeEnvironment} from 'hardhat/types'; -import {DeployFunction} from 'hardhat-deploy/types'; -const {deployments, getNamedAccounts} = require('hardhat'); +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"; + +const ETHEREUM_CHAIN_ID: number = 1; +const relayerThreshold: number = 1; const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { - const { deploy, execute, read, log } = deployments; - const { deployer } = await getNamedAccounts(); + const { deploy, execute, read, log } = deployments; + const { deployer } = await getNamedAccounts(); + const [signer] = await ethers.getSigners(); - await deploy("Bridge", { - from: deployer, - args: ["1", [], "1", "0", "0"], - log: true - }); + 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 + ); }; export default func; diff --git a/test/Bridge.ts b/test/Bridge.ts index bc45273..71eaa13 100644 --- a/test/Bridge.ts +++ b/test/Bridge.ts @@ -1,5 +1,5 @@ -import { ethers, } from "hardhat"; -import { BigNumber, Bytes, BytesLike, Signer } from "ethers"; +import { ethers } from "hardhat"; +import { BigNumber, Signer } from "ethers"; import chai from "chai"; import { solidity } from "ethereum-waffle"; diff --git a/utils/deploy.ts b/utils/deploy.ts new file mode 100644 index 0000000..534e338 --- /dev/null +++ b/utils/deploy.ts @@ -0,0 +1,10 @@ +import { Contract, Signer } from "ethers"; +import { DeployResult } from 'hardhat-deploy/types'; + +export function getContractFromDeploy(deploy: DeployResult, signer: Signer) { + return new Contract( + deploy.address, + deploy.abi, + signer + ); +}