Skip to content
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

fix: no-revert-on-transfer tokens can be drained + NFTs can get stuck if the recipient contract cannot handle them #4

Merged
merged 4 commits into from
May 17, 2022
Merged
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
8 changes: 4 additions & 4 deletions src/Cally.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import "./CallyNft.sol";
/// @title Cally - https://cally.finance
/// @author out.eth
/// @notice NFT & ERC20 covered call vaults
contract Cally is CallyNft, ReentrancyGuard, Ownable {
contract Cally is CallyNft, ReentrancyGuard, Ownable, ERC721TokenReceiver {
using SafeTransferLib for ERC20;
using SafeTransferLib for address payable;

Expand Down Expand Up @@ -223,7 +223,7 @@ contract Cally is CallyNft, ReentrancyGuard, Ownable {

// transfer the NFTs or ERC20s to the contract
vault.tokenType == TokenType.ERC721
? ERC721(vault.token).transferFrom(msg.sender, address(this), vault.tokenIdOrAmount)
? ERC721(vault.token).safeTransferFrom(msg.sender, address(this), vault.tokenIdOrAmount)
: ERC20(vault.token).safeTransferFrom(msg.sender, address(this), vault.tokenIdOrAmount);
}

Expand Down Expand Up @@ -319,7 +319,7 @@ contract Cally is CallyNft, ReentrancyGuard, Ownable {

// transfer the NFTs or ERC20s to the exerciser
vault.tokenType == TokenType.ERC721
? ERC721(vault.token).transferFrom(address(this), msg.sender, vault.tokenIdOrAmount)
? ERC721(vault.token).safeTransferFrom(address(this), msg.sender, vault.tokenIdOrAmount)
: ERC20(vault.token).safeTransfer(msg.sender, vault.tokenIdOrAmount);
}

Expand Down Expand Up @@ -368,7 +368,7 @@ contract Cally is CallyNft, ReentrancyGuard, Ownable {

// transfer the NFTs or ERC20s back to the owner
vault.tokenType == TokenType.ERC721
? ERC721(vault.token).transferFrom(address(this), msg.sender, vault.tokenIdOrAmount)
? ERC721(vault.token).safeTransferFrom(address(this), msg.sender, vault.tokenIdOrAmount)
: ERC20(vault.token).safeTransfer(msg.sender, vault.tokenIdOrAmount);
}

Expand Down
1 change: 1 addition & 0 deletions test/mocks/MockERC721.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;

import "solmate/tokens/ERC721.sol";

contract MockERC721 is ERC721 {
Expand Down
3 changes: 2 additions & 1 deletion test/shared/Fixture.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
pragma solidity ^0.8.0;

import "forge-std/Test.sol";
import "solmate/tokens/ERC721.sol";

import "../mocks/MockWeth.sol";
import "../mocks/MockERC721.sol";
import "../mocks/MockERC20.sol";

import "src/Cally.sol";

abstract contract Fixture is Test {
abstract contract Fixture is Test, ERC721TokenReceiver {
Cally internal c;
MockERC721 internal bayc;
MockERC20 internal link;
Expand Down
5 changes: 5 additions & 0 deletions test/units/BuyOption.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -250,5 +250,10 @@ contract TestBuyOption is Fixture {
// assert
assertEq(c.ownerOf(optionId), address(this), "Should have given option to buyer");
assertEq(c.ethBalance(babe), premium, "Should have credited premium ETH to babe");
assertEq(
c.vaults(vaultId).currentExpiration,
block.timestamp + uint32(durationDays) * 1 days,
"Should have updated the curent expiration"
);
}
}