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

feat: klima #793

Merged
merged 3 commits into from
Nov 21, 2024
Merged
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
19 changes: 18 additions & 1 deletion packages/chains/src/base/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
assetSymbols,
ChainlinkFeedBaseCurrency,
ChainlinkSpecificParams,
DiaSpecificParams,
OracleTypes,
PythSpecificParams,
SupportedAsset,
Expand Down Expand Up @@ -38,6 +39,7 @@ export const uSOL = "0x9B8Df6E244526ab5F6e6400d331DB28C8fdDdb55";
export const uSUI = "0xb0505e5a99abd03d94a1169e638B78EDfEd26ea4";
export const sUSDz = "0xe31eE12bDFDD0573D634124611e85338e2cBF0cF";
export const fBOMB = "0x74ccbe53F77b08632ce0CB91D3A545bF6B8E0979";
export const KLIMA = "0xDCEFd8C8fCc492630B943ABcaB3429F12Ea9Fea2";

export const assets: SupportedAsset[] = [
{
Expand Down Expand Up @@ -378,9 +380,24 @@ export const assets: SupportedAsset[] = [
feedBaseCurrency: ChainlinkFeedBaseCurrency.USD
},
extraDocs: defaultDocs("https://basescan.org", fBOMB),
initialCf: "0.30",
initialCf: "0.50",
initialSupplyCap: parseEther(String(20_000_000)).toString(),
initialBorrowCap: parseEther(String(15_000_000)).toString()
},
{
symbol: assetSymbols.KLIMA,
underlying: KLIMA,
name: "Klima DAO",
decimals: 9,
oracle: OracleTypes.DiaPriceOracle,
oracleSpecificParams: {
feed: "0x12df07B05E9DABE78bD04B90206E31F6f64D75bB",
key: "KLIMA/USD"
} as DiaSpecificParams,
extraDocs: defaultDocs("https://basescan.org", KLIMA),
initialSupplyCap: parseUnits(String(1_500_000), 9).toString(),
initialBorrowCap: parseUnits(String(1_200_000), 9).toString(),
initialCf: "0.55"
}
// DO NOT ADD TO MARKET UNLESS PROPER ORACLE IS DEPLOYED
// {
Expand Down
3 changes: 2 additions & 1 deletion packages/chains/src/base/oracles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const baseOracles = [
OracleTypes.FixedNativePriceOracle,
OracleTypes.MasterPriceOracle,
OracleTypes.SimplePriceOracle,
OracleTypes.PythPriceOracle
OracleTypes.PythPriceOracle,
OracleTypes.DiaPriceOracle
];

const oracles: OracleTypes[] = [...baseOracles, OracleTypes.ChainlinkPriceOracleV2];
Expand Down
93 changes: 93 additions & 0 deletions packages/contracts/chainDeploy/helpers/oracles/dia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Address, GetContractReturnType, WalletClient } from "viem";

import { prepareAndLogTransaction } from "../logging";

import { addUnderlyingsToMpo } from "./utils";
import { DiaAsset, DiaDeployFnParams } from "../../types";
import { diaPriceOracleAbi } from "../../../../sdk/src/generated";
import { assetSymbols, underlying } from "@ionicprotocol/types";
import { base } from "@ionicprotocol/chains";

export const deployDiaPriceOracle = async ({
viem,
getNamedAccounts,
deployments,
diaAssets,
diaNativeFeed
}: DiaDeployFnParams): Promise<{ diaOracle: GetContractReturnType<typeof diaPriceOracleAbi, WalletClient> }> => {
const { deployer } = await getNamedAccounts();
const publicClient = await viem.getPublicClient();

const mpo = await viem.getContractAt(
"MasterPriceOracle",
(await deployments.get("MasterPriceOracle")).address as Address
);

//// Dia Oracle
const dia = await deployments.deploy("DiaPriceOracle", {
from: deployer,
args: [
deployer,
true,
"0x4200000000000000000000000000000000000006",
diaNativeFeed?.feed ?? "0x0000000000000000000000000000000000000000",
diaNativeFeed?.key ?? "",
(await deployments.get("MasterPriceOracle")).address,
underlying(base.assets, assetSymbols.USDC)
],
log: true,
waitConfirmations: 1
});

if (dia.transactionHash) publicClient.waitForTransactionReceipt({ hash: dia.transactionHash as Address });
console.log("DiaPriceOracle: ", dia.address);

const diaOracle = await viem.getContractAt(
"DiaPriceOracle",
(await deployments.get("DiaPriceOracle")).address as Address
);

const diaAssetsToChange: DiaAsset[] = [];
console.log("🚀 ~ diaAssets:", diaAssets);
for (const diaAsset of diaAssets) {
const currentPriceFeed = await diaOracle.read.priceFeeds([diaAsset.underlying]);
console.log("🚀 ~ currentPriceFeed:", currentPriceFeed);
if (currentPriceFeed[0] !== diaAsset.feed || currentPriceFeed[1] !== diaAsset.key) {
diaAssetsToChange.push(diaAsset);
}
}
console.log("🚀 ~ diaAssetsToChange:", diaAssetsToChange);
if (diaAssetsToChange.length > 0) {
if (((await diaOracle.read.admin()) as Address).toLowerCase() === deployer.toLowerCase()) {
const tx = await diaOracle.write.setPriceFeeds([
diaAssetsToChange.map((f) => f.underlying),
diaAssetsToChange.map((f) => f.feed),
diaAssetsToChange.map((f) => f.key)
]);
await publicClient.waitForTransactionReceipt({ hash: tx });
console.log(`Set ${diaAssetsToChange.length} price feeds for DiaPriceOracle at ${tx}`);
} else {
await prepareAndLogTransaction({
contractInstance: diaOracle,
args: [
diaAssetsToChange.map((f) => f.underlying),
diaAssetsToChange.map((f) => f.feed),
diaAssetsToChange.map((f) => f.key)
],
description: `Set ${diaAssetsToChange.length} price feeds for DiaPriceOracle`,
functionName: "setPriceFeeds",
inputs: [
{ internalType: "address[]", name: "underlyings", type: "address[]" },
{ internalType: "bytes32[]", name: "feeds", type: "bytes32[]" },
{ internalType: "string[]", name: "keys", type: "string[]" }
]
});
console.log(`Logged Transaction to set ${diaAssetsToChange.length} price feeds for DiaPriceOracle `);
}
}

const underlyings = diaAssets.map((f) => f.underlying);
await addUnderlyingsToMpo(mpo as any, underlyings, diaOracle.address, deployer, publicClient);

return { diaOracle: diaOracle as any };
};
21 changes: 20 additions & 1 deletion packages/contracts/chainDeploy/mainnets/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Address, zeroAddress } from "viem";
import { ChainlinkSpecificParams, OracleTypes, PythSpecificParams } from "../types";
import { configureAddress } from "../helpers/liquidators/ionicLiquidator";
import { deployDiaPriceOracle } from "../helpers/oracles/dia";
import { DiaSpecificParams } from "@ionicprotocol/types";

const assets = base.assets;

Expand Down Expand Up @@ -61,7 +63,7 @@ export const deploy = async ({
usdToken: base.chainAddresses.STABLE_TOKEN as Address
});

//// ERC4626 Oracle
// //// ERC4626 Oracle
await deployErc4626PriceOracle({
run,
viem,
Expand Down Expand Up @@ -104,6 +106,23 @@ export const deploy = async ({
chainlinkAssets
});

const diaAssets = base.assets
.filter((asset) => asset.oracle === OracleTypes.DiaPriceOracle)
.map((asset) => ({
feed: (asset.oracleSpecificParams as DiaSpecificParams).feed,
underlying: asset.underlying,
key: (asset.oracleSpecificParams as DiaSpecificParams).key,
symbol: asset.symbol
}));
await deployDiaPriceOracle({
run,
viem,
getNamedAccounts,
deployments,
deployConfig,
diaAssets
});

const ap = await viem.getContractAt(
"AddressesProvider",
(await deployments.get("AddressesProvider")).address as Address
Expand Down
7 changes: 4 additions & 3 deletions packages/contracts/chainDeploy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export type ChainlinkAsset = {

export type DiaAsset = {
symbol: string;
underlying: string;
feed: string;
underlying: Address;
feed: Address;
key: string;
};

Expand Down Expand Up @@ -308,7 +308,8 @@ export enum OracleTypes {
RedstoneAdapterPriceOracle = "RedstoneAdapterPriceOracle",
RedstoneAdapterWrsETHPriceOracle = "RedstoneAdapterWrsETHPriceOracle",
VelodromePriceOracle = "VelodromePriceOracle",
AerodromePriceOracle = "AerodromePriceOracle"
AerodromePriceOracle = "AerodromePriceOracle",
DiaPriceOracle = "DiaPriceOracle"
}

export type ChainAddresses = {
Expand Down
Loading
Loading