Skip to content

Commit dc89e01

Browse files
authored
Merge pull request #150 from stabilitydao/143-base
fix and refactor deploy system, libs
2 parents 6705a0c + c001a80 commit dc89e01

17 files changed

+430
-510
lines changed

chains/BaseLib.sol

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ import "../src/interfaces/IFactory.sol";
1010
import "../src/interfaces/IPlatform.sol";
1111
import "../src/interfaces/ISwapper.sol";
1212
import "../src/integrations/convex/IConvexRewardPool.sol";
13-
import "../script/libs/DeployLib.sol";
13+
import "../script/libs/LogDeployLib.sol";
1414
import "../script/libs/DeployAdapterLib.sol";
15-
import "../script/libs/DeployStrategyLib.sol";
15+
import "../src/interfaces/IPlatformDeployer.sol";
16+
import "../src/strategies/CompoundFarmStrategy.sol";
17+
import "../src/strategies/libs/StrategyDeveloperLib.sol";
1618

17-
/// @dev Addresses, routes, farms, strategy logics, reward tokens, deploy function and other data for Base network
19+
/// @dev Base network [chainId: 8453] data library
20+
/// ┳┓
21+
/// ┣┫┏┓┏┏┓
22+
/// ┻┛┗┻┛┗
23+
/// @author Alien Deployer (https://github.com/a17)
1824
library BaseLib {
1925
// initial addresses
2026
address public constant MULTISIG = 0x626Bd898ca994c11c9014377f4c50d30f2B0006c; // team
@@ -59,28 +65,32 @@ library BaseLib {
5965
// DeX aggregators
6066
address public constant ONE_INCH = 0x1111111254EEB25477B68fb85Ed929f73A960582;
6167

62-
function runDeploy(bool showLog) internal returns (address platform) {
63-
//region ----- Deploy Platform -----
64-
uint[] memory buildingPrice = new uint[](1);
65-
buildingPrice[0] = 100e6;
66-
platform = DeployLib.deployPlatform(
67-
"24.06.0-alpha",
68-
MULTISIG,
69-
address(0),
70-
TOKEN_USDC,
71-
buildingPrice,
72-
"Base",
73-
CommonLib.bytesToBytes32(abi.encodePacked(bytes3(0x2356f0), bytes3(0x000000))),
74-
TOKEN_USDC,
75-
address(0),
76-
1e16,
77-
2e16
78-
);
68+
function platformDeployParams() internal pure returns (IPlatformDeployer.DeployPlatformParams memory p) {
69+
p.multisig = MULTISIG;
70+
p.version = "24.06.0-alpha";
71+
p.buildingPermitToken = address(0);
72+
p.buildingPayPerVaultToken = TOKEN_USDC;
73+
p.networkName = "Base";
74+
p.networkExtra = CommonLib.bytesToBytes32(abi.encodePacked(bytes3(0x2356f0), bytes3(0x000000)));
75+
p.targetExchangeAsset = TOKEN_USDC;
76+
p.gelatoAutomate = address(0);
77+
p.gelatoMinBalance = 1e16;
78+
p.gelatoDepositAmount = 2e16;
79+
}
80+
81+
function deployAndSetupInfrastructure(address platform, bool showLog) internal {
82+
IFactory factory = IFactory(IPlatform(platform).factory());
83+
84+
//region ----- Deployed Platform -----
7985
if (showLog) {
8086
console.log("Deployed Stability platform", IPlatform(platform).platformVersion());
8187
console.log("Platform address: ", platform);
8288
}
83-
//endregion -- Deploy Platform ----
89+
//endregion -- Deployed Platform ----
90+
91+
//region ----- Deploy and setup vault types -----
92+
_addVaultType(factory, VaultTypeLib.COMPOUNDING, address(new CVault()), 100e6);
93+
//endregion -- Deploy and setup vault types -----
8494

8595
//region ----- Deploy and setup oracle adapters -----
8696
IPriceReader priceReader = PriceReader(IPlatform(platform).priceReader());
@@ -100,14 +110,14 @@ library BaseLib {
100110
priceFeeds[2] = ORACLE_CHAINLINK_cbETH_USD;
101111
chainlinkAdapter.addPriceFeeds(assets, priceFeeds);
102112
priceReader.addAdapter(address(chainlinkAdapter));
103-
DeployLib.logDeployAndSetupOracleAdapter("ChainLink", address(chainlinkAdapter), showLog);
113+
LogDeployLib.logDeployAndSetupOracleAdapter("ChainLink", address(chainlinkAdapter), showLog);
104114
}
105115
//endregion -- Deploy and setup oracle adapters -----
106116

107117
//region ----- Deploy AMM adapters -----
108118
DeployAdapterLib.deployAmmAdapter(platform, AmmAdapterIdLib.UNISWAPV3);
109119
DeployAdapterLib.deployAmmAdapter(platform, AmmAdapterIdLib.CURVE);
110-
DeployLib.logDeployAmmAdapters(platform, showLog);
120+
LogDeployLib.logDeployAmmAdapters(platform, showLog);
111121
//endregion -- Deploy AMM adapters ----
112122

113123
//region ----- Setup Swapper -----
@@ -135,19 +145,18 @@ library BaseLib {
135145
thresholdAmount[6] = 1e15;
136146
thresholdAmount[7] = 1e15;
137147
swapper.setThresholds(tokenIn, thresholdAmount);
138-
DeployLib.logSetupSwapper(platform, showLog);
148+
LogDeployLib.logSetupSwapper(platform, showLog);
139149
}
140150
//endregion -- Setup Swapper -----
141151

142152
//region ----- Add farms -----
143-
IFactory factory = IFactory(IPlatform(platform).factory());
144153
factory.addFarms(farms());
145-
DeployLib.logAddedFarms(address(factory), showLog);
154+
LogDeployLib.logAddedFarms(address(factory), showLog);
146155
//endregion -- Add farms -----
147156

148157
//region ----- Deploy strategy logics -----
149-
DeployStrategyLib.deployStrategy(platform, StrategyIdLib.COMPOUND_FARM, true);
150-
DeployLib.logDeployStrategies(platform, showLog);
158+
_addStrategyLogic(factory, StrategyIdLib.COMPOUND_FARM, address(new CompoundFarmStrategy()), true);
159+
LogDeployLib.logDeployStrategies(platform, showLog);
151160
//endregion -- Deploy strategy logics -----
152161

153162
//region ----- Add DeX aggregators -----
@@ -219,5 +228,31 @@ library BaseLib {
219228
return farm;
220229
}
221230

231+
function _addVaultType(IFactory factory, string memory id, address implementation, uint buildingPrice) internal {
232+
factory.setVaultConfig(
233+
IFactory.VaultConfig({
234+
vaultType: id,
235+
implementation: implementation,
236+
deployAllowed: true,
237+
upgradeAllowed: true,
238+
buildingPrice: buildingPrice
239+
})
240+
);
241+
}
242+
243+
function _addStrategyLogic(IFactory factory, string memory id, address implementation, bool farming) internal {
244+
factory.setStrategyLogicConfig(
245+
IFactory.StrategyLogicConfig({
246+
id: id,
247+
implementation: address(implementation),
248+
deployAllowed: true,
249+
upgradeAllowed: true,
250+
farming: farming,
251+
tokenId: type(uint).max
252+
}),
253+
StrategyDeveloperLib.getDeveloper(id)
254+
);
255+
}
256+
222257
function testChainLib() external {}
223258
}

chains/PolygonLib.sol

Lines changed: 86 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,32 @@ pragma solidity ^0.8.23;
44
import "../src/core/proxy/Proxy.sol";
55
import "../src/adapters/libs/AmmAdapterIdLib.sol";
66
import "../src/adapters/ChainlinkAdapter.sol";
7-
import "../src/strategies/libs/StrategyIdLib.sol";
8-
import "../src/strategies/libs/ALMPositionNameLib.sol";
97
import "../src/interfaces/IFactory.sol";
108
import "../src/interfaces/IPlatform.sol";
119
import "../src/interfaces/ISwapper.sol";
10+
import "../src/interfaces/IPlatformDeployer.sol";
1211
import "../src/integrations/convex/IConvexRewardPool.sol";
13-
import "../script/libs/DeployLib.sol";
12+
import "../script/libs/LogDeployLib.sol";
1413
import "../script/libs/DeployAdapterLib.sol";
15-
import "../script/libs/DeployStrategyLib.sol";
16-
17-
/// @dev Addresses, routes, farms, strategy logics, reward tokens, deploy function and other data for Polygon network
14+
import "../src/strategies/libs/StrategyIdLib.sol";
15+
import "../src/strategies/libs/ALMPositionNameLib.sol";
16+
import "../src/strategies/libs/StrategyDeveloperLib.sol";
17+
import "../src/strategies/GammaQuickSwapMerklFarmStrategy.sol";
18+
import "../src/strategies/QuickSwapStaticMerklFarmStrategy.sol";
19+
import "../src/strategies/CompoundFarmStrategy.sol";
20+
import "../src/strategies/DefiEdgeQuickSwapMerklFarmStrategy.sol";
21+
import "../src/strategies/IchiQuickSwapMerklFarmStrategy.sol";
22+
import "../src/strategies/IchiRetroMerklFarmStrategy.sol";
23+
import "../src/strategies/GammaRetroMerklFarmStrategy.sol";
24+
import "../src/strategies/CurveConvexFarmStrategy.sol";
25+
import "../src/strategies/YearnStrategy.sol";
26+
27+
/// @dev Polygon network [chainId: 137] data library
28+
/// ┏┓ ┓
29+
/// ┃┃┏┓┃┓┏┏┓┏┓┏┓
30+
/// ┣┛┗┛┗┗┫┗┫┗┛┛┗
31+
/// ┛ ┛
32+
/// @author Alien Deployer (https://github.com/a17)
1833
library PolygonLib {
1934
// initial addresses
2035
address public constant MULTISIG = 0x36780E69D38c8b175761c6C5F8eD42E61ee490E9; // team
@@ -171,30 +186,34 @@ library PolygonLib {
171186
// Merkl
172187
address public constant MERKL_DISTRIBUTOR = 0x3Ef3D8bA38EBe18DB133cEc108f4D14CE00Dd9Ae;
173188

174-
function runDeploy(bool showLog) internal returns (address platform) {
175-
//region ----- Deploy Platform -----
176-
uint[] memory buildingPrice = new uint[](3);
177-
buildingPrice[0] = 50_000e18;
178-
buildingPrice[1] = 50_000e18;
179-
buildingPrice[2] = 100_000e18;
180-
platform = DeployLib.deployPlatform(
181-
"24.06.0-alpha",
182-
MULTISIG,
183-
TOKEN_PM,
184-
TOKEN_SDIV,
185-
buildingPrice,
186-
"Polygon",
187-
CommonLib.bytesToBytes32(abi.encodePacked(bytes3(0x7746d7), bytes3(0x040206))),
188-
TOKEN_USDCe,
189-
GELATO_AUTOMATE,
190-
1e18,
191-
2e18
192-
);
189+
function platformDeployParams() internal pure returns (IPlatformDeployer.DeployPlatformParams memory p) {
190+
p.multisig = MULTISIG;
191+
p.version = "24.06.0-alpha";
192+
p.buildingPermitToken = TOKEN_PM;
193+
p.buildingPayPerVaultToken = TOKEN_SDIV;
194+
p.networkName = "Polygon";
195+
p.networkExtra = CommonLib.bytesToBytes32(abi.encodePacked(bytes3(0x7746d7), bytes3(0x040206)));
196+
p.targetExchangeAsset = TOKEN_USDCe;
197+
p.gelatoAutomate = GELATO_AUTOMATE;
198+
p.gelatoMinBalance = 1e18;
199+
p.gelatoDepositAmount = 2e18;
200+
}
201+
202+
function deployAndSetupInfrastructure(address platform, bool showLog) internal {
203+
IFactory factory = IFactory(IPlatform(platform).factory());
204+
205+
//region ----- Deployed Platform -----
193206
if (showLog) {
194207
console.log("Deployed Stability platform", IPlatform(platform).platformVersion());
195208
console.log("Platform address: ", platform);
196209
}
197-
//endregion -- Deploy Platform ----
210+
//endregion -- Deployed Platform ----
211+
212+
//region ----- Deploy and setup vault types -----
213+
_addVaultType(factory, VaultTypeLib.COMPOUNDING, address(new CVault()), 50_000e18);
214+
_addVaultType(factory, VaultTypeLib.REWARDING, address(new RVault()), 50_000e18);
215+
_addVaultType(factory, VaultTypeLib.REWARDING_MANAGED, address(new RMVault()), 100_000e18);
216+
//endregion -- Deploy and setup vault types -----
198217

199218
//region ----- Deploy and setup oracle adapters -----
200219
IPriceReader priceReader = PriceReader(IPlatform(platform).priceReader());
@@ -214,7 +233,7 @@ library PolygonLib {
214233
priceFeeds[2] = ORACLE_CHAINLINK_DAI_USD;
215234
chainlinkAdapter.addPriceFeeds(assets, priceFeeds);
216235
priceReader.addAdapter(address(chainlinkAdapter));
217-
DeployLib.logDeployAndSetupOracleAdapter("ChainLink", address(chainlinkAdapter), showLog);
236+
LogDeployLib.logDeployAndSetupOracleAdapter("ChainLink", address(chainlinkAdapter), showLog);
218237
}
219238
//endregion -- Deploy and setup oracle adapters -----
220239

@@ -223,7 +242,7 @@ library PolygonLib {
223242
DeployAdapterLib.deployAmmAdapter(platform, AmmAdapterIdLib.ALGEBRA);
224243
DeployAdapterLib.deployAmmAdapter(platform, AmmAdapterIdLib.KYBER);
225244
DeployAdapterLib.deployAmmAdapter(platform, AmmAdapterIdLib.CURVE);
226-
DeployLib.logDeployAmmAdapters(platform, showLog);
245+
LogDeployLib.logDeployAmmAdapters(platform, showLog);
227246
//endregion -- Deploy AMM adapters ----
228247

229248
//region ----- Setup Swapper -----
@@ -256,12 +275,11 @@ library PolygonLib {
256275
thresholdAmount[8] = 1e15;
257276
thresholdAmount[9] = 1e15;
258277
swapper.setThresholds(tokenIn, thresholdAmount);
259-
DeployLib.logSetupSwapper(platform, showLog);
278+
LogDeployLib.logSetupSwapper(platform, showLog);
260279
}
261280
//endregion -- Setup Swapper -----
262281

263282
//region ----- Add farms -----
264-
IFactory factory = IFactory(IPlatform(platform).factory());
265283
factory.addFarms(farms());
266284
// Jan-09-2024
267285
if (block.number > 52122638) {
@@ -271,7 +289,7 @@ library PolygonLib {
271289
if (block.number > 54573098) {
272290
factory.addFarms(farms3());
273291
}
274-
DeployLib.logAddedFarms(address(factory), showLog);
292+
LogDeployLib.logAddedFarms(address(factory), showLog);
275293
//endregion -- Add farms -----
276294

277295
//region ----- Add strategy available init params -----
@@ -296,20 +314,20 @@ library PolygonLib {
296314
defaultBoostRewardToken[0] = TOKEN_PROFIT;
297315
defaultBoostRewardToken[1] = TOKEN_USDCe;
298316
IPlatform(platform).addBoostTokens(allowedBoostRewardToken, defaultBoostRewardToken);
299-
DeployLib.logSetupRewardTokens(platform, showLog);
317+
LogDeployLib.logSetupRewardTokens(platform, showLog);
300318
//endregion -- Reward tokens -----
301319

302320
//region ----- Deploy strategy logics -----
303-
DeployStrategyLib.deployStrategy(platform, StrategyIdLib.GAMMA_QUICKSWAP_MERKL_FARM, true);
304-
DeployStrategyLib.deployStrategy(platform, StrategyIdLib.QUICKSWAP_STATIC_MERKL_FARM, true);
305-
DeployStrategyLib.deployStrategy(platform, StrategyIdLib.COMPOUND_FARM, true);
306-
DeployStrategyLib.deployStrategy(platform, StrategyIdLib.DEFIEDGE_QUICKSWAP_MERKL_FARM, true);
307-
DeployStrategyLib.deployStrategy(platform, StrategyIdLib.ICHI_QUICKSWAP_MERKL_FARM, true);
308-
DeployStrategyLib.deployStrategy(platform, StrategyIdLib.ICHI_RETRO_MERKL_FARM, true);
309-
DeployStrategyLib.deployStrategy(platform, StrategyIdLib.GAMMA_RETRO_MERKL_FARM, true);
310-
DeployStrategyLib.deployStrategy(platform, StrategyIdLib.CURVE_CONVEX_FARM, true);
311-
DeployStrategyLib.deployStrategy(platform, StrategyIdLib.YEARN, false);
312-
DeployLib.logDeployStrategies(platform, showLog);
321+
_addStrategyLogic(factory, StrategyIdLib.GAMMA_QUICKSWAP_MERKL_FARM, address(new GammaQuickSwapMerklFarmStrategy()), true);
322+
_addStrategyLogic(factory, StrategyIdLib.QUICKSWAP_STATIC_MERKL_FARM, address(new QuickSwapStaticMerklFarmStrategy()), true);
323+
_addStrategyLogic(factory, StrategyIdLib.COMPOUND_FARM, address(new CompoundFarmStrategy()), true);
324+
_addStrategyLogic(factory, StrategyIdLib.DEFIEDGE_QUICKSWAP_MERKL_FARM, address(new DefiEdgeQuickSwapMerklFarmStrategy()), true);
325+
_addStrategyLogic(factory, StrategyIdLib.ICHI_QUICKSWAP_MERKL_FARM, address(new IchiQuickSwapMerklFarmStrategy()), true);
326+
_addStrategyLogic(factory, StrategyIdLib.ICHI_RETRO_MERKL_FARM, address(new IchiRetroMerklFarmStrategy()), true);
327+
_addStrategyLogic(factory, StrategyIdLib.GAMMA_RETRO_MERKL_FARM, address(new GammaRetroMerklFarmStrategy()), true);
328+
_addStrategyLogic(factory, StrategyIdLib.CURVE_CONVEX_FARM, address(new CurveConvexFarmStrategy()), true);
329+
_addStrategyLogic(factory, StrategyIdLib.YEARN, address(new YearnStrategy()), false);
330+
LogDeployLib.logDeployStrategies(platform, showLog);
313331
//endregion -- Deploy strategy logics -----
314332

315333
//region ----- Add DeX aggregators -----
@@ -619,5 +637,31 @@ library PolygonLib {
619637
return ISwapper.AddPoolData({pool: pool, ammAdapterId: ammAdapterId, tokenIn: tokenIn, tokenOut: tokenOut});
620638
}
621639

640+
function _addVaultType(IFactory factory, string memory id, address implementation, uint buildingPrice) internal {
641+
factory.setVaultConfig(
642+
IFactory.VaultConfig({
643+
vaultType: id,
644+
implementation: implementation,
645+
deployAllowed: true,
646+
upgradeAllowed: true,
647+
buildingPrice: buildingPrice
648+
})
649+
);
650+
}
651+
652+
function _addStrategyLogic(IFactory factory, string memory id, address implementation, bool farming) internal {
653+
factory.setStrategyLogicConfig(
654+
IFactory.StrategyLogicConfig({
655+
id: id,
656+
implementation: address(implementation),
657+
deployAllowed: true,
658+
upgradeAllowed: true,
659+
farming: farming,
660+
tokenId: type(uint).max
661+
}),
662+
StrategyDeveloperLib.getDeveloper(id)
663+
);
664+
}
665+
622666
function testPolygonLib() external {}
623667
}

script/Deploy.Base.s.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ pragma solidity ^0.8.23;
33

44
import "forge-std/Script.sol";
55
import "../chains/BaseLib.sol";
6+
import {DeployCore} from "./base/DeployCore.sol";
67

7-
contract DeployBase is Script {
8+
contract DeployBase is Script, DeployCore {
89
function run() external {
910
uint deployerPrivateKey = vm.envUint("PRIVATE_KEY");
1011
vm.startBroadcast(deployerPrivateKey);
11-
BaseLib.runDeploy(true);
12+
address platform = _deployCore(BaseLib.platformDeployParams());
13+
BaseLib.deployAndSetupInfrastructure(platform, false);
1214
vm.stopBroadcast();
1315
}
1416

script/Deploy.Polygon.s.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ pragma solidity ^0.8.23;
33

44
import "forge-std/Script.sol";
55
import "../chains/PolygonLib.sol";
6+
import {DeployCore} from "./base/DeployCore.sol";
67

7-
contract DeployPolygon is Script {
8+
contract DeployPolygon is Script, DeployCore {
89
function run() external {
910
uint deployerPrivateKey = vm.envUint("PRIVATE_KEY");
1011
vm.startBroadcast(deployerPrivateKey);
11-
PolygonLib.runDeploy(true);
12+
address platform = _deployCore(PolygonLib.platformDeployParams());
13+
PolygonLib.deployAndSetupInfrastructure(platform, false);
1214
vm.stopBroadcast();
1315
}
1416

0 commit comments

Comments
 (0)