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
4 changes: 3 additions & 1 deletion contracts/facets/VaultFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "../interfaces/IERC20.sol";
contract VaultFacet is IVaultFacet, StorageStead {
error NotInheritor();
error AmountMismatch();
error initialized(uint256 _nonce);

///////////////////
//VIEW FUNCTIONS//
Expand Down Expand Up @@ -58,6 +59,7 @@ contract VaultFacet is IVaultFacet, StorageStead {
//////////////////////
///WRITE FUNCTIONS///
////////////////////

//note: owner restriction is in external fns
function addInheritors(
address[] calldata _newInheritors,
Expand All @@ -74,7 +76,7 @@ contract VaultFacet is IVaultFacet, StorageStead {

function depositEther(uint256 _amount) external payable {
if (_amount != msg.value) revert AmountMismatch();
emit EthDeposited(_amount,vs.vaultID);
emit EthDeposited(_amount, vs.vaultID);
}

function withdrawEther(uint256 _amount, address _to) external {
Expand Down
49 changes: 45 additions & 4 deletions contracts/libraries/LibKeep.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ library LibKeep {
}

function getCurrentAllocated1155tokens(address _token, uint256 _tokenID)
internal view
internal
view
returns (uint256 alloc_)
{
VaultStorage storage vs = LibDiamond.vaultStorage();
Expand Down Expand Up @@ -170,11 +171,51 @@ library LibKeep {
vs.inheritorAllocatedERC20Tokens[_inheritor][x]
] = false;
}
//TO-DO Also reset for relevant ERC721 and ERC1155 Storage vars too
//@Abims-Web3bridge //@Falilah
//remove all token addresses
delete vs.inheritorAllocatedERC20Tokens[_inheritor];
}

if (vs.inheritorAllocatedERC721TokenAddresses[_inheritor].length > 0) {
for (
uint256 x;
x < vs.inheritorAllocatedERC721TokenAddresses[_inheritor].length;
x++
) {
uint256 tokenAllocated = vs.inheritorERC721Tokens[_inheritor][
vs.inheritorAllocatedERC721TokenAddresses[_inheritor][x]
];
if (tokenAllocated == 0) {
vs.whitelist[_inheritor][
vs.inheritorAllocatedERC721TokenAddresses[_inheritor][x]
] = false;
}
vs.inheritorERC721Tokens[_inheritor][
vs.inheritorAllocatedERC721TokenAddresses[_inheritor][x]
] = type(uint256).max - 2;
vs.allocatedERC721Tokens[
vs.inheritorAllocatedERC721TokenAddresses[_inheritor][x]
][tokenAllocated] = false;
}

delete vs.inheritorAllocatedERC721TokenAddresses[_inheritor];
}

if (vs.inheritorAllocatedERC1155TokenAddresses[_inheritor].length > 0) {
for (
uint256 x;
x < vs.inheritorAllocatedERC1155TokenAddresses[_inheritor].length;
x++
) {
vs.inheritorERC1155TokenAllocations[_inheritor][
vs.inheritorAllocatedERC1155TokenAddresses[_inheritor][x]
][
vs.inheritorAllocatedTokenIds[_inheritor][
vs.inheritorAllocatedERC1155TokenAddresses[_inheritor][x]
][x]
] = type(uint256).max - 2;
}

delete vs.inheritorAllocatedERC1155TokenAddresses[_inheritor];
}
}

//INHERITOR MUTATING OPERATIONS
Expand Down
211 changes: 93 additions & 118 deletions contracts/libraries/LibVaultStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pragma solidity 0.8.4;

import "./LibDiamond.sol";
struct FacetAddressAndPosition {
address facetAddress;
uint96 functionSelectorPosition; // position in facetFunctionSelectors.functionSelectors array
address facetAddress;
uint96 functionSelectorPosition; // position in facetFunctionSelectors.functionSelectors array
}
error NotBackupAddress();
error NotOwnerOrBackupAddress();
Expand All @@ -12,142 +12,117 @@ error HasExpired();
error Claimed();

struct FacetFunctionSelectors {
bytes4[] functionSelectors;
uint256 facetAddressPosition; // position of facetAddress in facetAddresses array
bytes4[] functionSelectors;
uint256 facetAddressPosition; // position of facetAddress in facetAddresses array
}

struct VaultStorage {
///VAULT DIAMOND VARS
// maps function selector to the facet address and
// the position of the selector in the facetFunctionSelectors.selectors array
mapping(bytes4 => FacetAddressAndPosition) selectorToFacetAndPosition;
// maps facet addresses to function selectors
mapping(address => FacetFunctionSelectors) facetFunctionSelectors;
// facet addresses
address[] facetAddresses;
// Used to query if a contract implements an interface.
// Used to implement ERC-165.
mapping(bytes4 => bool) supportedInterfaces;
//VAULT INTERNAL VARS

//Vault ID
uint256 vaultID;
// owner of the vault
address vaultOwner;
//last time pinged
uint256 lastPing;
//backup address
address backupAddress;
//array of all inheritors
address[] inheritors;
//active inheritors
mapping(address => bool) activeInheritors;
//inheritor WEI shares
mapping(address => uint256) inheritorWeishares;
//ERC20
//inheritor active tokens
mapping(address => mapping(address => bool)) inheritorActiveTokens;
//inheritor token shares
mapping(address => mapping(address => uint256)) inheritorTokenShares;
//address of tokens allocated
mapping(address => address[]) inheritorAllocatedERC20Tokens;
//ERC721
mapping(address => mapping(address => bool)) whitelist;
mapping(address => mapping(address => uint256)) inheritorERC721Tokens;
mapping(address => mapping(uint256 => address)) ERC721ToInheritor;
mapping(address => mapping(uint256 => bool)) allocatedERC721Tokens;
mapping(address => address[]) inheritorAllocatedERC721TokenAddresses;
//ERC1155
mapping(address => mapping(address => mapping(uint256 => uint256))) inheritorERC1155TokenAllocations;
mapping(address => address[]) inheritorAllocatedERC1155TokenAddresses;
//GLOBAL
mapping(address => mapping(address => uint256[])) inheritorAllocatedTokenIds;
mapping(address => bool) claimed;
///VAULT DIAMOND VARS
// maps function selector to the facet address and
// the position of the selector in the facetFunctionSelectors.selectors array
mapping(bytes4 => FacetAddressAndPosition) selectorToFacetAndPosition;
// maps facet addresses to function selectors
mapping(address => FacetFunctionSelectors) facetFunctionSelectors;
// facet addresses
address[] facetAddresses;
// Used to query if a contract implements an interface.
// Used to implement ERC-165.
mapping(bytes4 => bool) supportedInterfaces;
//VAULT INTERNAL VARS

//Vault ID
uint256 vaultID;
// owner of the vault
address vaultOwner;
//last time pinged
uint256 lastPing;
//backup address
address backupAddress;
//array of all inheritors
address[] inheritors;
//active inheritors
mapping(address => bool) activeInheritors;
//inheritor WEI shares
mapping(address => uint256) inheritorWeishares;
//ERC20
//inheritor active tokens
mapping(address => mapping(address => bool)) inheritorActiveTokens;
//inheritor token shares
mapping(address => mapping(address => uint256)) inheritorTokenShares;
//address of tokens allocated
mapping(address => address[]) inheritorAllocatedERC20Tokens;
//ERC721
mapping(address => mapping(address => bool)) whitelist;
mapping(address => mapping(address => uint256)) inheritorERC721Tokens; //inheritortokenshare
mapping(address => mapping(uint256 => address)) ERC721ToInheritor;
mapping(address => mapping(uint256 => bool)) allocatedERC721Tokens;
mapping(address => address[]) inheritorAllocatedERC721TokenAddresses;
//ERC1155
mapping(address => mapping(address => mapping(uint256 => uint256))) inheritorERC1155TokenAllocations;
mapping(address => address[]) inheritorAllocatedERC1155TokenAddresses;
//GLOBAL
mapping(address => mapping(address => uint256[])) inheritorAllocatedTokenIds;
mapping(address => bool) claimed;
}

abstract contract StorageStead {
VaultStorage internal vs;
VaultStorage internal vs;
}

library Guards {
function _onlyVaultOwner() internal view {
LibDiamond.enforceIsContractOwner();
}

function _onlyVaultOwnerOrBackup() internal view {
VaultStorage storage vs = LibDiamond.vaultStorage();
if (msg.sender != vs.backupAddress || msg.sender != vs.vaultOwner)
revert NotOwnerOrBackupAddress();
}

function _enforceIsBackupAddress() internal view {
VaultStorage storage vs = LibDiamond.vaultStorage();
if (msg.sender != vs.backupAddress) revert NotBackupAddress();
}

function _activeInheritor(address _inheritor)
internal














function _onlyVaultOwner() internal view {
LibDiamond.enforceIsContractOwner();
}

function _onlyVaultOwnerOrBackup() internal view {
VaultStorage storage vs = LibDiamond.vaultStorage();
if (msg.sender != vs.backupAddress || msg.sender != vs.vaultOwner)
revert NotOwnerOrBackupAddress();
}

function _enforceIsBackupAddress() internal view {
VaultStorage storage vs = LibDiamond.vaultStorage();
if (msg.sender != vs.backupAddress) revert NotBackupAddress();
}









view
function _activeInheritor(address _inheritor)
internal view
returns (bool active_)
{
VaultStorage storage vs = LibDiamond.vaultStorage();
if (_inheritor == address(0)) {
active_ == true;
} else {
active_ = (vs.activeInheritors[_inheritor]);
}
}

function _anInheritor(address _inheritor) internal view returns (bool inh) {
VaultStorage storage vs = LibDiamond.vaultStorage();
if (_inheritor == address(0)) {
inh = true;
} else {
for (uint256 i; i < vs.inheritors.length; i++) {
if (_inheritor == vs.inheritors[i]) {
inh = true;
}
}
}

function _anInheritor(address _inheritor) internal view returns (bool inh) {
VaultStorage storage vs = LibDiamond.vaultStorage();
if (_inheritor == address(0)) {
inh = true;
} else {
for (uint256 i; i < vs.inheritors.length; i++) {
if (_inheritor == vs.inheritors[i]) {
inh = true;
}
}
}
}

function _expired() internal view {
VaultStorage storage vs = LibDiamond.vaultStorage();
if (block.timestamp - vs.lastPing <= 24 weeks) revert NotExpired();
}

function _notExpired() internal view {
VaultStorage storage vs = LibDiamond.vaultStorage();
if (block.timestamp - vs.lastPing > 24 weeks) revert HasExpired();
}

function _notClaimed(address _inheritor) internal view {
VaultStorage storage vs = LibDiamond.vaultStorage();
if (vs.claimed[_inheritor]) revert Claimed();
}
}

function _expired() internal view {
VaultStorage storage vs = LibDiamond.vaultStorage();
if (block.timestamp - vs.lastPing <= 24 weeks) revert NotExpired();
}

function _notExpired() internal view {
VaultStorage storage vs = LibDiamond.vaultStorage();
if (block.timestamp - vs.lastPing > 24 weeks) revert HasExpired();
}

function _notClaimed(address _inheritor) internal view {
VaultStorage storage vs = LibDiamond.vaultStorage();
if (vs.claimed[_inheritor]) revert Claimed();
}
}