Skip to content

Commit

Permalink
Handling ERC4626 vaults in AcreRouter
Browse files Browse the repository at this point in the history
AcreRouter contract should manage ERC4626 vaults within the Acre system.
Owner of the contract should be able to add or remove vaults.
  • Loading branch information
dimpar committed Dec 4, 2023
1 parent 52cc0f4 commit 32b0f4d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
55 changes: 55 additions & 0 deletions core/contracts/AcreRouter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.21;

import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

/// @title AcreRouter
/// @notice AcreRouter is a contract that routes TBTC from stBTC (Acre) to
/// a given vault and back. Vaults supply yield strategies with TBTC that
/// generate yield for Bitcoin holders.
contract AcreRouter is OwnableUpgradeable {
struct Vault {
bool approved;
}

/// @notice Approved vaults within the Yiern Modules that implement ERC4626
/// standard. These vaults deposit assets to yield strategies, e.g.
/// Uniswap V3 WBTC/TBTC pool. Vault can be a part of Acre ecosystem
/// or can be implemented externally. As long as it complies with
/// ERC4626 standard and is approved by the owner it can be
/// plugged into Acre.
address[] public vaults;
mapping(address => Vault) public vaultsInfo;

event VaultAdded(address indexed vault);
event VaultRemoved(address indexed vault);

/// @notice Adds a vault to the list of approved vaults.
/// @param vault Address of the vault to add.
function addVault(address vault) external onlyOwner {
require(!vaultsInfo[vault].approved, "Vault already approved");

vaults.push(vault);
vaultsInfo[vault].approved = true;

emit VaultAdded(vault);
}

/// @notice Removes a vault from the list of approved vaults.
/// @param vault Address of the vault to remove.
function removeVault(address vault) external onlyOwner {
require(vaultsInfo[vault].approved, "Not a vault");

delete vaultsInfo[vault];

for (uint256 i = 0; i < vaults.length; i++) {
if (vaults[i] == vault) {
vaults[i] = vaults[vaults.length - 1];
vaults.pop();
break;
}
}

emit VaultRemoved(vault);
}
}
3 changes: 3 additions & 0 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@
"ts-node": "^10.9.1",
"typechain": "^8.3.2",
"typescript": "^5.3.2"
},
"dependencies": {
"@openzeppelin/contracts-upgradeable": "^5.0.0"
}
}

0 comments on commit 32b0f4d

Please sign in to comment.