Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix floor #701

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions src/Classes/ProjectBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {

import { ensOrAddress, replaceVideoWithGIF } from './APIBots/utils'
import {
getProjectFloor,
getProjectInvocations,
getRandomOobForProject,
getToken,
Expand All @@ -36,6 +35,9 @@ const ONE_MILLION = 1e6
type ReservoirTokenResponse =
paths['/tokens/v7']['get']['responses']['200']['schema']

type ReservoirCollectionResponse =
paths['/collections/v5']['get']['responses']['200']['schema']

/**
* Bot for handling projects
*/
Expand Down Expand Up @@ -152,12 +154,36 @@ export class ProjectBot {
}

if (content.toLowerCase().includes('#floor')) {
const floorToken = await getProjectFloor(this.id)
if (floorToken && floorToken.list_eth_price) {
content = `#${floorToken.invocation}`
} else {
try {
// Reservoir API collections are indexed like: 78000000:78999999
const floorResponse = await axios.request<ReservoirCollectionResponse>({
method: 'GET',
url: `https://api.reservoir.tools/collections/v5?useNonFlaggedFloorAsk=true&id=${
this.coreContract
}%3A${this.projectNumber * ONE_MILLION}%3A${
(this.projectNumber + 1) * ONE_MILLION - 1
}`,
headers: {
accept: '*/*',
'x-api-key': process.env.RESERVOIR_API_KEY,
},
timeout: 3000,
})
const floorToken =
floorResponse.data.collections?.[0]?.floorAsk?.token?.tokenId ?? ''

if (floorToken) {
content = `#${parseInt(floorToken) % ONE_MILLION}`
} else {
msg.channel.send(
`Sorry, looks like no ${this.projectName} tokens are for sale!`
)
return
}
} catch (e) {
console.error('Error getting floor token for:', this.projectName, e)
msg.channel.send(
`Sorry, looks like no ${this.projectName} tokens are for sale!`
`Sorry, looks like there was an error retrieving the floor token for ${this.projectName}. Try again in a bit!`
)
return
}
Expand Down
10 changes: 0 additions & 10 deletions src/Data/graphql/artbot-hasura-queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,6 @@ query getProjectInvocations($id: String!) {
}
}

query getProjectFloor($id: String!) {
projects_metadata(where: { id: { _eq: $id } }) {
tokens(limit: 3, order_by: { list_eth_price: asc }) {
invocation
list_eth_price
is_flagged
}
}
}

query getAllContracts {
contracts_metadata {
...ContractDetail
Expand Down
20 changes: 0 additions & 20 deletions src/Data/queryGraphQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
GetContractProjectsDocument,
GetProjectInvocationsDocument,
GetProjectInContractsDocument,
GetProjectFloorDocument,
TokenDetailFragment,
ProjectTokenDetailFragment,
GetMostRecentMintedTokenByContractDocument,
Expand Down Expand Up @@ -417,25 +416,6 @@ export async function getProjectInvocations(projectId: string) {
}
}

export async function getProjectFloor(projectId: string) {
const hasuraClient = getClientForContract(projectId.split('-')[0])
try {
const { data } = await hasuraClient
.query(GetProjectFloorDocument, {
id: projectId,
})
.toPromise()

if (!data) {
throw Error('No data returned from getProjectFloor Hasura query')
}
return data.projects_metadata[0].tokens.find((token) => !token.is_flagged)
} catch (err) {
console.error(err)
return undefined
}
}

export async function getToken(tokenId: string): Promise<TokenDetailFragment> {
const hasuraClient = getClientForContract(tokenId.split('-')[0])

Expand Down
Loading