Skip to content

Commit

Permalink
create vault constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-nyquist committed May 18, 2022
1 parent dfc2b50 commit 86762f4
Show file tree
Hide file tree
Showing 6 changed files with 940 additions and 3 deletions.
24 changes: 24 additions & 0 deletions src/HookERC721MultiVault.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
pragma solidity ^0.8.10;

import "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol";

/// @title ERC-721 MultiVault Proxy Contract
/// @author Jake Nyquist -- [email protected]
/// @notice Each instance of this contract is a unique multi-vault which references the
/// shared implementation pointed to by the Beacon
contract HookERC721MultiVault is BeaconProxy {
constructor(
address beacon,
address nftAddress,
address hookProtocolAddress
)
BeaconProxy(
beacon,
abi.encodeWithSignature(
"initialize(address,address)",
nftAddress,
hookProtocolAddress
)
)
{}
}
15 changes: 15 additions & 0 deletions src/HookERC721MultiVaultBeacon.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pragma solidity ^0.8.10;

import "./HookUpgradeableBeacon.sol";

/// @title HookERC721MultiVaultBeacon -- beacon holding pointer to current ERC721MultiVault implementation
/// @author Jake Nyquist -- [email protected]
/// @notice The beacon broadcasts the address which contains the existing implementation of the ERC721MultiVault
/// @dev Permissions for who can upgrade are contained within the protocol contract.
contract HookERC721MultiVaultBeacon is HookUpgradeableBeacon {
constructor(
address implementation,
address hookProtocol,
bytes32 upgraderRole
) HookUpgradeableBeacon(implementation, hookProtocol, upgraderRole) {}
}
2 changes: 1 addition & 1 deletion src/HookERC721MultiVaultImplV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import "./mixin/EIP712.sol";
/// @dev This contract implements ERC721Reciever
/// This contract views the tokenId for the asset on the ERC721 contract as the corresponding assetId for that asset
/// when deposited into the vault
contract HookERC721VaultImplV1 is
contract HookERC721MultiVaultImplV1 is
IHookERC721Vault,
EIP712,
Initializable,
Expand Down
21 changes: 19 additions & 2 deletions src/HookERC721VaultFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.10;

import "./HookERC721Vault.sol";
import "./HookERC721MultiVault.sol";
import "./interfaces/IHookERC721VaultFactory.sol";

/// @dev The factory itself is non-upgradeable; however, each vault is upgradeable (i.e. all vaults)
Expand All @@ -12,18 +13,34 @@ contract HookERC721VaultFactory is IHookERC721VaultFactory {
/// @dev From this view, we do not know if a vault is empty or full
mapping(address => mapping(uint256 => address)) public override getVault;

/// @notice Registry of all of the active multi-vaults within the protocol
mapping(address => address) public override getMultiVault;

address private _hookProtocol;
address private _beacon;
address private _multiBeacon;

constructor(address hookProtocolAddress, address beaconAddress) {
constructor(
address hookProtocolAddress,
address beaconAddress,
address multiBeaconAddress
) {
_hookProtocol = hookProtocolAddress;
_beacon = beaconAddress;
_multiBeacon = multiBeaconAddress;
}

/// @notice creates a vault for a specific tokenId. If there
/// is a multi-vault in existence which supports that address
/// the address for that vault is returned as a new one
/// does not need to be made.
function makeVault(address nftAddress, uint256 tokenId)
external
returns (address vault)
{
if (getMultiVault[nftAddress] != address(0)) {
return getMultiVault[nftAddress];
}
require(
getVault[nftAddress][tokenId] == address(0),
"makeVault -- a vault cannot already exist"
Expand All @@ -39,7 +56,7 @@ contract HookERC721VaultFactory is IHookERC721VaultFactory {
_hookProtocol
)
);

return getVault[nftAddress][tokenId];
}
}
5 changes: 5 additions & 0 deletions src/interfaces/IHookERC721VaultFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ interface IHookERC721VaultFactory {
view
returns (address vault);

function getMultiVault(address nftAddress)
external
view
returns (address vault);

function makeVault(address nftAddress, uint256 tokenId)
external
returns (address vault);
Expand Down
Loading

0 comments on commit 86762f4

Please sign in to comment.