Skip to content

Commit

Permalink
Merge pull request #139 from stabilitydao/136-factory-asset-symbol-al…
Browse files Browse the repository at this point in the history
…iases

feat: set, get function for aliasname
  • Loading branch information
hcrypto7 authored Jun 23, 2024
2 parents 338c4ab + 8714018 commit 0759557
Show file tree
Hide file tree
Showing 53 changed files with 1,903 additions and 1,956 deletions.
14 changes: 10 additions & 4 deletions chains/BaseLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ library BaseLib {

//region ----- Deploy strategy logics -----
_addStrategyLogic(factory, StrategyIdLib.COMPOUND_FARM, address(new CompoundFarmStrategy()), true);
_addStrategyLogic(factory, StrategyIdLib.GAMMA_UNISWAPV3_MERKL_FARM, address(new GammaUniswapV3MerklFarmStrategy()), true);
_addStrategyLogic(
factory, StrategyIdLib.GAMMA_UNISWAPV3_MERKL_FARM, address(new GammaUniswapV3MerklFarmStrategy()), true
);
LogDeployLib.logDeployStrategies(platform, showLog);
//endregion -- Deploy strategy logics -----

Expand Down Expand Up @@ -222,9 +224,13 @@ library BaseLib {
_farms[i++] = _makeCompoundFarm(COMPOUND_COMET_ETH);

// [3]-[5]
_farms[i++] = _makeGammaUniswapV3MerklFarm(GAMMA_UNISWAPV3_cbETH_WETH_500_PEGGED, ALMPositionNameLib.PEGGED, TOKEN_UNI);
_farms[i++] = _makeGammaUniswapV3MerklFarm(GAMMA_UNISWAPV3_WETH_wstETH_100_PEGGED, ALMPositionNameLib.PEGGED, TOKEN_wstETH);
_farms[i++] = _makeGammaUniswapV3MerklFarm(GAMMA_UNISWAPV3_USDC_USDT_100_STABLE, ALMPositionNameLib.STABLE, TOKEN_UNI);
_farms[i++] =
_makeGammaUniswapV3MerklFarm(GAMMA_UNISWAPV3_cbETH_WETH_500_PEGGED, ALMPositionNameLib.PEGGED, TOKEN_UNI);
_farms[i++] = _makeGammaUniswapV3MerklFarm(
GAMMA_UNISWAPV3_WETH_wstETH_100_PEGGED, ALMPositionNameLib.PEGGED, TOKEN_wstETH
);
_farms[i++] =
_makeGammaUniswapV3MerklFarm(GAMMA_UNISWAPV3_USDC_USDT_100_STABLE, ALMPositionNameLib.STABLE, TOKEN_UNI);
}

function _makeGammaUniswapV3MerklFarm(
Expand Down
32 changes: 27 additions & 5 deletions chains/PolygonLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,26 @@ library PolygonLib {
//endregion -- Reward tokens -----

//region ----- Deploy strategy logics -----
_addStrategyLogic(factory, StrategyIdLib.GAMMA_QUICKSWAP_MERKL_FARM, address(new GammaQuickSwapMerklFarmStrategy()), true);
_addStrategyLogic(factory, StrategyIdLib.QUICKSWAP_STATIC_MERKL_FARM, address(new QuickSwapStaticMerklFarmStrategy()), true);
_addStrategyLogic(
factory, StrategyIdLib.GAMMA_QUICKSWAP_MERKL_FARM, address(new GammaQuickSwapMerklFarmStrategy()), true
);
_addStrategyLogic(
factory, StrategyIdLib.QUICKSWAP_STATIC_MERKL_FARM, address(new QuickSwapStaticMerklFarmStrategy()), true
);
_addStrategyLogic(factory, StrategyIdLib.COMPOUND_FARM, address(new CompoundFarmStrategy()), true);
_addStrategyLogic(factory, StrategyIdLib.DEFIEDGE_QUICKSWAP_MERKL_FARM, address(new DefiEdgeQuickSwapMerklFarmStrategy()), true);
_addStrategyLogic(factory, StrategyIdLib.ICHI_QUICKSWAP_MERKL_FARM, address(new IchiQuickSwapMerklFarmStrategy()), true);
_addStrategyLogic(
factory,
StrategyIdLib.DEFIEDGE_QUICKSWAP_MERKL_FARM,
address(new DefiEdgeQuickSwapMerklFarmStrategy()),
true
);
_addStrategyLogic(
factory, StrategyIdLib.ICHI_QUICKSWAP_MERKL_FARM, address(new IchiQuickSwapMerklFarmStrategy()), true
);
_addStrategyLogic(factory, StrategyIdLib.ICHI_RETRO_MERKL_FARM, address(new IchiRetroMerklFarmStrategy()), true);
_addStrategyLogic(factory, StrategyIdLib.GAMMA_RETRO_MERKL_FARM, address(new GammaRetroMerklFarmStrategy()), true);
_addStrategyLogic(
factory, StrategyIdLib.GAMMA_RETRO_MERKL_FARM, address(new GammaRetroMerklFarmStrategy()), true
);
_addStrategyLogic(factory, StrategyIdLib.CURVE_CONVEX_FARM, address(new CurveConvexFarmStrategy()), true);
_addStrategyLogic(factory, StrategyIdLib.YEARN, address(new YearnStrategy()), false);
LogDeployLib.logDeployStrategies(platform, showLog);
Expand All @@ -335,6 +348,15 @@ library PolygonLib {
dexAggRouter[0] = ONE_INCH;
IPlatform(platform).addDexAggregators(dexAggRouter);
//endregion -- Add DeX aggregators -----

//region ----- Set AliasName of Token -----
factory.setAliasName(TOKEN_WETH, "E");
factory.setAliasName(TOKEN_WMATIC, "M");
factory.setAliasName(TOKEN_WBTC, "B");
factory.setAliasName(TOKEN_USDT, "UT");
factory.setAliasName(TOKEN_USDC, "UC");
factory.setAliasName(TOKEN_USDCe, "UCe");
//endregion ----- Set AliasName of Token -----
}

function routes()
Expand Down
23 changes: 23 additions & 0 deletions script/PrepareUpgrade.24.06.1-alpha.Polygon.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "forge-std/Script.sol";
import "../src/core/Factory.sol";
import "../src/core/vaults/CVault.sol";
import "../src/core/vaults/RVault.sol";
import "../src/core/vaults/RMVault.sol";
import "../src/strategies/YearnStrategy.sol";

contract PrepareUpgrade5Polygon is Script {
function run() external {
uint deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

// Factory 1.1.1: reduced factory size. moved upgradeStrategyProxy, upgradeVaultProxy logic to FactoryLib
new Factory();

vm.stopBroadcast();
}

function testDeployPolygon() external {}
}
48 changes: 20 additions & 28 deletions src/core/Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "./base/Controllable.sol";
import "./libs/CommonLib.sol";
import "./libs/VaultTypeLib.sol";
import "./libs/FactoryLib.sol";
import "./libs/FactoryNamingLib.sol";
import "./libs/DeployerLib.sol";
import "./libs/VaultStatusLib.sol";
import "../interfaces/IFactory.sol";
Expand All @@ -23,17 +24,19 @@ import "../interfaces/IStrategyLogic.sol";
/// Provides the opportunity to upgrade vaults and strategies.
/// Changelog:
/// 1.1.0: getDeploymentKey fix for not farming strategies, strategyAvailableInitParams
/// 1.1.1: reduced factory size. moved upgradeStrategyProxy, upgradeVaultProxy logic to FactoryLib
/// @author Alien Deployer (https://github.com/a17)
/// @author Jude (https://github.com/iammrjude)
/// @author JodsMigel (https://github.com/JodsMigel)
/// @author HCrypto7 (https://github.com/hcrypto7)
contract Factory is Controllable, ReentrancyGuardUpgradeable, IFactory {
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.Bytes32Set;

//region ----- Constants -----

/// @inheritdoc IControllable
string public constant VERSION = "1.1.0";
string public constant VERSION = "1.2.0";

uint internal constant _WEEK = 60 * 60 * 24 * 7;

Expand Down Expand Up @@ -297,19 +300,7 @@ contract Factory is Controllable, ReentrancyGuardUpgradeable, IFactory {
if ($.vaultStatus[vault] != VaultStatusLib.ACTIVE) {
revert NotActiveVault();
}
IVaultProxy proxy = IVaultProxy(vault);
bytes32 vaultTypeHash = proxy.vaultTypeHash();
address oldImplementation = proxy.implementation();
VaultConfig memory tempVaultConfig = $.vaultConfig[vaultTypeHash];
address newImplementation = tempVaultConfig.implementation;
if (!tempVaultConfig.upgradeAllowed) {
revert UpgradeDenied(vaultTypeHash);
}
if (oldImplementation == newImplementation) {
revert AlreadyLastVersion(vaultTypeHash);
}
proxy.upgrade();
emit VaultProxyUpgraded(vault, oldImplementation, newImplementation);
FactoryLib.upgradeVaultProxy($, vault);
}

/// @inheritdoc IFactory
Expand All @@ -318,19 +309,14 @@ contract Factory is Controllable, ReentrancyGuardUpgradeable, IFactory {
if (!$.isStrategy[strategyProxy]) {
revert NotStrategy();
}
IStrategyProxy proxy = IStrategyProxy(strategyProxy);
bytes32 idHash = proxy.strategyImplementationLogicIdHash();
StrategyLogicConfig storage config = $.strategyLogicConfig[idHash];
address oldImplementation = proxy.implementation();
address newImplementation = config.implementation;
if (!config.upgradeAllowed) {
revert UpgradeDenied(idHash);
}
if (oldImplementation == newImplementation) {
revert AlreadyLastVersion(idHash);
}
proxy.upgrade();
emit StrategyProxyUpgraded(strategyProxy, oldImplementation, newImplementation);
FactoryLib.upgradeStrategyProxy($, strategyProxy);
}

/// @inheritdoc IFactory
function setAliasName(address tokenAddress_, string memory aliasName_) external {
FactoryStorage storage $ = _getStorage();
$.aliasNames[tokenAddress_] = aliasName_;
emit IFactory.AliasNameChanged(msg.sender, tokenAddress_, $.aliasNames[tokenAddress_]);
}

//endregion -- User actions ----
Expand Down Expand Up @@ -490,7 +476,7 @@ contract Factory is Controllable, ReentrancyGuardUpgradeable, IFactory {
)
{
//slither-disable-next-line unused-return
return FactoryLib.getStrategyData(vaultType, strategyAddress, bbAsset);
return FactoryNamingLib.getStrategyData(vaultType, strategyAddress, bbAsset, platform());
}

/// @inheritdoc IFactory
Expand Down Expand Up @@ -582,6 +568,12 @@ contract Factory is Controllable, ReentrancyGuardUpgradeable, IFactory {
return $.strategyAvailableInitParams[idHash];
}

/// @inheritdoc IFactory
function getAliasName(address tokenAddress_) public view returns (string memory) {
FactoryStorage storage $ = _getStorage();
return $.aliasNames[tokenAddress_];
}

//endregion -- View functions -----

//region ----- Internal logic -----
Expand Down
99 changes: 37 additions & 62 deletions src/core/libs/FactoryLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import "../../interfaces/IFactory.sol";
import "../../interfaces/IPriceReader.sol";
import "../../interfaces/IVault.sol";
import "../../interfaces/IRVault.sol";
import "../../interfaces/IVaultProxy.sol";
import "../../interfaces/IStrategyProxy.sol";

library FactoryLib {
using SafeERC20 for IERC20;
Expand Down Expand Up @@ -442,36 +444,6 @@ library FactoryLib {
if (exchangeAssetIndex > type(uint).max) revert ISwapper.NoRoutesForAssets();
}

function _getSymbol(
string memory vaultType,
string memory strategyLogicId,
string memory symbols,
string memory specificName,
string memory bbAssetSymbol
) internal pure returns (string memory) {
bytes memory vaultTypeBytes = bytes(vaultType);
string memory prefix = "v";
if (vaultTypeBytes[0] == "C") {
prefix = "C";
}
if (CommonLib.eq(vaultType, VaultTypeLib.REWARDING)) {
prefix = "R";
}
if (CommonLib.eq(vaultType, VaultTypeLib.REWARDING_MANAGED)) {
prefix = "RM";
}
string memory bbAssetStr = bytes(bbAssetSymbol).length > 0 ? string.concat("-", bbAssetSymbol) : "";
return string.concat(
prefix,
"-",
symbols,
bbAssetStr,
"-",
CommonLib.shortId(strategyLogicId),
bytes(specificName).length > 0 ? CommonLib.shortId(specificName) : ""
);
}

function getName(
string memory vaultType,
string memory id,
Expand All @@ -488,36 +460,6 @@ library FactoryLib {
}
}

function getStrategyData(
string memory vaultType,
address strategyAddress,
address bbAsset
)
public
view
returns (
string memory strategyId,
address[] memory assets,
string[] memory assetsSymbols,
string memory specificName,
string memory vaultSymbol
)
{
strategyId = IStrategy(strategyAddress).strategyLogicId();
assets = IStrategy(strategyAddress).assets();
assetsSymbols = CommonLib.getSymbols(assets);
bool showSpecificInSymbol;
(specificName, showSpecificInSymbol) = IStrategy(strategyAddress).getSpecificName();
string memory bbAssetSymbol = bbAsset == address(0) ? "" : IERC20Metadata(bbAsset).symbol();
vaultSymbol = _getSymbol(
vaultType,
strategyId,
CommonLib.implode(assetsSymbols, ""),
showSpecificInSymbol ? specificName : "",
bbAssetSymbol
);
}

function getDeploymentKey(
string memory vaultType,
string memory strategyId,
Expand Down Expand Up @@ -622,8 +564,9 @@ library FactoryLib {
vars.isRewardingVaultType ? vaultInitNums[i] : vaultInitNums[1 + boostTokensLen + i];
//slither-disable-next-line unused-return
(uint price,) = priceReader.getPrice(token);
totalInitialBoostUsdPerDay += initialNotifyAmount * 1e18 / 10 ** IERC20Metadata(token).decimals()
* price / 1e18 * 86400 / durationSeconds;
totalInitialBoostUsdPerDay += (
((((initialNotifyAmount * 1e18) / 10 ** IERC20Metadata(token).decimals()) * price) / 1e18) * 86400
) / durationSeconds;
if (initialNotifyAmount > 0) {
IERC20(token).safeTransferFrom(msg.sender, address(this), initialNotifyAmount);
IERC20(token).forceApprove(vault, initialNotifyAmount);
Expand Down Expand Up @@ -654,4 +597,36 @@ library FactoryLib {
type_, vaultConfig_.implementation, vaultConfig_.deployAllowed, vaultConfig_.upgradeAllowed, newVaultType
);
}

function upgradeVaultProxy(IFactory.FactoryStorage storage $, address vault) external {
IVaultProxy proxy = IVaultProxy(vault);
bytes32 vaultTypeHash = proxy.vaultTypeHash();
address oldImplementation = proxy.implementation();
IFactory.VaultConfig memory tempVaultConfig = $.vaultConfig[vaultTypeHash];
address newImplementation = tempVaultConfig.implementation;
if (!tempVaultConfig.upgradeAllowed) {
revert IFactory.UpgradeDenied(vaultTypeHash);
}
if (oldImplementation == newImplementation) {
revert IFactory.AlreadyLastVersion(vaultTypeHash);
}
proxy.upgrade();
emit IFactory.VaultProxyUpgraded(vault, oldImplementation, newImplementation);
}

function upgradeStrategyProxy(IFactory.FactoryStorage storage $, address strategyProxy) external {
IStrategyProxy proxy = IStrategyProxy(strategyProxy);
bytes32 idHash = proxy.strategyImplementationLogicIdHash();
IFactory.StrategyLogicConfig storage config = $.strategyLogicConfig[idHash];
address oldImplementation = proxy.implementation();
address newImplementation = config.implementation;
if (!config.upgradeAllowed) {
revert IFactory.UpgradeDenied(idHash);
}
if (oldImplementation == newImplementation) {
revert IFactory.AlreadyLastVersion(idHash);
}
proxy.upgrade();
emit IFactory.StrategyProxyUpgraded(strategyProxy, oldImplementation, newImplementation);
}
}
Loading

0 comments on commit 0759557

Please sign in to comment.