Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into vaults-poc
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuba committed Dec 13, 2023
2 parents c317668 + 574cec8 commit f8c0d2d
Show file tree
Hide file tree
Showing 11 changed files with 321 additions and 316 deletions.
2 changes: 1 addition & 1 deletion core/.solhint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "thesis",
"plugins": [],
"rules": { "func-visibility": ["error", { "ignoreConstructors": true }] }
"rules": {}
}
62 changes: 0 additions & 62 deletions core/contracts/AcreRouter.sol

This file was deleted.

63 changes: 60 additions & 3 deletions core/contracts/Dispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,74 @@ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol

import "./Router.sol";

contract Dispatcher is Router, Ownable {
/// a given vault and back. Vaults supply yield strategies with TBTC that
/// generate yield for Bitcoin holders.
contract Dispatcher is Ownable {
using SafeERC20 for IERC20;

error VaultAlreadyAuthorized();
error VaultUnauthorized();

struct VaultInfo {
bool authorized;
}

Acre acre;

/// @notice Authorized Yield Vaults 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 authorized by the owner it can be plugged into
/// Acre.
address[] public vaults;
mapping(address => VaultInfo) public vaultsInfo;

event VaultAuthorized(address indexed vault);
event VaultDeauthorized(address indexed vault);

constructor(Acre _acre) Ownable(msg.sender) {
acre = _acre;
}

function assetsHolder() public virtual override returns (address){
/// @notice Adds a vault to the list of authorized vaults.
/// @param vault Address of the vault to add.
function authorizeVault(address vault) external onlyOwner {
if (vaultsInfo[vault].authorized) {
revert VaultAlreadyAuthorized();
}

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

emit VaultAuthorized(vault);
}

/// @notice Removes a vault from the list of authorized vaults.
/// @param vault Address of the vault to remove.
function deauthorizeVault(address vault) external onlyOwner {
if (!vaultsInfo[vault].authorized) {
revert VaultUnauthorized();
}

vaultsInfo[vault].authorized = false;

for (uint256 i = 0; i < vaults.length; i++) {
if (vaults[i] == vault) {
vaults[i] = vaults[vaults.length - 1];
// slither-disable-next-line costly-loop
vaults.pop();
break;
}
}

emit VaultDeauthorized(vault);
}

function getVaults() external view returns (address[] memory) {
return vaults;
}

return address(acre);
}

Expand All @@ -32,5 +90,4 @@ contract Dispatcher is Router, Ownable {
for (uint i=0; i<_vaults.length; i++) {
_vaults[i].transfer(newDispatcher, _vaults[i].balanceOf(address(this)));
}
}
}
4 changes: 2 additions & 2 deletions core/deploy/02_deploy_acre_router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { getNamedAccounts, deployments } = hre
const { deployer } = await getNamedAccounts()

await deployments.deploy("AcreRouter", {
await deployments.deploy("Dispatcher", {
from: deployer,
args: [],
log: true,
Expand All @@ -18,5 +18,5 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {

export default func

func.tags = ["AcreRouter"]
func.tags = ["Dispatcher"]
func.dependencies = ["Acre"]
5 changes: 3 additions & 2 deletions core/deploy/22_transfer_ownership_acre_router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployer, governance } = await getNamedAccounts()
const { log } = deployments

log(`transferring ownership of AcreRouter contract to ${governance}`)
log(`transferring ownership of Dispatcher contract to ${governance}`)

await deployments.execute(
"AcreRouter",
"Dispatcher",
{ from: deployer, log: true, waitConfirmations: 1 },
"transferOwnership",
governance,
Expand All @@ -19,3 +19,4 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
export default func

func.tags = ["TransferOwnershipAcreRouter"]
func.dependencies = ["Dispatcher"]
5 changes: 4 additions & 1 deletion core/scripts/fetch_external_artifacts.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#! /bin/bash
set -eou pipefail

ROOT_DIR="$(realpath "$(dirname $0)/../")"
ROOT_DIR=$(
cd "$(dirname $0)/../"
pwd -P
)
TMP_DIR=${ROOT_DIR}/tmp/external-artifacts
EXTERNAL_ARTIFACTS_DIR=${ROOT_DIR}/external

Expand Down
143 changes: 0 additions & 143 deletions core/test/AcreRouter.test.ts

This file was deleted.

Loading

0 comments on commit f8c0d2d

Please sign in to comment.