Verified contractExactMIT
Diamond
Address0x2ea507b9eda35ad1319bef78f04fbc9b8f15f8c1
- Balance
0 ETH
- Transactions
114
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- paris
- Via IR
- yes
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 24,972,440
- Creation transaction
- 0xeb2451b1eb…0d0f6b64ae
39 files
- contracts/Diamond.solmain2.19 KB
- contracts/facets/DiamondCutFacet.sol2.48 KB
- contracts/facets/DiamondInitFacet.sol4.19 KB
- contracts/facets/DiamondLoupeFacet.sol7.4 KB
- contracts/facets/GBMAdminFacet.sol3.51 KB
- contracts/facets/GBMAuctionRegistrationFacet.sol21.11 KB
- contracts/facets/GBMBiddingFacet.sol12.22 KB
- contracts/facets/GBMCurrencyFacet.sol4.28 KB
- contracts/facets/GBMEscrowFacet.sol3.83 KB
- contracts/facets/GBMGettersFacet.sol12.88 KB
- contracts/facets/GBMMarketPlaceAdminFacet.sol7.83 KB
- contracts/facets/GBMRegisterMarketplaceFacet.sol6.33 KB
- contracts/facets/GBMSettleAuctionFacet.sol14.22 KB
- contracts/facets/OwnershipFacet.sol581 B
- contracts/interfaces/IDiamondCut.sol1.29 KB
- contracts/interfaces/IDiamondLoupe.sol1.67 KB
- contracts/interfaces/IERC1155.sol7.82 KB
- contracts/interfaces/IERC1155TokenReceiver.sol2.87 KB
- contracts/interfaces/IERC165.sol643 B
- contracts/interfaces/IERC173.sol799 B
- contracts/interfaces/IERC20.sol775 B
- contracts/interfaces/IERC2981.sol1.05 KB
- contracts/interfaces/IERC721.sol5.9 KB
- contracts/interfaces/IERC721TokenReceiver.sol1.16 KB
- contracts/interfaces/IGBM.sol1.38 KB
- contracts/interfaces/facets/IGBMAdminFacet.sol1.04 KB
- contracts/interfaces/facets/IGBMAuctionRegistrationFacet.sol1.31 KB
- contracts/interfaces/facets/IGBMBiddingFacet.sol715 B
- contracts/interfaces/facets/IGBMCurrencyFacet.sol2.16 KB
- contracts/interfaces/facets/IGBMEventsFacet.sol12.19 KB
- contracts/interfaces/facets/IGBMGettersFacet.sol6.47 KB
- contracts/interfaces/facets/IGBMMarketPlaceAdminFacet.sol1.35 KB
- contracts/interfaces/facets/IGBMRegisterMarketplaceFacet.sol463 B
- contracts/interfaces/facets/IGBMSettleAuctionFacet.sol440 B
- contracts/libraries/GBM_Core.sol10.18 KB
- contracts/libraries/LibDiamond.sol11.63 KB
- contracts/test/ERC1155Generic.sol14.43 KB
- contracts/test/ERC20Generic.sol5.86 KB
- contracts/test/ERC721GenericMintFor.sol15.01 KB
contracts/Diamond.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/******************************************************************************\
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
*
* Implementation of a diamond.
/******************************************************************************/
import { LibDiamond } from "./libraries/LibDiamond.sol";
import { IDiamondCut } from "./interfaces/IDiamondCut.sol";
contract Diamond {
constructor(address _contractOwner, address _diamondCutFacet) payable {
LibDiamond.setContractOwner(_contractOwner);
// Add the diamondCut external function from the diamondCutFacet
IDiamondCut.FacetCut[] memory cut = new IDiamondCut.FacetCut[](1);
bytes4[] memory functionSelectors = new bytes4[](1);
functionSelectors[0] = IDiamondCut.diamondCut.selector;
cut[0] = IDiamondCut.FacetCut({
facetAddress: _diamondCutFacet,
action: IDiamondCut.FacetCutAction.Add,
functionSelectors: functionSelectors
});
LibDiamond.diamondCut(cut, address(0), "");
}
// Find facet for function that is called and execute the
// function if a facet is found and return any value.
fallback() external payable {
LibDiamond.DiamondStorage storage ds;
bytes32 position = LibDiamond.DIAMOND_STORAGE_POSITION;
assembly {
ds.slot := position
}
address facet = address(bytes20(ds.facets[msg.sig]));
require(facet != address(0), "Diamond: Function does not exist");
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), facet, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
receive() external payable {}
}
contracts/facets/DiamondCutFacet.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/******************************************************************************\
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
/******************************************************************************/
import { IDiamondCut } from "../interfaces/IDiamondCut.sol";
import { LibDiamond } from "../libraries/LibDiamond.sol";
contract DiamondCutFacet is IDiamondCut {
/// @notice Add/replace/remove any number of functions and optionally execute
/// a function with delegatecall
/// @param _diamondCut Contains the facet addresses and function selectors
/// @param _init The address of the contract or facet to execute _calldata
/// @param _calldata A function call, including function selector and arguments
/// _calldata is executed with delegatecall on _init
function diamondCut(
FacetCut[] calldata _diamondCut,
address _init,
bytes calldata _calldata
) external override {
LibDiamond.enforceIsContractOwner();
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
uint256 originalSelectorCount = ds.selectorCount;
uint256 selectorCount = originalSelectorCount;
bytes32 selectorSlot;
// Check if last selector slot is not full
if (selectorCount & 7 > 0) {
// get last selectorSlot
selectorSlot = ds.selectorSlots[selectorCount >> 3];
}
// loop through diamond cut
for (uint256 facetIndex; facetIndex < _diamondCut.length; facetIndex++) {
(selectorCount, selectorSlot) = LibDiamond.addReplaceRemoveFacetSelectors(
selectorCount,
selectorSlot,
_diamondCut[facetIndex].facetAddress,
_diamondCut[facetIndex].action,
_diamondCut[facetIndex].functionSelectors
);
}
if (selectorCount != originalSelectorCount) {
ds.selectorCount = uint16(selectorCount);
}
// If last selector slot is not full
if (selectorCount & 7 > 0) {
ds.selectorSlots[selectorCount >> 3] = selectorSlot;
}
emit DiamondCut(_diamondCut, _init, _calldata);
LibDiamond.initializeDiamondCut(_init, _calldata);
}
}
contracts/facets/DiamondInitFacet.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/******************************************************************************\
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
*
* Implementation of a diamond.
/******************************************************************************/
import {LibDiamond} from "../libraries/LibDiamond.sol";
import {IDiamondLoupe} from "../interfaces/IDiamondLoupe.sol";
import {IDiamondCut} from "../interfaces/IDiamondCut.sol";
import {IERC173} from "../interfaces/IERC173.sol";
import {IERC165} from "../interfaces/IERC165.sol";
import {IGBMEventsFacet} from "../interfaces/facets/IGBMEventsFacet.sol";
import "../libraries/GBM_Core.sol";
contract DiamondInitFacet is IGBMEventsFacet {
GBMStorage internal s;
function init(uint256 /*_conf */) external {
LibDiamond.enforceIsContractOwner();
// adding ERC165 data, implementation in DiamondLoupeFacet
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
require(
ds.supportedInterfaces[type(IERC165).interfaceId] == false,
"Diamond already intialized"
);
ds.supportedInterfaces[type(IERC165).interfaceId] = true; // Introspection
ds.supportedInterfaces[type(IDiamondCut).interfaceId] = true;
ds.supportedInterfaces[type(IDiamondLoupe).interfaceId] = true;
ds.supportedInterfaces[type(IERC173).interfaceId] = true; // Ownable
s.GBMAdminAccount = msg.sender; // LibDiamond.enforceIsContractOwner() above
s.GBMBackendSigner = msg.sender;
emit Admin_BackendSignerUpdated(msg.sender);
s.GBMProtocolFeeAuction = 2000;
s.GBMProtocolFeeFixedPrice = 2000;
s.GBMProtocolFeeSwap = 2000;
s.GBMProtocolWallet = 0x980D0D096a63A52480c9a2A903F41867Cb428132;
emit Admin_ProtocolFees_Updated(
2000,
2000,
2000,
0x980D0D096a63A52480c9a2A903F41867Cb428132
);
s.biddingPresetIDToName[0] = "Zero";
s.biddingPresetIDToStepMin[0] = 5000;
s.biddingPresetIDToIncentiveMin[0] = 0;
s.biddingPresetIDToIncentiveMax[0] = 0;
s.biddingPresetIDToIncentiveGrowthMultiplier[0] = 0;
emit Admin_BiddingPreset_Updated(0, "Zero", 5000, 0, 0, 0);
s.biddingPresetIDToName[1] = "Low";
s.biddingPresetIDToStepMin[1] = 5000;
s.biddingPresetIDToIncentiveMin[1] = 500;
s.biddingPresetIDToIncentiveMax[1] = 2000;
s.biddingPresetIDToIncentiveGrowthMultiplier[1] = 1620;
emit Admin_BiddingPreset_Updated(1, "Low", 5000, 500, 2000, 1620);
s.biddingPresetIDToName[2] = "Medium";
s.biddingPresetIDToStepMin[2] = 5000;
s.biddingPresetIDToIncentiveMin[2] = 500;
s.biddingPresetIDToIncentiveMax[2] = 5000;
s.biddingPresetIDToIncentiveGrowthMultiplier[2] = 4970;
emit Admin_BiddingPreset_Updated(2, "Medium", 5000, 500, 5000, 4970);
s.biddingPresetIDToName[3] = "High";
s.biddingPresetIDToStepMin[3] = 10000;
s.biddingPresetIDToIncentiveMin[3] = 1000;
s.biddingPresetIDToIncentiveMax[3] = 10000;
s.biddingPresetIDToIncentiveGrowthMultiplier[3] = 11000;
emit Admin_BiddingPreset_Updated(3, "High", 10000, 1000, 10000, 11000);
s.biddingPresetIDToName[4] = "Degen";
s.biddingPresetIDToStepMin[4] = 20000;
s.biddingPresetIDToIncentiveMin[4] = 2000;
s.biddingPresetIDToIncentiveMax[4] = 20000;
s.biddingPresetIDToIncentiveGrowthMultiplier[4] = 27000;
emit Admin_BiddingPreset_Updated(4, "Degen", 10000, 2000, 20000, 27000);
s.currencyNames[1] = "ETH";
s.currencyAddress[1] = address(0);
s.currencyIndex[address(0)] = 1;
emit Currency_AddressUpdated(1, address(0));
emit Currency_NameUpdated(1, "ETH");
s.defaultCurrency = 1;
emit Currency_DefaultUpdated(1, 1, address(0), "ETH");
}
}
contracts/facets/DiamondLoupeFacet.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/******************************************************************************\
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
/******************************************************************************/
import { LibDiamond } from "../libraries/LibDiamond.sol";
import { IDiamondLoupe } from "../interfaces/IDiamondLoupe.sol";
import { IERC165 } from "../interfaces/IERC165.sol";
contract DiamondLoupeFacet is IDiamondLoupe, IERC165 {
// Diamond Loupe Functions
////////////////////////////////////////////////////////////////////
/// These functions are expected to be called frequently by tools.
//
// struct Facet {
// address facetAddress;
// bytes4[] functionSelectors;
// }
/// @notice Gets all facets and their selectors.
/// @return facets_ Facet
function facets() external override view returns (Facet[] memory facets_) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
facets_ = new Facet[](ds.selectorCount);
uint8[] memory numFacetSelectors = new uint8[](ds.selectorCount);
uint256 numFacets;
uint256 selectorIndex;
// loop through function selectors
for (uint256 slotIndex; selectorIndex < ds.selectorCount; slotIndex++) {
bytes32 slot = ds.selectorSlots[slotIndex];
for (uint256 selectorSlotIndex; selectorSlotIndex < 8; selectorSlotIndex++) {
selectorIndex++;
if (selectorIndex > ds.selectorCount) {
break;
}
bytes4 selector = bytes4(slot << (selectorSlotIndex << 5));
address facetAddress_ = address(bytes20(ds.facets[selector]));
bool continueLoop = false;
for (uint256 facetIndex; facetIndex < numFacets; facetIndex++) {
if (facets_[facetIndex].facetAddress == facetAddress_) {
facets_[facetIndex].functionSelectors[numFacetSelectors[facetIndex]] = selector;
// probably will never have more than 256 functions from one facet contract
require(numFacetSelectors[facetIndex] < 255);
numFacetSelectors[facetIndex]++;
continueLoop = true;
break;
}
}
if (continueLoop) {
continueLoop = false;
continue;
}
facets_[numFacets].facetAddress = facetAddress_;
facets_[numFacets].functionSelectors = new bytes4[](ds.selectorCount);
facets_[numFacets].functionSelectors[0] = selector;
numFacetSelectors[numFacets] = 1;
numFacets++;
}
}
for (uint256 facetIndex; facetIndex < numFacets; facetIndex++) {
uint256 numSelectors = numFacetSelectors[facetIndex];
bytes4[] memory selectors = facets_[facetIndex].functionSelectors;
// setting the number of selectors
assembly {
mstore(selectors, numSelectors)
}
}
// setting the number of facets
assembly {
mstore(facets_, numFacets)
}
}
/// @notice Gets all the function selectors supported by a specific facet.
/// @param _facet The facet address.
/// @return _facetFunctionSelectors The selectors associated with a facet address.
function facetFunctionSelectors(address _facet) external override view returns (bytes4[] memory _facetFunctionSelectors) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
uint256 numSelectors;
_facetFunctionSelectors = new bytes4[](ds.selectorCount);
uint256 selectorIndex;
// loop through function selectors
for (uint256 slotIndex; selectorIndex < ds.selectorCount; slotIndex++) {
bytes32 slot = ds.selectorSlots[slotIndex];
for (uint256 selectorSlotIndex; selectorSlotIndex < 8; selectorSlotIndex++) {
selectorIndex++;
if (selectorIndex > ds.selectorCount) {
break;
}
bytes4 selector = bytes4(slot << (selectorSlotIndex << 5));
address facet = address(bytes20(ds.facets[selector]));
if (_facet == facet) {
_facetFunctionSelectors[numSelectors] = selector;
numSelectors++;
}
}
}
// Set the number of selectors in the array
assembly {
mstore(_facetFunctionSelectors, numSelectors)
}
}
/// @notice Get all the facet addresses used by a diamond.
/// @return facetAddresses_
function facetAddresses() external override view returns (address[] memory facetAddresses_) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
facetAddresses_ = new address[](ds.selectorCount);
uint256 numFacets;
uint256 selectorIndex;
// loop through function selectors
for (uint256 slotIndex; selectorIndex < ds.selectorCount; slotIndex++) {
bytes32 slot = ds.selectorSlots[slotIndex];
for (uint256 selectorSlotIndex; selectorSlotIndex < 8; selectorSlotIndex++) {
selectorIndex++;
if (selectorIndex > ds.selectorCount) {
break;
}
bytes4 selector = bytes4(slot << (selectorSlotIndex << 5));
address facetAddress_ = address(bytes20(ds.facets[selector]));
bool continueLoop = false;
for (uint256 facetIndex; facetIndex < numFacets; facetIndex++) {
if (facetAddress_ == facetAddresses_[facetIndex]) {
continueLoop = true;
break;
}
}
if (continueLoop) {
continueLoop = false;
continue;
}
facetAddresses_[numFacets] = facetAddress_;
numFacets++;
}
}
// Set the number of facet addresses in the array
assembly {
mstore(facetAddresses_, numFacets)
}
}
/// @notice Gets the facet that supports the given selector.
/// @dev If facet is not found return address(0).
/// @param _functionSelector The function selector.
/// @return facetAddress_ The facet address.
function facetAddress(bytes4 _functionSelector) external override view returns (address facetAddress_) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
facetAddress_ = address(bytes20(ds.facets[_functionSelector]));
}
// This implements ERC-165.
function supportsInterface(bytes4 _interfaceId) external override view returns (bool) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
return ds.supportedInterfaces[_interfaceId];
}
}
contracts/facets/GBMAdminFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
import "../libraries/GBM_Core.sol";
import { IGBMEventsFacet } from "../interfaces/facets/IGBMEventsFacet.sol";
import { LibDiamond } from "../libraries/LibDiamond.sol";
/// @title GBMAdminFacet Contract
/// @author Guillaume Gonnaud
contract GBMAdminFacet is IGBMEventsFacet {
GBMStorage internal s;
modifier onlyAdmin() {
require(msg.sender == s.GBMAdminAccount || msg.sender == LibDiamond.contractOwner(), "Function only callable by the GBM admin");
_;
}
modifier reentrancyProtector() {
require(!s.reentrancySemaphore, "No Double Dip, kthxbye");
s.reentrancySemaphore = true;
_;
s.reentrancySemaphore = false;
}
function setGBMAdminAccount(address _GBMAdminAccount) external onlyAdmin(){
s.GBMAdminAccount = _GBMAdminAccount;
}
function setGBMBackendSigner(address _backendSigner) external onlyAdmin(){
s.GBMBackendSigner = _backendSigner;
emit Admin_BackendSignerUpdated(_backendSigner);
}
function setProtocolFees(uint256 _auctionFee, uint256 _fixedPriceFee, uint256 _swapFee, address _feeRecipient) onlyAdmin() external {
s.GBMProtocolFeeAuction = _auctionFee;
s.GBMProtocolFeeFixedPrice = _fixedPriceFee;
s.GBMProtocolFeeSwap = _swapFee;
s.GBMProtocolWallet = _feeRecipient;
emit Admin_ProtocolFees_Updated( _auctionFee, _fixedPriceFee, _swapFee, _feeRecipient);
}
function setBiddingPreset(uint256 _presetID, string calldata _presetName, uint256 _stepMin, uint256 _incentiveMin, uint256 _incentiveMax, uint256 _incentiveGrowthMultiplier) onlyAdmin() external {
s.biddingPresetIDToName[_presetID] = _presetName;
s.biddingPresetIDToStepMin[_presetID] = _stepMin;
s.biddingPresetIDToIncentiveMin[_presetID] = _incentiveMin;
s.biddingPresetIDToIncentiveMax[_presetID] = _incentiveMax;
s.biddingPresetIDToIncentiveGrowthMultiplier[_presetID] = _incentiveGrowthMultiplier;
emit Admin_BiddingPreset_Updated(_presetID, _presetName, _stepMin, _incentiveMin, _incentiveMax, _incentiveGrowthMultiplier);
}
function set721Depositor(address _contract721, uint256 _tokenID, address _depositor) external onlyAdmin(){
if(s.erc721tokensAddressAndIDToEscrower[_contract721][_tokenID] != address(0)){
emit Escrow_ERC721Withdrawn( _contract721, _tokenID, s.erc721tokensAddressAndIDToEscrower[_contract721][_tokenID]);
}
s.erc721tokensAddressAndIDToEscrower[_contract721][_tokenID] = _depositor;
emit Escrow_ERC721Deposited(_contract721, _tokenID, _depositor);
}
function add1155Deposited(address _contract1155, uint256 _tokenID, uint256 _amount, address _depositor) external onlyAdmin(){
s.erc1155tokensAddressAndIDToEscrowerAmount[_contract1155][_tokenID][_depositor] += _amount;
emit Escrow_ERC1155Deposited(_contract1155, _tokenID, _amount, _depositor);
}
function remove1155Deposited(address _contract1155, uint256 _tokenID, uint256 _amount, address _depositor) external onlyAdmin(){
s.erc1155tokensAddressAndIDToEscrowerAmount[_contract1155][_tokenID][_depositor] -= _amount;
emit Escrow_ERC1155Withdrawn(_contract1155, _tokenID, _amount, _depositor);
}
}
contracts/facets/GBMAuctionRegistrationFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
import { IGBMAuctionRegistrationFacet } from "../interfaces/facets/IGBMAuctionRegistrationFacet.sol";
import "../libraries/GBM_Core.sol";
import { IGBMEventsFacet } from "../interfaces/facets/IGBMEventsFacet.sol";
import { LibDiamond } from "../libraries/LibDiamond.sol";
import { IERC721 } from "../interfaces/IERC721.sol";
import { IERC1155 } from "../interfaces/IERC1155.sol";
import { IERC20 } from "../interfaces/IERC20.sol";
/*
Backend checks to be made for the signature of an auction creation as those are NOT verified onchain
Is the seller (msg.sender) allowed to create auctions of this NFT in this marketplaceID ?
Is this NFT contract allowed to be sold on this marketplace ?
Is the GBMPresetId valid for this marketplace ?
*/
contract GBMAuctionRegistrationFacet is IGBMEventsFacet, IGBMAuctionRegistrationFacet{
GBMStorage internal s;
function getDOMAIN_SEPARATOR() internal view returns (bytes32) {
return keccak256(abi.encode(EIP712_DOMAIN_TYPEHASH, keccak256("GBM dApp"), keccak256("1"), block.chainid, address(this)));
}
modifier reentrancyProtector() {
require(!s.reentrancySemaphore, "No Double Dip, kthxbye");
s.reentrancySemaphore = true;
_;
s.reentrancySemaphore = false;
}
// =================================================================================================
//TODO : Remove once signature confirmed working
function register721AuctionTrySignature( address _erc721Contract, uint256 _tokenID, AuctionRegistrationParams calldata _auctionParams, bytes calldata _authorisation) external payable {
isRegistration721AuctionAuthorized(_erc721Contract, _tokenID, _auctionParams, _authorisation);
}
function register721AuctionsBatchTrySignature( address _erc721Contract, uint256[] calldata _tokenIDs, AuctionRegistrationParams calldata _auctionParams, bytes calldata _authorisation) payable external {
//Signature check
isRegistration721AuctionsBatchAuthorized(_erc721Contract, _tokenIDs, _auctionParams, _authorisation);
}
function register1155AuctionTrySignature( address _erc1155Contract, uint256 _tokenID, uint256 /*_amount */, AuctionRegistrationParams calldata _auctionParams, bytes calldata _authorisation) payable external reentrancyProtector() {
//Signature check
isRegistration1155AuctionAuthorized(_erc1155Contract, _tokenID, _auctionParams, _authorisation);
}
function register1155AuctionsBatchTrySignature( address _erc1155Contract, uint256[] calldata _tokenIDs, uint256[] calldata /*_amount */, AuctionRegistrationParams calldata _auctionParams, bytes calldata _authorisation) payable external reentrancyProtector() {
//Signature check
isRegistration1155AuctionsBatchAuthorized(_erc1155Contract, _tokenIDs, _auctionParams, _authorisation);
}
// =================================================================================================
function register721Auction( address _erc721Contract, uint256 _tokenID, AuctionRegistrationParams calldata _auctionParams, bytes calldata _authorisation) payable external reentrancyProtector() {
//Signature check
isRegistration721AuctionAuthorized(_erc721Contract, _tokenID, _auctionParams, _authorisation);
//Params checks
validateAuctionParams(_auctionParams);
//Auction registration
register721AuctionInternal( _tokenID, _erc721Contract, _auctionParams);
}
function register721AuctionsBatch( address _erc721Contract, uint256[] calldata _tokenIDs, AuctionRegistrationParams calldata _auctionParams, bytes calldata _authorisation) payable external reentrancyProtector() {
//Signature check
isRegistration721AuctionsBatchAuthorized(_erc721Contract, _tokenIDs, _auctionParams, _authorisation);
//Params checks
validateAuctionParams(_auctionParams);
for(uint i; i < _tokenIDs.length; i++){
//Auction registration
register721AuctionInternal( _tokenIDs[i], _erc721Contract, _auctionParams);
}
}
function register1155Auction( address _erc1155Contract, uint256 _tokenID, uint256 _amount, AuctionRegistrationParams calldata _auctionParams, bytes calldata _authorisation) payable external reentrancyProtector() {
//Signature check
isRegistration1155AuctionAuthorized(_erc1155Contract, _tokenID, _auctionParams, _authorisation);
//Params checks
validateAuctionParams(_auctionParams);
//Auction registration
register1155AuctionInternal(_erc1155Contract, _tokenID, _amount, _auctionParams);
}
function register1155AuctionsBatch( address _erc1155Contract, uint256[] calldata _tokenIDs, uint256[] calldata _amounts, AuctionRegistrationParams calldata _auctionParams, bytes calldata _authorisation) payable external reentrancyProtector() {
//Signature check
isRegistration1155AuctionsBatchAuthorized(_erc1155Contract, _tokenIDs, _auctionParams, _authorisation);
//Params checks
validateAuctionParams(_auctionParams);
for(uint i; i < _tokenIDs.length; i++){
//Auction registration
register1155AuctionInternal(_erc1155Contract, _tokenIDs[i], _amounts[i], _auctionParams);
}
}
// =================================================================================================
function register721AuctionInternal ( uint256 _tokenID, address _erc721Contract, AuctionRegistrationParams calldata _p) internal {
s.auctionHouseIDToAuctionsCreated[_p.marketplaceID]++;
uint256 _saleID = s.auctionHouseIDToAuctionsCreated[_p.marketplaceID];
//Check where the ERC721 is and if it's valid for sale
//If the token is with us, check that the msg.sender is the depositor
if(IERC721(_erc721Contract).ownerOf(_tokenID) == address(this)){
require(s.erc721tokensAddressAndIDToEscrower[_erc721Contract][_tokenID] == msg.sender, "msg.sender did not deposit the token in escrow");
} else { //If the token is not with us, transfer it
IERC721(_erc721Contract).safeTransferFrom( msg.sender, address(this), _tokenID);
}
//Setting up the auction variables
s.auctionHouseIDToSaleIDToTokenKind[_p.marketplaceID][_saleID] = ERC721;
s.auctionHouseIDToSaleIDToTokenContract[_p.marketplaceID][_saleID] = _erc721Contract;
s.auctionHouseIDToSaleIDToTokenID[_p.marketplaceID][_saleID] = _tokenID;
s.auctionHouseIDToSaleIDToSeller[_p.marketplaceID][_saleID] = msg.sender;
s.auctionHouseIDToSaleIDToGBMPresetID[_p.marketplaceID][_saleID] = _p.GBMPresetID;
s.auctionHouseIDToSaleIDToCurrency[_p.marketplaceID][_saleID] = _p.currency;
s.auctionHouseIDToSaleIDToStartTimestamp[_p.marketplaceID][_saleID] = _p.startTimestamp;
s.auctionHouseIDToSaleIDToEndTimestamp[_p.marketplaceID][_saleID] = _p.endTimestamp;
s.auctionHouseIDToSaleIDToHammerTimeDuration[_p.marketplaceID][_saleID] = _p.hammerTimeDuration;
s.auctionHouseIDToSaleIDToCancellationDuration[_p.marketplaceID][_saleID] = _p.cancellationDuration;
s.auctionHouseIDToSaleIDToAmountForSale[_p.marketplaceID][_saleID] = 1;
s.auctionHouseIDToSaleIDToSaleKind[_p.marketplaceID][_saleID] = 1; //Auction
//Adjusting escrow/Sale data
s.erc721tokensAddressAndIDToUnderSale[_erc721Contract][_tokenID] = true;
//Emitting the creation events
emit Auction_ERC721_Created(_p.marketplaceID, _saleID, msg.sender, _erc721Contract, _tokenID);
emit Auction_Parameters_Updated(_p.marketplaceID, _saleID, _p.GBMPresetID, s.currencyIndex[_p.currency], _p.startTimestamp, _p.endTimestamp, _p.hammerTimeDuration, _p.cancellationDuration, _p.startingBid);
//Capturing the fees if there is a starting bid
captureStartingBidFees(_p, _saleID);
}
function register1155AuctionInternal (address _erc1155Contract, uint256 _tokenID, uint256 _amount, AuctionRegistrationParams calldata _p) internal {
s.auctionHouseIDToAuctionsCreated[_p.marketplaceID]++;
uint256 _saleID = s.auctionHouseIDToAuctionsCreated[_p.marketplaceID];
//Check where the 1155 are and if it's valid for sale
uint256 _availableInEscrow = s.erc1155tokensAddressAndIDToEscrowerAmount[_erc1155Contract][_tokenID][msg.sender] - s.erc1155tokensAddressAndIDToEscrowerUnderSaleAmount[_erc1155Contract][_tokenID][msg.sender];
//Case : Not enough tokens in escrow
if(_availableInEscrow < _amount){
//Fetch the tokens
IERC1155(_erc1155Contract).safeTransferFrom(msg.sender, address(this), _tokenID, _amount - _availableInEscrow, abi.encodePacked(""));
_availableInEscrow = s.erc1155tokensAddressAndIDToEscrowerAmount[_erc1155Contract][_tokenID][msg.sender] - s.erc1155tokensAddressAndIDToEscrowerUnderSaleAmount[_erc1155Contract][_tokenID][msg.sender];
}
require(_availableInEscrow >= _amount, "Not enough tokens available for sale to start the auction");
//Setting up the auction variables
s.auctionHouseIDToSaleIDToTokenKind[_p.marketplaceID][_saleID] = ERC1155;
s.auctionHouseIDToSaleIDToTokenContract[_p.marketplaceID][_saleID] = _erc1155Contract;
s.auctionHouseIDToSaleIDToTokenID[_p.marketplaceID][_saleID] = _tokenID;
s.auctionHouseIDToSaleIDToSeller[_p.marketplaceID][_saleID] = msg.sender;
s.auctionHouseIDToSaleIDToGBMPresetID[_p.marketplaceID][_saleID] = _p.GBMPresetID;
s.auctionHouseIDToSaleIDToCurrency[_p.marketplaceID][_saleID] = _p.currency;
s.auctionHouseIDToSaleIDToStartTimestamp[_p.marketplaceID][_saleID] = _p.startTimestamp;
s.auctionHouseIDToSaleIDToEndTimestamp[_p.marketplaceID][_saleID] = _p.endTimestamp;
s.auctionHouseIDToSaleIDToHammerTimeDuration[_p.marketplaceID][_saleID] = _p.hammerTimeDuration;
s.auctionHouseIDToSaleIDToCancellationDuration[_p.marketplaceID][_saleID] = _p.cancellationDuration;
s.auctionHouseIDToSaleIDToAmountForSale[_p.marketplaceID][_saleID] = _amount;
s.auctionHouseIDToSaleIDToSaleKind[_p.marketplaceID][_saleID] = 1; //Auction
//Adjusting escrow/Sale data
s.erc1155tokensAddressAndIDToEscrowerUnderSaleAmount[_erc1155Contract][_tokenID][msg.sender] += _amount;
//Emitting the creation events
emit Auction_ERC1155_Created(_p.marketplaceID, _saleID, msg.sender, _erc1155Contract, _tokenID, _amount);
emit Auction_Parameters_Updated(_p.marketplaceID, _saleID, _p.GBMPresetID, s.currencyIndex[_p.currency], _p.startTimestamp, _p.endTimestamp, _p.hammerTimeDuration, _p.cancellationDuration, _p.startingBid);
//Capturing the fees if there is a starting bid
captureStartingBidFees(_p, _saleID);
}
function validateAuctionParams(AuctionRegistrationParams calldata _p) internal view {
require(s.auctionHouseIDToAuctionsEnabled[_p.marketplaceID], "Auctions disabled for this marketplace");
require(s.biddingPresetIDToStepMin[_p.GBMPresetID] != 0, "Invalid GBM preset ID");
require(s.auctionHouseIDToCurrencyAddressToAllowed[_p.marketplaceID][_p.currency], "This currency is not allowed for this marketplace");
require(block.timestamp < _p.endTimestamp, "The auction must finish in the future");
require(_p.endTimestamp > _p.startTimestamp, "The auction duration cannot be negative");
require(_p.hammerTimeDuration >= 60, "Hammertime need to last at least a minute");
require(_p.endTimestamp <= _p.startTimestamp + 691200, "The auction duration cannot exceed 8 days");
require(s.auctionHouseIDToFeeRecipient[_p.marketplaceID] != address(0), "No beneficary have been set for the marketplace fees");
}
function captureStartingBidFees(AuctionRegistrationParams calldata /* _p */, uint256 /* _saleID */) internal pure {
//Currently disabled. If enabling, don't forget to add the code in settlement
return;
/*
if(_p.startingBid == 0 || msg.sender == s.GBMAdminAccount || msg.sender == LibDiamond.contractOwner()){
return;
} else {
uint256 _amountToProtocol = (_p.startingBid * s.GBMProtocolFeeAuction) / DECIMALSK;
uint256 _amountToMarketplace = (_p.startingBid * s.auctionHouseIDToFeeAuction[_p.marketplaceID]) / DECIMALSK;
uint256 _paidAmount = _amountToProtocol + _amountToMarketplace;
s.auctionHouseIDToSaleIDToPrepaidAmount[_p.marketplaceID][_saleID] = _paidAmount;
s.auctionHouseIDToSaleIDToStartingBid[_p.marketplaceID][_saleID] = _p.startingBid;
//Capture the funds
//Case of base currency
if(_p.currency == address(0)){
require(msg.value == _paidAmount, "Not enough base currency was sent to pay for the auction creation");
if(s.GBMProtocolWallet != address(0) && _paidAmount != 0){
sendbaseCurrency(s.GBMProtocolWallet, _amountToProtocol);
sendbaseCurrency(s.auctionHouseIDToFeeRecipient[_p.marketplaceID], _amountToMarketplace);
}
} else { //Case ERC20
if(_paidAmount != 0){
IERC20(_p.currency).transferFrom(msg.sender, address(this), _paidAmount);
if(s.GBMProtocolWallet != address(0)){
IERC20(_p.currency).transfer(s.GBMProtocolWallet, _amountToProtocol);
IERC20(_p.currency).transfer(s.auctionHouseIDToFeeRecipient[_p.marketplaceID], _amountToMarketplace);
}
}
}
emit Money_StartingBid_FeeCapture(_p.marketplaceID, _saleID, msg.sender, _p.currency, _p.startingBid, _paidAmount);
emit Money_StartingBid_ProtocolFee(_p.marketplaceID, _saleID, msg.sender, _p.currency, _p.startingBid, _amountToProtocol, s.GBMProtocolWallet);
emit Money_StartingBid_MarketplaceFee(_p.marketplaceID, _saleID, msg.sender, _p.currency, _p.startingBid, _amountToMarketplace, s.auctionHouseIDToFeeRecipient[_p.marketplaceID]);
}
*/
}
function sendbaseCurrency(address to, uint256 amount) internal {
if (amount == 0) { return; }
(bool succ, ) = to.call{value: amount}("");
require( succ, "Transfer failed on a normal wallet. Je beg your pardon ?");
}
function generateRegistration721AuctionHash(address _contract721, uint256 _tokenID, AuctionRegistrationParams calldata _p) internal view returns(bytes32){
return keccak256(
abi.encode(
REGISTER721AUCTION_SIGNATURE_TYPEHASH,
msg.sender,
_contract721,
_tokenID,
_p.marketplaceID,
_p.GBMPresetID,
_p.currency,
_p.startTimestamp,
_p.endTimestamp,
_p.hammerTimeDuration,
_p.cancellationDuration,
_p.startingBid
)
);
}
function generateRegistration721AuctionsBatchHash(address _contract721, uint256[] calldata _tokenID, AuctionRegistrationParams calldata _p) internal view returns(bytes32){
bytes32 _tokenIDsHash = keccak256(abi.encodePacked(_tokenID));
return keccak256(
abi.encode(
REGISTER721AUCTIONS_BATCH_SIGNATURE_TYPEHASH,
msg.sender,
_contract721,
_tokenIDsHash,
_p.marketplaceID,
_p.GBMPresetID,
_p.currency,
_p.startTimestamp,
_p.endTimestamp,
_p.hammerTimeDuration,
_p.cancellationDuration,
_p.startingBid
)
);
}
function generateRegistration1155AuctionHash(address _contract1155, uint256 _tokenID, AuctionRegistrationParams calldata _p) internal view returns(bytes32){
//No amount cause stack too deep and not very relevant for signing
return keccak256(
abi.encode(
REGISTER1155AUCTION_SIGNATURE_TYPEHASH,
msg.sender,
_contract1155,
_tokenID,
_p.marketplaceID,
_p.GBMPresetID,
_p.currency,
_p.startTimestamp,
_p.endTimestamp,
_p.hammerTimeDuration,
_p.cancellationDuration,
_p.startingBid
)
);
}
function generateRegistration1155AuctionsBatchHash(address _contract1155, uint256[] calldata _tokenID, AuctionRegistrationParams calldata _p) internal view returns(bytes32){
//No amount cause stack too deep and not very relevant for signing
bytes32 _tokenIDsHash = keccak256(abi.encodePacked(_tokenID));
return keccak256(
abi.encode(
REGISTER1155AUCTIONS_BATCH_SIGNATURE_TYPEHASH,
msg.sender,
_contract1155,
_tokenIDsHash,
_p.marketplaceID,
_p.GBMPresetID,
_p.currency,
_p.startTimestamp,
_p.endTimestamp,
_p.hammerTimeDuration,
_p.cancellationDuration,
_p.startingBid
)
);
}
function isRegistration721AuctionAuthorized(address _contract721, uint256 _tokenID, AuctionRegistrationParams calldata _p, bytes calldata _authorisation) internal view returns (bool) {
bytes32 hash = generateRegistration721AuctionHash(_contract721, _tokenID, _p);
(uint8 _v, bytes32 _r, bytes32 _s) = splitSignature(abi.encodePacked(_authorisation));
require(verify(s.GBMBackendSigner, hash, _v, _r, _s), "Invalid Registration authorization");
return true;
}
function isRegistration721AuctionsBatchAuthorized(address _contract721, uint256[] calldata _tokenIDs, AuctionRegistrationParams calldata _p, bytes calldata _authorisation) internal view returns (bool) {
bytes32 hash = generateRegistration721AuctionsBatchHash(_contract721, _tokenIDs, _p);
(uint8 _v, bytes32 _r, bytes32 _s) = splitSignature(abi.encodePacked(_authorisation));
require(verify(s.GBMBackendSigner, hash, _v, _r, _s), "Invalid Registration authorization");
return true;
}
function isRegistration1155AuctionAuthorized(address _contract721, uint256 _tokenID, AuctionRegistrationParams calldata _p, bytes calldata _authorisation) internal view returns (bool) {
bytes32 hash = generateRegistration1155AuctionHash(_contract721, _tokenID, _p);
(uint8 _v, bytes32 _r, bytes32 _s) = splitSignature(abi.encodePacked(_authorisation));
require(verify(s.GBMBackendSigner, hash, _v, _r, _s), "Invalid Registration authorization");
return true;
}
function isRegistration1155AuctionsBatchAuthorized(address _contract721, uint256[] calldata _tokenIDs, AuctionRegistrationParams calldata _p, bytes calldata _authorisation) internal view returns (bool) {
bytes32 hash = generateRegistration1155AuctionsBatchHash(_contract721, _tokenIDs, _p);
(uint8 _v, bytes32 _r, bytes32 _s) = splitSignature(abi.encodePacked(_authorisation));
require(verify(s.GBMBackendSigner, hash, _v, _r, _s), "Invalid Registration authorization");
return true;
}
/// signature methods.
function splitSignature(bytes memory sig) internal pure returns (uint8 v_, bytes32 r_, bytes32 s_) {
require(sig.length == 65);
assembly {
// first 32 bytes, after the length prefix.
r_ := mload(add(sig, 32))
// second 32 bytes.
s_ := mload(add(sig, 64))
// final byte (first byte of the next 32 bytes).
v_ := byte(0, mload(add(sig, 96)))
}
return (v_, r_, s_);
}
function verify(address _signee, bytes32 _hash, uint8 _v, bytes32 _r, bytes32 _s) internal view returns (bool){
// Note: we need to use `encodePacked` here instead of `encode`.
bytes32 digest = keccak256(abi.encodePacked(
"\x19\x01",
getDOMAIN_SEPARATOR(),
_hash
));
return ecrecover(digest, _v, _r, _s) == _signee;
}
}
contracts/facets/GBMBiddingFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
import "../libraries/GBM_Core.sol";
import { IGBMEventsFacet } from "../interfaces/facets/IGBMEventsFacet.sol";
import { LibDiamond } from "../libraries/LibDiamond.sol";
import { IGBMBiddingFacet } from "../interfaces/facets/IGBMBiddingFacet.sol";
import { IERC1155 } from "../interfaces/IERC1155.sol";
import { IERC20 } from "../interfaces/IERC20.sol";
contract GBMBiddingFacet is IGBMBiddingFacet, IGBMEventsFacet {
GBMStorage internal s;
function getDOMAIN_SEPARATOR() internal view returns (bytes32) {
return keccak256(abi.encode(EIP712_DOMAIN_TYPEHASH, keccak256("GBM dApp"), keccak256("1"), block.chainid, address(this)));
}
modifier reentrancyProtector() {
require(!s.reentrancySemaphore, "No Double Dip, kthxbye");
s.reentrancySemaphore = true;
_;
s.reentrancySemaphore = false;
}
/// @notice Place a bid on a live GBM Auction
/// @dev The currency being used is the default currency of the auction
/// @param _auctionHouseID The auctionHouseID the bid is placed upon
/// @param _auctionID The auctionID the bid is placed upon
/// @param _newBidAmount The amount of the new bid
/// @param _previousHighestBidAmount The amount of the previous highest bid
/// @param _authorisation The authorisation to bid from the backend
function bid(
uint256 _auctionHouseID,
uint256 _auctionID,
uint256 _newBidAmount,
uint256 _previousHighestBidAmount,
uint256 _incentiveBoost,
bytes calldata _authorisation
) public payable virtual reentrancyProtector {
isPlacebidAllowed(msg.sender, _auctionHouseID, _auctionID, _newBidAmount, _previousHighestBidAmount, _incentiveBoost, _authorisation);
bidInternal(_auctionHouseID, _auctionID, _newBidAmount, _previousHighestBidAmount, _incentiveBoost);
}
function bidInternal(uint256 _auctionHouseID, uint256 _auctionID, uint256 _newBidAmount, uint256 _previousHighestBidAmount, uint256 _incentiveBoost) internal{
require(s.auctionHouseIDToSaleIDToSaleKind[_auctionHouseID][_auctionID] == 1, "You can only bid() on auctions");
require(s.auctionHouseIDToSaleIDToStartTimestamp[_auctionHouseID][_auctionID] != 0, "Auction doesn't exist");
require(_newBidAmount > _previousHighestBidAmount, "The new bid need to be higher than the previous bid");
uint256 _currTopBidIndex = s.auctionHouseIDToSaleIDToNumberOfBids[_auctionHouseID][_auctionID];
require(_previousHighestBidAmount == s.auctionHouseIDToSaleIDToBidIndexToValues[_auctionHouseID][_auctionID][_currTopBidIndex], "The previous highest bid do not match");
require( s.auctionHouseIDToSaleIDToStartTimestamp[_auctionHouseID][_auctionID] < block.timestamp, "The auction has not started yet");
require( s.auctionHouseIDToSaleIDToEndTimestamp[_auctionHouseID][_auctionID] > block.timestamp, "The auction has already ended");
require(_newBidAmount > 1, "newBidAmount cannot be 0");
require(_newBidAmount >= s.auctionHouseIDToSaleIDToStartingBid[_auctionHouseID][_auctionID], "newBidAmount cannot be less than the starting bid");
address _currAddress = s.auctionHouseIDToSaleIDToCurrency[_auctionHouseID][_auctionID];
uint256 _dueIncentives;
//Case of a native currency : Eth, Matic, etc...
if (_currAddress == address(0x0)) {
require(
msg.value == _newBidAmount,
"The amount of currency sent with the bid do not match the bid"
);
emit Money_BidCaptured(
_auctionHouseID,
_auctionID,
msg.sender,
address(0),
_newBidAmount
);
} else {
// Case of an ERC20 token
//Transfer the money of the bidder to the GBM smart contract
IERC20(_currAddress).transferFrom( msg.sender, address(this), _newBidAmount);
emit Money_BidCaptured(
_auctionHouseID,
_auctionID,
msg.sender,
_currAddress,
_newBidAmount
);
}
//Get the current bidIndex and bidamount/incentives
if(_currTopBidIndex != 0){
uint256 _prevBidAmount = s.auctionHouseIDToSaleIDToBidIndexToValues[_auctionHouseID][_auctionID][_currTopBidIndex];
_dueIncentives = s.auctionHouseIDToSaleIDToBidIndexToIncentives[_auctionHouseID][_auctionID][_currTopBidIndex];
address _prevBidder = s.auctionHouseIDToSaleIDToBidIndexToBidder[_auctionHouseID][_auctionID][_currTopBidIndex];
//Checking that stepMin is met
if(_prevBidAmount != 0){
uint256 _stepMin = s.biddingPresetIDToStepMin[s.auctionHouseIDToSaleIDToGBMPresetID[_auctionHouseID][_auctionID]];
require(_newBidAmount >= _prevBidAmount + ((_prevBidAmount * _stepMin) / DECIMALSK), "The new bid need to be at least stepMin higher than the previous bid");
}
emit Bid_Displaced(
_auctionHouseID,
_auctionID,
_currTopBidIndex,
_prevBidder,
_prevBidAmount,
_dueIncentives
);
if (_currAddress == address(0x0)) {
//Refund the previous bidder in native currency
(bool success, ) = _prevBidder.call{value: _prevBidAmount + _dueIncentives}("");
require(success, "Refund to previous bidder failed");
emit Money_BidRefunded(
_auctionHouseID,
_auctionID,
_prevBidder,
address(0),
_prevBidAmount,
_dueIncentives
);
} else {
//Refund the previous bidder in ERC20
IERC20(_currAddress).transfer(_prevBidder, _prevBidAmount + _dueIncentives);
emit Money_BidRefunded(
_auctionHouseID,
_auctionID,
_prevBidder,
_currAddress,
_prevBidAmount,
_dueIncentives
);
}
s.auctionHouseIDToSaleIDToAuctionDebt[_auctionHouseID][_auctionID] += _dueIncentives;
}
//Now switching context to the new bid
_currTopBidIndex = _currTopBidIndex + 1;
s.auctionHouseIDToSaleIDToNumberOfBids[_auctionHouseID][_auctionID] = _currTopBidIndex;
s.auctionHouseIDToSaleIDToBidIndexToValues[_auctionHouseID][_auctionID][_currTopBidIndex] = _newBidAmount;
_dueIncentives = calculateIncentives(_auctionHouseID, _auctionID, _newBidAmount, _previousHighestBidAmount, _incentiveBoost);
s.auctionHouseIDToSaleIDToBidIndexToIncentives[_auctionHouseID][_auctionID][_currTopBidIndex] = _dueIncentives;
s.auctionHouseIDToSaleIDToBidIndexToBidder[_auctionHouseID][_auctionID][_currTopBidIndex] = msg.sender;
emit Bid_Placed(
_auctionHouseID,
_auctionID,
_currTopBidIndex,
msg.sender,
_newBidAmount,
_dueIncentives
);
//Extend the auction if we are in the hammer time window
if(s.auctionHouseIDToSaleIDToHammerTimeDuration[_auctionHouseID][_auctionID] != 0){
uint256 _timeToEnd = s.auctionHouseIDToSaleIDToEndTimestamp[_auctionHouseID][_auctionID] - block.timestamp;
if(_timeToEnd < s.auctionHouseIDToSaleIDToHammerTimeDuration[_auctionHouseID][_auctionID]){
s.auctionHouseIDToSaleIDToEndTimestamp[_auctionHouseID][_auctionID] = block.timestamp + s.auctionHouseIDToSaleIDToHammerTimeDuration[_auctionHouseID][_auctionID];
emit Auction_EndTimestamp_Updated(
_auctionHouseID,
_auctionID,
s.auctionHouseIDToSaleIDToEndTimestamp[_auctionHouseID][_auctionID]
);
}
}
}
/// @notice Calculating and setting how much payout a bidder will receive if outbid
/// @dev Only callable internally
function calculateIncentives(
uint256 _auctionHouseID,
uint256 _auctionID,
uint256 _newBidValue,
uint256 _oldBidValue,
uint256 _incentiveBoost
) virtual internal view returns (uint256) {
uint256 _GBMPresetID = s.auctionHouseIDToSaleIDToGBMPresetID[_auctionHouseID][_auctionID];
uint256 _incentiveMin = s.biddingPresetIDToIncentiveMin[_GBMPresetID];
uint256 _incentiveMax = s.biddingPresetIDToIncentiveMax[_GBMPresetID];
uint256 _incentiveGrowthMultiplier = s.biddingPresetIDToIncentiveGrowthMultiplier[_GBMPresetID];
uint256 _stepMin = s.biddingPresetIDToStepMin[_GBMPresetID];
if(_incentiveMax == 0){
return 0;
}
//Init the baseline bid we need to perform against
uint256 _baseBid;
if(_oldBidValue != 0) {
_baseBid= (_oldBidValue * (DECIMALSK + _stepMin)) / DECIMALSK;
} else{
_baseBid = 1;
}
//Ratio of newBid compared to expected minBid
uint256 _decimaledRatio = ((DECIMALSK *
_incentiveGrowthMultiplier *
(_newBidValue - _baseBid)) / _baseBid) +
_incentiveMin *
DECIMALSK;
//Clamping
if (_decimaledRatio > (DECIMALSK * _incentiveMax)) {
_decimaledRatio = DECIMALSK * _incentiveMax;
}
_decimaledRatio = _decimaledRatio + _incentiveBoost * DECIMALSK;
return (_newBidValue * _decimaledRatio) / (DECIMALSK * DECIMALSK);
}
function generatePlaceBidHash(address _bidder, uint256 _auctionHouseID, uint256 _auctionID, uint256 _newBidAmount, uint256 _previousHighestBidAmount, uint256 _incentiveBoost) public pure returns (bytes32) {
return keccak256(
abi.encode(
PLACEBID_SIGNATURE_TYPEHASH,
_bidder,
_auctionHouseID,
_auctionID,
_newBidAmount,
_previousHighestBidAmount,
_incentiveBoost
)
);
}
function isPlacebidAllowed(address _bidder, uint256 _auctionHouseID, uint256 _auctionID, uint256 _newBidAmount, uint256 _previousHighestBidAmount, uint256 _incentiveBoost, bytes calldata _authorisation) internal view returns (bool) {
bytes32 hash = generatePlaceBidHash(_bidder, _auctionHouseID, _auctionID, _newBidAmount, _previousHighestBidAmount, _incentiveBoost);
(uint8 _v, bytes32 _r, bytes32 _s) = splitSignature(abi.encodePacked(_authorisation));
require(verify(s.GBMBackendSigner, hash, _v, _r, _s), "Invalid PlaceBid authorization");
return true;
}
/// signature methods.
function splitSignature(bytes memory sig) internal pure returns (uint8 v_, bytes32 r_, bytes32 s_) {
require(sig.length == 65);
assembly {
// first 32 bytes, after the length prefix.
r_ := mload(add(sig, 32))
// second 32 bytes.
s_ := mload(add(sig, 64))
// final byte (first byte of the next 32 bytes).
v_ := byte(0, mload(add(sig, 96)))
}
return (v_, r_, s_);
}
function verify(address _signee, bytes32 _hash, uint8 _v, bytes32 _r, bytes32 _s) internal view returns (bool){
// Note: we need to use `encodePacked` here instead of `encode`.
bytes32 digest = keccak256(abi.encodePacked(
"\x19\x01",
getDOMAIN_SEPARATOR(),
_hash
));
return ecrecover(digest, _v, _r, _s) == _signee;
}
}contracts/facets/GBMCurrencyFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
import { IGBMCurrencyFacet } from "../interfaces/facets/IGBMCurrencyFacet.sol";
import { GBMStorage } from "../libraries/GBM_Core.sol";
import { IGBMEventsFacet } from "../interfaces/facets/IGBMEventsFacet.sol";
import { LibDiamond } from "../libraries/LibDiamond.sol";
/// @title GBMCurrencyFacet Contract
/// @author Guillaume Gonnaud
contract GBMCurrencyFacet is IGBMEventsFacet, IGBMCurrencyFacet {
GBMStorage internal s;
modifier onlyAdmin() {
require(msg.sender == s.GBMAdminAccount || msg.sender == LibDiamond.contractOwner(), "Function only callable by the GBM admin");
_;
}
/// @notice Set the name of currency associated with the currency index
/// @dev Will throw if currencyIndex == 0. Will throw if not called by the GBM admin.
/// @param currencyIndex The index of the currency you wish to change the name of
/// @param currencyName The new name of the currency
function setCurrencyName(uint256 currencyIndex, string calldata currencyName) external onlyAdmin {
require(currencyIndex != 0, "currencyIndex cannot be equal to 0");
s.currencyNames[currencyIndex] = currencyName;
emit Currency_NameUpdated(currencyIndex, currencyName);
}
/// @notice Set the address of the ERC-20 currency associated with the currency index
/// @dev Will throw if currencyIndex == 0. Will throw if not called by the GBM admin.
/// To set to native chain currency, set currencyAddress to 0x0.
/// @param currencyIndex The index of the currency you wish to change the address of
/// @param currencyAddress The address of the currency. If set to 0x0, it mean that the
/// currency is the native chain currency. eg : ETH on Etherum, MATIC on Polygon, etc...
function setCurrencyAddress(uint256 currencyIndex, address currencyAddress) external onlyAdmin{
require(currencyIndex != 0, "currencyIndex cannot be equal to 0");
if(currencyAddress != address(0)){
require(s.currencyIndex[currencyAddress] != currencyIndex, "Currency already registered");
}
s.currencyAddress[currencyIndex] = currencyAddress;
s.currencyIndex[currencyAddress] = currencyIndex;
emit Currency_AddressUpdated(currencyIndex, currencyAddress);
}
/// @notice Set the name of currency associated with the currency index
/// @dev Will throw if currencyIndex == 0. Will throw if not called by the GBM admin.
/// @param currencyIndex The index of the currency you wish to change the name of
/// @param currencyAddress The address of the currency. If set to 0x0, it mean that the
/// @param currencyName The new name of the currency
function setCurrencyAddressAndName(uint256 currencyIndex, address currencyAddress, string calldata currencyName) external onlyAdmin {
require(currencyIndex != 0, "currencyIndex cannot be equal to 0");
if(currencyAddress != address(0)){
require(s.currencyIndex[currencyAddress] != currencyIndex, "Currency already registered");
}
s.currencyAddress[currencyIndex] = currencyAddress;
s.currencyIndex[currencyAddress] = currencyIndex;
s.currencyNames[currencyIndex] = currencyName;
emit Currency_AddressUpdated(currencyIndex, currencyAddress);
emit Currency_NameUpdated(currencyIndex, currencyName);
}
/// @notice Set the currency to be used by default if no currency params are specified
/// @dev /!\ Will also impact live auctions. Beware of unforseen consequences.
/// @param currencyIndex The index of the currency you wish to be the new default one.
function setDefaultCurrency(uint256 currencyIndex) external onlyAdmin{
require(currencyIndex != 0, "currencyIndex cannot be equal to 0");
uint256 previousDefaultCurrency = s.defaultCurrency;
s.defaultCurrency = currencyIndex;
emit Currency_DefaultUpdated(previousDefaultCurrency,currencyIndex,s.currencyAddress[currencyIndex], s.currencyNames[currencyIndex]);
}
}
contracts/facets/GBMEscrowFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
import { IERC721TokenReceiver } from "../interfaces/IERC721TokenReceiver.sol";
import { IERC1155TokenReceiver } from "../interfaces/IERC1155TokenReceiver.sol";
import { IERC721 } from "../interfaces/IERC721.sol";
import { IERC1155 } from "../interfaces/IERC1155.sol";
import { GBMStorage } from "../libraries/GBM_Core.sol";
import { IGBMEventsFacet } from "../interfaces/facets/IGBMEventsFacet.sol";
/// @title GBMEscrowFacet Contract
/// @author Guillaume Gonnaud
contract GBMEscrowFacet is IGBMEventsFacet, IERC721TokenReceiver, IERC1155TokenReceiver {
GBMStorage internal s;
modifier reentrancyProtector() {
require(!s.reentrancySemaphore, "No Double Dip, kthxbye");
s.reentrancySemaphore = true;
_;
s.reentrancySemaphore = false;
}
function onERC721Received(address /* _operator */, address _from, uint256 _tokenID, bytes calldata /* _data */) external returns(bytes4) {
s.erc721tokensAddressAndIDToEscrower[msg.sender][_tokenID] = _from;
emit Escrow_ERC721Deposited(msg.sender, _tokenID, _from);
return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
}
function onERC1155Received(address /* _operator */, address _from, uint256 _id, uint256 _value, bytes calldata /* _data */) external returns(bytes4) {
s.erc1155tokensAddressAndIDToEscrowerAmount[msg.sender][_id][_from] += _value;
emit Escrow_ERC1155Deposited(msg.sender, _id, _value, _from);
return bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"));
}
function onERC1155BatchReceived(address /* _operator */, address _from, uint256[] calldata _ids, uint256[] calldata _values, bytes calldata /* _data */) external returns(bytes4) {
for (uint i; i < _ids.length; i++) {
s.erc1155tokensAddressAndIDToEscrowerAmount[msg.sender][_ids[i]][_from] += _values[i];
emit Escrow_ERC1155Deposited(msg.sender, _ids[i], _values[i], _from);
}
return bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"));
}
function withdrawEscrowed721(address nftContract, uint256 tokenID) reentrancyProtector() external {
require(s.erc721tokensAddressAndIDToEscrower[nftContract][tokenID] == msg.sender, "You did not deposit this token in escrow");
require(!s.erc721tokensAddressAndIDToUnderSale[nftContract][tokenID], "This token is currently under sale");
s.erc721tokensAddressAndIDToEscrower[nftContract][tokenID] = address(0x0);
//Prevent doing a stay in the same place move.
IERC721(nftContract).safeTransferFrom(address(this), msg.sender, tokenID);
emit Escrow_ERC721Withdrawn(nftContract, tokenID, msg.sender);
}
function withdrawEscrowed1155(address nftContract, uint256 tokenID, uint256 tokenAmount) reentrancyProtector() external {
require(
s.erc1155tokensAddressAndIDToEscrowerAmount[nftContract][tokenID][msg.sender] - s.erc1155tokensAddressAndIDToEscrowerUnderSaleAmount[nftContract][tokenID][msg.sender] >= tokenAmount,
"You did not deposit enough tokens in escrow");
s.erc1155tokensAddressAndIDToEscrowerAmount[nftContract][tokenID][msg.sender] = s.erc1155tokensAddressAndIDToEscrowerAmount[nftContract][tokenID][msg.sender] - tokenAmount;
//Prevent doing a stay in the same place move.
IERC721(nftContract).safeTransferFrom(address(this), msg.sender, tokenID);
emit Escrow_ERC1155Withdrawn(nftContract, tokenID, tokenAmount, msg.sender);
}
}
contracts/facets/GBMGettersFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
import { IGBMGettersFacet } from "../interfaces/facets/IGBMGettersFacet.sol";
import "../libraries/GBM_Core.sol";
import { IGBMEventsFacet } from "../interfaces/facets/IGBMEventsFacet.sol";
import { LibDiamond } from "../libraries/LibDiamond.sol";
/// @title GBMGettersFacet Contract
/// @author Guillaume Gonnaud
contract GBMGettersFacet is IGBMGettersFacet {
GBMStorage internal s;
function getDOMAIN_SEPARATOR() external view returns (bytes32) {
return keccak256(abi.encode(EIP712_DOMAIN_TYPEHASH, keccak256("GBM dApp"), keccak256("1"), block.chainid, address(this)));
}
function getGBMAdminAccount() external view returns (address){ return s.GBMAdminAccount;}
function getGBMBackendSigner() external view returns (address){ return s.GBMBackendSigner;}
// =============================================================================================================
// Currencies
/// @notice Get the name of currency associated with the currency index
/// @dev Will return the default value if currencyIndex == 0
/// @param currencyIndex The index of the currency you wish to know the name of
/// @return currencyName The name of the currency
function getCurrencyName(uint256 currencyIndex) external view returns (string memory){
//If index = 0 assume default setting
if(currencyIndex == 0){
return s.currencyNames[s.defaultCurrency];
}
return s.currencyNames[currencyIndex];
}
/// @notice Get the address of currency associated with the currency index
/// @dev If currency is the native one, will return 0x0
/// @param currencyIndex The index of the currency you wish to know the address of. If you give index 0, this is the default currency.
/// @return currencyAddress The address of the currency
function getCurrencyAddress(uint256 currencyIndex) external view returns (address){
//If index = 0 assume default setting
if(currencyIndex == 0){
return s.currencyAddress[s.defaultCurrency];
}
return s.currencyAddress[currencyIndex];
}
/// @notice Get the index of currency to be used by default if no currency params are specified
/// @return currencyIndex The index of the default currency
function getDefaultCurrency() external view returns (uint256){ return s.defaultCurrency; }
// =============================================================================================================
// Fees
function getCurrencyIndex(address currencyAddress) external view returns (uint256){ return s.currencyIndex[currencyAddress];}
function getGBMProtocolFeeAuction() external view returns (uint256){ return s.GBMProtocolFeeAuction;}
function getGBMProtocolFeeFixedPrice() external view returns (uint256){ return s.GBMProtocolFeeFixedPrice;}
function getGBMProtocolFeeSwap() external view returns (uint256){ return s.GBMProtocolFeeSwap;}
function getGBMProtocolWallet() external view returns (address){ return s.GBMProtocolWallet;}
function getAHFeeAuction(uint256 _auctionHouseID) external view returns (uint256){ return s.auctionHouseIDToFeeAuction[_auctionHouseID];}
function getAHFeeFixedPrice(uint256 _auctionHouseID) external view returns (uint256){ return s.auctionHouseIDToFeeFixedPrice[_auctionHouseID];}
function getAHFeeSwap(uint256 _auctionHouseID) external view returns (uint256){ return s.auctionHouseIDToFeeSwap[_auctionHouseID];}
function getAHFeeRecipient(uint256 _auctionHouseID) external view returns (address){ return s.auctionHouseIDToFeeRecipient[_auctionHouseID];}
// =============================================================================================================
// Bidding Presets
function getBiddingPresetName(uint256 _BiddingPresetID) external view returns (string memory){ return s.biddingPresetIDToName[_BiddingPresetID];}
function getBiddingPresetStepMin(uint256 _BiddingPresetID) external view returns (uint256){ return s.biddingPresetIDToStepMin[_BiddingPresetID];}
function getBiddingPresetIncentiveMin(uint256 _BiddingPresetID) external view returns (uint256){ return s.biddingPresetIDToIncentiveMin[_BiddingPresetID];}
function getBiddingPresetIncentiveMax(uint256 _BiddingPresetID) external view returns (uint256){ return s.biddingPresetIDToIncentiveMax[_BiddingPresetID]; }
function getBiddingPresetIncentiveGrowthMultiplier(uint256 _BiddingPresetID) external view returns (uint256){ return s.biddingPresetIDToIncentiveGrowthMultiplier[_BiddingPresetID];}
// =============================================================================================================
// Escrow
/// @notice Get the depositor of a 721 token
/// @param tokenAddress The address of the token that was deposited
/// @param tokenID The tokenID of the deposited token
/// @return depositor The address of the depositor
function getERC721Token_depositor(address tokenAddress, uint256 tokenID) external view returns(address){
return s.erc721tokensAddressAndIDToEscrower[tokenAddress][tokenID];
}
/// @notice Get the sale status of a 721 token
/// @param tokenAddress The address of the token that was deposited
/// @param tokenID The tokenID of the deposited token
/// @return underSale True if the token is currently under sale
function getERC721Token_underSale(address tokenAddress, uint256 tokenID) external view returns(bool){
return s.erc721tokensAddressAndIDToUnderSale[tokenAddress][tokenID];
}
/// @notice Get the deposited amount of a 1155 token
/// @param tokenAddress The address of the token that was deposited
/// @param tokenID The tokenID of the deposited token
/// @param depositor The address of the depositor
/// @return amount The amount deposited by the specified depostior
function getERC1155Token_depositor(address tokenAddress, uint256 tokenID, address depositor) external view returns(uint256){
return s.erc1155tokensAddressAndIDToEscrowerAmount[tokenAddress][tokenID][depositor];
}
/// @notice Get the deposited amount of a 1155 token under sale
/// @param tokenAddress The address of the token that were deposited and are under sale
/// @param tokenID The tokenID of the deposited token and are under sale
/// @param depositor The address of the depositor
/// @return amount The amount under sale by the specified depostior
function getERC1155Token_UnderSaleByDepositor(address tokenAddress, uint256 tokenID, address depositor) external view returns(uint256){
return s.erc1155tokensAddressAndIDToEscrowerUnderSaleAmount[tokenAddress][tokenID][depositor];
}
// =============================================================================================================
// Marketplaces specific stuff
function getAHAdmin(uint256 _auctionHouseID) external view returns (address){ return s.auctionHouseIDToAdmin[_auctionHouseID];}
function getAHDelegate(uint256 _auctionHouseID) external view returns (address){ return s.auctionHouseIDToDelegate[_auctionHouseID];}
function getAHName(uint256 _auctionHouseID) external view returns (string memory){ return s.auctionHouseIDToName[_auctionHouseID];}
function getAHDomainName(uint256 _auctionHouseID) external view returns (string memory){ return s.auctionHouseIDToDomainName[_auctionHouseID];}
function getAHAuctionsCreated(uint256 _auctionHouseID) external view returns (uint256){ return s.auctionHouseIDToAuctionsCreated[_auctionHouseID];}
function getAHAuctionsSettled(uint256 _auctionHouseID) external view returns (uint256){ return s.auctionHouseIDToAuctionsSettled[_auctionHouseID];}
function getAHisEnabledAuctions(uint256 _auctionHouseID) external view returns (bool){ return s.auctionHouseIDToAuctionsEnabled[_auctionHouseID];}
function getAHisEnabledFixedPriceSales(uint256 _auctionHouseID) external view returns (bool){ return s.auctionHouseIDToFixedPriceEnabled[_auctionHouseID];}
function getAHisEnabledSwaps(uint256 _auctionHouseID) external view returns (bool){ return s.auctionHouseIDToSwapEnabled[_auctionHouseID];}
function getAHisCurrencyAllowed(uint256 _auctionHouseID, address _currency) external view returns (bool){ return s.auctionHouseIDToCurrencyAddressToAllowed[_auctionHouseID][_currency];}
// =============================================================================================================
// Auction specific stuff
function getSaleTokenKind(uint256 _auctionHouseID, uint256 _saleID) external view returns (bytes4){ return s.auctionHouseIDToSaleIDToTokenKind[_auctionHouseID][_saleID];}
function getSaleKind(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256){ return s.auctionHouseIDToSaleIDToSaleKind[_auctionHouseID][_saleID];}
function getSaleTokenContract(uint256 _auctionHouseID, uint256 _saleID) external view returns (address){ return s.auctionHouseIDToSaleIDToTokenContract[_auctionHouseID][_saleID];}
function getSaleTokenID(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256){ return s.auctionHouseIDToSaleIDToTokenID[_auctionHouseID][_saleID];}
function getSaleGBMPresetID(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256){ return s.auctionHouseIDToSaleIDToGBMPresetID[_auctionHouseID][_saleID];}
function getSaleCurrency(uint256 _auctionHouseID, uint256 _saleID) external view returns (address){ return s.auctionHouseIDToSaleIDToCurrency[_auctionHouseID][_saleID];}
function getSaleStartTimestamp(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256){ return s.auctionHouseIDToSaleIDToStartTimestamp[_auctionHouseID][_saleID];}
function getSaleEndTimestamp(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256){ return s.auctionHouseIDToSaleIDToEndTimestamp[_auctionHouseID][_saleID];}
function getSaleHammerTimeDuration(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256){ return s.auctionHouseIDToSaleIDToHammerTimeDuration[_auctionHouseID][_saleID];}
function getSaleCancellationDuration(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256){ return s.auctionHouseIDToSaleIDToCancellationDuration[_auctionHouseID][_saleID];}
function getSalePrepaidAmount(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256){ return s.auctionHouseIDToSaleIDToPrepaidAmount[_auctionHouseID][_saleID];}
function getSaleStartingBid(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256){ return s.auctionHouseIDToSaleIDToStartingBid[_auctionHouseID][_saleID];}
function getSaleAmountForSale(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256){ return s.auctionHouseIDToSaleIDToAmountForSale[_auctionHouseID][_saleID];}
function getSaleSeller(uint256 _auctionHouseID, uint256 _saleID) external view returns (address){ return s.auctionHouseIDToSaleIDToSeller[_auctionHouseID][_saleID];}
function getSaleNumberOfBids(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256){ return s.auctionHouseIDToSaleIDToNumberOfBids[_auctionHouseID][_saleID];}
function getSaleAuctionDebt(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256){ return s.auctionHouseIDToSaleIDToAuctionDebt[_auctionHouseID][_saleID];}
function getSaleBidValue(uint256 _auctionHouseID, uint256 _saleID, uint256 _bidIndex) external view returns (uint256){ return s.auctionHouseIDToSaleIDToBidIndexToValues[_auctionHouseID][_saleID][_bidIndex];}
function getSaleBidIncentive(uint256 _auctionHouseID, uint256 _saleID, uint256 _bidIndex) external view returns (uint256){ return s.auctionHouseIDToSaleIDToBidIndexToIncentives[_auctionHouseID][_saleID][_bidIndex];}
function getSaleBidder(uint256 _auctionHouseID, uint256 _saleID, uint256 _bidIndex) external view returns (address){ return s.auctionHouseIDToSaleIDToBidIndexToBidder[_auctionHouseID][_saleID][_bidIndex];}
function getSaleHighestBidder(uint256 _auctionHouseID, uint256 _saleID) external view returns (address){
uint256 numberOfBids = s.auctionHouseIDToSaleIDToNumberOfBids[_auctionHouseID][_saleID];
if(numberOfBids == 0) return address(0);
return s.auctionHouseIDToSaleIDToBidIndexToBidder[_auctionHouseID][_saleID][numberOfBids]; //Index start at 1 for bids, so the highest bidder is at the index of numberOfBids, not numberOfBids - 1
}
}contracts/facets/GBMMarketPlaceAdminFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
import "../libraries/GBM_Core.sol";
import { IGBMEventsFacet } from "../interfaces/facets/IGBMEventsFacet.sol";
import { LibDiamond } from "../libraries/LibDiamond.sol";
import { IGBMMarketPlaceAdminFacet } from "../interfaces/facets/IGBMMarketPlaceAdminFacet.sol";
/// @title GBMMarketPlaceAdminFacet Contract
/// @author Guillaume Gonnaud
contract GBMMarketPlaceAdminFacet is IGBMEventsFacet, IGBMMarketPlaceAdminFacet {
GBMStorage internal s;
modifier onlyMarketplaceAdmin(uint256 _marketplaceID) {
require(msg.sender == s.GBMAdminAccount || msg.sender == LibDiamond.contractOwner() || msg.sender == s.auctionHouseIDToAdmin[_marketplaceID], "Function only callable by the GBM admin");
_;
}
modifier onlyMarketplaceAdminOrDelegate(uint256 _marketplaceID) {
require(msg.sender == s.GBMAdminAccount || msg.sender == LibDiamond.contractOwner() || msg.sender == s.auctionHouseIDToAdmin[_marketplaceID] || msg.sender == s.auctionHouseIDToDelegate[_marketplaceID], "Function only callable by the GBM admin or delegate");
_;
}
modifier reentrancyProtector() {
require(!s.reentrancySemaphore, "No Double Dip, kthxbye");
s.reentrancySemaphore = true;
_;
s.reentrancySemaphore = false;
}
modifier noLiveAuctions(uint256 _marketplaceID){
require(s.auctionHouseIDToAuctionsCreated[_marketplaceID] == s.auctionHouseIDToAuctionsSettled[_marketplaceID], "Not callable while not all sales are settled or cancelled");
_;
}
function getDOMAIN_SEPARATOR() internal view returns (bytes32) {
return keccak256(abi.encode(EIP712_DOMAIN_TYPEHASH, keccak256("GBM dApp"), keccak256("1"), block.chainid, address(this)));
}
function setMarketplaceAdmin(uint256 _marketplaceID, address _newAdmin) onlyMarketplaceAdmin(_marketplaceID) external {
s.auctionHouseIDToAdmin[_marketplaceID] = _newAdmin;
emit Marketplace_Admin_Updated(_marketplaceID, _newAdmin);
}
function setMarketplaceDelegate(uint256 _marketplaceID, address _newDelegate) onlyMarketplaceAdminOrDelegate(_marketplaceID) external {
s.auctionHouseIDToDelegate[_marketplaceID] = _newDelegate;
emit Marketplace_Delegate_Updated(_marketplaceID, _newDelegate);
}
function setMarketplaceFees(uint256 _marketplaceID, uint256 _auctionFee, uint256 _fixedPriceFee, uint256 _swapFee, address _feeRecipient) onlyMarketplaceAdminOrDelegate(_marketplaceID) noLiveAuctions(_marketplaceID) external {
s.auctionHouseIDToFeeAuction[_marketplaceID] = _auctionFee;
s.auctionHouseIDToFeeFixedPrice[_marketplaceID] = _fixedPriceFee;
s.auctionHouseIDToFeeSwap[_marketplaceID] = _swapFee;
s.auctionHouseIDToFeeRecipient[_marketplaceID] = _feeRecipient;
emit Marketplace_Fees_Updated(_marketplaceID, _auctionFee, _fixedPriceFee, _swapFee, _feeRecipient);
}
function setAllowedCurrency(uint256 _marketplaceID, address _currency, bool _isAllowed) onlyMarketplaceAdminOrDelegate(_marketplaceID) external {
require(s.currencyIndex[_currency] != 0, "Currency not enabled for this Dapp");
s.auctionHouseIDToCurrencyAddressToAllowed[_marketplaceID][_currency] = _isAllowed;
emit Currency_AllowedOnMarketplace(_marketplaceID, s.currencyIndex[_currency], _currency, _isAllowed);
}
function setAllowedCurrencies(uint256 _marketplaceID, address[] calldata _currencies, bool[] calldata _isAllowed) onlyMarketplaceAdminOrDelegate(_marketplaceID) external {
require(_currencies.length == _isAllowed.length, "Array lenght missmatch in arguments");
for(uint i; i < _currencies.length; i++){
require(s.currencyIndex[_currencies[i]] != 0, "Currency not enabled for this Dapp");
s.auctionHouseIDToCurrencyAddressToAllowed[_marketplaceID][_currencies[i]] = _isAllowed[i];
emit Currency_AllowedOnMarketplace(_marketplaceID, s.currencyIndex[_currencies[i]], _currencies[i], _isAllowed[i]);
}
}
function setAuctionRegistrationAllowed(uint256 _marketplaceID, bool _allowAuctions) onlyMarketplaceAdminOrDelegate(_marketplaceID) external {
s.auctionHouseIDToAuctionsEnabled[_marketplaceID] = _allowAuctions;
emit Marketplace_RegistrationAuctions_Allowed(_marketplaceID, _allowAuctions);
}
function setFixedPriceRegistrationAllowed(uint256 _marketplaceID, bool _allowFixedPrices) onlyMarketplaceAdminOrDelegate(_marketplaceID) external {
s.auctionHouseIDToFixedPriceEnabled[_marketplaceID] = _allowFixedPrices;
emit Marketplace_RegistrationFixedPrice_Allowed(_marketplaceID, _allowFixedPrices);
}
function setSwapRegistrationAllowed(uint256 _marketplaceID, bool _allowSwaps) onlyMarketplaceAdminOrDelegate(_marketplaceID) external {
require(false, "Feature not implemented yet");
s.auctionHouseIDToSwapEnabled[_marketplaceID] = _allowSwaps;
emit Marketplace_RegistrationSwaps_Allowed(_marketplaceID, _allowSwaps);
}
function setMarketplaceName(uint256 _marketplaceID, string calldata _name) onlyMarketplaceAdminOrDelegate(_marketplaceID) external {
s.auctionHouseIDToName[_marketplaceID] = _name;
emit Marketplace_Name_Updated(_marketplaceID, _name);
}
function setMarketplaceDomainName(uint256 _marketplaceID, string calldata _domainName, bytes calldata _authorisation) onlyMarketplaceAdminOrDelegate(_marketplaceID) external {
isSetMarketplaceDomainNameAllowed(msg.sender, _marketplaceID, _domainName, _authorisation);
s.auctionHouseIDToDomainName[_marketplaceID] = _domainName;
emit Marketplace_DomainName_Updated(_marketplaceID, _domainName);
}
function generateAdminSetDomainNameHash(address _admin, uint256 _marketplaceID, string calldata _newDomainName) public pure returns (bytes32) {
return keccak256(
abi.encode(
ADMINSETDOMAINNAME_SIGNATURE_TYPEHASH,
_admin,
_marketplaceID,
keccak256(abi.encodePacked(_newDomainName))
)
);
}
function isSetMarketplaceDomainNameAllowed(address _admin, uint256 _marketplaceID, string calldata _newDomainName, bytes calldata _authorisation) internal view returns (bool) {
bytes32 hash = generateAdminSetDomainNameHash(_admin, _marketplaceID, _newDomainName);
(uint8 _v, bytes32 _r, bytes32 _s) = splitSignature(abi.encodePacked(_authorisation));
require(verify(s.GBMBackendSigner, hash, _v, _r, _s), "Invalid SetMarketplaceDomainName authorization");
return true;
}
/// signature methods.
function splitSignature(bytes memory sig) internal pure returns (uint8 v_, bytes32 r_, bytes32 s_) {
require(sig.length == 65);
assembly {
// first 32 bytes, after the length prefix.
r_ := mload(add(sig, 32))
// second 32 bytes.
s_ := mload(add(sig, 64))
// final byte (first byte of the next 32 bytes).
v_ := byte(0, mload(add(sig, 96)))
}
return (v_, r_, s_);
}
function verify(address _signee, bytes32 _hash, uint8 _v, bytes32 _r, bytes32 _s) internal view returns (bool){
// Note: we need to use `encodePacked` here instead of `encode`.
bytes32 digest = keccak256(abi.encodePacked(
"\x19\x01",
getDOMAIN_SEPARATOR(),
_hash
));
return ecrecover(digest, _v, _r, _s) == _signee;
}
}contracts/facets/GBMRegisterMarketplaceFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
import "../libraries/GBM_Core.sol";
import { IGBMEventsFacet } from "../interfaces/facets/IGBMEventsFacet.sol";
import { LibDiamond } from "../libraries/LibDiamond.sol";
import { IGBMRegisterMarketplaceFacet } from "../interfaces/facets/IGBMRegisterMarketplaceFacet.sol";
import { IERC20 } from "../interfaces/IERC20.sol";
/// @title GBMRegisterMarketplaceFacet Contract
/// @author Guillaume Gonnaud
contract GBMRegisterMarketplaceFacet is IGBMEventsFacet, IGBMRegisterMarketplaceFacet {
GBMStorage internal s;
function getDOMAIN_SEPARATOR() internal view returns (bytes32) {
return keccak256(abi.encode(EIP712_DOMAIN_TYPEHASH, keccak256("GBM dApp"), keccak256("1"), block.chainid, address(this)));
}
modifier onlyMarketplaceAdmin(uint256 _marketplaceID) {
require(msg.sender == s.GBMAdminAccount || msg.sender == LibDiamond.contractOwner() || msg.sender == s.auctionHouseIDToAdmin[_marketplaceID], "Function only callable by the Marketplace Admin");
_;
}
modifier onlyMarketplaceAdminOrDelegate(uint256 _marketplaceID) {
require(msg.sender == s.GBMAdminAccount || msg.sender == LibDiamond.contractOwner() || msg.sender == s.auctionHouseIDToAdmin[_marketplaceID] || msg.sender == s.auctionHouseIDToDelegate[_marketplaceID], "Function only callable by the Marketplace Admin or delegate");
_;
}
modifier reentrancyProtector() {
require(!s.reentrancySemaphore, "No Double Dip, kthxbye");
s.reentrancySemaphore = true;
_;
s.reentrancySemaphore = false;
}
//TODO : Delete once signature confirmed working
function registerAMarketPlaceSignatureTest(uint256 _marketplaceID, string calldata _name, string calldata _domainName, address _currency, uint256 _paidAmount, bytes calldata _authorisation) reentrancyProtector() external payable {
//Build and verify signature
isRegistrationAuthorized(_marketplaceID, _name, _domainName, _currency, _paidAmount, _authorisation);
}
function registerAMarketPlace(uint256 _marketplaceID, string calldata _name, string calldata _domainName, address _currency, uint256 _paidAmount, bytes calldata _authorisation) reentrancyProtector() external payable {
require(s.auctionHouseIDToAdmin[_marketplaceID] == address(0) && s.auctionHouseIDToAuctionsCreated[_marketplaceID] == 0, "Marketplace already registered");
//Build and verify signature
isRegistrationAuthorized(_marketplaceID, _name, _domainName, _currency, _paidAmount, _authorisation);
//assign variables and emit events
emit Marketplace_Registered(_marketplaceID, _currency, _paidAmount);
s.auctionHouseIDToAdmin[_marketplaceID] = msg.sender;
emit Marketplace_Admin_Updated(_marketplaceID, msg.sender);
s.auctionHouseIDToName[_marketplaceID] = _name;
s.auctionHouseIDToDomainName[_marketplaceID] = _domainName;
emit Marketplace_Name_Updated(_marketplaceID, _name);
emit Marketplace_DomainName_Updated(_marketplaceID, _domainName);
//get the money
//Case of base currency
if(_currency == address(0)){
require(msg.value == _paidAmount, "Not enough base currency was sent to pay for the marketplace creation");
if(s.GBMProtocolWallet != address(0) && _paidAmount != 0){
sendbaseCurrency(s.GBMProtocolWallet, _paidAmount);
}
} else { //Case ERC20
if(_paidAmount != 0){
IERC20(_currency).transferFrom(msg.sender, address(this), _paidAmount);
if(s.GBMProtocolWallet != address(0)){
IERC20(_currency).transfer(s.GBMProtocolWallet, _paidAmount);
}
}
}
}
//Generates a hash for an incoming data to store
function generateRegistrationHash(uint256 _marketplaceID, string memory _name, string memory _domainName, address _currency, uint256 _paidAmount) internal view returns(bytes32){
return keccak256(
abi.encode(
REGISTERMARKETPLACE_SIGNATURE_TYPEHASH,
msg.sender,
_marketplaceID,
keccak256(bytes(_name)),
keccak256(bytes(_domainName)),
_currency,
_paidAmount
)
);
}
/// signature methods.
function splitSignature(bytes memory sig) internal pure returns (uint8 v_, bytes32 r_, bytes32 s_) {
require(sig.length == 65);
assembly {
// first 32 bytes, after the length prefix.
r_ := mload(add(sig, 32))
// second 32 bytes.
s_ := mload(add(sig, 64))
// final byte (first byte of the next 32 bytes).
v_ := byte(0, mload(add(sig, 96)))
}
return (v_, r_, s_);
}
function verify(address _signee, bytes32 _hash, uint8 _v, bytes32 _r, bytes32 _s) internal view returns (bool){
// Note: we need to use `encodePacked` here instead of `encode`.
bytes32 digest = keccak256(abi.encodePacked(
"\x19\x01",
getDOMAIN_SEPARATOR(),
_hash
));
return ecrecover(digest, _v, _r, _s) == _signee;
}
function isRegistrationAuthorized(uint256 _marketplaceID, string calldata _name, string calldata _domainName, address _currency, uint256 _paidAmount, bytes calldata _authorisation) internal view returns (bool) {
bytes32 hash = generateRegistrationHash(_marketplaceID, _name, _domainName, _currency, _paidAmount);
(uint8 _v, bytes32 _r, bytes32 _s) = splitSignature(abi.encodePacked(_authorisation));
require(verify(s.GBMBackendSigner, hash, _v, _r, _s), "Invalid Registration authorization");
return true;
}
function sendbaseCurrency(address to, uint256 amount) internal {
if (amount == 0) { return; }
(bool succ, ) = to.call{value: amount}("");
require( succ, "Transfer failed on a normal wallet. Je beg your pardon ?");
}
}contracts/facets/GBMSettleAuctionFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
import "../libraries/GBM_Core.sol";
import { IGBMEventsFacet } from "../interfaces/facets/IGBMEventsFacet.sol";
import { LibDiamond } from "../libraries/LibDiamond.sol";
import { IGBMSettleAuctionFacet } from "../interfaces/facets/IGBMSettleAuctionFacet.sol";
import { IERC1155 } from "../interfaces/IERC1155.sol";
import { IERC721 } from "../interfaces/IERC721.sol";
import { IERC20 } from "../interfaces/IERC20.sol";
contract GBMSettleAuctionFacet is IGBMSettleAuctionFacet, IGBMEventsFacet {
GBMStorage internal s;
modifier reentrancyProtector() {
require(!s.reentrancySemaphore, "No Double Dip, kthxbye");
s.reentrancySemaphore = true;
_;
s.reentrancySemaphore = false;
}
/// @notice Settle an auction, transfer the funds to the seller and the NFT to the winning bidder.
/// @param _auctionHouseID The ID of the auction house where the auction took place.
/// @param _auctionID The ID of the auction to settle.
function settleAuction(uint256 _auctionHouseID, uint256 _auctionID) reentrancyProtector () external {
internal_settleAuction(_auctionHouseID, _auctionID);
}
function cancelAuction(uint256 _auctionHouseID, uint256 _auctionID) reentrancyProtector () external payable {
internal_cancelAuction(_auctionHouseID, _auctionID);
}
function internal_settleAuction(uint256 _auctionHouseID, uint256 _auctionID) internal {
require(s.auctionHouseIDToSaleIDToTokenKind[_auctionHouseID][_auctionID] != 0, "GBMSettleAuctionFacet: Auction not registered");
require(s.auctionHouseIDToSaleIDToSaleKind[_auctionHouseID][_auctionID] == 1, "GBMSettleAuctionFacet: Not an auction");
require(s.auctionHouseIDToSaleIDToSaleSettled[_auctionHouseID][_auctionID] == false, "GBMSettleAuctionFacet: Sale already claimed");
s.auctionHouseIDToSaleIDToSaleSettled[_auctionHouseID][_auctionID] = true;
uint256 tokendID = s.auctionHouseIDToSaleIDToTokenID[_auctionHouseID][_auctionID];
address tokenContract = s.auctionHouseIDToSaleIDToTokenContract[_auctionHouseID][_auctionID];
uint256 highestBidderIndex = s.auctionHouseIDToSaleIDToNumberOfBids[_auctionHouseID][_auctionID];
address highestBidder = s.auctionHouseIDToSaleIDToBidIndexToBidder[_auctionHouseID][_auctionID][highestBidderIndex];
address seller = s.auctionHouseIDToSaleIDToSeller[_auctionHouseID][_auctionID];
address currency = s.auctionHouseIDToSaleIDToCurrency[_auctionHouseID][_auctionID];
uint256 winbiddAmount = s.auctionHouseIDToSaleIDToBidIndexToValues[_auctionHouseID][_auctionID][highestBidderIndex];
uint256 amountForSale = s.auctionHouseIDToSaleIDToAmountForSale[_auctionHouseID][_auctionID];
//As long as there is no bids, the seller can claim the auction at any time
if(!(highestBidderIndex == 0 && msg.sender == seller)){
require(block.timestamp >= s.auctionHouseIDToSaleIDToEndTimestamp[_auctionHouseID][_auctionID] + s.auctionHouseIDToSaleIDToCancellationDuration[_auctionHouseID][_auctionID], "GBMSettleAuctionFacet: Auction not ended yet");
}
//Emitting the winning events
if(s.auctionHouseIDToSaleIDToTokenKind[_auctionHouseID][_auctionID] == ERC721){
emit Auction_721_Claimed(_auctionHouseID, _auctionID, tokenContract, tokendID, seller, winbiddAmount, currency, highestBidder);
} else {
emit Auction_1155_Claimed(_auctionHouseID, _auctionID, tokenContract, tokendID, amountForSale, seller, winbiddAmount, currency, highestBidder);
}
//Funds transfer
if(winbiddAmount > 0){
uint256 pot = winbiddAmount - s.auctionHouseIDToSaleIDToAuctionDebt[_auctionHouseID][_auctionID];
uint256 amountToProtocol = (winbiddAmount * s.GBMProtocolFeeAuction) / DECIMALSK;
uint256 amountToMarketplace = (winbiddAmount * s.auctionHouseIDToFeeAuction[_auctionHouseID]) / DECIMALSK;
pot = pot - amountToProtocol - amountToMarketplace;
if(currency == address(0)){
//Transfering the winning bid in native currency to the seller
emit Money_AuctionSettledProtocolFee(_auctionHouseID, _auctionID, seller, address(0), winbiddAmount, amountToProtocol, s.GBMProtocolWallet);
payable(s.GBMProtocolWallet).transfer(amountToProtocol);
emit Money_AuctionSettledMarketplaceFee(_auctionHouseID, _auctionID, seller, address(0), winbiddAmount, amountToMarketplace, s.auctionHouseIDToFeeRecipient[_auctionHouseID]);
payable(s.auctionHouseIDToFeeRecipient[_auctionHouseID]).transfer(amountToMarketplace);
emit Money_AuctionSettledSellerProceeds(_auctionHouseID, _auctionID, seller, address(0), winbiddAmount, pot);
payable(seller).transfer(pot);
} else {
//Transfering the winning bid in ERC20 to the seller
emit Money_AuctionSettledProtocolFee(_auctionHouseID, _auctionID, seller, currency, winbiddAmount, amountToProtocol, s.GBMProtocolWallet);
IERC20(currency).transfer(s.GBMProtocolWallet, amountToProtocol);
emit Money_AuctionSettledMarketplaceFee(_auctionHouseID, _auctionID, seller, currency, winbiddAmount, amountToMarketplace, s.auctionHouseIDToFeeRecipient[_auctionHouseID]);
IERC20(currency).transfer(s.auctionHouseIDToFeeRecipient[_auctionHouseID], amountToMarketplace);
emit Money_AuctionSettledSellerProceeds(_auctionHouseID, _auctionID, seller, currency, winbiddAmount, pot);
IERC20(currency).transfer(seller, pot);
}
} else {
//Returning token to seller if there is no bids
highestBidder = seller;
}
//Winning Token transfer
if(s.auctionHouseIDToSaleIDToTokenKind[_auctionHouseID][_auctionID] == ERC721){
//Transfer the 721 NFT to the winning bidder
IERC721(tokenContract).safeTransferFrom(address(this), highestBidder, tokendID);
//Unescrowing tokens in the records
s.erc721tokensAddressAndIDToEscrower[tokenContract][tokendID] = address(0);
s.erc721tokensAddressAndIDToUnderSale[tokenContract][tokendID] = false;
} else {
//Transfer the 1155 NFT to the winning bidder
IERC1155(tokenContract).safeTransferFrom(address(this), highestBidder, tokendID, amountForSale, "");
//Unescrowing tokens in the records
s.erc1155tokensAddressAndIDToEscrowerAmount[tokenContract][tokendID][seller] -= amountForSale;
s.erc1155tokensAddressAndIDToEscrowerUnderSaleAmount[tokenContract][tokendID][seller] -= amountForSale;
}
}
function internal_cancelAuction(uint256 _auctionHouseID, uint256 _auctionID) internal {
require(msg.sender == s.auctionHouseIDToSaleIDToSeller[_auctionHouseID][_auctionID], "GBMSettleAuctionFacet: Only the seller can cancel the auction");
uint256 numberOfBids = s.auctionHouseIDToSaleIDToNumberOfBids[_auctionHouseID][_auctionID];
//If there is no bids, just do a normal auction settlement
if(numberOfBids == 0){
internal_settleAuction(_auctionHouseID, _auctionID);
return;
}
require(s.auctionHouseIDToSaleIDToTokenKind[_auctionHouseID][_auctionID] != 0, "GBMSettleAuctionFacet: Auction not registered");
require(s.auctionHouseIDToSaleIDToSaleKind[_auctionHouseID][_auctionID] == 1, "GBMSettleAuctionFacet: Not an auction");
require(s.auctionHouseIDToSaleIDToSaleSettled[_auctionHouseID][_auctionID] == false, "GBMSettleAuctionFacet: Sale already claimed");
require(s.auctionHouseIDToSaleIDToEndTimestamp[_auctionHouseID][_auctionID] + s.auctionHouseIDToSaleIDToCancellationDuration[_auctionHouseID][_auctionID] > block.timestamp, "GBMSettleAuctionFacet: Cancellation period ended");
require(s.auctionHouseIDToSaleIDToEndTimestamp[_auctionHouseID][_auctionID] < block.timestamp, "GBMSettleAuctionFacet: Cancellation period not started");
s.auctionHouseIDToSaleIDToSaleSettled[_auctionHouseID][_auctionID] = true;
uint256 tokendID = s.auctionHouseIDToSaleIDToTokenID[_auctionHouseID][_auctionID];
address tokenContract = s.auctionHouseIDToSaleIDToTokenContract[_auctionHouseID][_auctionID];
address highestBidder = s.auctionHouseIDToSaleIDToBidIndexToBidder[_auctionHouseID][_auctionID][numberOfBids];
address seller = s.auctionHouseIDToSaleIDToSeller[_auctionHouseID][_auctionID];
address currency = s.auctionHouseIDToSaleIDToCurrency[_auctionHouseID][_auctionID];
uint256 winbiddAmount = s.auctionHouseIDToSaleIDToBidIndexToValues[_auctionHouseID][_auctionID][numberOfBids];
uint256 amountForSale = s.auctionHouseIDToSaleIDToAmountForSale[_auctionHouseID][_auctionID];
uint256 dueIncentives = s.auctionHouseIDToSaleIDToBidIndexToIncentives[_auctionHouseID][_auctionID][numberOfBids];
uint256 amountToProtocol = (winbiddAmount * s.GBMProtocolFeeAuction) / DECIMALSK;
uint256 amountToMarketplace = (winbiddAmount * s.auctionHouseIDToFeeAuction[_auctionHouseID]) / DECIMALSK;
uint256 debt = s.auctionHouseIDToSaleIDToAuctionDebt[_auctionHouseID][_auctionID] + dueIncentives + amountToProtocol + amountToMarketplace;
s.auctionHouseIDToSaleIDToAuctionDebt[_auctionHouseID][_auctionID] += dueIncentives;
if(s.auctionHouseIDToSaleIDToTokenKind[_auctionHouseID][_auctionID] == ERC721){
emit Auction_721_Cancelled(_auctionHouseID, _auctionID, tokenContract, tokendID, seller, winbiddAmount, currency, debt);
} else {
emit Auction_1155_Cancelled(_auctionHouseID, _auctionID, tokenContract, tokendID, amountForSale, seller, winbiddAmount, currency, debt);
}
//Capture the cancellation fee
//Case of a native currency : Eth, Matic, etc...
if (currency == address(0x0)) {
require(
msg.value == debt,
"The amount of currency sent with the bid do not match the bid"
);
emit Money_CancellationFee(_auctionHouseID, _auctionID, seller, address(0), debt);
} else {
// Case of an ERC20 token
//Transfer the money of the bidder to the GBM smart contract
IERC20(currency).transferFrom( msg.sender, address(this), debt);
emit Money_CancellationFee(_auctionHouseID, _auctionID, seller, currency, debt);
}
//Bid back to highest bidder
emit Bid_Displaced(
_auctionHouseID,
_auctionID,
numberOfBids,
highestBidder,
winbiddAmount,
dueIncentives
);
if (currency == address(0x0)) {
//Refund the highest bidder in native currency
(bool success, ) = highestBidder.call{value: winbiddAmount + dueIncentives}("");
require(success, "Refund to highest bidder failed");
emit Money_BidRefunded(
_auctionHouseID,
_auctionID,
highestBidder,
address(0),
winbiddAmount,
dueIncentives
);
} else {
//Refund the highest bidder in ERC20_winbiddAmount
IERC20(currency).transfer(highestBidder, winbiddAmount + dueIncentives);
emit Money_BidRefunded(
_auctionHouseID,
_auctionID,
highestBidder,
currency,
winbiddAmount,
dueIncentives
);
}
// Fees
if(currency == address(0)){
emit Money_AuctionSettledProtocolFee(_auctionHouseID, _auctionID, seller, address(0), winbiddAmount, amountToProtocol, s.GBMProtocolWallet);
payable(s.GBMProtocolWallet).transfer(amountToProtocol);
emit Money_AuctionSettledMarketplaceFee(_auctionHouseID, _auctionID, seller, address(0), winbiddAmount, amountToMarketplace, s.auctionHouseIDToFeeRecipient[_auctionHouseID]);
payable(s.auctionHouseIDToFeeRecipient[_auctionHouseID]).transfer(amountToMarketplace);
} else {
emit Money_AuctionSettledProtocolFee(_auctionHouseID, _auctionID, seller, currency, winbiddAmount, amountToProtocol, s.GBMProtocolWallet);
IERC20(currency).transfer(s.GBMProtocolWallet, amountToProtocol);
emit Money_AuctionSettledMarketplaceFee(_auctionHouseID, _auctionID, seller, currency, winbiddAmount, amountToMarketplace, s.auctionHouseIDToFeeRecipient[_auctionHouseID]);
IERC20(currency).transfer(s.auctionHouseIDToFeeRecipient[_auctionHouseID], amountToMarketplace);
}
//Token transfer back to the seller
if(s.auctionHouseIDToSaleIDToTokenKind[_auctionHouseID][_auctionID] == ERC721){
//Transfer the 721 NFT to the seller
IERC721(tokenContract).safeTransferFrom(address(this), seller, tokendID);
//Unescrowing tokens in the records
s.erc721tokensAddressAndIDToEscrower[tokenContract][tokendID] = address(0);
s.erc721tokensAddressAndIDToUnderSale[tokenContract][tokendID] = false;
} else {
//Transfer the 1155 NFT to the seller
IERC1155(tokenContract).safeTransferFrom(address(this), seller, tokendID, amountForSale, "");
//Unescrowing tokens in the records
s.erc1155tokensAddressAndIDToEscrowerAmount[tokenContract][tokendID][seller] -= amountForSale;
s.erc1155tokensAddressAndIDToEscrowerUnderSaleAmount[tokenContract][tokendID][seller] -= amountForSale;
}
}
}contracts/facets/OwnershipFacet.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.28;
import { LibDiamond } from "../libraries/LibDiamond.sol";
import { IERC173 } from "../interfaces/IERC173.sol";
/// @title OwnershipFacet
/// @author Guillaume Gonnaud
contract OwnershipFacet is IERC173 {
function transferOwnership(address _newOwner) external override {
LibDiamond.enforceIsContractOwner();
LibDiamond.setContractOwner(_newOwner);
}
function owner() external override view returns (address owner_) {
owner_ = LibDiamond.contractOwner();
}
}
contracts/interfaces/IDiamondCut.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/******************************************************************************\
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
/******************************************************************************/
interface IDiamondCut {
enum FacetCutAction {Add, Replace, Remove}
// Add=0, Replace=1, Remove=2
struct FacetCut {
address facetAddress;
FacetCutAction action;
bytes4[] functionSelectors;
}
/// @notice Add/replace/remove any number of functions and optionally execute
/// a function with delegatecall
/// @param _diamondCut Contains the facet addresses and function selectors
/// @param _init The address of the contract or facet to execute _calldata
/// @param _calldata A function call, including function selector and arguments
/// _calldata is executed with delegatecall on _init
function diamondCut(
FacetCut[] calldata _diamondCut,
address _init,
bytes calldata _calldata
) external;
event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata);
}
contracts/interfaces/IDiamondLoupe.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/******************************************************************************\
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
/******************************************************************************/
// A loupe is a small magnifying glass used to look at diamonds.
// These functions look at diamonds
interface IDiamondLoupe {
/// These functions are expected to be called frequently
/// by tools.
struct Facet {
address facetAddress;
bytes4[] functionSelectors;
}
/// @notice Gets all facet addresses and their four byte function selectors.
/// @return facets_ Facet
function facets() external view returns (Facet[] memory facets_);
/// @notice Gets all the function selectors supported by a specific facet.
/// @param _facet The facet address.
/// @return facetFunctionSelectors_
function facetFunctionSelectors(address _facet) external view returns (bytes4[] memory facetFunctionSelectors_);
/// @notice Get all the facet addresses used by a diamond.
/// @return facetAddresses_
function facetAddresses() external view returns (address[] memory facetAddresses_);
/// @notice Gets the facet that supports the given selector.
/// @dev If facet is not found return address(0).
/// @param _functionSelector The function selector.
/// @return facetAddress_ The facet address.
function facetAddress(bytes4 _functionSelector) external view returns (address facetAddress_);
}
contracts/interfaces/IERC1155.sol
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.8.28;
/// @title ERC-1155 Multi Token Standard
/// @dev ee https://eips.ethereum.org/EIPS/eip-1155
/// The ERC-165 identifier for this interface is 0xd9b67a26.
interface IERC1155 /* is ERC165 */ {
/**
@dev Either `TransferSingle` or `TransferBatch` MUST emit when tokens are transferred, including zero value transfers as well as minting or burning (see "Safe Transfer Rules" section of the standard).
The `_operator` argument MUST be the address of an account/contract that is approved to make the transfer (SHOULD be msg.sender).
The `_from` argument MUST be the address of the holder whose balance is decreased.
The `_to` argument MUST be the address of the recipient whose balance is increased.
The `_id` argument MUST be the token type being transferred.
The `_value` argument MUST be the number of tokens the holder balance is decreased by and match what the recipient balance is increased by.
When minting/creating tokens, the `_from` argument MUST be set to `0x0` (i.e. zero address).
When burning/destroying tokens, the `_to` argument MUST be set to `0x0` (i.e. zero address).
*/
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _value);
/**
@dev Either `TransferSingle` or `TransferBatch` MUST emit when tokens are transferred, including zero value transfers as well as minting or burning (see "Safe Transfer Rules" section of the standard).
The `_operator` argument MUST be the address of an account/contract that is approved to make the transfer (SHOULD be msg.sender).
The `_from` argument MUST be the address of the holder whose balance is decreased.
The `_to` argument MUST be the address of the recipient whose balance is increased.
The `_ids` argument MUST be the list of tokens being transferred.
The `_values` argument MUST be the list of number of tokens (matching the list and order of tokens specified in _ids) the holder balance is decreased by and match what the recipient balance is increased by.
When minting/creating tokens, the `_from` argument MUST be set to `0x0` (i.e. zero address).
When burning/destroying tokens, the `_to` argument MUST be set to `0x0` (i.e. zero address).
*/
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _values);
/**
@dev MUST emit when approval for a second party/operator address to manage all tokens for an owner address is enabled or disabled (absence of an event assumes disabled).
*/
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/**
@dev MUST emit when the URI is updated for a token ID.
URIs are defined in RFC 3986.
The URI MUST point to a JSON file that conforms to the "ERC-1155 Metadata URI JSON Schema".
*/
event URI(string _value, uint256 indexed _id);
/**
@notice Transfers `_value` amount of an `_id` from the `_from` address to the `_to` address specified (with safety call).
@dev Caller must be approved to manage the tokens being transferred out of the `_from` account (see "Approval" section of the standard).
MUST revert if `_to` is the zero address.
MUST revert if balance of holder for token `_id` is lower than the `_value` sent.
MUST revert on any other error.
MUST emit the `TransferSingle` event to reflect the balance change (see "Safe Transfer Rules" section of the standard).
After the above conditions are met, this function MUST check if `_to` is a smart contract (e.g. code size > 0). If so, it MUST call `onERC1155Received` on `_to` and act appropriately (see "Safe Transfer Rules" section of the standard).
@param _from Source address
@param _to Target address
@param _id ID of the token type
@param _value Transfer amount
@param _data Additional data with no specified format, MUST be sent unaltered in call to `onERC1155Received` on `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes calldata _data) external;
/**
@notice Transfers `_values` amount(s) of `_ids` from the `_from` address to the `_to` address specified (with safety call).
@dev Caller must be approved to manage the tokens being transferred out of the `_from` account (see "Approval" section of the standard).
MUST revert if `_to` is the zero address.
MUST revert if length of `_ids` is not the same as length of `_values`.
MUST revert if any of the balance(s) of the holder(s) for token(s) in `_ids` is lower than the respective amount(s) in `_values` sent to the recipient.
MUST revert on any other error.
MUST emit `TransferSingle` or `TransferBatch` event(s) such that all the balance changes are reflected (see "Safe Transfer Rules" section of the standard).
Balance changes and events MUST follow the ordering of the arrays (_ids[0]/_values[0] before _ids[1]/_values[1], etc).
After the above conditions for the transfer(s) in the batch are met, this function MUST check if `_to` is a smart contract (e.g. code size > 0). If so, it MUST call the relevant `ERC1155TokenReceiver` hook(s) on `_to` and act appropriately (see "Safe Transfer Rules" section of the standard).
@param _from Source address
@param _to Target address
@param _ids IDs of each token type (order and length must match _values array)
@param _values Transfer amounts per token type (order and length must match _ids array)
@param _data Additional data with no specified format, MUST be sent unaltered in call to the `ERC1155TokenReceiver` hook(s) on `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _values, bytes calldata _data) external;
/**
@notice Get the balance of an account's tokens.
@param _owner The address of the token holder
@param _id ID of the token
@return The _owner's balance of the token type requested
*/
function balanceOf(address _owner, uint256 _id) external view returns (uint256);
/**
@notice Get the balance of multiple account/token pairs
@param _owners The addresses of the token holders
@param _ids ID of the tokens
@return The _owner's balance of the token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] calldata _owners, uint256[] calldata _ids) external view returns (uint256[] memory);
/**
@notice Enable or disable approval for a third party ("operator") to manage all of the caller's tokens.
@dev MUST emit the ApprovalForAll event on success.
@param _operator Address to add to the set of authorized operators
@param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
@notice Queries the approval status of an operator for a given owner.
@param _owner The owner of the tokens
@param _operator Address of authorized operator
@return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator) external view returns (bool);
}
contracts/interfaces/IERC1155TokenReceiver.sol
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.8.28;
/**
Note: The ERC-165 identifier for this interface is 0x4e2312e0.
*/
interface IERC1155TokenReceiver {
/**
@notice Handle the receipt of a single ERC1155 token type.
@dev An ERC1155-compliant smart contract MUST call this function on the token recipient contract, at the end of a `safeTransferFrom` after the balance has been updated.
This function MUST return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` (i.e. 0xf23a6e61) if it accepts the transfer.
This function MUST revert if it rejects the transfer.
Return of any other value than the prescribed keccak256 generated value MUST result in the transaction being reverted by the caller.
@param _operator The address which initiated the transfer (i.e. msg.sender)
@param _from The address which previously owned the token
@param _id The ID of the token being transferred
@param _value The amount of tokens being transferred
@param _data Additional data with no specified format
@return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
*/
function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4);
/**
@notice Handle the receipt of multiple ERC1155 token types.
@dev An ERC1155-compliant smart contract MUST call this function on the token recipient contract, at the end of a `safeBatchTransferFrom` after the balances have been updated.
This function MUST return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` (i.e. 0xbc197c81) if it accepts the transfer(s).
This function MUST revert if it rejects the transfer(s).
Return of any other value than the prescribed keccak256 generated value MUST result in the transaction being reverted by the caller.
@param _operator The address which initiated the batch transfer (i.e. msg.sender)
@param _from The address which previously owned the token
@param _ids An array containing ids of each token being transferred (order and length must match _values array)
@param _values An array containing amounts of each token being transferred (order and length must match _ids array)
@param _data Additional data with no specified format
@return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
*/
function onERC1155BatchReceived(address _operator, address _from, uint256[] calldata _ids, uint256[] calldata _values, bytes calldata _data) external returns(bytes4);
}contracts/interfaces/IERC165.sol
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.8.28;
/// @title IERC165
/// @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md
interface IERC165 {
/// @notice Query if a contract implements an interface
/// @param interfaceID The interface identifier, as specified in ERC-165
/// @dev Interface identification is specified in ERC-165. This function
/// uses less than 30,000 gas.
/// @return `true` if the contract implements `interfaceID` and
/// `interfaceID` is not 0xffffffff, `false` otherwise
function supportsInterface(bytes4 interfaceID) external view returns (bool);
}contracts/interfaces/IERC173.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/// @title ERC-173 Contract Ownership Standard
/// Note: the ERC-165 identifier for this interface is 0x7f5828d0
/* is ERC165 */
interface IERC173 {
/// @dev This emits when ownership of a contract changes.
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/// @notice Get the address of the owner
/// @return owner_ The address of the owner.
function owner() external view returns (address owner_);
/// @notice Set the address of the new owner of the contract
/// @dev Set _newOwner to address(0) to renounce any ownership.
/// @param _newOwner The address of the new owner of the contract
function transferOwnership(address _newOwner) external;
}
contracts/interfaces/IERC20.sol
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.8.28;
/// @title ERC20 interface
/// @dev https://github.com/ethereum/EIPs/issues/20
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
contracts/interfaces/IERC2981.sol
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.8.28;
/// @dev Interface for the NFT Royalty Standard
interface IERC2981 {
/// ERC165 bytes to add to interface array - set in parent contract
/// implementing this standard
///
/// bytes4(keccak256("royaltyInfo(uint256,uint256)")) == 0x2a55205a
/// bytes4 private constant _INTERFACE_ID_ERC2981 = 0x2a55205a;
/// _registerInterface(_INTERFACE_ID_ERC2981);
/// @notice Called with the sale price to determine how much royalty
// is owed and to whom.
/// @param _tokenId - the NFT asset queried for royalty information
/// @param _salePrice - the sale price of the NFT asset specified by _tokenId
/// @return receiver - address of who should be sent the royalty payment
/// @return royaltyAmount - the royalty payment amount for _salePrice
function royaltyInfo(
uint256 _tokenId,
uint256 _salePrice
) external view returns (
address receiver,
uint256 royaltyAmount
);
}
contracts/interfaces/IERC721.sol
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.8.28;
/// @title ERC-721 Non-Fungible Token Standard
/// @dev See https://eips.ethereum.org/EIPS/eip-721
/// Note: the ERC-165 identifier for this interface is 0x80ac58cd.
interface IERC721 /* is ERC165 */ {
/// @dev This emits when ownership of any NFT changes by any mechanism.
/// This event emits when NFTs are created (`from` == 0) and destroyed
/// (`to` == 0). Exception: during contract creation, any number of NFTs
/// may be created and assigned without emitting Transfer. At the time of
/// any transfer, the approved address for that NFT (if any) is reset to none.
event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);
/// @dev This emits when the approved address for an NFT is changed or
/// reaffirmed. The zero address indicates there is no approved address.
/// When a Transfer event emits, this also indicates that the approved
/// address for that NFT (if any) is reset to none.
event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
/// The operator can manage all NFTs of the owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @notice Count all NFTs assigned to an owner
/// @dev NFTs assigned to the zero address are considered invalid, and this
/// function throws for queries about the zero address.
/// @param _owner An address for whom to query the balance
/// @return The number of NFTs owned by `_owner`, possibly zero
function balanceOf(address _owner) external view returns (uint256);
/// @notice Find the owner of an NFT
/// @dev NFTs assigned to zero address are considered invalid, and queries
/// about them do throw.
/// @param _tokenId The identifier for an NFT
/// @return The address of the owner of the NFT
function ownerOf(uint256 _tokenId) external view returns (address);
/// @notice Transfers the ownership of an NFT from one address to another address
/// @dev Throws unless `msg.sender` is the current owner, an authorized
/// operator, or the approved address for this NFT. Throws if `_from` is
/// not the current owner. Throws if `_to` is the zero address. Throws if
/// `_tokenId` is not a valid NFT. When transfer is complete, this function
/// checks if `_to` is a smart contract (code size > 0). If so, it calls
/// `onERC721Received` on `_to` and throws if the return value is not
/// `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`.
/// @param _from The current owner of the NFT
/// @param _to The new owner
/// @param _tokenId The NFT to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes calldata data) external payable;
/// @notice Transfers the ownership of an NFT from one address to another address
/// @dev This works identically to the other function with an extra data parameter,
/// except this function just sets data to "".
/// @param _from The current owner of the NFT
/// @param _to The new owner
/// @param _tokenId The NFT to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;
/// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE
/// TO CONFIRM THAT `_to` IS CAPABLE OF RECEIVING NFTS OR ELSE
/// THEY MAY BE PERMANENTLY LOST
/// @dev Throws unless `msg.sender` is the current owner, an authorized
/// operator, or the approved address for this NFT. Throws if `_from` is
/// not the current owner. Throws if `_to` is the zero address. Throws if
/// `_tokenId` is not a valid NFT.
/// @param _from The current owner of the NFT
/// @param _to The new owner
/// @param _tokenId The NFT to transfer
function transferFrom(address _from, address _to, uint256 _tokenId) external payable;
/// @notice Change or reaffirm the approved address for an NFT
/// @dev The zero address indicates there is no approved address.
/// Throws unless `msg.sender` is the current NFT owner, or an authorized
/// operator of the current owner.
/// @param _approved The new approved NFT controller
/// @param _tokenId The NFT to approve
function approve(address _approved, uint256 _tokenId) external payable;
/// @notice Enable or disable approval for a third party ("operator") to manage
/// all of `msg.sender`'s assets
/// @dev Emits the ApprovalForAll event. The contract MUST allow
/// multiple operators per owner.
/// @param _operator Address to add to the set of authorized operators
/// @param _approved True if the operator is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved) external;
/// @notice Get the approved address for a single NFT
/// @dev Throws if `_tokenId` is not a valid NFT.
/// @param _tokenId The NFT to find the approved address for
/// @return The approved address for this NFT, or the zero address if there is none
function getApproved(uint256 _tokenId) external view returns (address);
/// @notice Query if an address is an authorized operator for another address
/// @param _owner The address that owns the NFTs
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool);
}
contracts/interfaces/IERC721TokenReceiver.sol
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.8.28;
/// @title IERC721TokenReceiver
/// @dev See https://eips.ethereum.org/EIPS/eip-721. Note: the ERC-165 identifier for this interface is 0x150b7a02.
interface IERC721TokenReceiver {
/// @notice Handle the receipt of an NFT
/// @dev The ERC721 smart contract calls this function on the recipient
/// after a `transfer`. This function MAY throw to revert and reject the
/// transfer. Return of other than the magic value MUST result in the
/// transaction being reverted.
/// Note: the contract address is always the message sender.
/// @param _operator The address which called `safeTransferFrom` function
/// @param _from The address which previously owned the token
/// @param _tokenId The NFT identifier which is being transferred
/// @param _data Additional data with no specified format
/// @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
/// unless throwing
function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes calldata _data) external returns(bytes4);
}contracts/interfaces/IGBM.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2025. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
import {IERC173} from "../interfaces/IERC173.sol";
import {IERC721TokenReceiver} from "../interfaces/IERC721TokenReceiver.sol";
import {IERC1155TokenReceiver} from "../interfaces/IERC1155TokenReceiver.sol";
import {IGBMAdminFacet} from "../interfaces/facets/IGBMAdminFacet.sol";
import {
IGBMBiddingFacet
} from "../interfaces/facets/IGBMBiddingFacet.sol";
import {
IGBMAuctionRegistrationFacet
} from "../interfaces/facets/IGBMAuctionRegistrationFacet.sol";
import {IGBMCurrencyFacet} from "../interfaces/facets/IGBMCurrencyFacet.sol";
import {IGBMEventsFacet} from "../interfaces/facets/IGBMEventsFacet.sol";
import {IGBMGettersFacet} from "../interfaces/facets/IGBMGettersFacet.sol";
import {
IGBMMarketPlaceAdminFacet
} from "../interfaces/facets/IGBMMarketPlaceAdminFacet.sol";
import {
IGBMRegisterMarketplaceFacet
} from "../interfaces/facets/IGBMRegisterMarketplaceFacet.sol";
interface IGBM is
IERC173,
IERC721TokenReceiver,
IERC1155TokenReceiver,
IGBMAdminFacet,
IGBMBiddingFacet,
IGBMAuctionRegistrationFacet,
IGBMCurrencyFacet,
IGBMEventsFacet,
IGBMGettersFacet,
IGBMMarketPlaceAdminFacet,
IGBMRegisterMarketplaceFacet
{}
contracts/interfaces/facets/IGBMAdminFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
/// @title IGBMAdminFacet interface
/// @author Guillaume Gonnaud
interface IGBMAdminFacet {
function setGBMAdminAccount(address _GBMAdminAccount) external;
function setGBMBackendSigner(address _backendSigner) external;
function setProtocolFees(uint256 _auctionFee, uint256 _fixedPriceFee, uint256 _swapFee, address _feeRecipient) external;
function setBiddingPreset(uint256 _presetID, string calldata _presetName, uint256 _stepMin, uint256 _incentiveMin, uint256 _incentiveMax, uint256 _incentiveGrowthMultiplier)external;
function set721Depositor(address _contract721, uint256 _tokenID, address _depositor) external;
function add1155Deposited(address _contract1155, uint256 _tokenID, uint256 _amount, address _depositor) external;
function remove1155Deposited(address _contract1155, uint256 _tokenID, uint256 _amount, address _depositor) external;
}contracts/interfaces/facets/IGBMAuctionRegistrationFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
import "../../libraries/GBM_Core.sol";
/// @title IGBMAuctionRegistrationFacet interface
/// @author Guillaume Gonnaud
interface IGBMAuctionRegistrationFacet {
function register721Auction(
address _erc721Contract,
uint256 _tokenID,
AuctionRegistrationParams calldata _auctionParams,
bytes calldata _authorisation
) external payable;
function register721AuctionsBatch(
address _erc721Contract,
uint256[] calldata _tokenIDs,
AuctionRegistrationParams calldata _auctionParams,
bytes calldata _authorisation
) external payable;
function register1155Auction(
address _erc1155Contract,
uint256 _tokenID,
uint256 _amount,
AuctionRegistrationParams calldata _auctionParams,
bytes calldata _authorisation
) external payable;
function register1155AuctionsBatch(
address _erc1155Contract,
uint256[] calldata _tokenIDs,
uint256[] calldata _amounts,
AuctionRegistrationParams calldata _auctionParams,
bytes calldata _authorisation
) external payable;
}
contracts/interfaces/facets/IGBMBiddingFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity ^0.8.28;
interface IGBMBiddingFacet {
function bid(
uint256 _auctionHouseID,
uint256 _auctionID,
uint256 _newBidAmount,
uint256 _previousHighestBidAmount,
uint256 _incentiveBoost,
bytes calldata _authorisation
) external payable;
function generatePlaceBidHash(
address _bidder,
uint256 _auctionHouseID,
uint256 _auctionID,
uint256 _newBidAmount,
uint256 _previousHighestBidAmount,
uint256 _incentiveBoost
) external pure returns (bytes32);
}contracts/interfaces/facets/IGBMCurrencyFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
/// @title IGBMCurrencyFacet interface
/// @author Guillaume Gonnaud
interface IGBMCurrencyFacet {
/// @notice Set the name of currency associated with the currency index
/// @dev Will throw if currencyIndex == 0. Will throw if not called by the GBM admin.
/// @param currencyIndex The index of the currency you wish to change the name of
/// @param currencyName The new name of the currency
function setCurrencyName(uint256 currencyIndex, string calldata currencyName) external;
/// @notice Set the address of the ERC-20 currency associated with the currency index
/// @dev Will throw if currencyIndex == 0. Will throw if not called by the GBM admin.
/// To set to native chain currency, set currencyAddress to 0x0.
/// @param currencyIndex The index of the currency you wish to change the address of
/// @param currencyAddress The address of the currency. If set to 0x0, it mean that the
/// currency is the native chain currency. eg : ETH on Etherum, MATIC on Polygon, etc...
function setCurrencyAddress(uint256 currencyIndex, address currencyAddress) external;
/// @notice Set the name of currency associated with the currency index
/// @dev Will throw if currencyIndex == 0. Will throw if not called by the GBM admin.
/// @param currencyIndex The index of the currency you wish to change the name of
/// @param currencyAddress The address of the currency. If set to 0x0, it mean that the
/// @param currencyName The new name of the currency
function setCurrencyAddressAndName(uint256 currencyIndex, address currencyAddress,string calldata currencyName) external;
/// @notice Set the currency to be used by default if no currency params are specified
/// @dev /!\ Will also impact live auctions. Beware of unforseen consequences.
/// @param currencyIndex The index of the currency you wish to be the new default one.
function setDefaultCurrency(uint256 currencyIndex) external;
}contracts/interfaces/facets/IGBMEventsFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
/// @title IGBMAdminFacet interface
/// @author Guillaume Gonnaud
interface IGBMEventsFacet {
/// ***********************************************
/// ************** Admin Events ******************
/// ***********************************************
event Admin_BackendSignerUpdated(address indexed GBMBackendSigner);
event Admin_ProtocolFees_Updated(
uint256 auctionFee,
uint256 fixedPriceFee,
uint256 swapFee,
address protocolWallet
);
event Admin_BiddingPreset_Updated(
uint256 indexed presetID,
string presetName,
uint256 stepMin,
uint256 incentiveMin,
uint256 incentiveMax,
uint256 incentiveGrowthMultiplier
);
event Admin_SetBonusERC1155Badge(
address bonusERC1155Badges
);
event Admin_SetBonusERC1155BadgeBonusAmount(
uint256 tokenID,
uint256 bonusAmount
);
event Admin_SetNumberOfTiers(
uint256 numberOfTiers
);
/// ***********************************************
/// *************** Currency Events ***************
/// ***********************************************
/// @dev This event emits whenever a currency name is registered/modified
event Currency_NameUpdated(
uint256 indexed currencyIndex,
string currencyName
);
/// @dev This event emits whenever a currency address is registered/modified
/// If currencyAddress == address(0), then this is the native Chain currency (eg: Eth, Matic, GLMR)
/// If currencyAddress != address(0), then this is an ERC20 token (eg: USDC, WETH)
event Currency_AddressUpdated(
uint256 indexed currencyIndex,
address currencyAddress
);
/// @dev This event emits whenever the default currency is being set to a new one
event Currency_DefaultUpdated(
uint256 previousCurrencyIndex,
uint256 indexed currencyIndex,
address currencyAddress,
string currencyName
);
event Currency_AllowedOnMarketplace(
uint256 indexed marketplaceID,
uint256 currencyIndex,
address currencyAddress,
bool isAllowed
);
/// ***********************************************
/// ********* Marketplace Admin Events*************
/// ***********************************************
event Marketplace_Registered(
uint256 indexed marketplaceID,
address currency,
uint256 paidAmount
);
event Marketplace_Name_Updated(
uint256 indexed marketplaceID,
string name
);
event Marketplace_DomainName_Updated(
uint256 indexed marketplaceID,
string domainName
);
event Marketplace_Admin_Updated(
uint256 indexed marketplaceID,
address indexed newAdmin
);
event Marketplace_Delegate_Updated(
uint256 indexed marketplaceID,
address indexed newDelegate
);
event Marketplace_Fees_Updated(
uint256 indexed marketplaceID,
uint256 auctionFee,
uint256 fixedPriceFee,
uint256 swapFee,
address recipient
);
event Marketplace_RegistrationAuctions_Allowed(
uint256 indexed marketplaceID,
bool isAllowed
);
event Marketplace_RegistrationFixedPrice_Allowed(
uint256 indexed marketplaceID,
bool isAllowed
);
event Marketplace_RegistrationSwaps_Allowed(
uint256 indexed marketplaceID,
bool isAllowed
);
/// ***********************************************
/// ************** Escrow Events ******************
/// ***********************************************
event Escrow_ERC721Deposited(
address indexed contract721,
uint256 indexed tokenID,
address depositor
);
event Escrow_ERC721Withdrawn(
address indexed contract721,
uint256 indexed tokenID,
address collector
);
event Escrow_ERC1155Deposited(
address indexed contract1155,
uint256 indexed tokenID,
uint256 indexed amount,
address depositor
);
event Escrow_ERC1155Withdrawn(
address indexed contract1155,
uint256 indexed tokenID,
uint256 indexed amount,
address collector
);
/// ***********************************************
/// **************** Money flows ******************
/// ***********************************************
event Money_StartingBid_FeeCapture(
uint256 indexed marketplaceID,
uint256 indexed saleID,
address seller,
address currency,
uint256 startingBid,
uint256 feeAmount
);
event Money_StartingBid_ProtocolFee(
uint256 indexed marketplaceID,
uint256 indexed saleID,
address seller,
address currency,
uint256 startingBid,
uint256 feeAmount,
address protocolWallet
);
event Money_StartingBid_MarketplaceFee(
uint256 indexed marketplaceID,
uint256 indexed saleID,
address seller,
address currency,
uint256 startingBid,
uint256 feeAmount,
address marketplaceWallet
);
event Money_BidCaptured(
uint256 indexed marketplaceID,
uint256 indexed saleID,
address bidder,
address currency,
uint256 bidAmount
);
event Money_BidRefunded(
uint256 indexed marketplaceID,
uint256 indexed saleID,
address bidder,
address currency,
uint256 bidAmount,
uint256 incentivesAmount
);
event Money_AuctionSettledProtocolFee(
uint256 indexed marketplaceID,
uint256 indexed saleID,
address seller,
address currency,
uint256 winningBidAmount,
uint256 protocolFeeAmount,
address protocolWallet
);
event Money_AuctionSettledMarketplaceFee(
uint256 indexed marketplaceID,
uint256 indexed saleID,
address seller,
address currency,
uint256 winningBidAmount,
uint256 marketplaceFeeAmount,
address marketplaceWallet
);
event Money_AuctionSettledSellerProceeds(
uint256 indexed marketplaceID,
uint256 indexed saleID,
address seller,
address currency,
uint256 winningBidAmount,
uint256 sellerProceeds
);
event Money_CancellationFee(
uint256 indexed marketplaceID,
uint256 indexed saleID,
address seller,
address currency,
uint256 cancellationFeeAmount
);
/// ***********************************************
/// ************** Auction Event *****************
/// ***********************************************
event Auction_ERC721_Created(
uint256 indexed marketplaceID,
uint256 indexed saleID,
address seller,
address erc721Contract,
uint256 tokenID
);
event Auction_ERC1155_Created(
uint256 indexed marketplaceID,
uint256 indexed saleID,
address seller,
address erc1155Contract,
uint256 tokenID,
uint256 amount
);
event Auction_Parameters_Updated(
uint256 indexed marketplaceID,
uint256 indexed saleID,
uint256 GBMPresetID,
uint256 currencyIndex,
uint256 startTimestamp,
uint256 endTimestamp,
uint256 hammerTimeDuration,
uint256 cancellationDuration,
uint256 startingBid
);
event Auction_EndTimestamp_Updated(
uint256 indexed marketplaceID,
uint256 indexed saleID,
uint256 endTimestamp
);
/// @dev This event emits whenever an auction is being settled, with the proceeds and token going to their rightful owner
event Auction_721_Claimed(
uint256 indexed marketplaceID,
uint256 indexed saleID, // The id of auction
address tokenContractAddress, // The address of the contract of the NFT being auctionned
uint256 tokenID, // The ID of the token being auctionned
address beneficiary, // Who is the seller that is receiving the profits of the sale
uint256 winningBidAmount, // How big was the winning bid
address currency, // In what currency was the winning bid
address winner // What is the adress of the winning bidder
);
event Auction_1155_Claimed(
uint256 indexed marketplaceID,
uint256 indexed saleID, // The id of auction
address tokenContractAddress, // The address of the contract of the NFT being auctionned
uint256 tokenID, // The ID of the token being auctionned
uint256 tokenAmount, // How many tokens sold at once in this auction
address beneficiary, // Who is the seller that is receiving the profits of the sale
uint256 winningBidAmount, // How big was the winning bid
address currency, // In what currency was the winning bid
address winner // What is the address of the winning bidder
);
/// @dev This event emits whenever an auction is being canceled, with the proceeds and token going to their rightful owner
event Auction_721_Cancelled(
uint256 indexed marketplaceID,
uint256 indexed saleID, // The id of auction
address tokenContractAddress, // The address of the contract of the NFT being auctionned
uint256 tokenID, // The ID of the token being auctionned
address seller, // Who is the seller that is receiving the profits of the sale
uint256 topBidAmount, // How big was the winning bid
address currency, // In what currency was the winning bid
uint256 debt // What is the debt in the auction
);
/// @dev This event emits whenever an auction is being canceled, with the proceeds and token going to their rightful owner
event Auction_1155_Cancelled(
uint256 indexed marketplaceID,
uint256 indexed saleID, // The id of auction
address tokenContractAddress, // The address of the contract of the NFT being auctionned
uint256 tokenID, // The ID of the token being auctionned
uint256 tokenAmount, // How many tokens sold at once in this auction
address seller, // Who is the seller that is receiving the profits of the sale
uint256 topBidAmount, // How big was the winning bid
address currency, // In what currency was the winning bid
uint256 debt // What is the debt in the auction
);
/// ***********************************************
/// **************** Bid Event *******************
/// ***********************************************
event Bid_Placed(
uint256 indexed marketplaceID,
uint256 indexed saleID,
uint256 bidIndex,
address bidder,
uint256 bidAmount,
uint256 incentivesAmount
);
event Bid_Displaced(
uint256 indexed marketplaceID,
uint256 indexed saleID,
uint256 displacedBidIndex,
address displacedBidder,
uint256 displacedBidAmount,
uint256 displacedBidIncentives
);
}
contracts/interfaces/facets/IGBMGettersFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
/// @title IGBMGettersFacet Interface
/// @author Guillaume Gonnaud
interface IGBMGettersFacet {
function getDOMAIN_SEPARATOR() external view returns (bytes32);
function getGBMAdminAccount() external view returns (address);
function getGBMBackendSigner() external view returns (address);
// =============================================================================================================
// Currencies
function getCurrencyName(uint256 currencyIndex) external view returns (string memory);
function getCurrencyAddress(uint256 currencyIndex) external view returns (address);
function getDefaultCurrency() external view returns (uint256);
// =============================================================================================================
// Fees
function getCurrencyIndex(address currencyAddress) external view returns (uint256);
function getGBMProtocolFeeAuction() external view returns (uint256);
function getGBMProtocolFeeFixedPrice() external view returns (uint256);
function getGBMProtocolFeeSwap() external view returns (uint256);
function getGBMProtocolWallet() external view returns (address);
function getAHFeeAuction(uint256 _auctionHouseID) external view returns (uint256);
function getAHFeeFixedPrice(uint256 _auctionHouseID) external view returns (uint256);
function getAHFeeSwap(uint256 _auctionHouseID) external view returns (uint256);
function getAHFeeRecipient(uint256 _auctionHouseID) external view returns (address);
// =============================================================================================================
// Bidding Presets
function getBiddingPresetName(uint256 _BiddingPresetID) external view returns (string memory);
function getBiddingPresetStepMin(uint256 _BiddingPresetID) external view returns (uint256);
function getBiddingPresetIncentiveMin(uint256 _BiddingPresetID) external view returns (uint256);
function getBiddingPresetIncentiveMax(uint256 _BiddingPresetID) external view returns (uint256);
function getBiddingPresetIncentiveGrowthMultiplier(uint256 _BiddingPresetID) external view returns (uint256);
// =============================================================================================================
// Escrow
function getERC721Token_depositor(address tokenAddress, uint256 tokenID) external view returns(address);
function getERC721Token_underSale(address tokenAddress, uint256 tokenID) external view returns(bool);
function getERC1155Token_depositor(address tokenAddress, uint256 tokenID, address depositor) external view returns(uint256);
function getERC1155Token_UnderSaleByDepositor(address tokenAddress, uint256 tokenID, address depositor) external view returns(uint256);
// =============================================================================================================
// Marketplaces specific stuff
function getAHAdmin(uint256 _auctionHouseID) external view returns (address);
function getAHDelegate(uint256 _auctionHouseID) external view returns (address);
function getAHName(uint256 _auctionHouseID) external view returns (string memory);
function getAHDomainName(uint256 _auctionHouseID) external view returns (string memory);
function getAHAuctionsCreated(uint256 _auctionHouseID) external view returns (uint256);
function getAHAuctionsSettled(uint256 _auctionHouseID) external view returns (uint256);
function getAHisEnabledAuctions(uint256 _auctionHouseID) external view returns (bool);
function getAHisEnabledFixedPriceSales(uint256 _auctionHouseID) external view returns (bool);
function getAHisEnabledSwaps(uint256 _auctionHouseID) external view returns (bool);
function getAHisCurrencyAllowed(uint256 _auctionHouseID, address _currency) external view returns (bool);
// =============================================================================================================
// Auction specific stuff
function getSaleTokenKind(uint256 _auctionHouseID, uint256 _saleID) external view returns (bytes4);
function getSaleKind(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256);
function getSaleTokenContract(uint256 _auctionHouseID, uint256 _saleID) external view returns (address);
function getSaleTokenID(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256);
function getSaleGBMPresetID(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256);
function getSaleCurrency(uint256 _auctionHouseID, uint256 _saleID) external view returns (address);
function getSaleStartTimestamp(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256);
function getSaleEndTimestamp(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256);
function getSaleHammerTimeDuration(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256);
function getSaleCancellationDuration(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256);
function getSalePrepaidAmount(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256);
function getSaleStartingBid(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256);
function getSaleAmountForSale(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256);
function getSaleSeller(uint256 _auctionHouseID, uint256 _saleID) external view returns (address);
function getSaleNumberOfBids(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256);
function getSaleAuctionDebt(uint256 _auctionHouseID, uint256 _saleID) external view returns (uint256);
function getSaleBidValue(uint256 _auctionHouseID, uint256 _saleID, uint256 _bidIndex) external view returns (uint256);
function getSaleBidIncentive(uint256 _auctionHouseID, uint256 _saleID, uint256 _bidIndex) external view returns (uint256);
function getSaleBidder(uint256 _auctionHouseID, uint256 _saleID, uint256 _bidIndex) external view returns (address);
function getSaleHighestBidder(uint256 _auctionHouseID, uint256 _saleID) external view returns (address);
}contracts/interfaces/facets/IGBMMarketPlaceAdminFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
/// @title IGBMAdminFacet interface
/// @author Guillaume Gonnaud
interface IGBMMarketPlaceAdminFacet {
function setMarketplaceAdmin(uint256 _marketplaceID, address _newAdmin) external;
function setMarketplaceDelegate(uint256 _marketplaceID, address _newDelegate) external;
function setMarketplaceFees(uint256 _marketplaceID, uint256 _auctionFee, uint256 _fixedPriceFee, uint256 _swapFee, address _feeRecipient) external;
function setAllowedCurrency(uint256 _marketplaceID, address _currency, bool _isAllowed) external;
function setAllowedCurrencies(uint256 _marketplaceID, address[] calldata _currencies, bool[] calldata _isAllowed) external;
function setAuctionRegistrationAllowed(uint256 _marketplaceID, bool _allowAuctions) external;
function setFixedPriceRegistrationAllowed(uint256 _marketplaceID, bool _allowFixedPrices) external;
function setSwapRegistrationAllowed(uint256 _marketplaceID, bool _allowSwaps) external;
function setMarketplaceName(uint256 _marketplaceID, string calldata _name) external;
function setMarketplaceDomainName(uint256 _marketplaceID, string calldata _domainName, bytes calldata _authorisation) external;
}contracts/interfaces/facets/IGBMRegisterMarketplaceFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
/// @title IGBMAdminFacet interface
/// @author Guillaume Gonnaud
interface IGBMRegisterMarketplaceFacet {
function registerAMarketPlace(uint256 _marketplaceID, string calldata _name, string calldata _domainName, address _currency, uint256 _paidAmount, bytes calldata _authorisation)external payable;
}contracts/interfaces/facets/IGBMSettleAuctionFacet.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
/// @title IGBMSettleAuctionFacet Interface
/// @author Guillaume Gonnaud
interface IGBMSettleAuctionFacet {
function settleAuction(uint256 _auctionHouseID, uint256 _auctionID) external;
function cancelAuction(uint256 _auctionHouseID, uint256 _auctionID) external payable;
}
contracts/libraries/GBM_Core.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2026. Patent pending. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
bytes32 constant EIP712_DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
bytes32 constant REGISTERMARKETPLACE_SIGNATURE_TYPEHASH = keccak256("RegisterMarketplaceSignature(address registrant,uint256 marketplaceID,string name,string domainName,address currency,uint256 paidAmount)");
bytes32 constant REGISTER721AUCTION_SIGNATURE_TYPEHASH = keccak256("Register721AuctionSignature(address seller,address contract721,uint256 tokenID,uint256 marketplaceID,uint256 GBMPresetID,address currency,uint256 startTimestamp,uint256 endTimestamp,uint256 hammerTimeDuration,uint256 cancellationDuration,uint256 startingBid)");
bytes32 constant REGISTER721AUCTIONS_BATCH_SIGNATURE_TYPEHASH = keccak256("Register721AuctionsBatchSignature(address seller,address contract721,bytes32 hashedTokenIDs,uint256 marketplaceID,uint256 GBMPresetID,address currency,uint256 startTimestamp,uint256 endTimestamp,uint256 hammerTimeDuration,uint256 cancellationDuration,uint256 startingBid)");
bytes32 constant REGISTER1155AUCTION_SIGNATURE_TYPEHASH = keccak256("Register1155AuctionSignature(address seller,address contract1155,uint256 tokenID,uint256 marketplaceID,uint256 GBMPresetID,address currency,uint256 startTimestamp,uint256 endTimestamp,uint256 hammerTimeDuration,uint256 cancellationDuration,uint256 startingBid)");
bytes32 constant REGISTER1155AUCTIONS_BATCH_SIGNATURE_TYPEHASH = keccak256("Register1155AuctionsBatchSignature(address seller,address contract1155,bytes32 hashedTokenIDs,uint256 marketplaceID,uint256 GBMPresetID,address currency,uint256 startTimestamp,uint256 endTimestamp,uint256 hammerTimeDuration,uint256 cancellationDuration,uint256 startingBid)");
bytes32 constant PLACEBID_SIGNATURE_TYPEHASH = keccak256("PlaceBidSignature(address bidder,uint256 auctionHouseID,uint256 auctionID,uint256 newBidAmount,uint256 previousHighestBidAmount,uint256 incentiveBoost)");
bytes32 constant ADMINSETDOMAINNAME_SIGNATURE_TYPEHASH = keccak256("AdminSetDomainName(address admin,uint256 marketplaceID,string newDomainName)");
bytes4 constant ERC721 = bytes4(keccak256("ERC721"));
bytes4 constant ERC1155 = bytes4(keccak256("ERC1155"));
uint256 constant DECIMALSK = 100000;
//Design philosophy :
//Never register something at index 0 in a mapping. 0 is the default value that is reserved for "un-initialized" gas saving shortcuts.
// The struct used as storage by the main diamond contract
struct GBMStorage {
bool reentrancySemaphore; // Boolean used to guarantee no-reentrancy
address GBMAdminAccount; // The address of the primary GBM administrator
address GBMBackendSigner; // The address countersigning transactions
// =============================================================================================================
// Currencies
mapping (uint256 => string) currencyNames; // Name of the authorized currencies
mapping (uint256 => address) currencyAddress; // Address of the ERC-20 tokens currencies. An address of 0 imply a Native currency.
mapping (address => uint256) currencyIndex;
uint256 defaultCurrency; // The index of the currencies used by default
// =============================================================================================================
// Fees
uint256 GBMProtocolFeeAuction; // The protocol fee on auctions
uint256 GBMProtocolFeeFixedPrice; // The protocol fee on fixed price sales
uint256 GBMProtocolFeeSwap; // The protocol fee on swaps
address GBMProtocolWallet; // The address to which the GBM fees are being paid to
mapping (uint256 => uint256) auctionHouseIDToFeeAuction; // A mapping storing the auction fee percentkage for this marketplace
mapping (uint256 => uint256) auctionHouseIDToFeeFixedPrice; // A mapping storing the FixedPrice fee percentkage for this marketplace
mapping (uint256 => uint256) auctionHouseIDToFeeSwap; // A mapping storing the Swap fee percentkage for this marketplace
mapping (uint256 => address) auctionHouseIDToFeeRecipient; // A mapping storing the fee recipient for this marketplace
// =============================================================================================================
// Bidding Presets
mapping (uint256 => string) biddingPresetIDToName; // The name of a Preset
mapping (uint256 => uint256) biddingPresetIDToStepMin; // The minimal %k increase between two successive bids
mapping (uint256 => uint256) biddingPresetIDToIncentiveMin; // The minimal %k incentive reward from a bid
mapping (uint256 => uint256) biddingPresetIDToIncentiveMax; // The maximal %k incentive reward from a bid
mapping (uint256 => uint256) biddingPresetIDToIncentiveGrowthMultiplier; // The growth factor in a GBM auction
// =============================================================================================================
// Escrow
mapping (address => mapping(uint256 => address)) erc721tokensAddressAndIDToEscrower; //A mapping keeping track of who deposited an ERC721 token in escrow
mapping (address => mapping(uint256 => bool)) erc721tokensAddressAndIDToUnderSale; //A mapping keeping track of which ERC721 tokens are under sale
mapping (address => mapping(uint256 => mapping(address => uint256))) erc1155tokensAddressAndIDToEscrowerAmount; //A mapping keeping track of how much by whom ERC1155 tokens have been deposited in escrow
mapping (address => mapping(uint256 => mapping(address => uint256))) erc1155tokensAddressAndIDToEscrowerUnderSaleAmount; //A mapping keeping track of how much by whom ERC1155 tokens are under sale
// =============================================================================================================
// Marketplaces specific stuff
mapping (uint256 => address) auctionHouseIDToAdmin; // A mapping storing who is the admin of each marketplace
mapping (uint256 => address) auctionHouseIDToDelegate; // A mapping storing who is the delegate of each marketplace
mapping (uint256 => string) auctionHouseIDToName;
mapping (uint256 => string) auctionHouseIDToDomainName;
mapping (uint256 => uint256) auctionHouseIDToAuctionsCreated;
mapping (uint256 => uint256) auctionHouseIDToAuctionsSettled;
mapping(uint256 => bool) auctionHouseIDToAuctionsEnabled; // Allow the creation of this kind of sale on the marketplace
mapping(uint256 => bool) auctionHouseIDToFixedPriceEnabled; // Allow the creation of this kind of sale on the marketplace
mapping(uint256 => bool) auctionHouseIDToSwapEnabled; // Allow the creation of this kind of sale on the marketplace
mapping(uint256 => mapping(address => bool)) auctionHouseIDToCurrencyAddressToAllowed; //Mapping storing which currency are allowed to create sales on the mktplace
// =============================================================================================================
// Auction specific stuff
mapping(uint256 => mapping(uint256 => bytes4)) auctionHouseIDToSaleIDToTokenKind; // hash of either ERC721 or ERC1155
mapping(uint256 => mapping(uint256 => uint256)) auctionHouseIDToSaleIDToSaleKind; // 0 = none, 1 = auction, 2 = direct sale, 3 = swaps
mapping(uint256 => mapping(uint256 => address)) auctionHouseIDToSaleIDToTokenContract; // The adddress of the contract of the token for sale
mapping(uint256 => mapping(uint256 => uint256)) auctionHouseIDToSaleIDToTokenID; // The tokenID for sale
mapping(uint256 => mapping(uint256 => uint256)) auctionHouseIDToSaleIDToGBMPresetID; // GBM Preset used for the sale
mapping(uint256 => mapping(uint256 => address)) auctionHouseIDToSaleIDToCurrency; // Address of the currency used in the sale
mapping(uint256 => mapping(uint256 => uint256)) auctionHouseIDToSaleIDToStartTimestamp;
mapping(uint256 => mapping(uint256 => uint256)) auctionHouseIDToSaleIDToEndTimestamp;
mapping(uint256 => mapping(uint256 => uint256)) auctionHouseIDToSaleIDToHammerTimeDuration;
mapping(uint256 => mapping(uint256 => uint256)) auctionHouseIDToSaleIDToCancellationDuration;
mapping(uint256 => mapping(uint256 => uint256)) auctionHouseIDToSaleIDToPrepaidAmount; // Prepaid amount when a starting bid was present
mapping(uint256 => mapping(uint256 => uint256)) auctionHouseIDToSaleIDToStartingBid;
mapping(uint256 => mapping(uint256 => uint256)) auctionHouseIDToSaleIDToAmountForSale;
mapping(uint256 => mapping(uint256 => address)) auctionHouseIDToSaleIDToSeller;
mapping(uint256 => mapping(uint256 => uint256)) auctionHouseIDToSaleIDToNumberOfBids;
mapping(uint256 => mapping(uint256 => uint256)) auctionHouseIDToSaleIDToAuctionDebt;
mapping(uint256 => mapping(uint256 => bool)) auctionHouseIDToSaleIDToSaleSettled;
mapping(uint256 => mapping(uint256 => mapping(uint256 => uint256))) auctionHouseIDToSaleIDToBidIndexToValues; // A mapping storing the bid values for each auction
mapping(uint256 => mapping(uint256 => mapping(uint256 => uint256))) auctionHouseIDToSaleIDToBidIndexToIncentives; // A mapping storing the incentive rewards due for each bid in each auction
mapping(uint256 => mapping(uint256 => mapping(uint256 => address))) auctionHouseIDToSaleIDToBidIndexToBidder;
}
struct AuctionRegistrationParams {
uint256 marketplaceID;
uint256 GBMPresetID;
address currency;
uint256 startTimestamp;
uint256 endTimestamp;
uint256 hammerTimeDuration;
uint256 cancellationDuration;
uint256 startingBid;
}contracts/libraries/LibDiamond.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/******************************************************************************\
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
/******************************************************************************/
import { IDiamondCut } from "../interfaces/IDiamondCut.sol";
library LibDiamond {
bytes32 constant DIAMOND_STORAGE_POSITION = keccak256("diamond.standard.diamond.storage");
struct DiamondStorage {
// maps function selectors to the facets that execute the functions.
// and maps the selectors to their position in the selectorSlots array.
// func selector => address facet, selector position
mapping(bytes4 => bytes32) facets;
// array of slots of function selectors.
// each slot holds 8 function selectors.
mapping(uint256 => bytes32) selectorSlots;
// The number of function selectors in selectorSlots
uint16 selectorCount;
// Used to query if a contract implements an interface.
// Used to implement ERC-165.
mapping(bytes4 => bool) supportedInterfaces;
// owner of the contract
address contractOwner;
}
function diamondStorage() internal pure returns (DiamondStorage storage ds) {
bytes32 position = DIAMOND_STORAGE_POSITION;
assembly {
ds.slot := position
}
}
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
function setContractOwner(address _newOwner) internal {
DiamondStorage storage ds = diamondStorage();
address previousOwner = ds.contractOwner;
ds.contractOwner = _newOwner;
emit OwnershipTransferred(previousOwner, _newOwner);
}
function contractOwner() internal view returns (address contractOwner_) {
contractOwner_ = diamondStorage().contractOwner;
}
function enforceIsContractOwner() internal view {
require(msg.sender == diamondStorage().contractOwner, "LibDiamond: Must be contract owner");
}
event DiamondCut(IDiamondCut.FacetCut[] _diamondCut, address _init, bytes _calldata);
bytes32 constant CLEAR_ADDRESS_MASK = bytes32(uint256(0xffffffffffffffffffffffff));
bytes32 constant CLEAR_SELECTOR_MASK = bytes32(uint256(0xffffffff << 224));
// Internal function version of diamondCut
// This code is almost the same as the external diamondCut,
// except it is using 'Facet[] memory _diamondCut' instead of
// 'Facet[] calldata _diamondCut'.
// The code is duplicated to prevent copying calldata to memory which
// causes an error for a two dimensional array.
function diamondCut(
IDiamondCut.FacetCut[] memory _diamondCut,
address _init,
bytes memory _calldata
) internal {
DiamondStorage storage ds = diamondStorage();
uint256 originalSelectorCount = ds.selectorCount;
uint256 selectorCount = originalSelectorCount;
bytes32 selectorSlot;
// Check if last selector slot is not full
if (selectorCount & 7 > 0) {
// get last selectorSlot
selectorSlot = ds.selectorSlots[selectorCount >> 3];
}
// loop through diamond cut
for (uint256 facetIndex; facetIndex < _diamondCut.length; facetIndex++) {
(selectorCount, selectorSlot) = addReplaceRemoveFacetSelectors(
selectorCount,
selectorSlot,
_diamondCut[facetIndex].facetAddress,
_diamondCut[facetIndex].action,
_diamondCut[facetIndex].functionSelectors
);
}
if (selectorCount != originalSelectorCount) {
ds.selectorCount = uint16(selectorCount);
}
// If last selector slot is not full
if (selectorCount & 7 > 0) {
ds.selectorSlots[selectorCount >> 3] = selectorSlot;
}
emit DiamondCut(_diamondCut, _init, _calldata);
initializeDiamondCut(_init, _calldata);
}
function addReplaceRemoveFacetSelectors(
uint256 _selectorCount,
bytes32 _selectorSlot,
address _newFacetAddress,
IDiamondCut.FacetCutAction _action,
bytes4[] memory _selectors
) internal returns (uint256, bytes32) {
DiamondStorage storage ds = diamondStorage();
require(_selectors.length > 0, "LibDiamondCut: No selectors in facet to cut");
if (_action == IDiamondCut.FacetCutAction.Add) {
enforceHasContractCode(_newFacetAddress, "LibDiamondCut: Add facet has no code");
for (uint256 selectorIndex; selectorIndex < _selectors.length; selectorIndex++) {
bytes4 selector = _selectors[selectorIndex];
bytes32 oldFacet = ds.facets[selector];
require(address(bytes20(oldFacet)) == address(0), "LibDiamondCut: Can't add function that already exists");
// add facet for selector
ds.facets[selector] = bytes20(_newFacetAddress) | bytes32(_selectorCount);
uint256 selectorInSlotPosition = (_selectorCount & 7) << 5;
// clear selector position in slot and add selector
_selectorSlot = (_selectorSlot & ~(CLEAR_SELECTOR_MASK >> selectorInSlotPosition)) | (bytes32(selector) >> selectorInSlotPosition);
// if slot is full then write it to storage
if (selectorInSlotPosition == 224) {
ds.selectorSlots[_selectorCount >> 3] = _selectorSlot;
_selectorSlot = 0;
}
_selectorCount++;
}
} else if (_action == IDiamondCut.FacetCutAction.Replace) {
enforceHasContractCode(_newFacetAddress, "LibDiamondCut: Replace facet has no code");
for (uint256 selectorIndex; selectorIndex < _selectors.length; selectorIndex++) {
bytes4 selector = _selectors[selectorIndex];
bytes32 oldFacet = ds.facets[selector];
address oldFacetAddress = address(bytes20(oldFacet));
// only useful if immutable functions exist
require(oldFacetAddress != address(this), "LibDiamondCut: Can't replace immutable function");
require(oldFacetAddress != _newFacetAddress, "LibDiamondCut: Can't replace function with same function");
require(oldFacetAddress != address(0), "LibDiamondCut: Can't replace function that doesn't exist");
// replace old facet address
ds.facets[selector] = (oldFacet & CLEAR_ADDRESS_MASK) | bytes20(_newFacetAddress);
}
} else if (_action == IDiamondCut.FacetCutAction.Remove) {
require(_newFacetAddress == address(0), "LibDiamondCut: Remove facet address must be address(0)");
uint256 selectorSlotCount = _selectorCount >> 3;
uint256 selectorInSlotIndex = _selectorCount & 7;
for (uint256 selectorIndex; selectorIndex < _selectors.length; selectorIndex++) {
if (_selectorSlot == 0) {
// get last selectorSlot
selectorSlotCount--;
_selectorSlot = ds.selectorSlots[selectorSlotCount];
selectorInSlotIndex = 7;
} else {
selectorInSlotIndex--;
}
bytes4 lastSelector;
uint256 oldSelectorsSlotCount;
uint256 oldSelectorInSlotPosition;
// adding a block here prevents stack too deep error
{
bytes4 selector = _selectors[selectorIndex];
bytes32 oldFacet = ds.facets[selector];
require(address(bytes20(oldFacet)) != address(0), "LibDiamondCut: Can't remove function that doesn't exist");
// only useful if immutable functions exist
require(address(bytes20(oldFacet)) != address(this), "LibDiamondCut: Can't remove immutable function");
// replace selector with last selector in ds.facets
// gets the last selector
lastSelector = bytes4(_selectorSlot << (selectorInSlotIndex << 5));
if (lastSelector != selector) {
// update last selector slot position info
ds.facets[lastSelector] = (oldFacet & CLEAR_ADDRESS_MASK) | bytes20(ds.facets[lastSelector]);
}
delete ds.facets[selector];
uint256 oldSelectorCount = uint16(uint256(oldFacet));
oldSelectorsSlotCount = oldSelectorCount >> 3;
oldSelectorInSlotPosition = (oldSelectorCount & 7) << 5;
}
if (oldSelectorsSlotCount != selectorSlotCount) {
bytes32 oldSelectorSlot = ds.selectorSlots[oldSelectorsSlotCount];
// clears the selector we are deleting and puts the last selector in its place.
oldSelectorSlot =
(oldSelectorSlot & ~(CLEAR_SELECTOR_MASK >> oldSelectorInSlotPosition)) |
(bytes32(lastSelector) >> oldSelectorInSlotPosition);
// update storage with the modified slot
ds.selectorSlots[oldSelectorsSlotCount] = oldSelectorSlot;
} else {
// clears the selector we are deleting and puts the last selector in its place.
_selectorSlot =
(_selectorSlot & ~(CLEAR_SELECTOR_MASK >> oldSelectorInSlotPosition)) |
(bytes32(lastSelector) >> oldSelectorInSlotPosition);
}
if (selectorInSlotIndex == 0) {
delete ds.selectorSlots[selectorSlotCount];
_selectorSlot = 0;
}
}
_selectorCount = selectorSlotCount * 8 + selectorInSlotIndex;
} else {
revert("LibDiamondCut: Incorrect FacetCutAction");
}
return (_selectorCount, _selectorSlot);
}
function initializeDiamondCut(address _init, bytes memory _calldata) internal {
if (_init == address(0)) {
require(_calldata.length == 0, "LibDiamondCut: _init is address(0) but_calldata is not empty");
} else {
require(_calldata.length > 0, "LibDiamondCut: _calldata is empty but _init is not address(0)");
if (_init != address(this)) {
enforceHasContractCode(_init, "LibDiamondCut: _init address has no code");
}
(bool success, bytes memory error) = _init.delegatecall(_calldata);
if (!success) {
if (error.length > 0) {
// bubble up the error
revert(string(error));
} else {
revert("LibDiamondCut: _init function reverted");
}
}
}
}
function enforceHasContractCode(address _contract, string memory _errorMessage) internal view {
uint256 contractSize;
assembly {
contractSize := extcodesize(_contract)
}
require(contractSize > 0, _errorMessage);
}
}
contracts/test/ERC1155Generic.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2022. All rights reserved. Perpetual Altruism Ltd.
pragma solidity ^0.8.0;
import "../interfaces/IERC1155.sol";
import "../interfaces/IERC1155TokenReceiver.sol";
import "../interfaces/IERC165.sol";
/// @author Guillaume Gonnaud 2021
/// @title ERC1155 Generic placeholder smart contract for testing and ABI
contract ERC1155Generic is IERC1155, IERC165 {
string public name; // Returns the name of the token - e.g. "Generic ERC1155".
string public symbol; // Returns the symbol of the token. E.g. GEN1155.
address public owner;
mapping(address => mapping(uint256 => uint256)) internal balanceOfVar; // owner => id => balance
mapping(address => mapping(address => bool)) internal isApprovedForAllVar; // owner => oprator => isapproved ?
mapping(uint256 => bool) internal occupiedTokenID;
uint256[] public tokenIDArray;
mapping(bytes4 => bool) supportedInterfaces;
mapping(uint256 => string) internal m_tokenURI;
/// @notice Constructor
/// @dev Please change the values in here if you want more specific values, or make the constructor takes arguments
constructor(string memory _name, string memory _symbol) {
owner = msg.sender;
name = _name;
symbol = _symbol;
supportedInterfaces[0xd9b67a26] = true; //1155
supportedInterfaces[0x2a55205a] = true; //2981
supportedInterfaces[0x01ffc9a7] = true; //165
}
/// @notice Transfers `_value` amount of an `_id` from the `_from` address to the `_to` address specified (with safety call).
/// @dev Caller must be approved to manage the tokens being transferred out of the `_from` account (see "Approval" section of the standard).
/// MUST revert if `_to` is the zero address.
/// MUST revert if balance of holder for token `_id` is lower than the `_value` sent.
/// MUST revert on any other error.
/// UST emit the `TransferSingle` event to reflect the balance change (see "Safe Transfer Rules" section of the standard).
/// After the above conditions are met, this function MUST check if `_to` is a smart contract (e.g. code size > 0). If so, it MUST call `onERC1155Received` on `_to` and act appropriately (see "Safe Transfer Rules" section of the standard).
/// @param _from Source address
/// @param _to Target address
/// @param _id ID of the token type
/// @param _value Transfer amount
/// @param _data Additional data with no specified format, MUST be sent unaltered in call to `onERC1155Received` on `_to`
function safeTransferFrom(
address _from,
address _to,
uint256 _id,
uint256 _value,
bytes calldata _data
) external override {
require(
msg.sender == _from || isApprovedForAllVar[_from][msg.sender],
"safeTransferFrom: msg.sender is not allowed to manipulate _from tokens"
);
require(
_to != address(0x0),
"safeTransferFrom: cannot transfer to 0x0"
);
require(
_value <= balanceOfVar[_from][_id],
"safeTransferFrom: Balance of _from is too low to transfer _value tokens"
);
//Adjusting the balances
balanceOfVar[_from][_id] = balanceOfVar[_from][_id] - _value;
balanceOfVar[_to][_id] = balanceOfVar[_to][_id] + _value;
//Emitting the event
emit TransferSingle(msg.sender, _from, _to, _id, _value);
if (isContract(_to)) {
//bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)")) == 0xf23a6e61
require(
IERC1155TokenReceiver(_to).onERC1155Received(
msg.sender,
_from,
_id,
_value,
_data
) == bytes4(0xf23a6e61)
);
}
}
/// @notice Transfers `_values` amount(s) of `_ids` from the `_from` address to the `_to` address specified (with safety call).
/// @dev Caller must be approved to manage the tokens being transferred out of the `_from` account (see "Approval" section of the standard).
/// MUST revert if `_to` is the zero address.
/// MUST revert if length of `_ids` is not the same as length of `_values`.
/// MUST revert if any of the balance(s) of the holder(s) for token(s) in `_ids` is lower than the respective amount(s) in `_values` sent to the recipient.
/// MUST revert on any other error.
/// MUST emit `TransferSingle` or `TransferBatch` event(s) such that all the balance changes are reflected (see "Safe Transfer Rules" section of the standard).
/// Balance changes and events MUST follow the ordering of the arrays (_ids[0]/_values[0] before _ids[1]/_values[1], etc).
/// After the above conditions for the transfer(s) in the batch are met, this function MUST check if `_to` is a smart contract (e.g. code size > 0). If so, it MUST call the relevant `ERC1155TokenReceiver` hook(s) on `_to` and act appropriately (see "Safe Transfer Rules" section of the standard).
/// @param _from Source address
/// @param _to Target address
/// @param _ids IDs of each token type (order and length must match _values array)
/// @param _values Transfer amounts per token type (order and length must match _ids array)
/// @param _data Additional data with no specified format, MUST be sent unaltered in call to the `ERC1155TokenReceiver` hook(s) on `_to`
function safeBatchTransferFrom(
address _from,
address _to,
uint256[] calldata _ids,
uint256[] calldata _values,
bytes calldata _data
) external override {
require(
msg.sender == _from || isApprovedForAllVar[_from][msg.sender],
"safeBatchTransferFrom: msg.sender is not allowed to manipulate _from tokens"
);
require(
_to != address(0x0),
"safeBatchTransferFrom: cannot transfer to 0x0"
);
require(
_ids.length == _values.length,
"safeBatchTransferFrom: _ids and _values lenght mismatch"
);
uint256 tmp;
while (tmp < _ids.length) {
//using while for 0 case optimization
require(
_values[tmp] <= balanceOfVar[_from][_ids[tmp]],
"safeBatchTransferFrom: Balance of _from is too low to transfer _values tokens"
);
//Adjusting the balances
balanceOfVar[_from][_ids[tmp]] =
balanceOfVar[_from][_ids[tmp]] -
_values[tmp];
balanceOfVar[_to][_ids[tmp]] =
balanceOfVar[_to][_ids[tmp]] +
_values[tmp];
tmp++;
}
//Emitting the event
emit TransferBatch(msg.sender, _from, _to, _ids, _values);
if (isContract(_to)) {
//bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)")) == 0xf23a6e61
require(
IERC1155TokenReceiver(_to).onERC1155BatchReceived(
msg.sender,
_from,
_ids,
_values,
_data
) == bytes4(0xbc197c81)
);
}
}
/// @notice Get the balance of an account's tokens.
/// @param _owner The address of the token holder
/// @param _id ID of the token
/// @return The _owner's balance of the token type requested
function balanceOf(
address _owner,
uint256 _id
) external view override returns (uint256) {
return balanceOfVar[_owner][_id];
}
/// @notice Get the balance of multiple account/token pairs
/// @param _owners The addresses of the token holders
/// @param _ids ID of the tokens
/// @return balances The _owner's balance of the token types requested (i.e. balance for each (owner, id) pair)
function balanceOfBatch(
address[] calldata _owners,
uint256[] calldata _ids
) external view override returns (uint256[] memory) {
//Making value readable from stack directly instead of having to read the stack as pointer to get length = less gas when looping
uint256 ownerslength = _owners.length;
uint256 idslength = _ids.length;
require(
ownerslength == idslength,
"owners and ids must have the same length"
);
uint256[] memory retour = new uint256[](ownerslength);
uint256 i;
//using while for 0 case optimization
while (i < ownerslength) {
//iterating owners
retour[i] = balanceOfVar[_owners[i]][_ids[i]];
i++;
}
return retour;
}
/// @notice Enable or disable approval for a third party ("operator") to manage all of the caller's tokens.
/// @dev MUST emit the ApprovalForAll event on success.
/// @param _operator Address to add to the set of authorized operators
/// @param _approved True if the operator is approved, false to revoke approval
function setApprovalForAll(
address _operator,
bool _approved
) external override {
//mapping(address => mapping(address => bool)) internal isApprovedForAllVar; // owner => oprator => isapproved ?
isApprovedForAllVar[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/// @notice Queries the approval status of an operator for a given owner.
/// @param _owner The owner of the tokens
/// @param _operator Address of authorized operator
/// @return True if the operator is approved, false if not
function isApprovedForAll(
address _owner,
address _operator
) external view override returns (bool) {
return isApprovedForAllVar[_owner][_operator];
}
/// @notice Query if a contract implements an interface
/// @param interfaceID The interface identifier, as specified in ERC-165
/// @dev Interface identification is specified in ERC-165. This function
/// uses less than 30,000 gas.
/// @return `true` if the contract implements `interfaceID` and
/// `interfaceID` is not 0xffffffff, `false` otherwise
function supportsInterface(
bytes4 interfaceID
) external pure override returns (bool) {
bool retour = interfaceID == 0xd9b67a26;
return (retour);
}
/// @notice Mint tokens for message.sender
/// @param _id The tokens ID
/// @param _value Minted amount
/// @param _uri The token URi
function mint(uint256 _id, uint256 _value, string calldata _uri) external {
require(msg.sender == owner);
//Adjusting the balance
balanceOfVar[msg.sender][_id] = balanceOfVar[msg.sender][_id] + _value;
//Emitting the event
emit TransferSingle(msg.sender, address(0x0), msg.sender, _id, _value);
if (isContract(msg.sender)) {
//bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)")) == 0xf23a6e61
require(
IERC1155TokenReceiver(msg.sender).onERC1155Received(
msg.sender,
msg.sender,
_id,
_value,
""
) == bytes4(0xf23a6e61)
);
}
if (!occupiedTokenID[_id]) {
occupiedTokenID[_id] = true;
tokenIDArray.push(_id);
}
m_tokenURI[_id] = _uri;
emit URI(_uri, _id);
}
function setURI(uint256 _id, string calldata _uri) external {
require(msg.sender == owner);
m_tokenURI[_id] = _uri;
emit URI(_uri, _id);
}
/// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
/// @dev Throws if `_tokenId` is not a valid NFT. URIs are defined in RFC
/// 3986. The URI may point to a JSON file that conforms to the "ERC721
/// Metadata JSON Schema".
function uri(uint256 _tokenId) external view returns (string memory) {
return m_tokenURI[_tokenId];
}
/// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
/// @dev Throws if `_tokenId` is not a valid NFT. URIs are defined in RFC
/// 3986. The URI may point to a JSON file that conforms to the "ERC721
/// Metadata JSON Schema".
function tokenURI(uint256 _tokenId) external view returns (string memory) {
return m_tokenURI[_tokenId];
}
function getTokenIDArray() external view returns (uint256[] memory) {
return tokenIDArray;
}
/// @notice Check if an address is a contract
/// @param _address The adress you want to test
/// @return true if the address has bytecode, false if not
function isContract(address _address) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
assembly {
codehash := extcodehash(_address)
}
return (codehash != accountHash && codehash != 0x0);
}
mapping(uint256 => address) royaltyReceiver;
mapping(uint256 => uint256) royaltyPercentage;
function setRoyaltyInfo(
uint256,
address receiver,
uint256 percentkage
) external {
require(msg.sender == owner);
royaltyReceiver[0] = receiver;
royaltyPercentage[0] = percentkage;
}
function royaltyInfo(
uint256,
uint256 finalAmount
) public view returns (address receiver, uint256 royaltyAmount) {
uint256 royalty = (finalAmount * royaltyPercentage[0]) / 100000;
return (royaltyReceiver[0], royalty);
}
}
contracts/test/ERC20Generic.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2022. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
import "../interfaces/IERC20.sol";
import "../interfaces/IERC165.sol";
/// @author Guillaume Gonnaud 2020
/// @title ERC20 Generic placeholder smart contract for testing and ABI
contract ERC20Generic is IERC20, IERC165 {
string public name; // Returns the name of the token - e.g. "Generic ERC20".
string public symbol; // Returns the symbol of the token. E.g. GEN20.
uint8 public decimals; // Returns the number of decimals the token uses - e.g. 8, means to divide the token amount by 100000000 to get its user representation.
uint256 public override totalSupply; //Returns the total token supply.
mapping(address => uint256) public override balanceOf; //Returns the account balance of another account with address _owner.
mapping(address => mapping(address => uint256))
internal individualAllowance; // Mapping of allowance per owner/spender
mapping(bytes4 => bool) supportedInterfaces;
/// @notice Constructor
/// @dev Please change the values in here if you want more specific values, or make the constructor takes arguments
constructor() {
name = "fake USD";
symbol = "fUSD";
decimals = 6; //Same as USDC
supportedInterfaces[0x01ffc9a7] = true; //ERC165
supportedInterfaces[0x36372b07] = true; //ERC20
}
/// @notice Transfer a _value amount of ERC token from msg.sender to _to
/// Throw if msg.sender doesn't have enough tokens
/// @param _to The address of the recipient
/// @param _value The amount of token to send
/// @return success true if success, throw if failed
function transfer(
address _to,
uint256 _value
) public override returns (bool success) {
require(
balanceOf[msg.sender] >= _value,
"transfer: msg.sender balance is too low"
);
balanceOf[msg.sender] = balanceOf[msg.sender] - _value;
balanceOf[_to] = balanceOf[_to] + _value;
emit Transfer(msg.sender, _to, _value);
return true;
}
/// @notice Transfer a _value amount of ERC token from _drom to _to.
/// Only work if msg.sender == from or if msg.sender allowance < value
/// Throw if _from doesn't have enough tokens
/// @param _from The address of the account being removed tokens
/// @param _to The address of the account being given tokens
/// @param _value The amount of token to send
/// @return success true if success, throw if failed
function transferFrom(
address _from,
address _to,
uint256 _value
) public override returns (bool success) {
require(
balanceOf[_from] >= _value,
"transferFrom: _from balance is too low"
);
require(
individualAllowance[_from][msg.sender] >= _value ||
msg.sender == _from,
"transferFrom: msg.sender allowance with _from is too low"
);
if (msg.sender != _from) {
individualAllowance[_from][msg.sender] =
individualAllowance[_from][msg.sender] -
_value;
}
balanceOf[_from] = balanceOf[_from] - _value;
balanceOf[_to] = balanceOf[_to] + _value;
emit Transfer(_from, _to, _value);
return true;
}
/// @notice Approve an amount of token _spender can spend on behalf of msg.sender
/// @param _spender The address of the account being approved for tokens
/// @param _value The amount of token to be spent in total
/// @return success true if success
function approve(
address _spender,
uint256 _value
) public override returns (bool success) {
individualAllowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/// @notice get the approved amount of token _spender can spend on behalf of _owner
/// @param _owner The address of the account being approved for tokens
/// @param _spender The amount of token to be spent in total
/// @return remaining the allowance of _spender on behalf of _owner
function allowance(
address _owner,
address _spender
) public view override returns (uint256 remaining) {
return individualAllowance[_owner][_spender];
}
/// @notice Mint _value tokens for msg.sender
/// Function not present in ERC20 spec : allow for the minting of a token for test purposes
/// @param _value Amount of tokens to mint
function mint(uint256 _value) public {
balanceOf[msg.sender] = balanceOf[msg.sender] + _value;
totalSupply += _value;
}
/// @notice Mint _value tokens for msg.sender
/// Function not present in ERC20 spec : allow for the minting of a token for test purposes
/// @param _value Amount of tokens to mint
/// @param _recipient The recipient of the minted tokens
function mintFor(uint256 _value, address _recipient) public {
balanceOf[_recipient] = balanceOf[_recipient] + _value;
totalSupply += _value;
}
/// @notice Query if a contract implements an interface
/// @param interfaceID The interface identifier, as specified in ERC-165
/// @dev Interface identification is specified in ERC-165. This function
/// uses less than 30,000 gas.
/// @return `true` if the contract implements `interfaceID` and
/// `interfaceID` is not 0xffffffff, `false` otherwise
function supportsInterface(
bytes4 interfaceID
) external view override returns (bool) {
return (supportedInterfaces[interfaceID]);
}
}
contracts/test/ERC721GenericMintFor.sol
// SPDX-License-Identifier: UNLICENSED
// © Copyright 2022. All rights reserved. Perpetual Altruism Ltd.
pragma solidity 0.8.28;
import "../interfaces/IERC721.sol";
import "../interfaces/IERC721TokenReceiver.sol";
import "../interfaces/IERC165.sol";
import "../interfaces/IERC173.sol";
/// @author Guillaume Gonnaud 2021
/// @title ERC721 Generic placeholder smart contract for testing and ABI
contract ERC721GenericMintFor is IERC721, IERC165, IERC173 {
string public name; // Returns the name of the token - e.g. "Generic ERC721".
string public symbol; // Returns the symbol of the token. E.g. GEN721.
mapping(address => uint256) public override balanceOf; //The number of token an address own
uint256 public totalSupply; //The total amount of minted tokens
mapping(uint256 => string) tokenURIs;
address public owner;
mapping(uint256 => address) internal ownerOfVar;
mapping(uint256 => address) internal approvedTransferAddress; //Address allowed to Transfer a token
mapping(address => mapping(address => bool)) internal approvedOperator; //Approved operators mapping: owner => operator => allowed?
mapping(bytes4 => bool) supportedInterfaces;
/// @notice Constructor
/// @dev Please change the values in here if you want more specific values, or make the constructor takes arguments
constructor(string memory _name, string memory _symbol) {
owner = msg.sender;
name = _name;
symbol = _symbol;
supportedInterfaces[0x2a55205a] = true; //Royalty standard ERC2981
supportedInterfaces[0x80ac58cd] = true; //ERC721
supportedInterfaces[0x5b5e139f] = true; //ERC721Metadata support (NFT images/json)
supportedInterfaces[0x01ffc9a7] = true; //ERC165
}
function transferOwnership(address _newOwner) external {
require(owner == msg.sender, "Only the owner can do this");
owner = _newOwner;
emit OwnershipTransferred(owner, _newOwner);
}
/// @notice Find the owner of an NFT
/// @dev NFTs assigned to zero address are considered invalid, and queries about them do throw.
/// @param _tokenId The identifier for an NFT
/// @return The address of the owner of the NFT
function ownerOf(
uint256 _tokenId
) external view override returns (address) {
require(
ownerOfVar[_tokenId] != address(0x0),
"ownerOf: ERC721 NFTs assigned to the zero address are considered invalid"
);
return ownerOfVar[_tokenId];
}
/// @notice Transfers the ownership of an NFT from one address to another address
/// @dev Throws unless `msg.sender` is the current owner, an authorized
/// operator, or the approved address for this NFT. Throws if `_from` is
/// not the current owner. Throws if `_to` is the zero address. Throws if
/// `_tokenId` is not a valid NFT. When transfer is complete, this function
/// checks if `_to` is a smart contract (code size > 0). If so, it calls
/// `onERC721Received` on `_to` and throws if the return value is not
/// `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`.
/// @param _from The current owner of the NFT
/// @param _to The new owner
/// @param _tokenId The NFT to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes calldata data
) external payable override {
safeTransferFromInternal(_from, _to, _tokenId, data);
}
/// @notice Transfers the ownership of an NFT from one address to another address
/// @dev This works identically to the other function with an extra data parameter,
/// except this function just sets data to "".
/// @param _from The current owner of the NFT
/// @param _to The new owner
/// @param _tokenId The NFT to transfer
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId
) external payable override {
safeTransferFromInternal(_from, _to, _tokenId, "");
}
/// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE
/// TO CONFIRM THAT `_to` IS CAPABLE OF RECEIVING NFTS OR ELSE
/// THEY MAY BE PERMANENTLY LOST
/// @dev Throws unless `msg.sender` is the current owner, an authorized
/// operator, or the approved address for this NFT. Throws if `_from` is
/// not the current owner. Throws if `_to` is the zero address. Throws if
/// `_tokenId` is not a valid NFT.
/// @param _from The current owner of the NFT
/// @param _to The new owner
/// @param _tokenId The NFT to transfer
function transferFrom(
address _from,
address _to,
uint256 _tokenId
) external payable override {
transferFromInternal(_from, _to, _tokenId);
}
/// @notice Change or reaffirm the approved address for an NFT
/// @dev The zero address indicates there is no approved address.
/// Throws unless `msg.sender` is the current NFT owner, or an authorized
/// operator of the current owner.
/// @param _approved The new approved NFT controller
/// @param _tokenId The NFT to approve
function approve(
address _approved,
uint256 _tokenId
) external payable override {
require(
msg.sender == ownerOfVar[_tokenId] ||
approvedOperator[ownerOfVar[_tokenId]][msg.sender],
"approve: msg.sender is not allowed to approve the token"
);
approvedTransferAddress[_tokenId] = _approved;
emit Approval(ownerOfVar[_tokenId], _approved, _tokenId);
}
/// @notice Enable or disable approval for a third party ("operator") to manage
/// all of `msg.sender`'s assets
/// @dev Emits the ApprovalForAll event. The contract MUST allow
/// multiple operators per owner.
/// @param _operator Address to add to the set of authorized operators
/// @param _approved True if the operator is approved, false to revoke approval
function setApprovalForAll(
address _operator,
bool _approved
) external override {
approvedOperator[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/// @notice Get the approved address for a single NFT
/// @dev Throws if `_tokenId` is not a valid NFT.
/// @param _tokenId The NFT to find the approved address for
/// @return The approved address for this NFT, or the zero address if there is none
function getApproved(
uint256 _tokenId
) external view override returns (address) {
return approvedTransferAddress[_tokenId];
}
/// @notice Query if an address is an authorized operator for another address
/// @param _owner The address that owns the NFTs
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(
address _owner,
address _operator
) external view override returns (bool) {
return approvedOperator[_owner][_operator];
}
/// @notice Query if a contract implements an interface
/// @param interfaceID The interface identifier, as specified in ERC-165
/// @dev Interface identification is specified in ERC-165. This function
/// uses less than 30,000 gas.
/// @return `true` if the contract implements `interfaceID` and
/// `interfaceID` is not 0xffffffff, `false` otherwise
function supportsInterface(
bytes4 interfaceID
) external view override returns (bool) {
return (supportedInterfaces[interfaceID]);
}
/// @notice Mint a token for msg.sender
function mint(string calldata _URI) external returns (uint256) {
require(owner == msg.sender, "Only the owner can mint");
return internalMint(_URI);
}
/// @notice Mint a token for msg.sender
function mintCreator(
address _creator,
string calldata _URI
) external returns (uint256) {
require(owner == msg.sender, "Only the owner can mint");
return internalMintCreator(_creator, _URI);
}
/// @notice Mint a tokenId for someone
function mintCustomStartAuction(
address _for,
uint _tokenId,
string calldata _URI
) external returns (uint256) {
require(owner == msg.sender, "Only the owner can mint");
return internalMintCustomStartAuction(_for, _tokenId, _URI);
}
function internalMintCustomStartAuction(
address _for,
uint _tokenId,
string calldata _URI
) internal returns (uint256) {
require(
ownerOfVar[_tokenId] == address(0),
"tokenId has already been minted"
);
totalSupply++;
balanceOf[msg.sender] = balanceOf[msg.sender] + 1;
//Changing ownership
ownerOfVar[_tokenId] = msg.sender;
tokenURIs[_tokenId] = _URI;
//Emitting transfer event
emit Transfer(address(0x0), _for, _tokenId);
emit Transfer(_for, msg.sender, _tokenId);
if (isContract(msg.sender)) {
//bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")) == 0x150b7a02
require(
IERC721TokenReceiver(msg.sender).onERC721Received(
msg.sender,
_for,
_tokenId,
""
) == bytes4(0x150b7a02)
);
}
return _tokenId;
}
function internalMintCreator(
address _creator,
string calldata _URI
) internal returns (uint256) {
totalSupply++;
balanceOf[msg.sender] = balanceOf[msg.sender] + 1;
//Changing ownership
ownerOfVar[totalSupply] = msg.sender;
tokenURIs[totalSupply] = _URI;
//Emitting transfer event
emit Transfer(address(0x0), _creator, totalSupply);
emit Transfer(_creator, msg.sender, totalSupply);
return totalSupply;
}
function internalMint(string calldata _URI) internal returns (uint256) {
totalSupply++;
balanceOf[msg.sender] = balanceOf[msg.sender] + 1;
//Changing ownership
ownerOfVar[totalSupply] = msg.sender;
tokenURIs[totalSupply] = _URI;
//Emitting transfer event
emit Transfer(address(0x0), msg.sender, totalSupply);
return totalSupply;
}
/// @dev Called by both variants of Safetransfer. Is a transfer followed by a smartContract check and then
/// an onERC721Received call
function safeTransferFromInternal(
address _from,
address _to,
uint256 _tokenId,
bytes memory data
) internal {
transferFromInternal(_from, _to, _tokenId);
if (isContract(_to)) {
//bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")) == 0x150b7a02
require(
IERC721TokenReceiver(_to).onERC721Received(
msg.sender,
_from,
_tokenId,
data
) == bytes4(0x150b7a02)
);
}
}
/// @dev Actual token transfer code called by all the other functions
function transferFromInternal(
address _from,
address _to,
uint256 _tokenId
) internal {
require(
_to != address(0x0),
"transferFromInternal: Tokens cannot be send to 0x0. Use 0xdead instead ?"
);
require(
ownerOfVar[_tokenId] == _from,
"transferFromInternal: _from is not the owner of the token"
);
require(
msg.sender == ownerOfVar[_tokenId] ||
approvedOperator[ownerOfVar[_tokenId]][msg.sender] ||
msg.sender == approvedTransferAddress[_tokenId],
"transferFromInternal: msg.sender is not allowed to manipulate the token"
);
// Adjusting token balances
if (_from != address(0x0)) {
balanceOf[_from] = balanceOf[_from] - 1;
}
balanceOf[_to] = balanceOf[_to] + 1;
//Resetting approved addresse permission
approvedTransferAddress[_tokenId] = address(0x0);
//Changing ownership
ownerOfVar[_tokenId] = _to;
//Emitting transfer event
emit Transfer(_from, _to, _tokenId);
}
/// @notice Check if an address is a contract
/// @param _address The adress you want to test
/// @return true if the address has bytecode, false if not
function isContract(address _address) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
assembly {
codehash := extcodehash(_address)
}
return (codehash != accountHash && codehash != 0x0);
}
mapping(uint256 => address) royaltyReceiver;
mapping(uint256 => uint256) royaltyPercentage;
function setRoyaltyInfo(
uint256,
address receiver,
uint256 percentkage
) external {
require(msg.sender == owner);
royaltyReceiver[0] = receiver;
royaltyPercentage[0] = percentkage;
}
function royaltyInfo(
uint256,
uint256 finalAmount
) public view returns (address receiver, uint256 royaltyAmount) {
uint256 royalty = (finalAmount * royaltyPercentage[0]) / 100000;
return (royaltyReceiver[0], royalty);
}
/// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
/// @dev Throws if `_tokenId` is not a valid NFT. URIs are defined in RFC
/// 3986. The URI may point to a JSON file that conforms to the "ERC721
/// Metadata JSON Schema".
function tokenURI(uint256 _tokenId) external view returns (string memory) {
return (tokenURIs[_tokenId]);
}
function _setTokenURI(uint256 _tokenId, string memory _tokenURI) internal {
tokenURIs[_tokenId] = _tokenURI;
}
function setTokenURI(uint256 _tokenId, string memory _tokenURI) external {
require(msg.sender == owner);
_setTokenURI(_tokenId, _tokenURI);
}
}
Compiler settingsShow
{
"viaIR": true,
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "paris"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.