Skip to content

Commit

Permalink
Join pool schema to market schema (#232)
Browse files Browse the repository at this point in the history
* Update schema

* Overwrite migration file based on schema changes

* Regenerate code

* Connect pool schema to market at poolCreate handler

* Modify account details before saving pool
  • Loading branch information
saboonikhil committed Nov 22, 2022
1 parent bd79162 commit 8f1c96e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ type Market @entity {
scoringRule: String!
"Status of the market"
status: String!
"Zeitgeist's indentifier for liquidity pool"
poolId: Int
"Market's liquidity pool details"
pool: Pool
"Reported outcome of the market. Null if the market is not reported yet"
report: MarketReport
"Resolved outcome for the market"
Expand Down
34 changes: 17 additions & 17 deletions src/mappings/swaps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,6 @@ export async function poolCreate(ctx: EventHandlerContext<Store, {event: {args:
await store.save<Account>(acc)
}

let market = await store.get(Market, { where: { marketId: pool.marketId } })
if (market) {
market.poolId = pool.poolId
console.log(`[${event.name}] Saving market: ${JSON.stringify(market, null, 2)}`)
await store.save<Market>(market)

let hm = new HistoricalMarket()
hm.id = event.id + '-' + market.marketId
hm.marketId = market.marketId
hm.event = event.name.split('.')[1]
hm.poolId = market.poolId
hm.blockNumber = block.height
hm.timestamp = new Date(block.timestamp)
console.log(`[${event.name}] Saving historical market: ${JSON.stringify(hm, null, 2)}`)
await store.save<HistoricalMarket>(hm)
}

if (swapPool.weights && swapPool.weights[swapPool.weights.length - 1][0].__kind == 'Ztg') {
const tokenWeightIn = +swapPool.weights[swapPool.weights.length - 1][1].toString()
await Promise.all(
Expand Down Expand Up @@ -152,6 +135,23 @@ export async function poolCreate(ctx: EventHandlerContext<Store, {event: {args:
hp.timestamp = new Date(block.timestamp)
console.log(`[${event.name}] Saving historical pool: ${JSON.stringify(hp, null, 2)}`)
await store.save<HistoricalPool>(hp)

let market = await store.get(Market, { where: { marketId: pool.marketId } })
if (market) {
market.pool = pool
console.log(`[${event.name}] Saving market: ${JSON.stringify(market, null, 2)}`)
await store.save<Market>(market)

let hm = new HistoricalMarket()
hm.id = event.id + '-' + market.marketId
hm.marketId = market.marketId
hm.event = event.name.split('.')[1]
hm.poolId = market.pool.poolId
hm.blockNumber = block.height
hm.timestamp = new Date(block.timestamp)
console.log(`[${event.name}] Saving historical market: ${JSON.stringify(hm, null, 2)}`)
await store.save<HistoricalMarket>(hm)
}
}

export async function poolExit(ctx: EventHandlerContext<Store, {event: {args: true}}>) {
Expand Down
10 changes: 6 additions & 4 deletions src/model/generated/market.model.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_} from "typeorm"
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, ManyToOne as ManyToOne_, Index as Index_} from "typeorm"
import * as marshal from "./marshal"
import {CategoryMetadata} from "./_categoryMetadata"
import {MarketDeadlines} from "./_marketDeadlines"
import {MarketType} from "./_marketType"
import {MarketPeriod} from "./_marketPeriod"
import {Pool} from "./pool.model"
import {MarketReport} from "./_marketReport"
import {MarketDisputeMechanism} from "./_marketDisputeMechanism"

Expand Down Expand Up @@ -137,10 +138,11 @@ export class Market {
status!: string

/**
* Zeitgeist's indentifier for liquidity pool
* Market's liquidity pool details
*/
@Column_("int4", {nullable: true})
poolId!: number | undefined | null
@Index_()
@ManyToOne_(() => Pool, {nullable: true})
pool!: Pool | undefined | null

/**
* Reported outcome of the market. Null if the market is not reported yet
Expand Down

0 comments on commit 8f1c96e

Please sign in to comment.