Skip to content

Commit

Permalink
fix: flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Apr 23, 2024
1 parent da6e53f commit 56c77e0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 54 deletions.
51 changes: 10 additions & 41 deletions src/L1Deployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {Proxy} from "@zkevm-stb/Proxy.sol";
import {RoleManager} from "./RoleManager.sol";
import {DeployerBase} from "./DeployerBase.sol";
import {L1YearnEscrow} from "./L1YearnEscrow.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IPolygonRollupManager, IPolygonRollupContract} from "./interfaces/Polygon/IPolygonRollupManager.sol";

Expand Down Expand Up @@ -133,10 +132,10 @@ contract L1Deployer is DeployerBase, RoleManager {
ESCROW CREATION
//////////////////////////////////////////////////////////////*/

function newAsset(
function newEscrow(
uint32 _rollupID,
address _asset
) external virtual returns (address _vault, address _l1Escrow) {
) external virtual returns (address _l1Escrow, address _vault) {
// Verify the rollup Id is valid.
require(
address(chainConfig[_rollupID].rollupContract) != address(0),
Expand All @@ -152,32 +151,31 @@ contract L1Deployer is DeployerBase, RoleManager {

// If not, deploy one and do full setup
if (_vault == address(0)) {
_vault = _deployNewVault(DEFAULT_ID, _asset);
_vault = _newVault(DEFAULT_ID, _asset);
}

// Deploy L1 Escrow.
_l1Escrow = _deployL1Escrow(_rollupID, _asset, _vault);
}

function newCustomAsset(
function newCustomVault(
uint32 _rollupID,
address _asset
) external virtual onlyRollupAdmin(_rollupID) returns (address _vault) {
_vault = _deployNewVault(_rollupID, _asset);
// Custom Roles???
_newCustomAsset(_rollupID, _asset, _vault);
_vault = _newVault(_rollupID, _asset);
_newCustomVault(_rollupID, _asset, _vault);
}

function newCustomAsset(
function newCustomVault(
uint32 _rollupID,
address _asset,
address _vault
) external virtual onlyRollupAdmin(_rollupID) {
_addNewVault(_rollupID, _vault);
_newCustomAsset(_rollupID, _asset, _vault);
_newCustomVault(_rollupID, _asset, _vault);
}

function _newCustomAsset(
function _newCustomVault(
uint32 _rollupID,
address _asset,
address _vault
Expand All @@ -192,38 +190,9 @@ contract L1Deployer is DeployerBase, RoleManager {
}

/*//////////////////////////////////////////////////////////////
VAULT CREATION
ESCROW CREATION
//////////////////////////////////////////////////////////////*/

function _deployNewVault(
uint32 _rollupID,
address _asset
) internal virtual returns (address) {
// Append the rollup ID for the name and symbol of custom vaults.
string memory _id = _rollupID == DEFAULT_ID
? ""
: Strings.toString(_rollupID);

// Name is "{SYMBOL}-STB yVault"
string memory _name = string(
abi.encodePacked(ERC20(_asset).symbol(), "-STB", _id, " yVault")
);
// Symbol is "stb{SYMBOL}".
string memory _symbol = string(
abi.encodePacked("stb", ERC20(_asset).symbol(), _id)
);

return
_newVault(
_asset,
_name,
_symbol,
_rollupID,
2 ** 256 - 1,
defaultProfitMaxUnlock
);
}

function _deployL1Escrow(
uint32 _rollupID,
address _asset,
Expand Down
30 changes: 19 additions & 11 deletions src/RoleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Roles} from "@yearn-vaults/interfaces/Roles.sol";
import {IVault} from "@yearn-vaults/interfaces/IVault.sol";
import {IAccountant} from "./interfaces/Yearn/IAccountant.sol";
import {Registry} from "@vault-periphery/registry/Registry.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {DebtAllocatorFactory} from "@vault-periphery/debtAllocators/DebtAllocatorFactory.sol";

Expand Down Expand Up @@ -178,26 +179,34 @@ contract RoleManager {

/**
* @notice Creates a new endorsed vault.
* @param _rollupID Id of the rollup to deploy for.
* @param _asset Address of the underlying asset.
* @param _depositLimit The deposit limit to start the vault with.
* @param _profitMaxUnlockTime Time until profits are fully unlocked.
* @return _vault Address of the newly created vault.
*/
function _newVault(
address _asset,
string memory _name,
string memory _symbol,
uint32 _rollupID,
uint256 _depositLimit,
uint256 _profitMaxUnlockTime
address _asset
) internal virtual returns (address _vault) {
// Append the rollup ID for the name and symbol of custom vaults.
string memory _id = _rollupID == DEFAULT_ID
? ""
: string(abi.encodePacked("-", Strings.toString(_rollupID)));
// Name is "{SYMBOL}-STB yVault"
string memory _name = string(
abi.encodePacked(ERC20(_asset).symbol(), "-STB", _id, " yVault")
);
// Symbol is "stb{SYMBOL}".
string memory _symbol = string(
abi.encodePacked("stb", ERC20(_asset).symbol(), _id)
);

// Deploy through the registry so it is automatically endorsed.
_vault = Registry(getPositionHolder(REGISTRY)).newEndorsedVault(
_asset,
_name,
_symbol,
address(this),
_profitMaxUnlockTime
defaultProfitMaxUnlock
);

// Deploy a new debt allocator for the vault.
Expand All @@ -209,9 +218,8 @@ contract RoleManager {
// Set up the accountant.
_setAccountant(_vault);

if (_depositLimit != 0) {
_setDepositLimit(_vault, _depositLimit);
}
// Set deposit limit to max uint.
_setDepositLimit(_vault, 2 ** 256 - 1);

// Add the vault config to the mapping.
vaultConfig[_vault] = VaultConfig({
Expand Down
5 changes: 3 additions & 2 deletions test/Setup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity >=0.8.18;

import {Setup, console, Roles} from "./utils/Setup.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

contract SetupTest is Setup {
uint256 public managementRoles =
Expand Down Expand Up @@ -84,7 +85,7 @@ contract SetupTest is Setup {
vm.prank(admin);
l1Deployer.registerRollup(rollupID, manager);

l1Deployer.newAsset(rollupID, address(asset));
l1Deployer.newEscrow(rollupID, address(asset));
}

function test_newToken() public {
Expand All @@ -96,7 +97,7 @@ contract SetupTest is Setup {
l1Deployer.registerRollup(rollupID, manager);

address _l1Escrow;
(, _l1Escrow) = l1Deployer.newAsset(rollupID, address(asset));
(_l1Escrow, ) = l1Deployer.newEscrow(rollupID, address(asset));
bytes memory data = abi.encode(
address(asset),
_l1Escrow,
Expand Down

0 comments on commit 56c77e0

Please sign in to comment.