generated from eldargab/hydra-template
-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat(1115): flipping nfts #88
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2c7a556
feat: model of flipping nft
KngZhi 23998ae
feat: resolver
KngZhi 0b26eda
feat: lint sql and add params
KngZhi fabd16e
Merge branch 'main' into 1619-flipping-nfts
KngZhi 66259ad
feat: previous price
KngZhi 46db70b
feat: prev owners
KngZhi a4e72ba
Merge branch '1619-flipping-nfts' of github.com:KngZhi/rubick into 16…
KngZhi e3caba4
feat: distribution
KngZhi 605bb37
feat: distribution
KngZhi b32669f
Merge branch '1619-flipping-nfts' of github.com:KngZhi/rubick into 16…
KngZhi a4c3922
feat: rename and beautify sql code
KngZhi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Field, ObjectType } from 'type-graphql'; | ||
|
||
@ObjectType() | ||
export class FlippingNFT { | ||
@Field(() => String, { nullable: false, name: 'nftId' }) | ||
nft_id!: string | ||
|
||
@Field(() => String, { nullable: false, name: 'collectionId' }) | ||
collection_id!: string | ||
|
||
@Field(() => String, { nullable: false }) | ||
author!: string | ||
|
||
@Field(() => Date, { nullable: false }) | ||
date!: Date | ||
|
||
@Field(() => String) | ||
previous!: string | ||
|
||
@Field(() => String, { nullable: false }) | ||
current!: string | ||
|
||
@Field(() => BigInt, { nullable: true, defaultValue: 0n, name: 'floorPrice' }) | ||
floor_price!: bigint | ||
|
||
@Field(() => Number, { name: 'previousOwner' }) | ||
previous_owners!: number | ||
|
||
@Field(() => Number, { nullable: false }) | ||
total!: number | ||
|
||
@Field(() => Number, { nullable: false, name: 'owners' }) | ||
unique_collectors!: number | ||
|
||
@Field(() => String, { nullable: false }) | ||
distribution!: string | ||
|
||
@Field(() => BigInt, { name: 'emotes' }) | ||
emote_count!: number | ||
|
||
constructor(props: Partial<FlippingNFT>) { | ||
Object.assign(this, props); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const collectionsDistribution = (idList: string): string => | ||
`SELECT ce.id, | ||
COUNT(ne.current_owner) AS owners, | ||
COUNT (DISTINCT ne.current_owner) AS unique_owner | ||
FROM collection_entity ce | ||
LEFT JOIN nft_entity ne ON ne.collection_id = ce.id | ||
WHERE ce.id in (${idList}) | ||
GROUP BY ce.id` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Query, Resolver, Arg } from 'type-graphql' | ||
import type { EntityManager } from 'typeorm' | ||
import { NFTEntity } from '../../model/generated' | ||
import { FlippingNFT } from '../model/nft.model' | ||
import { flippingQuery, previousPriceQuery } from "../query/nft"; | ||
import { collectionsDistribution } from "../query/collection" | ||
import { makeQuery, toSqlInParams } from "../utils"; | ||
|
||
type PreviousNft = { | ||
nft_id: string, | ||
meta: string, | ||
rank: number, | ||
} | ||
|
||
type CollectionDistribution = { | ||
id: string | ||
owners: number | ||
unique_owner: number | ||
} | ||
|
||
@Resolver() | ||
export class FlippingNFTsResolver { | ||
constructor(private tx: () => Promise<EntityManager>) { } | ||
|
||
@Query(() => [FlippingNFT]) | ||
async flippingNFTs( | ||
@Arg('limit', { nullable: true, defaultValue: 20 }) limit: number, | ||
@Arg('offset', { nullable: true, defaultValue: 0 }) offset: number, | ||
): Promise<Array<FlippingNFT>> { | ||
const result: Array<FlippingNFT> = await makeQuery(this.tx, NFTEntity, flippingQuery, [limit, offset]) | ||
|
||
const nfts = result.map(item => item.nft_id) | ||
|
||
const prevNFTs: [PreviousNft] = (await makeQuery( | ||
this.tx, | ||
NFTEntity, | ||
previousPriceQuery(toSqlInParams(nfts)))) | ||
|
||
const collections: CollectionDistribution[] = await makeQuery( | ||
this.tx, | ||
NFTEntity, | ||
collectionsDistribution(toSqlInParams(result.map(item => item.collection_id)))) | ||
|
||
return result.map(nft => { | ||
const { nft_id, collection_id } = nft | ||
const previousNft = prevNFTs.find((nft) => nft.nft_id === nft_id) || { meta: "0" } | ||
// handle LIST meta is not money | ||
const previous = Number(previousNft.meta) | ||
const { owners = 0, unique_owner = 0} = collections.find(col => col.id === collection_id) || {} | ||
|
||
return { | ||
...nft, | ||
previous: Number.isNaN(previous) ? "0" : String(previous), | ||
distribution: (owners / unique_owner).toFixed(2), | ||
} | ||
|
||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may a bit better name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I should change all those
Flipping
toMostTraded
?