Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyth oracle deploy script added. #627

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions packages/sdk/chainDeploy/helpers/oracles/pyth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { assetSymbols, SupportedAsset } from "@midas-capital/types";
import { providers } from "ethers";

import { AddressesProvider } from "../../../lib/contracts/typechain/AddressesProvider";
import { PythPriceOracle } from "../../../lib/contracts/typechain/PythPriceOracle";
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);

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)
);

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 };
};
11 changes: 11 additions & 0 deletions packages/sdk/chainDeploy/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export type ChainlinkAsset = {
feedBaseCurrency: ChainlinkFeedBaseCurrency;
};

export type PythAsset = {
symbol: string;
feed: string;
};

export type DiaAsset = {
symbol: string;
underlying: string;
Expand Down Expand Up @@ -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;
Expand Down
43 changes: 34 additions & 9 deletions packages/sdk/chainDeploy/testnets/neondevnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -29,7 +31,26 @@ export const deployConfig: ChainDeployConfig = {
cgId: neondevnet.specificParams.cgId,
};

export const deploy = async ({ ethers, getNamedAccounts, deployments }): Promise<void> => {
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<void> => {
const { deployer } = await getNamedAccounts();
//// ORACLES
const simplePO = await deployments.deploy("SimplePriceOracle", {
Expand All @@ -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) {
Expand Down