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

VAL-121 Consolidate Vault implementations; make upgradeable #154

Merged
merged 5 commits into from
Dec 12, 2022
Merged
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
43 changes: 0 additions & 43 deletions contracts/CollateralVault.sol

This file was deleted.

35 changes: 0 additions & 35 deletions contracts/FeeVault.sol

This file was deleted.

56 changes: 0 additions & 56 deletions contracts/FirstLossVault.sol

This file was deleted.

43 changes: 0 additions & 43 deletions contracts/FundingVault.sol

This file was deleted.

30 changes: 19 additions & 11 deletions contracts/Loan.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "./interfaces/ILoan.sol";
import "./interfaces/IPool.sol";
import "./interfaces/IServiceConfiguration.sol";
import "./interfaces/IVault.sol";
import "./factories/interfaces/IVaultFactory.sol";
import "./libraries/LoanLib.sol";
import "./CollateralVault.sol";
import "./FundingVault.sol";
import "./upgrades/BeaconImplementation.sol";

/**
Expand All @@ -23,8 +23,8 @@ contract Loan is ILoan, BeaconImplementation {
ILoanLifeCycleState private _state = ILoanLifeCycleState.Requested;
address private _borrower;
address private _pool;
CollateralVault public _collateralVault;
FundingVault public fundingVault;
IVault public collateralVault;
IVault public fundingVault;
address[] private _fungibleCollateral;
ILoanNonFungibleCollateral[] private _nonFungibleCollateral;
uint256 public createdAt;
Expand Down Expand Up @@ -128,14 +128,20 @@ contract Loan is ILoan, BeaconImplementation {
address borrower_,
address pool_,
address liquidityAsset_,
address vaultFactory,
ILoanSettings memory settings_
) public virtual initializer {
_serviceConfiguration = IServiceConfiguration(serviceConfiguration_);
_factory = factory_;
_borrower = borrower_;
_pool = pool_;
_collateralVault = new CollateralVault(address(this));
fundingVault = new FundingVault(address(this), liquidityAsset_);

collateralVault = IVault(
IVaultFactory(vaultFactory).createVault(address(this))
);
fundingVault = IVault(
IVaultFactory(vaultFactory).createVault(address(this))
);
createdAt = block.timestamp;
liquidityAsset = liquidityAsset_;
settings = settings_;
Expand Down Expand Up @@ -215,6 +221,7 @@ contract Loan is ILoan, BeaconImplementation {

LoanLib.returnCanceledLoanPrincipal(
fundingVault,
liquidityAsset,
_pool,
settings.principal
);
Expand All @@ -240,9 +247,9 @@ contract Loan is ILoan, BeaconImplementation {
"Loan: unable to claim collateral"
);

LoanLib.withdrawFungibleCollateral(_collateralVault, assets);
LoanLib.withdrawFungibleCollateral(collateralVault, assets);
LoanLib.withdrawNonFungibleCollateral(
_collateralVault,
collateralVault,
nonFungibleAssets
);
}
Expand All @@ -261,7 +268,7 @@ contract Loan is ILoan, BeaconImplementation {
{
require(amount > 0, "Loan: posting 0 collateral");
_state = LoanLib.postFungibleCollateral(
address(_collateralVault),
address(collateralVault),
asset,
amount,
_state,
Expand All @@ -287,7 +294,7 @@ contract Loan is ILoan, BeaconImplementation {
returns (ILoanLifeCycleState)
{
_state = LoanLib.postNonFungibleCollateral(
address(_collateralVault),
address(collateralVault),
asset,
tokenId,
_state,
Expand Down Expand Up @@ -328,7 +335,7 @@ contract Loan is ILoan, BeaconImplementation {
function reclaimFunds(uint256 amount) external onlyNotPaused onlyPoolAdmin {
require(settings.loanType == ILoanType.Open);

fundingVault.withdraw(amount, _pool);
fundingVault.withdrawERC20(liquidityAsset, amount, _pool);
IPool(_pool).onLoanPrincipalReturned(amount);

emit FundsReclaimed(amount, _pool);
Expand All @@ -347,6 +354,7 @@ contract Loan is ILoan, BeaconImplementation {
{
(_state, paymentDueDate) = LoanLib.drawdown(
amount,
liquidityAsset,
fundingVault,
msg.sender,
paymentDueDate,
Expand Down
6 changes: 5 additions & 1 deletion contracts/LoanFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ contract LoanFactory is ILoanFactory, BeaconProxyFactory {
*/
mapping(address => bool) internal _isLoan;

constructor(address serviceConfiguration) {
address internal _vaultFactory;

constructor(address serviceConfiguration, address vaultFactory) {
_serviceConfiguration = IServiceConfiguration(serviceConfiguration);
_vaultFactory = vaultFactory;
}

/**
Expand Down Expand Up @@ -59,6 +62,7 @@ contract LoanFactory is ILoanFactory, BeaconProxyFactory {
borrower,
pool,
liquidityAsset,
_vaultFactory,
settings
)
);
Expand Down
14 changes: 10 additions & 4 deletions contracts/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ pragma solidity ^0.8.16;

import "./interfaces/ILoan.sol";
import "./interfaces/IPool.sol";
import "./interfaces/IVault.sol";
import "./interfaces/IServiceConfiguration.sol";
import "./controllers/interfaces/IWithdrawController.sol";
import "./controllers/interfaces/IPoolController.sol";
import "./factories/interfaces/IWithdrawControllerFactory.sol";
import "./factories/interfaces/IPoolControllerFactory.sol";
import "./factories/interfaces/IVaultFactory.sol";
import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {SafeERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import "./libraries/PoolLib.sol";
import "./FeeVault.sol";
import "./FirstLossVault.sol";
import "./upgrades/BeaconImplementation.sol";

/**
Expand All @@ -29,7 +29,7 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {

IServiceConfiguration private _serviceConfiguration;
IERC20Upgradeable private _liquidityAsset;
FeeVault private _feeVault;
IVault private _feeVault;
IPoolAccountings private _accountings;

IWithdrawController public withdrawController;
Expand Down Expand Up @@ -120,6 +120,8 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
* @param poolAdmin admin of the pool
* @param serviceConfiguration_ address of global service configuration
* @param withdrawControllerFactory factory address of the withdraw controller
* @param poolControllerFactory factory address for emitting pool controllers
* @param vaultFactory factory address of the Vault
* @param poolSettings configurable settings for the pool
* @param tokenName Name used for issued pool tokens
* @param tokenSymbol Symbol used for issued pool tokens
Expand All @@ -130,14 +132,17 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
address serviceConfiguration_,
address withdrawControllerFactory,
address poolControllerFactory,
address vaultFactory,
IPoolConfigurableSettings memory poolSettings,
string memory tokenName,
string memory tokenSymbol
) public initializer {
__ERC20_init(tokenName, tokenSymbol);
_serviceConfiguration = IServiceConfiguration(serviceConfiguration_);
_liquidityAsset = IERC20Upgradeable(liquidityAsset);
_feeVault = new FeeVault(address(this));
_feeVault = IVault(
IVaultFactory(vaultFactory).createVault(address(this))
);

// Build the withdraw controller
withdrawController = IWithdrawController(
Expand All @@ -152,6 +157,7 @@ contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
serviceConfiguration_,
poolAdmin,
liquidityAsset,
vaultFactory,
poolSettings
)
);
Expand Down
Loading