Skip to content

Commit

Permalink
fix: simplehash
Browse files Browse the repository at this point in the history
  • Loading branch information
guanbinrui committed Nov 26, 2024
1 parent 21fe829 commit 76b9373
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 174 deletions.
5 changes: 1 addition & 4 deletions packages/web3-providers/src/SimpleHash/apis/EVM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import {
createNextIndicator,
NetworkPluginID,
} from '@masknet/shared-base'
import {
type NonFungibleAsset,
type NonFungibleCollection,
} from '@masknet/web3-shared-base'
import { type NonFungibleAsset, type NonFungibleCollection } from '@masknet/web3-shared-base'
import { ChainId, SchemaType, isValidChainId, isValidAddress } from '@masknet/web3-shared-evm'
import {
fetchFromSimpleHash,
Expand Down
14 changes: 7 additions & 7 deletions packages/web3-providers/src/SimpleHash/apis/Solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class SimpleHashAPI_Solana implements NonFungibleTokenAPI.Provider<ChainId, Sche

async getAssetsByCollectionId(
collectionId: string,
{ chainId = ChainId.Mainnet, indicator, }: BaseHubOptions<ChainId> = {},
{ chainId = ChainId.Mainnet, indicator }: BaseHubOptions<ChainId> = {},
skipScoreCheck = false,
) {
const chain = resolveChain(NetworkPluginID.PLUGIN_SOLANA, chainId)
Expand All @@ -94,9 +94,9 @@ class SimpleHashAPI_Solana implements NonFungibleTokenAPI.Provider<ChainId, Sche
})

const response = await fetchFromSimpleHash<{ next_cursor: string; nfts: SimpleHash.Asset[] }>(path)
const assets = response.nfts.map((x) => createSolanaNonFungibleAsset(x, skipScoreCheck)).filter(Boolean) as Array<
NonFungibleAsset<ChainId, SchemaType>
>
const assets = response.nfts
.map((x) => createSolanaNonFungibleAsset(x, skipScoreCheck))
.filter(Boolean) as Array<NonFungibleAsset<ChainId, SchemaType>>

return createPageable(
assets,
Expand All @@ -122,9 +122,9 @@ class SimpleHashAPI_Solana implements NonFungibleTokenAPI.Provider<ChainId, Sche

const response = await fetchFromSimpleHash<{ next_cursor: string; nfts: SimpleHash.Asset[] }>(path)

const assets = response.nfts.map((x) => createSolanaNonFungibleAsset(x, skipScoreCheck)).filter(Boolean) as Array<
NonFungibleAsset<ChainId, SchemaType>
>
const assets = response.nfts
.map((x) => createSolanaNonFungibleAsset(x, skipScoreCheck))
.filter(Boolean) as Array<NonFungibleAsset<ChainId, SchemaType>>

return createPageable(
assets,
Expand Down
328 changes: 165 additions & 163 deletions packages/web3-providers/src/types/SimpleHash.ts
Original file line number Diff line number Diff line change
@@ -1,183 +1,185 @@
import { type BigNumber } from 'bignumber.js'

export interface FloorPrice {
marketplace_id: LiteralUnion<'blur' | 'looksrare' | 'opensea' | 'x2y2'>
marketplace_name: LiteralUnion<'Blur' | 'LooksRare' | 'OpenSea' | 'X2Y2'>
value: number
payment_token: PaymentToken
}

// TODO: Contract address will be added in SimpleHash v1 release.
// TODO: Asking SimpleHash to add schema in SimpleHash v1 release.
export interface Collection {
// TODO: the collection id key name may change in SimpleHash v1 release.
id: string
chain: string
banner_image_url: string
collection_id: string
description: string
external_url: string
/**
* The score is a numeric value from 0 to 100, with 0 being deemed not spam, and 100 being deemed likely spam.
* null means undetermined
*/
spam_score: number | null
discord_url: string
floor_prices: Array<{
export namespace SimpleHash {
export interface FloorPrice {
marketplace_id: LiteralUnion<'blur' | 'looksrare' | 'opensea' | 'x2y2'>
marketplace_name: LiteralUnion<'Blur' | 'LooksRare' | 'OpenSea' | 'X2Y2'>
value: number
payment_token: PaymentToken
}>
image_url: string
marketplace_pages?: Array<{
collection_url: string
nft_url: string
marketplace_collection_id: string
marketplace_id: string
marketplace_name: string
verified: boolean
}>
distinct_nfts_owned: number
total_copies_owned: number
distinct_owner_count: number
distinct_nft_count: number
name: string
/** e.g ["ethereum.0x18487d2cac946c7fe800855c4039aac210f68baa"] */
top_contracts: string[]
nft_ids?: string[]
total_quantity: number
/** twitter handler */
twitter_username: string | null
instagram_username: string | null
medium_username: string | null
telegram_url: string | null
}
export interface Asset {
chain: string // ethereum
collection: Collection
contract: {
deployed_by: string // EOA
deployed_via_contract: string | null
name: string
symbol: string
type: string // ERC721
}
contract_address: string
description: string
image_url: string
name: string
created_date: string // "2022-04-04T20:15:02"
token_id: string
token_count: number
nft_id: string // ethereum.0x18487d2cac946c7fe800855c4039aac210f68baa.1597
last_sale?: {
from_address: string
to_address: string
marketplace_id: string
total_price?: BigNumber.Value
unit_price: BigNumber.Value
transaction: string // tx hash
marketplace_name: string
payment_token?: PaymentToken
timestamp: string // "2022-04-04T20:15:02"
}
floor_prices: FloorPrice[]
owners: Array<{
owner_address: string
}>
previews: {
blurhash: string
image_large_url: string
image_medium_url: string
image_opengraph_url: string
image_small_url: string
predominant_color: string

// TODO: Contract address will be added in SimpleHash v1 release.
// TODO: Asking SimpleHash to add schema in SimpleHash v1 release.
export interface Collection {
// TODO: the collection id key name may change in SimpleHash v1 release.
id: string
chain: string
banner_image_url: string
collection_id: string
description: string
external_url: string
/**
* The score is a numeric value from 0 to 100, with 0 being deemed not spam, and 100 being deemed likely spam.
* null means undetermined
*/
spam_score: number | null
discord_url: string
floor_prices: Array<{
marketplace_id: LiteralUnion<'blur' | 'looksrare' | 'opensea' | 'x2y2'>
marketplace_name: LiteralUnion<'Blur' | 'LooksRare' | 'OpenSea' | 'X2Y2'>
value: number
payment_token: PaymentToken
}>
image_url: string
marketplace_pages?: Array<{
collection_url: string
nft_url: string
marketplace_collection_id: string
marketplace_id: string
marketplace_name: string
verified: boolean
}>
distinct_nfts_owned: number
total_copies_owned: number
distinct_owner_count: number
distinct_nft_count: number
name: string
/** e.g ["ethereum.0x18487d2cac946c7fe800855c4039aac210f68baa"] */
top_contracts: string[]
nft_ids?: string[]
total_quantity: number
/** twitter handler */
twitter_username: string | null
instagram_username: string | null
medium_username: string | null
telegram_url: string | null
}
extra_metadata?: {
attributes: Array<{
trait_type: string
value: string
display_type: string | null
export interface Asset {
chain: string // ethereum
collection: Collection
contract: {
deployed_by: string // EOA
deployed_via_contract: string | null
name: string
symbol: string
type: string // ERC721
}
contract_address: string
description: string
image_url: string
name: string
created_date: string // "2022-04-04T20:15:02"
token_id: string
token_count: number
nft_id: string // ethereum.0x18487d2cac946c7fe800855c4039aac210f68baa.1597
last_sale?: {
from_address: string
to_address: string
marketplace_id: string
total_price?: BigNumber.Value
unit_price: BigNumber.Value
transaction: string // tx hash
marketplace_name: string
payment_token?: PaymentToken
timestamp: string // "2022-04-04T20:15:02"
}
floor_prices: FloorPrice[]
owners: Array<{
owner_address: string
}>
event_id?: number
previews: {
blurhash: string
image_large_url: string
image_medium_url: string
image_opengraph_url: string
image_small_url: string
predominant_color: string
}
extra_metadata?: {
attributes: Array<{
trait_type: string
value: string
display_type: string | null
}>
event_id?: number
}
}
}

export interface PaymentToken {
address: string | null
decimals: number
name: string
payment_token_id: string // e.g. ethereum.native
symbol: string
value: BigNumber.Value
}
export interface PaymentToken {
address: string | null
decimals: number
name: string
payment_token_id: string // e.g. ethereum.native
symbol: string
value: BigNumber.Value
}

export interface PriceStat {
timestamp: string
floor_price: number
}
export interface PriceStat {
timestamp: string
floor_price: number
}

export interface CollectionOverview {
collection_id: string
name: string
all_time_volume: number
market_cap: number
payment_token: PaymentToken
'1_day_volume': number
'1_day_prior_volume': number
'1_day_volume_change_percent': number
'7_day_volume': number
'30_day_volume': number
'90_day_volume': number
}
export interface CollectionOverview {
collection_id: string
name: string
all_time_volume: number
market_cap: number
payment_token: PaymentToken
'1_day_volume': number
'1_day_prior_volume': number
'1_day_volume_change_percent': number
'7_day_volume': number
'30_day_volume': number
'90_day_volume': number
}

export enum ActivityType {
Transfer = 'transfer',
Mint = 'mint',
Sale = 'sale',
Burn = 'burn',
}
export enum ActivityType {
Transfer = 'transfer',
Mint = 'mint',
Sale = 'sale',
Burn = 'burn',
}

export interface Activity {
nft_id: string
chain: string
contract_address: string
token_id: string
event_type: ActivityType
from_address: string
to_address: string
quantity: number
timestamp: string
transaction: string
transaction_initiator: string
sale_details: {
marketplace_id: string
marketplace_name: string
payment_token: PaymentToken
unit_price: number
total_price: number
export interface Activity {
nft_id: string
chain: string
contract_address: string
token_id: string
event_type: ActivityType
from_address: string
to_address: string
quantity: number
timestamp: string
transaction: string
transaction_initiator: string
sale_details: {
marketplace_id: string
marketplace_name: string
payment_token: PaymentToken
unit_price: number
total_price: number
}
}
}

export interface Ownership {
wallet_address: string
contracts: Array<{ contract_address: string; token_ids: string[] }>
}
export interface Ownership {
wallet_address: string
contracts: Array<{ contract_address: string; token_ids: string[] }>
}

export interface Owner {
nft_id: string
owner_address: string
token_id: string
quantity: number
first_acquired_date: string
last_acquired_date: string
}
export interface Owner {
nft_id: string
owner_address: string
token_id: string
quantity: number
first_acquired_date: string
last_acquired_date: string
}

export interface TopCollector {
owner_address: string
owner_ens_name: string | null
owner_image: string
distinct_nfts_owned: number
total_copies_owned: number
export interface TopCollector {
owner_address: string
owner_ens_name: string | null
owner_image: string
distinct_nfts_owned: number
total_copies_owned: number
}
}

0 comments on commit 76b9373

Please sign in to comment.