Skip to content

Commit

Permalink
ON-479: Remove 1155 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed Sep 27, 2023
1 parent 39c3f3f commit 82821ac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 57 deletions.
28 changes: 4 additions & 24 deletions contracts/OriumMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
pragma solidity 0.8.9;

import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import { IERC1155 } from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IRolesRegistry } from "./interfaces/IRolesRegistry.sol";
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import { EIP712Upgradeable } from "@openzeppelin/contracts-upgradeable/utils/cryptography/draft-EIP712Upgradeable.sol";
import { ERC165Checker } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
import { ECDSAUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol";

/**
* @title Orium Marketplace - Marketplace for renting NFTs
Expand Down Expand Up @@ -142,19 +139,10 @@ contract OriumMarketplace is Initializable, OwnableUpgradeable, PausableUpgradea
* @param _tokenId The id of the token.
*/
modifier onlyTokenOwner(address _tokenAddress, uint256 _tokenId) {
if (isERC1155(_tokenAddress)) {
require(
IERC1155(_tokenAddress).balanceOf(msg.sender, _tokenId) > 0,
"OriumMarketplace: only token owner can call this function"
);
} else if (isERC721(_tokenAddress)) {
require(
msg.sender == IERC721(_tokenAddress).ownerOf(_tokenId),
"OriumMarketplace: only token owner can call this function"
);
} else {
revert("OriumMarketplace: token address is not ERC1155 or ERC721");
}
require(
msg.sender == IERC721(_tokenAddress).ownerOf(_tokenId),
"OriumMarketplace: only token owner can call this function"
);
_;
}

Expand Down Expand Up @@ -382,14 +370,6 @@ contract OriumMarketplace is Initializable, OwnableUpgradeable, PausableUpgradea
);
}

function isERC1155(address _tokenAddress) public view returns (bool) {
return ERC165Checker.supportsInterface(_tokenAddress, type(IERC1155).interfaceId);
}

function isERC721(address _tokenAddress) public view returns (bool) {
return ERC165Checker.supportsInterface(_tokenAddress, type(IERC721).interfaceId);
}

/** ============================ Core Functions ================================== **/

/** ######### Setters ########### **/
Expand Down
28 changes: 1 addition & 27 deletions test/OriumMarketplace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ describe('OriumMarketplace', () => {
let marketplace: Contract
let mockERC721: Contract
let mockERC20: Contract
let mockERC1155: Contract

// We are disabling this rule because hardhat uses first account as deployer by default, and we are separating deployer and operator
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -41,7 +40,7 @@ describe('OriumMarketplace', () => {
beforeEach(async () => {
// we are disabling this rule so ; may not be added automatically by prettier at the beginning of the line
// prettier-ignore
[marketplace, mockERC721, mockERC20, mockERC1155] = await loadFixture(deployMarketplaceContracts)
[marketplace, mockERC721, mockERC20] = await loadFixture(deployMarketplaceContracts)
})

describe('Main Functions', async () => {
Expand Down Expand Up @@ -82,25 +81,6 @@ describe('OriumMarketplace', () => {
rentalOffer.rolesData,
)
})
it('Should create a rental offer for ERC1155', async () => {
await mockERC1155.mint(lender.address, tokenId, 1, [])
rentalOffer.tokenAddress = mockERC1155.address
rentalOffer.tokenId = tokenId
await expect(marketplace.connect(lender).createRentalOffer(rentalOffer))
.to.emit(marketplace, 'RentalOfferCreated')
.withArgs(
rentalOffer.nonce,
rentalOffer.lender,
rentalOffer.borrower,
rentalOffer.tokenAddress,
rentalOffer.tokenId,
rentalOffer.feeTokenAddress,
rentalOffer.feeAmountPerSecond,
rentalOffer.deadline,
rentalOffer.roles,
rentalOffer.rolesData,
)
})
it('Should NOT create a rental offer if caller is not the lender', async () => {
await expect(marketplace.connect(notOperator).createRentalOffer(rentalOffer)).to.be.revertedWith(
'OriumMarketplace: only token owner can call this function',
Expand Down Expand Up @@ -137,12 +117,6 @@ describe('OriumMarketplace', () => {
'OriumMarketplace: offer already created',
)
})
it('Should NOT create a rental offer if NFT is neither ERC721 nor ERC1155', async () => {
rentalOffer.tokenAddress = ethers.constants.AddressZero
await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith(
'OriumMarketplace: token address is not ERC1155 or ERC721',
)
})
})
})
describe('Core Functions', async () => {
Expand Down
8 changes: 2 additions & 6 deletions test/fixtures/OriumMarketplaceFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Contract } from 'ethers'
/**
* @dev deployer and operator needs to be the first two accounts in the hardhat ethers.getSigners()
* list respectively. This should be considered to use this fixture in tests
* @returns [marketplace, mockERC721, mockERC20, mockERC1155]
* @returns [marketplace, mockERC721, mockERC20]
*/
export async function deployMarketplaceContracts() {
const [, operator] = await ethers.getSigners()
Expand All @@ -27,9 +27,5 @@ export async function deployMarketplaceContracts() {
const mockERC20 = await MockERC20Factory.deploy()
await mockERC20.deployed()

const MockERC1155Factory = await ethers.getContractFactory('MockERC1155')
const mockERC1155 = await MockERC1155Factory.deploy()
await mockERC1155.deployed()

return [marketplace, mockERC721, mockERC20, mockERC1155] as Contract[]
return [marketplace, mockERC721, mockERC20] as Contract[]
}

0 comments on commit 82821ac

Please sign in to comment.