Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling ERC4626 vaults in AcreRouter #62

Merged
merged 20 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
nkuba marked this conversation as resolved.
Show resolved Hide resolved

/// @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 {
nkuba marked this conversation as resolved.
Show resolved Hide resolved
bool approved;
nkuba marked this conversation as resolved.
Show resolved Hide resolved
}

/// @notice Approved vaults within the Yiern Modules that implement ERC4626
/// standard. These vaults deposit assets to yield strategies, e.g.
nkuba marked this conversation as resolved.
Show resolved Hide resolved
/// 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);
nkuba marked this conversation as resolved.
Show resolved Hide resolved

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

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 {
nkuba marked this conversation as resolved.
Show resolved Hide resolved
require(vaultsInfo[vault].approved, "Not a vault");
nkuba marked this conversation as resolved.
Show resolved Hide resolved

delete vaultsInfo[vault];
nkuba marked this conversation as resolved.
Show resolved Hide resolved

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"
nkuba marked this conversation as resolved.
Show resolved Hide resolved
}
}
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading