Skip to content

Instantly share code, notes, and snippets.

@nazt
Forked from dievardump/README.md
Created January 23, 2022 21:43
Show Gist options
  • Save nazt/5379d82da5f71af4d9abcafaa23d48ca to your computer and use it in GitHub Desktop.
Save nazt/5379d82da5f71af4d9abcafaa23d48ca to your computer and use it in GitHub Desktop.

Revisions

  1. @dievardump dievardump revised this gist Sep 3, 2021. 1 changed file with 32 additions and 14 deletions.
    46 changes: 32 additions & 14 deletions BaseOpenSea.sol
    Original file line number Diff line number Diff line change
    @@ -3,34 +3,52 @@ pragma solidity ^0.8.0;

    /// @title OpenSea contract helper that defines a few things
    /// @author Simon Fremaux (@dievardump)
    /// @dev This is a contract used to add OpenSea's support for gas-less trading
    /// by checking if operator is owner's proxy
    /// @dev This is a contract used to add OpenSea's
    /// gas-less trading and contractURI support
    contract BaseOpenSea {
    string private _contractURI;
    ProxyRegistry private _proxyRegistry;
    address private _proxyRegistry;

    /// @notice Returns the contract URI function. Used on OpenSea to get details
    /// about a contract (owner, royalties etc...)
    /// See documentation: https://docs.opensea.io/docs/contract-level-metadata
    // about a contract (owner, royalties etc...)
    function contractURI() public view returns (string memory) {
    return _contractURI;
    }

    /// @notice Helper for OpenSea gas-less trading
    /// @dev Allows to check if `operator` is owner's OpenSea proxy
    /// @notice Returns the current OS proxyRegistry address registered
    function proxyRegistry() public view returns (address) {
    return _proxyRegistry;
    }

    /// @notice Helper allowing OpenSea gas-less trading by verifying who's operator
    /// for owner
    /// @dev Allows to check if `operator` is owner's OpenSea proxy on eth mainnet / rinkeby
    /// or to check if operator is OpenSea's proxy contract on Polygon and Mumbai
    /// @param owner the owner we check for
    /// @param operator the operator (proxy) we check for
    function isOwnersOpenSeaProxy(address owner, address operator)
    public
    view
    returns (bool)
    {
    ProxyRegistry proxyRegistry = _proxyRegistry;
    return
    // we have a proxy registry address
    address(proxyRegistry) != address(0) &&
    // current operator is owner's proxy address
    address(proxyRegistry.proxies(owner)) == operator;
    address proxyRegistry_ = _proxyRegistry;

    // if we have a proxy registry
    if (proxyRegistry_ != address(0)) {
    // on ethereum mainnet or rinkeby use "ProxyRegistry" to
    // get owner's proxy
    if (block.chainid == 1 || block.chainid == 4) {
    return
    address(ProxyRegistry(proxyRegistry_).proxies(owner)) ==
    operator;
    } else if (block.chainid == 137 || block.chainid == 80001) {
    // on Polygon and Mumbai just try with OpenSea's proxy contract
    // https://docs.opensea.io/docs/polygon-basic-integration
    return proxyRegistry_ == operator;
    }
    }

    return false;
    }

    /// @dev Internal function to set the _contractURI
    @@ -42,7 +60,7 @@ contract BaseOpenSea {
    /// @dev Internal function to set the _proxyRegistry
    /// @param proxyRegistryAddress the new proxy registry address
    function _setOpenSeaRegistry(address proxyRegistryAddress) internal {
    _proxyRegistry = ProxyRegistry(proxyRegistryAddress);
    _proxyRegistry = proxyRegistryAddress;
    }
    }

  2. @dievardump dievardump renamed this gist Sep 1, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions My1155.sol → MyERC1155.sol
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ import "./OpenSea/BaseOpenSea.sol";
    /// @title Example of usage of BaseOpenSea
    /// @author Simon Fremaux (@dievardump)
    /// @notice This contract is only an example of how I implement BaseOpenSea
    contract My1155 is
    contract MyERC1155 is
    Ownable,
    ERC1155,
    BaseOpenSea
    @@ -18,7 +18,7 @@ contract My1155 is
    /// @param uri_ - the contract base uri
    /// @param openSeaProxyRegistry - the address of OpenSea Proxy Registry
    /// @param contractURI_ - the contract metadata URI (https://docs.opensea.io/docs/contract-level-metadata)
    constructor(string memory uri_, address openSeaProxyRegistry, string memory contractURI_) ERC155(uri_) {
    constructor(string memory uri_, address openSeaProxyRegistry, string memory contractURI_) ERC1155(uri_) {
    if (openSeaProxyRegistry != address(0)) {
    _setOpenSeaRegistry(openSeaProxyRegistry);
    }
  3. @dievardump dievardump revised this gist Sep 1, 2021. 2 changed files with 51 additions and 1 deletion.
    50 changes: 50 additions & 0 deletions My1155.sol
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    //SPDX-License-Identifier: MIT
    pragma solidity ^0.8.0;

    import "@openzeppelin/contracts/access/Ownable.sol";
    import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

    import "./OpenSea/BaseOpenSea.sol";

    /// @title Example of usage of BaseOpenSea
    /// @author Simon Fremaux (@dievardump)
    /// @notice This contract is only an example of how I implement BaseOpenSea
    contract My1155 is
    Ownable,
    ERC1155,
    BaseOpenSea
    {
    /// @notice constructor
    /// @param uri_ - the contract base uri
    /// @param openSeaProxyRegistry - the address of OpenSea Proxy Registry
    /// @param contractURI_ - the contract metadata URI (https://docs.opensea.io/docs/contract-level-metadata)
    constructor(string memory uri_, address openSeaProxyRegistry, string memory contractURI_) ERC155(uri_) {
    if (openSeaProxyRegistry != address(0)) {
    _setOpenSeaRegistry(openSeaProxyRegistry);
    }

    if (bytes(contractURI_).length > 0) {
    _setContractURI(contractURI_);
    }
    }

    /// @notice Allows gas-less trading on OpenSea by safelisting the ProxyRegistry of the user
    /// @dev Override isApprovedForAll to check first if current operator is owner's OpenSea proxy
    /// @inheritdoc ERC1155
    function isApprovedForAll(address owner, address operator)
    public
    view
    override
    returns (bool)
    {
    // allows gas less trading on OpenSea
    return super.isApprovedForAll(owner, operator) || isOwnersOpenSeaProxy(owner, operator);
    }

    /// @notice Helper for the owner of the contract to set the new contract URI
    /// @dev caller needs to be owner
    /// @param contractURI_ new contract URI
    function setContractURI(string memory contractURI_) external onlyOwner {
    _setContractURI(contractURI_);
    }
    }
    2 changes: 1 addition & 1 deletion MyNFT.sol → MyERC721.sol
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ import "./OpenSea/BaseOpenSea.sol";
    /// @title Example of usage of BaseOpenSea
    /// @author Simon Fremaux (@dievardump)
    /// @notice This contract is only an example of how I implement BaseOpenSea
    contract MyNFT is
    contract MyERC721 is
    Ownable,
    ERC721,
    BaseOpenSea
  4. @dievardump dievardump revised this gist Aug 1, 2021. 3 changed files with 8 additions and 4 deletions.
    3 changes: 2 additions & 1 deletion BaseOpenSea.sol
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,8 @@ contract BaseOpenSea {
    ProxyRegistry private _proxyRegistry;

    /// @notice Returns the contract URI function. Used on OpenSea to get details
    // about a contract (owner, royalties etc...)
    /// about a contract (owner, royalties etc...)
    /// See documentation: https://docs.opensea.io/docs/contract-level-metadata
    function contractURI() public view returns (string memory) {
    return _contractURI;
    }
    2 changes: 1 addition & 1 deletion MyNFT.sol
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ contract MyNFT is
    {
    /// @notice constructor
    /// @param openSeaProxyRegistry - the address of OpenSea Proxy Registry
    /// @param contractURI_ - the contract metadata URI
    /// @param contractURI_ - the contract metadata URI (https://docs.opensea.io/docs/contract-level-metadata)
    constructor(address openSeaProxyRegistry, string memory contractURI_) ERC721('MyNFT', 'NFT') {
    if (openSeaProxyRegistry != address(0)) {
    _setOpenSeaRegistry(openSeaProxyRegistry);
    7 changes: 5 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,14 @@

    Those two files allow to have easy gas-less trading on OpenSea


    # Registries

    OpenSea Proxyregistry addresses:

    Mainnet: 0xa5409ec958c83c3f309868babaca7c86dcb077c1

    Rinkeby: 0xf57b2c51ded3a29e6891aba85459d600256cf317
    Rinkeby: 0xf57b2c51ded3a29e6891aba85459d600256cf317

    # Contract level metadata with `contractURI()`

    https://docs.opensea.io/docs/contract-level-metadata
  5. @dievardump dievardump revised this gist Aug 1, 2021. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,12 @@
    # Gas-Less trading

    Those two files allow to have easy gas-less trading on OpenSea


    # Registries

    OpenSea Proxyregistry addresses:

    Mainnet: 0xa5409ec958c83c3f309868babaca7c86dcb077c1

    Rinkeby: 0xf57b2c51ded3a29e6891aba85459d600256cf317
  6. @dievardump dievardump revised this gist Aug 1, 2021. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    Those two files allow to have easy gas-less trading on OpenSea


    OpenSea Proxyregistry addresses:

    Mainnet: 0xa5409ec958c83c3f309868babaca7c86dcb077c1

    Rinkeby: 0xf57b2c51ded3a29e6891aba85459d600256cf317
  7. @dievardump dievardump revised this gist Aug 1, 2021. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@

    OpenSea Proxyregistry addresses:

    Mainnet: 0xa5409ec958c83c3f309868babaca7c86dcb077c1

    Rinkeby: 0xf57b2c51ded3a29e6891aba85459d600256cf317
  8. @dievardump dievardump revised this gist Aug 1, 2021. 2 changed files with 4 additions and 4 deletions.
    6 changes: 3 additions & 3 deletions BaseOpenSea.sol
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,8 @@ pragma solidity ^0.8.0;

    /// @title OpenSea contract helper that defines a few things
    /// @author Simon Fremaux (@dievardump)
    /// @dev This is a contract used to add OpenSea's gas-less trading support
    /// by verifying if the operator is current owner's Proxy.
    /// @dev This is a contract used to add OpenSea's support for gas-less trading
    /// by checking if operator is owner's proxy
    contract BaseOpenSea {
    string private _contractURI;
    ProxyRegistry private _proxyRegistry;
    @@ -26,7 +26,7 @@ contract BaseOpenSea {
    {
    ProxyRegistry proxyRegistry = _proxyRegistry;
    return
    // we have a proxy address
    // we have a proxy registry address
    address(proxyRegistry) != address(0) &&
    // current operator is owner's proxy address
    address(proxyRegistry.proxies(owner)) == operator;
    2 changes: 1 addition & 1 deletion MyNFT.sol
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ contract MyNFT is

    /// @notice Allows gas-less trading on OpenSea by safelisting the ProxyRegistry of the user
    /// @dev Override isApprovedForAll to check first if current operator is owner's OpenSea proxy
    /// @inheritdoc ERC721Upgradeable
    /// @inheritdoc ERC721
    function isApprovedForAll(address owner, address operator)
    public
    view
  9. @dievardump dievardump revised this gist Aug 1, 2021. 1 changed file with 2 additions and 9 deletions.
    11 changes: 2 additions & 9 deletions BaseOpenSea.sol
    Original file line number Diff line number Diff line change
    @@ -3,19 +3,12 @@ pragma solidity ^0.8.0;

    /// @title OpenSea contract helper that defines a few things
    /// @author Simon Fremaux (@dievardump)
    /// @dev This is a contract used to add OpenSea's support
    /// This is a contract made to work with upgradeable contract,
    /// if you ever add state variables, you must update __gap accordingly.
    /// -> https://forum.openzeppelin.com/t/what-exactly-is-the-reason-for-uint256-50-private-gap/798
    /// if you do not use Upgradeable contracts, you should comment the line that defines __gap
    /// @dev This is a contract used to add OpenSea's gas-less trading support
    /// by verifying if the operator is current owner's Proxy.
    contract BaseOpenSea {
    string private _contractURI;
    ProxyRegistry private _proxyRegistry;

    /// @dev If you ever add new state variable please add BEFORE this comment, and update __gap accordingly
    /// @dev https://forum.openzeppelin.com/t/what-exactly-is-the-reason-for-uint256-50-private-gap/798
    uint256[10] private __gap;

    /// @notice Returns the contract URI function. Used on OpenSea to get details
    // about a contract (owner, royalties etc...)
    function contractURI() public view returns (string memory) {
  10. @dievardump dievardump revised this gist Jul 19, 2021. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions MyNFT.sol
    Original file line number Diff line number Diff line change
    @@ -37,11 +37,7 @@ contract MyNFT is
    returns (bool)
    {
    // allows gas less trading on OpenSea
    if (isOwnersOpenSeaProxy(owner, operator)) {
    return true;
    }

    return super.isApprovedForAll(owner, operator);
    return super.isApprovedForAll(owner, operator) || isOwnersOpenSeaProxy(owner, operator);
    }

    /// @notice Helper for the owner of the contract to set the new contract URI
  11. @dievardump dievardump revised this gist Jun 30, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion MyNFT.sol
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ contract MyNFT is
    /// @notice constructor
    /// @param openSeaProxyRegistry - the address of OpenSea Proxy Registry
    /// @param contractURI_ - the contract metadata URI
    function constructor(address openSeaProxyRegistry, string memory contractURI_) ERC721('MyNFT', 'NFT') {
    constructor(address openSeaProxyRegistry, string memory contractURI_) ERC721('MyNFT', 'NFT') {
    if (openSeaProxyRegistry != address(0)) {
    _setOpenSeaRegistry(openSeaProxyRegistry);
    }
  12. @dievardump dievardump revised this gist Jun 13, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion BaseOpenSea.sol
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    pragma solidity ^0.8.0;

    /// @title OpenSea contract helper that defines a few things
    /// @author Simon Fremaux (@dievrarump)
    /// @author Simon Fremaux (@dievardump)
    /// @dev This is a contract used to add OpenSea's support
    /// This is a contract made to work with upgradeable contract,
    /// if you ever add state variables, you must update __gap accordingly.
  13. @dievardump dievardump revised this gist Jun 12, 2021. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion MyNFT.sol
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,8 @@ import "./OpenSea/BaseOpenSea.sol";
    /// @author Simon Fremaux (@dievardump)
    /// @notice This contract is only an example of how I implement BaseOpenSea
    contract MyNFT is
    Ownable
    Ownable,
    ERC721,
    BaseOpenSea
    {
    /// @notice constructor
  14. @dievardump dievardump revised this gist Jun 12, 2021. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion MyNFT.sol
    Original file line number Diff line number Diff line change
    @@ -15,10 +15,15 @@ contract MyNFT is
    {
    /// @notice constructor
    /// @param openSeaProxyRegistry - the address of OpenSea Proxy Registry
    function constructor(address openSeaProxyRegistry) ERC721('MyNFT', 'NFT') {
    /// @param contractURI_ - the contract metadata URI
    function constructor(address openSeaProxyRegistry, string memory contractURI_) ERC721('MyNFT', 'NFT') {
    if (openSeaProxyRegistry != address(0)) {
    _setOpenSeaRegistry(openSeaProxyRegistry);
    }

    if (bytes(contractURI_).length > 0) {
    _setContractURI(contractURI_);
    }
    }

    /// @notice Allows gas-less trading on OpenSea by safelisting the ProxyRegistry of the user
  15. @dievardump dievardump revised this gist Jun 12, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion MyNFT.sol
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ contract MyNFT is
    }

    /// @notice Allows gas-less trading on OpenSea by safelisting the ProxyRegistry of the user
    /// @dev Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings.
    /// @dev Override isApprovedForAll to check first if current operator is owner's OpenSea proxy
    /// @inheritdoc ERC721Upgradeable
    function isApprovedForAll(address owner, address operator)
    public
  16. @dievardump dievardump revised this gist Jun 12, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion MyNFT.sol
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ contract MyNFT is
    }
    }

    /// @notice Allows gas-less trading on OpenSea by whitelisting the ProxyRegistry of the user
    /// @notice Allows gas-less trading on OpenSea by safelisting the ProxyRegistry of the user
    /// @dev Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings.
    /// @inheritdoc ERC721Upgradeable
    function isApprovedForAll(address owner, address operator)
  17. @dievardump dievardump revised this gist Jun 12, 2021. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion MyNFT.sol
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,12 @@ contract MyNFT is
    BaseOpenSea
    {
    /// @notice constructor
    function constructor() ERC721('MyNFT', 'NFT') {}
    /// @param openSeaProxyRegistry - the address of OpenSea Proxy Registry
    function constructor(address openSeaProxyRegistry) ERC721('MyNFT', 'NFT') {
    if (openSeaProxyRegistry != address(0)) {
    _setOpenSeaRegistry(openSeaProxyRegistry);
    }
    }

    /// @notice Allows gas-less trading on OpenSea by whitelisting the ProxyRegistry of the user
    /// @dev Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings.
  18. @dievardump dievardump created this gist Jun 12, 2021.
    59 changes: 59 additions & 0 deletions BaseOpenSea.sol
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    //SPDX-License-Identifier: MIT
    pragma solidity ^0.8.0;

    /// @title OpenSea contract helper that defines a few things
    /// @author Simon Fremaux (@dievrarump)
    /// @dev This is a contract used to add OpenSea's support
    /// This is a contract made to work with upgradeable contract,
    /// if you ever add state variables, you must update __gap accordingly.
    /// -> https://forum.openzeppelin.com/t/what-exactly-is-the-reason-for-uint256-50-private-gap/798
    /// if you do not use Upgradeable contracts, you should comment the line that defines __gap
    contract BaseOpenSea {
    string private _contractURI;
    ProxyRegistry private _proxyRegistry;

    /// @dev If you ever add new state variable please add BEFORE this comment, and update __gap accordingly
    /// @dev https://forum.openzeppelin.com/t/what-exactly-is-the-reason-for-uint256-50-private-gap/798
    uint256[10] private __gap;

    /// @notice Returns the contract URI function. Used on OpenSea to get details
    // about a contract (owner, royalties etc...)
    function contractURI() public view returns (string memory) {
    return _contractURI;
    }

    /// @notice Helper for OpenSea gas-less trading
    /// @dev Allows to check if `operator` is owner's OpenSea proxy
    /// @param owner the owner we check for
    /// @param operator the operator (proxy) we check for
    function isOwnersOpenSeaProxy(address owner, address operator)
    public
    view
    returns (bool)
    {
    ProxyRegistry proxyRegistry = _proxyRegistry;
    return
    // we have a proxy address
    address(proxyRegistry) != address(0) &&
    // current operator is owner's proxy address
    address(proxyRegistry.proxies(owner)) == operator;
    }

    /// @dev Internal function to set the _contractURI
    /// @param contractURI_ the new contract uri
    function _setContractURI(string memory contractURI_) internal {
    _contractURI = contractURI_;
    }

    /// @dev Internal function to set the _proxyRegistry
    /// @param proxyRegistryAddress the new proxy registry address
    function _setOpenSeaRegistry(address proxyRegistryAddress) internal {
    _proxyRegistry = ProxyRegistry(proxyRegistryAddress);
    }
    }

    contract OwnableDelegateProxy {}

    contract ProxyRegistry {
    mapping(address => OwnableDelegateProxy) public proxies;
    }
    42 changes: 42 additions & 0 deletions MyNFT.sol
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    //SPDX-License-Identifier: MIT
    pragma solidity ^0.8.0;

    import "@openzeppelin/contracts/access/Ownable.sol";
    import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

    import "./OpenSea/BaseOpenSea.sol";

    /// @title Example of usage of BaseOpenSea
    /// @author Simon Fremaux (@dievardump)
    /// @notice This contract is only an example of how I implement BaseOpenSea
    contract MyNFT is
    Ownable
    BaseOpenSea
    {
    /// @notice constructor
    function constructor() ERC721('MyNFT', 'NFT') {}

    /// @notice Allows gas-less trading on OpenSea by whitelisting the ProxyRegistry of the user
    /// @dev Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings.
    /// @inheritdoc ERC721Upgradeable
    function isApprovedForAll(address owner, address operator)
    public
    view
    override
    returns (bool)
    {
    // allows gas less trading on OpenSea
    if (isOwnersOpenSeaProxy(owner, operator)) {
    return true;
    }

    return super.isApprovedForAll(owner, operator);
    }

    /// @notice Helper for the owner of the contract to set the new contract URI
    /// @dev caller needs to be owner
    /// @param contractURI_ new contract URI
    function setContractURI(string memory contractURI_) external onlyOwner {
    _setContractURI(contractURI_);
    }
    }