Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Nov 16, 2022
1 parent ed26e8e commit f250949
Show file tree
Hide file tree
Showing 20 changed files with 655 additions and 314 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# seaport-gossip

![CI][github-actions-badge]
[![CI][github-actions-badge]][github-actions-link]

A peer-to-peer network for sharing [Seaport][seaport-repo] orders.

Expand Down Expand Up @@ -153,12 +153,14 @@ You can query for orders, add new orders, and subscribe to events.
) {
chainId
offer {
tokenAddress
token
identifierOrCriteria
startAmount
endAmount
}
consideration {
tokenAddress
token
identifierOrCriteria
startAmount
endAmount
}
Expand Down Expand Up @@ -257,3 +259,4 @@ You can get stats for your node via the `stats` query.
[api-docs]: ./docs
[libp2p-website]: https://libp2p.io/
[github-actions-badge]: https://github.com/ProjectOpenSea/seaport-gossip/actions/workflows/test.yml/badge.svg?branch=main
[github-actions-link]: https://github.com/ProjectOpenSea/seaport-gossip/actions
Binary file modified datadirs/datadir/dev.db
Binary file not shown.
Binary file modified datadirs/datadir2/dev.db
Binary file not shown.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@
"@chainsafe/libp2p-gossipsub": "^4.1.1",
"@chainsafe/libp2p-noise": "^8.0.1",
"@chainsafe/ssz": "^0.9.2",
"@ethereumjs/trie": "^5.0.0",
"@graphql-yoga/node": "^2.13.13",
"@libp2p/interfaces": "^3.0.3",
"@libp2p/kad-dht": "^3.0.5",
"@libp2p/mplex": "^5.2.4",
"@libp2p/peer-id": "^1.1.16",
"@libp2p/peer-id-factory": "^1.0.18",
"@libp2p/websockets": "^3.0.4",
"@multiformats/multiaddr": "^11.0.0",
"@opensea/seaport-order-validator": "^0.1.1",
Expand All @@ -62,6 +63,7 @@
"graphql-scalars": "^1.18.0",
"it-pipe": "^2.0.4",
"libp2p": "^0.39.2",
"merkletreejs": "^0.3.3",
"node-fetch": "^3.2.10",
"prom-client": "^14.1.0",
"reflect-metadata": "^0.1.13",
Expand All @@ -73,7 +75,6 @@
},
"devDependencies": {
"@chainsafe/eslint-plugin-node": "^11.2.3",
"@libp2p/peer-id-factory": "^1.0.18",
"@types/chai": "^4.3.3",
"@types/chai-as-promised": "^7.1.5",
"@types/graphql-fields": "^1.3.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ CREATE TABLE "OrderMetadata" (
"isValid" BOOLEAN NOT NULL,
"isAuction" BOOLEAN NOT NULL,
"isFullyFulfilled" BOOLEAN NOT NULL,
"lastFulfilledAt" DATETIME,
"lastFulfilledAt" TEXT,
"lastFulfilledPrice" TEXT,
"isPinned" BOOLEAN NOT NULL DEFAULT false,
"isRemoved" BOOLEAN NOT NULL DEFAULT false,
Expand Down
6 changes: 4 additions & 2 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()

async function main() {
/*
const order1 = await prisma.order.upsert({
where: {
hash: '0x0000000000000000000000000000000000000000000000000000000000000000',
hash: '0xa3c92e0a25acabf6f3a11722e6d2013a11ff2bf9832c5c7c3e1cd7ea2fe2d06f',
},
update: {},
create: {
hash: '0x0000000000000000000000000000000000000000000000000000000000000000',
hash: '0xa3c92e0a25acabf6f3a11722e6d2013a11ff2bf9832c5c7c3e1cd7ea2fe2d06f',
offer: {
create: {
itemType: 1,
Expand Down Expand Up @@ -134,6 +135,7 @@ async function main() {
})
console.log({ order1, order2 })
*/
}

main()
Expand Down
2 changes: 1 addition & 1 deletion scripts/simulate/run-local-net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type { PeerId } from '@libp2p/interface-peer-id'
import type { Multiaddr } from '@multiformats/multiaddr'

const opts: SeaportGossipNodeOpts = {
web3Provider: new MockProvider('mainnet'),
web3Provider: new MockProvider('mainnet') as any,
collectionAddresses: [
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
// '0x3F53082981815Ed8142384EDB1311025cA750Ef1',
Expand Down
34 changes: 21 additions & 13 deletions src/listeners/seaport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ethers } from 'ethers'
import ISeaport from '../contract-abi/Seaport.json' assert { type: 'json' }
import { short } from '../index.js'
import { publishEvent } from '../util/gossipsub.js'
import { emptyOrderJSON } from '../util/serialize.js'
import { ItemType, OrderEvent, SeaportEvent } from '../util/types.js'

import type { SeaportGossipNode } from '../node.js'
Expand Down Expand Up @@ -158,6 +159,7 @@ export class SeaportListener {
const event = {
event: OrderEvent.FULFILLED,
orderHash,
order,
blockNumber: block.number.toString(),
blockHash: block.hash,
}
Expand Down Expand Up @@ -190,8 +192,9 @@ export class SeaportListener {
const event = {
event: OrderEvent.CANCELLED,
orderHash,
lastValidatedBlockNumber: block.number.toString(),
lastValidatedBlockHash: block.hash,
order,
blockNumber: block.number.toString(),
blockHash: block.hash,
}
await this._publishEvent(event)
}
Expand Down Expand Up @@ -223,18 +226,20 @@ export class SeaportListener {
const event = {
event: OrderEvent.VALIDATED,
orderHash,
lastValidatedBlockNumber: lastValidatedBlockNumber.toString(),
lastValidatedBlockHash,
order,
blockNumber: lastValidatedBlockNumber.toString(),
blockHash: lastValidatedBlockHash,
}
await this._publishEvent(event)
}

/**
* Handle CounterIncremented event from the Seaport contract.
*/
private async _onCounterIncrementedEvent(
public async _onCounterIncrementedEvent(
newCounter: number,
offerer: Address
offerer: Address,
publishGossipsubEvent = true
) {
const orders = await this.prisma.order.findMany({
where: { offerer, counter: { lt: newCounter } },
Expand All @@ -257,14 +262,17 @@ export class SeaportListener {
})
}

const event = {
event: OrderEvent.COUNTER_INCREMENTED,
offerer,
newCounter,
blockNumber: block.number.toString(),
blockHash: block.hash,
if (publishGossipsubEvent) {
const event = {
event: OrderEvent.COUNTER_INCREMENTED,
offerer,
orderHash: ethers.constants.HashZero,
order: { ...emptyOrderJSON, offerer, counter: newCounter },
blockNumber: block.number.toString(),
blockHash: block.hash,
}
await this._publishEvent(event)
}
await this._publishEvent(event)
}

/**
Expand Down
Loading

0 comments on commit f250949

Please sign in to comment.