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

merge #739

Merged
merged 22 commits into from
Oct 30, 2024
Merged

merge #739

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
15 changes: 15 additions & 0 deletions packages/chains/src/base/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const USDplus = "0xB79DD08EA68A908A97220C76d19A6aA9cBDE4376";
export const wUSDplus = "0xd95ca61CE9aAF2143E81Ef5462C0c2325172E028";
export const USDz = "0x04D5ddf5f3a8939889F11E97f8c4BB48317F1938";
export const uSOL = "0x9B8Df6E244526ab5F6e6400d331DB28C8fdDdb55";
export const uSUI = "0xb0505e5a99abd03d94a1169e638B78EDfEd26ea4";

export const assets: SupportedAsset[] = [
{
Expand Down Expand Up @@ -333,6 +334,20 @@ export const assets: SupportedAsset[] = [
initialBorrowCap: parseEther(String(1000)).toString(),
initialSupplyCap: parseEther(String(2000)).toString(),
initialCf: "0.80"
},
{
symbol: assetSymbols.uSUI,
underlying: uSUI,
name: "Sui (Universal)",
decimals: 18,
oracle: OracleTypes.PythPriceOracle,
oracleSpecificParams: {
feed: "0x23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744"
} as PythSpecificParams,
extraDocs: defaultDocs("https://basescan.org", uSUI),
initialBorrowCap: parseEther(String(150_000)).toString(),
initialSupplyCap: parseEther(String(250_000)).toString(),
initialCf: "0.70"
}
// DO NOT ADD TO MARKET UNLESS PROPER ORACLE IS DEPLOYED
// {
Expand Down
4 changes: 2 additions & 2 deletions packages/chains/src/optimism/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export const assets: SupportedAsset[] = [
oracleSpecificParams: { feed: "0x39d020f60982ed892abbcd4a06a276a9f9b7bfbce003204c110b6e488f502da3" },
extraDocs: defaultDocs("https://optimistic.etherscan.io", SNX),
initialCf: "70",
initialSupplyCap: parseEther(String(40_000)).toString(),
initialBorrowCap: parseEther(String(32_000)).toString()
initialSupplyCap: parseEther(String(350_000)).toString(),
initialBorrowCap: parseEther(String(280_000)).toString()
},
{
symbol: assetSymbols.WBTC,
Expand Down
22 changes: 18 additions & 4 deletions packages/contracts/chainDeploy/mainnets/mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { configureAddress } from "../helpers/liquidators/ionicLiquidator";
const KIM_ROUTER = "0xAc48FcF1049668B285f3dC72483DF5Ae2162f7e8";
const VELODROME_V2_ROUTER = "0x3a63171DD9BebF4D07BC782FECC7eb0b890C2A45";
const VELODROME_V2_FACTORY = "0x31832f2a97Fd20664D76Cc421207669b55CE4BC0";
const SWAPMODE_ROUTER = "0xc1e624C810D297FD70eF53B0E08F44FABE468591";

export const deployConfig: ChainDeployConfig = {
blocksPerYear: 30 * 60 * 24 * 365, // 30 blocks per minute = 2 sec block time
Expand Down Expand Up @@ -106,15 +107,28 @@ export const deploy = async ({

await configureAddress(ap, publicClient, deployer, "ALGEBRA_SWAP_ROUTER", KIM_ROUTER);

const velodromeV2Liquidator = await deployments.deploy("VelodromeV2Liquidator", {
// const velodromeV2Liquidator = await deployments.deploy("VelodromeV2Liquidator", {
// from: deployer,
// args: [],
// log: true,
// waitConfirmations: 1
// });
// console.log("VelodromeV2Liquidator: ", velodromeV2Liquidator.address);
await configureAddress(ap, publicClient, deployer, "AERODROME_V2_ROUTER", VELODROME_V2_ROUTER);
await configureAddress(ap, publicClient, deployer, "AERODROME_V2_FACTORY", VELODROME_V2_FACTORY);

const uniswapV2Liquidator = await deployments.deploy("UniswapV2LiquidatorFunder", {
from: deployer,
args: [],
log: true,
waitConfirmations: 1
});
console.log("VelodromeV2Liquidator: ", velodromeV2Liquidator.address);
await configureAddress(ap, publicClient, deployer, "AERODROME_V2_ROUTER", VELODROME_V2_ROUTER);
await configureAddress(ap, publicClient, deployer, "AERODROME_V2_FACTORY", VELODROME_V2_FACTORY);

if (uniswapV2Liquidator.transactionHash) {
await publicClient.waitForTransactionReceipt({ hash: uniswapV2Liquidator.transactionHash as Hash });
}
console.log("UniswapV2LiquidatorFunder: ", uniswapV2Liquidator.address);
await configureAddress(ap, publicClient, deployer, "IUniswapV2Router02", SWAPMODE_ROUTER);

// await deployVelodromeOracle({
// viem,
Expand Down
107 changes: 107 additions & 0 deletions packages/contracts/deployments/mode/UniswapV2Liquidator.json

Large diffs are not rendered by default.

167 changes: 167 additions & 0 deletions packages/contracts/deployments/mode/UniswapV2LiquidatorFunder.json

Large diffs are not rendered by default.

32 changes: 29 additions & 3 deletions packages/contracts/tasks/chain-specific/base/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import { task } from "hardhat/config";
import { base } from "@ionicprotocol/chains";
import { assetSymbols } from "@ionicprotocol/types";
import { COMPTROLLER } from ".";
import { Address } from "viem";
import { prepareAndLogTransaction } from "../../../chainDeploy/helpers/logging";

task("markets:deploy:base:new", "deploy base market").setAction(async (_, { viem, run }) => {
const assetsToDeploy: string[] = [assetSymbols.uSOL];
const assetsToDeploy: string[] = [assetSymbols.uSUI];
for (const asset of base.assets.filter((asset) => assetsToDeploy.includes(asset.symbol))) {
console.log("Deploying market for ", asset.symbol, asset.name);
await new Promise((resolve) => setTimeout(resolve, 10000)); // Wait 10 seconds

if (!asset.underlying || !asset.symbol) {
throw new Error("Invalid asset");
}
Expand Down Expand Up @@ -33,13 +38,34 @@ task("markets:deploy:base:new", "deploy base market").setAction(async (_, { viem
}
});

task("base:set-caps:new", "one time setup").setAction(async (_, { viem, run }) => {
const asset = base.assets.find((asset) => asset.symbol === assetSymbols.cbBTC);
task("base:set-caps:new", "one time setup").setAction(async (_, { viem, run, getNamedAccounts, deployments }) => {
const { deployer } = await getNamedAccounts();
const asset = base.assets.find((asset) => asset.symbol === assetSymbols.uSUI);
if (!asset) {
throw new Error("asset not found in base assets");
}
const pool = await viem.getContractAt("IonicComptroller", COMPTROLLER);
const cToken = await pool.read.cTokensByUnderlying([asset.underlying]);
const asExt = await viem.getContractAt("CTokenFirstExtension", cToken);
const admin = await pool.read.admin();
const ap = await deployments.get("AddressesProvider");
// if (admin.toLowerCase() !== deployer.toLowerCase()) {
// await prepareAndLogTransaction({
// contractInstance: asExt,
// functionName: "_setAddressesProvider",
// args: [ap.address as Address],
// description: "Set Addresses Provider",
// inputs: [
// {
// internalType: "address",
// name: "_ap",
// type: "address"
// }
// ]
// });
// } else {
// await asExt.write._setAddressesProvider([ap.address as Address]);
// }

await run("market:set-borrow-cap", {
market: cToken,
Expand Down
27 changes: 26 additions & 1 deletion packages/contracts/tasks/chain-specific/mode/liquidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ task("mode:liquidation:whitelist-redemption-strategies", "Whitelist redemption s
const aerodromeV2Liquidator = await deployments.get("AerodromeV2Liquidator");
const kimLiquidator = await deployments.get("AlgebraSwapLiquidator");
const velodromeV2Liquidator = await deployments.get("VelodromeV2Liquidator");
const uniswapV2Liquidator = await deployments.get("UniswapV2LiquidatorFunder");
const ionicLiquidator = await viem.getContractAt(
"IonicUniV3Liquidator",
(await deployments.get("IonicUniV3Liquidator")).address as Address
);
const liquidators = [
aerodromeV2Liquidator.address as Address,
kimLiquidator.address as Address,
velodromeV2Liquidator.address as Address
velodromeV2Liquidator.address as Address,
uniswapV2Liquidator.address as Address
];
for (const liquidator of liquidators) {
const isWhitelisted = await ionicLiquidator.read.redemptionStrategiesWhitelist([liquidator]);
Expand Down Expand Up @@ -123,6 +125,7 @@ task("mode:liquidation:set-redemption-strategies", "Set redemption strategy").se
}
const kimLiquidator = await deployments.get("AlgebraSwapLiquidator");
const velodromeV2Liquidator = await deployments.get("VelodromeV2Liquidator");
const uniswapV2Liquidator = await deployments.get("UniswapV2LiquidatorFunder");
await resetLiquidationStrategies(viem, deployments, deployer as Address, [
{
inputToken: modeToken.underlying,
Expand Down Expand Up @@ -228,6 +231,16 @@ task("mode:liquidation:set-redemption-strategies", "Set redemption strategy").se
inputToken: wethToken.underlying,
outputToken: wbtcToken.underlying,
strategy: kimLiquidator.address as Address
},
{
inputToken: wbtcToken.underlying,
outputToken: mbtcToken.underlying,
strategy: uniswapV2Liquidator.address as Address
},
{
inputToken: mbtcToken.underlying,
outputToken: wbtcToken.underlying,
strategy: uniswapV2Liquidator.address as Address
}
]);

Expand Down Expand Up @@ -278,5 +291,17 @@ task("mode:liquidation:set-redemption-strategies", "Set redemption strategy").se
outputToken: wbtcToken.underlying,
optimalPath: [usdcToken.underlying, wethToken.underlying, wbtcToken.underlying]
});

await setOptimalSwapPath(viem, deployments, deployer as Address, {
inputToken: wbtcToken.underlying,
outputToken: wethToken.underlying,
optimalPath: [mbtcToken.underlying, wethToken.underlying]
});

await setOptimalSwapPath(viem, deployments, deployer as Address, {
inputToken: wethToken.underlying,
outputToken: wbtcToken.underlying,
optimalPath: [mbtcToken.underlying, wbtcToken.underlying]
});
}
);
35 changes: 19 additions & 16 deletions packages/contracts/tasks/chain-specific/mode/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mode } from "@ionicprotocol/chains";
import { assetSymbols } from "@ionicprotocol/types";

import { prepareAndLogTransaction } from "../../../chainDeploy/helpers/logging";
import { COMPTROLLER_MAIN, dmBTC_MARKET, MODE_NATIVE_MARKET, MS_DAI_MARKET } from ".";
import { COMPTROLLER_MAIN, COMPTROLLER_NATIVE, dmBTC_MARKET, MODE_NATIVE_MARKET, MS_DAI_MARKET } from ".";

const modeAssets = mode.assets;

Expand Down Expand Up @@ -43,25 +43,28 @@ task("markets:deploy:mode:new", "deploy new mode assets").setAction(async (_, {
}
});

task("market:setup:mode:new", "Sets caps on a market").setAction(async (_, { run }) => {
// const asset = modeAssets.find((asset) => asset.symbol === assetSymbols.dMBTC);
// if (!asset) {
// throw new Error("dMBTC not found in mode assets");
// }
// await run("market:set-borrow-cap", {
// market: MODE_NATIVE_MARKET,
// maxBorrow: parseEther(String(11_000_000)).toString()
// });
task("market:setup:mode:new", "Sets caps on a market").setAction(async (_, { viem, run }) => {
const asset = modeAssets.find((asset) => asset.symbol === assetSymbols.MODE);
if (!asset) {
throw new Error("dMBTC not found in mode assets");
}
const pool = await viem.getContractAt("IonicComptroller", COMPTROLLER_NATIVE);
const cToken = await pool.read.cTokensByUnderlying([asset.underlying]);

await run("market:set-borrow-cap", {
market: cToken,
maxBorrow: parseEther(String(30_000_000)).toString()
});

await run("market:set-supply-cap", {
market: MODE_NATIVE_MARKET,
maxSupply: parseEther(String(25_000_000)).toString()
market: cToken,
maxSupply: parseEther(String(24_000_000)).toString()
});

// await run("market:set:ltv", {
// marketAddress: dmBTC_MARKET,
// ltv: asset.initialCf
// });
await run("market:set:ltv", {
marketAddress: cToken,
ltv: asset.initialCf
});
});

task("mode:irm:set-prudentia", "Set new IRM to ctoken").setAction(
Expand Down
14 changes: 12 additions & 2 deletions packages/contracts/tasks/chain-specific/optimism/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ task("markets:deploy:optimism:new", "deploy new mode assets").setAction(async (_
}
});

task("market:set-cf:optimism:new", "Sets CF on a market").setAction(async (_, { viem, run }) => {
for (const asset of optimism.assets.filter((asset) => asset.symbol === assetSymbols.wUSDM)) {
task("market:set-caps:optimism:new", "Sets CF on a market").setAction(async (_, { viem, run }) => {
for (const asset of optimism.assets.filter((asset) => asset.symbol === assetSymbols.SNX)) {
const pool = await viem.getContractAt("IonicComptroller", COMPTROLLER_MAIN);
const cToken = await pool.read.cTokensByUnderlying([asset.underlying]);
console.log("cToken: ", cToken, asset.symbol);
Expand All @@ -51,5 +51,15 @@ task("market:set-cf:optimism:new", "Sets CF on a market").setAction(async (_, {
ltv: asset.initialCf
});
}

await run("market:set-supply-cap", {
market: cToken,
maxSupply: asset.initialSupplyCap
});

await run("market:set-borrow-cap", {
market: cToken,
maxBorrow: asset.initialBorrowCap
});
}
});
8 changes: 8 additions & 0 deletions packages/contracts/tasks/market/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ task("market:set:ltv", "Set the LTV (loan to value / collateral factor) of a mar
const ltvMantissa = parseUnits(ltv, 18);
console.log(`will set the LTV of market ${marketAddress} to ${ltvMantissa}`);

const _market = await pool.read.markets([marketAddress]);
const currentLtv = _market[1];
console.log("currentLtv: ", currentLtv);
if (currentLtv === ltvMantissa) {
console.log(`LTV is already set to ${ltvMantissa}`);
return;
}

if ((await pool.read.admin()).toLowerCase() !== deployer.toLowerCase()) {
await prepareAndLogTransaction({
contractInstance: pool,
Expand Down
3 changes: 1 addition & 2 deletions packages/contracts/tasks/market/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ task("market:deploy", "deploy market")
]
);

const feeDistributor = await viem.getContractAt("FeeDistributor", config.feeDistributor);
const owner = (await feeDistributor.read.owner()) as Address;
const owner = (await comptroller.read.admin()) as Address;
// Test Transaction
const errorCode = await comptroller.simulate._deployMarket(
[delegateType, constructorData, implementationData, collateralFactorBN],
Expand Down
6 changes: 6 additions & 0 deletions packages/sdk/deployments/mode.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@
"SimplePriceOracle_Proxy": {
"address": "0x5f0369AA93f36cA6a8B5ed7aAc47bf9e76086D03"
},
"UniswapV2Liquidator": {
"address": "0x586671b05A8Ab0E9F288207761808c15a24813ba"
},
"UniswapV2LiquidatorFunder": {
"address": "0x678645c6F57F030aE98a0B33834292120aa3882e"
},
"VelodromePriceOracle": {
"address": "0x9Bb6eFb9c1C16f4561591Fe13ea06AF8d1Fce2a9"
},
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export enum assetSymbols {
wUSDplus = "wUSD+",
USDz = "USDz",
uSOL = "uSOL",
uSUI = "uSUI",

// optimism
OP = "OP",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/app/_components/dashboards/InfoRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { multipliers } from '@ui/utils/multipliers';
import { handleSwitchOriginChain } from '@ui/utils/NetworkChecker';

import { getAssetName } from '../../util/utils';
const Rewards = dynamic(() => import('../markets/Rewards'), {
const Rewards = dynamic(() => import('../markets/FlyWheelRewards'), {
ssr: false
});
import BorrowPopover from '../markets/BorrowPopover';
Expand Down
Loading
Loading