From cd1b9ec24da45477074c1514e182edb216dbbe05 Mon Sep 17 00:00:00 2001 From: Schlagonia Date: Mon, 22 Apr 2024 11:03:05 -0600 Subject: [PATCH 1/4] test: l1 escrow --- package.json | 4 +- src/L1YearnEscrow.sol | 33 +- .../Polygon/IPolygonZkEVMBridge.sol | 2 + test/L1Escrow.t.sol | 325 ++++++++++++++++++ test/{setup.t.sol => Setup.t.sol} | 44 ++- test/mocks/MockBridge.sol | 18 +- test/mocks/MockStrategy.sol | 6 +- test/mocks/MockTokenizedStrategy.sol | 11 +- test/utils/Setup.sol | 184 ++++++---- 9 files changed, 527 insertions(+), 100 deletions(-) create mode 100644 test/L1Escrow.t.sol rename test/{setup.t.sol => Setup.t.sol} (79%) diff --git a/package.json b/package.json index 5ea7501..14c59c2 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "solhint-plugin-prettier": "^0.0.5" }, "scripts": { - "format": "prettier --write 'src/**/*.(sol|json)'", - "format:check": "prettier --check 'src/**/*.*(sol|json)'", + "format": "prettier --write 'src/**/*.(sol|json)' 'test/**/*.(sol|json)'", + "format:check": "prettier --check 'src/**/*.*(sol|json)' 'test/**/*.(sol|json)'", "lint": "solhint 'src/**/*.sol'", "lint:fix": "solhint --fix 'src/**/*.sol'" } diff --git a/src/L1YearnEscrow.sol b/src/L1YearnEscrow.sol index 1fa28a3..f370b09 100644 --- a/src/L1YearnEscrow.sol +++ b/src/L1YearnEscrow.sol @@ -1,11 +1,17 @@ // SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.20; -import {L1Escrow} from "@zkevm-stb/L1Escrow.sol"; +import {L1Escrow, SafeERC20, IERC20} from "@zkevm-stb/L1Escrow.sol"; import {IVault} from "@yearn-vaults/interfaces/IVault.sol"; // ADD buffer contract L1YearnEscrow is L1Escrow { + // **************************** + // * Libraries * + // **************************** + + using SafeERC20 for IERC20; + // **************************** // * Events * // ************************** @@ -87,7 +93,9 @@ contract L1YearnEscrow is L1Escrow { ); VaultStorage storage $ = _getVaultStorage(); - // Set the vault variables + // Max approve the vault + originTokenAddress().forceApprove(_vaultAddress, 2 ** 256 - 1); + // Set the vault variable $.vaultAddress = IVault(_vaultAddress); } @@ -131,8 +139,7 @@ contract L1YearnEscrow is L1Escrow { address destinationAddress, uint256 amount ) internal virtual override whenNotPaused { - // Withdraw from vault to receiver. - VaultStorage storage $ = _getVaultStorage(); + // Check if there is enough loose balance. uint256 underlyingBalance = originTokenAddress().balanceOf( address(this) ); @@ -148,6 +155,8 @@ contract L1YearnEscrow is L1Escrow { } } + // Withdraw from vault to receiver. + VaultStorage storage $ = _getVaultStorage(); $.vaultAddress.withdraw(amount, destinationAddress, address(this)); } @@ -186,12 +195,28 @@ contract L1YearnEscrow is L1Escrow { IVault oldVault = $.vaultAddress; // If re-initializing to a new vault address. if (address(oldVault) != address(0)) { + // Lower allowance to 0 + originTokenAddress().forceApprove(address(oldVault), 0); + uint256 balance = oldVault.balanceOf(address(this)); // Withdraw the full balance of the current vault. if (balance != 0) { oldVault.redeem(balance, address(this), address(this)); } } + + // Migrate to new vault if applicable + if (_vaultAddress != address(0)) { + // Max approve the new vault + originTokenAddress().forceApprove(_vaultAddress, 2 ** 256 - 1); + + // Deposit any loose funds + uint256 balance = originTokenAddress().balanceOf(address(this)); + if (balance != 0) + IVault(_vaultAddress).deposit(balance, address(this)); + } + + // Update Storage $.vaultAddress = IVault(_vaultAddress); emit UpdateVaultAddress(_vaultAddress); diff --git a/src/interfaces/Polygon/IPolygonZkEVMBridge.sol b/src/interfaces/Polygon/IPolygonZkEVMBridge.sol index 2b001a1..6728863 100644 --- a/src/interfaces/Polygon/IPolygonZkEVMBridge.sol +++ b/src/interfaces/Polygon/IPolygonZkEVMBridge.sol @@ -118,4 +118,6 @@ interface IPolygonZkEVMBridge { function networkID() external returns (uint32); function polygonRollupManager() external view returns (address); + + function depositCount() external view returns (uint256); } diff --git a/test/L1Escrow.t.sol b/test/L1Escrow.t.sol new file mode 100644 index 0000000..b9a503e --- /dev/null +++ b/test/L1Escrow.t.sol @@ -0,0 +1,325 @@ +// SPDX-License-Identifier: AGPL-3.0 +pragma solidity >=0.8.18; + +import {Setup, console, L1YearnEscrow, IVault} from "./utils/Setup.sol"; + +contract EscrowTest is Setup { + address public l2TokenAddress; + + L1YearnEscrow public mockEscrow; + + function setUp() public virtual override { + super.setUp(); + l2TokenAddress = getL2TokenAddress(address(asset)); + vault = deployMockVault(); + } + + function test_implementationSetup() public { + // No level should be initialized + assertEq(l1EscrowImpl.owner(), address(0)); + assertEq(l2EscrowImpl.polygonZkEVMBridge(), address(0)); + assertEq(address(l1EscrowImpl.originTokenAddress()), address(0)); + assertEq(address(l1EscrowImpl.vaultAddress()), address(0)); + + // Cannot be re-initialized + vm.expectRevert(); + l1EscrowImpl.initialize( + governator, + czar, + address(polygonZkEVMBridge), + address(l2EscrowImpl), + l2RollupID, + address(asset), + l2TokenAddress, + address(vault) + ); + + assertEq(l1EscrowImpl.owner(), address(0)); + assertEq(l2EscrowImpl.polygonZkEVMBridge(), address(0)); + assertEq(address(l1EscrowImpl.originTokenAddress()), address(0)); + assertEq(address(l1EscrowImpl.vaultAddress()), address(0)); + } + + function test_newEscrow() public { + bytes memory data = abi.encodeCall( + L1YearnEscrow.initialize, + ( + governator, + czar, + address(polygonZkEVMBridge), + address(l2EscrowImpl), + l2RollupID, + address(asset), + l2TokenAddress, + address(vault) + ) + ); + + mockEscrow = L1YearnEscrow( + _create3Deploy( + keccak256(abi.encodePacked(bytes("L1Escrow:"), address(asset))), + address(l1EscrowImpl), + data + ) + ); + + assertEq(mockEscrow.owner(), governator); + assertTrue(mockEscrow.hasRole(mockEscrow.ESCROW_MANAGER_ROLE(), czar)); + assertEq(mockEscrow.polygonZkEVMBridge(), address(polygonZkEVMBridge)); + assertEq(mockEscrow.counterpartContract(), address(l2EscrowImpl)); + assertEq(mockEscrow.counterpartNetwork(), l2RollupID); + assertEq(address(mockEscrow.originTokenAddress()), address(asset)); + assertEq(address(mockEscrow.wrappedTokenAddress()), l2TokenAddress); + assertEq(address(mockEscrow.vaultAddress()), address(vault)); + assertEq(mockEscrow.minimumBuffer(), 0); + assertEq( + asset.allowance(address(mockEscrow), address(vault)), + 2 ** 256 - 1 + ); + } + + function test_bridgeAsset(uint256 _amount) public { + _amount = bound(_amount, minFuzzAmount, maxFuzzAmount); + + mockEscrow = deployMockL1Escrow(); + + // Simulate a bridge txn + airdrop(asset, user, _amount); + + vm.prank(user); + asset.approve(address(mockEscrow), _amount); + + bytes memory data = abi.encode(user, _amount); + uint256 depositCount = polygonZkEVMBridge.depositCount(); + vm.expectEmit(true, true, true, true, address(polygonZkEVMBridge)); + emit BridgeEvent( + 1, + l1RollupID, + address(mockEscrow), + l2RollupID, + address(l2EscrowImpl), + 0, + data, + uint32(depositCount) + ); + vm.prank(user); + mockEscrow.bridgeToken(user, _amount, true); + + assertEq(vault.totalAssets(), _amount); + assertEq(asset.balanceOf(user), 0); + assertEq(asset.balanceOf(address(mockEscrow)), 0); + assertEq(vault.balanceOf(address(mockEscrow)), _amount); + + // Withdraw half + uint256 toWithdraw = _amount / 2; + + data = abi.encode(user, toWithdraw); + + vm.expectRevert( + "TokenWrapped::PolygonBridgeBase: Not PolygonZkEVMBridge" + ); + mockEscrow.onMessageReceived(address(l2EscrowImpl), l2RollupID, data); + + vm.expectRevert( + "TokenWrapped::PolygonBridgeBase: Not counterpart contract" + ); + vm.prank(address(polygonZkEVMBridge)); + mockEscrow.onMessageReceived(address(l1EscrowImpl), l2RollupID, data); + + vm.expectRevert( + "TokenWrapped::PolygonBridgeBase: Not counterpart network" + ); + vm.prank(address(polygonZkEVMBridge)); + mockEscrow.onMessageReceived(address(l2EscrowImpl), l1RollupID, data); + + vm.prank(address(polygonZkEVMBridge)); + mockEscrow.onMessageReceived(address(l2EscrowImpl), l2RollupID, data); + + assertEq(vault.totalAssets(), _amount - toWithdraw); + assertEq(asset.balanceOf(user), toWithdraw); + assertEq(asset.balanceOf(address(mockEscrow)), 0); + assertEq(vault.balanceOf(address(mockEscrow)), _amount - toWithdraw); + + data = abi.encode(user, _amount - toWithdraw); + + vm.prank(address(polygonZkEVMBridge)); + mockEscrow.onMessageReceived(address(l2EscrowImpl), l2RollupID, data); + + assertEq(vault.totalAssets(), 0); + assertEq(asset.balanceOf(user), _amount); + assertEq(asset.balanceOf(address(mockEscrow)), 0); + assertEq(vault.balanceOf(address(mockEscrow)), 0); + } + + function test_bridgeAsset_minimumBuffer( + uint256 _amount, + uint256 _minimumBuffer + ) public { + _amount = bound(_amount, minFuzzAmount, maxFuzzAmount); + _minimumBuffer = bound(_minimumBuffer, 10, maxFuzzAmount); + + mockEscrow = deployMockL1Escrow(); + + vm.expectRevert(); + mockEscrow.updateMinimumBuffer(_minimumBuffer); + + vm.prank(governator); + mockEscrow.updateMinimumBuffer(_minimumBuffer); + + // expected amount the escrow will deposit to the vault + uint256 toDeposit = _minimumBuffer >= _amount + ? 0 + : _amount - _minimumBuffer; + + // Simulate a bridge txn + mintAndBridge(mockEscrow, user, _amount); + + assertEq(vault.totalAssets(), toDeposit); + assertEq(asset.balanceOf(user), 0); + assertEq(asset.balanceOf(address(mockEscrow)), _amount - toDeposit); + assertEq(vault.balanceOf(address(mockEscrow)), toDeposit); + + // Withdraw everything + bytes memory data = abi.encode(user, _amount); + vm.prank(address(polygonZkEVMBridge)); + mockEscrow.onMessageReceived(address(l2EscrowImpl), l2RollupID, data); + + assertEq(vault.totalAssets(), 0); + assertEq(asset.balanceOf(user), _amount); + assertEq(asset.balanceOf(address(mockEscrow)), 0); + assertEq(vault.balanceOf(address(mockEscrow)), 0); + } + + function test_bridgeAsset_updateVault(uint256 _amount) public { + _amount = bound(_amount, minFuzzAmount, maxFuzzAmount); + + mockEscrow = deployMockL1Escrow(); + + // Simulate a bridge txn + mintAndBridge(mockEscrow, user, _amount); + + assertEq(vault.totalAssets(), _amount); + assertEq(asset.balanceOf(user), 0); + assertEq(asset.balanceOf(address(mockEscrow)), 0); + assertEq(vault.balanceOf(address(mockEscrow)), _amount); + + IVault newVault = deployMockVault(); + + // Migrate funds to the new vault. + vm.expectRevert(); + mockEscrow.updateVault(address(newVault)); + + vm.prank(governator); + mockEscrow.updateVault(address(newVault)); + + assertEq(vault.totalAssets(), 0); + assertEq(vault.balanceOf(address(mockEscrow)), 0); + assertEq(asset.allowance(address(mockEscrow), address(vault)), 0); + assertEq(asset.balanceOf(address(mockEscrow)), 0); + assertEq(newVault.totalAssets(), _amount); + assertEq(newVault.balanceOf(address(mockEscrow)), _amount); + assertEq( + asset.allowance(address(mockEscrow), address(newVault)), + 2 ** 256 - 1 + ); + + // Bridge again to cause deposit + mintAndBridge(mockEscrow, user, _amount); + + assertEq(vault.totalAssets(), 0); + assertEq(newVault.totalAssets(), _amount * 2); + assertEq(asset.balanceOf(user), 0); + assertEq(asset.balanceOf(address(mockEscrow)), 0); + assertEq(vault.balanceOf(address(mockEscrow)), 0); + assertEq(newVault.balanceOf(address(mockEscrow)), _amount * 2); + + // Withdraw everything + bytes memory data = abi.encode(user, _amount * 2); + vm.prank(address(polygonZkEVMBridge)); + mockEscrow.onMessageReceived(address(l2EscrowImpl), l2RollupID, data); + + assertEq(newVault.totalAssets(), 0); + assertEq(asset.balanceOf(user), _amount * 2); + assertEq(asset.balanceOf(address(mockEscrow)), 0); + assertEq(newVault.balanceOf(address(mockEscrow)), 0); + } + + function test_managerWithdraw(uint256 _amount) public { + _amount = bound(_amount, minFuzzAmount, maxFuzzAmount); + + mockEscrow = deployMockL1Escrow(); + + // Simulate a bridge txn + mintAndBridge(mockEscrow, user, _amount); + + assertEq(vault.totalAssets(), _amount); + assertEq(asset.balanceOf(user), 0); + assertEq(asset.balanceOf(address(mockEscrow)), 0); + assertEq(vault.balanceOf(address(mockEscrow)), _amount); + + // Migrate funds to the new vault. + vm.expectRevert(); + mockEscrow.withdraw(czar, _amount); + + vm.expectRevert(); + vm.prank(czar); + mockEscrow.withdraw(czar, _amount + 1); + + vm.prank(czar); + mockEscrow.withdraw(czar, _amount); + + assertEq(vault.totalAssets(), _amount); + assertEq(vault.balanceOf(address(mockEscrow)), 0); + assertEq(vault.balanceOf(czar), _amount); + assertEq(asset.balanceOf(address(mockEscrow)), 0); + + // Withdraw and donate underlying. should still be able to withdraw + vm.prank(czar); + vault.redeem(_amount, address(mockEscrow), czar); + + // Withdraw everything + bytes memory data = abi.encode(user, _amount); + vm.prank(address(polygonZkEVMBridge)); + mockEscrow.onMessageReceived(address(l2EscrowImpl), l2RollupID, data); + + assertEq(vault.totalAssets(), 0); + assertEq(asset.balanceOf(user), _amount); + assertEq(asset.balanceOf(address(mockEscrow)), 0); + assertEq(vault.balanceOf(address(mockEscrow)), 0); + } + + event BridgeEvent( + uint8 leafType, + uint32 originNetwork, + address originAddress, + uint32 destinationNetwork, + address destinationAddress, + uint256 amount, + bytes metadata, + uint32 depositCount + ); + + function deployMockL1Escrow() internal returns (L1YearnEscrow newEscrow) { + bytes memory data = abi.encodeCall( + L1YearnEscrow.initialize, + ( + governator, + czar, + address(polygonZkEVMBridge), + address(l2EscrowImpl), + l2RollupID, + address(asset), + l2TokenAddress, + address(vault) + ) + ); + + newEscrow = L1YearnEscrow( + _create3Deploy( + keccak256(abi.encodePacked(bytes("L1Escrow:"), address(asset))), + address(l1EscrowImpl), + data + ) + ); + } +} diff --git a/test/setup.t.sol b/test/Setup.t.sol similarity index 79% rename from test/setup.t.sol rename to test/Setup.t.sol index e42f734..e063a2b 100644 --- a/test/setup.t.sol +++ b/test/Setup.t.sol @@ -1,22 +1,22 @@ // SPDX-License-Identifier: AGPL-3.0 pragma solidity >=0.8.18; -import {Setup, console} from "./utils/Setup.sol"; -import {Roles} from "@yearn-vaults/interfaces/Roles.sol"; +import {Setup, console, Roles} from "./utils/Setup.sol"; contract SetupTest is Setup { - - uint256 public managementRoles = Roles.REPORTING_MANAGER | - Roles.DEBT_MANAGER | - Roles.QUEUE_MANAGER | - Roles.DEPOSIT_LIMIT_MANAGER | - Roles.DEBT_PURCHASER | - Roles.PROFIT_UNLOCK_MANAGER; + uint256 public managementRoles = + Roles.REPORTING_MANAGER | + Roles.DEBT_MANAGER | + Roles.QUEUE_MANAGER | + Roles.DEPOSIT_LIMIT_MANAGER | + Roles.DEBT_PURCHASER | + Roles.PROFIT_UNLOCK_MANAGER; uint256 public keeperRoles = Roles.REPORTING_MANAGER; - uint256 public debtAllocatorRoles = Roles.REPORTING_MANAGER | Roles.DEBT_MANAGER; + uint256 public debtAllocatorRoles = + Roles.REPORTING_MANAGER | Roles.DEBT_MANAGER; - function setUp() public virtual override{ + function setUp() public virtual override { super.setUp(); } @@ -66,7 +66,10 @@ contract SetupTest is Setup { assertEq(l2Deployer.getRiskManager(), l2RiskManager); assertEq(l2Deployer.getEscrowManager(), l2EscrowManager); assertEq(l2Deployer.getTokenImplementation(), address(l2TokenImpl)); - assertEq(l2Deployer.getConvertorImplementation(), address(l2TokenConverterImpl)); + assertEq( + l2Deployer.getConvertorImplementation(), + address(l2TokenConverterImpl) + ); } function test_newVault() public { @@ -76,7 +79,7 @@ contract SetupTest is Setup { address manager = address(123); vm.expectRevert("!admin"); - l1Deployer.registerRollup(rollupID, manager); + l1Deployer.registerRollup(rollupID, manager); vm.prank(admin); l1Deployer.registerRollup(rollupID, manager); @@ -93,10 +96,15 @@ contract SetupTest is Setup { l1Deployer.registerRollup(rollupID, manager); address _l1Escrow; - ( , _l1Escrow) = l1Deployer.newAsset(rollupID, address(asset)); - bytes memory data = abi.encode(address(asset), _l1Escrow, asset.name(), bytes(asset.symbol())); - - vm.prank(polygonZkEVMBridge); + (, _l1Escrow) = l1Deployer.newAsset(rollupID, address(asset)); + bytes memory data = abi.encode( + address(asset), + _l1Escrow, + asset.name(), + bytes(asset.symbol()) + ); + + vm.prank(address(polygonZkEVMBridge)); l2Deployer.onMessageReceived(address(l1Deployer), 0, data); } -} \ No newline at end of file +} diff --git a/test/mocks/MockBridge.sol b/test/mocks/MockBridge.sol index b83780a..ecf1596 100644 --- a/test/mocks/MockBridge.sol +++ b/test/mocks/MockBridge.sol @@ -10,19 +10,25 @@ interface IBridgeMessageReceiver { } contract MockBridge { - uint32 public L1_NETWORK_ID = 1; uint32 public L2_NETWORK_ID = 2; - address public polygonRollupManager = 0x5132A183E9F3CB7C848b0AAC5Ae0c4f0491B7aB2; + address public polygonRollupManager = + 0x5132A183E9F3CB7C848b0AAC5Ae0c4f0491B7aB2; - function bridgeMessage( + function bridgeMessage( uint32 destinationNetwork, address destinationAddress, bool, bytes calldata metadata ) external payable { - uint32 originNetwork = destinationNetwork == L2_NETWORK_ID ? L1_NETWORK_ID : L2_NETWORK_ID; - IBridgeMessageReceiver(destinationAddress).onMessageReceived(msg.sender, originNetwork, metadata); + uint32 originNetwork = destinationNetwork == L2_NETWORK_ID + ? L1_NETWORK_ID + : L2_NETWORK_ID; + IBridgeMessageReceiver(destinationAddress).onMessageReceived( + msg.sender, + originNetwork, + metadata + ); } -} \ No newline at end of file +} diff --git a/test/mocks/MockStrategy.sol b/test/mocks/MockStrategy.sol index 30390c1..3b569ba 100644 --- a/test/mocks/MockStrategy.sol +++ b/test/mocks/MockStrategy.sol @@ -4,7 +4,5 @@ pragma solidity >=0.8.18; import {ERC4626Mock} from "@openzeppelin/contracts/mocks/token/ERC4626Mock.sol"; contract MockStrategy is ERC4626Mock { - - constructor(address _asset) ERC4626Mock(_asset) { - } -} \ No newline at end of file + constructor(address _asset) ERC4626Mock(_asset) {} +} diff --git a/test/mocks/MockTokenizedStrategy.sol b/test/mocks/MockTokenizedStrategy.sol index 612655c..6576e99 100644 --- a/test/mocks/MockTokenizedStrategy.sol +++ b/test/mocks/MockTokenizedStrategy.sol @@ -4,17 +4,16 @@ pragma solidity >=0.8.18; import {BaseStrategy, ERC20} from "./BaseStrategy.sol"; contract MockTokenizedStrategy is BaseStrategy { - constructor( address _asset, string memory _name - ) BaseStrategy(_asset, _name){} + ) BaseStrategy(_asset, _name) {} - function _deployFunds(uint256 _amount) internal override virtual {} + function _deployFunds(uint256 _amount) internal virtual override {} - function _freeFunds(uint256 _amount) internal override virtual {} + function _freeFunds(uint256 _amount) internal virtual override {} - function _harvestAndReport() internal override virtual returns (uint256) { + function _harvestAndReport() internal virtual override returns (uint256) { return asset.balanceOf(address(this)); } } @@ -26,7 +25,7 @@ contract MockTokenized is MockTokenizedStrategy { constructor( address _asset, string memory _name - ) MockTokenizedStrategy(_asset, _name){} + ) MockTokenizedStrategy(_asset, _name) {} function realizeLoss(uint256 _amount) external { asset.transfer(msg.sender, _amount); diff --git a/test/utils/Setup.sol b/test/utils/Setup.sol index c151912..4e90007 100644 --- a/test/utils/Setup.sol +++ b/test/utils/Setup.sol @@ -17,6 +17,8 @@ import {DebtAllocator, DebtAllocatorFactory} from "@vault-periphery/debtAllocato import {ICREATE3Factory} from "../../src/interfaces/ICREATE3Factory.sol"; +import {IPolygonZkEVMBridge} from "../../src/interfaces/Polygon/IPolygonZkEVMBridge.sol"; + import {IAccountant} from "../../src/interfaces/Yearn/IAccountant.sol"; import {IAccountantFactory} from "../../src/interfaces/Yearn/IAccountantFactory.sol"; @@ -24,6 +26,7 @@ import {L1Deployer} from "../../src/L1Deployer.sol"; import {L2Deployer} from "../../src/L2Deployer.sol"; import {L1YearnEscrow} from "../../src/L1YearnEscrow.sol"; +import {Proxy} from "@zkevm-stb/Proxy.sol"; import {L2Escrow} from "@zkevm-stb/L2Escrow.sol"; import {L2Token} from "@zkevm-stb/L2Token.sol"; import {L2TokenConverter} from "@zkevm-stb/L2TokenConverter.sol"; @@ -35,9 +38,9 @@ contract Setup is ExtendedTest { // Contract instances that we will use repeatedly. ERC20 public asset; - IStrategy public mockStrategy; - address public polygonZkEVMBridge = 0x2a3DD3EB832aF982ec71669E178424b10Dca2EDe; + IPolygonZkEVMBridge public polygonZkEVMBridge = + IPolygonZkEVMBridge(0x2a3DD3EB832aF982ec71669E178424b10Dca2EDe); address public rollupManager = 0x5132A183E9F3CB7C848b0AAC5Ae0c4f0491B7aB2; @@ -47,17 +50,20 @@ contract Setup is ExtendedTest { // Vault contracts to test with. IVault public vault; // Vault Factory v3.0.2 - IVaultFactory public vaultFactory = IVaultFactory(0x444045c5C13C246e117eD36437303cac8E250aB0); + IVaultFactory public vaultFactory = + IVaultFactory(0x444045c5C13C246e117eD36437303cac8E250aB0); /// Periphery Contracts \\\ Registry public registry; - RegistryFactory public registryFactory = RegistryFactory(0x8648FF16ed48FAD456BF0e0e2190AeA8710BdC81); + RegistryFactory public registryFactory = + RegistryFactory(0x8648FF16ed48FAD456BF0e0e2190AeA8710BdC81); DebtAllocatorFactory public allocatorFactory; IAccountant public accountant; - IAccountantFactory public accountantFactory = IAccountantFactory(0xF728f839796a399ACc2823c1e5591F05a31c32d1); + IAccountantFactory public accountantFactory = + IAccountantFactory(0xF728f839796a399ACc2823c1e5591F05a31c32d1); /// Core Contracts \\\\ @@ -87,7 +93,7 @@ contract Setup is ExtendedTest { address public emergencyAdmin = address(6); address public l2RiskManager = address(48); address public l2EscrowManager = address(67); - + mapping(string => address) public tokenAddrs; // Integer variables that will be used repeatedly. @@ -96,12 +102,15 @@ contract Setup is ExtendedTest { uint256 public WAD = 1e18; // Fuzz amount - uint256 public maxFuzzAmount = 1e12; - uint256 public minFuzzAmount = MAX_BPS; + uint256 public maxFuzzAmount = 1e30; + uint256 public minFuzzAmount = 1e4; // Default profit max unlock time is set for 10 days uint256 public profitMaxUnlockTime = 10 days; + uint32 public l1RollupID = 0; + uint32 public l2RollupID = 1; + function setUp() public virtual { _setTokenAddrs(); @@ -111,19 +120,23 @@ contract Setup is ExtendedTest { ); // Deploy new Debt Allocator Factory. - allocatorFactory = DebtAllocatorFactory(new DebtAllocatorFactory(governator)); + allocatorFactory = DebtAllocatorFactory( + new DebtAllocatorFactory(governator) + ); // Deploy new Accountant - accountant = IAccountant(accountantFactory.newAccountant( - governator, // governance - feeRecipient, // Fee recipient - 0, // Management Fee - 1_000, // Perf Fee - 0, // Refund Ratio - 10_000, // Max Fee - 20_000, // Max Gain - 0 // Max Loss - )); + accountant = IAccountant( + accountantFactory.newAccountant( + governator, // governance + feeRecipient, // Fee recipient + 0, // Management Fee + 1_000, // Perf Fee + 0, // Refund Ratio + 10_000, // Max Fee + 20_000, // Max Gain + 0 // Max Loss + ) + ); l1EscrowImpl = new L1YearnEscrow(); @@ -150,7 +163,7 @@ contract Setup is ExtendedTest { address(l1Deployer), l2RiskManager, l2EscrowManager, - polygonZkEVMBridge, + address(polygonZkEVMBridge), address(l2TokenImpl), address(l2EscrowImpl), address(l2TokenConverterImpl) @@ -158,9 +171,15 @@ contract Setup is ExtendedTest { vm.startPrank(governator); registry.setEndorser(address(l1Deployer), true); - l1Deployer.setPositionHolder(l1Deployer.ACCOUNTANT(), address(accountant)); + l1Deployer.setPositionHolder( + l1Deployer.ACCOUNTANT(), + address(accountant) + ); accountant.setVaultManager(address(l1Deployer)); - l1Deployer.setPositionHolder(l1Deployer.L2_DEPLOYER(), address(l2Deployer)); + l1Deployer.setPositionHolder( + l1Deployer.L2_DEPLOYER(), + address(l2Deployer) + ); vm.stopPrank(); // Make sure everything works with USDT @@ -175,7 +194,7 @@ contract Setup is ExtendedTest { vm.label(keeper, "keeper"); vm.label(address(asset), "asset"); vm.label(management, "management"); - vm.label(address(mockStrategy), "strategy"); + vm.label(address(vault), "vault"); vm.label(address(vaultFactory), " vault factory"); vm.label(feeRecipient, "feeRecipient"); vm.label(address(registry), "Registry"); @@ -190,6 +209,28 @@ contract Setup is ExtendedTest { vm.label(address(create3Factory), "Create 3 Factory"); } + function deployMockVault() public returns (IVault _newVault) { + // Skip 1 to always get a unique name each time + skip(1); + _newVault = IVault( + vaultFactory.deploy_new_vault( + address(asset), + string.concat( + "Mock Vault", + string(abi.encode(block.timestamp)) + ), + "yvMock", + governator, + 10 days + ) + ); + + vm.startPrank(governator); + _newVault.set_role(governator, Roles.ALL); + _newVault.set_deposit_limit(2 ** 256 - 1); + vm.stopPrank(); + } + function setUpStrategy() public returns (IStrategy) { // we save the strategy as a IStrategyInterface to give it the needed interface IStrategy _strategy = IStrategy( @@ -209,25 +250,25 @@ contract Setup is ExtendedTest { return _strategy; } - function depositIntoStrategy( - IStrategy _strategy, + function bridgeAsset( + L1YearnEscrow _escrow, address _user, uint256 _amount ) public { vm.startPrank(_user); - asset.approve(address(_strategy), _amount); + asset.approve(address(_escrow), _amount); - _strategy.deposit(_amount, _user); + _escrow.bridgeToken(_user, _amount, true); vm.stopPrank(); } - function mintAndDepositIntoStrategy( - IStrategy _strategy, + function mintAndBridge( + L1YearnEscrow _escrow, address _user, uint256 _amount ) public { airdrop(asset, _user, _amount); - depositIntoStrategy(_strategy, _user, _amount); + bridgeAsset(_escrow, _user, _amount); } function addStrategyToVault(IVault _vault, IStrategy _strategy) public { @@ -253,50 +294,73 @@ contract Setup is ExtendedTest { function addStrategyAndDebt( IVault _vault, IStrategy _strategy, - address _user, uint256 _amount ) public { addStrategyToVault(_vault, _strategy); - mintAndDepositIntoStrategy(IStrategy(address(_vault)), _user, _amount); addDebtToStrategy(_vault, _strategy, _amount); } - // For checking the amounts in the strategy - function checkStrategyTotals( - IStrategy _strategy, - uint256 _totalAssets, - uint256 _totalDebt, - uint256 _totalIdle - ) public view { - uint256 _assets = _strategy.totalAssets(); - uint256 _balance = ERC20(_strategy.asset()).balanceOf( - address(_strategy) - ); - uint256 _idle = _balance > _assets ? _assets : _balance; - uint256 _debt = _assets - _idle; - assertEq(_assets, _totalAssets, "!totalAssets"); - assertEq(_debt, _totalDebt, "!totalDebt"); - assertEq(_idle, _totalIdle, "!totalIdle"); - assertEq(_totalAssets, _totalDebt + _totalIdle, "!Added"); - } - function airdrop(ERC20 _asset, address _to, uint256 _amount) public { uint256 balanceBefore = _asset.balanceOf(_to); deal(address(_asset), _to, balanceBefore + _amount); } - function setFees(uint16 _protocolFee, uint16 _performanceFee) public { - address gov = vaultFactory.governance(); + function getL2TokenAddress( + address _l1TokenAddress + ) public view virtual returns (address) { + return + create3Factory.getDeployed( + address(l2Deployer), + keccak256(abi.encodePacked(bytes("L2Token:"), _l1TokenAddress)) + ); + } + + function getL1EscrowAddress( + address _l1TokenAddress + ) public view virtual returns (address) { + return + create3Factory.getDeployed( + address(l1Deployer), + keccak256(abi.encodePacked(bytes("L1Escrow:"), _l1TokenAddress)) + ); + } - // Need to make sure there is a protocol fee recipient to set the fee. - vm.prank(gov); - vaultFactory.set_protocol_fee_recipient(gov); + function getL2EscrowAddress( + address _l1TokenAddress + ) public view virtual returns (address) { + return + create3Factory.getDeployed( + address(l2Deployer), + keccak256(abi.encodePacked(bytes("L2Escrow:"), _l1TokenAddress)) + ); + } - vm.prank(gov); - vaultFactory.set_protocol_fee_bps(_protocolFee); + function getL2ConvertorAddress( + address _l1TokenAddress + ) public view virtual returns (address) { + return + create3Factory.getDeployed( + address(l2Deployer), + keccak256( + abi.encodePacked( + bytes("L2TokenConverter:"), + _l1TokenAddress + ) + ) + ); + } - vm.prank(management); - mockStrategy.setPerformanceFee(_performanceFee); + function _create3Deploy( + bytes32 _salt, + address _implementation, + bytes memory _initData + ) internal returns (address) { + bytes memory _creationCode = abi.encodePacked( + type(Proxy).creationCode, + abi.encode(_implementation, _initData) + ); + + return create3Factory.deploy(_salt, _creationCode); } function _setTokenAddrs() internal { From e1577b37847ce2594db0110f04a4fc65501ac638 Mon Sep 17 00:00:00 2001 From: Schlagonia Date: Mon, 22 Apr 2024 13:02:35 -0600 Subject: [PATCH 2/4] fix: format --- src/L1Deployer.sol | 12 ++++-------- src/L1YearnEscrow.sol | 2 +- src/L2Deployer.sol | 6 ++---- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/L1Deployer.sol b/src/L1Deployer.sol index c768917..be10b6b 100644 --- a/src/L1Deployer.sol +++ b/src/L1Deployer.sol @@ -1,17 +1,13 @@ // SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.20; -import {L1YearnEscrow} from "./L1YearnEscrow.sol"; -import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; - -import {IPolygonRollupManager, IPolygonRollupContract} from "./interfaces/Polygon/IPolygonRollupManager.sol"; - import {Proxy} from "@zkevm-stb/Proxy.sol"; - import {RoleManager} from "./RoleManager.sol"; -import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.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"; // TODO: // getters for custom position holders diff --git a/src/L1YearnEscrow.sol b/src/L1YearnEscrow.sol index f370b09..5684a5c 100644 --- a/src/L1YearnEscrow.sol +++ b/src/L1YearnEscrow.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.20; -import {L1Escrow, SafeERC20, IERC20} from "@zkevm-stb/L1Escrow.sol"; import {IVault} from "@yearn-vaults/interfaces/IVault.sol"; +import {L1Escrow, SafeERC20, IERC20} from "@zkevm-stb/L1Escrow.sol"; // ADD buffer contract L1YearnEscrow is L1Escrow { diff --git a/src/L2Deployer.sol b/src/L2Deployer.sol index 6544b21..3e966fc 100644 --- a/src/L2Deployer.sol +++ b/src/L2Deployer.sol @@ -1,14 +1,12 @@ // SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.20; -import {L2Escrow} from "@zkevm-stb/L2Escrow.sol"; import {L2Token} from "@zkevm-stb/L2Token.sol"; +import {DeployerBase} from "./DeployerBase.sol"; +import {L2Escrow} from "@zkevm-stb/L2Escrow.sol"; import {L2TokenConverter} from "@zkevm-stb/L2TokenConverter.sol"; - import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -import {DeployerBase} from "./DeployerBase.sol"; - // Array of tokens? // m contract L2Deployer is DeployerBase { From da6e53fd5bde1e93b5f3845d41b5adb78d5d202f Mon Sep 17 00:00:00 2001 From: Schlagonia Date: Mon, 22 Apr 2024 20:37:27 -0600 Subject: [PATCH 3/4] fix: deployments --- src/DeployerBase.sol | 4 ++++ src/L1Deployer.sol | 53 +++++++++++++------------------------------ src/L1YearnEscrow.sol | 14 +++++++++--- src/RoleManager.sol | 2 +- 4 files changed, 32 insertions(+), 41 deletions(-) diff --git a/src/DeployerBase.sol b/src/DeployerBase.sol index 6e5d6a7..e6cb5b0 100644 --- a/src/DeployerBase.sol +++ b/src/DeployerBase.sol @@ -10,6 +10,10 @@ import {IPolygonZkEVMBridge} from "./interfaces/Polygon/IPolygonZkEVMBridge.sol" * @notice To be inherited by the L1 and L2 Deployer's for common functionality. */ abstract contract DeployerBase { + /*////////////////////////////////////////////////////////////// + POSITION ID'S + //////////////////////////////////////////////////////////////*/ + bytes32 public constant ESCROW_IMPLEMENTATION = keccak256("Escrow Implementation"); bytes32 public constant L1_DEPLOYER = keccak256("L1 Deployer"); diff --git a/src/L1Deployer.sol b/src/L1Deployer.sol index be10b6b..0397b07 100644 --- a/src/L1Deployer.sol +++ b/src/L1Deployer.sol @@ -52,7 +52,7 @@ contract L1Deployer is DeployerBase, RoleManager { } /*////////////////////////////////////////////////////////////// - POSITION ID'S + IMMUTABLE'S //////////////////////////////////////////////////////////////*/ IPolygonRollupManager public immutable rollupManager; @@ -152,7 +152,7 @@ contract L1Deployer is DeployerBase, RoleManager { // If not, deploy one and do full setup if (_vault == address(0)) { - _vault = _deployDefaultVault(_asset); + _vault = _deployNewVault(DEFAULT_ID, _asset); } // Deploy L1 Escrow. @@ -163,36 +163,7 @@ contract L1Deployer is DeployerBase, RoleManager { uint32 _rollupID, address _asset ) external virtual onlyRollupAdmin(_rollupID) returns (address _vault) { - string memory _rollupIDString = Strings.toString(_rollupID); - - // Name is "{SYMBOL}-STB-{rollupID} yVault" - string memory _name = string( - abi.encodePacked( - ERC20(_asset).symbol(), - "-STB-", - _rollupIDString, - " yVault" - ) - ); - // Symbol is "stb{SYMBOL}-{rollupID}". - string memory _symbol = string( - abi.encodePacked( - "stb", - ERC20(_asset).symbol(), - "-", - _rollupIDString - ) - ); - - _vault = _newVault( - _asset, - _name, - _symbol, - _rollupID, - 2 ** 256 - 1, - defaultProfitMaxUnlock - ); - + _vault = _deployNewVault(_rollupID, _asset); // Custom Roles??? _newCustomAsset(_rollupID, _asset, _vault); } @@ -224,16 +195,22 @@ contract L1Deployer is DeployerBase, RoleManager { VAULT CREATION //////////////////////////////////////////////////////////////*/ - function _deployDefaultVault( + 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 yVault") + abi.encodePacked(ERC20(_asset).symbol(), "-STB", _id, " yVault") ); // Symbol is "stb{SYMBOL}". string memory _symbol = string( - abi.encodePacked("stb", ERC20(_asset).symbol()) + abi.encodePacked("stb", ERC20(_asset).symbol(), _id) ); return @@ -241,7 +218,7 @@ contract L1Deployer is DeployerBase, RoleManager { _asset, _name, _symbol, - DEFAULT_ID, + _rollupID, 2 ** 256 - 1, defaultProfitMaxUnlock ); @@ -268,6 +245,8 @@ contract L1Deployer is DeployerBase, RoleManager { ) ); + address expectedL1Escrow = getL1EscrowAddress(_asset); + _l1Escrow = _create3Deploy( keccak256(abi.encodePacked(bytes("L1Escrow:"), _asset)), getPositionHolder(ESCROW_IMPLEMENTATION), @@ -275,7 +254,7 @@ contract L1Deployer is DeployerBase, RoleManager { ); // Make sure we got the right address. - require(_l1Escrow == getL1EscrowAddress(_asset), "wrong address"); + require(_l1Escrow == expectedL1Escrow, "wrong address"); // Set the mapping _chainConfig.escrows[_asset] = _l1Escrow; diff --git a/src/L1YearnEscrow.sol b/src/L1YearnEscrow.sol index 5684a5c..8455952 100644 --- a/src/L1YearnEscrow.sol +++ b/src/L1YearnEscrow.sol @@ -4,7 +4,11 @@ pragma solidity ^0.8.20; import {IVault} from "@yearn-vaults/interfaces/IVault.sol"; import {L1Escrow, SafeERC20, IERC20} from "@zkevm-stb/L1Escrow.sol"; -// ADD buffer +/** + * @title L1YearnEscrow + * @author yearn.fi + * @dev L1 escrow that will deploy the assets to a Yearn vault to earn yield. + */ contract L1YearnEscrow is L1Escrow { // **************************** // * Libraries * @@ -139,6 +143,8 @@ contract L1YearnEscrow is L1Escrow { address destinationAddress, uint256 amount ) internal virtual override whenNotPaused { + VaultStorage storage $ = _getVaultStorage(); + // Check if there is enough loose balance. uint256 underlyingBalance = originTokenAddress().balanceOf( address(this) @@ -147,7 +153,10 @@ contract L1YearnEscrow is L1Escrow { if (underlyingBalance >= amount) { super._transferTokens(destinationAddress, amount); return; - } else { + } + + uint256 maxWithdraw = $.vaultAddress.maxWithdraw(address(this)); + if (maxWithdraw < amount) { super._transferTokens(destinationAddress, underlyingBalance); unchecked { amount = amount - underlyingBalance; @@ -156,7 +165,6 @@ contract L1YearnEscrow is L1Escrow { } // Withdraw from vault to receiver. - VaultStorage storage $ = _getVaultStorage(); $.vaultAddress.withdraw(amount, destinationAddress, address(this)); } diff --git a/src/RoleManager.sol b/src/RoleManager.sol index 9729c7d..42ce4c3 100644 --- a/src/RoleManager.sol +++ b/src/RoleManager.sol @@ -624,7 +624,7 @@ contract RoleManager { * @return The default vault for the specified `_asset`. */ function getVault(address _asset) public view virtual returns (address) { - return _assetToVault[_asset][DEFAULT_ID]; + return getVault(_asset, DEFAULT_ID); } /** From 56c77e06930484c3007ff47af458447939c4519d Mon Sep 17 00:00:00 2001 From: Schlagonia Date: Mon, 22 Apr 2024 21:33:09 -0600 Subject: [PATCH 4/4] fix: flow --- src/L1Deployer.sol | 51 +++++++++------------------------------------ src/RoleManager.sol | 30 ++++++++++++++++---------- test/Setup.t.sol | 5 +++-- 3 files changed, 32 insertions(+), 54 deletions(-) diff --git a/src/L1Deployer.sol b/src/L1Deployer.sol index 0397b07..d21f0b0 100644 --- a/src/L1Deployer.sol +++ b/src/L1Deployer.sol @@ -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"; @@ -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), @@ -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 @@ -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, diff --git a/src/RoleManager.sol b/src/RoleManager.sol index 42ce4c3..3c660cd 100644 --- a/src/RoleManager.sol +++ b/src/RoleManager.sol @@ -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"; @@ -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. @@ -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({ diff --git a/test/Setup.t.sol b/test/Setup.t.sol index e063a2b..4782ea2 100644 --- a/test/Setup.t.sol +++ b/test/Setup.t.sol @@ -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 = @@ -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 { @@ -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,