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

Deploy process and abstractions #6

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 6 additions & 5 deletions packages/004_xfuji_forge/script/DeployGoerli.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ pragma solidity ^0.8.13;
import "forge-std/console.sol";
import {ScriptPlus} from "./ScriptPlus.sol";
import {IConnextHandler} from "nxtp/core/connext/interfaces/IConnextHandler.sol";
import {BorrowingVault} from "../src/vaults/borrowing/BorrowingVault.sol";
import {IVault} from "../src/interfaces/IVault.sol";
import {Vault, ERC20} from "../src/Vault.sol";
import {XRouter} from "../src/XRouter.sol";
import {IWETH9} from "../src/helpers/PeripheryPayments.sol";
import {AaveV3Goerli} from "../src/providers/goerli/AaveV3Goerli.sol";
import {ILendingProvider} from "../src/interfaces/ILendingProvider.sol";

contract DeployGoerli is ScriptPlus {
Vault public vault;
IVault public vault;
XRouter public router;
ILendingProvider public aaveV3;

Expand Down Expand Up @@ -43,12 +43,13 @@ contract DeployGoerli is ScriptPlus {
router = new XRouter(weth, connextHandler);
saveAddress("./deployments/goerli/XRouter", address(router));

vault = new Vault(
vault = new BorrowingVault(
asset,
debtAsset,
oracle
oracle,
address(0)
);
saveAddress("./deployments/goerli/Vault", address(vault));
saveAddress("./deployments/goerli/BorrowingVault", address(vault));

vault.setActiveProvider(aaveV3);
router.registerVault(IVault(address(vault)));
Expand Down
11 changes: 6 additions & 5 deletions packages/004_xfuji_forge/script/DeployRinkeby.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ pragma solidity ^0.8.13;
import "forge-std/console.sol";
import {ScriptPlus} from "./ScriptPlus.sol";
import {IConnextHandler} from "nxtp/core/connext/interfaces/IConnextHandler.sol";
import {BorrowingVault} from "../src/vaults/borrowing/BorrowingVault.sol";
import {IVault} from "../src/interfaces/IVault.sol";
import {Vault, ERC20} from "../src/Vault.sol";
import {XRouter} from "../src/XRouter.sol";
import {IWETH9} from "../src/helpers/PeripheryPayments.sol";
import {AaveV3Rinkeby} from "../src/providers/rinkeby/AaveV3Rinkeby.sol";
import {ILendingProvider} from "../src/interfaces/ILendingProvider.sol";

contract DeployRinkeby is ScriptPlus {
Vault public vault;
IVault public vault;
XRouter public router;
ILendingProvider public aaveV3;

Expand Down Expand Up @@ -43,12 +43,13 @@ contract DeployRinkeby is ScriptPlus {
router = new XRouter(weth, connextHandler);
saveAddress("./deployments/rinkeby/XRouter", address(router));

vault = new Vault(
vault = new BorrowingVault(
asset,
debtAsset,
oracle
oracle,
address(0)
);
saveAddress("./deployments/rinkeby/Vault", address(vault));
saveAddress("./deployments/rinkeby/BorrowingVault", address(vault));

vault.setActiveProvider(aaveV3);
router.registerVault(IVault(address(vault)));
Expand Down
2 changes: 1 addition & 1 deletion packages/004_xfuji_forge/script/bash/goerli/router.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ deploy_contract XRouter --constructor-args $WETH $CONNEXT_HANDLER

ROUTER=$(cat ./deployments/goerli/XRouter)

VAULT=$(cat ./deployments/goerli/Vault)
VAULT=$(cat ./deployments/goerli/BorrowingVault)

cast_tx $ROUTER "setTestnetToken(address)" $TEST_TOKEN

Expand Down
4 changes: 2 additions & 2 deletions packages/004_xfuji_forge/script/bash/goerli/vault.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

AAVE_V3=$(cat ./deployments/goerli/AaveV3Goerli)

deploy_contract Vault --constructor-args $ASSET $DEBT_ASSET $ORACLE
deploy_contract BorrowingVault --constructor-args $ASSET $DEBT_ASSET $ORACLE 0

VAULT=$(cat ./deployments/goerli/Vault)
VAULT=$(cat ./deployments/goerli/BorrowingVault)

cast_tx $VAULT "setActiveProvider(address)" $AAVE_V3
2 changes: 1 addition & 1 deletion packages/004_xfuji_forge/script/bash/rinkeby/router.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ deploy_contract XRouter --constructor-args $WETH $CONNEXT_HANDLER

ROUTER=$(cat ./deployments/rinkeby/XRouter)

VAULT=$(cat ./deployments/rinkeby/Vault)
VAULT=$(cat ./deployments/rinkeby/BorrowingVault)

cast_tx $ROUTER "setTestnetToken(address)" $TEST_TOKEN

Expand Down
4 changes: 2 additions & 2 deletions packages/004_xfuji_forge/script/bash/rinkeby/vault.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

AAVE_V3=$(cat ./deployments/rinkeby/AaveV3Rinkeby)

deploy_contract Vault --constructor-args $ASSET $DEBT_ASSET $ORACLE
deploy_contract BorrowingVault --constructor-args $ASSET $DEBT_ASSET $ORACLE 0

VAULT=$(cat ./deployments/rinkeby/Vault)
VAULT=$(cat ./deployments/rinkeby/BorrowingVault)

cast_tx $VAULT "setActiveProvider(address)" $AAVE_V3
38 changes: 38 additions & 0 deletions packages/004_xfuji_forge/src/Chief.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.9;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

import {IVaultFactory} from "./interfaces/IVaultFactory.sol";

/// @dev Custom Errors
error ZeroAddress();
error NotAllowed();

/// @notice Vault deployer contract with template factory allow.
/// ref: https://github.com/sushiswap/trident/blob/master/contracts/deployer/MasterDeployer.sol
contract Chief is Ownable {
event DeployVault(address indexed factory, address indexed vault, bytes deployData);
event AddToAllowed(address indexed factory);
event RemoveFromAllowed(address indexed factory);

mapping(address => bool) public vaults;
mapping(address => bool) public allowedFactories;

function deployVault(address _factory, bytes calldata _deployData) external returns (address vault) {
if (!allowedFactories[_factory]) revert NotAllowed();
vault = IVaultFactory(_factory).deployVault(_deployData);
vaults[vault] = true;
emit DeployVault(_factory, vault, _deployData);
}

function addToAllowed(address _factory) external onlyOwner {
allowedFactories[_factory] = true;
emit AddToAllowed(_factory);
}

function removeFromAllowed(address _factory) external onlyOwner {
allowedFactories[_factory] = false;
emit RemoveFromAllowed(_factory);
}
}
Loading