diff --git a/README.md b/README.md index e3a30058..35ee11b2 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,7 @@ type Item = { type Order = { id: string nftId: string + marketplaceAddress: string contractAddress: string tokenId: string owner: string @@ -139,6 +140,7 @@ type Order = { - `first`: Limit the number of results. Type: `number`. - `skip`: Skip results. Type: `number`. - `sortBy`: Sort results. Possible values: `recently_listed`, `recently_updated`, `cheapest`. +- `marketplaceAddress`: Filter results by marketplace contract address. It supports multiple values by adding the query param multiple times. Type: `address`. - `owner`: Filter by owner. Type: `address`. - `buyer`: Filter by buyer. Type: `address`. - `contractAddress`: Filter results by contract address. It supports multiple values by adding the query param multiple times. Type: `address`. @@ -155,6 +157,7 @@ type Order = { ```ts type Bid = { id: string + bidAddress: string bidder: string seller: string price: string @@ -177,6 +180,7 @@ type Bid = { - `first`: Limit the number of results. Type: `number`. - `skip`: Skip results. Type: `number`. - `sortBy`: Sort results. Possible values: `recently_offered`, `recently_updated`, `most_expensive`. +- `bidAddress`: Filter results by bid contract address. It supports multiple values by adding the query param multiple times. Type: `address`. - `bidder`: Filter by bidder. Type: `address`. - `seller`: Filter by seller. Type: `address`. - `contractAddress`: Filter results by contract address. It supports multiple values by adding the query param multiple times. Type: `address`. diff --git a/package-lock.json b/package-lock.json index 54d0aef9..40de0442 100644 --- a/package-lock.json +++ b/package-lock.json @@ -533,9 +533,9 @@ "dev": true }, "@dcl/schemas": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@dcl/schemas/-/schemas-2.2.0.tgz", - "integrity": "sha512-SCpUfQdq106NNycmoqI/F7NSeyPYpeA8I+F//1a2kvfjjcIi0/ALFY8Ds9Av3LcqaaUUKApYvri/+NPkEBDsTg==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@dcl/schemas/-/schemas-3.0.0.tgz", + "integrity": "sha512-9hs+Vafs9D3X/lYjLnPTXQ1BCcZTUExNhH9aIAbt7LlwXFxN5xvmhFDvEcBZ6KLRgc8SA2lR2Z9KpHalrNk1Uw==", "requires": { "ajv": "^7.1.0" } @@ -1690,8 +1690,7 @@ "assert-plus": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", - "optional": true + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" }, "async-listener": { "version": "0.6.10", @@ -2907,8 +2906,7 @@ "extsprintf": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", - "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=", - "optional": true + "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" }, "fast-deep-equal": { "version": "3.1.3", @@ -3029,7 +3027,6 @@ "version": "1.0.12", "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.12.tgz", "integrity": "sha512-WvJ193OHa0GHPEL+AycEJgxvBEwyfRkN1vhjca23OaPVMCaLCXTd5qAu82AjTcgP1UJmytkOKb63Ypde7raDIg==", - "optional": true, "requires": { "graceful-fs": "^4.1.2", "inherits": "~2.0.0", @@ -5670,8 +5667,7 @@ "jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", - "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", - "optional": true + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" }, "jsdom": { "version": "16.7.0", @@ -7422,8 +7418,7 @@ "tweetnacl": { "version": "0.14.5", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", - "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", - "optional": true + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" }, "type-check": { "version": "0.3.2", diff --git a/package.json b/package.json index 0e47753b..959cbc9d 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "printWidth": 80 }, "dependencies": { - "@dcl/schemas": "^2.2.0", + "@dcl/schemas": "^3.0.0", "@types/sqlite3": "^3.1.7", "@well-known-components/env-config-provider": "^1.0.0", "@well-known-components/http-server": "^1.0.0", diff --git a/src/adapters/handlers/bids.ts b/src/adapters/handlers/bids.ts index 3c25b3a9..020d61d3 100644 --- a/src/adapters/handlers/bids.ts +++ b/src/adapters/handlers/bids.ts @@ -17,6 +17,7 @@ export function createBidsHandler( const sortBy = params.getValue('sortBy', BidSortBy) const bidder = params.getAddress('bidder') const seller = params.getAddress('seller') + const bidAddress = params.getAddress('bidAddress') const contractAddress = params.getAddress('contractAddress') const tokenId = params.getString('tokenId') const status = params.getValue('status', ListingStatus) @@ -29,6 +30,7 @@ export function createBidsHandler( sortBy, bidder, seller, + bidAddress, contractAddress, tokenId, status, diff --git a/src/adapters/handlers/orders.ts b/src/adapters/handlers/orders.ts index 23489303..24531349 100644 --- a/src/adapters/handlers/orders.ts +++ b/src/adapters/handlers/orders.ts @@ -16,6 +16,7 @@ export function createOrdersHandler( const sortBy = params.getValue('sortBy', OrderSortBy) const owner = params.getAddress('owner') const buyer = params.getAddress('buyer') + const marketplaceAddress = params.getAddress('marketplaceAddress') const contractAddress = params.getAddress('contractAddress') const tokenId = params.getString('tokenId') const status = params.getValue('status', ListingStatus) @@ -28,6 +29,7 @@ export function createOrdersHandler( sortBy, owner, buyer, + marketplaceAddress, contractAddress, tokenId, status, diff --git a/src/index.ts b/src/index.ts index 60da856a..41abfa35 100644 --- a/src/index.ts +++ b/src/index.ts @@ -182,8 +182,18 @@ async function initComponents(): Promise { chainId: marketplaceChainId, }) + const collectionsBids = createBidsComponent({ + subgraph: collectionsSubgraph, + network: Network.MATIC, + chainId: collectionsChainId, + }) + + const bids = createMergerComponent({ - sources: [createBidsSource(marketplaceBids)], + sources: [ + createBidsSource(marketplaceBids), + createBidsSource(collectionsBids) + ], defaultSortBy: BID_DEFAULT_SORT_BY, directions: { [BidSortBy.RECENTLY_OFFERED]: SortDirection.DESC, diff --git a/src/ports/bids/types.ts b/src/ports/bids/types.ts index 81c55d32..3012ed68 100644 --- a/src/ports/bids/types.ts +++ b/src/ports/bids/types.ts @@ -7,10 +7,11 @@ export interface IBidsComponent { export type BidFragment = { id: string + bidAddress: string bidder: string seller: string price: string - fingerprint: string + fingerprint?: string status: ListingStatus blockchainId: string blockNumber: string diff --git a/src/ports/bids/utils.ts b/src/ports/bids/utils.ts index e1a8f51c..c59497cb 100644 --- a/src/ports/bids/utils.ts +++ b/src/ports/bids/utils.ts @@ -17,10 +17,11 @@ export function fromBidFragment( ): Bid { const bid: Bid = { id: fragment.id, + bidAddress: fragment.bidAddress, bidder: fragment.bidder, seller: fragment.seller, price: fragment.price, - fingerprint: fragment.fingerprint, + fingerprint: fragment.fingerprint || '0x', status: fragment.status, blockchainId: fragment.blockchainId, blockNumber: fragment.blockNumber, @@ -36,14 +37,15 @@ export function fromBidFragment( return bid } -export const getBidFields = () => ` +export const getBidFields = (withFingerprint: boolean) => ` fragment bidFields on Bid { id + bidAddress blockchainId bidder seller price - fingerprint + ${withFingerprint ? 'fingerprint' : ''} status blockNumber expiresAt @@ -52,7 +54,7 @@ export const getBidFields = () => ` } ` -export const getBidFragment = () => ` +export const getBidFragment = (withFingerprint: boolean) => ` fragment bidFragment on Bid { ...bidFields nft { @@ -60,7 +62,7 @@ export const getBidFragment = () => ` tokenId } } - ${getBidFields()} + ${getBidFields(withFingerprint)} ` export function getBidsQuery(filters: BidFilters, isCount = false) { @@ -68,15 +70,21 @@ export function getBidsQuery(filters: BidFilters, isCount = false) { first, skip, sortBy, + bidAddress, contractAddress, tokenId, bidder, seller, status, + network, } = filters const where: string[] = [] + if (bidAddress) { + where.push(`bidAddress: "${bidAddress}""`) + } + if (contractAddress) { where.push(`nftAddress: "${contractAddress}"`) } @@ -132,14 +140,14 @@ export function getBidsQuery(filters: BidFilters, isCount = false) { return ` query Bids { bids( - first: ${total}, - orderBy: ${orderBy}, - orderDirection: ${orderDirection}, + first: ${total}, + orderBy: ${orderBy}, + orderDirection: ${orderDirection}, where: { ${where.join('\n')} - }) + }) { ${isCount ? 'id' : `...bidFragment`} } } - ${isCount ? '' : getBidFragment()} + ${isCount ? '' : getBidFragment(network === Network.ETHEREUM)} ` } diff --git a/src/ports/orders/types.ts b/src/ports/orders/types.ts index 42747ff9..4ec32243 100644 --- a/src/ports/orders/types.ts +++ b/src/ports/orders/types.ts @@ -7,6 +7,7 @@ export interface IOrdersComponent { export type OrderFragment = { id: string + marketplaceAddress: string nftAddress: string owner: string buyer: string | null diff --git a/src/ports/orders/utils.ts b/src/ports/orders/utils.ts index 9f980176..c8eeac6d 100644 --- a/src/ports/orders/utils.ts +++ b/src/ports/orders/utils.ts @@ -13,6 +13,7 @@ export const ORDER_DEFAULT_SORT_BY = OrderSortBy.RECENTLY_LISTED export const getOrderFields = () => ` fragment orderFields on Order { id + marketplaceAddress nftAddress owner buyer @@ -38,6 +39,7 @@ export const getOrdersQuery = (filters: OrderFilters, isCount = false) => { first, skip, sortBy, + marketplaceAddress, contractAddress, tokenId, buyer, @@ -47,6 +49,10 @@ export const getOrdersQuery = (filters: OrderFilters, isCount = false) => { const where: string[] = [] + if (marketplaceAddress) { + where.push(`marketplaceAddress : "${marketplaceAddress}"`) + } + if (contractAddress) { where.push(`nftAddress: "${contractAddress}"`) } @@ -74,10 +80,10 @@ export const getOrdersQuery = (filters: OrderFilters, isCount = false) => { const total = isCount ? max : typeof first !== 'undefined' - ? typeof skip !== 'undefined' - ? skip + first - : first - : max + ? typeof skip !== 'undefined' + ? skip + first + : first + : max let orderBy: string let orderDirection: string @@ -102,12 +108,12 @@ export const getOrdersQuery = (filters: OrderFilters, isCount = false) => { return ` query Orders { orders( - first: ${total}, - orderBy: ${orderBy}, - orderDirection: ${orderDirection}, + first: ${total}, + orderBy: ${orderBy}, + orderDirection: ${orderDirection}, where: { ${where.join('\n')} - }) + }) { ${isCount ? 'id' : `...orderFragment`} } } ${isCount ? '' : getOrderFragment()} @@ -121,6 +127,7 @@ export function fromOrderFragment( ): Order { const order: Order = { id: fragment.id, + marketplaceAddress: fragment.marketplaceAddress, contractAddress: fragment.nftAddress, tokenId: fragment.nft.tokenId, owner: fragment.owner,