-
Notifications
You must be signed in to change notification settings - Fork 7
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
Vault withdrawn untracked #59
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ | |
error CommunityVault_IndexOutOfBounds(); | ||
error CommunityVault_ERC721TokenAlreadyDeposited(); | ||
error CommunityVault_ERC721TokenNotDeposited(); | ||
error CommunityVault_AmountExceedsUntrackedBalanceERC20(); | ||
error CommunityVault_CannotWithdrawTrackedERC721(); | ||
|
||
mapping(address => uint256) public erc20TokenBalances; | ||
mapping(address => EnumerableSet.UintSet) private erc721TokenIds; | ||
|
@@ -169,6 +171,53 @@ | |
} | ||
} | ||
|
||
/// @notice Withdraws a specified amount of an untracked ERC20 token from the community vault. | ||
/// @dev This function allows the community owner or token master to withdraw untracked ERC20 tokens. It checks if | ||
/// the requested amount does not exceed the untracked balance. If it does, the transaction is reverted. | ||
/// @param tokenAddress The address of the ERC20 token to withdraw. | ||
/// @param amount The amount of the ERC20 token to withdraw. | ||
/// @param to The address to which the ERC20 tokens will be transferred. | ||
function withdrawUntrackedERC20( | ||
address tokenAddress, | ||
uint256 amount, | ||
address to | ||
) | ||
public | ||
onlyCommunityOwnerOrTokenMaster | ||
{ | ||
uint256 contractBalance = IERC20(tokenAddress).balanceOf(address(this)); | ||
uint256 untrackedBalance = contractBalance - erc20TokenBalances[tokenAddress]; | ||
|
||
if (amount > untrackedBalance) { | ||
revert CommunityVault_AmountExceedsUntrackedBalanceERC20(); | ||
} | ||
|
||
IERC20(tokenAddress).safeTransfer(to, amount); | ||
} | ||
|
||
/// @notice Withdraws specified ERC721 tokens that are not tracked by the community vault. | ||
/// @dev This function allows the community owner or token master to withdraw untracked ERC721 tokens by token IDs. | ||
/// It checks each token ID against tracked tokens and if any are found, the transaction is reverted. | ||
/// @param tokenAddress The address of the ERC721 token to withdraw. | ||
/// @param tokenIds An array of token IDs of the ERC721 tokens to withdraw. | ||
/// @param to The address to which the ERC721 tokens will be transferred. | ||
function withdrawUntrackedERC721( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
address tokenAddress, | ||
uint256[] memory tokenIds, | ||
address to | ||
) | ||
public | ||
onlyCommunityOwnerOrTokenMaster | ||
{ | ||
for (uint256 i = 0; i < tokenIds.length; i++) { | ||
if (erc721TokenIds[tokenAddress].contains(tokenIds[i])) { | ||
revert CommunityVault_CannotWithdrawTrackedERC721(); | ||
} | ||
|
||
IERC721(tokenAddress).safeTransferFrom(address(this), to, tokenIds[i]); | ||
} | ||
} | ||
|
||
/** | ||
* @dev Handles the receipt of an ERC721 token. | ||
* @return bytes4 Returns `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get some natspec pretty please?