Skip to content

Commit

Permalink
refactor: Update deployment scripts (#47)
Browse files Browse the repository at this point in the history
* refactor: Update deployment scripts

* price feeds script
  • Loading branch information
rbajollari authored Jun 19, 2024
1 parent 4a82a97 commit 3561a3a
Show file tree
Hide file tree
Showing 11 changed files with 310 additions and 148 deletions.
8 changes: 3 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
PRIVATE_KEY=yourprivatekeyhere
CONTRACT_KEY=yourkeyhere
MAINNET=FALSE
OJO_CONTRACT_ADDRESS=0x0
AXELAR_GAS_RECEIVER_ADDRESS=0x2d5d7d31F671F86C782533cc367F14109a082712
CREATE2_DEPLOYER_ADDRESS=0x98b2920d53612483f91f12ed7754e51b4a77919e
EVM_CHAINS=["Ethereum"]
OJO_CHAIN=ojo
OJO_ADDRESS=ojo1es9mhmnunh208ucwq8rlrl97hqulxrz8k37dcu
RESOLVE_WINDOW=7200
ASSET_LIMIT=5
PRICE_FEED_IMPLEMENTATION_CONTRACT_ADDRESS=0xD1077c12ba7C0ED41d288F5505af2Cb23bBD680a
CLONE_FACTORY_CONTRACT_ADDRESS=0x9AaE2ac2637B9f441d1537bBdCEB712854dd426B
PRICE_FEED_DECIMALS=9
PRICE_FEED_DESCRIPTIONS=["steakLRT", "Re7LRT", "amphrETH", "rstETH"]
33 changes: 30 additions & 3 deletions mainnet_chains.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,47 @@
"chainId": 42161,
"gateway": "0xe432150cce91c13a887f7D836923d5597adD8E31",
"rpc": "https://arbitrum-mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161",
"tokenSymbol": "ETH"
"tokenSymbol": "ETH",
"gasReceiver": "0x2d5d7d31F671F86C782533cc367F14109a082712",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"priceFeedImplementation": "0xa1aB70C0F3725AcA1D1e85Bd4402Dd2d5F6AFf19",
"cloneFactory": "0xd285A4F0Ad1BB6b1Db8cD3dD839E9f423938ef9E"
},
{
"name": "Optimism",
"chainId": 10,
"gateway": "0xe432150cce91c13a887f7D836923d5597adD8E31",
"rpc": "https://optimism-mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161",
"tokenSymbol": "ETH"
"tokenSymbol": "ETH",
"gasReceiver": "0x2d5d7d31F671F86C782533cc367F14109a082712",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"priceFeedImplementation": "0xfaC9d315b9b558e10eBdb0462aA42577aADe6601",
"cloneFactory": "0x02Ed15B70D4dE1209c3Dd5a75195CB3f3dDB8B07"
},
{
"name": "Base",
"chainId": 8453,
"gateway": "0xe432150cce91c13a887f7D836923d5597adD8E31",
"rpc": "https://developer-access-mainnet.base.org",
"tokenSymbol": "ETH"
"tokenSymbol": "ETH",
"gasReceiver": "0x2d5d7d31F671F86C782533cc367F14109a082712",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"priceFeedImplementation": "0x09d43904C8ABd470df1B793df68904A9714558CF",
"cloneFactory": "0xfaC9d315b9b558e10eBdb0462aA42577aADe6601"
},
{
"name": "Ethereum",
"chainId": 1,
"gateway": "0x4F4495243837681061C4743b74B3eEdf548D56A5",
"rpc": "https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161",
"tokenSymbol": "ETH",
"gasReceiver": "0x2d5d7d31F671F86C782533cc367F14109a082712",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"priceFeedImplementation": "0xde471274F1B684476d341eB131224F389AD4A270",
"cloneFactory": "0x710C8a3c8CB393cA24748849de3585b5C48D4D0c"
}
]
37 changes: 0 additions & 37 deletions scripts/createPriceFeed.ts

This file was deleted.

50 changes: 50 additions & 0 deletions scripts/createPriceFeeds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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 evmChains = JSON.parse(process.env.EVM_CHAINS!);
const priceFeedDecimals = process.env.PRICE_FEED_DECIMALS as any;
const priceFeedDescriptions = JSON.parse(process.env.PRICE_FEED_DESCRIPTIONS!);

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 = process.env.MAINNET as string
let chains = testnet_chains.map((chain) => ({ ...chain }));
if (mainnet === "TRUE") {
chains = mainnet_chains.map((chain) => ({ ...chain }));
}

for (const chain of chains) {
if (evmChains.includes(chain.name)) {
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(chain.cloneFactory, CloneFactory.abi, wallet)
for (const priceFeedDescription of priceFeedDescriptions) {
console.log(`Deploying ${priceFeedDescription} price feed on ${chain.name}`);
try {
const tx = await cloneFactoryContract.createPriceFeed(priceFeedDecimals, priceFeedDescription);
console.log(`Transaction sent: ${tx.hash}`);

const receipt = await tx.wait();
console.log(`Transaction mined: ${receipt.transactionHash}`);
} catch (error) {
console.error(`Failed to deploy ${priceFeedDescription} on ${chain.name}:`, error);
}
}
}
}
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
24 changes: 13 additions & 11 deletions scripts/deployCloneFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import testnet_chains from '../testnet_chains.json';
import mainnet_chains from '../mainnet_chains.json';

async function main () {
const priceFeedImplementation = process.env.PRICE_FEED_IMPLEMENTATION_CONTRACT_ADDRESS;
const evmChains = JSON.parse(process.env.EVM_CHAINS!);

const privateKey = process.env.PRIVATE_KEY;

Expand All @@ -13,20 +13,22 @@ async function main () {
}

const mainnet = process.env.MAINNET as string
let evmChains = testnet_chains.map((chain) => ({ ...chain }));
let chains = testnet_chains.map((chain) => ({ ...chain }));
if (mainnet === "TRUE") {
evmChains = mainnet_chains.map((chain) => ({ ...chain }));
chains = 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}`);
for (const chain of chains) {
if (evmChains.includes(chain.name)) {
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()}`);
const priceFeedFactory = new ethers.ContractFactory(CloneFactory.abi, CloneFactory.bytecode, wallet)
const priceFeed = await priceFeedFactory.deploy(chain.priceFeedImplementation)
console.log(`${chain.name}, address: ${await priceFeed.getAddress()}`);
}
}
}

Expand Down
39 changes: 20 additions & 19 deletions scripts/deployMockOjo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import testnet_chains from '../testnet_chains.json';
import mainnet_chains from '../mainnet_chains.json';

async function main() {
const ojoContractddress = process.env.OJO_CONTRACT_ADDRESS;
const create2DeployerAddress = process.env.CREATE2_DEPLOYER_ADDRESS as string;
const evmChains = JSON.parse(process.env.EVM_CHAINS!);

const privateKey = process.env.PRIVATE_KEY;

Expand All @@ -15,32 +14,34 @@ async function main() {
}

const mainnet = process.env.MAINNET as string
let evmChains = testnet_chains.map((chain) => ({ ...chain }));
let chains = testnet_chains.map((chain) => ({ ...chain }));
if (mainnet === "TRUE") {
evmChains = mainnet_chains.map((chain) => ({ ...chain }));
chains = 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}`);
for (const chain of chains) {
if (evmChains.includes(chain.name)) {
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 deployerContract = new ethers.Contract(create2DeployerAddress, Create2Deployer.abi, wallet);
const deployerContract = new ethers.Contract(chain.create2Deployer, Create2Deployer.abi, wallet);

const salt = ethers.zeroPadValue(ethers.toUtf8Bytes("MockOjo"), 32);
const salt = ethers.zeroPadValue(ethers.toUtf8Bytes("MockOjo"), 32);

const creationCode = ethers.solidityPacked(
const creationCode = ethers.solidityPacked(
["bytes", "bytes"],
[MockOjo.bytecode, ethers.AbiCoder.defaultAbiCoder().encode(["address"], [ojoContractddress])]
);
[MockOjo.bytecode, ethers.AbiCoder.defaultAbiCoder().encode(["address"], [chain.ojoContract])]
);

// perform static call to log address of the contract
const deployedAddress = await deployerContract.deploy.staticCallResult(creationCode, salt);
console.log(`${chain.name}, address: ${deployedAddress}`);
// perform static call to log address of the contract
const deployedAddress = await deployerContract.deploy.staticCallResult(creationCode, salt);
console.log(`${chain.name}, address: ${deployedAddress}`);

// perform actual deploy tx
await deployerContract.deploy(creationCode, salt);
// perform actual deploy tx
await deployerContract.deploy(creationCode, salt);
}
}
}

Expand Down
62 changes: 37 additions & 25 deletions scripts/deployOjo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import Ojo from '../artifacts/contracts/Ojo.sol/Ojo.json';
import OjoProxy from '../artifacts/contracts/OjoProxy.sol/OjoProxy.json';
import testnet_chains from '../testnet_chains.json';
import mainnet_chains from '../mainnet_chains.json';
import { deployCreate2InitUpgradable } from './utils/upgradable';
import { deployCreate2InitUpgradable, estimateDeploymentGas } from './utils/upgradable';

async function main() {
const axelarGasReceiverAddress = process.env.AXELAR_GAS_RECEIVER_ADDRESS;
const create2DeployerAddress = process.env.CREATE2_DEPLOYER_ADDRESS;
const evmChains = JSON.parse(process.env.EVM_CHAINS!);
const ojoChain = process.env.OJO_CHAIN;
const ojoAddress = process.env.OJO_ADDRESS;
const resolveWindow = Number(process.env.RESOLVE_WINDOW);
const assetLimit = Number(process.env.ASSET_LIMIT);

Expand All @@ -20,30 +18,44 @@ async function main() {
}

const mainnet = process.env.MAINNET as string
let evmChains = testnet_chains.map((chain) => ({ ...chain }));
let chains = testnet_chains.map((chain) => ({ ...chain }));
if (mainnet === "TRUE") {
evmChains = mainnet_chains.map((chain) => ({ ...chain }));
chains = mainnet_chains.map((chain) => ({ ...chain }));
}

const key = Number(process.env.PRIVATE_KEY);

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 deployedContract = await deployCreate2InitUpgradable(
create2DeployerAddress,
wallet,
Ojo,
OjoProxy,
[chain.gateway, axelarGasReceiverAddress],
ethers.AbiCoder.defaultAbiCoder().encode(["string", "string", "uint256", "uint16"],[ojoChain, ojoAddress, resolveWindow, assetLimit]),
key
);

console.log(`${chain.name}, address: ${await deployedContract.getAddress()}`);
const key = Number(process.env.CONTRACT_KEY);

for (const chain of chains) {
if (evmChains.includes(chain.name)) {
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 feeData = await provider.getFeeData();
const gasPrice = feeData.maxFeePerGas ?? feeData.gasPrice;
if (!gasPrice) {
throw new Error('Unable to retrieve gas price');
}
const estimatedGas = await estimateDeploymentGas(wallet, Ojo, [chain.gateway, chain.gasReceiver]);
const deploymentCost = estimatedGas * gasPrice;

if (balance < deploymentCost) {
throw new Error(`Insufficient funds in wallet for deploying on ${chain.name}, deploymentCost: ${ethers.formatEther(deploymentCost.toString())} ${chain.tokenSymbol}`);
}

const deployedContract = await deployCreate2InitUpgradable(
chain.create2Deployer,
wallet,
Ojo,
OjoProxy,
[chain.gateway, chain.gasReceiver],
ethers.AbiCoder.defaultAbiCoder().encode(["string", "string", "uint256", "uint16"],[ojoChain, chain.ojoContract, resolveWindow, assetLimit]),
key
);

console.log(`${chain.name}, address: ${await deployedContract.getAddress()}`);
}
}
}

Expand Down
24 changes: 13 additions & 11 deletions scripts/deployPriceFeedImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import testnet_chains from '../testnet_chains.json';
import mainnet_chains from '../mainnet_chains.json';

async function main() {
const ojoAddress = process.env.OJO_CONTRACT_ADDRESS;
const evmChains = JSON.parse(process.env.EVM_CHAINS!);

const privateKey = process.env.PRIVATE_KEY;

Expand All @@ -13,20 +13,22 @@ async function main() {
}

const mainnet = process.env.MAINNET as string
let evmChains = testnet_chains.map((chain) => ({ ...chain }));
let chains = testnet_chains.map((chain) => ({ ...chain }));
if (mainnet === "TRUE") {
evmChains = mainnet_chains.map((chain) => ({ ...chain }));
chains = 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}`);
for (const chain of chains) {
if (evmChains.includes(chain.name)) {
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()}`);
const priceFeedFactory = new ethers.ContractFactory(PriceFeed.abi, PriceFeed.bytecode, wallet)
const priceFeed = await priceFeedFactory.deploy(chain.ojoContract)
console.log(`${chain.name}, address: ${await priceFeed.getAddress()}`);
}
}
}

Expand Down
Loading

0 comments on commit 3561a3a

Please sign in to comment.