Skip to content

Commit

Permalink
scripts and contract bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rbajollari committed Oct 10, 2024
1 parent 86e8959 commit 23104a4
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ ASSET_LIMIT=5
PRICE_FEED_DECIMALS=9
PRICE_FEED_DESCRIPTIONS=["steakLRT", "Re7LRT", "amphrETH", "rstETH"]
QUOTED_PRICE_FEEDS=["WETH/ETH", "WETH/USDC"]
MELLOW_PRICE_FEEDS=["amphrETH/wstETH"]
MELLOW_VAULTS=["0x5fD13359Ba15A84B76f7F87568309040176167cd"]
9 changes: 8 additions & 1 deletion contracts/mellowpricefeed/CloneFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@ contract CloneFactory {

/// @notice Create clone of MellowPriceFeed contract and initialize it.
/// @dev Clone method returns address of created clone.
/// @param _vault Address of Mellow LRT vault.
/// @param _priceFeedDecimals Amount of decimals a PriceFeed is denominiated in.
/// @param _priceFeedBase Base asset of PriceFeed, should be set to asset symbol ticker.
/// @param _priceFeedQuote Quote asset of PriceFeed, should be set to asset symbol ticker.
function createMellowPriceFeed(
address _vault,
uint8 _priceFeedDecimals,
string calldata _priceFeedBase,
string calldata _priceFeedQuote
) external {
address mellowPriceFeedCloneAddress = Clones.clone(implementationAddress);
MellowPriceFeed(mellowPriceFeedCloneAddress).initialize(_priceFeedDecimals, _priceFeedBase, _priceFeedQuote);
MellowPriceFeed(mellowPriceFeedCloneAddress).initialize(
_vault,
_priceFeedDecimals,
_priceFeedBase,
_priceFeedQuote
);
MellowPriceFeedCloneAddresses[msg.sender] = mellowPriceFeedCloneAddress;
emit MellowPriceFeedCloneCreated(mellowPriceFeedCloneAddress);
}
Expand Down
23 changes: 10 additions & 13 deletions contracts/mellowpricefeed/MellowPriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract MellowPriceFeed is Initializable, AggregatorV3Interface {

string private priceFeedQuote;

IVault public immutable vault;
IVault public vault;

uint80 constant DEFAULT_ROUND = 1;

Expand All @@ -25,20 +25,19 @@ contract MellowPriceFeed is Initializable, AggregatorV3Interface {

error GetRoundDataCanBeOnlyCalledWithLatestRound(uint80 requestedRoundId);

error UnsafeUintToIntConversion(uint256 value);

constructor(address vault_) {
vault = IVault(vault_);
}

/// @notice Initialize clone of this contract.
/// @dev This function is used in place of a constructor in proxy contracts.
/// @param _vault Address of Mellow LRT vault.
/// @param _priceFeedDecimals Amount of decimals a PriceFeed is denominiated in.
/// @param _priceFeedBase Base asset of PriceFeed.
/// @param _priceFeedQuote Quote asset of PriceFeed.
function initialize(uint8 _priceFeedDecimals, string calldata _priceFeedBase, string calldata _priceFeedQuote)
external
initializer {
function initialize(
address _vault,
uint8 _priceFeedDecimals,
string calldata _priceFeedBase,
string calldata _priceFeedQuote
) external initializer {
vault = IVault(_vault);
priceFeedDecimals = _priceFeedDecimals;
priceFeedBase = _priceFeedBase;
priceFeedQuote = _priceFeedQuote;
Expand Down Expand Up @@ -105,14 +104,12 @@ contract MellowPriceFeed is Initializable, AggregatorV3Interface {
uint80 answeredInRound
) {
roundId = latestRound();
bytes32 baseAssetName = bytes32(bytes(priceFeedBase));
bytes32 quoteAssetName = bytes32(bytes(priceFeedQuote));

IVault.ProcessWithdrawalsStack memory processWithdrawalsStack = vault.calculateStack();

answer = 0;
if (processWithdrawalsStack.totalSupply != 0) {
answer = int256(processWithdrawalsStack.totalSupply) * 1e18 / int256(processWithdrawalsStack.totalSupply);
answer = int256(processWithdrawalsStack.totalValue) * 1e18 / int256(processWithdrawalsStack.totalSupply);
}

// These values are equal after chainlink’s OCR update
Expand Down
16 changes: 12 additions & 4 deletions mainnet_chains.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"priceFeedImplementation": "0xa1aB70C0F3725AcA1D1e85Bd4402Dd2d5F6AFf19",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
"cloneFactory": "0xd285A4F0Ad1BB6b1Db8cD3dD839E9f423938ef9E",
"cloneFactoryQuoted": ""
"cloneFactoryQuoted": "",
"cloneFactoryMellow": ""
},
{
"name": "Optimism",
Expand All @@ -24,8 +26,10 @@
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"priceFeedImplementation": "0xfaC9d315b9b558e10eBdb0462aA42577aADe6601",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
"cloneFactory": "0x02Ed15B70D4dE1209c3Dd5a75195CB3f3dDB8B07",
"cloneFactoryQuoted": ""
"cloneFactoryQuoted": "",
"cloneFactoryMellow": ""
},
{
"name": "Base",
Expand All @@ -38,8 +42,10 @@
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"priceFeedImplementation": "0x09d43904C8ABd470df1B793df68904A9714558CF",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
"cloneFactory": "0xfaC9d315b9b558e10eBdb0462aA42577aADe6601",
"cloneFactoryQuoted": ""
"cloneFactoryQuoted": "",
"cloneFactoryMellow": ""
},
{
"name": "Ethereum",
Expand All @@ -52,7 +58,9 @@
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"priceFeedImplementation": "0xde471274F1B684476d341eB131224F389AD4A270",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
"cloneFactory": "0x710C8a3c8CB393cA24748849de3585b5C48D4D0c",
"cloneFactoryQuoted": ""
"cloneFactoryQuoted": "",
"cloneFactoryMellow": ""
}
]
61 changes: 61 additions & 0 deletions scripts/createMellowPriceFeeds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Wallet, ethers } from "ethers";
import CloneFactory from '../artifacts/contracts/mellowpricefeed/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 mellowPriceFeedDecimals = process.env.PRICE_FEED_DECIMALS as any;
const mellowPriceFeeds = JSON.parse(process.env.MELLOW_PRICE_FEEDS!);
const mellowVaults = JSON.parse(process.env.MELLOW_VAULTS!);

if (mellowPriceFeeds.length !== mellowVaults.length) {
throw new Error('unequal amount of mellowVaults associated with mellowPriceFeeds');
}

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 cloneFactoryMellowContract = new ethers.Contract(chain.cloneFactoryMellow, CloneFactory.abi, wallet)
let i = 0
for (const mellowPriceFeed of mellowPriceFeeds) {
console.log(`Deploying ${mellowPriceFeed} price feed on ${chain.name}`);
try {
const [baseAsset, quoteAsset] = mellowPriceFeed.split('/');

console.log("baseAsset", baseAsset)
console.log("quoteAsset", quoteAsset)
const tx = await cloneFactoryMellowContract.createMellowPriceFeed(mellowPriceFeedDecimals, mellowVaults[i], baseAsset, quoteAsset);
console.log(`Transaction sent: ${tx.hash}`);

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

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
38 changes: 38 additions & 0 deletions scripts/deployMellowCloneFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Wallet, ethers } from "ethers";
import CloneFactoryQuoted from '../artifacts/contracts/mellowpricefeed/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 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 cloneFactoryQuotedFactory = new ethers.ContractFactory(CloneFactoryQuoted.abi, CloneFactoryQuoted.bytecode, wallet)
const cloneFactoryQuoted = await cloneFactoryQuotedFactory.deploy(chain.mellowPriceFeedImplementation)
console.log(`${chain.name}, address: ${await cloneFactoryQuoted.getAddress()}`);
}
}
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
38 changes: 38 additions & 0 deletions scripts/deployMellowPriceFeedImplementation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Wallet, ethers } from "ethers";
import MellowPriceFeed from '../artifacts/contracts/mellowpricefeed/MellowPriceFeed.sol/MellowPriceFeed.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 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 mellowPriceFeedFactory = new ethers.ContractFactory(MellowPriceFeed.abi, MellowPriceFeed.bytecode, wallet)
const mellowPriceFeed = await mellowPriceFeedFactory.deploy()
console.log(`${chain.name}, address: ${await mellowPriceFeed.getAddress()}`);
}
}
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Loading

0 comments on commit 23104a4

Please sign in to comment.