Skip to content
Open
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
13 changes: 11 additions & 2 deletions contracts/Aavegotchi/InitDiamond.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ contract InitDiamond {
address rarityFarming;
string name;
string symbol;
address wghstContract;
address ghstContract;
bytes32 chainlinkKeyHash;
uint64 subscriptionId;
address vrfCoordinator;
}

function init(Args memory _args) external {
Expand All @@ -42,8 +45,14 @@ contract InitDiamond {
ds.supportedInterfaces[type(IERC173).interfaceId] = true;
ds.supportedInterfaces[(type(IERC721).interfaceId)] = true;

s.ghstContract = _args.ghstContract;
s.keyHash = _args.chainlinkKeyHash;
s.subscriptionId = _args.subscriptionId;
s.vrfCoordinator = _args.vrfCoordinator;

s.listingFeeInWei = 1e17;

s.name = _args.name;
s.symbol = _args.symbol;
s.wghstContract = _args.wghstContract;
}
}
6 changes: 6 additions & 0 deletions contracts/Aavegotchi/facets/AavegotchiGameFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ contract AavegotchiGameFacet is Modifiers {
portalAavegotchiTraits_ = LibAavegotchi.portalAavegotchiTraits(_tokenId);
}

///@notice Query the $GHST token address
///@return contract_ the deployed address of the $GHST token contract
function ghstAddress() external view returns (address contract_) {
contract_ = s.ghstContract;
}

///@notice Query the numeric traits of an NFT
///@dev Only valid for claimed Aavegotchis
///@param _tokenId The identifier of the NFT to query
Expand Down
12 changes: 6 additions & 6 deletions contracts/Aavegotchi/facets/DAOFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract DAOFacet is Modifiers {
event UpdateItemPrice(uint256 _itemId, uint256 _priceInWei);
event GotchiGeistBridgeUpdate(address _newBridge);
event ItemGeistBridgeUpdate(address _newBridge);
event WGHSTContractUpdate(address _newWGHSTContract);
event GHSTContractUpdate(address _newGHSTContract);
event BaazaarTradingAllowlistUpdate(address _contract, bool _allow);

/***********************************|
Expand Down Expand Up @@ -450,13 +450,13 @@ contract DAOFacet is Modifiers {
emit ItemGeistBridgeUpdate(_newBridge);
}

function setWGHSTContract(address _wghstContract) external onlyDaoOrOwner {
s.wghstContract = _wghstContract;
emit WGHSTContractUpdate(_wghstContract);
function setGHSTContract(address _ghstContract) external onlyDaoOrOwner {
s.ghstContract = _ghstContract;
emit GHSTContractUpdate(_ghstContract);
}

function getWGHSTContract() external view returns (address) {
return s.wghstContract;
function getGHSTContract() external view returns (address) {
return s.ghstContract;
}

function setBaazaarTradingAllowlists(address[] calldata _contracts, bool[] calldata _allows) external onlyDaoOrOwner {
Expand Down
12 changes: 9 additions & 3 deletions contracts/Aavegotchi/facets/ERC1155BuyOrderFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ pragma solidity 0.8.1;

import {LibBuyOrder} from "../libraries/LibBuyOrder.sol";
import {LibERC1155Marketplace} from "../libraries/LibERC1155Marketplace.sol";
import {LibERC20} from "../../shared/libraries/LibERC20.sol";
import {LibERC1155} from "../../shared/libraries/LibERC1155.sol";
import {LibItems} from "../libraries/LibItems.sol";
import {IERC20} from "../../shared/interfaces/IERC20.sol";
import {IERC1155} from "../../shared/interfaces/IERC1155.sol";
import {LibMeta} from "../../shared/libraries/LibMeta.sol";
import {Modifiers, ERC1155BuyOrder} from "../libraries/LibAppStorage.sol";
Expand Down Expand Up @@ -42,15 +44,18 @@ contract ERC1155BuyOrderFacet is Modifiers {
uint256 _priceInWei,
uint256 _quantity,
uint256 _duration
) external payable {
) external {
uint256 cost = _quantity * _priceInWei;
require(cost >= 1e15, "ERC1155BuyOrder: cost should be 0.001 GHST or larger");

address sender = LibMeta.msgSender();
uint256 category = LibSharedMarketplace.getERC1155Category(_erc1155TokenAddress, _erc1155TokenId);
uint256 ghstBalance = IERC20(s.ghstContract).balanceOf(sender);

// Transfer ETH
require(msg.value == cost, "ERC1155BuyOrder:GHST amount mismatch");
// New order
// Transfer GHST
require(ghstBalance >= cost, "ERC1155BuyOrder: Not enough GHST!");
LibERC20.transferFrom(s.ghstContract, sender, address(this), cost);

// Place new buy order
s.nextERC1155BuyOrderId++;
Expand Down Expand Up @@ -133,6 +138,7 @@ contract ERC1155BuyOrderFacet is Modifiers {
BaazaarSplit memory split = LibSharedMarketplace.getBaazaarSplit(cost, new uint256[](0), [10000, 0]);
LibSharedMarketplace.transferSales(
SplitAddresses({
ghstContract: s.ghstContract,
buyer: address(this),
seller: sender,
affiliate: address(0),
Expand Down
37 changes: 29 additions & 8 deletions contracts/Aavegotchi/facets/ERC1155MarketplaceFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.1;

import {Modifiers} from "../libraries/LibAppStorage.sol";
import {LibERC1155Marketplace, ERC1155Listing} from "../libraries/LibERC1155Marketplace.sol";
import {IERC20} from "../../shared/interfaces/IERC20.sol";
import {IERC1155} from "../../shared/interfaces/IERC1155.sol";
import {LibMeta} from "../../shared/libraries/LibMeta.sol";
import {LibItems} from "../libraries/LibItems.sol";
Expand Down Expand Up @@ -40,6 +41,15 @@ contract ERC1155MarketplaceFacet is Modifiers {
///@dev Is sent in tandem with ERC1155ExecutedListing
event ERC1155ExecutedToRecipient(uint256 indexed listingId, address indexed buyer, address indexed recipient);

event ChangedListingFee(uint256 listingFeeInWei);

///@notice Allow the aavegotchi diamond owner or DAO to set the default listing fee
///@param _listingFeeInWei The new listing fee in wei
function setListingFee(uint256 _listingFeeInWei) external onlyDaoOrOwner {
s.listingFeeInWei = _listingFeeInWei;
emit ChangedListingFee(s.listingFeeInWei);
}

struct Category {
address erc1155TokenAddress;
uint256 erc1155TypeId;
Expand Down Expand Up @@ -118,7 +128,7 @@ contract ERC1155MarketplaceFacet is Modifiers {
);

uint256 cost = _quantity * _priceInWei;
require(cost >= 1e18, "ERC1155Marketplace: cost should be 1 GHST or larger");
require(cost >= 1e15, "ERC1155Marketplace: cost should be 0.001 GHST or larger");
require(_principalSplit[0] + _principalSplit[1] == 10000, "ERC1155Marketplace: Sum of principal splits not 10000");
if (_affiliate == address(0)) {
require(_principalSplit[1] == 0, "ERC1155Marketplace: Affiliate split must be 0 for address(0)");
Expand Down Expand Up @@ -161,6 +171,11 @@ contract ERC1155MarketplaceFacet is Modifiers {
listing.quantity = _quantity;
emit LibERC1155Marketplace.UpdateERC1155Listing(listingId, _quantity, listing.priceInWei, block.timestamp);
}

//Burn listing fee
if (s.listingFeeInWei > 0) {
LibSharedMarketplace.burnListingFee(s.listingFeeInWei, LibMeta.msgSender(), s.ghstContract);
}
}

///@notice Allow an ERC1155 owner to cancel his NFT listing through the listingID
Expand All @@ -176,7 +191,7 @@ contract ERC1155MarketplaceFacet is Modifiers {
///@param _listingId The identifier of the listing to execute
///@param _quantity The amount of ERC1155 NFTs execute/buy
///@param _priceInWei the cost price of the ERC1155 NFTs individually
function executeERC1155Listing(uint256 _listingId, uint256 _quantity, uint256 _priceInWei) external payable {
function executeERC1155Listing(uint256 _listingId, uint256 _quantity, uint256 _priceInWei) external {
ERC1155Listing storage listing = s.erc1155Listings[_listingId];
handleExecuteERC1155Listing(_listingId, listing.erc1155TokenAddress, listing.erc1155TypeId, _quantity, _priceInWei, LibMeta.msgSender());
}
Expand All @@ -196,7 +211,7 @@ contract ERC1155MarketplaceFacet is Modifiers {
uint256 _quantity,
uint256 _priceInWei,
address _recipient
) external payable {
) external {
handleExecuteERC1155Listing(_listingId, _contractAddress, _itemId, _quantity, _priceInWei, _recipient);
}

Expand All @@ -216,7 +231,7 @@ contract ERC1155MarketplaceFacet is Modifiers {
}

///@notice execute ERC1155 listings in batch
function batchExecuteERC1155Listing(ExecuteERC1155ListingParams[] calldata listings) external payable {
function batchExecuteERC1155Listing(ExecuteERC1155ListingParams[] calldata listings) external {
require(listings.length <= 10, "ERC1155Marketplace: length should be lower than 10");
for (uint256 i = 0; i < listings.length; i++) {
handleExecuteERC1155Listing(
Expand Down Expand Up @@ -255,10 +270,7 @@ contract ERC1155MarketplaceFacet is Modifiers {
require(_quantity <= listing.quantity, "ERC1155Marketplace: quantity is greater than listing");
listing.quantity -= _quantity;
uint256 cost = _quantity * _priceInWei;

// Transfer ETH from buyer to contract
require(msg.value == cost, "ERC1155Marketplace: GHST amount mismatch");

require(IERC20(s.ghstContract).balanceOf(buyer) >= cost, "ERC1155Marketplace: not enough GHST");
{
BaazaarSplit memory split = LibSharedMarketplace.getBaazaarSplit(
cost,
Expand All @@ -268,6 +280,7 @@ contract ERC1155MarketplaceFacet is Modifiers {

LibSharedMarketplace.transferSales(
SplitAddresses({
ghstContract: s.ghstContract,
buyer: buyer,
seller: seller,
affiliate: listing.affiliate,
Expand Down Expand Up @@ -374,6 +387,9 @@ contract ERC1155MarketplaceFacet is Modifiers {
///@param _priceInWei The price of the item
function updateERC1155ListingPriceAndQuantity(uint256 _listingId, uint256 _quantity, uint256 _priceInWei) external {
LibERC1155Marketplace.updateERC1155ListingPriceAndQuantity(_listingId, _quantity, _priceInWei);
if (s.listingFeeInWei > 0) {
LibSharedMarketplace.burnListingFee(s.listingFeeInWei, LibMeta.msgSender(), s.ghstContract);
}
}

function batchUpdateERC1155ListingPriceAndQuantity(
Expand All @@ -387,5 +403,10 @@ contract ERC1155MarketplaceFacet is Modifiers {
for (uint256 i; i < _listingIds.length; i++) {
LibERC1155Marketplace.updateERC1155ListingPriceAndQuantity(_listingIds[i], _quantities[i], _priceInWeis[i]);
}

if (s.listingFeeInWei > 0) {
uint256 totalFee = s.listingFeeInWei * _listingIds.length;
LibSharedMarketplace.burnListingFee(totalFee, LibMeta.msgSender(), s.ghstContract);
}
}
}
12 changes: 9 additions & 3 deletions contracts/Aavegotchi/facets/ERC721BuyOrderFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pragma solidity 0.8.1;
import {LibAavegotchi} from "../libraries/LibAavegotchi.sol";
import {LibBuyOrder} from "../libraries/LibBuyOrder.sol";
import {LibERC721Marketplace} from "../libraries/LibERC721Marketplace.sol";
import {LibERC20} from "../../shared/libraries/LibERC20.sol";
import {IERC20} from "../../shared/interfaces/IERC20.sol";
import {IERC721} from "../../shared/interfaces/IERC721.sol";
import {LibMeta} from "../../shared/libraries/LibMeta.sol";
import {LibGotchiLending} from "../libraries/LibGotchiLending.sol";
Expand Down Expand Up @@ -105,12 +107,12 @@ contract ERC721BuyOrderFacet is Modifiers {
uint256 _priceInWei,
uint256 _duration,
bool[] calldata _validationOptions // 0: BRS, 1: GHST, 2: skill points
) external payable {
) external {
require(_priceInWei >= 1e18, "ERC721BuyOrder: price should be 1 GHST or larger");

require(msg.value == _priceInWei, "ERC721BuyOrder: GHST amount mismatch!");

address sender = LibMeta.msgSender();
uint256 ghstBalance = IERC20(s.ghstContract).balanceOf(sender);
require(ghstBalance >= _priceInWei, "ERC721BuyOrder: Not enough GHST!");

uint256 category = LibSharedMarketplace.getERC721Category(_erc721TokenAddress, _erc721TokenId);
require(category != LibAavegotchi.STATUS_VRF_PENDING, "ERC721BuyOrder: Cannot buy a portal that is pending VRF");
Expand All @@ -130,6 +132,9 @@ contract ERC721BuyOrderFacet is Modifiers {
}
}

// Transfer GHST
LibERC20.transferFrom(s.ghstContract, sender, address(this), _priceInWei);

// Place new buy order
s.nextERC721BuyOrderId++;
uint256 buyOrderId = s.nextERC721BuyOrderId;
Expand Down Expand Up @@ -220,6 +225,7 @@ contract ERC721BuyOrderFacet is Modifiers {

LibSharedMarketplace.transferSales(
SplitAddresses({
ghstContract: s.ghstContract,
buyer: address(this),
seller: sender,
affiliate: address(0),
Expand Down
21 changes: 18 additions & 3 deletions contracts/Aavegotchi/facets/ERC721MarketplaceFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.1;

import {LibAavegotchi} from "../libraries/LibAavegotchi.sol";
import {IERC721} from "../../shared/interfaces/IERC721.sol";
import {IERC20} from "../../shared/interfaces/IERC20.sol";
import {IERC165} from "../../shared/interfaces/IERC165.sol";
import {IERC2981} from "../../shared/interfaces/IERC2981.sol";
import {IMultiRoyalty} from "../../shared/interfaces/IMultiRoyalty.sol";
Expand Down Expand Up @@ -192,6 +193,11 @@ contract ERC721MarketplaceFacet is Modifiers {
if (_erc721TokenAddress == address(this)) {
s.aavegotchis[_erc721TokenId].locked = true;
}

//Burn listing fee
if (s.listingFeeInWei > 0) {
LibSharedMarketplace.burnListingFee(s.listingFeeInWei, msgSender, s.ghstContract);
}
}

///@notice Allow an ERC721 owner to update list price of his NFT for sale
Expand All @@ -200,6 +206,9 @@ contract ERC721MarketplaceFacet is Modifiers {
///@param _priceInWei The price of the item
function updateERC721ListingPrice(uint256 _listingId, uint256 _priceInWei) external {
LibERC721Marketplace.updateERC721ListingPrice(_listingId, _priceInWei);
if (s.listingFeeInWei > 0) {
LibSharedMarketplace.burnListingFee(s.listingFeeInWei, LibMeta.msgSender(), s.ghstContract);
}
}

function batchUpdateERC721ListingPrice(uint256[] calldata _listingIds, uint256[] calldata _priceInWeis) external {
Expand All @@ -208,6 +217,11 @@ contract ERC721MarketplaceFacet is Modifiers {
for (uint256 i; i < _listingIds.length; i++) {
LibERC721Marketplace.updateERC721ListingPrice(_listingIds[i], _priceInWeis[i]);
}

if (s.listingFeeInWei > 0) {
uint256 totalFee = s.listingFeeInWei * _listingIds.length;
LibSharedMarketplace.burnListingFee(totalFee, LibMeta.msgSender(), s.ghstContract);
}
}

///@notice Allow an ERC721 owner to cancel his NFT listing by providing the NFT contract address and identifier
Expand Down Expand Up @@ -237,7 +251,7 @@ contract ERC721MarketplaceFacet is Modifiers {
uint256 _priceInWei,
uint256 _tokenId,
address _recipient
) external payable {
) external {
handleExecuteERC721Listing(_listingId, _contractAddress, _priceInWei, _tokenId, _recipient);
}

Expand All @@ -255,7 +269,7 @@ contract ERC721MarketplaceFacet is Modifiers {
}

///@notice execute gotchi listings in batch
function batchExecuteERC721Listing(ExecuteERC721ListingParams[] calldata listings) external payable {
function batchExecuteERC721Listing(ExecuteERC721ListingParams[] calldata listings) external {
require(listings.length <= 10, "ERC721Marketplace: length should be lower than 10");
for (uint256 i = 0; i < listings.length; i++) {
handleExecuteERC721Listing(
Expand All @@ -276,7 +290,6 @@ contract ERC721MarketplaceFacet is Modifiers {
address _recipient
) internal {
ERC721Listing storage listing = s.erc721Listings[_listingId];
require(msg.value == _priceInWei, "ERC721MarketplaceFacet: GHST amount mismatch");
require(listing.timePurchased == 0, "ERC721Marketplace: listing already sold");
require(listing.cancelled == false, "ERC721Marketplace: listing cancelled");
require(listing.timeCreated != 0, "ERC721Marketplace: listing not found");
Expand All @@ -289,6 +302,7 @@ contract ERC721MarketplaceFacet is Modifiers {
if (listing.whitelistId > 0) {
require(s.isWhitelisted[listing.whitelistId][buyer] > 0, "ERC721Marketplace: Not whitelisted address");
}
require(IERC20(s.ghstContract).balanceOf(buyer) >= _priceInWei, "ERC721Marketplace: Not enough GHST");

listing.timePurchased = block.timestamp;
LibERC721Marketplace.removeERC721ListingItem(_listingId, seller);
Expand All @@ -315,6 +329,7 @@ contract ERC721MarketplaceFacet is Modifiers {

LibSharedMarketplace.transferSales(
SplitAddresses({
ghstContract: s.ghstContract,
buyer: buyer,
seller: seller,
affiliate: listing.affiliate,
Expand Down
2 changes: 1 addition & 1 deletion contracts/Aavegotchi/facets/GotchiLendingFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ contract GotchiLendingFacet is Modifiers {
uint96 _initialCost,
uint32 _period,
uint8[3] calldata _revenueSplit
) external payable {
) external {
address sender = LibMeta.msgSender();
//LibGotchiLending.addBorrowerTokenId(sender, _erc721TokenId); // This functions as a check for whether the sender already has a borrow after the upgrade
LibGotchiLending._agreeGotchiLending(sender, _listingId, _erc721TokenId, _initialCost, _period, _revenueSplit);
Expand Down
Loading