Skip to content

Commit

Permalink
test: l1 escrow
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Apr 22, 2024
1 parent ef3cd38 commit cd1b9ec
Show file tree
Hide file tree
Showing 9 changed files with 527 additions and 100 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
}
Expand Down
33 changes: 29 additions & 4 deletions src/L1YearnEscrow.sol
Original file line number Diff line number Diff line change
@@ -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 *
// **************************
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
);
Expand All @@ -148,6 +155,8 @@ contract L1YearnEscrow is L1Escrow {
}
}

// Withdraw from vault to receiver.
VaultStorage storage $ = _getVaultStorage();
$.vaultAddress.withdraw(amount, destinationAddress, address(this));
}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/Polygon/IPolygonZkEVMBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,6 @@ interface IPolygonZkEVMBridge {
function networkID() external returns (uint32);

function polygonRollupManager() external view returns (address);

function depositCount() external view returns (uint256);
}
Loading

0 comments on commit cd1b9ec

Please sign in to comment.