Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'development' into fix/always-permission-per
Browse files Browse the repository at this point in the history
  • Loading branch information
rhlsthrm committed Aug 19, 2024
2 parents 7c3f513 + 0ac137c commit cbec863
Show file tree
Hide file tree
Showing 39 changed files with 12,605 additions and 4,284 deletions.
152 changes: 52 additions & 100 deletions chainDeploy/helpers/oracles/chainlink.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { addTransaction } from "../logging";
import { prepareAndLogTransaction } from "../logging";

import { addUnderlyingsToMpo } from "./utils";
import { Address, encodeFunctionData } from "viem";
import { Address, Hex, zeroAddress } from "viem";
import { underlying } from "../utils";
import { ChainlinkFeedBaseCurrency } from "../../../../monorepo/packages/types";
import { ChainlinkDeployFnParams } from "../../types";
Expand All @@ -12,29 +12,31 @@ export const deployChainlinkOracle = async ({
deployments,
deployConfig,
assets,
chainlinkAssets
chainlinkAssets,
namePostfix
}: ChainlinkDeployFnParams): Promise<{ cpo: any; chainLinkv2: any }> => {
const { deployer } = await getNamedAccounts();
const publicClient = await viem.getPublicClient();
const walletClient = await viem.getWalletClient(deployer as Address);
let tx;
let tx: Hex;

//// Chainlink Oracle

const contractName = ["ChainlinkPriceOracleV2", namePostfix].join("_");

console.log("deployConfig.stableToken: ", deployConfig.stableToken);
console.log("deployConfig.nativeTokenUsdChainlinkFeed: ", deployConfig.nativeTokenUsdChainlinkFeed);
const cpo = await deployments.deploy("ChainlinkPriceOracleV2", {
const cpo = await deployments.deploy(contractName, {
contract: "ChainlinkPriceOracleV2",
from: deployer,
args: [],
log: true,
proxy: {
execute: {
init: {
methodName: "initialize",
args: [deployConfig.stableToken, deployConfig.nativeTokenUsdChainlinkFeed]
args: [deployConfig.stableToken, zeroAddress]
}
},
owner: deployer,
proxyContract: "OpenZeppelinTransparentProxy"
},
waitConfirmations: 1
Expand All @@ -44,7 +46,7 @@ export const deployChainlinkOracle = async ({

const chainLinkv2 = await viem.getContractAt(
"ChainlinkPriceOracleV2",
(await deployments.get("ChainlinkPriceOracleV2")).address as Address
(await deployments.get(contractName)).address as Address
);

const chainlinkAssetsToChange = [];
Expand Down Expand Up @@ -75,37 +77,20 @@ export const deployChainlinkOracle = async ({
await publicClient.waitForTransactionReceipt({ hash: tx });
console.log(`Set ${usdBasedFeeds.length} USD price feeds for ChainlinkPriceOracleV2 at ${tx}`);
} else {
const tx = await walletClient.prepareTransactionRequest({
account: (await chainLinkv2.read.owner()) as Address,
to: chainLinkv2.address,
data: encodeFunctionData({
abi: chainLinkv2.abi,
functionName: "setPriceFeeds",
args: [
usdBasedFeeds.map((c) => underlying(assets, c.symbol)),
usdBasedFeeds.map((c) => c.aggregator),
feedCurrency
]
})
});
addTransaction({
to: tx.to,
value: tx.value ? tx.value.toString() : "0",
data: null,
contractMethod: {
inputs: [
{ internalType: "address[]", name: "underlyings", type: "address[]" },
{ internalType: "address[]", name: "feeds", type: "address[]" },
{ internalType: "uint8", name: "baseCurrency", type: "uint8" }
],
name: "setPriceFeeds",
payable: false
},
contractInputsValues: {
underlyings: usdBasedFeeds.map((c) => underlying(assets, c.symbol)),
feeds: usdBasedFeeds.map((c) => c.aggregator),
baseCurrency: feedCurrency
}
await prepareAndLogTransaction({
contractInstance: chainLinkv2,
description: `Set ${usdBasedFeeds.length} USD price feeds for ChainlinkPriceOracleV2`,
functionName: "setPriceFeeds",
args: [
usdBasedFeeds.map((c) => underlying(assets, c.symbol)),
usdBasedFeeds.map((c) => c.aggregator),
feedCurrency
],
inputs: [
{ internalType: "address[]", name: "underlyings", type: "address[]" },
{ internalType: "address[]", name: "feeds", type: "address[]" },
{ internalType: "uint8", name: "baseCurrency", type: "uint8" }
]
});
console.log(`Logged Transaction to set ${usdBasedFeeds.length} USD price feeds for ChainlinkPriceOracleV2`);
}
Expand All @@ -121,37 +106,20 @@ export const deployChainlinkOracle = async ({
await publicClient.waitForTransactionReceipt({ hash: tx });
console.log(`Set ${ethBasedFeeds.length} native price feeds for ChainlinkPriceOracleV2`);
} else {
tx = await walletClient.prepareTransactionRequest({
account: (await chainLinkv2.read.owner()) as Address,
to: chainLinkv2.address,
data: encodeFunctionData({
abi: chainLinkv2.abi,
functionName: "setPriceFeeds",
args: [
ethBasedFeeds.map((c) => underlying(assets, c.symbol)),
ethBasedFeeds.map((c) => c.aggregator),
feedCurrency
]
})
});
addTransaction({
to: tx.to,
value: tx.value ? tx.value.toString() : "0",
data: null,
contractMethod: {
inputs: [
{ internalType: "address[]", name: "underlyings", type: "address[]" },
{ internalType: "address[]", name: "feeds", type: "address[]" },
{ internalType: "uint8", name: "baseCurrency", type: "uint8" }
],
name: "setPriceFeeds",
payable: false
},
contractInputsValues: {
underlyings: ethBasedFeeds.map((c) => underlying(assets, c.symbol)),
feeds: ethBasedFeeds.map((c) => c.aggregator),
baseCurrency: feedCurrency
}
await prepareAndLogTransaction({
contractInstance: chainLinkv2,
description: `Set ${ethBasedFeeds.length} USD price feeds for ChainlinkPriceOracleV2`,
functionName: "setPriceFeeds",
args: [
ethBasedFeeds.map((c) => underlying(assets, c.symbol)),
ethBasedFeeds.map((c) => c.aggregator),
feedCurrency
],
inputs: [
{ internalType: "address[]", name: "underlyings", type: "address[]" },
{ internalType: "address[]", name: "feeds", type: "address[]" },
{ internalType: "uint8", name: "baseCurrency", type: "uint8" }
]
});
console.log(`Logged Transaction to set ${ethBasedFeeds.length} ETH price feeds for ChainlinkPriceOracleV2`);
}
Expand All @@ -163,44 +131,28 @@ export const deployChainlinkOracle = async ({
"MasterPriceOracle",
(await deployments.get("MasterPriceOracle")).address as Address
);
await addUnderlyingsToMpo(mpo as any, underlyings, chainLinkv2.address, deployer, publicClient, walletClient);
await addUnderlyingsToMpo(mpo as any, underlyings, chainLinkv2.address, deployer, publicClient);

const addressesProvider = await viem.getContractAt(
"AddressesProvider",
(await deployments.get("AddressesProvider")).address as Address
);
const chainLinkv2Address = await addressesProvider.read.getAddress(["ChainlinkPriceOracleV2"]);
const chainLinkv2Address = await addressesProvider.read.getAddress([contractName]);
if (chainLinkv2Address !== chainLinkv2.address) {
if (((await addressesProvider.read.owner()) as Address).toLowerCase() === deployer.toLowerCase()) {
tx = await addressesProvider.write.setAddress(["ChainlinkPriceOracleV2", chainLinkv2.address]);
tx = await addressesProvider.write.setAddress([contractName, chainLinkv2.address]);
await publicClient.waitForTransactionReceipt({ hash: tx });
console.log(`setAddress ChainlinkPriceOracleV2 at ${tx}`);
console.log(`setAddress ${contractName} at ${tx}`);
} else {
tx = await walletClient.prepareTransactionRequest({
account: (await addressesProvider.read.owner()) as Address,
to: addressesProvider.address,
data: encodeFunctionData({
abi: addressesProvider.abi,
functionName: "setAddress",
args: ["ChainlinkPriceOracleV2", chainLinkv2.address]
})
});
addTransaction({
to: tx.to,
value: tx.value ? tx.value.toString() : "0",
data: null,
contractMethod: {
inputs: [
{ internalType: "string", name: "id", type: "string" },
{ internalType: "address", name: "newAddress", type: "address" }
],
name: "setAddress",
payable: false
},
contractInputsValues: {
id: "ChainlinkPriceOracleV2",
newAddress: chainLinkv2.address
}
await prepareAndLogTransaction({
contractInstance: addressesProvider,
description: `setAddress ${contractName}`,
functionName: "setAddress",
args: [contractName, chainLinkv2.address],
inputs: [
{ internalType: "string", name: "id", type: "string" },
{ internalType: "address", name: "newAddress", type: "address" }
]
});
console.log("Logged Transaction to setAddress ChainlinkPriceOracleV2 on AddressProvider");
}
Expand Down
82 changes: 33 additions & 49 deletions chainDeploy/helpers/oracles/pyth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, encodeFunctionData, GetContractReturnType, WalletClient } from "viem";

import { addTransaction } from "../logging";
import { addTransaction, prepareAndLogTransaction } from "../logging";
import { pythPriceOracleAbi } from "../../../generated";

import { addUnderlyingsToMpo } from "./utils";
Expand All @@ -24,30 +24,30 @@ export const deployPythPriceOracle = async ({
(await deployments.get("MasterPriceOracle")).address as Address
);

//// Pyth Oracle
const pyth = await deployments.deploy("PythPriceOracle", {
from: deployer,
args: [],
log: true,
proxy: {
execute: {
init: {
methodName: "initialize",
args: [pythAddress, nativeTokenUsdFeed, usdToken]
},
onUpgrade: {
methodName: "reinitialize",
args: [pythAddress, nativeTokenUsdFeed, usdToken]
}
},
owner: deployer,
proxyContract: "OpenZeppelinTransparentProxy"
},
waitConfirmations: 1
});
// //// Pyth Oracle
// const pyth = await deployments.deploy("PythPriceOracle", {
// from: deployer,
// args: [],
// log: true,
// proxy: {
// execute: {
// init: {
// methodName: "initialize",
// args: [pythAddress, nativeTokenUsdFeed, usdToken]
// },
// onUpgrade: {
// methodName: "reinitialize",
// args: [pythAddress, nativeTokenUsdFeed, usdToken]
// }
// },
// owner: deployer,
// proxyContract: "OpenZeppelinTransparentProxy"
// },
// waitConfirmations: 1
// });

if (pyth.transactionHash) publicClient.waitForTransactionReceipt({ hash: pyth.transactionHash as Address });
console.log("PythPriceOracle: ", pyth.address);
// if (pyth.transactionHash) publicClient.waitForTransactionReceipt({ hash: pyth.transactionHash as Address });
// console.log("PythPriceOracle: ", pyth.address);

const pythOracle = await viem.getContractAt(
"PythPriceOracle",
Expand All @@ -70,31 +70,15 @@ export const deployPythPriceOracle = async ({
await publicClient.waitForTransactionReceipt({ hash: tx });
console.log(`Set ${pythAssetsToChange.length} price feeds for PythPriceOracle at ${tx}`);
} else {
const tx = await walletClient.prepareTransactionRequest({
account: (await pythOracle.read.owner()) as Address,
to: pythOracle.address,
data: encodeFunctionData({
abi: pythOracle.abi,
functionName: "setPriceFeeds",
args: [pythAssetsToChange.map((f) => f.underlying), pythAssetsToChange.map((f) => f.feed)]
})
});
addTransaction({
to: tx.to,
value: tx.value ? tx.value.toString() : "0",
data: null,
contractMethod: {
inputs: [
{ internalType: "address[]", name: "underlyings", type: "address[]" },
{ internalType: "bytes32[]", name: "feeds", type: "bytes32[]" }
],
name: "setPriceFeeds",
payable: false
},
contractInputsValues: {
underlyings: pythAssetsToChange.map((f) => f.underlying),
feeds: pythAssetsToChange.map((f) => f.feed)
}
await prepareAndLogTransaction({
contractInstance: pythOracle,
args: [pythAssetsToChange.map((f) => f.underlying), pythAssetsToChange.map((f) => f.feed)],
description: `Set ${pythAssetsToChange.length} price feeds for PythPriceOracle`,
functionName: "setPriceFeeds",
inputs: [
{ internalType: "address[]", name: "underlyings", type: "address[]" },
{ internalType: "bytes32[]", name: "feeds", type: "bytes32[]" }
]
});
console.log(`Logged Transaction to set ${pythAssetsToChange.length} price feeds for PythPriceOracle `);
}
Expand Down
40 changes: 11 additions & 29 deletions chainDeploy/helpers/oracles/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address, encodeFunctionData, PublicClient, WalletClient, zeroAddress } from "viem";
import { addTransaction } from "../logging";
import { addTransaction, prepareAndLogTransaction } from "../logging";
import { masterPriceOracleAbi } from "../../../generated";
import type { GetContractReturnType } from "@nomicfoundation/hardhat-viem/types.js";

Expand All @@ -8,8 +8,7 @@ export async function addUnderlyingsToMpo(
underlyingsToCheck: Address[],
oracleAddress: Address,
deployer: string,
publicClient: PublicClient,
walletClient: WalletClient
publicClient: PublicClient
) {
const oracles: Address[] = [];
const underlyings: Address[] = [];
Expand All @@ -28,32 +27,15 @@ export async function addUnderlyingsToMpo(
await publicClient.waitForTransactionReceipt({ hash: tx });
console.log(`Master Price Oracle updated oracles for tokens ${underlyings.join(",")} at ${tx}`);
} else {
const tx = await walletClient.prepareTransactionRequest({
chain: walletClient.chain,
account: await mpo.read.admin(),
to: mpo.address,
data: encodeFunctionData({
abi: mpo.abi,
functionName: "add",
args: [underlyings, oracles]
})
});
addTransaction({
to: tx.to,
value: tx.value ? tx.value.toString() : "0",
data: null,
contractMethod: {
inputs: [
{ internalType: "address[]", name: "underlyings", type: "address[]" },
{ internalType: "address[]", name: "_oracles", type: "address[]" }
],
name: "add",
payable: false
},
contractInputsValues: {
underlyings: underlyings,
_oracles: oracles
}
await prepareAndLogTransaction({
contractInstance: mpo,
functionName: "add",
args: [underlyings, oracles],
description: `Add oracles for ${underlyings.join(",")}`,
inputs: [
{ internalType: "address[]", name: "underlyings", type: "address[]" },
{ internalType: "address[]", name: "_oracles", type: "address[]" }
]
});

console.log(`Logged Transaction for Master Price Oracle update for tokens ${underlyings.join(",")}`);
Expand Down
Loading

0 comments on commit cbec863

Please sign in to comment.