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 #874

Merged
merged 8 commits into from
Dec 19, 2024
Merged

merge #874

Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: ink
  • Loading branch information
rhlsthrm committed Dec 19, 2024
commit 7e7b742fd81bc4b78e83f538807cb880b905b544
1 change: 1 addition & 0 deletions packages/contracts/tasks/chain-specific/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "./lisk";
import "./virtual-base";
import "./superseed";
import "./worldchain";
import "./ink";

export const SUPPLY_DURATION = 29 * (24 * 60 * 60) + 1 * (23 * 60 * 60); // 29 days 23 hours
export const BORROW_DURATION = 30 * (24 * 60 * 60); // 30 days
2 changes: 1 addition & 1 deletion packages/contracts/tasks/chain-specific/ink/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./market";

export const COMPTROLLER_MAIN = "0x5E149502e2a65Be3b7C46F7767C9b16cB5765F48";
export const COMPTROLLER_MAIN = "0x239593BCAad13561ba58Ba98bc5069aFfe2Ef20D";
134 changes: 79 additions & 55 deletions packages/contracts/tasks/chain-specific/ink/market.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { task } from "hardhat/config";
import { Address, formatUnits, parseEther, zeroAddress } from "viem";
import { Address, zeroAddress } from "viem";
import { assetSymbols } from "@ionicprotocol/types";

import { prepareAndLogTransaction } from "../../../chainDeploy/helpers/logging";
import { getMarketInfo } from "../../market";
import { worldchain } from "@ionicprotocol/chains";
import { chainIdtoChain, ink } from "@ionicprotocol/chains";
import { COMPTROLLER_MAIN } from ".";

const worldchainAssets = worldchain.assets;
const inkAssets = ink.assets;

task("markets:deploy:worldchain:new", "deploy new worldchain assets").setAction(
async (_, { viem, run, deployments }) => {
task("markets:deploy:ink:new", "deploy new ink assets").setAction(
async (_, { viem, run, deployments, getNamedAccounts, getChainId }) => {
const { deployer } = await getNamedAccounts();
const chainId = parseInt(await getChainId());
const publicClient = await viem.getPublicClient({ chain: chainIdtoChain[chainId] });
const walletClient = await viem.getWalletClient(deployer as Address, { chain: chainIdtoChain[chainId] });
const assetsToDeploy: string[] = [assetSymbols.WETH];
for (const asset of worldchainAssets.filter((asset) => assetsToDeploy.includes(asset.symbol))) {
for (const asset of inkAssets.filter((asset) => assetsToDeploy.includes(asset.symbol))) {
if (!asset.name || !asset.symbol || !asset.underlying) {
throw new Error(`Asset ${asset.symbol} has no name, symbol or underlying`);
}
Expand All @@ -28,13 +31,17 @@ task("markets:deploy:worldchain:new", "deploy new worldchain assets").setAction(
symbol,
name
});
const pool = await viem.getContractAt("IonicComptroller", COMPTROLLER_MAIN);
const pool = await viem.getContractAt("IonicComptroller", COMPTROLLER_MAIN, {
client: { public: publicClient, wallet: walletClient }
});
const cToken = await pool.read.cTokensByUnderlying([asset.underlying]);
console.log(`Deployed ${asset.symbol} at ${cToken}`);

if (cToken !== zeroAddress) {
const ap = await deployments.get("AddressesProvider");
const asExt = await viem.getContractAt("CTokenFirstExtension", cToken);
const asExt = await viem.getContractAt("CTokenFirstExtension", cToken, {
client: { public: publicClient, wallet: walletClient }
});
const tx = await asExt.write._setAddressesProvider([ap.address as Address]);
console.log("set addresses provider", tx);

Expand All @@ -52,57 +59,74 @@ task("markets:deploy:worldchain:new", "deploy new worldchain assets").setAction(
}
);

task("worldchain:set-caps:new", "one time setup").setAction(async (_, { viem, run, getNamedAccounts, deployments }) => {
const { deployer } = await getNamedAccounts();
const assetsToDeploy: string[] = [assetSymbols.WETH];
for (const asset of worldchain.assets.filter((asset) => assetsToDeploy.includes(asset.symbol))) {
const pool = await viem.getContractAt("IonicComptroller", COMPTROLLER_MAIN);
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"
}
]
task("ink:set-caps:new", "one time setup").setAction(
async (_, { viem, run, getNamedAccounts, deployments, getChainId }) => {
const { deployer } = await getNamedAccounts();
const chainId = parseInt(await getChainId());
const publicClient = await viem.getPublicClient({ chain: chainIdtoChain[chainId] });
const walletClient = await viem.getWalletClient(deployer as Address, { chain: chainIdtoChain[chainId] });
const assetsToDeploy: string[] = [assetSymbols.WETH];
for (const asset of ink.assets.filter((asset) => assetsToDeploy.includes(asset.symbol))) {
const pool = await viem.getContractAt("IonicComptroller", COMPTROLLER_MAIN, {
client: { public: publicClient, wallet: walletClient }
});
} else {
const tx = await asExt.write._setAddressesProvider([ap.address as Address]);
console.log("set addresses provider", tx);
}
const cToken = await pool.read.cTokensByUnderlying([asset.underlying]);
const asExt = await viem.getContractAt("CTokenFirstExtension", cToken, {
client: { public: publicClient, wallet: walletClient }
});
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 {
const tx = await asExt.write._setAddressesProvider([ap.address as Address]);
console.log("set addresses provider", tx);
}

await run("market:set-borrow-cap", {
market: cToken,
maxBorrow: asset.initialBorrowCap
});
await run("market:set-borrow-cap", {
market: cToken,
maxBorrow: asset.initialBorrowCap
});

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

task("market:set-cf:worldchain:new", "Sets CF on a market").setAction(async (_, { viem, run }) => {
for (const asset of worldchain.assets.filter((asset) => asset.symbol === assetSymbols.WETH)) {
const pool = await viem.getContractAt("IonicComptroller", COMPTROLLER_MAIN);
const cToken = await pool.read.cTokensByUnderlying([asset.underlying]);
console.log("cToken: ", cToken, asset.symbol);
);

if (asset.initialCf) {
await run("market:set:ltv", {
marketAddress: cToken,
ltv: asset.initialCf
task("market:set-cf:ink:new", "Sets CF on a market").setAction(
async (_, { viem, run, getNamedAccounts, getChainId }) => {
const { deployer } = await getNamedAccounts();
const chainId = parseInt(await getChainId());
const publicClient = await viem.getPublicClient({ chain: chainIdtoChain[chainId] });
const walletClient = await viem.getWalletClient(deployer as Address, { chain: chainIdtoChain[chainId] });
for (const asset of ink.assets.filter((asset) => asset.symbol === assetSymbols.WETH)) {
const pool = await viem.getContractAt("IonicComptroller", COMPTROLLER_MAIN, {
client: { public: publicClient, wallet: walletClient }
});
const cToken = await pool.read.cTokensByUnderlying([asset.underlying]);
console.log("cToken: ", cToken, asset.symbol);

if (asset.initialCf) {
await run("market:set:ltv", {
marketAddress: cToken,
ltv: asset.initialCf
});
}
}
}
});
);
11 changes: 8 additions & 3 deletions packages/contracts/tasks/market/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Address, encodeAbiParameters, parseAbiParameters, parseEther } from "vi

import { MarketConfig } from "../../chainDeploy";
import { prepareAndLogTransaction } from "../../chainDeploy/helpers/logging";
import { chainIdtoChain } from "@ionicprotocol/chains";

task("market:deploy", "deploy market")
.addParam("signer", "Named account to use for tx", "deployer", types.string)
Expand All @@ -13,10 +14,14 @@ task("market:deploy", "deploy market")
.addParam("name", "CToken name", undefined, types.string)
.addOptionalParam("initialSupplyCap", "Initial supply cap", undefined, types.string)
.addOptionalParam("initialBorrowCap", "Initial borrow cap", undefined, types.string)
.setAction(async (taskArgs, { viem, deployments, getNamedAccounts }) => {
.setAction(async (taskArgs, { viem, deployments, getNamedAccounts, getChainId }) => {
const { deployer } = await getNamedAccounts();
const publicClient = await viem.getPublicClient();
const comptroller = await viem.getContractAt("IonicComptroller", taskArgs.comptroller as Address);
const chainId = parseInt(await getChainId());
const publicClient = await viem.getPublicClient({ chain: chainIdtoChain[chainId] });
const walletClient = await viem.getWalletClient(deployer as Address, { chain: chainIdtoChain[chainId] });
const comptroller = await viem.getContractAt("IonicComptroller", taskArgs.comptroller as Address, {
client: { public: publicClient, wallet: walletClient }
});

const delegateType = 1;
const implementationData = "0x00";
Expand Down
16 changes: 12 additions & 4 deletions packages/contracts/tasks/market/risk/borrow-caps.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { task, types } from "hardhat/config";
import { prepareAndLogTransaction } from "../../../chainDeploy/helpers/logging";
import { chainIdtoChain } from "@ionicprotocol/chains";
import { Address } from "viem";

export default task("market:set-borrow-cap", "Set borrow cap on market")
.addParam("admin", "Named account from which to set the borrow caps", "deployer", types.string)
.addParam("market", "The address of the CToken", undefined, types.string)
.addParam("maxBorrow", "Maximum amount of tokens that can be borrowed", undefined, types.string)
.setAction(async ({ market, maxBorrow }, { viem, getNamedAccounts }) => {
.setAction(async ({ market, maxBorrow }, { viem, getNamedAccounts, getChainId }) => {
const { deployer } = await getNamedAccounts();
const publicClient = await viem.getPublicClient();
const cToken = await viem.getContractAt("ICErc20", market);
const chainId = parseInt(await getChainId());
const publicClient = await viem.getPublicClient({ chain: chainIdtoChain[chainId] });
const walletClient = await viem.getWalletClient(deployer as Address, { chain: chainIdtoChain[chainId] });
const cToken = await viem.getContractAt("ICErc20", market, {
client: { public: publicClient, wallet: walletClient }
});
const comptroller = await cToken.read.comptroller();
const pool = await viem.getContractAt("IonicComptroller", comptroller);
const pool = await viem.getContractAt("IonicComptroller", comptroller, {
client: { public: publicClient, wallet: walletClient }
});

const currentBorrowCap = await pool.read.borrowCaps([cToken.address]);
console.log(`Current borrow cap is ${currentBorrowCap}`);
Expand Down
16 changes: 12 additions & 4 deletions packages/contracts/tasks/market/risk/supply-caps.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { task, types } from "hardhat/config";
import { prepareAndLogTransaction } from "../../../chainDeploy/helpers/logging";
import { chainIdtoChain } from "@ionicprotocol/chains";
import { Address } from "viem";

export default task("market:set-supply-cap", "Sets supply cap on a market")
.addParam("admin", "Deployer account", "deployer", types.string)
.addParam("market", "The address of the CToken", undefined, types.string)
.addParam("maxSupply", "Maximum amount of tokens that can be supplied", undefined, types.string)
.setAction(async ({ market, maxSupply }, { viem, getNamedAccounts }) => {
.setAction(async ({ market, maxSupply }, { viem, getNamedAccounts, getChainId }) => {
const { deployer } = await getNamedAccounts();
const publicClient = await viem.getPublicClient();
const cToken = await viem.getContractAt("ICErc20", market);
const chainId = parseInt(await getChainId());
const publicClient = await viem.getPublicClient({ chain: chainIdtoChain[chainId] });
const walletClient = await viem.getWalletClient(deployer as Address, { chain: chainIdtoChain[chainId] });
const cToken = await viem.getContractAt("ICErc20", market, {
client: { public: publicClient, wallet: walletClient }
});
const comptroller = await cToken.read.comptroller();
const pool = await viem.getContractAt("IonicComptroller", comptroller);
const pool = await viem.getContractAt("IonicComptroller", comptroller, {
client: { public: publicClient, wallet: walletClient }
});

const currentSupplyCap = await pool.read.supplyCaps([cToken.address]);
console.log(`Current supply cap is ${currentSupplyCap}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/tasks/pool/admin/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ task("pool:create:worldchain").setAction(async ({}, { run, deployments }) => {
task("pool:create:ink").setAction(async ({}, { run, deployments }) => {
const mpo = await deployments.get("MasterPriceOracle");
await run("pool:create", {
name: "Ink Main Market",
name: "Ink Main Pool",
creator: "deployer",
priceOracle: mpo.address, // MPO
closeFactor: "50",
Expand Down