Skip to content

Commit

Permalink
Merge pull request #114 from OpenQDev/fix-review-nfts
Browse files Browse the repository at this point in the history
Fix review - removes all NFT related code
  • Loading branch information
FlacoJones authored Feb 28, 2023
2 parents 26c11e0 + 64b9284 commit dc6fc17
Show file tree
Hide file tree
Showing 19 changed files with 10 additions and 741 deletions.
36 changes: 0 additions & 36 deletions contracts/Bounty/Implementations/AtomicBountyV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ contract AtomicBountyV1 is AtomicBountyStorageV1 {
issuer = _issuer;
organization = _organization;
bountyCreatedTime = block.timestamp;
nftDepositLimit = 5;

(
bool _hasFundingGoal,
Expand Down Expand Up @@ -116,41 +115,6 @@ contract AtomicBountyV1 is AtomicBountyStorageV1 {
closerData = _closerData;
}

/// @notice Receives an NFT for this contract
/// @param _sender Sender of the NFT
/// @param _tokenAddress NFT token address
/// @param _tokenId NFT token id
/// @param _expiration How long before this deposit becomes refundable
/// @return bytes32 the deposit id
function receiveNft(
address _sender,
address _tokenAddress,
uint256 _tokenId,
uint256 _expiration,
bytes calldata
) external onlyDepositManager nonReentrant returns (bytes32) {
require(
nftDeposits.length < nftDepositLimit,
Errors.NFT_DEPOSIT_LIMIT_REACHED
);
require(_expiration > 0, Errors.EXPIRATION_NOT_GREATER_THAN_ZERO);
_receiveNft(_tokenAddress, _sender, _tokenId);

bytes32 depositId = _generateDepositId();

funder[depositId] = _sender;
tokenAddress[depositId] = _tokenAddress;
depositTime[depositId] = block.timestamp;
tokenId[depositId] = _tokenId;
expiration[depositId] = _expiration;
isNFT[depositId] = true;

deposits.push(depositId);
nftDeposits.push(depositId);

return depositId;
}

/// @notice Whether or not invoice has been completed
/// @param _data ABI encoded data
/// @dev see IBountyCore.setInvoiceComplete.(_data) for _data ABI encoding schema
Expand Down
63 changes: 4 additions & 59 deletions contracts/Bounty/Implementations/BountyCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,17 @@ abstract contract BountyCore is BountyStorageCore {
volume[depositId] = volumeReceived;
depositTime[depositId] = block.timestamp;
expiration[depositId] = _expiration;
isNFT[depositId] = false;

deposits.push(depositId);
tokenAddresses.add(_tokenAddress);

return (depositId, volumeReceived);
}

/// @notice Transfers volume of deposit or NFT of deposit from bounty to funder
/// @notice Transfers volume of deposit from bounty to funder
/// @param _depositId The deposit to refund
/// @param _funder The initial funder of the deposit
/// @param _volume The volume to be refunded (only relevant if deposit is not an NFT, otherwise is zero)
/// @param _volume The volume to be refunded
function refundDeposit(
bytes32 _depositId,
address _funder,
Expand All @@ -77,12 +76,6 @@ abstract contract BountyCore is BountyStorageCore {

if (tokenAddress[_depositId] == address(0)) {
_transferProtocolToken(funder[_depositId], _volume);
} else if (isNFT[_depositId]) {
_transferNft(
tokenAddress[_depositId],
funder[_depositId],
tokenId[_depositId]
);
} else {
_transferERC20(
tokenAddress[_depositId],
Expand Down Expand Up @@ -119,22 +112,6 @@ abstract contract BountyCore is BountyStorageCore {
return expiration[_depositId];
}

/// @notice Transfers NFT from bounty address to _payoutAddress
/// @param _payoutAddress The destination address for the NFT
/// @param _depositId The payout address of the bounty
function claimNft(address _payoutAddress, bytes32 _depositId)
external
virtual
onlyClaimManager
nonReentrant
{
_transferNft(
tokenAddress[_depositId],
_payoutAddress,
tokenId[_depositId]
);
}

/// @notice Sets the funding goal
/// @param _fundingToken Token address for funding goal
/// @param _fundingGoal Token volume for funding goal
Expand Down Expand Up @@ -237,32 +214,6 @@ abstract contract BountyCore is BountyStorageCore {
payable(_payoutAddress).sendValue(_volume);
}

/// @notice Receives NFT of _tokenId on _tokenAddress from _funder to bounty address
/// @param _tokenAddress The ERC721 token address
/// @param _sender The sender of the NFT
/// @param _tokenId The tokenId
function _receiveNft(
address _tokenAddress,
address _sender,
uint256 _tokenId
) internal virtual {
IERC721Upgradeable nft = IERC721Upgradeable(_tokenAddress);
nft.safeTransferFrom(_sender, address(this), _tokenId);
}

/// @notice Transfers NFT of _tokenId on _tokenAddress from bounty address to _payoutAddress
/// @param _tokenAddress The ERC721 token address
/// @param _payoutAddress The sender of the NFT
/// @param _tokenId The tokenId
function _transferNft(
address _tokenAddress,
address _payoutAddress,
uint256 _tokenId
) internal virtual {
IERC721Upgradeable nft = IERC721Upgradeable(_tokenAddress);
nft.safeTransferFrom(address(this), _payoutAddress, _tokenId);
}

/// @notice Generates a unique deposit ID from bountyId and the current length of deposits
function _generateDepositId() internal view virtual returns (bytes32) {
return keccak256(abi.encode(bountyId, deposits.length));
Expand Down Expand Up @@ -298,18 +249,12 @@ abstract contract BountyCore is BountyStorageCore {
return token.balanceOf(address(this));
}

/// @notice Returns an array of all deposits (ERC20, protocol token, and NFT) for this bounty
/// @return deposits The array of deposits including ERC20, protocol token, and NFT
/// @notice Returns an array of all deposits for this bounty
/// @return deposits The array of deposits including ERC20 and protocol token
function getDeposits() external view virtual returns (bytes32[] memory) {
return deposits;
}

/// @notice Returns an array of ONLY NFT deposits for this bounty
/// @return nftDeposits The array of NFT deposits
function getNftDeposits() external view virtual returns (bytes32[] memory) {
return nftDeposits;
}

/// @notice Returns an array of all ERC20 token addresses which have funded this bounty
/// @return tokenAddresses An array of all ERC20 token addresses which have funded this bounty
function getTokenAddresses()
Expand Down
39 changes: 0 additions & 39 deletions contracts/Bounty/Implementations/TieredBountyCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,6 @@ import '../Storage/TieredBountyStorageCore.sol';
/// @notice Shared methods common to all tiered bounty types (tier meaning multiple payout levels, e.g. 1st, 2nd, 3rd)
/// @dev TieredBountyCore -> TieredBountyStorageCore -> BountyCore -> BountyStorageCore -> Core Dependencies (OZ + Custom)
abstract contract TieredBountyCore is TieredBountyStorageCore {
/// @notice Receives an NFT for this contract
/// @param _sender Sender of the NFT
/// @param _tokenAddress NFT token address
/// @param _tokenId NFT token id
/// @param _expiration How long before this deposit becomes refundable
/// @param _data ABI encoded data (unused in this case)
/// @return bytes32 the deposit id
function receiveNft(
address _sender,
address _tokenAddress,
uint256 _tokenId,
uint256 _expiration,
bytes calldata _data
) external override onlyDepositManager nonReentrant returns (bytes32) {
require(
nftDeposits.length < nftDepositLimit,
Errors.NFT_DEPOSIT_LIMIT_REACHED
);
require(_expiration > 0, Errors.EXPIRATION_NOT_GREATER_THAN_ZERO);
_receiveNft(_tokenAddress, _sender, _tokenId);

bytes32 depositId = _generateDepositId();

funder[depositId] = _sender;
tokenAddress[depositId] = _tokenAddress;
depositTime[depositId] = block.timestamp;
tokenId[depositId] = _tokenId;
expiration[depositId] = _expiration;
isNFT[depositId] = true;

uint256 _tier = abi.decode(_data, (uint256));
tier[depositId] = _tier;

deposits.push(depositId);
nftDeposits.push(depositId);

return depositId;
}

/// @notice Sets tierClaimed to true for the given tier
/// @param _tier The tier being claimed
function setTierClaimed(uint256 _tier) external onlyClaimManager {
Expand Down
16 changes: 3 additions & 13 deletions contracts/Bounty/Implementations/TieredFixedBountyV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract TieredFixedBountyV1 is TieredFixedBountyStorageV1 {
/// @param _claimManager The Claim Manager proxy address
/// @param _depositManager The Deposit Manager proxy address
/// @param _operation The ABI encoded data determining the type of bounty being initialized and associated data
/// @dev see IBountyCore.initialize.(_operation) for _operation ABI encoding schema for TIERED FIXED
/// @dev see IBountyCore.initialize.(_operation) for _operation ABI encoding schema for TIERED FIXED
function initialize(
string memory _bountyId,
address _issuer,
Expand All @@ -46,7 +46,6 @@ contract TieredFixedBountyV1 is TieredFixedBountyStorageV1 {
issuer = _issuer;
organization = _organization;
bountyCreatedTime = block.timestamp;
nftDepositLimit = 5;

(
uint256[] memory _payoutSchedule,
Expand All @@ -59,21 +58,12 @@ contract TieredFixedBountyV1 is TieredFixedBountyStorageV1 {

) = abi.decode(
_operation.data,
(
uint256[],
address,
bool,
bool,
bool,
string,
string,
string
)
(uint256[], address, bool, bool, bool, string, string, string)
);

bountyType = OpenQDefinitions.TIERED_FIXED;
payoutSchedule = _payoutSchedule;
payoutTokenAddress = _payoutTokenAddress;
payoutTokenAddress = _payoutTokenAddress;
invoiceRequired = _invoiceRequired;
kycRequired = _kycRequired;
supportingDocumentsRequired = _supportingDocumentsRequired;
Expand Down
37 changes: 2 additions & 35 deletions contracts/Bounty/Interfaces/IBountyCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,10 @@ interface IBountyCore {
uint256 _expiration
) external payable returns (bytes32, uint256);

/// @notice Receives an NFT for this contract
/// @param _sender Sender of the NFT
/// @param _tokenAddress NFT token address
/// @param _tokenId NFT token id
/// @param _expiration How long before this deposit becomes refundable
/// @param _data ABI encoded data (unused in this case)
/// @return bytes32 the deposit id
/// @dev _data (TIERED): (uint256):(tier)
/// @dev _data (ATOMIC): empty bytes array
/// @dev _data (ONGOING): empty bytes array
function receiveNft(
address _sender,
address _tokenAddress,
uint256 _tokenId,
uint256 _expiration,
bytes calldata _data
) external returns (bytes32);

/// @notice Transfers volume of deposit or NFT of deposit from bounty to funder
/// @notice Transfers volume of deposit from bounty to funder
/// @param _depositId The deposit to refund
/// @param _funder The initial funder of the deposit
/// @param _volume The volume to be refunded (only relevant if deposit is not an NFT, otherwise is zero)
/// @param _volume The volume to be refunded
function refundDeposit(
bytes32 _depositId,
address _funder,
Expand All @@ -89,11 +71,6 @@ interface IBountyCore {
address _funder
) external returns (uint256);

/// @notice Transfers NFT from bounty address to _payoutAddress
/// @param _payoutAddress The destination address for the NFT
/// @param _depositId The payout address of the bounty
function claimNft(address _payoutAddress, bytes32 _depositId) external;

/// @notice Sets the funding goal
/// @param _fundingToken Token address for funding goal
/// @param _fundingGoal Token volume for funding goal
Expand Down Expand Up @@ -149,10 +126,6 @@ interface IBountyCore {
/// @return tokenAddresses An array of all ERC20 token addresses which have funded this bounty
function getTokenAddresses() external view returns (address[] memory);

/// @notice Returns an array of ONLY NFT deposits for this bounty
/// @return nftDeposits The array of NFT deposits
function getNftDeposits() external view returns (bytes32[] memory);

/// @notice Returns the amount of locked tokens (of a specific token) on a bounty address, only available for claims but not for refunds
/// @param _depositId The depositId that determines which token is being looked at
/// @return uint256
Expand All @@ -177,8 +150,6 @@ interface IBountyCore {

function status() external view returns (uint256);

function nftDepositLimit() external view returns (uint256);

function funder(bytes32) external view returns (address);

function tokenAddress(bytes32) external view returns (address);
Expand All @@ -195,12 +166,8 @@ interface IBountyCore {

function expiration(bytes32) external view returns (uint256);

function isNFT(bytes32) external view returns (bool);

function deposits(uint256) external view returns (bytes32);

function nftDeposits(uint256) external view returns (bytes32);

function closerData() external view returns (bytes memory);

function bountyType() external view returns (uint256);
Expand Down
6 changes: 0 additions & 6 deletions contracts/Bounty/Storage/BountyStorageCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
pragma solidity 0.8.17;

import '@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol';
import '@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol';
import '@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol';
import '@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/token/ERC721/utils/ERC721HolderUpgradeable.sol';

import '../../OnlyOpenQ/OnlyOpenQ.sol';
import '../../ClaimManager/ClaimManagerOwnable.sol';
Expand All @@ -24,7 +22,6 @@ import '../Interfaces/IBountyCore.sol';
abstract contract BountyStorageCore is
IBountyCore,
ReentrancyGuardUpgradeable,
ERC721HolderUpgradeable,
OnlyOpenQ,
ClaimManagerOwnable,
DepositManagerOwnable
Expand All @@ -37,7 +34,6 @@ abstract contract BountyStorageCore is
string public organization;
address public closer;
uint256 public status;
uint256 public nftDepositLimit;

/// @notice Deconstructed deposit struct
mapping(bytes32 => address) public funder;
Expand All @@ -48,11 +44,9 @@ abstract contract BountyStorageCore is
mapping(bytes32 => address) public payoutAddress;
mapping(bytes32 => uint256) public tokenId;
mapping(bytes32 => uint256) public expiration;
mapping(bytes32 => bool) public isNFT;

/// @notice Array of depositIds
bytes32[] public deposits;
bytes32[] public nftDeposits;

/// @notice Set of unique token address
EnumerableSetUpgradeable.AddressSet internal tokenAddresses;
Expand Down
Loading

0 comments on commit dc6fc17

Please sign in to comment.