Skip to content

siborg-ads/dsponsor-subgraph

Repository files navigation

dsponsor-subgraph

Use the deployed API

Base (Chain ID = 8453)

Mode (Chain ID = 34443)

Sepolia Testnet (Chain ID = 11155111)

Abstract Testnet (Chain ID = 11124)

Request example

query MyQuery {
  # get latest ad offers
  adOffers(
    orderBy: creationTimestamp
    orderDirection: desc
    first: 15
    where: { and: [{ disable: false }] }
  ) {
    id # offerId
    name

    metadataURL
    metadata {
      creator_categories
      offer_name
      offer_categories
      offer_validFrom
      offer_validTo
    }

    nftContract {
      id # DSponsorNFT smart contract address
      owner # contract owner

      contractURI
      metadata {
        name
        description
        external_link
      }

      allowList # defines if there is a token allowlist
      # default mint prices
      prices(where: { enabled: true }) {
        currency # ERC20 smart contract
        amount # wei, mind decimals() function to transform in human readable value !
        enabled
      }

      # ERC-2981: NFT Royalty Standard
      royalty {
        receiver 
        bps
      }

      # get all tokens - /!\ non-minted tokens may not appear here
      tokens {
        tokenId
        owner # token ownshership
        mint {
          tokenData
          transactionHash # if = null => not minted yet, so it's available
        }
        setInAllowList # to check is allowList (above) is true, define if is in allowlist
      }
    }
  }
  # get current marketplace listing (auctions & direct buys)
  marketplaceListings(
    orderBy: endTime
    orderDirection: asc
    where: {
      and: [
        {
          status: CREATED
          quantity_gt: 0
          # startTime_lte: 1713371400 # TO REPLACE BY current timestamp
          # endTime_gte: 1713371400 # TO REPLACE BY current timestamp
        }
      ]
    }
  ) {
    id # listingId
    token {
      tokenId
      nftContract {
        id # = assetContract
        adOffers {
          metadataURL # offerMetadata
        }
      }
      mint {
        tokenData
      }
    }

    # listingType = 0 <-> 'Direct', listingType = 1 <-> 'Auction'
    listingType

    currency # ERC20 smart contract addr
    # PRICE
    # if listingType = 'Direct'
    #    price = buyoutPricePerToken
    # else if listingType = 'Auction'
    #    price = bids[0].totalBidAmount || reservePricePerToken
    reservePricePerToken
    buyoutPricePerToken
    bids(orderBy: totalBidAmount, orderDirection: desc, first: 1) {
      bidder
      totalBidAmount
      status
    }

    lister

    startTime
    endTime

    # 'UNSET', 'CREATED', 'COMPLETED' or 'CANCELLED'
    status

    tokenType
    transferType
    rentalExpirationTimestamp
  }
  # get all revenues per month, year, currency
  epochCurrencyRevenues {
    year
    month
    currency
    totalAmount 
    callsWithProtocolFee {
      fee
      spender
      enabler
      referralAddresses
      transactionHash
      revenueTransaction {
        # fees from mint in this tx
        mints {
          tokenId
          tokenData
          from
          to
          amount
          feeMethodology
          currency
          amountSentToProtocol
          protocolRecipient
        }
        # fees from a direct lisitng (secondary sale) in this tx
        marketplaceDirectBuys {
          id
          listing {
            id
            token {
              nftContract {
                id
              }
            }
          }
          feeMethodology
          amountSentToProtocol # same as fee
          protocolRecipient
          amountSentToSeller
          amountSentToCreator
          creatorRecipient
          quantityBought
          totalPricePaid
        }
      }
    }
  }
}

Development

Follow the instructions from The Graph website.

Setup

npm install -g @graphprotocol/graph-cli
npm i
graph auth --studio <deploy-key-from-studio>

Build

npm run build

Test

Docker must be installed on the machine.

npm run test 

Deploy

Deploy on The Graph Studio

npm run deploy-<THEGRAPH-NETWORK>
Available THEGRAPH-NETWORK values
  • base
  • mode-mainnet
  • sepolia

Deploy on Alchemy Subgraphs

Get you API key on the Alchemy dashboard

graph deploy dsponsor-subgraph-sepolia \
--version-label v0.1 \
--node https://subgraphs.alchemy.com/api/subgraphs/deploy \
--ipfs https://ipfs.satsuma.xyz 
--network <ALCHEMY-NETWORK> \
--deploy-key <DEPLOY_KEY>
Available ALCHEMY-NETWORK values
  • base
  • mode-mainnet
  • sepolia

Deploy on Goldsky

  • First you should update the subgraph.yaml and then rebuild
rm -rf build && rm -rf generated
npm run build
goldsky login
goldsky subgraph deploy <NAME>/<VERSION> --path .