Skip to content

Commit

Permalink
feat: add custom withdrwaw
Browse files Browse the repository at this point in the history
  • Loading branch information
0xChin committed Nov 1, 2024
1 parent c9f1519 commit 95ccc81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/contracts/Grateful.sol
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,19 @@ contract Grateful is IGrateful, Ownable2Step {
vault.redeem(_shares, msg.sender, address(this));
}

function withdraw(address _token, uint256 _assets) external onlyWhenTokenWhitelisted(_token) {
AaveV3ERC4626 vault = vaults[_token];
if (address(vault) == address(0)) {
revert Grateful_VaultNotSet();
}
uint256 _shares = shares[msg.sender][_token];
if (vault.convertToShares(_assets) < _shares) {
revert Grateful_WithdrawExceedsShares();
}
shares[msg.sender][_token] = 0;
vault.withdraw(_assets, msg.sender, address(this));
}

/// @inheritdoc IGrateful
function switchYieldingFunds() external {
yieldingFunds[msg.sender] = !yieldingFunds[msg.sender];
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/IGrateful.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ interface IGrateful {
/// @notice Thrown when the payment id has been used.
error Grateful_PaymentIdAlreadyUsed();

/// @notice Thrown when the user tries to withdraw more than he has
error Grateful_WithdrawExceedsShares();

/*///////////////////////////////////////////////////////////////
VARIABLES
//////////////////////////////////////////////////////////////*/
Expand Down

0 comments on commit 95ccc81

Please sign in to comment.