Skip to content

Commit

Permalink
chore: change script to hardhat
Browse files Browse the repository at this point in the history
  • Loading branch information
jr-alpaca committed Oct 11, 2023
1 parent 9b30dd3 commit 7f0c4d5
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 307 deletions.
2 changes: 1 addition & 1 deletion .mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"tusd": "0x14016E85a25aeb13065688cAFB43044C2ef86784",
"usdt": "0x55d398326f99059fF775485246999027B3197955",
"usdc": "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
"wbeth": "",
"wbeth": "0xa2E3356610840701BDf5611a53974510Ae27E2e1",
"wbnb": "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
"xrp": "0x1D2F0da169ceB9fC7B3144628dB156f3F6c60dBE"
},
Expand Down
31 changes: 31 additions & 0 deletions deploy/exec/chainlink-oracle/config/set-price-feed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { IChainLinkPriceOracle__factory } from "../../../../typechain";
import { ConfigFileHelper } from "../../../file-helper.ts/config-file.helper";
import { getDeployer } from "../../../utils/deployer-helper";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const configFileHelper = new ConfigFileHelper();
const config = configFileHelper.getConfig();
/*
░██╗░░░░░░░██╗░█████╗░██████╗░███╗░░██╗██╗███╗░░██╗░██████╗░
░██║░░██╗░░██║██╔══██╗██╔══██╗████╗░██║██║████╗░██║██╔════╝░
░╚██╗████╗██╔╝███████║██████╔╝██╔██╗██║██║██╔██╗██║██║░░██╗░
░░████╔═████║░██╔══██║██╔══██╗██║╚████║██║██║╚████║██║░░╚██╗
░░╚██╔╝░╚██╔╝░██║░░██║██║░░██║██║░╚███║██║██║░╚███║╚██████╔╝
░░░╚═╝░░░╚═╝░░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝╚═╝╚═╝░░╚══╝░╚═════╝░
Check all variables below before execute the deployment script
*/
const TOKEN0S: string[] = [config.tokens.wbeth];
const TOKEN1S: string[] = [config.usdPlaceholder];
const SOURCES: string[] = ["0x97398272a927c56735f7bfce95752540f5e23ccd"];

const deployer = await getDeployer();
const chainLinkOracle = IChainLinkPriceOracle__factory.connect(config.oracle.chainlinkOracle, deployer);

const setPriceFeedTx = await chainLinkOracle.setPriceFeeds(TOKEN0S, TOKEN1S, SOURCES);
console.log(`✅Done: ${setPriceFeedTx.hash}`);
};

export default func;
func.tags = ["SetPriceFeed"];
40 changes: 37 additions & 3 deletions deploy/exec/money-market/config/open-market.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { reverseAssetTier } from "./../../../interfaces";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { getDeployer } from "../../../utils/deployer-helper";
Expand Down Expand Up @@ -38,7 +39,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Check all variables below before execute the deployment script
*/

const inputs: OpenMarketInput[] = [
const openMarketInputs: OpenMarketInput[] = [
{
token: config.tokens.wbeth,
interestModel: config.sharedConfig.doubleSlope2,
Expand All @@ -54,9 +55,9 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

const moneyMarket = IMoneyMarket__factory.connect(config.moneyMarket.moneyMarketDiamond, deployer);

for (const input of inputs) {
for (const input of openMarketInputs) {
const token = ERC20__factory.connect(input.token, deployer);
const tokenDecimal = await token.decimals();
const [tokenSymbol, tokenDecimal] = await Promise.all([token.symbol(), token.decimals()]);

const maxBorrow = parseUnits(input.maxBorrow.toString(), tokenDecimal);
const maxCollateral = parseUnits(input.maxCollateral.toString(), tokenDecimal);
Expand Down Expand Up @@ -86,6 +87,39 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const setInterestModelTx = await moneyMarket.setInterestModel(input.token, input.interestModel);
await setInterestModelTx.wait();
console.log(`✅Done:${setInterestModelTx.hash}`);

const [ibToken, debtToken] = await Promise.all([
moneyMarket.getIbTokenFromToken(input.token),
moneyMarket.getDebtTokenFromToken(input.token),
]);

const [ibPId, debtPid] = await Promise.all([
moneyMarket.getMiniFLPoolIdOfToken(ibToken),
moneyMarket.getMiniFLPoolIdOfToken(debtToken),
]);

console.log(`Writing new market and miniFL pools`);
configFileHelper.addNewMarket({
name: tokenSymbol,
tier: reverseAssetTier[input.tier as AssetTier],
token: input.token,
ibToken: ibToken,
debtToken: debtToken,
interestModel: input.interestModel,
});
configFileHelper.addMiniFLPool({
id: ibPId.toNumber(),
name: "ib" + tokenSymbol,
stakingToken: ibToken,
rewarders: [],
});
configFileHelper.addMiniFLPool({
id: debtPid.toNumber(),
name: "debt" + tokenSymbol,
stakingToken: debtToken,
rewarders: [],
});
console.log(`✅Done`);
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { OracleMedianizer__factory } from "../../../../typechain";
import { ConfigFileHelper } from "../../../file-helper.ts/config-file.helper";
import { getDeployer } from "../../../utils/deployer-helper";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const configFileHelper = new ConfigFileHelper();
const config = configFileHelper.getConfig();
const DEFAULT_MAX_PRICE_DEVIATION = "1000000000000000000";
const DEFAULT_MAX_PRICE_STALE = 86400;
/*
░██╗░░░░░░░██╗░█████╗░██████╗░███╗░░██╗██╗███╗░░██╗░██████╗░
░██║░░██╗░░██║██╔══██╗██╔══██╗████╗░██║██║████╗░██║██╔════╝░
░╚██╗████╗██╔╝███████║██████╔╝██╔██╗██║██║██╔██╗██║██║░░██╗░
░░████╔═████║░██╔══██║██╔══██╗██║╚████║██║██║╚████║██║░░╚██╗
░░╚██╔╝░╚██╔╝░██║░░██║██║░░██║██║░╚███║██║██║░╚███║╚██████╔╝
░░░╚═╝░░░╚═╝░░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝╚═╝╚═╝░░╚══╝░╚═════╝░
Check all variables below before execute the deployment script
*/

const TOKEN0S: string[] = [config.tokens.wbeth];
const TOKEN1S: string[] = [config.usdPlaceholder];
const MAX_PRICE_DEVIATIONS: string[] = [DEFAULT_MAX_PRICE_DEVIATION];
const MAX_PRICE_STALES: number[] = [DEFAULT_MAX_PRICE_STALE];
const SOURCES = [[config.oracle.chainlinkOracle]];

const deployer = await getDeployer();
const oracleMedianizer = OracleMedianizer__factory.connect(config.oracle.oracleMedianizer, deployer);

const setMultiplePrimarySourcesTx = await oracleMedianizer.setMultiPrimarySources(
TOKEN0S,
TOKEN1S,
MAX_PRICE_DEVIATIONS,
MAX_PRICE_STALES,
SOURCES
);
console.log(`✅Done: ${setMultiplePrimarySourcesTx.hash}`);
};

export default func;
func.tags = ["SetMultiplePrimarySources"];
5 changes: 2 additions & 3 deletions deploy/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface UpgradableContract {
interface AccountManager extends UpgradableContract {}

export interface Config {
usdPlaceholder: string;
moneyMarket: MoneyMarket;
sharedConfig: SharedConfig;
tokens: Tokens;
Expand Down Expand Up @@ -84,16 +85,14 @@ export interface Rewarder {
rewardToken: string;
}

// export type AssetTier = 0 | 1 | 2 | 3;
export enum AssetTier {
UNLISTED = 0,
ISOLATE = 1,
CROSS = 2,
COLLATERAL = 3,
}

type AssetTierString = "UNLISTED" | "ISOLATE" | "CROSS" | "COLLATERAL";
export const reverseAssetTier: Record<AssetTier, AssetTierString> = {
export const reverseAssetTier: Record<AssetTier, keyof typeof AssetTier> = {
0: "UNLISTED",
1: "ISOLATE",
2: "CROSS",
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"exec:bsc_mainnet:debt-token:deploy": "forge script script/deployments/DebtToken/deploy/DebtTokenImplementation.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:money-market:deploy": "forge script script/deployments/MoneyMarket/deploy/MoneyMarket.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:money-market:cut:flash-loan-facet": "forge script script/deployments/MoneyMarket/diamond-cut/FlashloanFacetCut.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:money-market:config:open-market": "forge script script/deployments/MoneyMarket/config/OpenMarket.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:money-market:config:set-interest-model": "forge script script/deployments/MoneyMarket/config/SetInterestModel.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:money-market:config:set-fees": "forge script script/deployments/MoneyMarket/config/SetFees.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:money-market:config:set-max-num-token": "forge script script/deployments/MoneyMarket/config/SetMaxNumOfToken.s.sol --rpc-url bsc_mainnet --broadcast --slow",
Expand Down Expand Up @@ -63,10 +62,8 @@
"exec:bsc_mainnet:alpaca-v2-oracle:config:set-oracle": "forge script script/deployments/AlpacaV2Oracle/config/SetOracle.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:alpaca-v2-oracle02:deploy": "forge script script/deployments/AlpacaV2Oracle02/deploy/AlpacaV2Oracle02.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:oracle-medianizer:deploy": "forge script script/deployments/OracleMedianizer/deploy/OracleMedianizer.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:oracle-medianizer:config:set-multiple-primary-sources": "forge script script/deployments/OracleMedianizer/config/SetMultiPrimarySources.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:wnative-relayer:config:set-caller-ok": "forge script script/deployments/WNativeRelayer/config/setCallerOk.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:money-market-reader:deploy": "forge script script/deployments/MoneyMarketReader/deploy/MoneyMarketReader.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:chainlink-price-oracle:config:set-price-feeds": "forge script script/deployments/ChainLinkOracle/config/SetPriceFeeds.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:fix-fee-model-500-bps:deploy": "forge script script/deployments/RepurchaseRewardModel/deploy/FixedFeeModel500Bps.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:triple-slope-model0:deploy": "forge script script/deployments/InterestModels/deploy/TripleSlopeModel0.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:double-slope-model1:deploy": "forge script script/deployments/InterestModels/deploy/MMDoubleSlopeModel1.s.sol --rpc-url bsc_mainnet --broadcast --slow",
Expand Down Expand Up @@ -97,7 +94,10 @@
"exec:bsc_mainnet:money-market:diamond-cut": "hardhat --network bsc_mainnet deploy --no-compile --reset --tags ExecuteDiamondCut",
"exec:bsc_mainnet:money-market:upgrade:account-manager": "hardhat --network bsc_mainnet deploy --no-compile --reset --tags UpgradeMoneyMarketAccountManager",
"exec:bsc_mainnet:config:transfer-ownership": "hardhat --network bsc_mainnet deploy --no-compile --reset --tags TransferOwnership",
"exec:bsc_mainnet:config:accept-ownership": "hardhat --network bsc_mainnet deploy --no-compile --reset --tags AcceptOwnership"
"exec:bsc_mainnet:config:accept-ownership": "hardhat --network bsc_mainnet deploy --no-compile --reset --tags AcceptOwnership",
"exec:bsc_mainnet:money-market:config:open-market": "hardhat --network bsc_mainnet deploy --no-compile --reset --tags OpenMarket",
"exec:bsc_mainnet:chainlink-price-oracle:config:set-price-feeds": "hardhat --network bsc_mainnet deploy --no-compile --reset --tags SetPriceFeed",
"exec:bsc_mainnet:oracle-medianizer:config:set-multiple-primary-sources": "hardhat --network bsc_mainnet deploy --no-compile --reset --tags SetMultiplePrimarySources"
},
"devDependencies": {
"@safe-global/safe-core-sdk": "^3.3.3",
Expand Down
56 changes: 0 additions & 56 deletions script/deployments/ChainLinkOracle/config/SetPriceFeeds.s.sol

This file was deleted.

118 changes: 0 additions & 118 deletions script/deployments/MoneyMarket/config/OpenMarket.s.sol

This file was deleted.

Loading

0 comments on commit 7f0c4d5

Please sign in to comment.