Skip to content

Commit

Permalink
Merge branch 'development' into feat/hypernative-security-oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
rhlsthrm committed Oct 21, 2024
2 parents 30dfc25 + 847166e commit e2ebfd0
Show file tree
Hide file tree
Showing 39 changed files with 10,210 additions and 360 deletions.
14 changes: 14 additions & 0 deletions packages/bots/pyth-updater/src/config/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { PythAssetConfig } from '../types';

import { pythConfig as commonPythConfig } from './common';

export const pythConfig: PythAssetConfig[] = [
...commonPythConfig,
{
// price feed for SOL
priceId: '0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d',
configRefreshRateInSeconds: 3600,
validTimePeriodSeconds: 86400, // 24 hrs
deviationThresholdBps: 100, // 1%
},
];
4 changes: 3 additions & 1 deletion packages/bots/pyth-updater/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { mode } from '@ionicprotocol/chains';
import { base, mode } from '@ionicprotocol/chains';

import { pythConfig as basePythConfig } from './base';
import { pythConfig as modePythConfig } from './mode';

export const chainIdToConfig = {
[mode.chainId]: modePythConfig,
[base.chainId]: basePythConfig,
};
18 changes: 17 additions & 1 deletion packages/chains/src/base/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ChainlinkFeedBaseCurrency,
ChainlinkSpecificParams,
OracleTypes,
PythSpecificParams,
SupportedAsset,
SupportedChains
} from "@ionicprotocol/types";
Expand Down Expand Up @@ -33,6 +34,7 @@ export const EURC = "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42";
export const USDplus = "0xB79DD08EA68A908A97220C76d19A6aA9cBDE4376";
export const wUSDplus = "0xd95ca61CE9aAF2143E81Ef5462C0c2325172E028";
export const USDz = "0x04D5ddf5f3a8939889F11E97f8c4BB48317F1938";
export const uSOL = "0x9B8Df6E244526ab5F6e6400d331DB28C8fdDdb55";

export const assets: SupportedAsset[] = [
{
Expand Down Expand Up @@ -108,7 +110,7 @@ export const assets: SupportedAsset[] = [
underlying: SNX,
name: "Synthetix Network Token",
decimals: 18,
oracle: OracleTypes.PythPriceOracle,
oracle: OracleTypes.ChainlinkPriceOracleV2,
oracleSpecificParams: {
aggregator: "0xe3971Ed6F1A5903321479Ef3148B5950c0612075",
feedBaseCurrency: ChainlinkFeedBaseCurrency.USD
Expand Down Expand Up @@ -317,6 +319,20 @@ export const assets: SupportedAsset[] = [
initialCf: "0.80",
initialSupplyCap: parseEther(String(13_000_000)).toString(),
initialBorrowCap: parseEther(String(10_000_000)).toString()
},
{
symbol: assetSymbols.uSOL,
underlying: uSOL,
name: "Wrapped Solana",
decimals: 18,
oracle: OracleTypes.PythPriceOracle,
oracleSpecificParams: {
feed: "0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d"
} as PythSpecificParams,
extraDocs: defaultDocs("https://basescan.org", uSOL),
initialBorrowCap: parseEther(String(1000)).toString(),
initialSupplyCap: parseEther(String(2000)).toString(),
initialCf: "0.80"
}
// DO NOT ADD TO MARKET UNLESS PROPER ORACLE IS DEPLOYED
// {
Expand Down
7 changes: 6 additions & 1 deletion packages/chains/src/base/oracles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { OracleTypes } from "@ionicprotocol/types";

const baseOracles = [OracleTypes.FixedNativePriceOracle, OracleTypes.MasterPriceOracle, OracleTypes.SimplePriceOracle];
const baseOracles = [
OracleTypes.FixedNativePriceOracle,
OracleTypes.MasterPriceOracle,
OracleTypes.SimplePriceOracle,
OracleTypes.PythPriceOracle
];

const oracles: OracleTypes[] = [...baseOracles, OracleTypes.ChainlinkPriceOracleV2];

Expand Down
53 changes: 28 additions & 25 deletions packages/contracts/chainDeploy/helpers/oracles/pyth.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Address, encodeFunctionData, GetContractReturnType, WalletClient } from "viem";

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

import { addUnderlyingsToMpo } from "./utils";
import { PythAsset, PythDeployFnParams } from "../../types";
import { pythPriceOracleAbi } from "../../../../sdk/src/generated";

export const deployPythPriceOracle = async ({
viem,
Expand All @@ -15,7 +15,7 @@ export const deployPythPriceOracle = async ({
pythAssets,
nativeTokenUsdFeed
}: PythDeployFnParams): Promise<{ pythOracle: GetContractReturnType<typeof pythPriceOracleAbi, WalletClient> }> => {
const { deployer } = await getNamedAccounts();
const { deployer, multisig } = await getNamedAccounts();
const publicClient = await viem.getPublicClient();
const walletClient = await viem.getWalletClient(deployer as Address);

Expand All @@ -24,43 +24,46 @@ 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: multisig ?? 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",
(await deployments.get("PythPriceOracle")).address as Address
);

const pythAssetsToChange: PythAsset[] = [];
console.log("🚀 ~ pythAssets:", pythAssets);
for (const pythAsset of pythAssets) {
const currentPriceFeed = await pythOracle.read.priceFeedIds([pythAsset.underlying]);
console.log("🚀 ~ currentPriceFeed:", currentPriceFeed);
if (currentPriceFeed !== pythAsset.feed) {
pythAssetsToChange.push(pythAsset);
}
}
console.log("🚀 ~ pythAssetsToChange:", pythAssetsToChange);
if (pythAssetsToChange.length > 0) {
if (((await pythOracle.read.owner()) as Address).toLowerCase() === deployer.toLowerCase()) {
const tx = await pythOracle.write.setPriceFeeds([
Expand Down
22 changes: 20 additions & 2 deletions packages/contracts/chainDeploy/mainnets/base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ChainDeployConfig, deployChainlinkOracle, deployErc4626PriceOracle } from "../helpers";
import { ChainDeployConfig, deployChainlinkOracle, deployErc4626PriceOracle, deployPythPriceOracle } from "../helpers";
import { base } from "@ionicprotocol/chains";
import { deployAerodromeOracle } from "../helpers/oracles/aerodrome";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Address, zeroAddress } from "viem";
import { ChainlinkSpecificParams, OracleTypes } from "../types";
import { ChainlinkSpecificParams, OracleTypes, PythSpecificParams } from "../types";
import { configureAddress } from "../helpers/liquidators/ionicLiquidator";

const assets = base.assets;
Expand Down Expand Up @@ -43,6 +43,24 @@ export const deploy = async ({
const { deployer, multisig } = await getNamedAccounts();
const publicClient = await viem.getPublicClient();

//// Pyth Oracle
await deployPythPriceOracle({
run,
viem,
getNamedAccounts,
deployments,
deployConfig,
pythAssets: base.assets
.filter((asset) => asset.oracle === OracleTypes.PythPriceOracle)
.map((asset) => ({
feed: (asset.oracleSpecificParams as PythSpecificParams).feed,
underlying: asset.underlying
})),
nativeTokenUsdFeed: "0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
pythAddress: "0x8250f4aF4B972684F7b336503E2D6dFeDeB1487a",
usdToken: base.chainAddresses.STABLE_TOKEN as Address
});

//// ERC4626 Oracle
await deployErc4626PriceOracle({
run,
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit e2ebfd0

Please sign in to comment.