-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Slim down marketplace subgraph into essential information only (#3)
- Loading branch information
Showing
22 changed files
with
1,395 additions
and
0 deletions.
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
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,17 @@ | ||
{ | ||
"name": "marketplace", | ||
"version": "1.0.0", | ||
"description": "Subgraph that powers the Treasure Marketplace", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "graph build subgraph.yaml", | ||
"codegen": "graph codegen subgraph.yaml", | ||
"deploy:dev": "graphx deploy --product hosted-service treasureproject/bridgeworld-dev", | ||
"deploy:prod": "graph deploy --product hosted-service treasureproject/marketplace", | ||
"deploy:staging": "graph deploy --product hosted-service treasureproject/marketplace-next", | ||
"prepare:arbitrum": "mustache ../../node_modules/@treasure/subgraph-config/src/arbitrum.json template.yaml > subgraph.yaml", | ||
"prepare:arbitrum-testnet": "mustache ../../node_modules/@treasure/subgraph-config/src/arbitrum-testnet.json template.yaml > subgraph.yaml", | ||
"prepare:mainnet": "true", | ||
"test": "graph test" | ||
} | ||
} |
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,92 @@ | ||
enum Status { | ||
Active | ||
Inactive | ||
Sold | ||
} | ||
|
||
enum TokenStandard { | ||
ERC721 | ||
ERC1155 | ||
} | ||
|
||
type Collection @entity { | ||
id: ID! | ||
|
||
contract: String! | ||
floorPrice: BigInt! | ||
listings: [Listing!]! | ||
name: String! | ||
tokens: [Token!]! @derivedFrom(field: "collection") | ||
standard: TokenStandard! | ||
|
||
totalListings: Int! | ||
totalSales: BigInt! | ||
totalVolume: BigInt! | ||
} | ||
|
||
type Listing @entity { | ||
id: ID! | ||
|
||
# "Track originally listed quantity, needed when staking Treasures" | ||
# _listedQuantity: BigInt! | ||
|
||
blockTimestamp: BigInt! | ||
buyer: User | ||
# contract: String! | ||
collection: Collection! | ||
# collectionName: String! | ||
expires: BigInt! | ||
|
||
# "Used to support multiple filters with metadata attributes" | ||
# filters: [String!] | ||
|
||
# nicePrice: String | ||
pricePerItem: BigInt! | ||
quantity: Int! | ||
seller: User! | ||
status: Status! | ||
token: Token! | ||
# tokenName: String | ||
# totalPrice: String | ||
|
||
# Sold listing | ||
transactionLink: String | ||
} | ||
|
||
type Token @entity { | ||
id: ID! | ||
|
||
collection: Collection! | ||
# contract: String! | ||
"For ERC1155s, but is it needed?" | ||
floorPrice: BigInt | ||
listings: [Listing!] @derivedFrom(field: "token") | ||
name: String | ||
owners: [UserToken!]! @derivedFrom(field: "token") | ||
tokenId: BigInt! | ||
} | ||
|
||
type User @entity { | ||
id: ID! | ||
|
||
listings: [Listing!]! @derivedFrom(field: "seller") | ||
purchases: [Listing!]! @derivedFrom(field: "buyer") | ||
tokens: [UserToken!]! @derivedFrom(field: "user") | ||
staked: [StakedToken!]! @derivedFrom(field: "user") | ||
} | ||
|
||
type UserToken @entity { | ||
id: ID! | ||
|
||
quantity: Int! | ||
token: Token! | ||
user: User! | ||
} | ||
|
||
type StakedToken @entity { | ||
id: ID! | ||
|
||
quantity: Int! | ||
token: Token! | ||
user: User! | ||
} |
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,13 @@ | ||
import { Address, BigInt } from "@graphprotocol/graph-ts"; | ||
|
||
export function getAddressId(address: Address, tokenId: BigInt): string { | ||
return `${address.toHexString()}-${tokenId.toHexString()}`; | ||
} | ||
|
||
export function getUserAddressId( | ||
user: Address, | ||
address: Address, | ||
tokenId: BigInt | ||
): string { | ||
return [user.toHexString(), getAddressId(address, tokenId)].join("-"); | ||
} |
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,4 @@ | ||
export * from "./ids"; | ||
export * from "./model"; | ||
export * from "./token-id"; | ||
export * from "./utils"; |
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 { Address, log } from "@graphprotocol/graph-ts"; | ||
import { Collection } from "../../generated/schema"; | ||
|
||
function createCollection( | ||
contract: Address, | ||
name: string, | ||
standard: string | ||
): void { | ||
let id = contract.toHexString(); | ||
let collection = Collection.load(id); | ||
|
||
if (!collection) { | ||
collection = new Collection(id); | ||
|
||
collection.contract = id; | ||
collection.listings = []; | ||
collection.name = name; | ||
collection.standard = standard; | ||
|
||
collection.save(); | ||
} | ||
} | ||
|
||
export function createErc721Collection(contract: Address, name: string): void { | ||
createCollection(contract, name, "ERC721"); | ||
} | ||
|
||
export function createErc1155Collection(contract: Address, name: string): void { | ||
createCollection(contract, name, "ERC1155"); | ||
} | ||
|
||
export function getCollection(contract: Address): Collection { | ||
let id = contract.toHexString(); | ||
let collection = Collection.load(id); | ||
|
||
// Should never happen, famous last words | ||
if (!collection) { | ||
collection = new Collection(id); | ||
|
||
log.warning("Unknown collection: {}", [contract.toHexString()]); | ||
} | ||
|
||
return collection; | ||
} |
Oops, something went wrong.