Skip to content

Commit

Permalink
Merge branch 'main' into chore/upgrade-account-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
wow-alpaca committed May 22, 2023
2 parents 81d23ac + bde188f commit cdebd0f
Show file tree
Hide file tree
Showing 25 changed files with 1,410 additions and 202 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ yarn-error.log
broadcast/

deployedAddresses.json

yarn-error.log
2 changes: 2 additions & 0 deletions .mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"doge": "0xbA2aE424d960c26247Dd6c32edC70B295c744C43",
"dot": "0x7083609fCE4d1d8Dc0C979AAb8c869Ea2C873402",
"eth": "0x2170Ed0880ac9A755fd29B2688956BD959F933F8",
"high": "0x5f4Bde007Dc06b867f86EBFE4802e34A1fFEEd63",
"matic": "0xCC42724C6683B7E57334c4E856f4c9965ED682bD",
"tusd": "0x14016E85a25aeb13065688cAFB43044C2ef86784",
"usdt": "0x55d398326f99059fF775485246999027B3197955",
Expand Down Expand Up @@ -197,6 +198,7 @@
}
]
},
"rewarders": [],
"moneyMarketReader": "0x4913DEC75cC0e061Ba78ebbDb2584905760be4C6",
"smartTreasury": {
"implementation": "",
Expand Down
17 changes: 16 additions & 1 deletion deploy/file-helper.ts/config-file.helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config, Market, MiniFLPool } from "../interfaces";
import { Config, Market, MiniFLPool, Rewarder } from "../interfaces";
import MainnetConfig from "../../.mainnet.json";
import * as fs from "fs";

Expand All @@ -20,6 +20,21 @@ export class ConfigFileHelper {
this._writeConfigFile(this.config);
}

public setMiniFLPoolRewarders(pid: number, rewarderAddresses: string[]): void {
const miniFLPool = this.config.miniFL.pools.find((pool) => pool.id === Number(pid))!;

const rewarders = rewarderAddresses.map(
(rewarder) => this.config.rewarders.find((configRewarder) => configRewarder.address === rewarder)!
);
miniFLPool.rewarders = rewarders;
this._writeConfigFile(this.config);
}

public addRewarder(rewarder: Rewarder): void {
this.config.rewarders.push(rewarder);
this._writeConfigFile(this.config);
}

public getConfig() {
return this.config;
}
Expand Down
9 changes: 8 additions & 1 deletion deploy/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface UpgradableContract {
export interface Config {
moneyMarket: MoneyMarket;
miniFL: MiniFL;
rewarders: Rewarder[];
proxyAdmin: string;
timelock: string;
opMultiSig: string;
Expand Down Expand Up @@ -47,7 +48,13 @@ export interface MiniFLPool {
id: number;
name: string;
stakingToken: string;
rewarders: string[];
rewarders: Rewarder[];
}

export interface Rewarder {
name: string;
address: string;
rewardToken: string;
}

export type AssetTier = 0 | 1 | 2 | 3;
Expand Down
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const config: HardhatUserConfig = {
},
paths: {
sources: "./solidity/contracts",
tests: "./test",
cache: "./cache",
artifacts: "./artifacts",
},
Expand Down
15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@alpaca-finance/alpaca-money-market",
"version": "1.0.0",
"version": "0.0.3",
"main": "index.js",
"license": "MIT",
"scripts": {
"compile": "hardhat typechain --config hardhat.config.ts",
"hardhat": "hardhat",
"build": "yarn run build:cjs",
"prepublishOnly": "yarn compile",
"compile": "hardhat compile && yarn build",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build": "yarn run build:cjs",
"bsc_mainnet": "hardhat console --no-compile --network bsc_mainnet",
"----------Deploy Foundry Script-------------": "----------Deploy Foundry Script-------------",
"exec:bsc_mainnet:proxy-admin:deploy": "forge script script/deployments/ProxyAdmin/deploy/ProxyAdmin.s.sol --rpc-url bsc_mainnet --broadcast --slow",
Expand Down Expand Up @@ -40,9 +40,11 @@
"exec:bsc_mainnet:money-market:config:set-operator-ok": "forge script script/deployments/MoneyMarket/config/SetOperatorsOk.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:money-market:config:withdraw-protocol-reserves": "forge script script/deployments/MoneyMarket/config/WithdrawProtocolReserves.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:money-market:config:set-flash-loan-params": "forge script script/deployments/MoneyMarket/config/SetFlashloanParams.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:money-market:config:set-token-max-capacity": "forge script script/deployments/MoneyMarket/config/SetTokenMaximumCapacities.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:money-market:admin-facet:deploy": "forge script script/deployments/MoneyMarket/deploy/AdminFacet.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:money-market:flash-loan-facet:deploy": "forge script script/deployments/MoneyMarket/deploy/FlashloanFacet.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:money-market:view-facet:deploy": "forge script script/deployments/MoneyMarket/deploy/ViewFacet.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:money-market:liquidation-facet:deploy": "forge script script/deployments/MoneyMarket/deploy/LiquidationFacet.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:mm-account-manager:deploy": "forge script script/deployments/MoneyMarketAccountManager/deploy/MoneyMarketAccountManager.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:pancake-v2-liquidate-strat:deploy": "forge script script/deployments/PancakeswapV2LiquidationStrategy/deploy/PancakeswapV2LiquidationStrategy.s.sol --rpc-url bsc_mainnet --broadcast --slow",
"exec:bsc_mainnet:pancake-v2-liquidate-ib-strat:deploy": "forge script script/deployments/PancakeswapV2IbTokenLiquidationStrategy/deploy/PancakeswapV2IbTokenLiquidationStrategy.s.sol --rpc-url bsc_mainnet --broadcast --slow",
Expand Down Expand Up @@ -93,6 +95,7 @@
"@openzeppelin/contracts": "^4.7.1",
"@openzeppelin/contracts-upgradeable": "^4.7.3",
"@openzeppelin/hardhat-upgrades": "^1.16.1",
"@typechain/ethers-v5": "^10.2.0",
"commander": "^9.2.0",
"dotenv": "^16.0.0",
"ethers": "^5.7.0",
Expand All @@ -101,6 +104,10 @@
"prettier": "^2.6.0",
"prettier-plugin-solidity": "^1.0.0-beta.19"
},
"files": [
"typechain",
"artifacts"
],
"engines": {
"node": ">=14.15.4"
}
Expand Down
2 changes: 2 additions & 0 deletions script/BaseScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ abstract contract BaseScript is Script {
address internal doge;
address internal dot;
address internal eth;
address internal high;
address internal matic;
address internal tusd;
address internal usdt;
Expand Down Expand Up @@ -134,6 +135,7 @@ abstract contract BaseScript is Script {
doge = abi.decode(configJson.parseRaw(".tokens.doge"), (address));
dot = abi.decode(configJson.parseRaw(".tokens.dot"), (address));
eth = abi.decode(configJson.parseRaw(".tokens.eth"), (address));
high = abi.decode(configJson.parseRaw(".tokens.high"), (address));
matic = abi.decode(configJson.parseRaw(".tokens.matic"), (address));
tusd = abi.decode(configJson.parseRaw(".tokens.tusd"), (address));
usdt = abi.decode(configJson.parseRaw(".tokens.usdt"), (address));
Expand Down
39 changes: 8 additions & 31 deletions script/deployments/AlpacaV2Oracle/config/SetTokenConfig.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,17 @@ contract SetTokenConfigScript is BaseScript {

// set alpaca guard path

// WBNB
alpacaGuardPath.push(wbnb);
alpacaGuardPath.push(usdt);
addSetTokenConfigList(
IAlpacaV2Oracle.Config({ path: alpacaGuardPath, router: address(0), maxPriceDiffBps: 10500, isUsingV3Pool: true })
);

// USDC
alpacaGuardPath.push(usdc);
alpacaGuardPath.push(usdt);
addSetTokenConfigList(
IAlpacaV2Oracle.Config({ path: alpacaGuardPath, router: address(0), maxPriceDiffBps: 10500, isUsingV3Pool: true })
);

// BUSD
// HIGH
alpacaGuardPath.push(high);
alpacaGuardPath.push(busd);
alpacaGuardPath.push(usdt);
addSetTokenConfigList(
IAlpacaV2Oracle.Config({ path: alpacaGuardPath, router: address(0), maxPriceDiffBps: 10500, isUsingV3Pool: true })
);

// BTCB
alpacaGuardPath.push(btcb);
alpacaGuardPath.push(usdt);
addSetTokenConfigList(
IAlpacaV2Oracle.Config({ path: alpacaGuardPath, router: address(0), maxPriceDiffBps: 10500, isUsingV3Pool: true })
);

// ETH
alpacaGuardPath.push(eth);
alpacaGuardPath.push(wbnb);
alpacaGuardPath.push(usdt);
addSetTokenConfigList(
IAlpacaV2Oracle.Config({ path: alpacaGuardPath, router: address(0), maxPriceDiffBps: 10500, isUsingV3Pool: true })
IAlpacaV2Oracle.Config({
path: alpacaGuardPath,
router: pancakeswapRouterV2,
maxPriceDiffBps: 10500,
isUsingV3Pool: false
})
);

//---- execution ----//
Expand Down
6 changes: 3 additions & 3 deletions script/deployments/ChainLinkOracle/config/SetPriceFeeds.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ contract SetPriceFeedsScript is BaseScript {
Check all variables below before execute the deployment script
*/

// USDC
// HIGH
addSetPriceFeeds(
SetPriceFeedsInput({
token0: usdc,
token0: high,
token1: usdPlaceholder,
source: IAggregatorV3(0x51597f405303C4377E36123cBc172b13269EA163)
source: IAggregatorV3(0xdF4Dd957a84F798acFADd448badd2D8b9bC99047)
})
);

Expand Down
2 changes: 1 addition & 1 deletion script/deployments/MiniFL/config/SetAlpacaPerSecond.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract SetAlpacaPerSecondScript is BaseScript {
Check all variables below before execute the deployment script
*/

uint256 _newAlpacaPerSecond = 33068783068783070;
uint256 _newAlpacaPerSecond = 0.1421957671957672 ether;
bool _withUpdate = true;

//---- execution ----//
Expand Down
52 changes: 49 additions & 3 deletions script/deployments/MiniFL/config/SetPoolRewarders.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ pragma solidity 0.8.19;
import "../../../BaseScript.sol";

contract SetPoolRewardersScript is BaseScript {
struct SetPoolRewarderInput {
uint256 pId;
address[] rewarders;
}

SetPoolRewarderInput[] setPoolRewarderInputs;

function run() public {
/*
░██╗░░░░░░░██╗░█████╗░██████╗░███╗░░██╗██╗███╗░░██╗░██████╗░
Expand All @@ -15,15 +22,54 @@ contract SetPoolRewardersScript is BaseScript {
Check all variables below before execute the deployment script
*/

uint256 _pid = 1;
address[] memory rewarders = new address[](1);
rewarders[0] = 0x0886B13E413bc0fBAeDB76b0855CA5F2dae82E99;
rewarders[0] = 0x7180f062aa725057EB110224a262f64978e89b24;

setIbPoolRewarders(high, rewarders);
setDebtPoolRewarders(high, rewarders);

//---- execution ----//
_startDeployerBroadcast();

miniFL.setPoolRewarders(_pid, rewarders);
for (uint256 i; i < setPoolRewarderInputs.length; i++) {
miniFL.setPoolRewarders(setPoolRewarderInputs[i].pId, setPoolRewarderInputs[i].rewarders);

writeRewarderToMiniFLPool(setPoolRewarderInputs[i].pId, setPoolRewarderInputs[i].rewarders);
}

_stopBroadcast();
}

function setIbPoolRewarders(address _token, address[] memory _rewarders) internal {
address _ibToken = moneyMarket.getIbTokenFromToken(_token);
uint256 _pId = moneyMarket.getMiniFLPoolIdOfToken(_ibToken);
setPoolRewarders(_pId, _rewarders);
}

function setDebtPoolRewarders(address _token, address[] memory _rewarders) internal {
address _debtToken = moneyMarket.getDebtTokenFromToken(_token);
uint256 _pId = moneyMarket.getMiniFLPoolIdOfToken(_debtToken);
setPoolRewarders(_pId, _rewarders);
}

function setPoolRewarders(uint256 _pId, address[] memory _rewarders) internal {
setPoolRewarderInputs.push(SetPoolRewarderInput({ pId: _pId, rewarders: _rewarders }));
}

function writeRewarderToMiniFLPool(uint256 _pId, address[] memory _rewarders) internal {
uint256 rewardersLength = _rewarders.length;
string[] memory cmds = new string[](6 + rewardersLength);
cmds[0] = "npx";
cmds[1] = "ts-node";
cmds[2] = "./type-script/scripts/set-mini-fl-pool-rewarders.ts";
cmds[3] = "--pid";
cmds[4] = vm.toString(_pId);
cmds[5] = "--rewarderAddress";

for (uint256 i; i < rewardersLength; i++) {
cmds[6 + i] = vm.toString(_rewarders[i]);
}

vm.ffi(cmds);
}
}
79 changes: 7 additions & 72 deletions script/deployments/MoneyMarket/config/OpenMarket.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,81 +31,16 @@ contract OpenMarketScript is BaseScript {
*/
_startDeployerBroadcast();

// WBNB
// HIGH
executeOpenMarket(
OpenMarketInput({
token: wbnb,
token: high,
interestModel: doubleSlope1,
tier: LibConstant.AssetTier.COLLATERAL,
collateralFactor: 8000,
borrowingFactor: 8500,
maxCollateral: 250_000 ether,
maxBorrow: 200_000 ether
})
);

// USDC
executeOpenMarket(
OpenMarketInput({
token: usdc,
interestModel: doubleSlope3,
tier: LibConstant.AssetTier.COLLATERAL,
collateralFactor: 9000,
borrowingFactor: 9400,
maxCollateral: 75_000_000 ether,
maxBorrow: 50_000_000 ether
})
);

// USDT
executeOpenMarket(
OpenMarketInput({
token: usdt,
interestModel: doubleSlope3,
tier: LibConstant.AssetTier.COLLATERAL,
collateralFactor: 9000,
borrowingFactor: 9400,
maxCollateral: 75_000_000 ether,
maxBorrow: 50_000_000 ether
})
);

// BUSD
executeOpenMarket(
OpenMarketInput({
token: busd,
interestModel: doubleSlope3,
tier: LibConstant.AssetTier.COLLATERAL,
collateralFactor: 9000,
borrowingFactor: 9400,
maxCollateral: 75_000_000 ether,
maxBorrow: 50_000_000 ether
})
);

// BTCB
executeOpenMarket(
OpenMarketInput({
token: btcb,
interestModel: doubleSlope2,
tier: LibConstant.AssetTier.COLLATERAL,
collateralFactor: 8800,
borrowingFactor: 9100,
maxCollateral: 5_000 ether,
maxBorrow: 4_500 ether
})
);

// ETH
executeOpenMarket(
OpenMarketInput({
token: eth,
interestModel: doubleSlope2,
tier: LibConstant.AssetTier.COLLATERAL,
collateralFactor: 8800,
borrowingFactor: 9100,
maxCollateral: 50_000 ether,
maxBorrow: 45_000 ether
tier: LibConstant.AssetTier.CROSS,
collateralFactor: 0,
borrowingFactor: 5000,
maxCollateral: 0 ether,
maxBorrow: 500_000 ether
})
);

Expand Down
Loading

0 comments on commit cdebd0f

Please sign in to comment.