Skip to content

Commit

Permalink
Merge pull request #700 from ArtBlocks/fixing-artbot-listings
Browse files Browse the repository at this point in the history
removing old AB marketplace stuff
  • Loading branch information
grantoesterling authored Dec 3, 2024
2 parents f6850dd + 5f2df25 commit 1c94c51
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@graphql-codegen/typescript-urql": "^3.7.3",
"@graphql-codegen/urql-introspection": "^2.2.1",
"@graphql-tools/utils": "^8.3.0",
"@reservoir0x/reservoir-sdk": "^2.4.11",
"@reservoir0x/reservoir-sdk": "^2.4.32",
"@supabase/supabase-js": "^2.29.0",
"@types/node": "20.1.2",
"@types/node-cron": "^3.0.8",
Expand Down
38 changes: 32 additions & 6 deletions src/Classes/ProjectBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ import { ProjectConfig } from '../ProjectConfig/projectConfig'
import { ProjectHandlerHelper } from './ProjectHandlerHelper'
import { UpcomingProjectDetailFragment } from '../../generated/graphql'
import { getDayName, getMonthName, getDayOfMonth } from '../Utils/common'
import { paths } from '@reservoir0x/reservoir-sdk'

const ONE_MILLION = 1e6

type ReservoirTokenResponse =
paths['/tokens/v7']['get']['responses']['200']['schema']

/**
* Bot for handling projects
*/
Expand Down Expand Up @@ -327,13 +331,35 @@ export class ProjectBot {
inline: true,
})

if (tokenMetadata.list_price && !tokenMetadata.is_flagged) {
embedContent.addFields({
name: 'Buy Now',
value: `[${tokenMetadata.list_price} ${
tokenMetadata.list_currency_symbol
} on Art Blocks Marketplace](${tokenUrl + PROJECTBOT_BUY_UTM})`,
try {
const response = await axios.request<ReservoirTokenResponse>({
method: 'GET',
url: `https://api.reservoir.tools/tokens/v7?tokens=${this.coreContract}%3A${tokenID}`,
headers: { accept: '*/*', 'x-api-key': process.env.RESERVOIR_API_KEY },
timeout: 3000,
})

if (
response.data &&
response.data.tokens &&
response.data.tokens.length > 0
) {
const price =
response.data.tokens[0].market?.floorAsk?.price?.amount?.native
const symbol =
response.data.tokens[0].market?.floorAsk?.price?.currency?.symbol

if (price && symbol) {
embedContent.addFields({
name: 'Buy Now',
value: `[${price} ${symbol} on Art Blocks Marketplace](${
tokenUrl + PROJECTBOT_BUY_UTM
})`,
})
}
}
} catch (e) {
console.error('Error getting price info for token:', tokenID, e)
}
msg.channel.send({ embeds: [embedContent] })
}
Expand Down
2 changes: 0 additions & 2 deletions src/Data/graphql/artbot-hasura-queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ fragment TokenDetail on tokens_metadata {
}
preview_asset_url
live_view_url
list_currency_symbol
list_price
owner {
public_address
}
Expand Down
75 changes: 41 additions & 34 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
} from './Classes/APIBots/utils'
import { ScheduleBot } from './Classes/SchedulerBot'
import { verifyTwitter } from './Utils/twitterUtils'
import axios from 'axios'
import { paths } from '@reservoir0x/reservoir-sdk'

const smartBotResponse = require('./Utils/smartBotResponse').smartBotResponse

Expand Down Expand Up @@ -243,54 +245,59 @@ const initReservoirBots = async () => {
const studioContracts = await waitForStudioContracts()
const engineContracts = await waitForEngineContracts()

const buildContractsString = (contracts: string[]): string => {
const ans = 'contracts=' + contracts.join('&contracts=')
return ans
}

const createReservoirBots = (
listParams: string,
saleParams: string,
pollTimeMs: number
) => {
new ReservoirListBot(
`https://api.reservoir.tools/orders/asks/v5?${listParams}&sortBy=createdAt&limit=${reservoirListLimit}&normalizeRoyalties=true`,
pollTimeMs,
bot,
{
Accept: 'application/json',
'x-api-key': process.env.RESERVOIR_API_KEY,
}
)

new ReservoirSaleBot(
`https://api.reservoir.tools/sales/v4?${saleParams}&limit=${reservoirSaleLimit}`,
pollTimeMs,
bot,
{
Accept: 'application/json',
'x-api-key': process.env.RESERVOIR_API_KEY,
}
)
}

const allContracts = Object.values(CORE_CONTRACTS)
.concat(Object.values(COLLAB_CONTRACTS))
.concat(Object.values(EXPLORATIONS_CONTRACTS))
.concat(studioContracts ?? [])
.concat(engineContracts ?? [])

type ReservoirContractSetResponse =
paths['/contracts-sets/v1']['post']['responses']['200']['schema']

const response = await axios.request<ReservoirContractSetResponse>({
method: 'POST',
url: 'https://api.reservoir.tools/contracts-sets/v1',
headers: {
accept: '*/*',
'content-type': 'application/json',
'x-api-key': process.env.RESERVOIR_API_KEY,
},
data: { contracts: allContracts },
})

const contractSetID = response.data.contractsSetId

// List endpoint lets you use contractSet param which is very nice
new ReservoirListBot(
`https://api.reservoir.tools/orders/asks/v5?contractsSetId=${contractSetID}&sortBy=createdAt&limit=${reservoirListLimit}&normalizeRoyalties=true`,
API_POLL_TIME_MS,
bot,
{
Accept: 'application/json',
'x-api-key': process.env.RESERVOIR_API_KEY,
}
)

// Sadly sales endpoint does not support contractSet param yet - need to batch by 20 contracts
const RESERVOIR_CONTRACT_LIMIT = 20
const numBotInstances = Math.ceil(
allContracts.length / RESERVOIR_CONTRACT_LIMIT
)
for (let i = 0; i < numBotInstances; i++) {
const start = i * RESERVOIR_CONTRACT_LIMIT
const end = start + RESERVOIR_CONTRACT_LIMIT
const listParams = buildContractsString(allContracts.slice(start, end))
const saleParams = listParams.replaceAll('contracts', 'contract')
const saleParams =
'contract=' + allContracts.slice(start, end).join('&contract=')

createReservoirBots(listParams, saleParams, API_POLL_TIME_MS + i * 3000)
new ReservoirSaleBot(
`https://api.reservoir.tools/sales/v4?${saleParams}&limit=${reservoirSaleLimit}`,
API_POLL_TIME_MS + i * 3000,
bot,
{
Accept: 'application/json',
'x-api-key': process.env.RESERVOIR_API_KEY,
}
)
}
}

Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2619,14 +2619,14 @@ __metadata:
languageName: node
linkType: hard

"@reservoir0x/reservoir-sdk@npm:^2.4.11":
version: 2.4.11
resolution: "@reservoir0x/reservoir-sdk@npm:2.4.11"
"@reservoir0x/reservoir-sdk@npm:^2.4.32":
version: 2.4.32
resolution: "@reservoir0x/reservoir-sdk@npm:2.4.32"
dependencies:
axios: "npm:^1.6.7"
peerDependencies:
viem: ~2.17.4
checksum: 10c0/0b90356a47b66ae31c6976616d5511249f6f859678b8a737fa9de3e05c7a0bc072da40b80b3451faac0cd3a1464d1830125a0464eaccc4b197e3f8bbe4f43de3
checksum: 10c0/c383bc4d431fb96426f4704a645bb289c27f4da3b99ef791173586f216bb014d853ec7b8a21e075a3981ee3a60f71c538f258f93603b232a6df9fc382cf0678c
languageName: node
linkType: hard

Expand Down Expand Up @@ -3630,7 +3630,7 @@ __metadata:
"@graphql-codegen/typescript-urql": "npm:^3.7.3"
"@graphql-codegen/urql-introspection": "npm:^2.2.1"
"@graphql-tools/utils": "npm:^8.3.0"
"@reservoir0x/reservoir-sdk": "npm:^2.4.11"
"@reservoir0x/reservoir-sdk": "npm:^2.4.32"
"@supabase/supabase-js": "npm:^2.29.0"
"@types/node": "npm:20.1.2"
"@types/node-cron": "npm:^3.0.8"
Expand Down

0 comments on commit 1c94c51

Please sign in to comment.