Skip to content

Commit

Permalink
Merge pull request #868 from XYOracleNetwork/feature/extract-nft-sche…
Browse files Browse the repository at this point in the history
…ma-from-plugin

Extract NFT schema from plugin
  • Loading branch information
JoelBCarter authored Jun 27, 2023
2 parents 24b5181 + 21ec151 commit 05344e7
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"dependencies": {
"@xyo-network/payload-model": "workspace:^",
"@xyo-network/payload-plugin": "workspace:^"
"@xyo-network/payload-plugin": "workspace:^",
"@xyo-network/witness": "workspace:^"
},
"devDependencies": {
"@xylabs/ts-scripts-yarn3": "^2.17.17",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { DivinerConfig } from '@xyo-network/diviner-model'

import { NftScoreSchema } from './Schema'

export type NftScoreDivinerConfigSchema = `${NftScoreSchema}.diviner.config`
export const NftScoreDivinerConfigSchema: NftScoreDivinerConfigSchema = `${NftScoreSchema}.diviner.config`

export type NftScoreDivinerConfig = DivinerConfig<{ schema: NftScoreDivinerConfigSchema }>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Payload } from '@xyo-network/payload-model'

import { NftScoreSchema } from './Schema'

export type PassFailScore = [total: number, possible: 1]
export const PASS: PassFailScore = [1, 1]
export const FAIL: PassFailScore = [0, 1]
export type ScaledScore = [total: number, possible: number]
export const SKIP: ScaledScore = [0, 0]
export type Score = ScaledScore | PassFailScore

export type AttributesScoringCriteria = 'Attributes'

export type MetadataScoringCriteria =
| 'Animation URL'
| 'Background Color'
| 'Description'
| 'External Url'
| 'Image'
| 'Image Data'
| 'Name'
| 'YouTube URL'
| AttributesScoringCriteria

export type ScoringCriteria = 'Contract Address' | 'Supply' | 'Token Id' | 'Type' | MetadataScoringCriteria

export type ScoringCriteriaKey = ScoringCriteria & PropertyKey

export type NftAnalysis = {
[key in ScoringCriteriaKey]: Score
}

export type NftScorePayload = Payload<{ schema: NftScoreSchema } & Partial<Omit<NftAnalysis, 'schema'>>>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { NftSchema } from '../Schema'

export type NftScoreSchema = `${NftSchema}.score`
export const NftScoreSchema: NftScoreSchema = `${NftSchema}.score`
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './Config'
export * from './Payload'
export * from './Schema'
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
export type NftSchema = 'network.xyo.crypto.nft'
export const NftSchema: NftSchema = 'network.xyo.crypto.nft'

export type NftWitnessConfigSchema = `${NftSchema}.witness.config`
export const NftWitnessConfigSchema: NftWitnessConfigSchema = `${NftSchema}.witness.config`
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NftWitnessConfigSchema } from '@xyo-network/crypto-wallet-nft-payload-plugin'
import { WitnessConfig } from '@xyo-network/witness'

import { NftWitnessConfigSchema } from './Schema'

export type CryptoWalletNftWitnessConfig = WitnessConfig<{
address?: string
chainId?: number
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { NftSchema } from '../Schema'

export type NftWitnessConfigSchema = `${NftSchema}.witness.config`
export const NftWitnessConfigSchema: NftWitnessConfigSchema = `${NftSchema}.witness.config`
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Config'
export * from './Schema'
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { NftInfoPayloadPlugin } from './Plugin'

export * from './Diviner'
export * from './Payload'
export * from './Schema'
export * from './Template'
export * from './Witness'

export { NftInfoPayloadPlugin }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { AbstractDiviner } from '@xyo-network/abstract-diviner'
import { isNftInfoPayload, NftSchema } from '@xyo-network/crypto-wallet-nft-payload-plugin'
import { DivinerConfig, DivinerParams } from '@xyo-network/diviner-model'
import {
isNftInfoPayload,
NftScoreDivinerConfig,
NftScoreDivinerConfigSchema,
NftScorePayload,
NftScoreSchema,
} from '@xyo-network/crypto-wallet-nft-payload-plugin'
import { DivinerParams } from '@xyo-network/diviner-model'
import { AnyConfigSchema } from '@xyo-network/module'
import { Payload } from '@xyo-network/payload-model'

import { analyzeNft, NftAnalysis } from './lib'

export type NftScoreSchema = `${NftSchema}.score`
export const NftScoreSchema: NftScoreSchema = `${NftSchema}.score`

export type NftScoreDivinerConfigSchema = `${NftScoreSchema}.diviner.config`
export const NftScoreDivinerConfigSchema: NftScoreDivinerConfigSchema = `${NftScoreSchema}.diviner.config`

export type NftScoreDivinerConfig = DivinerConfig<{ schema: NftScoreDivinerConfigSchema }>
export type NftScoreDivinerParams = DivinerParams<AnyConfigSchema<NftScoreDivinerConfig>>

export type NftScorePayload = Payload<{ schema: NftScoreSchema } & Partial<Omit<NftAnalysis, 'schema'>>>

const toNftScorePayload = (rating: NftAnalysis): NftScorePayload => {
return { ...rating, schema: NftScoreSchema } as NftScorePayload
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { ExternalProvider, JsonRpcFetchFunc } from '@ethersproject/providers'
import { assertEx } from '@xylabs/assert'
import { NftInfoPayload, NftSchema, NftWitnessConfigSchema } from '@xyo-network/crypto-wallet-nft-payload-plugin'
import { CryptoWalletNftWitnessConfig, NftInfoPayload, NftSchema, NftWitnessConfigSchema } from '@xyo-network/crypto-wallet-nft-payload-plugin'
import { AnyConfigSchema } from '@xyo-network/module'
import { Payload } from '@xyo-network/payload-model'
import { AbstractWitness, WitnessParams } from '@xyo-network/witness'

import { CryptoWalletNftWitnessConfig } from './Config'
import { getNftsOwnedByAddress } from './lib'

export type CryptoWalletNftWitnessParams = WitnessParams<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CryptoWalletNftPlugin } from './Plugin'

export * from './Config'
export * from './Diviner'
export * from './lib'
export * from './Witness'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { NftInfo, NftInfoPayload, NftSchema } from '@xyo-network/crypto-wallet-nft-payload-plugin'
import { NftInfo, NftInfoPayload, NftSchema, NftScoreDivinerConfigSchema } from '@xyo-network/crypto-wallet-nft-payload-plugin'
import { PayloadWrapper } from '@xyo-network/payload-wrapper'
import { readFile } from 'fs/promises'
import { join } from 'path'

import { isNftScorePayload, NftScoreDiviner, NftScoreDivinerConfigSchema } from '../Diviner'
import { isNftScorePayload, NftScoreDiviner } from '../Diviner'

describe('NftScoreDiviner', () => {
let data: NftInfoPayload[]
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6260,6 +6260,7 @@ __metadata:
"@xylabs/tsconfig": ^2.17.17
"@xyo-network/payload-model": "workspace:^"
"@xyo-network/payload-plugin": "workspace:^"
"@xyo-network/witness": "workspace:^"
typescript: ^5.1.3
languageName: unknown
linkType: soft
Expand Down

0 comments on commit 05344e7

Please sign in to comment.