diff --git a/scripts/createPriceFeed.ts b/scripts/createPriceFeed.ts new file mode 100644 index 0000000..362e37f --- /dev/null +++ b/scripts/createPriceFeed.ts @@ -0,0 +1,37 @@ +import { Wallet, ethers } from "ethers"; +import CloneFactory from '../artifacts/contracts/pricefeed/CloneFactory.sol/CloneFactory.json'; +import testnet_chains from '../testnet_chains.json'; +import mainnet_chains from '../mainnet_chains.json'; + +async function main() { + const cloneFactoryAddress = process.env.CLONE_FACTORY_ADDRESS as string; + const priceFeedDecimals = 18; + const priceFeedDescription = "ETH"; + + const privateKey = process.env.PRIVATE_KEY; + + if (!privateKey) { + throw new Error('Invalid private key. Make sure the PRIVATE_KEY environment variable is set.'); + } + + const mainnet = Boolean(process.env.MAINNET) + let evmChains = testnet_chains.map((chain) => ({ ...chain })); + if (mainnet === true) { + evmChains = mainnet_chains.map((chain) => ({ ...chain })); + } + + for (const chain of evmChains) { + const provider = new ethers.JsonRpcProvider(chain.rpc) + const wallet = new Wallet(privateKey, provider); + const balance = await provider.getBalance(wallet.address) + console.log(`${chain.name} wallet balance: ${ethers.formatEther(balance.toString())} ${chain.tokenSymbol}`); + + const cloneFactoryContract = new ethers.Contract(cloneFactoryAddress, CloneFactory.abi, wallet) + await cloneFactoryContract.createPriceFeed(priceFeedDecimals, priceFeedDescription) + } +} + +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/scripts/deployCloneFactory.ts b/scripts/deployCloneFactory.ts new file mode 100644 index 0000000..d78f813 --- /dev/null +++ b/scripts/deployCloneFactory.ts @@ -0,0 +1,36 @@ +import { Wallet, ethers } from "ethers"; +import CloneFactory from '../artifacts/contracts/pricefeed/CloneFactory.sol/CloneFactory.json'; +import testnet_chains from '../testnet_chains.json'; +import mainnet_chains from '../mainnet_chains.json'; + +async function main () { + const priceFeedImplementation = process.env.PRICE_FEED_IMPLEMENTATION_ADDRESS; + + const privateKey = process.env.PRIVATE_KEY; + + if (!privateKey) { + throw new Error('Invalid private key. Make sure the PRIVATE_KEY environment variable is set.'); + } + + const mainnet = Boolean(process.env.MAINNET) + let evmChains = testnet_chains.map((chain) => ({ ...chain })); + if (mainnet === true) { + evmChains = mainnet_chains.map((chain) => ({ ...chain })); + } + + for (const chain of evmChains) { + const provider = new ethers.JsonRpcProvider(chain.rpc) + const wallet = new Wallet(privateKey, provider); + const balance = await provider.getBalance(wallet.address) + console.log(`${chain.name} wallet balance: ${ethers.formatEther(balance.toString())} ${chain.tokenSymbol}`); + + const priceFeedFactory = new ethers.ContractFactory(CloneFactory.abi, CloneFactory.bytecode, wallet) + const priceFeed = await priceFeedFactory.deploy(priceFeedImplementation) + console.log(`${chain.name}, address: ${await priceFeed.getAddress()}`); + } +} + +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/scripts/deployPriceFeedImplementation.ts b/scripts/deployPriceFeedImplementation.ts new file mode 100644 index 0000000..77368ec --- /dev/null +++ b/scripts/deployPriceFeedImplementation.ts @@ -0,0 +1,36 @@ +import { Wallet, ethers } from "ethers"; +import PriceFeed from '../artifacts/contracts/pricefeed/PriceFeed.sol/PriceFeed.json'; +import testnet_chains from '../testnet_chains.json'; +import mainnet_chains from '../mainnet_chains.json'; + +async function main() { + const ojoAddress = process.env.OJO_ADDRESS; + + const privateKey = process.env.PRIVATE_KEY; + + if (!privateKey) { + throw new Error('Invalid private key. Make sure the PRIVATE_KEY environment variable is set.'); + } + + const mainnet = Boolean(process.env.MAINNET) + let evmChains = testnet_chains.map((chain) => ({ ...chain })); + if (mainnet === true) { + evmChains = mainnet_chains.map((chain) => ({ ...chain })); + } + + for (const chain of evmChains) { + const provider = new ethers.JsonRpcProvider(chain.rpc) + const wallet = new Wallet(privateKey, provider); + const balance = await provider.getBalance(wallet.address) + console.log(`${chain.name} wallet balance: ${ethers.formatEther(balance.toString())} ${chain.tokenSymbol}`); + + const priceFeedFactory = new ethers.ContractFactory(PriceFeed.abi, PriceFeed.bytecode, wallet) + const priceFeed = await priceFeedFactory.deploy(ojoAddress) + console.log(`${chain.name}, address: ${await priceFeed.getAddress()}`); + } +} + +main().catch((error) => { + console.error(error); + process.exitCode = 1; +});