Skip to content
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
52 changes: 51 additions & 1 deletion src/ATokenVaultFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {TransparentUpgradeableProxy} from "@openzeppelin/proxy/transparent/Trans
import {ATokenVault} from "./ATokenVault.sol";
import {SafeERC20} from "@openzeppelin/token/ERC20/utils/SafeERC20.sol";
import {ProxyAdmin} from "@openzeppelin/proxy/transparent/ProxyAdmin.sol";
import {ATokenVaultRevenueSplitterOwner} from "./ATokenVaultRevenueSplitterOwner.sol";

/**
* @title ATokenVaultImplDeploymentLib
Expand Down Expand Up @@ -59,6 +60,20 @@ contract ATokenVaultFactory {
VaultParams params
);

/**
* @dev Emitted when a new revenue splitter owner is deployed
* @param revenueSplitterOwner The address of the deployed revenue splitter owner
* @param vault The address of the vault to split the revenue from
* @param owner The address of the owner of the revenue splitter, effective owner of the vault
* @param revenueRecipients The recipients of the revenue
*/
event RevenueSplitterOwnerDeployed(
address indexed revenueSplitterOwner,
address indexed vault,
address indexed owner,
ATokenVaultRevenueSplitterOwner.Recipient[] revenueRecipients
);

/*//////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////*/
Expand All @@ -83,6 +98,7 @@ contract ATokenVaultFactory {
string shareName;
string shareSymbol;
uint256 initialLockDeposit;
ATokenVaultRevenueSplitterOwner.Recipient[] revenueRecipients;
}

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -133,10 +149,19 @@ contract ATokenVaultFactory {
""
));

address vaultOwner = params.owner;
if (params.revenueRecipients.length > 0) {
vaultOwner = _deployRevenueSplitterOwner(
vault,
params.owner,
params.revenueRecipients
);
}

IERC20(params.underlying).safeApprove(vault, params.initialLockDeposit);

ATokenVault(vault).initialize(
params.owner,
vaultOwner,
params.initialFee,
params.shareName,
params.shareSymbol,
Expand All @@ -151,4 +176,29 @@ contract ATokenVaultFactory {
params
);
}

/**
* @notice Deploys a new ATokenVaultRevenueSplitterOwner with the given parameters
* @param vaultAddress The address of the vault to split the revenue from
* @param owner The address of the owner of the revenue splitter, effective owner of the vault
* @param revenueRecipients The recipients of the revenue
* @return revenueSplitter The address of the deployed revenue splitter
*/
function deployRevenueSplitterOwner(
address vaultAddress,
address owner,
ATokenVaultRevenueSplitterOwner.Recipient[] memory revenueRecipients
) external returns (address) {
return _deployRevenueSplitterOwner(vaultAddress, owner, revenueRecipients);
}

function _deployRevenueSplitterOwner(
address vaultAddress,
address owner,
ATokenVaultRevenueSplitterOwner.Recipient[] memory revenueRecipients
) internal returns (address) {
address revenueSplitter = address(new ATokenVaultRevenueSplitterOwner(vaultAddress, owner, revenueRecipients));
emit RevenueSplitterOwnerDeployed(revenueSplitter, vaultAddress, owner, revenueRecipients);
return revenueSplitter;
}
}
Loading