Skip to content
This repository was archived by the owner on Aug 26, 2024. It is now read-only.

Commit 81c20a8

Browse files
committed
feat: full viem
1 parent fa81658 commit 81c20a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+4551
-479
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ deployments/kovan/
1313
contracts.iml
1414
node_modules/
1515
ionic-contracts.iml
16+
cache_hardhat

.vscode/extensions.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"arcanis.vscode-zipfs",
4+
"esbenp.prettier-vscode"
5+
]
6+
}

.vscode/settings.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
"editor.defaultFormatter": "esbenp.prettier-vscode",
33
"editor.formatOnSave": true,
44
"editor.tabSize": 2,
5-
"typescript.tsdk": "node_modules/typescript/lib",
5+
"typescript.tsdk": ".yarn/sdks/typescript/lib",
66
"[typescript]": {
77
"editor.defaultFormatter": "esbenp.prettier-vscode"
88
},
99
"solidity.packageDefaultDependenciesContractsDirectory": "contracts",
10-
"solidity.packageDefaultDependenciesDirectory": "lib"
10+
"solidity.packageDefaultDependenciesDirectory": "lib",
11+
"search.exclude": {
12+
"**/.yarn": true,
13+
"**/.pnp.*": true
14+
},
15+
"prettier.prettierPath": ".yarn/sdks/prettier/index.cjs",
16+
"typescript.enablePromptUseWorkspaceTsdk": true
1117
}

chainDeploy/helpers/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ export { deployIRMs } from "./irms";
33
export { deployChainlinkOracle } from "./oracles/chainlink";
44
export { deployFlywheelWithDynamicRewards } from "./dynamicFlywheels";
55
export { deployErc4626PriceOracle } from "./oracles/erc4626";
6-
export { configureBalancerSwap } from "./liquidators/ionicLiquidator";
6+
export { deployPythPriceOracle } from "./oracles/pyth";

chainDeploy/helpers/liquidators/ionicLiquidator.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const deployIonicLiquidator = async ({
1818
const { deployer, multisig } = await getNamedAccounts();
1919
const publicClient = await viem.getPublicClient();
2020

21-
const initializeArgs = [
21+
const initializeArgs: [Address, Address, number] = [
2222
deployConfig.wtoken,
2323
deployConfig.uniswap.uniswapV2RouterAddress,
2424
deployConfig.uniswap.flashSwapFee
@@ -107,11 +107,9 @@ export const deployIonicUniV3Liquidator = async ({
107107
export const configureIonicLiquidator = async ({
108108
contractName,
109109
viem,
110-
getNamedAccounts,
111110
chainId,
112111
deployments
113112
}: LiquidatorConfigFnParams): Promise<void> => {
114-
const { deployer } = await getNamedAccounts();
115113
const publicClient = await viem.getPublicClient();
116114

117115
const strategies: string[] = [];
@@ -124,7 +122,7 @@ export const configureIonicLiquidator = async ({
124122
for (const redemptionStrategyConfig of chainIdToConfig[chainId].redemptionStrategies) {
125123
const { strategy } = redemptionStrategyConfig;
126124
const redemptionStrategyContract = await viem.getContractAt(
127-
strategy,
125+
strategy as string,
128126
(await deployments.get(strategy)).address as Address
129127
);
130128

chainDeploy/helpers/oracles/chainlink.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export const deployChainlinkOracle = async ({
162162
"MasterPriceOracle",
163163
(await deployments.get("MasterPriceOracle")).address as Address
164164
);
165-
await addUnderlyingsToMpo(mpo, underlyings, chainLinkv2.address, deployer);
165+
await addUnderlyingsToMpo(mpo as any, underlyings, chainLinkv2.address, deployer, publicClient, walletClient);
166166

167167
const addressesProvider = await viem.getContractAt(
168168
"AddressesProvider",
@@ -181,7 +181,7 @@ export const deployChainlinkOracle = async ({
181181
data: encodeFunctionData({
182182
abi: addressesProvider.abi,
183183
functionName: "setAddress",
184-
args: [chainLinkv2.address]
184+
args: ["ChainlinkPriceOracleV2", chainLinkv2.address]
185185
})
186186
});
187187
addTransaction({

chainDeploy/helpers/oracles/redstoneWeETHFallbacks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Address } from "viem";
33
import { addUnderlyingsToMpoFallback } from "./utils";
44
import { RedStoneDeployFnParams } from "../../../chains/types";
55

6-
export const addRedstoneFallbacks = async ({
6+
export const addRedstoneWeETHFallbacks = async ({
77
viem,
88
getNamedAccounts,
99
deployments,

chainDeploy/helpers/oracles/redstoneWrsETH.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { RedStoneDeployFnParams } from "../../../chains/types";
33
import { addUnderlyingsToMpo } from "./utils";
44
import { Address } from "viem";
55

6-
export const deployRedStonePriceOracle = async ({
6+
export const deployRedStoneWrsETHPriceOracle = async ({
77
viem,
88
getNamedAccounts,
99
deployments,

chainDeploy/helpers/oracles/utils.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Address, encodeFunctionData, GetContractReturnType, PublicClient, WalletClient, zeroAddress } from "viem";
1+
import { Address, encodeFunctionData, PublicClient, WalletClient, zeroAddress } from "viem";
22
import { addTransaction } from "../logging";
33
import { masterPriceOracleAbi } from "../../../generated";
4+
import type { GetContractReturnType } from "@nomicfoundation/hardhat-viem/types.js";
45

56
export async function addUnderlyingsToMpo(
6-
mpo: GetContractReturnType<typeof masterPriceOracleAbi, WalletClient>,
7+
mpo: GetContractReturnType<typeof masterPriceOracleAbi>,
78
underlyingsToCheck: Address[],
89
oracleAddress: Address,
910
deployer: string,
@@ -23,6 +24,7 @@ export async function addUnderlyingsToMpo(
2324
if (underlyings.length) {
2425
if ((await mpo.read.admin()).toLowerCase() === deployer.toLowerCase()) {
2526
const tx = await mpo.write.add([underlyings, oracles]);
27+
console.log("tx: ", tx);
2628
await publicClient.waitForTransactionReceipt({ hash: tx });
2729
console.log(`Master Price Oracle updated oracles for tokens ${underlyings.join(",")} at ${tx}`);
2830
} else {
@@ -60,7 +62,7 @@ export async function addUnderlyingsToMpo(
6062
}
6163

6264
export async function addUnderlyingsToMpoFallback(
63-
mpo: GetContractReturnType<typeof masterPriceOracleAbi, WalletClient>,
65+
mpo: GetContractReturnType<typeof masterPriceOracleAbi>,
6466
underlyingsToCheck: Address[],
6567
oracleAddress: Address,
6668
deployer: Address,

chainDeploy/helpers/utils.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
import { Address } from "viem";
12
import { SupportedAsset } from "../../chains/types";
23

3-
export const underlying = (assets: SupportedAsset[], symbol: string): string => {
4+
export const underlying = (assets: SupportedAsset[], symbol: string): Address => {
45
return assetFilter(assets, symbol).underlying;
56
};
67

78
export const assetArrayToMap = (assets: SupportedAsset[]): { [key: string]: SupportedAsset } =>
8-
assets.reduce((acc, curr) => {
9-
acc[curr.underlying] = curr;
10-
return acc;
11-
}, {} as Record<string, SupportedAsset>);
9+
assets.reduce(
10+
(acc, curr) => {
11+
acc[curr.underlying] = curr;
12+
return acc;
13+
},
14+
{} as Record<string, SupportedAsset>
15+
);
1216

1317
export const assetFilter = (assets: SupportedAsset[], symbol: string): SupportedAsset => {
1418
const asset = assets.find((a: SupportedAsset) => a.symbol === symbol);

chainDeploy/mainnets/base.ts

+57-60
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,64 @@
1-
import { base } from "@ionicprotocol/chains";
2-
import { ChainlinkSpecificParams, OracleTypes } from "@ionicprotocol/types";
1+
// import { ChainDeployConfig, deployChainlinkOracle } from "../helpers";
2+
// import { ChainlinkAsset } from "../../chains/types";
33

4-
import { ChainDeployConfig, deployChainlinkOracle } from "../helpers";
5-
import { ChainlinkAsset } from "../../chains/types";
4+
// const assets = base.assets;
65

7-
const assets = base.assets;
6+
// export const deployConfig: ChainDeployConfig = {
7+
// blocksPerYear: Number(base.specificParams.blocksPerYear),
8+
// cgId: base.specificParams.cgId,
9+
// nativeTokenName: "Base",
10+
// nativeTokenSymbol: "ETH",
11+
// stableToken: base.chainAddresses.STABLE_TOKEN,
12+
// uniswap: {
13+
// flashSwapFee: 30, // TODO set the correct fee
14+
// hardcoded: [],
15+
// uniswapData: [],
16+
// uniswapOracleInitialDeployTokens: [],
17+
// uniswapV2FactoryAddress: "0x8909Dc15e40173Ff4699343b6eB8132c65e18eC6",
18+
// uniswapV2RouterAddress: "0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24",
19+
// uniswapV3SwapRouter: "0x2626664c2603336E57B271c5C0b26F421741e481",
20+
// uniswapV3Quoter: "0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a"
21+
// },
22+
// wtoken: base.chainAddresses.W_TOKEN,
23+
// nativeTokenUsdChainlinkFeed: base.chainAddresses.W_TOKEN_USD_CHAINLINK_PRICE_FEED
24+
// };
825

9-
export const deployConfig: ChainDeployConfig = {
10-
blocksPerYear: Number(base.specificParams.blocksPerYear),
11-
cgId: base.specificParams.cgId,
12-
nativeTokenName: "Base",
13-
nativeTokenSymbol: "ETH",
14-
stableToken: base.chainAddresses.STABLE_TOKEN,
15-
uniswap: {
16-
flashSwapFee: 30, // TODO set the correct fee
17-
hardcoded: [],
18-
uniswapData: [],
19-
uniswapOracleInitialDeployTokens: [],
20-
uniswapV2FactoryAddress: "0x8909Dc15e40173Ff4699343b6eB8132c65e18eC6",
21-
uniswapV2RouterAddress: "0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24",
22-
uniswapV3SwapRouter: "0x2626664c2603336E57B271c5C0b26F421741e481",
23-
uniswapV3Quoter: "0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a"
24-
},
25-
wtoken: base.chainAddresses.W_TOKEN,
26-
nativeTokenUsdChainlinkFeed: base.chainAddresses.W_TOKEN_USD_CHAINLINK_PRICE_FEED
27-
};
26+
// const chainlinkAssets: ChainlinkAsset[] = base.assets
27+
// .filter((asset) => asset.oracle === OracleTypes.ChainlinkPriceOracleV2)
28+
// .map((asset) => ({
29+
// aggregator: (asset.oracleSpecificParams as ChainlinkSpecificParams).aggregator,
30+
// feedBaseCurrency: (asset.oracleSpecificParams as ChainlinkSpecificParams).feedBaseCurrency,
31+
// symbol: asset.symbol
32+
// }));
2833

29-
const chainlinkAssets: ChainlinkAsset[] = base.assets
30-
.filter((asset) => asset.oracle === OracleTypes.ChainlinkPriceOracleV2)
31-
.map((asset) => ({
32-
aggregator: (asset.oracleSpecificParams as ChainlinkSpecificParams).aggregator,
33-
feedBaseCurrency: (asset.oracleSpecificParams as ChainlinkSpecificParams).feedBaseCurrency,
34-
symbol: asset.symbol
35-
}));
34+
// export const deploy = async ({ run, ethers, getNamedAccounts, deployments }): Promise<void> => {
35+
// const { deployer } = await getNamedAccounts();
3636

37-
export const deploy = async ({ run, ethers, getNamedAccounts, deployments }): Promise<void> => {
38-
const { deployer } = await getNamedAccounts();
37+
// //// ChainLinkV2 Oracle
38+
// await deployChainlinkOracle({
39+
// run,
40+
// ethers,
41+
// getNamedAccounts,
42+
// deployments,
43+
// deployConfig,
44+
// assets,
45+
// chainlinkAssets
46+
// });
3947

40-
//// ChainLinkV2 Oracle
41-
await deployChainlinkOracle({
42-
run,
43-
ethers,
44-
getNamedAccounts,
45-
deployments,
46-
deployConfig,
47-
assets,
48-
chainlinkAssets
49-
});
48+
// //// Uniswap V3 Liquidator Funder
49+
// const uniswapV3LiquidatorFunder = await deployments.deploy("UniswapV3LiquidatorFunder", {
50+
// from: deployer,
51+
// args: [],
52+
// log: true,
53+
// waitConfirmations: 1
54+
// });
55+
// console.log("UniswapV3LiquidatorFunder: ", uniswapV3LiquidatorFunder.address);
5056

51-
//// Uniswap V3 Liquidator Funder
52-
const uniswapV3LiquidatorFunder = await deployments.deploy("UniswapV3LiquidatorFunder", {
53-
from: deployer,
54-
args: [],
55-
log: true,
56-
waitConfirmations: 1
57-
});
58-
console.log("UniswapV3LiquidatorFunder: ", uniswapV3LiquidatorFunder.address);
59-
60-
const solidlySwapLiquidator = await deployments.deploy("SolidlySwapLiquidator", {
61-
from: deployer,
62-
args: [],
63-
log: true,
64-
waitConfirmations: 1
65-
});
66-
console.log("solidlySwapLiquidator: ", solidlySwapLiquidator.address);
67-
};
57+
// const solidlySwapLiquidator = await deployments.deploy("SolidlySwapLiquidator", {
58+
// from: deployer,
59+
// args: [],
60+
// log: true,
61+
// waitConfirmations: 1
62+
// });
63+
// console.log("solidlySwapLiquidator: ", solidlySwapLiquidator.address);
64+
// };

chainDeploy/mainnets/mode.ts

+30-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
import { Hash, zeroAddress } from "viem";
2+
13
import { ChainDeployConfig, deployChainlinkOracle, deployPythPriceOracle } from "../helpers";
24
import { writeTransactionsToFile } from "../helpers/logging";
35
import { addRedstoneFallbacks } from "../helpers/oracles/redstoneFallbacks";
46
import { addRedstoneWeETHFallbacks } from "../helpers/oracles/redstoneWeETHFallbacks";
57
import { deployRedStoneWrsETHPriceOracle } from "../helpers/oracles/redstoneWrsETH";
6-
import { ChainlinkAsset, PythAsset, RedStoneAsset } from "../../chains/types";
8+
import { ChainlinkAsset, ChainlinkFeedBaseCurrency, PythAsset, RedStoneAsset } from "../../chains/types";
9+
import { mode } from "../../chains";
10+
import { underlying } from "../helpers/utils";
11+
import { assetSymbols } from "../../chains/assets";
12+
import { HardhatRuntimeEnvironment } from "hardhat/types";
713

814
export const deployConfig: ChainDeployConfig = {
915
blocksPerYear: 30 * 60 * 24 * 365, // 30 blocks per minute = 2 sec block time
@@ -69,11 +75,18 @@ const convertedApi3Assets: PythAsset[] = api3Assets.map((asset) => ({
6975
feed: asset.aggregator
7076
}));
7177

72-
export const deploy = async ({ run, ethers, getNamedAccounts, deployments }): Promise<void> => {
78+
export const deploy = async ({
79+
run,
80+
viem,
81+
getNamedAccounts,
82+
deployments
83+
}: HardhatRuntimeEnvironment): Promise<void> => {
84+
const { deployer } = await getNamedAccounts();
85+
const publicClient = await viem.getPublicClient();
7386
await deployPythPriceOracle({
7487
run,
7588
deployConfig,
76-
ethers,
89+
viem,
7790
getNamedAccounts,
7891
deployments,
7992
usdToken: mode.chainAddresses.STABLE_TOKEN,
@@ -84,7 +97,7 @@ export const deploy = async ({ run, ethers, getNamedAccounts, deployments }): Pr
8497

8598
await deployChainlinkOracle({
8699
run,
87-
ethers,
100+
viem,
88101
getNamedAccounts,
89102
deployments,
90103
deployConfig,
@@ -93,38 +106,43 @@ export const deploy = async ({ run, ethers, getNamedAccounts, deployments }): Pr
93106
});
94107

95108
await addRedstoneFallbacks({
96-
ethers,
109+
viem,
97110
getNamedAccounts,
98111
deployments,
99-
assets: [...pythAssets, convertedApi3Assets[0]]
112+
redStoneAssets: [...pythAssets, convertedApi3Assets[0]],
113+
redStoneAddress: "0x7C1DAAE7BB0688C9bfE3A918A4224041c7177256",
114+
run,
115+
deployConfig
100116
});
101117

102118
await addRedstoneWeETHFallbacks({
103-
ethers,
119+
viem,
104120
getNamedAccounts,
105121
deployments,
106-
assets: [convertedApi3Assets[1]]
122+
redStoneAssets: [convertedApi3Assets[1]],
123+
redStoneAddress: "0x7C1DAAE7BB0688C9bfE3A918A4224041c7177256",
124+
run,
125+
deployConfig
107126
});
108127

109128
await deployRedStoneWrsETHPriceOracle({
110129
run,
111130
deployConfig,
112-
ethers,
131+
viem,
113132
getNamedAccounts,
114133
deployments,
115134
redStoneAddress: "0x7C1DAAE7BB0688C9bfE3A918A4224041c7177256",
116135
redStoneAssets: redStoneWrsETHAssets
117136
});
118137

119-
const deployer = await ethers.getNamedSigner("deployer");
120138
const algebraSwapLiquidator = await deployments.deploy("AlgebraSwapLiquidator", {
121-
from: deployer.address,
139+
from: deployer,
122140
args: [],
123141
log: true,
124142
waitConfirmations: 1
125143
});
126144
if (algebraSwapLiquidator.transactionHash) {
127-
await ethers.provider.waitForTransaction(algebraSwapLiquidator.transactionHash);
145+
await publicClient.waitForTransactionReceipt({ hash: algebraSwapLiquidator.transactionHash as Hash });
128146
}
129147
console.log("AlgebraSwapLiquidator: ", algebraSwapLiquidator.address);
130148
await writeTransactionsToFile();

0 commit comments

Comments
 (0)