From e06f311b6e266f2256e1b2370a85711e39675020 Mon Sep 17 00:00:00 2001 From: coolnft Date: Tue, 6 Sep 2022 10:17:51 -0400 Subject: [PATCH 1/2] pyth oracle deploy script added. --- .../sdk/chainDeploy/helpers/oracles/pyth.ts | 69 +++++++++++++++++++ packages/sdk/chainDeploy/helpers/types.ts | 11 +++ .../sdk/chainDeploy/testnets/neondevnet.ts | 43 +++++++++--- 3 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 packages/sdk/chainDeploy/helpers/oracles/pyth.ts diff --git a/packages/sdk/chainDeploy/helpers/oracles/pyth.ts b/packages/sdk/chainDeploy/helpers/oracles/pyth.ts new file mode 100644 index 000000000..08317e73c --- /dev/null +++ b/packages/sdk/chainDeploy/helpers/oracles/pyth.ts @@ -0,0 +1,69 @@ +import { assetSymbols, SupportedAsset } from "@midas-capital/types"; +import { providers } from "ethers"; +import { AddressesProvider } from "../../../lib/contracts/typechain"; +import { PythDeployFnParams } from "../types"; + +export const deployPythOracle = async ({ + ethers, + getNamedAccounts, + deployments, + deployConfig, + assets, + pythAssets, +}: PythDeployFnParams): Promise<{ ppo: any }> => { + const { deployer } = await getNamedAccounts(); + let tx: providers.TransactionResponse; + + const pyth = await deployments.deploy("Pyth", { + from: deployer, + args: [], + log: true, + waitConfirmations: 1, + }); + console.log("Pyth: ", pyth.address); + + const mpo = await ethers.getContract("MasterPriceOracle", deployer); + + // deploy pyth price oracle + const pythOracle = await deployments.deploy("PythPriceOracle", { + from: deployer, + args: [ + true, + deployConfig.wtoken, + pyth.address, + "7f57ca775216655022daa88e41c380529211cde01a1517735dbcf30e4a02bdaa", + mpo.address, + assets.find((a: SupportedAsset) => a.symbol === assetSymbols.USDC)!.underlying, + ], + log: true, + waitConfirmations: 1, + }); + console.log("PythPriceOracle: ", pythOracle.address); + + tx = await pythOracle.setPriceFeeds( + pythAssets.map((p) => assets.find((a: SupportedAsset) => a.symbol === p.symbol)!.underlying), + pythAssets.map((p) => p.feed) + ); + + console.log(`Set price feeds for PythPriceOracle: ${tx.hash}`); + await tx.wait(); + console.log(`Set price feeds for PythPriceOracle mined: ${tx.hash}`); + + const underlyings = pythAssets.map((p) => assets.find((a) => a.symbol === p.symbol)!.underlying); + const oracles = Array(pythAssets.length).fill(pythOracle.address); + + tx = await mpo.add(underlyings, oracles); + await tx.wait(); + + console.log(`Master Price Oracle updated for tokens ${underlyings.join(", ")}`); + + const addressesProvider = (await ethers.getContract("AddressesProvider", deployer)) as AddressesProvider; + const pythPriceOracleAddress = await addressesProvider.callStatic.getAddress("PythPriceOracle"); + if (pythPriceOracleAddress !== pythOracle.address) { + tx = await addressesProvider.setAddress("PythPriceOracle", pythOracle.address); + await tx.wait(); + console.log("setAddress PythPriceOracle: ", tx.hash); + } + + return { ppo: pythOracle }; +}; diff --git a/packages/sdk/chainDeploy/helpers/types.ts b/packages/sdk/chainDeploy/helpers/types.ts index 46d209826..a62094e96 100644 --- a/packages/sdk/chainDeploy/helpers/types.ts +++ b/packages/sdk/chainDeploy/helpers/types.ts @@ -55,6 +55,11 @@ export type ChainlinkAsset = { feedBaseCurrency: ChainlinkFeedBaseCurrency; }; +export type PythAsset = { + symbol: string; + feed: string; +}; + export type DiaAsset = { symbol: string; underlying: string; @@ -99,6 +104,12 @@ export type ChainlinkDeployFnParams = ChainDeployFnParams & { deployConfig: ChainDeployConfig; }; +export type PythDeployFnParams = ChainDeployFnParams & { + assets: SupportedAsset[]; + pythAssets: PythAsset[]; + deployConfig: ChainDeployConfig; +}; + export type DiaDeployFnParams = ChainDeployFnParams & { diaAssets: DiaAsset[]; deployConfig: ChainDeployConfig; diff --git a/packages/sdk/chainDeploy/testnets/neondevnet.ts b/packages/sdk/chainDeploy/testnets/neondevnet.ts index 4f70a075a..6e6522991 100644 --- a/packages/sdk/chainDeploy/testnets/neondevnet.ts +++ b/packages/sdk/chainDeploy/testnets/neondevnet.ts @@ -3,6 +3,8 @@ import { assetSymbols, SupportedAsset } from "@midas-capital/types"; import { BigNumber, ethers, utils } from "ethers"; import { ChainDeployConfig } from "../helpers"; +import { deployPythOracle } from "../helpers/oracles/pyth"; +import { PythAsset } from "../helpers/types"; const assets = neondevnet.assets; const BN = ethers.utils.parseEther("1"); @@ -29,7 +31,26 @@ export const deployConfig: ChainDeployConfig = { cgId: neondevnet.specificParams.cgId, }; -export const deploy = async ({ ethers, getNamedAccounts, deployments }): Promise => { +const pythAssets: PythAsset[] = [ + { + symbol: assetSymbols.WBTC, + feed: "f9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b", + }, + { + symbol: assetSymbols.AAVE, + feed: "d6b3bc030a8bbb7dd9de46fb564c34bb7f860dead8985eb16a49cdc62f8ab3a5", + }, + { + symbol: assetSymbols.WETH, + feed: "ca80ba6dc32e08d06f1aa886011eed1d77c77be9eb761cc10d72b7d0a2fd57a6", + }, + { + symbol: assetSymbols.USDC, + feed: "41f3625971ca2ed2263e78573fe5ce23e13d2558ed3f2e47ab0f84fb9e7ae722", + }, +]; + +export const deploy = async ({ run, ethers, getNamedAccounts, deployments }): Promise => { const { deployer } = await getNamedAccounts(); //// ORACLES const simplePO = await deployments.deploy("SimplePriceOracle", { @@ -40,18 +61,22 @@ export const deploy = async ({ ethers, getNamedAccounts, deployments }): Promise }); console.log("SimplePriceOracle: ", simplePO.address); - const pyth = await deployments.deploy("Pyth", { - from: deployer, - args: [], - log: true, - waitConfirmations: 1, - }); - console.log("Pyth: ", pyth.address); - const _assets = assets.filter((a) => a.symbol !== assetSymbols.WNEON); const masterPriceOracle = await ethers.getContract("MasterPriceOracle", deployer); const simplePriceOracle = await ethers.getContract("SimplePriceOracle", deployer); + + // deploy pyth oracle + await deployPythOracle({ + run, + ethers, + getNamedAccounts, + deployments, + deployConfig, + assets, + pythAssets, + }); + let tx; for (const a of _assets) { From 2563e29ad6d49ce6990e9428e7e2517dedd746d6 Mon Sep 17 00:00:00 2001 From: carlomazzaferro Date: Tue, 6 Sep 2022 22:57:56 +0200 Subject: [PATCH 2/2] get pyth PO --- packages/sdk/chainDeploy/helpers/oracles/pyth.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/sdk/chainDeploy/helpers/oracles/pyth.ts b/packages/sdk/chainDeploy/helpers/oracles/pyth.ts index 08317e73c..575c62c01 100644 --- a/packages/sdk/chainDeploy/helpers/oracles/pyth.ts +++ b/packages/sdk/chainDeploy/helpers/oracles/pyth.ts @@ -1,6 +1,8 @@ import { assetSymbols, SupportedAsset } from "@midas-capital/types"; import { providers } from "ethers"; -import { AddressesProvider } from "../../../lib/contracts/typechain"; + +import { AddressesProvider } from "../../../lib/contracts/typechain/AddressesProvider"; +import { PythPriceOracle } from "../../../lib/contracts/typechain/PythPriceOracle"; import { PythDeployFnParams } from "../types"; export const deployPythOracle = async ({ @@ -40,7 +42,8 @@ export const deployPythOracle = async ({ }); console.log("PythPriceOracle: ", pythOracle.address); - tx = await pythOracle.setPriceFeeds( + const pythPriceOracle = (await ethers.getContract("PythPriceOracle", deployer)) as PythPriceOracle; + tx = await pythPriceOracle.setPriceFeeds( pythAssets.map((p) => assets.find((a: SupportedAsset) => a.symbol === p.symbol)!.underlying), pythAssets.map((p) => p.feed) );