diff --git a/db/migrations/1666492329299-Data.js b/db/migrations/1666696411991-Data.js similarity index 92% rename from db/migrations/1666492329299-Data.js rename to db/migrations/1666696411991-Data.js index 93f7d32e..be63f178 100644 --- a/db/migrations/1666492329299-Data.js +++ b/db/migrations/1666696411991-Data.js @@ -1,5 +1,5 @@ -module.exports = class Data1666492329299 { - name = 'Data1666492329299' +module.exports = class Data1666696411991 { + name = 'Data1666696411991' async up(db) { await db.query(`CREATE TABLE "account" ("id" character varying NOT NULL, "account_id" text NOT NULL, "market_id" integer, "pool_id" integer, "pvalue" numeric NOT NULL, CONSTRAINT "PK_54115ee388cdb6d86bb4bf5b2ea" PRIMARY KEY ("id"))`) @@ -8,7 +8,7 @@ module.exports = class Data1666492329299 { await db.query(`CREATE TABLE "historical_account_balance" ("id" character varying NOT NULL, "account_id" text NOT NULL, "asset_id" text NOT NULL, "d_balance" numeric NOT NULL, "balance" numeric NOT NULL, "d_value" numeric, "value" numeric, "pvalue" numeric, "event" text NOT NULL, "block_number" integer NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, CONSTRAINT "PK_bfc701998dd9e45981c88f4d1af" PRIMARY KEY ("id"))`) await db.query(`CREATE TABLE "asset" ("id" character varying NOT NULL, "asset_id" text NOT NULL, "pool_id" integer, "price" numeric, "amount_in_pool" numeric, CONSTRAINT "PK_1209d107fe21482beaea51b745e" PRIMARY KEY ("id"))`) await db.query(`CREATE TABLE "historical_asset" ("id" character varying NOT NULL, "account_id" text, "ztg_traded" numeric, "asset_id" text NOT NULL, "d_price" numeric, "d_amount_in_pool" numeric, "new_price" numeric, "new_amount_in_pool" numeric, "event" text NOT NULL, "block_number" integer NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, CONSTRAINT "PK_24bfbff0fb73bae4960d7301293" PRIMARY KEY ("id"))`) - await db.query(`CREATE TABLE "market" ("id" character varying NOT NULL, "market_id" integer NOT NULL, "creator" text NOT NULL, "creation" text NOT NULL, "creator_fee" integer, "oracle" text NOT NULL, "outcome_assets" text array NOT NULL, "slug" text, "question" text, "description" text, "categories" jsonb, "scalar_type" text, "deadlines" jsonb, "tags" text array, "img" text, "metadata" text NOT NULL, "market_type" jsonb NOT NULL, "period" jsonb NOT NULL, "end" numeric NOT NULL, "scoring_rule" text NOT NULL, "status" text NOT NULL, "pool_id" integer, "report" jsonb, "resolved_outcome" text, "dispute_mechanism" jsonb NOT NULL, CONSTRAINT "PK_1e9a2963edfd331d92018e3abac" PRIMARY KEY ("id"))`) + await db.query(`CREATE TABLE "market" ("id" character varying NOT NULL, "market_id" integer NOT NULL, "creator" text NOT NULL, "creation" text NOT NULL, "creator_fee" integer, "oracle" text NOT NULL, "outcome_assets" text array NOT NULL, "slug" text, "question" text, "description" text, "categories" jsonb, "scalar_type" text, "deadlines" jsonb, "tags" text array, "img" text, "metadata" text NOT NULL, "market_type" jsonb NOT NULL, "period" jsonb NOT NULL, "scoring_rule" text NOT NULL, "status" text NOT NULL, "pool_id" integer, "report" jsonb, "resolved_outcome" text, "dispute_mechanism" jsonb NOT NULL, CONSTRAINT "PK_1e9a2963edfd331d92018e3abac" PRIMARY KEY ("id"))`) await db.query(`CREATE TABLE "historical_market" ("id" character varying NOT NULL, "market_id" integer NOT NULL, "pool_id" integer, "status" text, "report" jsonb, "resolved_outcome" text, "event" text NOT NULL, "block_number" integer NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, CONSTRAINT "PK_8b5b3dfdac79a88102b94d55498" PRIMARY KEY ("id"))`) await db.query(`CREATE TABLE "pool" ("id" character varying NOT NULL, "pool_id" integer NOT NULL, "account_id" text, "base_asset" text NOT NULL, "market_id" integer NOT NULL, "pool_status" text NOT NULL, "scoring_rule" text NOT NULL, "swap_fee" text NOT NULL, "total_subsidy" text NOT NULL, "total_weight" text NOT NULL, "weights" jsonb NOT NULL, "ztg_qty" numeric NOT NULL, "volume" numeric NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL, CONSTRAINT "PK_db1bfe411e1516c01120b85f8fe" PRIMARY KEY ("id"))`) await db.query(`CREATE TABLE "historical_pool" ("id" character varying NOT NULL, "pool_id" integer NOT NULL, "pool_status" text, "ztg_qty" numeric, "volume" numeric, "event" text NOT NULL, "block_number" integer NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, CONSTRAINT "PK_6ee31afe7b6dc3500a94effc951" PRIMARY KEY ("id"))`) diff --git a/schema.graphql b/schema.graphql index 4b3791dc..3fa74cce 100644 --- a/schema.graphql +++ b/schema.graphql @@ -146,8 +146,6 @@ type Market @entity { marketType: MarketType! "Time period expressed in block numbers or timestamps" period: MarketPeriod! - "Timestamp at which market should end" - end: BigInt! "Scoring rule used for the market" scoringRule: String! "Status of the market" @@ -285,9 +283,13 @@ Time period of the market """ type MarketPeriod @jsonField { "start & end block numbers" - block: String + block: [BigInt] + "Timestamp at which market should end" + end: BigInt! + "Timestamp at which market should start" + start: BigInt! "start & end timestamps" - timestamp: String + timestamp: [BigInt] } """ diff --git a/src/mappings/predictionMarkets/index.ts b/src/mappings/predictionMarkets/index.ts index ebe6c841..e7cae500 100644 --- a/src/mappings/predictionMarkets/index.ts +++ b/src/mappings/predictionMarkets/index.ts @@ -255,17 +255,24 @@ export async function marketCreated(ctx: EventHandlerContext>, json?: any) { Object.assign(this, props) if (json != null) { - this._block = json.block == null ? undefined : marshal.string.fromJSON(json.block) - this._timestamp = json.timestamp == null ? undefined : marshal.string.fromJSON(json.timestamp) + this._block = json.block == null ? undefined : marshal.fromList(json.block, val => val == null ? undefined : marshal.bigint.fromJSON(val)) + this._end = marshal.bigint.fromJSON(json.end) + this._start = marshal.bigint.fromJSON(json.start) + this._timestamp = json.timestamp == null ? undefined : marshal.fromList(json.timestamp, val => val == null ? undefined : marshal.bigint.fromJSON(val)) } } /** * start & end block numbers */ - get block(): string | undefined | null { + get block(): (bigint | undefined | null)[] | undefined | null { return this._block } - set block(value: string | undefined | null) { + set block(value: (bigint | undefined | null)[] | undefined | null) { this._block = value } + /** + * Timestamp at which market should end + */ + get end(): bigint { + assert(this._end != null, 'uninitialized access') + return this._end + } + + set end(value: bigint) { + this._end = value + } + + /** + * Timestamp at which market should start + */ + get start(): bigint { + assert(this._start != null, 'uninitialized access') + return this._start + } + + set start(value: bigint) { + this._start = value + } + /** * start & end timestamps */ - get timestamp(): string | undefined | null { + get timestamp(): (bigint | undefined | null)[] | undefined | null { return this._timestamp } - set timestamp(value: string | undefined | null) { + set timestamp(value: (bigint | undefined | null)[] | undefined | null) { this._timestamp = value } toJSON(): object { return { - block: this.block, - timestamp: this.timestamp, + block: this.block == null ? undefined : this.block.map((val: any) => val == null ? undefined : marshal.bigint.toJSON(val)), + end: marshal.bigint.toJSON(this.end), + start: marshal.bigint.toJSON(this.start), + timestamp: this.timestamp == null ? undefined : this.timestamp.map((val: any) => val == null ? undefined : marshal.bigint.toJSON(val)), } } } diff --git a/src/model/generated/market.model.ts b/src/model/generated/market.model.ts index c381639c..970b4851 100644 --- a/src/model/generated/market.model.ts +++ b/src/model/generated/market.model.ts @@ -124,12 +124,6 @@ export class Market { @Column_("jsonb", {transformer: {to: obj => obj.toJSON(), from: obj => new MarketPeriod(undefined, marshal.nonNull(obj))}, nullable: false}) period!: MarketPeriod - /** - * Timestamp at which market should end - */ - @Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false}) - end!: bigint - /** * Scoring rule used for the market */