Skip to content

Commit

Permalink
add deployment scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
rbajollari committed May 13, 2024
1 parent 083b0cd commit 285d42a
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
37 changes: 37 additions & 0 deletions scripts/createPriceFeed.ts
Original file line number Diff line number Diff line change
@@ -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;
});
36 changes: 36 additions & 0 deletions scripts/deployCloneFactory.ts
Original file line number Diff line number Diff line change
@@ -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;
});
36 changes: 36 additions & 0 deletions scripts/deployPriceFeedImplementation.ts
Original file line number Diff line number Diff line change
@@ -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;
});

0 comments on commit 285d42a

Please sign in to comment.