From c2dfae64387c8fb4ab249fb34a5b021b0e7f1000 Mon Sep 17 00:00:00 2001 From: pradyuman-verma Date: Mon, 6 Dec 2021 01:34:41 +0530 Subject: [PATCH] refactored scripts/* --- scripts/tests/buildDSAv2.ts | 14 ++++++++-- scripts/tests/deployAndEnableConnector.ts | 13 ++++++++-- scripts/tests/getMasterSigner.ts | 12 +++++++-- scripts/tests/mainnet/addresses.ts | 11 ++++++++ scripts/tests/mainnet/constant.ts | 6 +++++ scripts/tests/mainnet/tokens.ts | 23 ++++++++++++++++ .../addresses.ts => addressesPolygon.ts} | 2 +- scripts/tests/polygon/buildDSAv2.ts | 19 -------------- .../tests/polygon/{constant => }/constant.ts | 0 .../tests/polygon/deployAndEnableConnector.ts | 26 ------------------- scripts/tests/polygon/encodeSpells.ts | 17 ------------ scripts/tests/polygon/getMasterSigner.ts | 24 ----------------- .../tests/polygon/{constant => }/tokens.ts | 0 13 files changed, 74 insertions(+), 93 deletions(-) create mode 100644 scripts/tests/mainnet/addresses.ts create mode 100644 scripts/tests/mainnet/constant.ts create mode 100644 scripts/tests/mainnet/tokens.ts rename scripts/tests/polygon/{constant/addresses.ts => addressesPolygon.ts} (89%) delete mode 100644 scripts/tests/polygon/buildDSAv2.ts rename scripts/tests/polygon/{constant => }/constant.ts (100%) delete mode 100644 scripts/tests/polygon/deployAndEnableConnector.ts delete mode 100644 scripts/tests/polygon/encodeSpells.ts delete mode 100644 scripts/tests/polygon/getMasterSigner.ts rename scripts/tests/polygon/{constant => }/tokens.ts (100%) diff --git a/scripts/tests/buildDSAv2.ts b/scripts/tests/buildDSAv2.ts index 0820b14e..aa97a026 100644 --- a/scripts/tests/buildDSAv2.ts +++ b/scripts/tests/buildDSAv2.ts @@ -1,13 +1,23 @@ import { ethers } from "hardhat"; -import { addresses } from "../constant/addresses"; +const network = String(process.env.networkType); + +import { addressesPolygon } from "./polygon/addressesPolygon"; +import { addresses } from "./mainnet/addresses"; import { abis } from "../constant/abis"; import { abi } from "../../deployements/mainnet/Implementation_m1.sol/InstaImplementationM1.json"; +function getAddress(network: string | undefined) { + if (network === "polygon") return addressesPolygon.core.instaIndex; + // else if (network === "arbitrum") return addressesPolygon.core.instaIndex; + // else if (network === "avalanche") return addressesPolygon.core.instaIndex; + else return addresses.core.instaIndex; +} + export async function buildDSAv2(owner: any) { const instaIndex = await ethers.getContractAt( abis.core.instaIndex, - addresses.core.instaIndex + getAddress(String(process.env.networkType)) ); const tx = await instaIndex.build(owner, 2, owner); diff --git a/scripts/tests/deployAndEnableConnector.ts b/scripts/tests/deployAndEnableConnector.ts index 362277f2..3c60a814 100644 --- a/scripts/tests/deployAndEnableConnector.ts +++ b/scripts/tests/deployAndEnableConnector.ts @@ -1,4 +1,5 @@ -import { addresses } from "../constant/addresses"; +import { addressesPolygon } from "./polygon/addressesPolygon"; +import { addresses } from "./mainnet/addresses"; import { abis } from "../constant/abis"; // const { deployContract } = waffle; @@ -6,6 +7,13 @@ import { abis } from "../constant/abis"; // import { promises as fs } from "fs"; // import { deployContract } from "ethereum-waffle"; +function getAddress(network: string | undefined) { + if (network === "polygon") return addressesPolygon; + // else if (network === "arbitrum") return addressesPolygon; + // else if (network === "avalanche") return addressesPolygon; + else return addresses; +} + export async function deployAndEnableConnector({ connectorName, contractArtifact, @@ -19,7 +27,8 @@ export async function deployAndEnableConnector({ .connect(signer) .addConnectors([connectorName], [connectorInstanace.address]); - addresses.connectors[connectorName] = connectorInstanace.address; + getAddress(String(process.env.networkType)).connectors[connectorName] = + connectorInstanace.address; abis.connectors[connectorName] = contractArtifact.abi; return connectorInstanace; diff --git a/scripts/tests/getMasterSigner.ts b/scripts/tests/getMasterSigner.ts index 59f59afb..b6f2bef7 100644 --- a/scripts/tests/getMasterSigner.ts +++ b/scripts/tests/getMasterSigner.ts @@ -1,11 +1,19 @@ import { ethers, network } from "hardhat"; -import { addresses } from "../constant/addresses"; +import { addressesPolygon } from "./polygon/addressesPolygon"; +import { addresses } from "./mainnet/addresses"; import { abis } from "../constant/abis"; +function getAddress(network: string | undefined) { + if (network === "polygon") return addressesPolygon.core.instaIndex; + // else if (network === "arbitrum") return addressesPolygon.core.instaIndex; + // else if (network === "avalanche") return addressesPolygon.core.instaIndex; + else return addresses.core.instaIndex; +} + export async function getMasterSigner() { const [_, __, ___, wallet3] = await ethers.getSigners(); const instaIndex = new ethers.Contract( - addresses.core.instaIndex, + getAddress(String(process.env.networkType)), abis.core.instaIndex, wallet3 ); diff --git a/scripts/tests/mainnet/addresses.ts b/scripts/tests/mainnet/addresses.ts new file mode 100644 index 00000000..28b6afec --- /dev/null +++ b/scripts/tests/mainnet/addresses.ts @@ -0,0 +1,11 @@ +export const addresses = { + connectors: { + basic: "0xe5398f279175962E56fE4c5E0b62dc7208EF36c6", + auth: "0xd1aff9f2acf800c876c409100d6f39aea93fc3d9", + "INSTAPOOL-A": "0x5806af7ab22e2916fa582ff05731bf7c682387b2", + }, + core: { + connectorsV2: "0x97b0B3A8bDeFE8cB9563a3c610019Ad10DB8aD11", + instaIndex: "0x2971AdFa57b20E5a416aE5a708A8655A9c74f723", + }, +}; diff --git a/scripts/tests/mainnet/constant.ts b/scripts/tests/mainnet/constant.ts new file mode 100644 index 00000000..9e659d77 --- /dev/null +++ b/scripts/tests/mainnet/constant.ts @@ -0,0 +1,6 @@ +export const constants = { + address_zero: "0x0000000000000000000000000000000000000000", + native_address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", + max_value: + "115792089237316195423570985008687907853269984665640564039457584007913129639935", +}; diff --git a/scripts/tests/mainnet/tokens.ts b/scripts/tests/mainnet/tokens.ts new file mode 100644 index 00000000..d3c95180 --- /dev/null +++ b/scripts/tests/mainnet/tokens.ts @@ -0,0 +1,23 @@ +export const tokens = { + eth: { + type: "token", + symbol: "ETH", + name: "Ethereum", + address: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + decimals: 18, + }, + dai: { + type: "token", + symbol: "DAI", + name: "DAI Stable", + address: "0x6B175474E89094C44Da98b954EedeAC495271d0F", + decimals: 18, + }, + usdc: { + type: "token", + symbol: "USDC", + name: "USD Coin", + address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", + decimals: 6, + }, +}; diff --git a/scripts/tests/polygon/constant/addresses.ts b/scripts/tests/polygon/addressesPolygon.ts similarity index 89% rename from scripts/tests/polygon/constant/addresses.ts rename to scripts/tests/polygon/addressesPolygon.ts index d60133c0..2ad864c3 100644 --- a/scripts/tests/polygon/constant/addresses.ts +++ b/scripts/tests/polygon/addressesPolygon.ts @@ -1,4 +1,4 @@ -export const addresses = { +export const addressesPolygon = { connectors: { basic: "0x1cAF5EC802ca602E98139AD96A8f2B7BC524264E", auth: "0xf6474aD0dA75A0dE15D2c915e601D9f754B9e6fe", diff --git a/scripts/tests/polygon/buildDSAv2.ts b/scripts/tests/polygon/buildDSAv2.ts deleted file mode 100644 index 3c7b81f7..00000000 --- a/scripts/tests/polygon/buildDSAv2.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { ethers } from "hardhat"; - -import { addresses } from "./constant/addresses"; -import { abis } from "../../constant/abis"; -import { abi } from "../../../deployements/mainnet/Implementation_m1.sol/InstaImplementationM1.json"; - -module.exports = async function(owner: any) { - const instaIndex = await ethers.getContractAt( - abis.core.instaIndex, - addresses.core.instaIndex - ); - - const tx = await instaIndex.build(owner, 2, owner); - const receipt = await tx.wait(); - const event = receipt.events.find( - (a: { event: string }) => a.event === "LogAccountCreated" - ); - return await ethers.getContractAt(abi, event.args.account); -}; diff --git a/scripts/tests/polygon/constant/constant.ts b/scripts/tests/polygon/constant.ts similarity index 100% rename from scripts/tests/polygon/constant/constant.ts rename to scripts/tests/polygon/constant.ts diff --git a/scripts/tests/polygon/deployAndEnableConnector.ts b/scripts/tests/polygon/deployAndEnableConnector.ts deleted file mode 100644 index 355da3ac..00000000 --- a/scripts/tests/polygon/deployAndEnableConnector.ts +++ /dev/null @@ -1,26 +0,0 @@ -import "@nomiclabs/hardhat-waffle"; - -import { addresses } from "./constant/addresses"; -import { abis } from "../../constant/abis"; - -import * as hre from "hardhat"; -const { ethers, waffle } = hre; -const { deployContract } = waffle; - -module.exports = async function({ - connectorName, - contractArtifact, - signer, - connectors, -}) { - const connectorInstanace = await deployContract(signer, contractArtifact, []); - - await connectors - .connect(signer) - .addConnectors([connectorName], [connectorInstanace.address]); - - addresses.connectors[connectorName] = connectorInstanace.address; - abis.connectors[connectorName] = contractArtifact.abi; - - return connectorInstanace; -}; diff --git a/scripts/tests/polygon/encodeSpells.ts b/scripts/tests/polygon/encodeSpells.ts deleted file mode 100644 index d35b4277..00000000 --- a/scripts/tests/polygon/encodeSpells.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { abis } from "../../constant/abis"; -import { web3 } from "hardhat"; - -export function encodeSpells(spells: any[]) { - const targets = spells.map((a) => a.connector); - const calldatas = spells.map((a) => { - const functionName = a.method; - // console.log(functionName) - const abi = abis.connectors[a.connector].find((b: { name: any }) => { - return b.name === functionName; - }); - // console.log(functionName) - if (!abi) throw new Error("Couldn't find function"); - return web3.eth.abi.encodeFunctionCall(abi, a.args); - }); - return [targets, calldatas]; -} diff --git a/scripts/tests/polygon/getMasterSigner.ts b/scripts/tests/polygon/getMasterSigner.ts deleted file mode 100644 index 43cf5e12..00000000 --- a/scripts/tests/polygon/getMasterSigner.ts +++ /dev/null @@ -1,24 +0,0 @@ -const { ethers, network } = "hardhat"; -import { addresses } from "./constant/addresses"; -import { abis } from "../../constant/abis"; - -module.exports = async function() { - const [_, __, ___, wallet3] = await ethers.getSigners(); - const instaIndex = new ethers.Contract( - addresses.core.instaIndex, - abis.core.instaIndex, - wallet3 - ); - - const masterAddress = await instaIndex.master(); // TODO: make it constant? - await network.provider.request({ - method: "hardhat_impersonateAccount", - params: [masterAddress], - }); - await wallet3.sendTransaction({ - to: masterAddress, - value: ethers.utils.parseEther("10"), - }); - - return await ethers.getSigner(masterAddress); -}; diff --git a/scripts/tests/polygon/constant/tokens.ts b/scripts/tests/polygon/tokens.ts similarity index 100% rename from scripts/tests/polygon/constant/tokens.ts rename to scripts/tests/polygon/tokens.ts